use of org.activityinfo.shared.report.model.layers.BubbleMapLayer in project activityinfo by bedatadriven.
the class ReportJsonFactory method encodeLayers.
public JsonArray encodeLayers(List<MapLayer> layers) {
JsonArray jsonLayers = new JsonArray();
for (int i = 0; i < layers.size(); i++) {
MapLayer layer = layers.get(i);
JsonObject jsonLayer = new JsonObject();
if (layer instanceof BubbleMapLayer) {
jsonLayer.addProperty("layerType", layer.getTypeName());
jsonLayer.add("colorDimensions", encodeDimensionList(((BubbleMapLayer) layer).getColorDimensions()));
jsonLayer.addProperty("bubbleColor", ((BubbleMapLayer) layer).getBubbleColor());
jsonLayer.addProperty("labelColor", ((BubbleMapLayer) layer).getLabelColor());
jsonLayer.addProperty("minRadius", ((BubbleMapLayer) layer).getMinRadius());
jsonLayer.addProperty("maxRadius", ((BubbleMapLayer) layer).getMaxRadius());
jsonLayer.addProperty("alpha", ((BubbleMapLayer) layer).getAlpha());
jsonLayer.addProperty("scaling", ((BubbleMapLayer) layer).getScaling().toString());
} else if (layer instanceof PiechartMapLayer) {
jsonLayer.addProperty("layerType", layer.getTypeName());
jsonLayer.add("slices", encodeSlicesList(((PiechartMapLayer) layer).getSlices()));
jsonLayer.addProperty("minRadius", ((PiechartMapLayer) layer).getMinRadius());
jsonLayer.addProperty("maxRadius", ((PiechartMapLayer) layer).getMaxRadius());
jsonLayer.addProperty("alpha", ((PiechartMapLayer) layer).getAlpha());
jsonLayer.addProperty("scaling", ((PiechartMapLayer) layer).getScaling().toString());
} else if (layer instanceof IconMapLayer) {
jsonLayer.addProperty("layerType", layer.getTypeName());
jsonLayer.add("activityIds", encodeIntegerList(((IconMapLayer) layer).getActivityIds()));
jsonLayer.addProperty("icon", ((IconMapLayer) layer).getIcon());
}
jsonLayer.addProperty("isVisible", layer.isVisible());
jsonLayer.add("indicatorIds", encodeIntegerList(layer.getIndicatorIds()));
// jsonLayer.addProperty("labelSequence", layer.getLabelSequence()
// .next());
// jsonLayer.addProperty("cluster", (Boolean) layer.isClustered());
jsonLayer.addProperty("name", layer.getName());
jsonLayer.add("filter", encodeFilter(layer.getFilter()));
jsonLayers.add(jsonLayer);
}
return jsonLayers;
}
use of org.activityinfo.shared.report.model.layers.BubbleMapLayer in project activityinfo by bedatadriven.
the class ReportJsonFactory method decodeLayers.
public List<MapLayer> decodeLayers(JsonArray layers) {
Iterator<JsonElement> it = layers.iterator();
List<MapLayer> mapLayers = new ArrayList<MapLayer>();
while (it.hasNext()) {
JsonObject jsonLayer = it.next().getAsJsonObject();
if ("Bubble".equals(jsonLayer.get("type"))) {
BubbleMapLayer layer = new BubbleMapLayer();
JsonArray colorDimensions = jsonLayer.get("colorDimensions").getAsJsonArray();
if (colorDimensions.size() > 0) {
layer.setColorDimensions(decodeDimensionList(colorDimensions));
}
JsonElement bubbleColor = jsonLayer.get("bubbleColor");
if (bubbleColor != null) {
layer.setBubbleColor(bubbleColor.getAsString());
}
JsonElement labelColor = jsonLayer.get("labelColor");
if (labelColor != null) {
layer.setLabelColor(labelColor.getAsString());
}
JsonElement minRadius = jsonLayer.get("minRadius");
if (minRadius != null) {
layer.setMinRadius(minRadius.getAsInt());
}
JsonElement maxRadius = jsonLayer.get("maxRadius");
if (maxRadius != null) {
layer.setMaxRadius(maxRadius.getAsInt());
}
JsonElement alpha = jsonLayer.get("alpha");
if (alpha != null) {
layer.setAlpha(alpha.getAsDouble());
}
JsonElement scaling = jsonLayer.get("scaling");
if (scaling != null) {
layer.setScaling(ScalingType.valueOf(scaling.getAsString()));
}
layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
Iterator<JsonElement> itr = indicators.iterator();
while (itr.hasNext()) {
layer.addIndicator(itr.next().getAsInt());
}
if (jsonLayer.get("cluster").getAsBoolean()) {
layer.setClustering(new AutomaticClustering());
} else {
layer.setClustering(new NoClustering());
}
layer.setName(jsonLayer.get("name").getAsString());
layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
mapLayers.add(layer);
} else if ("Piechart".equals(jsonLayer.get("type"))) {
PiechartMapLayer layer = new PiechartMapLayer();
JsonElement minRadius = jsonLayer.get("minRadius");
if (minRadius != null) {
layer.setMinRadius(minRadius.getAsInt());
}
JsonElement maxRadius = jsonLayer.get("maxRadius");
if (maxRadius != null) {
layer.setMaxRadius(maxRadius.getAsInt());
}
JsonElement alpha = jsonLayer.get("alpha");
if (alpha != null) {
layer.setAlpha(alpha.getAsDouble());
}
JsonElement scaling = jsonLayer.get("scaling");
if (scaling != null) {
layer.setScaling(ScalingType.valueOf(scaling.getAsString()));
}
layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
Iterator<JsonElement> itr = indicators.iterator();
while (itr.hasNext()) {
layer.addIndicatorId(itr.next().getAsInt());
}
if (jsonLayer.get("cluster").getAsBoolean()) {
layer.setClustering(new AutomaticClustering());
} else {
layer.setClustering(new NoClustering());
}
layer.setName(jsonLayer.get("name").getAsString());
layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
mapLayers.add(layer);
} else if ("Bubble".equals(jsonLayer.get("type"))) {
IconMapLayer layer = new IconMapLayer();
JsonArray activityIds = jsonLayer.get("activityIds").getAsJsonArray();
Iterator<JsonElement> activityIrtator = activityIds.iterator();
while (activityIrtator.hasNext()) {
layer.addActivityId(activityIrtator.next().getAsInt());
}
JsonElement icon = jsonLayer.get("icon");
if (icon != null) {
layer.setIcon(icon.getAsString());
}
layer.setVisible(jsonLayer.get("isVisible").getAsBoolean());
JsonArray indicators = jsonLayer.get("indicatorIds").getAsJsonArray();
Iterator<JsonElement> itr = indicators.iterator();
while (itr.hasNext()) {
layer.addIndicatorId(itr.next().getAsInt());
}
if (jsonLayer.get("cluster").getAsBoolean()) {
layer.setClustering(new AutomaticClustering());
} else {
layer.setClustering(new NoClustering());
}
layer.setName(jsonLayer.get("name").getAsString());
layer.setFilter(decodeFilter(jsonLayer.get("filter").getAsJsonObject()));
mapLayers.add(layer);
}
}
return mapLayers;
}
use of org.activityinfo.shared.report.model.layers.BubbleMapLayer in project activityinfo by bedatadriven.
the class ReadWriteReportTest method readWriteReportTest.
@Test
public void readWriteReportTest() throws Throwable {
Report report = new Report();
MapReportElement map = new MapReportElement();
map.getLayers().add(new BubbleMapLayer());
PiechartMapLayer pielayer = new PiechartMapLayer();
Slice slice1 = new Slice();
slice1.setColor("FF00AA");
slice1.setIndicatorId(1);
Slice slice2 = new Slice();
slice2.setColor("00FFAA");
slice2.setIndicatorId(2);
pielayer.getSlices().add(slice1);
pielayer.getSlices().add(slice2);
map.getLayers().add(pielayer);
report.getElements().add(map);
Report.class.getPackage();
JAXBContext jc = JAXBContext.newInstance(Report.class.getPackage().getName());
Marshaller marshaller = jc.createMarshaller();
marshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
FileOutputStream fo = new FileOutputStream("SomeXmlTest.xml");
marshaller.marshal(report, fo);
}
use of org.activityinfo.shared.report.model.layers.BubbleMapLayer in project activityinfo by bedatadriven.
the class ReportsTest method testConsolideDesActivitesReport.
@Test
public void testConsolideDesActivitesReport() throws Throwable {
// Setup test
Report report = getReport("realworld/ConsolideDesActivites.xml");
reportGenerator.generate(user, report, null, null);
TableElement pivotTable = (TableElement) report.getElements().get(2);
MapReportElement map1 = pivotTable.getMap();
BubbleMapLayer bubbleMap = (BubbleMapLayer) map1.getLayers().get(0);
assertTrue("Arabic numbering expected", bubbleMap.getLabelSequence() instanceof ArabicNumberSequence);
assertEquals("MinRadius of 8 expected", bubbleMap.getMinRadius(), 8);
assertEquals("MaxRadius of 14 expected", bubbleMap.getMaxRadius(), 14);
assertEquals("Graduated scaling expected", bubbleMap.getScaling(), ScalingType.Graduated);
}
use of org.activityinfo.shared.report.model.layers.BubbleMapLayer in project activityinfo by bedatadriven.
the class TableGeneratorTest method testMap.
//
// @Test
// public void tableWithMap() {
//
// MapReportElement map = new MapReportElement();
// map.setBaseMapId(GoogleBaseMap.ROADMAP.getId());
//
// BubbleMapLayer layer = new BubbleMapLayer();
// layer.addIndicator(INDICATOR_ID);
// map.addLayer(layer);
//
// TableElement table = new TableElement();
// table.setMap(map);
//
// TableColumn column = new TableColumn("Location", "location.name");
// table.addColumn(column);
//
// TableColumn mapColumn = new TableColumn("Map", "map");
// table.addColumn(mapColumn);
//
// DispatcherSync dispatcher = createDispatcher();
// TableGenerator gtor = new TableGenerator(dispatcher, new
// MapGenerator(dispatcher, null, null));
// gtor.generate(user, table, null, null);
//
// Assert.assertNotNull("content is set", table.getContent());
//
// TableData data = table.getContent().getData();
// List<SiteDTO> rows = data.getRows();
// Assert.assertEquals("row count", 1, rows.size());
//
// SiteDTO row = rows.get(0);
// assertThat((String)row.get(column.getSitePropertyName()),
// equalTo("tampa bay"));
// assertThat((String)row.get("map"), equalTo("1"));
// }
@Test
public void testMap() {
TableElement table = new TableElement();
table.addColumn(new TableColumn("Index", "map"));
table.addColumn(new TableColumn("Site", "location.name"));
MapReportElement map = new MapReportElement();
map.setBaseMapId("map1");
CircledMapLayer layer = new BubbleMapLayer();
layer.setLabelSequence(new ArabicNumberSequence());
map.addLayer(layer);
table.setMap(map);
DispatcherSync dispatcher = createMock(DispatcherSync.class);
expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
TileBaseMap baseMap1 = new TileBaseMap();
baseMap1.setId("map1");
baseMap1.setMinZoom(0);
baseMap1.setMaxZoom(12);
baseMap1.setCopyright("(C)");
baseMap1.setName("Grand Canyon");
baseMap1.setTileUrlPattern("http://s/test.png");
expect(dispatcher.execute(isA(GetBaseMaps.class))).andReturn(new BaseMapResult(Collections.singletonList(baseMap1)));
replay(dispatcher);
TableGenerator gtor = new TableGenerator(dispatcher, new MapGenerator(dispatcher, new MockIndicatorDAO()));
gtor.generate(user, table, null, null);
MapContent mapContent = map.getContent();
Assert.assertNotNull("map content", mapContent);
Assert.assertEquals("marker count", 1, mapContent.getMarkers().size());
Assert.assertEquals("label on marker", "1", ((BubbleMapMarker) mapContent.getMarkers().get(0)).getLabel());
Map<Integer, String> siteLabels = mapContent.siteLabelMap();
Assert.assertEquals("site id in map", "1", siteLabels.get(1));
SiteDTO row = table.getContent().getData().getRows().get(0);
Assert.assertEquals("label on row", "1", row.get("map"));
}
Aggregations