-
Notifications
You must be signed in to change notification settings - Fork 1
/
GoogleChart.sbi
253 lines (192 loc) · 6.88 KB
/
GoogleChart.sbi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
DeclareModule GoogleChart
EnableExplicit
; ChartTypes:
#ChartTypeAnnotation = "AnnotationChart"
#ChartTypeArea = "AreaChart"
#ChartTypeBar = "BarChart"
#ChartTypeBubble = "BubbleChart"
#ChartTypeCandleStick = "CandlestickChart"
#ChartTypeCalendar = "Calendar"
#ChartTypeColumn = "ColumnChart"
#ChartTypeCombo = "ComboChart"
#ChartTypeGantt = "Gantt"
#ChartTypeGauge = "Gauge"
#ChartTypeGeo = "GeoChart"
#ChartTypeHistogram = "Histogram"
#ChartTypeLine = "LineChart"
#ChartTypeMap = "Map"
#ChartTypeOrg = "OrgChart"
#ChartTypePie = "PieChart"
#ChartTypeSankey = "Sankey"
#ChartTypeScatter = "ScatterChart"
#ChartTypeSteppedArea = "SteppedAreaChart"
#ChartTypeTable = "Table"
#ChartTypeTimeline = "Timeline"
#ChartTypeTreeMap = "TreeMap"
#ChartTypeWordTree = "WordTree"
EnumerationBinary ; EventTypes
; Table
#EventType_Select = 1
#EventType_Page
#EventType_Sort
#EventType_Ready
#EventType_Error
EndEnumeration
Enumeration
#ChartOptions
#ChartData
#ChartDataTable
#ChartQuery
EndEnumeration
Global IsInitialized
Declare Init(Callback, Packages = 0)
Declare BindGadget(Gadget, ChartType.s = #ChartTypeLine)
Declare GetChartGadgetAttribute(Gadget, Attribute)
Declare SetChartGadgetAttribute(Gadget, Attribute, Value)
Declare BindChartGadgetEvent(Gadget, Callback, EventType = #PB_All)
Declare GetChartGadgetState(Gadget)
Declare NewDataTable()
Declare.s GetChartGadgetItemText(Gadget, Position, Column = 0)
Declare DataTableAddColumn(DataTable, Text.s, Type.s="string")
Declare DataTableAddRow(DataTable, JsArray)
Declare ClearDataTable(Gadget)
Declare Refresh(Gadget)
EndDeclareModule
Module GoogleChart
EnableExplicit
Macro GetSelector
! var selector = $(spider_GadgetID(v_gadget).div).find('.dijitContentPane');
EndMacro
Macro GetChart
GetSelector
! var chart = selector.data("GoogleChart");
EndMacro
Procedure Init(Callback, Packages = 0)
! require(["https://www.gstatic.com/charts/loader.js"],
! function() {
IsInitialized = #True
! google.charts.load('current', { packages : v_packages } );
! google.charts.setOnLoadCallback(v_callback);
! });
EndProcedure
Procedure BindGadget(Gadget, ChartType.s = #ChartTypeLine)
GetSelector
! var chart = new google.visualization.ChartWrapper ({
! chartType: v_charttype,
! containerId: selector[0].id
! });
! chart.setOptions( {} );
! chart.setDataTable( [] );
! spider.DojoAspect.after(dijit.byId(spider_GadgetID(v_gadget).gadget.id), "resize", function() {
! chart.draw();
! });
! selector.data("GoogleChart", chart);
! chart.draw();
EndProcedure
Procedure SetChartGadgetAttribute(Gadget, Attribute, Value)
GetChart
Select Attribute
Case #ChartData
! chart.setDataTable(google.visualization.arrayToDataTable(v_value));
Case #ChartDataTable
! chart.setDataTable(v_value);
Case #ChartOptions
; ! chart.setOptions($.extend(v_value, chart.getOptions()));
! chart.setOptions($.extend({}, chart.getOptions(), v_value));
Case #ChartQuery
! chart.setQuery(v_value);
EndSelect
! chart.draw();
EndProcedure
Procedure GetChartGadgetAttribute(Gadget, Attribute)
GetChart
Select Attribute
Case #ChartDataTable
! return chart.getDataTable();
Case #ChartOptions
! return chart.getOptions();
Case #ChartQuery
! return chart.getQuery();
EndSelect
! chart.draw();
EndProcedure
Procedure _BindChartGadgetEvent(chart, event.s, etype, etypes, gadget, callback)
If etypes & etype = etype
! google.visualization.events.addListener(v_chart, v_event, function(e) {
! spider.event.eventObject = v_gadget;
! spider.event.eventType = v_etype;
! v_callback(e);
! });
EndIf
EndProcedure
Procedure BindChartGadgetEvent(Gadget, Callback, EventType = #PB_All)
; Table-Events:
;
; select // Standard select event, but only entire rows can be selected.
; // Properties: None
;
; page // Triggered when users click on a page navigation button.
; // Properties: page: Number. The index of page to navigate to.
;
; sort // Triggered when users click on a column header, and the sort option is not 'disable'.
; // Properties: An object with the following properties:
; // column - (number) Index of the column by which the table is sorted.
; // ascending - (boolean) true if the sort is ascending, false if descending.
; // sortedIndexes - (numeric array) Array of numbers, wherethe index in the array is the row number as sorted (in the visible table), and the value is the index of that row in the underlying (unsorted) data table.
;
; ready // The chart is ready for external method calls. If you want to interact with the chart, and call methods after you draw it, you should set up a listener for this event before you call the draw method, and call them only after the event was fired.
; // Properties: None
If EventType = #PB_All
EventType = #EventType_Select |
#EventType_Page |
#EventType_Sort |
#EventType_Ready |
#EventType_Error
EndIf
Protected chart
GetSelector
! v_chart = selector.data("GoogleChart");
_BindChartGadgetEvent(chart, "select", #EventType_Select, EventType, Gadget, Callback)
_BindChartGadgetEvent(chart, "page", #EventType_Page, EventType, Gadget, Callback)
_BindChartGadgetEvent(chart, "sort", #EventType_Sort, EventType, Gadget, Callback)
_BindChartGadgetEvent(chart, "ready", #EventType_Ready, EventType, Gadget, Callback)
_BindChartGadgetEvent(chart, "error", #EventType_Error, EventType, Gadget, Callback)
EndProcedure
Procedure GetChartGadgetState(Gadget)
GetChart
! if (chart.getChart().getSelection()[0]) return chart.getChart().getSelection()[0].row;
! return -1;
EndProcedure
Procedure.s GetChartGadgetItemText(Gadget, Position, Column = 0)
GetChart
! var dt = chart.getDataTable();
! return dt.getValue(v_position, v_column);
EndProcedure
Procedure NewDataTable()
! return new google.visualization.DataTable();
EndProcedure
Procedure DataTableAddColumn(DataTable, Text.s, Type.s="string")
! v_datatable.addColumn(v_type, v_text);
EndProcedure
Procedure DataTableAddRow(DataTable, JsArray)
! v_datatable.addRow(v_jsarray);
EndProcedure
Procedure ClearDataTable(Gadget)
GetChart
! var dt = chart.getDataTable();
! dt.removeRows(0, dt.getNumberOfRows());
! chart.draw();
EndProcedure
Procedure Refresh(Gadget)
GetChart
! chart.draw();
EndProcedure
EndModule
; IDE Options = SpiderBasic 2.10 (Windows - x86)
; CursorPosition = 243
; FirstLine = 187
; Folding = ----
; iOSAppOrientation = 0
; AndroidAppOrientation = 0
; EnableXP
; CompileSourceDirectory