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();
}
Aggregations