Search in sources :

Example 1 with AutomaticClustering

use of org.activityinfo.shared.report.model.clustering.AutomaticClustering 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 2 with AutomaticClustering

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

the class ClusteringOptionsWidget method buildForm.

private void buildForm(Set<CountryDTO> countries) {
    radios = Lists.newArrayList();
    radios.add(new ClusteringRadio(I18N.CONSTANTS.none(), new NoClustering()));
    radios.add(new ClusteringRadio(I18N.CONSTANTS.automatic(), new AutomaticClustering()));
    if (countries.size() == 1) {
        CountryDTO country = countries.iterator().next();
        for (AdminLevelDTO level : country.getAdminLevels()) {
            AdministrativeLevelClustering clustering = new AdministrativeLevelClustering();
            clustering.getAdminLevels().add(level.getId());
            radios.add(new ClusteringRadio(level.getName(), clustering));
        }
    }
    radioGroup = new RadioGroup();
    radioGroup.setOrientation(Orientation.VERTICAL);
    radioGroup.setStyleAttribute("padding", "5px");
    for (ClusteringRadio radio : radios) {
        radioGroup.add(radio);
        if (radio.getClustering().equals(value)) {
            radioGroup.setValue(radio);
        }
    }
    add(radioGroup);
    radioGroup.addListener(Events.Change, new Listener<FieldEvent>() {

        @Override
        public void handleEvent(FieldEvent be) {
            ClusteringRadio radio = (ClusteringRadio) radioGroup.getValue();
            setValue(radio.getClustering(), true);
        }
    });
    layout();
// unmask();
}
Also used : AdministrativeLevelClustering(org.activityinfo.shared.report.model.clustering.AdministrativeLevelClustering) RadioGroup(com.extjs.gxt.ui.client.widget.form.RadioGroup) CountryDTO(org.activityinfo.shared.dto.CountryDTO) AdminLevelDTO(org.activityinfo.shared.dto.AdminLevelDTO) FieldEvent(com.extjs.gxt.ui.client.event.FieldEvent) NoClustering(org.activityinfo.shared.report.model.clustering.NoClustering) AutomaticClustering(org.activityinfo.shared.report.model.clustering.AutomaticClustering)

Aggregations

AutomaticClustering (org.activityinfo.shared.report.model.clustering.AutomaticClustering)2 NoClustering (org.activityinfo.shared.report.model.clustering.NoClustering)2 FieldEvent (com.extjs.gxt.ui.client.event.FieldEvent)1 RadioGroup (com.extjs.gxt.ui.client.widget.form.RadioGroup)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 AdminLevelDTO (org.activityinfo.shared.dto.AdminLevelDTO)1 CountryDTO (org.activityinfo.shared.dto.CountryDTO)1 AdministrativeLevelClustering (org.activityinfo.shared.report.model.clustering.AdministrativeLevelClustering)1 BubbleMapLayer (org.activityinfo.shared.report.model.layers.BubbleMapLayer)1 IconMapLayer (org.activityinfo.shared.report.model.layers.IconMapLayer)1 MapLayer (org.activityinfo.shared.report.model.layers.MapLayer)1 PiechartMapLayer (org.activityinfo.shared.report.model.layers.PiechartMapLayer)1