use of org.activityinfo.shared.report.model.clustering.NoClustering 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));
}
use of org.activityinfo.shared.report.model.clustering.NoClustering 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.NoClustering in project activityinfo by bedatadriven.
the class LayersWidget method addLayer.
public void addLayer(MapLayer layer) {
if (layer instanceof PointMapLayer) {
((PointMapLayer) layer).setClustering(new NoClustering());
}
mapElement.getLayers().add(layer);
reportEventBus.fireChange();
updateStore();
}
use of org.activityinfo.shared.report.model.clustering.NoClustering 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