Search in sources :

Example 16 with MapReportElement

use of org.activityinfo.shared.report.model.MapReportElement 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 17 with MapReportElement

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

Example 18 with MapReportElement

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

Example 19 with MapReportElement

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

the class PolygonGeneratorTest method polygonWithHole.

@Test
public void polygonWithHole() throws IOException {
    AdminMarker marker = new AdminMarker();
    marker.setAdminEntityId(1930);
    marker.setColor("#FFBBBB");
    AdminOverlay overlay = new AdminOverlay(1383);
    overlay.setOutlineColor("#FF0000");
    overlay.addPolygon(marker);
    PolygonMapLayer layer = new PolygonMapLayer();
    layer.addIndicatorId(1);
    layer.setAdminLevelId(1383);
    MapContent content = new MapContent();
    content.setZoomLevel(8);
    content.setBaseMap(GoogleBaseMap.ROADMAP);
    content.setCenter(new AiLatLng(12.60500192642215, -7.98924994468689));
    content.getAdminOverlays().add(overlay);
    content.setFilterDescriptions(new ArrayList<FilterDescription>());
    PolygonLegend.ColorClass clazz1 = new PolygonLegend.ColorClass(1, 53.6, "0000FF");
    PolygonLegend.ColorClass clazz2 = new PolygonLegend.ColorClass(600, 600, "FF0000");
    PolygonLegend legend = new PolygonLegend(layer, Lists.newArrayList(clazz1, clazz2));
    content.getLegends().add(legend);
    IndicatorDTO indicator = new IndicatorDTO();
    indicator.setId(1);
    indicator.setName("Indicator Test");
    content.getIndicators().add(indicator);
    MapReportElement map = new MapReportElement();
    map.addLayer(layer);
    map.setContent(content);
    FileOutputStream fos = new FileOutputStream("target/report-tests/polygon-hole.pdf");
    PdfReportRenderer pdfr = new PdfReportRenderer(TestGeometry.get(), "");
    pdfr.render(map, fos);
    fos.close();
}
Also used : PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) PdfReportRenderer(org.activityinfo.server.report.renderer.itext.PdfReportRenderer) FilterDescription(org.activityinfo.shared.report.content.FilterDescription) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) AdminOverlay(org.activityinfo.shared.report.content.AdminOverlay) PolygonLegend(org.activityinfo.shared.report.content.PolygonLegend) AdminMarker(org.activityinfo.shared.report.content.AdminMarker) FileOutputStream(java.io.FileOutputStream) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Test(org.junit.Test)

Example 20 with MapReportElement

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

the class ItextReportRendererTest method legendTest.

