use of com.vaadin.addon.charts.model.DataProviderSeries.HIGH_PROPERTY in project charts by vaadin.
the class DataProviderSeriesBeanSerializer method createDataArray.
private ArrayNode createDataArray(DataProviderSeries<?> chartDataProvider) {
ArrayNode data = JsonNodeFactory.instance.arrayNode();
Set<String> attributes = chartDataProvider.getChartAttributes();
checkRequiredProperties(attributes);
Mode mode = inferSerializationMode(attributes);
for (final Map<String, Optional<Object>> chartAttributeToValue : chartDataProvider.getValues()) {
Optional<Object> xValue = chartAttributeToValue.getOrDefault(xAttribute, Optional.empty());
Optional<Object> yValue = chartAttributeToValue.getOrDefault(yAttribute, Optional.empty());
Optional<Object> oValue = chartAttributeToValue.getOrDefault(OPEN_PROPERTY, Optional.empty());
Optional<Object> lValue = chartAttributeToValue.getOrDefault(LOW_PROPERTY, Optional.empty());
Optional<Object> hValue = chartAttributeToValue.getOrDefault(HIGH_PROPERTY, Optional.empty());
Optional<Object> cValue = chartAttributeToValue.getOrDefault(CLOSE_PROPERTY, Optional.empty());
switch(mode) {
case ONLY_Y:
final Optional<Object> value = chartAttributeToValue.get(yAttribute);
addValue(data, value);
break;
case XY:
if (xValue.isPresent() && yValue.isPresent()) {
final ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
data.add(entryArray);
addValue(entryArray, xValue);
addValue(entryArray, yValue);
} else {
data.addNull();
}
break;
case XLH:
if (xValue.isPresent() && lValue.isPresent() && hValue.isPresent()) {
final ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
data.add(entryArray);
addValue(entryArray, xValue);
addValue(entryArray, lValue);
addValue(entryArray, hValue);
} else {
data.addNull();
}
break;
case XOHLC:
if (xValue.isPresent() && oValue.isPresent() && hValue.isPresent() && lValue.isPresent() && cValue.isPresent()) {
final ArrayNode entryArray = JsonNodeFactory.instance.arrayNode();
data.add(entryArray);
addValue(entryArray, xValue);
addValue(entryArray, oValue);
addValue(entryArray, hValue);
addValue(entryArray, lValue);
addValue(entryArray, cValue);
} else {
data.addNull();
}
break;
default:
// render as json object
final ObjectNode entryObject = JsonNodeFactory.instance.objectNode();
xValue.ifPresent(o -> addNamedValue(entryObject, xAttribute, xValue));
yValue.ifPresent(o -> addNamedValue(entryObject, yAttribute, yValue));
chartAttributeToValue.entrySet().stream().filter(e -> !e.getKey().equals(xAttribute)).filter(e -> !e.getKey().equals(yAttribute)).forEach(e -> addNamedValue(entryObject, e.getKey(), e.getValue()));
data.add(entryObject);
break;
}
}
return data;
}
Aggregations