Search in sources :

Example 1 with TempDir

use of org.gephi.utils.TempDirUtils.TempDir in project gephi by gephi.

the class StatisticsModelImpl method unembedImages.

private String unembedImages(String report) {
    StringBuilder builder = new StringBuilder();
    String[] result = report.split("data:image/png;base64");
    if (result.length == 0) {
        return report;
    }
    try {
        TempDir tempDir = TempDirUtils.createTempDir();
        for (int i = 0; i < result.length; i++) {
            if (result[i].contains("</IMG>")) {
                String next = result[i];
                int endIndex = next.indexOf('\"');
                String pngStr = next.substring(0, endIndex);
                byte[] imageBytes = Base64.decodeBase64(pngStr);
                String fileName = "image" + i + ".png";
                File file = tempDir.createFile(fileName);
                FileOutputStream fos = new FileOutputStream(file);
                fos.write(imageBytes);
                String path = "file:" + file.getAbsolutePath();
                builder.append(path);
                builder.append(next.substring(endIndex, next.length()));
            } else {
                builder.append(result[i]);
            }
        }
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    return builder.toString();
}
Also used : TempDir(org.gephi.utils.TempDirUtils.TempDir) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 2 with TempDir

use of org.gephi.utils.TempDirUtils.TempDir in project gephi by gephi.

the class ColumnValuesFrequency method writePieChart.

private void writePieChart(final StringBuilder sb, JFreeChart chart, Dimension dimension) throws IOException {
    TempDir tempDir = TempDirUtils.createTempDir();
    String fileName = "frequencies-pie-chart.png";
    File file = tempDir.createFile(fileName);
    String imageFile = "<center><img src=\"file:" + file.getAbsolutePath() + "\"</img></center>";
    ChartUtilities.saveChartAsPNG(file, chart, dimension != null ? dimension.width : 1000, dimension != null ? dimension.height : 1000);
    sb.append(imageFile);
}
Also used : TempDir(org.gephi.utils.TempDirUtils.TempDir) File(java.io.File)

Example 3 with TempDir

use of org.gephi.utils.TempDirUtils.TempDir in project gephi by gephi.

the class ChartUtils method renderChart.

public static String renderChart(JFreeChart chart, String fileName) {
    String imageFile = "";
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        TempDir tempDir = TempDirUtils.createTempDir();
        File file1 = tempDir.createFile(fileName);
        imageFile = "<IMG SRC=\"file:" + file1.getAbsolutePath() + "\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\"></IMG>";
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
    } catch (IOException e) {
    }
    return imageFile;
}
Also used : TempDir(org.gephi.utils.TempDirUtils.TempDir) StandardEntityCollection(org.jfree.chart.entity.StandardEntityCollection) ChartRenderingInfo(org.jfree.chart.ChartRenderingInfo) IOException(java.io.IOException) File(java.io.File)

Example 4 with TempDir

use of org.gephi.utils.TempDirUtils.TempDir in project gephi by gephi.

the class ChartsUtils method writeChart.

private static void writeChart(final StringBuilder sb, final JFreeChart chart, final Dimension dimension, final String fileName) throws IOException {
    TempDir tempDir = TempDirUtils.createTempDir();
    String imageFile = "";
    File file = tempDir.createFile(fileName);
    imageFile = "<center><img src=\"file:" + file.getAbsolutePath() + "\"</img></center>";
    ChartUtilities.saveChartAsPNG(file, chart, dimension.width, dimension.height);
    sb.append(imageFile);
}
Also used : TempDir(org.gephi.utils.TempDirUtils.TempDir) File(java.io.File)

Example 5 with TempDir

use of org.gephi.utils.TempDirUtils.TempDir in project gephi by gephi.

the class GraphDistance method getReport.

/**
 * @return
 */
@Override
public String getReport() {
    String htmlIMG1 = "";
    String htmlIMG2 = "";
    String htmlIMG3 = "";
    String htmlIMG4 = "";
    try {
        TempDir tempDir = TempDirUtils.createTempDir();
        htmlIMG1 = createImageFile(tempDir, betweenness, "Betweenness Centrality Distribution", "Value", "Count");
        htmlIMG2 = createImageFile(tempDir, closeness, "Closeness Centrality Distribution", "Value", "Count");
        htmlIMG3 = createImageFile(tempDir, harmonicCloseness, "Harmonic Closeness Centrality Distribution", "Value", "Count");
        htmlIMG4 = createImageFile(tempDir, eccentricity, "Eccentricity Distribution", "Value", "Count");
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    }
    String report = "<HTML> <BODY> <h1>Graph Distance  Report </h1> " + "<hr>" + "<br>" + "<h2> Parameters: </h2>" + "Network Interpretation:  " + (isDirected ? "directed" : "undirected") + "<br />" + "<br /> <h2> Results: </h2>" + "Diameter: " + diameter + "<br />" + "Radius: " + radius + "<br />" + "Average Path length: " + avgDist + "<br />" + htmlIMG1 + "<br /><br />" + htmlIMG2 + "<br /><br />" + htmlIMG3 + "<br /><br />" + htmlIMG4 + "<br /><br />" + "<h2> Algorithm: </h2>" + "Ulrik Brandes, <i>A Faster Algorithm for Betweenness Centrality</i>, in Journal of Mathematical Sociology 25(2):163-177, (2001)<br />" + "</BODY> </HTML>";
    return report;
}
Also used : TempDir(org.gephi.utils.TempDirUtils.TempDir) IOException(java.io.IOException)

Aggregations

TempDir (org.gephi.utils.TempDirUtils.TempDir)5 File (java.io.File)4 IOException (java.io.IOException)3 FileOutputStream (java.io.FileOutputStream)1 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)1 StandardEntityCollection (org.jfree.chart.entity.StandardEntityCollection)1