Search in sources :

Example 1 with PiechartMapLayer

use of org.activityinfo.shared.report.model.layers.PiechartMapLayer 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 PiechartMapLayer

use of org.activityinfo.shared.report.model.layers.PiechartMapLayer in project activityinfo by bedatadriven.

the class PiechartMapLayerGeneratorTest method testSomething.

@Test
public void testSomething() {
    SiteDTO siteData = new SiteDTO();
    siteData.setId(42);
    siteData.setX(15.0);
    siteData.setY(0.0);
    siteData.setIndicatorValue(1, 50.0);
    siteData.setIndicatorValue(2, 10.0);
    siteData.setIndicatorValue(3, 20.0);
    siteData.setIndicatorValue(4, 40.0);
    PiechartMapLayer pcml = new PiechartMapLayer();
    pcml.setMinRadius(10);
    pcml.setMaxRadius(50);
    pcml.addIndicatorId(1);
    pcml.addIndicatorId(2);
    pcml.addIndicatorId(3);
    pcml.addIndicatorId(4);
    pcml.setClustering(new NoClustering());
    TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
    Map<Integer, Indicator> indicators = Maps.newHashMap();
    indicators.put(1, new Indicator());
    indicators.put(2, new Indicator());
    indicators.put(3, new Indicator());
    indicators.put(4, new Indicator());
    PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
    gen.setSites(Arrays.asList(siteData));
    MapContent mc = new MapContent();
    gen.generate(map, mc);
    assertThat(mc.getMarkers().size(), equalTo(1));
    assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
Also used : MapContent(org.activityinfo.shared.report.content.MapContent) NoClustering(org.activityinfo.shared.report.model.clustering.NoClustering) 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) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) Test(org.junit.Test)

Example 3 with PiechartMapLayer

use of org.activityinfo.shared.report.model.layers.PiechartMapLayer 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 4 with PiechartMapLayer

use of org.activityinfo.shared.report.model.layers.PiechartMapLayer 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 5 with PiechartMapLayer

use of org.activityinfo.shared.report.model.layers.PiechartMapLayer 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)

Aggregations

PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)6 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)4 Test (org.junit.Test)4 MapContent (org.activityinfo.shared.report.content.MapContent)3 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)3 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)2 SiteDTO (org.activityinfo.shared.dto.SiteDTO)2 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)2 PieMapMarker (org.activityinfo.shared.report.content.PieMapMarker)2 Report (org.activityinfo.shared.report.model.Report)2 NoClustering (org.activityinfo.shared.report.model.clustering.NoClustering)2 MapLayer (org.activityinfo.shared.report.model.layers.MapLayer)2 JsonElement (com.google.gson.JsonElement)1 FileOutputStream (java.io.FileOutputStream)1 Iterator (java.util.Iterator)1 JAXBContext (javax.xml.bind.JAXBContext)1