]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.charts/scl/Simantics/Chart.scl
efbe3143f27103a0b810e7044ac04e0d2d763855
[simantics/platform.git] / bundles / org.simantics.charts / scl / Simantics / Chart.scl
1 import "Simantics/DB"
2 import "Simantics/Variables"
3 import "Simantics/Model"
4 import "Simantics/Entity"
5 import "Simantics/Subscription"
6
7 import "http://www.simantics.org/Charts-1.2" as CHART
8
9 type Chart = Resource
10 type ChartGroup = Resource
11 type ChartItem = Resource
12
13 importJava "org.simantics.charts.ui.SCLChart" where
14     @JavaName createNewChart
15     """
16     Creates a new Chart to the default Charts folder under the given Model parameter. Returns the created Chart.
17     """
18     createChart :: Model -> <Proc> Chart
19
20     @JavaName createNewChart
21     """
22     Creates a new Chart under the given ChartGroup parameter. Returns the created Chart.
23     """
24     createChartInGroup :: ChartGroup -> <Proc> Chart
25
26     @JavaName createNewChartGroup
27     """
28     Creates a new ChartGroup under the given Model parameter. Returns the created ChartGroup.
29     """
30     createChartGroup :: Model -> <Proc> ChartGroup
31
32     @JavaName addChartItems
33     """
34     Creates new chartItem with the given Variable to the given Chart and returns the created ChartItem. New Subscription item is created at the same time.
35     """
36     addChartItems :: Chart -> Variable -> <WriteGraph> ChartItem 
37
38     @JavaName linkSubToChart
39     """
40     Links the given Subscription to the given chart and returns the created ChartItem.
41     """
42     linkSubToChart :: Subscription -> Chart -> <WriteGraph> ChartItem
43
44 """
45 Browses the given Model for its Charts and then returns them in a list.
46 """
47 chartsOf :: Model -> <ReadGraph> [Chart]
48 chartsOf model = recurse (toResource model)
49   where
50     recurse r = do
51         cs = resourceChildrenOf r 
52         charts = map fromResource $ filter isChart cs
53         chartGrp = filter isChartGroup cs
54         charts + concatMap recurse chartGrp
55     isChart r = isInstanceOf r CHART.TimeSeriesChart
56     isChartGroup r = isInstanceOf r CHART.ChartGroup