forked from hpcc-systems/Visualizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVisualizer.ecl
374 lines (321 loc) · 19.6 KB
/
Visualizer.ecl
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
EXPORT Visualizer := MODULE
IMPORT Std;
EXPORT Bundle := MODULE(Std.BundleBase)
EXPORT Name := 'Visualizer';
EXPORT Description := 'ECL Visualization Bundle';
EXPORT Authors := ['HPCC Systems'];
EXPORT License := 'http://www.apache.org/licenses/LICENSE-2.0';
EXPORT Copyright := 'Copyright (C) 2016 HPCC Systems';
EXPORT DependsOn := [];
EXPORT Version := '1.0.0';
END;
EXPORT KeyValueDef := RECORD
STRING key;
STRING value
END;
SHARED NullKeyValue := DATASET([], KeyValueDef);
EXPORT FiltersDef := RECORD
STRING source;
DATASET(KeyValueDef) mappings;
END;
SHARED NullFilters := DATASET([], FiltersDef);
/**
* Meta - Outputs visualization meta information
*
* Creates a "special" output file, containing the meta information for
* the visualization.
*
* @param _classID Visualization Type
* @param _id Visualization ID
* @param _dataSource Location of result (WU, Logical File, Roxie)
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
**/
EXPORT Meta(STRING _classID, STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
MetaDef := RECORD
STRING classid;
STRING datasource;
STRING resultname;
DATASET(KeyValueDef) mappings;
DATASET(FiltersDef) filteredby;
DATASET(KeyValueDef) properties;
END;
id := IF(_id = '', _outputName, _id);
ds := DATASET([{_classID, _dataSource, _outputName, _mappings, _filteredBy, _properties}], MetaDef);
RETURN OUTPUT(ds, NAMED(id + '__hpcc_visualization'));
END;
/* -----------------------------------------------------------------------
*/
EXPORT Any := MODULE
/**
* Grid - Renders data in a data grid / table
*
* mappings can be used to limit / rename the columns.
*
* @param _id Visualization ID
* @param _dataSource Location of result (WU, Logical File, Roxie), defaults to current WU
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
* @see Common/Meta
**/
EXPORT Grid(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('other_Table', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT HandsonGrid(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('handson_Table', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT __test := FUNCTION
ds := DATASET([ {'English', 5, 43, 41, 92},
{'History', 17, 43, 83, 93},
{'Geography', 7, 45, 52, 83},
{'Chemistry', 16, 73, 52, 83},
{'Spanish', 26, 83, 11, 72},
{'Bioligy', 66, 60, 85, 6},
{'Physics', 46, 20, 53, 7},
{'Math', 98, 30, 23, 13}],
{STRING subject, INTEGER4 year1, INTEGER4 year2, INTEGER4 year3, INTEGER4 year4});
data_exams := OUTPUT(ds, NAMED('ChartAny__test'));
viz_grid := Grid('grid',, 'ChartAny__test');
viz_grid2 := HandsonGrid('handsonGrid',, 'ChartAny__test', DATASET([{'Subject', 'subject'}, {'2013', 'year3'}, {'2014', 'year4'}], KeyValueDef), , DATASET([{'fixedColumn', true}], KeyValueDef));
RETURN PARALLEL(data_exams, viz_grid, viz_grid2);
END;
END;
/* -----------------------------------------------------------------------
Two Dimensional Visualizations
Default Data requirements (can be overriden by mappings):
* 2 Columns
- Column 1 (string): Label
- Column 2 (number): Value
All other columns will be ignored. See __test for an example.
*/
EXPORT TwoD := MODULE
/**
* Bubble - Renders data in a data grid / table
*
* mappings can be used to limit / rename the columns.
*
* @param _id Visualization ID
* @param _dataSource Location of result (WU, Logical File, Roxie), defaults to current WU
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
* @see Common/Meta
**/
EXPORT Bubble(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Bubble', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Pie(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Pie', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Summary(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
_props2 := DATASET([{'playInterval', 3000}], KeyValueDef) + _properties;
RETURN Meta('chart_Summary', _id, _dataSource, _outputName, , _filteredBy, _props2);
END;
EXPORT WordCloud(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('other_WordCloud', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT __test := FUNCTION
ds := DATASET([ {'English', 5},
{'History', 17},
{'Geography', 7},
{'Chemistry', 16},
{'Irish', 26},
{'Spanish', 67},
{'Bioligy', 66},
{'Physics', 46},
{'Math', 98}],
{STRING subject, INTEGER4 year});
data_exams := OUTPUT(ds, NAMED('TwoD__test'));
viz_bubble := Bubble('bubble',, 'TwoD__test');
viz_pie := Pie('pie',, 'TwoD__test');
viz_summary := Summary('summary',, 'TwoD__test');
viz_wordCloud := WordCloud('wordCloud',, 'TwoD__test');
RETURN PARALLEL(data_exams, viz_bubble, viz_pie, viz_summary, viz_wordCloud);
END;
END;
/* -----------------------------------------------------------------------
Multi Dimensional Visualizations
Data requirements (can be overriden by mappings):
* N Columns
- Column 1 (string): Label
- Column 2 (number): Value
- Column 3 (number): Value
...
- Column N (number): Value
See __Test for an example.
*/
EXPORT MultiD := MODULE
/**
* Area - Renders data in a XY Axis chart
*
* mappings can be used to limit / rename the columns.
*
* @param _id Visualization ID
* @param _dataSource Location of result (WU, Logical File, Roxie), defaults to current WU
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
* @see Common/Meta
**/
EXPORT Area(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Area', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Bar(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Bar', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Column(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Column', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT HexBin(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_HexBin', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Line(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Line', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Scatter(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Scatter', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT Step(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('chart_Step', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT __test := FUNCTION
ds := DATASET([ {'English', 5, 43, 41, 92},
{'History', 17, 43, 83, 93},
{'Geography', 7, 45, 52, 83},
{'Chemistry', 16, 73, 52, 83},
{'Spanish', 26, 83, 11, 72},
{'Bioligy', 66, 60, 85, 6},
{'Physics', 46, 20, 53, 7},
{'Math', 98, 30, 23, 13}],
{STRING subject, INTEGER4 year1, INTEGER4 year2, INTEGER4 year3, INTEGER4 year4});
data_exams := OUTPUT(ds, NAMED('MultiD__test'));
viz_area := Area('area',, 'MultiD__test');
viz_bar := Bar('bar',, 'MultiD__test');
viz_column := Column('column',, 'MultiD__test');
viz_hexBin := HexBin('hexBin',, 'MultiD__test');
viz_line := Line('line',, 'MultiD__test');
viz_scatter := Scatter('scatter',, 'MultiD__test');
viz_step := Step('step',, 'MultiD__test');
RETURN PARALLEL(data_exams, viz_area, viz_bar, viz_column, viz_hexBin, viz_line, viz_scatter, viz_step);
END;
END;
/* -----------------------------------------------------------------------
Geo Spatial Visualizations
Data requirements (can be overriden by mappings):
* 2 Columns
- Column 1 (string): location ID (depends on geo spatial type)
- Column 2 (number): Value
See __Test for an example.
*/
EXPORT Choropleth := MODULE
/**
* USStates - US States Choropleth
*
* Data requirements (can be overriden by mappings):
* * 2 Columns
* - Column 1 (string): State 2 letter code
* - Column 2 (number): Value
*
* @param _id Visualization ID
* @param _dataSource Location of result (WU, Logical File, Roxie), defaults to current WU
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
* @see Common/Meta
**/
EXPORT USStates(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('map_ChoroplethStates', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
/**
* USCounties - US States Choropleth
*
* Data requirements (can be overriden by mappings):
* * 2 Columns
* - Column 1 (number): FIPS code
* - Column 2 (number): Value
*
* @param _id Visualization ID
* @param _dataSource Location of result (WU, Logical File, Roxie), defaults to current WU
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
* @see Common/Meta
**/
EXPORT USCounties(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Meta('map_ChoroplethCounties', _id, _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
/**
* Euro - US States Choropleth
*
* Data requirements (can be overriden by mappings):
* * 2 Columns
* - Column 1 (number): Administration name
* - Column 2 (number): Value
*
* @param _id Visualization ID
* @param _region 2 Letter Euro Code (GB, IE etc.)
* @param _dataSource Location of result (WU, Logical File, Roxie), defaults to current WU
* @param _outputName Result name (ignored for Logical Files)
* @param _mappings Maps Column Name <--> field ID
* @param _filteredBy Specifies filter condition
* @param _properties User specified dermatology properties
* @return A "meta" output describing the visualization
* @see Common/Meta
**/
EXPORT Euro(STRING _id, STRING _region, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
_props2 := DATASET([{'region', _region}], KeyValueDef) + _properties;
RETURN Meta('map_TopoJSONChoropleth', _id, _dataSource, _outputName, _mappings, _filteredBy, _props2);
END;
EXPORT EuroIE(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Euro(_id, 'IE', _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
EXPORT EuroGB(STRING _id, STRING _dataSource = '', STRING _outputName = '', DATASET(KeyValueDef) _mappings = NullKeyValue, DATASET(FiltersDef) _filteredBy = NullFilters, DATASET(KeyValueDef) _properties = NullKeyValue) := FUNCTION
RETURN Euro(_id, 'GB', _dataSource, _outputName, _mappings, _filteredBy, _properties);
END;
SHARED __testData := FUNCTION
_usStates := DATASET([ {'AL', 4779736},
{'AK', 710231},
{'AZ', 6392017},
{'AR', 2915918}],
{STRING State, INTEGER4 weight});
data_usStates := OUTPUT(_usStates, NAMED('choro_usStates'));
_usCounties := DATASET([ {1073,29.946185501741},
{1097,0.79566003616637},
{1117,1.5223596574691},
{4005,27.311773623042}],
{STRING FIPS, INTEGER4 weight});
data_usCounties := OUTPUT(_usCounties, NAMED('choro_usCounties'));
_euroIE := DATASET([ {'Carlow', '27431', '27181', '54612'},
{'Dublin City', '257303', '270309', '527612'},
{'Kilkenny', '47788', '47631', '95419'},
{'Cork', '198658', '201144', '399802'}],
{STRING region, INTEGER4 males, INTEGER4 females, INTEGER4 total});
data_euroIE := OUTPUT(_euroIE, NAMED('choro_euroIE'));
RETURN PARALLEL(data_usStates, data_usCounties, data_euroIE);
END;
EXPORT __test := FUNCTION
viz_usstates := USStates('usStates',, 'choro_usStates');
viz_uscounties := USCounties('usCounties',, 'choro_usCounties');
viz_euroIE := EuroIE('euroIE',, 'choro_euroIE', DATASET([{'County', 'region'}, {'Population', 'total'}], KeyValueDef),, DATASET([{'paletteID', 'Greens'}], KeyValueDef));
viz_euroGB := EuroGB('euroGB');
RETURN PARALLEL(__testData, viz_usstates, viz_uscounties, viz_euroIE, viz_euroGB);
END;
END;
EXPORT main := FUNCTION
RETURN PARALLEL(Any.__test, TwoD.__test, MultiD.__test, Choropleth.__test);
END;
END;