Search in sources :

Example 1 with Slice

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

the class ReportJsonFactory method encodeSlicesList.

private JsonArray encodeSlicesList(List<Slice> slices) {
    JsonArray jsonSlices = new JsonArray();
    for (int i = 0; i < slices.size(); i++) {
        Slice slice = slices.get(i);
        JsonObject jsonSlice = new JsonObject();
        if (slice.getColor() != null) {
            jsonSlice.addProperty("color", slice.getColor());
        }
        jsonSlice.addProperty("indicatorId", slice.getIndicatorId());
        jsonSlices.add(jsonSlice);
    }
    return jsonSlices;
}
Also used : JsonArray(com.google.gson.JsonArray) Slice(org.activityinfo.shared.report.model.layers.PiechartMapLayer.Slice) JsonObject(com.google.gson.JsonObject)

Example 2 with Slice

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

the class PiechartLayerOptions method populateColorPickerWidget.

private void populateColorPickerWidget() {
    indicatorsStore.removeAll();
    if (piechartMapLayer != null && piechartMapLayer.getIndicatorIds() != null && piechartMapLayer.getIndicatorIds().size() > 0) {
        for (Slice slice : piechartMapLayer.getSlices()) {
            String name = schema.getIndicatorById(slice.getIndicatorId()).getName();
            indicatorsStore.add(new NamedSlice(slice.getColor(), slice.getIndicatorId(), name, slice));
        }
    }
    layout(true);
}
Also used : Slice(org.activityinfo.shared.report.model.layers.PiechartMapLayer.Slice)

Example 3 with Slice

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

the class PiechartLayerGenerator method calulateSlices.

private void calulateSlices(PointValue pv, SiteDTO site) {
    pv.setSlices(new ArrayList<PieMapMarker.SliceValue>());
    for (Slice slice : layer.getSlices()) {
        EntityCategory indicatorCategory = new EntityCategory(slice.getIndicatorId());
        Double value = site.getIndicatorValue(slice.getIndicatorId());
        if (value != null && value != 0) {
            PieMapMarker.SliceValue sliceValue = new PieMapMarker.SliceValue();
            sliceValue.setValue(value);
            sliceValue.setCategory(indicatorCategory);
            sliceValue.setColor(slice.getColor());
            sliceValue.setIndicatorId(slice.getIndicatorId());
            pv.getSlices().add(sliceValue);
        }
    }
}
Also used : Slice(org.activityinfo.shared.report.model.layers.PiechartMapLayer.Slice) PieMapMarker(org.activityinfo.shared.report.content.PieMapMarker) EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Example 4 with Slice

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

the class ItextMapRenderer method addPieChartDescription.

private void addPieChartDescription(MapReportElement element, Cell descriptionCell, PiechartMapLayer layer) throws BadElementException, IOException {
    for (Slice slice : layer.getSlices()) {
        IndicatorDTO indicator = element.getContent().getIndicatorById(slice.getIndicatorId());
        Color color = ColorUtil.colorFromString(slice.getColor());
        ItextGraphic sliceImage = renderSlice(imageCreator, color, 10);
        Chunk box = new Chunk(sliceImage.toItextImage(), 0, 0);
        Chunk description = new Chunk(indicator.getName());
        Phrase phrase = new Phrase();
        phrase.add(box);
        phrase.add(description);
        Paragraph paragraph = new Paragraph(phrase);
        descriptionCell.add(paragraph);
    }
}
Also used : IndicatorDTO(org.activityinfo.shared.dto.IndicatorDTO) Slice(org.activityinfo.shared.report.model.layers.PiechartMapLayer.Slice) Color(com.google.code.appengine.awt.Color) Phrase(com.lowagie.text.Phrase) Chunk(com.lowagie.text.Chunk) ItextGraphic(org.activityinfo.server.report.renderer.image.ItextGraphic) Paragraph(com.lowagie.text.Paragraph)

Example 5 with Slice

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

Aggregations

Slice (org.activityinfo.shared.report.model.layers.PiechartMapLayer.Slice)5 Color (com.google.code.appengine.awt.Color)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 Chunk (com.lowagie.text.Chunk)1 Paragraph (com.lowagie.text.Paragraph)1 Phrase (com.lowagie.text.Phrase)1 FileOutputStream (java.io.FileOutputStream)1 JAXBContext (javax.xml.bind.JAXBContext)1 Marshaller (javax.xml.bind.Marshaller)1 ItextGraphic (org.activityinfo.server.report.renderer.image.ItextGraphic)1 IndicatorDTO (org.activityinfo.shared.dto.IndicatorDTO)1 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)1 PieMapMarker (org.activityinfo.shared.report.content.PieMapMarker)1 MapReportElement (org.activityinfo.shared.report.model.MapReportElement)1 Report (org.activityinfo.shared.report.model.Report)1 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)1 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)1 Test (org.junit.Test)1