Search in sources :

Example 1 with RowInfo

use of org.eclipse.rap.chartjs.pie.PieChartRowData.RowInfo 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);
    }
}
Also used : Color(java.awt.Color) ArrayList(java.util.ArrayList) EJCoreMainScreenItemProperties(org.entirej.framework.core.properties.EJCoreMainScreenItemProperties) ChartStyle(org.eclipse.rap.chartjs.ChartStyle) RGB(org.eclipse.swt.graphics.RGB) RowInfo(org.eclipse.rap.chartjs.pie.PieChartRowData.RowInfo) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) RowInfo(org.eclipse.rap.chartjs.pie.PieChartRowData.RowInfo) JsonObject(org.eclipse.rap.json.JsonObject) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) PieChartRowData(org.eclipse.rap.chartjs.pie.PieChartRowData) EJCoreVisualAttributeProperties(org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)

Aggregations

Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 ChartStyle (org.eclipse.rap.chartjs.ChartStyle)1 PieChartRowData (org.eclipse.rap.chartjs.pie.PieChartRowData)1 RowInfo (org.eclipse.rap.chartjs.pie.PieChartRowData.RowInfo)1 JsonObject (org.eclipse.rap.json.JsonObject)1 RGB (org.eclipse.swt.graphics.RGB)1 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)1 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)1 EJCoreMainScreenItemProperties (org.entirej.framework.core.properties.EJCoreMainScreenItemProperties)1 EJCoreVisualAttributeProperties (org.entirej.framework.core.properties.EJCoreVisualAttributeProperties)1