]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/src/org/simantics/charts/query/ChartDataQuery.java
Merge "View for used SCL expressions"
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / query / ChartDataQuery.java
1 package org.simantics.charts.query;
2
3 import java.util.Arrays;
4
5 import org.simantics.charts.ontology.ChartResource;
6 import org.simantics.charts.ui.ChartData;
7 import org.simantics.charts.ui.ChartData.ItemKey;
8 import org.simantics.databoard.Bindings;
9 import org.simantics.db.ReadGraph;
10 import org.simantics.db.Resource;
11 import org.simantics.db.common.NamedResource;
12 import org.simantics.db.common.request.ObjectsWithType;
13 import org.simantics.db.common.request.ResourceRead;
14 import org.simantics.db.exception.DatabaseException;
15 import org.simantics.layer0.Layer0;
16 import org.simantics.trend.configuration.TrendItem;
17 import org.simantics.trend.configuration.YAxisMode;
18
19 public class ChartDataQuery extends ResourceRead<ChartData> {
20
21     public ChartDataQuery(Resource resource) {
22         super(resource);
23     }
24
25     @Override
26     public ChartData perform(ReadGraph g) throws DatabaseException {
27         Resource chart = resource;
28         ChartData data = new ChartData();
29
30         Layer0 L0 = Layer0.getInstance(g);
31         ChartResource CHART = ChartResource.getInstance(g);
32
33         data.name = g.getPossibleRelatedValue(chart, L0.HasName, Bindings.STRING);
34
35         Resource am = g.getPossibleObject(chart, CHART.Chart_YAxisMode);
36         if ( CHART.YAxisMode_SingleAxis.equals(am) ) data.axisMode = YAxisMode.SingleAxis;
37         else if ( CHART.YAxisMode_MultiAxis.equals(am) ) data.axisMode = YAxisMode.MultiAxis;
38         else {
39             data.axisMode = YAxisMode.SingleAxis;
40         }
41
42         Double increment = g.getPossibleRelatedAdapter(chart, CHART.Chart_TimeWindowIncrement, Double.class);
43         if ( increment!=null ) data.timeIncrement = increment;
44         Double length = g.getPossibleRelatedAdapter(chart, CHART.Chart_TimeWindowLength, Double.class);
45         if ( length !=null ) data.timeLength = length;
46         Double start = g.getPossibleRelatedAdapter(chart, CHART.Chart_TimeWindowStart, Double.class);
47         if ( start!=null ) data.timeStart = start;
48
49         Boolean showMilestones = g.getPossibleRelatedValue(chart, CHART.Chart_ShowMilestones, Bindings.BOOLEAN);
50         if ( showMilestones!=null ) data.showMilestones = showMilestones;
51         Boolean showGrid = g.getPossibleRelatedValue(chart, CHART.Chart_showGrid, Bindings.BOOLEAN);
52         if ( showGrid!=null ) data.showGrid = showGrid;
53         Boolean trackExperimentTime = g.getPossibleRelatedValue(chart, CHART.Chart_trackExperimentTime, Bindings.BOOLEAN);
54         if ( trackExperimentTime!=null ) data.trackExperimentTime = trackExperimentTime;
55
56         for (Resource chartItem : g.syncRequest(new ObjectsWithType(chart, L0.ConsistsOf, CHART.Chart_Item))) {
57             TrendItem ti = g.syncRequest(new TrendItemQuery(chartItem));
58             NamedResource nr = new NamedResource(ti.label, chartItem);
59             ItemKey key = new ItemKey(ti.renderer, ti.index, nr);
60             data.allItems.put(key, ti);
61             Boolean hidden = g.getPossibleRelatedValue(chartItem, CHART.Chart_Item_hidden, Bindings.BOOLEAN);
62             if (Boolean.TRUE.equals(hidden))
63                 data.hiddenItems.add(key);
64         }
65
66         float[] bgColor = g.getPossibleRelatedValue(chart, CHART.Chart_backgroundColor, Bindings.FLOAT_ARRAY);
67         if (bgColor != null && bgColor.length >= 3) {
68             int len = bgColor.length;
69             if (len >= 6) {
70                 data.backgroundGradient = true;
71                 data.backgroundColor1 = Arrays.copyOfRange(bgColor, 0, 3);
72                 data.backgroundColor2 = Arrays.copyOfRange(bgColor, 3, 6);
73             } else if (len >= 3) {
74                 data.backgroundGradient = false;
75                 data.backgroundColor1 = Arrays.copyOfRange(bgColor, 0, 3);
76                 data.backgroundColor2 = data.backgroundColor1;
77             }
78         }
79
80         float[] gridColor = g.getPossibleRelatedValue(chart, CHART.Chart_gridColor, Bindings.FLOAT_ARRAY);
81         if (gridColor != null && gridColor.length >= 3) {
82             data.gridColor = gridColor;
83         }
84
85         return data;
86     }
87
88 }