Search in sources :

Example 16 with Point

use of org.activityinfo.legacy.shared.reports.content.Point 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

Point (org.activityinfo.legacy.shared.reports.content.Point)16 PointValue (org.activityinfo.legacy.shared.reports.model.PointValue)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)5 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)4 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 MarkerGraph (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph)2 File (java.io.File)1 FileWriter (java.io.FileWriter)1 List (java.util.List)1 IconLayerLegend (org.activityinfo.legacy.shared.reports.content.IconLayerLegend)1 MapSymbol (org.activityinfo.legacy.shared.reports.model.MapSymbol)1 Extents (org.activityinfo.model.type.geo.Extents)1 Clusterer (org.activityinfo.server.report.generator.map.cluster.Clusterer)1 BubbleFitnessFunctor (org.activityinfo.server.report.generator.map.cluster.genetic.BubbleFitnessFunctor)1 GeneticSolver (org.activityinfo.server.report.generator.map.cluster.genetic.GeneticSolver)1 IntersectionCalculator (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.IntersectionCalculator)1 Node (org.activityinfo.server.report.generator.map.cluster.genetic.MarkerGraph.Node)1