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