use of org.eclipse.rap.chartjs.line.LineChartRowData in project rap by entirej.
the class EJRWTLineChartRecordBlockRenderer method refresh.
public void refresh(Object input) {
if (_chartView != null && !_chartView.isDisposed()) {
if (xAxisColumn == null && xAxisColumn.isEmpty()) {
return;
}
Map<Object, Map<String, Float>> dataset = new HashMap<Object, Map<String, Float>>();
Map<Object, Map<String, EJCoreVisualAttributeProperties>> datasetVa = new HashMap<Object, Map<String, EJCoreVisualAttributeProperties>>();
Collection<EJDataRecord> records = _block.getRecords();
Collection<EJScreenItemController> screenItems = getScreenItems();
List<Object> labelsIndex = new ArrayList<Object>();
Map<String, Number> lastVal = new HashMap<String, Number>();
for (EJDataRecord ejDataRecord : records) {
Object xobject = ejDataRecord.getValue(xAxisColumn);
if (xobject != null) {
Map<String, Float> set = dataset.get(xobject);
Map<String, EJCoreVisualAttributeProperties> setVa = datasetVa.get(xobject);
if (set == null) {
set = new HashMap<String, Float>();
setVa = new HashMap<String, EJCoreVisualAttributeProperties>();
dataset.put(xobject, set);
datasetVa.put(xobject, setVa);
labelsIndex.add(xobject);
}
for (EJScreenItemController sItem : screenItems) {
if (!sItem.isSpacerItem()) {
Object yvalue = ejDataRecord.getValue(sItem.getName());
Float val = null;
if (yvalue instanceof Number) {
lastVal.put(sItem.getName(), (Number) yvalue);
val = ((Number) yvalue).floatValue();
} else {
Number last = lastVal.get(sItem.getName());
val = last != null ? last.floatValue() : 0f;
}
set.put(sItem.getName(), val);
EJCoreVisualAttributeProperties visualAttribute = ejDataRecord.getItem(sItem.getName()).getVisualAttribute();
if (visualAttribute == null)
visualAttribute = sItem.getItemRenderer().getVisualAttributeProperties();
setVa.put(sItem.getName(), visualAttribute);
}
}
}
}
List<String> xlabel = new ArrayList<String>(labelsIndex.size());
for (Object object : labelsIndex) {
String xvalue;
xvalue = getStrValue(object);
xlabel.add(xvalue);
}
LineChartRowData chartRowData = new LineChartRowData(xlabel.toArray(new String[0]));
for (EJScreenItemController sItem : screenItems) {
if (sItem.isSpacerItem())
continue;
List<Float> row = new ArrayList<Float>();
List<EJCoreVisualAttributeProperties> rowVa = new ArrayList<EJCoreVisualAttributeProperties>();
for (Object object : labelsIndex) {
Map<String, Float> map = dataset.get(object);
Map<String, EJCoreVisualAttributeProperties> mapVa = datasetVa.get(object);
if (map == null || mapVa == null)
continue;
row.add(map.get(sItem.getName()));
rowVa.add(mapVa.get(sItem.getName()));
}
float[] floatArray = new float[row.size()];
ChartStyle[] styleArray = new ChartStyle[row.size()];
int i = 0;
for (Float f : row) {
floatArray[i] = (f != null ? f : 0);
ChartStyle colors = new ChartStyle(220, 220, 220, 0.8f);
EJCoreVisualAttributeProperties attributeProperties = rowVa.get(i);
if (attributeProperties != null) {
if (attributeProperties.getForegroundColor() != null) {
Color color = attributeProperties.getForegroundColor();
colors = new ChartStyle(color.getRed(), color.getGreen(), color.getBlue(), 0.8f);
}
if (attributeProperties.getBackgroundColor() != null) {
Color color = attributeProperties.getBackgroundColor();
colors.setFillColor(new RGB(color.getRed(), color.getGreen(), color.getBlue()));
}
}
styleArray[i] = colors;
i++;
}
/*
* String pointStyle = "circle";
*
* ChartStyle chartStyle;
*/
LineChartRowData.RowInfo info = new LineChartRowData.RowInfo();
String label = sItem.getProperties().getLabel();
if (label.trim().isEmpty()) {
label = sItem.getProperties().getReferencedItemName();
}
ChartStyle colors = new ChartStyle(220, 220, 220, 0.8f);
EJCoreVisualAttributeProperties attributeProperties = sItem.getItemRenderer().getVisualAttributeProperties();
if (attributeProperties != null) {
if (attributeProperties.getForegroundColor() != null) {
Color color = attributeProperties.getForegroundColor();
colors = new ChartStyle(color.getRed(), color.getGreen(), color.getBlue(), 0.8f);
}
if (attributeProperties.getBackgroundColor() != null) {
Color color = attributeProperties.getBackgroundColor();
colors.setFillColor(new RGB(color.getRed(), color.getGreen(), color.getBlue()));
}
}
info.setLabel(label);
info.setChartStyle(colors);
info.setHidden(!sItem.isVisible());
EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) sItem.getProperties();
info.setFill(mainScreenItemProperties.getBlockRendererRequiredProperties().getBooleanProperty(SHOW_FILL, info.isFill()));
String action = mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty("action");
if (action == null || action.trim().isEmpty()) {
action = "select";
}
info.setAction(action);
info.setPointStyle(mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty(POINT_STYLE));
info.setShowLine(mainScreenItemProperties.getBlockRendererRequiredProperties().getBooleanProperty(SHOW_LINE, info.isShowLine()));
info.setLineWidth(mainScreenItemProperties.getBlockRendererRequiredProperties().getIntProperty(LINE_WIDTH, info.getLineWidth()));
info.setLineTension(mainScreenItemProperties.getBlockRendererRequiredProperties().getFloatProperty(LINE_TENSION, (float) info.getLineTension()));
info.setSteppedLine(mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty(STEPPED_LINE));
chartRowData.addRow(info, floatArray, styleArray);
// chartRowData.addRow(floatArray, colors);
}
_chartView.load(chartRowData, options);
}
}
Aggregations