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;
}
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();
}
Aggregations