Search in sources :

Example 11 with Cluster

use of org.activityinfo.server.report.generator.map.cluster.Cluster in project activityinfo by bedatadriven.

the class GraphTest method saveClusters.

protected void saveClusters(MarkerGraph graph, String fileName, List<Cluster> clusters) throws IOException {
    File outputDir = new File("build/report-tests");
    outputDir.mkdirs();
    File outputFile = new File("build/report-tests/" + fileName + ".svg");
    FileWriter svg = new FileWriter(outputFile);
    svg.write("<svg width='100%' height='100%' transform='scale(500)' version='1.1'  " + "xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' >\n");
    for (MarkerGraph.Edge edge : graph.getEdges()) {
        svg.write(String.format("<path d='M%d %d L%d %d' " + "style='stroke:rgb(92,92,92);stroke-width:0.25'/>\n", edge.getA().getPoint().getX(), edge.getA().getPoint().getY(), edge.getB().getPoint().getX(), edge.getB().getPoint().getY()));
    }
    String[] colors = new String[] { "antiquewhite", "blue", "brown", "chartreuse", "cornflowerblue", "crimson", "darkkhaki", "darkorange", "darkorchid", "lightpink", "lightseagreen", "lightskyblue", "lime", "limegreen", "magenta", "mediumaqua" };
    int colorIndex = 0;
    for (int i = 0; i != clusters.size(); ++i) {
        Cluster cluster = clusters.get(i);
        svg.write(String.format("<circle cx='%d' cy='%d' r='%f' " + "style='fill: %s; fill-opacity: 0.5; stroke:none'/>\n", cluster.getPoint().getX(), cluster.getPoint().getY(), cluster.getRadius(), colors[colorIndex]));
        for (PointValue pointValue : cluster.getPointValues()) {
            svg.write(String.format("<circle cx='%d' cy='%d' r='1.5' " + "style='stroke:rgb(92,92,92); stroke-width:0.1; fill: %s' title='%f'/>\n", pointValue.getPx().getX(), pointValue.getPx().getY(), colors[colorIndex], pointValue.getValue()));
        }
        colorIndex++;
        if (colorIndex == colors.length) {
            colorIndex = 0;
        }
    }
    // label subgraphs
    List<List<MarkerGraph.Node>> subgraphs = graph.getSubgraphs();
    for (int i = 0; i != subgraphs.size(); ++i) {
        Point p = findLR(subgraphs.get(i));
        svg.write(String.format("<text x='%d' y='%d'>%d</text>\n", p.getX() + 5, p.getY(), i));
    }
    svg.write("</svg>\n");
    svg.close();
}
Also used : MarkerGraph(org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph) PointValue(org.activityinfo.legacy.shared.reports.model.PointValue) FileWriter(java.io.FileWriter) Cluster(org.activityinfo.server.report.generator.map.cluster.Cluster) List(java.util.List) ArrayList(java.util.ArrayList) Point(org.activityinfo.legacy.shared.reports.content.Point) File(java.io.File) Point(org.activityinfo.legacy.shared.reports.content.Point)

Aggregations

Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)11 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)7 ArrayList (java.util.ArrayList)6 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)5 Point (org.activityinfo.legacy.shared.reports.content.Point)4 Test (org.junit.Test)4 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)3 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)3 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)3 FileWriter (java.io.FileWriter)2 List (java.util.List)2 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)2 BubbleFitnessFunctor (org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor)2 GeneticSolver (org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 IconLayerLegend (org.activityinfo.legacy.shared.reports.content.IconLayerLegend)1 IconMapMarker (org.activityinfo.legacy.shared.reports.content.IconMapMarker)1