@Test
public void legendTest() throws IOException {
    BubbleMapMarker marker1 = new BubbleMapMarker();
    marker1.setLat(-2.45);
    marker1.setLng(28.8);
    marker1.setX(100);
    marker1.setY(100);
    marker1.setRadius(25);
    marker1.setValue(300);
    TileBaseMap baseMap = new TileBaseMap();
    baseMap.setTileUrlPattern("//www.activityinfo.org/resources/tile/nordkivu.cd/{z}/{x}/{y}.png");
    BubbleMapLayer layer1 = new BubbleMapLayer();
    layer1.addIndicatorId(101);
    layer1.setMinRadius(10);
    layer1.setMaxRadius(10);
    BubbleLayerLegend legend1 = new BubbleLayerLegend();
    legend1.setDefinition(layer1);
    legend1.setMinValue(1000);
    legend1.setMaxValue(3000);
    BubbleMapLayer layer2 = new BubbleMapLayer();
    layer2.addIndicatorId(102);
    layer2.addIndicatorId(103);
    layer2.setMinRadius(10);
    layer2.setMaxRadius(25);
    BubbleLayerLegend legend2 = new BubbleLayerLegend();
    legend2.setDefinition(layer2);
    legend2.setMinValue(600);
    legend2.setMaxValue(999);
    IconMapLayer layer3 = new IconMapLayer();
    layer3.setIcon(MapIcon.Icon.Default.name());
    layer3.getIndicatorIds().add(101);
    IconLayerLegend legend3 = new IconLayerLegend();
    legend3.setDefinition(layer3);
    List<PieChartLegend> pieChartLegends = Lists.newArrayList();
    List<PiechartMapLayer> pieChartLayers = Lists.newArrayList();
    int[] indicatorIds = new int[] { 101, 102, 103 };
    for (int sliceCount = 1; sliceCount < 10; ++sliceCount) {
        PiechartMapLayer pieChartLayer = new PiechartMapLayer();
        for (int i = 0; i != sliceCount; ++i) {
            pieChartLayer.addIndicatorId(indicatorIds[i % indicatorIds.length]);
        }
        pieChartLayer.setMinRadius(25);
        pieChartLayer.setMaxRadius(25);
        PieChartLegend pieChartLegend = new PieChartLegend();
        pieChartLegend.setDefinition(pieChartLayer);
        pieChartLayers.add(pieChartLayer);
        pieChartLegends.add(pieChartLegend);
    }
    IndicatorDTO indicator101 = new IndicatorDTO();
    indicator101.setId(101);
    indicator101.setName("Nombre de salles de classe fonctionnelles (construites, rehabilitees, equipees) " + "pour l'education formelle et non formelle.");
    IndicatorDTO indicator102 = new IndicatorDTO();
    indicator102.setId(102);
    indicator102.setName("Nombre d'enfants ayant beneficie de kits scolaires, recreatifs et didactiques");
    IndicatorDTO indicator103 = new IndicatorDTO();
    indicator103.setId(103);
    indicator103.setName("Pourcentage des ménages qui utilsent la moustiquaire rationnellement");
    MapContent mapContent = new MapContent();
    mapContent.setFilterDescriptions(Collections.EMPTY_LIST);
    mapContent.setBaseMap(baseMap);
    mapContent.setZoomLevel(8);
    mapContent.setCenter(new Extents(-2.2, -2.1, 28.85, 28.9).center());
    mapContent.setMarkers(Arrays.asList((MapMarker) marker1));
    mapContent.getIndicators().addAll(Arrays.asList(indicator101, indicator102, indicator103));
    mapContent.addLegend(legend1);
    mapContent.addLegend(legend2);
    mapContent.addLegend(legend3);
    mapContent.getLegends().addAll(pieChartLegends);
    MapReportElement map = new MapReportElement();
    map.setTitle("My Map");
    map.setContent(mapContent);
    map.addLayer(layer1);
    map.addLayer(layer2);
    map.addLayer(layer3);
    map.getLayers().addAll(pieChartLayers);
    ReportContent content = new ReportContent();
    content.setFilterDescriptions(Collections.EMPTY_LIST);
    Report report = new Report();
    report.setContent(content);
    report.addElement(map);
    renderToPdf(report, "legend.pdf");
    renderToHtml(report, "legend.html");
    renderToRtf(report, "legend.rtf");
    renderToPpt(map, "legend.ppt");
}
Also used : ReportContent(org.activityinfo.shared.report.content.ReportContent) BubbleLayerLegend(org.activityinfo.shared.report.content.BubbleLayerLegend) MapMarker(org.activityinfo.shared.report.content.MapMarker) IconMapMarker(org.activityinfo.shared.report.content.IconMapMarker) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) MapContent(org.activityinfo.shared.report.content.MapContent) Report(org.activityinfo.shared.report.model.Report) BubbleMapMarker(org.activityinfo.shared.report.content.BubbleMapMarker) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) Extents(org.activityinfo.shared.util.mapping.Extents) MapReportElement(org.activityinfo.shared.report.model.MapReportElement) IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) PieChartLegend(org.activityinfo.shared.report.content.PieChartLegend) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) IconLayerLegend(org.activityinfo.shared.report.content.IconLayerLegend) Test(org.junit.Test)

Aggregations

MapReportElement (org.activityinfo.shared.report.model.MapReportElement)23 Test (org.junit.Test)17 MapContent (org.activityinfo.shared.report.content.MapContent)12 Report (org.activityinfo.shared.report.model.Report)8 BubbleMapMarker (org.activityinfo.shared.report.content.BubbleMapMarker)6 IconMapMarker (org.activityinfo.shared.report.content.IconMapMarker)6 TileBaseMap (org.activityinfo.shared.map.TileBaseMap)5 MapMarker (org.activityinfo.shared.report.content.MapMarker)5 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)5 FileOutputStream (java.io.FileOutputStream)4 PivotChartReportElement (org.activityinfo.shared.report.model.PivotChartReportElement)4 AiLatLng (org.activityinfo.shared.report.content.AiLatLng)3 ReportContent (org.activityinfo.shared.report.content.ReportContent)3 TableElement (org.activityinfo.shared.report.model.TableElement)3 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)3 Extents (org.activityinfo.shared.util.mapping.Extents)3 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 PdfReportRenderer (org.activityinfo.server.report.renderer.itext.PdfReportRenderer)2 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)2