Search in sources :

Example 6 with PieMapMarker

use of org.activityinfo.shared.report.content.PieMapMarker in project activityinfo by bedatadriven.

the class PiechartLayerGenerator method sumSlices.

private void sumSlices(PieMapMarker marker, List<PointValue> pvs) {
    Map<DimensionCategory, PieMapMarker.SliceValue> slices = new HashMap<DimensionCategory, PieMapMarker.SliceValue>();
    for (PointValue pv : pvs) {
        for (PieMapMarker.SliceValue slice : pv.getSlices()) {
            PieMapMarker.SliceValue summedSlice = slices.get(slice.getCategory());
            if (summedSlice == null) {
                summedSlice = new PieMapMarker.SliceValue(slice);
                summedSlice.setIndicatorId(slice.getIndicatorId());
                slices.put(slice.getCategory(), summedSlice);
            } else {
                summedSlice.setValue(summedSlice.getValue() + slice.getValue());
            }
        }
    }
    marker.setSlices(new ArrayList<PieMapMarker.SliceValue>(slices.values()));
}
Also used : DimensionCategory(org.activityinfo.shared.report.content.DimensionCategory) HashMap(java.util.HashMap) PointValue(org.activityinfo.shared.report.model.PointValue) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker)

Example 7 with PieMapMarker

use of org.activityinfo.shared.report.content.PieMapMarker in project activityinfo by bedatadriven.

the class PieChartLegendRenderer method drawSymbol.

private void drawSymbol(Graphics2D g2d) {
    PieMapMarker marker = new PieMapMarker();
    marker.setRadius(layer.getMaxRadius());
    marker.setX(PADDING + layer.getMaxRadius());
    marker.setY(PADDING + layer.getMaxRadius());
    double[] values = calculateNiceLookingValues(layer.getSlices().size());
    int nextValue = 0;
    for (PiechartMapLayer.Slice slice : layer.getSlices()) {
        PieMapMarker.SliceValue sliceValue = new PieMapMarker.SliceValue();
        sliceValue.setColor(slice.getColor());
        sliceValue.setValue(values[nextValue++]);
        marker.getSlices().add(sliceValue);
    }
    ImageMapRenderer.drawPieMarker(g2d, marker);
}
Also used : PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer)

Example 8 with PieMapMarker

use of org.activityinfo.shared.report.content.PieMapMarker in project activityinfo by bedatadriven.

the class PieMapMarkerTest method testPies.

@Test
public void testPies() {
    Dimension dimension = new Dimension(DimensionType.Indicator);
    dimension.setCategoryColor(101, 255);
    dimension.setCategoryColor(102, 0x00FF00);
    dimension.setCategoryColor(103, 0x0000FF);
    SiteDTO site1 = new SiteDTO();
    site1.setId(1);
    site1.setX(0d);
    site1.setY(0d);
    site1.setIndicatorValue(101, 50d);
    site1.setIndicatorValue(102, 40d);
    site1.setIndicatorValue(103, 10d);
    List<SiteDTO> sites = new ArrayList<SiteDTO>();
    sites.add(site1);
    PiechartMapLayer layer = new PiechartMapLayer();
    layer.addIndicatorId(101);
    layer.addIndicatorId(102);
    layer.addIndicatorId(103);
    // layer.getColorDimensions().add(dimension);
    MapReportElement mapElement = new MapReportElement();
    mapElement.addLayer(layer);
    MapContent content = new MapContent();
    TiledMap map = new TiledMap(640, 480, new AiLatLng(0, 0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(101, new Indicator());
    indicators.put(102, new Indicator());
    indicators.put(103, new Indicator());
    PiechartLayerGenerator generator = new PiechartLayerGenerator(layer, indicators);
    generator.setSites(sites);
    generator.generate(map, content);
    Assert.assertEquals(1, content.getMarkers().size());
    PieMapMarker marker = (PieMapMarker) content.getMarkers().get(0);
    Assert.assertEquals(3, marker.getSlices().size());
}
Also used : MapContent(org.activityinfo.shared.report.content.MapContent) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) SiteDTO(org.activityinfo.shared.dto.SiteDTO) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) Test(org.junit.Test)

Example 9 with PieMapMarker

use of org.activityinfo.shared.report.content.PieMapMarker in project activityinfo by bedatadriven.

the class ImageMapRendererTest method renderPieChart.

private void renderPieChart(double value) throws FileNotFoundException, IOException {
    int radius = 21;
    SliceValue s1 = new SliceValue();
    s1.setColor("4169E1");
    s1.setValue(value);
    SliceValue s2 = new SliceValue();
    s2.setColor("EEEE00");
    s2.setValue(360d - value);
    PieMapMarker pmm = new PieMapMarker();
    pmm.setRadius(21);
    pmm.setColor("FF0000");
    pmm.getSlices().add(s1);
    pmm.getSlices().add(s2);
    pmm.setX(radius);
    pmm.setY(radius);
    BufferedImage icon = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = icon.createGraphics();
    g2d.setPaint(new Color(255, 255, 255, 0));
    g2d.fillRect(0, 0, radius * 2, radius * 2);
    ImageMapRenderer.drawPieMarker(g2d, pmm);
    File outputFile = new File("target/report-tests/pieChart-" + ((int) value) + ".png");
    outputFile.getParentFile().mkdirs();
    FileOutputStream fos = new FileOutputStream(outputFile);
    ImageIO.write(icon, "PNG", fos);
    fos.close();
}
Also used : PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) Color(com.google.code.appengine.awt.Color) FileOutputStream(java.io.FileOutputStream) SliceValue(org.activityinfo.shared.report.content.PieMapMarker.SliceValue) File(java.io.File) BufferedImage(com.google.code.appengine.awt.image.BufferedImage) Graphics2D(com.google.code.appengine.awt.Graphics2D)

Aggregations

PieMapMarker (org.activityinfo.shared.report.content.PieMapMarker)9 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)3 SliceValue (org.activityinfo.shared.report.content.PieMapMarker.SliceValue)3 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)3 Color (com.google.code.appengine.awt.Color)2 Graphics2D (com.google.code.appengine.awt.Graphics2D)2 BufferedImage (com.google.code.appengine.awt.image.BufferedImage)2 ArrayList (java.util.ArrayList)2 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)2 SiteDTO (org.activityinfo.shared.dto.SiteDTO)2 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)2 MapContent (org.activityinfo.shared.report.content.MapContent)2 PointValue (org.activityinfo.shared.report.model.PointValue)2 Test (org.junit.Test)2 Rectangle (com.google.code.appengine.awt.Rectangle)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 Cluster (org.activityinfo.server.report.generator.map.cluster.Cluster)1