use of org.eclipse.rap.chartjs.ChartStyle 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);
}
}
use of org.eclipse.rap.chartjs.ChartStyle in project rap by entirej.
the class EJRWTBarChartRecordBlockRenderer 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);
}
BarChartRowData chartRowData = new BarChartRowData(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;
*/
BarChartRowData.RowInfo info = new BarChartRowData.RowInfo();
String label = sItem.getProperties().getLabel();
if (label.trim().isEmpty()) {
label = sItem.getProperties().getReferencedItemName();
}
info.setLabel(label);
EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) sItem.getProperties();
String action = mainScreenItemProperties.getBlockRendererRequiredProperties().getStringProperty("action");
if (action == null || action.trim().isEmpty()) {
action = "select";
}
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.setAction(action);
info.setChartStyle(colors);
info.setHidden(!sItem.isVisible());
chartRowData.addRow(info, floatArray, styleArray);
// chartRowData.addRow(floatArray, colors);
}
if (horizontalBar)
_chartView.loadHorizontal(chartRowData, options);
else
_chartView.load(chartRowData, options);
}
}
use of org.eclipse.rap.chartjs.ChartStyle in project rap by entirej.
the class EJRWTPieChartRecordBlockRenderer method refresh.
public void refresh(Object input) {
if (_chartView != null && !_chartView.isDisposed()) {
Collection<EJDataRecord> records = (!multi) ? Arrays.asList(currentRecord == null ? getFirstRecord() : currentRecord) : _block.getRecords();
Collection<EJScreenItemController> screenItems = getScreenItems();
List<String> xlabel = new ArrayList<String>(screenItems.size());
for (EJScreenItemController sItem : screenItems) {
if (sItem.isSpacerItem())
continue;
xlabel.add(sItem.getProperties().getLabel());
}
PieChartRowData chartRowData = new PieChartRowData(xlabel.toArray(new String[0]));
for (EJDataRecord ejDataRecord : records) {
if (ejDataRecord == null)
continue;
Object lbl = labelColumn != null ? ejDataRecord.getValue(labelColumn) : "";
PieChartRowData.RowInfo rowInfo = new RowInfo();
rowInfo.setLabel(lbl != null ? lbl.toString() : "");
boolean[] hidden = new boolean[screenItems.size()];
ChartStyle[] styles = new ChartStyle[screenItems.size()];
double[] data = new double[screenItems.size()];
int[] widths = new int[screenItems.size()];
int index = 0;
for (EJScreenItemController sItem : screenItems) {
ChartStyle colors = new ChartStyle(220, 220, 220, 0.8f);
EJCoreVisualAttributeProperties attributeProperties = sItem.getItemRenderer().getVisualAttributeProperties();
EJCoreVisualAttributeProperties visualAttribute = ejDataRecord.getItem(sItem.getName()).getVisualAttribute();
if (visualAttribute != null) {
attributeProperties = visualAttribute;
}
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()));
}
}
EJCoreMainScreenItemProperties mainScreenItemProperties = (EJCoreMainScreenItemProperties) sItem.getProperties();
styles[index] = (colors);
hidden[index] = (!sItem.isVisible());
widths[index] = (mainScreenItemProperties.getBlockRendererRequiredProperties().getIntProperty(LINE_WIDTH, 1));
Object yvalue = ejDataRecord.getValue(sItem.getName());
double val = 0;
if (yvalue instanceof Number) {
val = ((Number) yvalue).doubleValue();
}
data[index] = (val);
index++;
}
// rowInfo.setHidden(hidden);
rowInfo.setChartStyle(styles);
rowInfo.setBorderWidth(widths);
rowInfo.setAction("_pie_select");
chartRowData.addRow(rowInfo, data);
}
_chartView.load(chartRowData, options);
}
}
Aggregations