Search in sources :

Example 6 with PieMapMarker

use of org.activityinfo.legacy.shared.reports.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.legacy.shared.reports.content.MapContent) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) PieMapMarker(org.activityinfo.legacy.shared.reports.content.PieMapMarker) AiLatLng(org.activityinfo.model.type.geo.AiLatLng) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) PiechartMapLayer(org.activityinfo.legacy.shared.reports.model.layers.PiechartMapLayer) Test(org.junit.Test)

Example 7 with PieMapMarker

use of org.activityinfo.legacy.shared.reports.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("build/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.legacy.shared.reports.content.PieMapMarker) Color(com.google.code.appengine.awt.Color) FileOutputStream(java.io.FileOutputStream) SliceValue(org.activityinfo.legacy.shared.reports.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.legacy.shared.reports.content.PieMapMarker)7 SliceValue (org.activityinfo.legacy.shared.reports.content.PieMapMarker.SliceValue)3 PiechartMapLayer (org.activityinfo.legacy.shared.reports.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 SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 BubbleMapMarker (org.activityinfo.legacy.shared.reports.content.BubbleMapMarker)2 IconMapMarker (org.activityinfo.legacy.shared.reports.content.IconMapMarker)2 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)2 MapMarker (org.activityinfo.legacy.shared.reports.content.MapMarker)2 AiLatLng (org.activityinfo.model.type.geo.AiLatLng)2 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)2 Options (org.discotools.gwt.leaflet.client.Options)2 CircleMarker (org.discotools.gwt.leaflet.client.marker.CircleMarker)2 Marker (org.discotools.gwt.leaflet.client.marker.Marker)2 MarkerOptions (org.discotools.gwt.leaflet.client.marker.MarkerOptions)2 IconOptions (org.discotools.gwt.leaflet.client.types.IconOptions)2 Test (org.junit.Test)2 File (java.io.File)1