Search in sources :

Example 1 with BubbleMapLayer

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;
}
Also used : JsonArray(com.google.gson.JsonArray) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) JsonObject(com.google.gson.JsonObject) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer)

Example 2 with BubbleMapLayer

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;
}
Also used : IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) NoClustering(org.activityinfo.shared.report.model.clustering.NoClustering) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Iterator(java.util.Iterator) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) AutomaticClustering(org.activityinfo.shared.report.model.clustering.AutomaticClustering)

Example 3 with BubbleMapLayer

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);
}
Also used : MapReportElement(org.activityinfo.shared.report.model.MapReportElement) Marshaller(javax.xml.bind.Marshaller) Report(org.activityinfo.shared.report.model.Report) Slice(org.activityinfo.shared.report.model.layers.PiechartMapLayer.Slice) FileOutputStream(java.io.FileOutputStream) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) JAXBContext(javax.xml.bind.JAXBContext) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) Test(org.junit.Test)

Example 4 with BubbleMapLayer

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);
}
Also used : MapReportElement(org.activityinfo.shared.report.model.MapReportElement) ArabicNumberSequence(org.activityinfo.shared.report.model.labeling.ArabicNumberSequence) Report(org.activityinfo.shared.report.model.Report) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) TableElement(org.activityinfo.shared.report.model.TableElement) Test(org.junit.Test)

Example 5 with BubbleMapLayer

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"));
}
Also used : ArabicNumberSequence(org.activityinfo.shared.report.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.shared.report.content.MapContent) BaseMapResult(org.activityinfo.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.shared.report.model.TableColumn) TableElement(org.activityinfo.shared.report.model.TableElement) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) SiteResult(org.activityinfo.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) CircledMapLayer(org.activityinfo.shared.report.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.shared.dto.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Aggregations

BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)7 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)5 Test (org.junit.Test)5 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)4 MapContent (org.activityinfo.shared.report.content.MapContent)3 Report (org.activityinfo.shared.report.model.Report)3 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)2 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)2 TableElement (org.activityinfo.shared.report.model.TableElement)2 ArabicNumberSequence (org.activityinfo.shared.report.model.labeling.ArabicNumberSequence)2 MapLayer (org.activityinfo.shared.report.model.layers.MapLayer)2 JsonElement (com.google.gson.JsonElement)1 FileOutputStream (java.io.FileOutputStream)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1