@datagrok/api-samples 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +1 -1
  2. package/package.json +16 -5
  3. package/scripts/dapi/projects.js +8 -0
  4. package/scripts/dapi/users.js +7 -0
  5. package/scripts/data-frame/construction/create-from-columns.js +4 -4
  6. package/scripts/data-frame/construction/export-to-csv-advanced.js +7 -0
  7. package/scripts/data-frame/construction/export-to-csv.js +2 -0
  8. package/scripts/data-frame/metadata/formula-lines.js +185 -0
  9. package/scripts/functions/calling.js +2 -2
  10. package/scripts/grid/advanced/cell-renderer.js +13 -0
  11. package/scripts/grid/advanced/charts-in-cells.js +30 -0
  12. package/scripts/grid/advanced/sparklines.js +4 -0
  13. package/scripts/grid/color-coding/color-coding.js +6 -1
  14. package/scripts/grid/grid-from-properties.js +14 -0
  15. package/scripts/grid/{html-dynamic-cells.js → html-cells/html-dynamic-cells.js} +0 -0
  16. package/scripts/grid/{html-markup-cells.js → html-cells/html-markup-cells.js} +0 -0
  17. package/scripts/grid/html-cells/html-table-cells.js +12 -0
  18. package/scripts/scripting/scripting.js +3 -3
  19. package/scripts/shell/last-error.js +11 -0
  20. package/scripts/ui/components/loading-indicators.js +24 -0
  21. package/scripts/ui/components/menu.js +12 -1
  22. package/scripts/ui/components/property-grid.js +27 -0
  23. package/scripts/ui/components/tab-control.js +9 -6
  24. package/scripts/ui/components/tree-view-adv.js +9 -0
  25. package/scripts/ui/dialogs/wizard.js +15 -0
  26. package/scripts/ui/elements/inputs/inputs.js +1 -0
  27. package/scripts/ui/inputs/for-columns.js +4 -0
  28. package/scripts/ui/inputs/for-properties.js +40 -0
  29. package/scripts/ui/inputs/master-details.js +25 -0
  30. package/scripts/ui/viewers/advanced/default-axis-type.js +3 -0
  31. package/scripts/ui/viewers/create-viewers-dynamically.js +11 -0
  32. package/scripts/ui/viewers/filters/custom-filters.js +4 -0
  33. package/scripts/ui/viewers/filters/filter-group.js +7 -0
  34. package/scripts/ui/viewers/viewer-tooltips.js +5 -0
  35. package/scripts/ui/views/multi-view.js +16 -0
  36. package/scripts/ux/Dialogs/link-table-dlg.js +1 -0
  37. package/scripts/data-frame/metadata/shapes.js +0 -163
package/README.md CHANGED
@@ -18,7 +18,7 @@ Here are the directories of particular interest:
18
18
  * [grid](https://github.com/datagrok-ai/public/tree/master/packages/ApiSamples/scripts/grid)
19
19
  : directory with examples how to work with [table grid](https://datagrok.ai/help/visualize/viewers/grid)
20
20
  * [scripting](https://github.com/datagrok-ai/public/tree/master/packages/ApiSamples/scripts/scripting)
21
- : directory with examples how to use [scripting](https://datagrok.ai/help/develop/scripting)
21
+ : directory with examples how to use [scripting](https://datagrok.ai/help/compute/scripting)
22
22
  * [ui](https://github.com/datagrok-ai/public/tree/master/packages/ApiSamples/scripts/ui)
23
23
  : directory with ui manipulation examples
24
24
 
package/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "@datagrok/api-samples",
3
- "version": "1.0.1",
4
- "fullName": "Grok API Examples",
5
- "description": "Grok API Examples",
6
- "sources": [ ],
3
+ "version": "1.0.2",
4
+ "friendlyName": "API Samples",
5
+ "description": "API Samples",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/datagrok-ai/public.git",
9
+ "directory": "packages/ApiSamples"
10
+ },
11
+ "sources": [],
7
12
  "scripts": {
8
13
  "samples-upload": "datagrok-upload http://localhost:8082 deploy",
9
14
  "publish samples local": "grok publish local"
10
- }
15
+ },
16
+ "canEdit": [
17
+ "Developers"
18
+ ],
19
+ "canView": [
20
+ "All users"
21
+ ]
11
22
  }
@@ -0,0 +1,8 @@
1
+ let project = DG.Project.create();
2
+ let table = grok.data.demo.demog();
3
+ let tableInfo = table.getTableInfo();
4
+ project.addChild(tableInfo);
5
+
6
+ await grok.dapi.tables.uploadDataFrame(table);
7
+ await grok.dapi.tables.save(tableInfo);
8
+ await grok.dapi.projects.save(project);
@@ -0,0 +1,7 @@
1
+ let user = DG.User.create();
2
+ user.login = 'newlogin';
3
+ user.status = USER_STATUS.STATUS_NEW;
4
+ user.firstName = 'new';
5
+ user.lastName = 'user';
6
+
7
+ await grok.dapi.users.save(user);
@@ -1,10 +1,10 @@
1
1
  //tags: DataFrame, Column, construction
2
2
  // API References:
3
3
  //
4
- // https://datagrok.ai/js-api/classes/dg.columnlist
5
- // https://datagrok.ai/js-api/classes/dg.dataframe
6
- // https://datagrok.ai/js-api/classes/dg.column#.fromlist
7
- // https://datagrok.ai/js-api/classes/dg.column#.qnum
4
+ // https://datagrok.ai/js-api/classes/dg.ColumnList
5
+ // https://datagrok.ai/js-api/classes/dg.DataFrame
6
+ // https://datagrok.ai/js-api/classes/dg.Column#fromList
7
+ // https://datagrok.ai/js-api/classes/dg.Column#qnum
8
8
  //
9
9
  // Note that the "population" data type becomes int
10
10
 
@@ -0,0 +1,7 @@
1
+ let nums = ['>5', '6', '<7'];
2
+ let t = DG.DataFrame.fromColumns([
3
+ DG.Column.qnum('qnum', 3).init((i) => DG.Qnum.parse(nums[i]))
4
+ ]);
5
+
6
+ let csv = t.toCsv({qualifierAsColumn: true});
7
+ grok.shell.addTableView(DG.DataFrame.fromCsv(csv));
@@ -0,0 +1,2 @@
1
+ let t = grok.data.demo.demog(5);
2
+ console.log(t.toCsv({delimiter: ' - '}));
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Formula Lines.
3
+ * Documentation: https://datagrok.ai/help/develop/how-to/show-formula-lines
4
+ */
5
+
6
+ let demog = grok.data.demo.demog(100);
7
+
8
+ /**
9
+ * An example of adding a line with a complete set of parameters to the dataframe.
10
+ * Only one parameter ("formula") is required.
11
+ * All other parameters have their default values.
12
+ */
13
+ demog.meta.formulaLines.addLine({
14
+ title: 'Red Line', // Short title.
15
+ description: 'Description', // Detailed description.
16
+
17
+ // Formula for line.
18
+ // There should be one column to the left of the "=". And any formula using the second column on the right side.
19
+ // The formula uses syntax and formulas similar to the "Add New Column" form.
20
+ formula: '${height} = 0.69 * max($[weight])',
21
+
22
+ zIndex: -45, // Line depth. The viewer's chart has a depth of 0.
23
+ color: '#ff0000', // Line color.
24
+ visible: true, // Visibility.
25
+ opacity: 80, // Opacity [0..100], where 0 - invisible, 100 - opaque.
26
+
27
+ // Line boundaries along the value axis. In this example, the line will be drawn for a "Weight" between 50 and 300 kg.
28
+ min: 50,
29
+ max: 300,
30
+
31
+ // Parameters specific to Lines:
32
+ width: 2, // Line width in pixels.
33
+ spline: 0.9, // Smoothness of curve line [0..1], where 0 - no smoothing, 1 - max smoothing.
34
+ style: 'dashed' // Line style ('solid', 'dotted', 'dashed', 'longdash', 'dotdash').
35
+ });
36
+
37
+ /**
38
+ * An example of adding a band to the dataframe. Most of the parameters are the same as for lines.
39
+ * There are two required parameters here - "column" and "formula".
40
+ * All other parameters have their default values.
41
+ */
42
+ demog.meta.formulaLines.addBand({
43
+ title: 'My first Band', // Short title.
44
+ description: 'Band is a rectangle', // Detailed description.
45
+
46
+ // Band boundary formula.
47
+ // The formula can contain expressions of the form: "${colName} < 200", "${colName} > avg", "${colName} in(18, 60)", "${colName} in(q1, q3)".
48
+ // The numbers are specified in the units of the column. in this case in centimeters.
49
+ formula: '${height} in(175, 185)',
50
+
51
+ zIndex: -15, // Line depth. The viewer's chart has a depth of 0.
52
+ color: '#FFD700', // Band background color.
53
+ max: 160, // Maximum band size.
54
+ opacity: 100, // Opacity [0..100], where 0 - invisible, 100 - opaque.
55
+
56
+ // Parameters specific to Bands:
57
+ column2: 'weight' // Second column for which the band will be drawn.
58
+ });
59
+
60
+ demog.meta.formulaLines.addLine({
61
+ title: 'Blue Line',
62
+ formula: '${weight} = 180',
63
+ color: '#0000ff',
64
+ width: 4,
65
+ opacity: 50
66
+ });
67
+
68
+ demog.meta.formulaLines.addLine({
69
+ title: 'Y = X',
70
+ description: 'Some description',
71
+ formula: '${weight} = ${height}',
72
+ width: 1
73
+ });
74
+
75
+ demog.meta.formulaLines.addLine({
76
+ title: 'Parabola',
77
+ formula: '${height} = 180 + 0.01 * ${weight} * ${weight} - 1.5 * ${weight}',
78
+ zIndex: -30,
79
+ color: '#FFA500',
80
+ width: 2,
81
+ visible: true,
82
+ style: 'dotdash'
83
+ });
84
+
85
+ demog.meta.formulaLines.addLine({
86
+ title: 'Green Line',
87
+ formula: '${height} = 140 + ${weight} * 0',
88
+ zIndex: -20,
89
+ color: '#00ff00',
90
+ width: 6,
91
+ max: 200
92
+ });
93
+
94
+ demog.meta.formulaLines.addLine({
95
+ title: 'Sinusoid',
96
+ formula: '${height} = 90 + max($[age]) + 4 * sin(0.2 * ${weight} + 60)',
97
+ zIndex: -45,
98
+ color: '#00BFFF',
99
+ width: 3,
100
+ visible: true,
101
+ max: 200
102
+ });
103
+
104
+ demog.meta.formulaLines.addLine({
105
+ title: 'Hidden Line',
106
+ formula: '${height} = 2 * ${weight}',
107
+ zIndex: -45,
108
+ width: 1,
109
+ visible: false, // This line will not be displayed.
110
+ opacity: 80
111
+ });
112
+
113
+ demog.meta.formulaLines.addLine({
114
+ title: 'Circle Top',
115
+ description: 'Description of circle',
116
+ formula: '${height} = 181.2 + sqrt(pow(25, 2) - pow((${weight} - 108.75), 2)) * 0.34',
117
+ zIndex: -40,
118
+ color: '#5F9EA0',
119
+ width: 6
120
+ });
121
+
122
+ demog.meta.formulaLines.addLine({
123
+ title: 'Circle Bottom',
124
+ formula: '${height} = 178.8 - sqrt(pow(25, 2) - pow((${weight} - 108.75), 2)) * 0.34',
125
+ zIndex: -40,
126
+ color: '#5F9EA0',
127
+ width: 6
128
+ });
129
+
130
+ demog.meta.formulaLines.addLine({
131
+ title: 'X Top',
132
+ formula: '${height} = 115 + sqrt(pow(20, 2) - pow((${weight} - 188.95), 2)) * 1.0',
133
+ zIndex: -45,
134
+ color: '#228B22',
135
+ width: 4
136
+ });
137
+
138
+ demog.meta.formulaLines.addLine({
139
+ title: 'X Bottom',
140
+ formula: '${height} = 147 - sqrt(pow(20, 2) - pow((${weight} - 188.95), 2)) * 1.0',
141
+ zIndex: -45,
142
+ color: '#228B22',
143
+ width: 20,
144
+ style: 'dotted'
145
+ });
146
+
147
+ demog.meta.formulaLines.addBand({
148
+ title: 'Band 2',
149
+ description: 'Second band',
150
+ formula: '${weight} < 80',
151
+ column2: 'height',
152
+ zIndex: -45,
153
+ color: '#FFC0CB',
154
+ opacity: 30,
155
+ min: 130
156
+ });
157
+
158
+ demog.meta.formulaLines.addBand({
159
+ title: 'Band 3',
160
+ description: 'Another band',
161
+ formula: '${weight} > max',
162
+ column2: 'height',
163
+ zIndex: -45,
164
+ color: '#7FFFD4',
165
+ opacity: 30,
166
+ max: 160
167
+ });
168
+
169
+ let view = grok.shell.addTableView(demog);
170
+
171
+ let plot = view.scatterPlot({
172
+ x: 'weight',
173
+ y: 'height',
174
+ showDataframeFormulaLines: true, // Show all lines stored in the dataframe.
175
+ showViewerFormulaLines: true // Show all lines stored in the viewer.
176
+ });
177
+
178
+ /**
179
+ * An example of adding a line to the viewer.
180
+ */
181
+ plot.meta.formulaLines.addLine({
182
+ formula: '${weight} = 150',
183
+ color: '#ff0000',
184
+ width: 10
185
+ });
@@ -4,9 +4,9 @@
4
4
 
5
5
  // Calling "RDup" function that belongs to the "RSrcipts" package
6
6
  // It is implemented in R and returns a duplicated string
7
- // https://github.com/datagrok-ai/public/blob/master/packages/RScripts/scripts/r_dup.R
7
+ // https://github.com/datagrok-ai/public/blob/master/packages/DemoScripts/scripts/r/r_dup.R
8
8
  grok.functions
9
- .call("RScripts:RDup", {s: "Foo"})
9
+ .call("DemoScripts:RDup", {s: "Foo"})
10
10
  .then((res) => {
11
11
  grok.shell.info(res);
12
12
  });
@@ -0,0 +1,13 @@
1
+ // Reusing core grid renderers
2
+
3
+ let view = grok.shell.addTableView(grok.data.demo.molecules());
4
+ view.dataFrame.col('logD').colors.setLinear();
5
+ let canvas = ui.canvas(300, 200);
6
+
7
+ view.grid.onCurrentCellChanged.subscribe((gridCell) =>
8
+ gridCell.renderer.render(canvas.getContext('2d'), 20, 20, 200, 100, gridCell, gridCell.style));
9
+
10
+ ui.dialog()
11
+ .add('Click on a cell to render it in the canvas below')
12
+ .add(canvas)
13
+ .show();
@@ -0,0 +1,30 @@
1
+ let t = grok.data.demo.molecules(100);
2
+ t.columns.addNew('ic50', DG.TYPE.DATA_FRAME).init((i) => grok.data.demo.doseResponse());
3
+ t.columns.addNew('hist', DG.TYPE.DATA_FRAME).init((i) => t.col('ic50').get(i));
4
+ let tv = grok.shell.addTableView(t);
5
+
6
+ tv.grid.columns.byName('ic50').cellType = 'html';
7
+ tv.grid.columns.byName('hist').cellType = 'html';
8
+ tv.grid.columns.byName('ic50').width = 300;
9
+
10
+ const lineOptions = {
11
+ xColumnName: 'concentration [ug/ml]',
12
+ yColumnNames: ['viability [%]'],
13
+ splitColumnName: 'compound',
14
+ xAxisType: 'logarithmic',
15
+ style: 'dashboard',
16
+ showTopPanel: 'false',
17
+ showSplitSelector: 'false',
18
+ legendVisibility: 'Never',
19
+ showXAxis: 'false',
20
+ showYAxis: 'false',
21
+ showLegend: 'false'
22
+ };
23
+
24
+ tv.grid.setOptions({rowHeight: 200});
25
+ tv.grid.onCellPrepare((gc) => {
26
+ if (gc.isTableCell && gc.gridColumn.name === 'ic50' && gc.cell.value != null)
27
+ gc.style.element = gc.cell.value.plot.line(lineOptions).root;
28
+ if (gc.isTableCell && gc.gridColumn.name === 'hist' && gc.cell.value != null)
29
+ gc.style.element = gc.cell.value.plot.histogram({showBinSelector: 'false', showColumnSelector: 'false'}).root;
30
+ });
@@ -0,0 +1,4 @@
1
+ // Adds a virtual column with the renderer defined in the PowerGrid package (make sure the package is installed).
2
+
3
+ var grid = grok.shell.addTableView(grok.data.demo.demog()).grid;
4
+ grid.columns.add({cellType: 'sparkline'});
@@ -6,9 +6,14 @@ t.col('height').tags[DG.TAGS.COLOR_CODING_CONDITIONAL] = `{"20-170":"#00FF00","1
6
6
 
7
7
  // Linear color-coding for numerical columns
8
8
  t.col('age').tags[DG.TAGS.COLOR_CODING_TYPE] = 'Linear';
9
+ t.col('age').tags[DG.TAGS.COLOR_CODING_LINEAR] = '["#ff0000", "#ffff00", "#00ff00"]';
9
10
 
10
11
  // Categorical color-coding for string columns
11
12
  t.col('race').tags[DG.TAGS.COLOR_CODING_TYPE] = 'Categorical';
12
13
  t.col('race').tags[DG.TAGS.COLOR_CODING_CATEGORICAL] = `{"Asian":4278190335,"Black":4286578816}`;
13
14
 
14
- grok.shell.addTableView(t);
15
+ grok.shell.addTableView(t);
16
+
17
+ // To turn the color-coding off, use either approach:
18
+ //t.col('height').tags[DG.TAGS.COLOR_CODING_TYPE] = 'Off';
19
+ //delete t.col('height').tags[DG.TAGS.COLOR_CODING_TYPE];
@@ -0,0 +1,14 @@
1
+ const properties = [
2
+ DG.Property.jsInt('age'),
3
+ DG.Property.jsString('sex'),
4
+ DG.Property.jsBool('control')
5
+ ];
6
+
7
+ const items = [
8
+ { age: 28, sex: 'M', control: true },
9
+ { age: 35, sex: 'M', control: false },
10
+ { age: 56, sex: 'F', control: true },
11
+ { age: 30, sex: 'F', control: false }
12
+ ]
13
+
14
+ DG.Grid.fromProperties(items, properties).root
@@ -0,0 +1,12 @@
1
+ // HTML cells in a dataframe
2
+
3
+ let t = DG.DataFrame.fromColumns([
4
+ DG.Column.fromStrings('test', [
5
+ '<button>Click me</button>',
6
+ '<div style="background: red">Div</div>',
7
+ '<input type="range">'
8
+ ])
9
+ ]);
10
+ t.col('test').tags['cell.renderer'] = 'html';
11
+
12
+ grok.shell.addTableView(t);
@@ -1,6 +1,6 @@
1
1
  //tags: Script, Package
2
- //help-url: https://datagrok.ai/help/develop/scripting
2
+ //help-url: https://datagrok.ai/help/compute/scripting
3
3
  // An example of using scripting (R, Python etc.)
4
4
 
5
- grok.functions.call('PythonScripts:PythonDup', {'s': '1010'}).then(result => grok.shell.info(result));
6
- grok.functions.call('RScripts:RDup', {'s': '0101'}).then(result => grok.shell.info(result));
5
+ grok.functions.call('DemoScripts:PythonDup', {'s': '1010'}).then(result => grok.shell.info(result));
6
+ grok.functions.call('DemoScripts:RDup', {'s': '0101'}).then(result => grok.shell.info(result));
@@ -0,0 +1,11 @@
1
+ //name: shellLastError
2
+ //description: Hello world script
3
+ //language: javascript
4
+
5
+ // First uncomment this errorneous line in the script:
6
+ // 2 ++ 2;
7
+ // Hit save the script like that, you should now see an error.
8
+ // Then comment this bad line above and run the script again.
9
+ // The alert will contain the error's text.
10
+
11
+ alert(grok.shell.lastError);
@@ -0,0 +1,24 @@
1
+ //wait, waitBox, loader
2
+
3
+ async function sleep() {
4
+ return new Promise(resolve => setTimeout(resolve, 2000));
5
+ }
6
+
7
+ //load indicator
8
+ let loader = ui.loader();
9
+
10
+ //wait container
11
+ let wait = ui.wait(async () => {
12
+ await sleep();
13
+ return ui.divText('ui.wait element');
14
+ })
15
+
16
+ //wait container. Recommend to use inside tabControl, accordion, box, view.box
17
+ let waitBox = ui.waitBox(async () => {
18
+ await sleep();
19
+ return ui.divText('ui.waitBox element');
20
+ })
21
+
22
+ wait.style.border = '1px solid var(--grey-1)';
23
+ waitBox.style.border = '1px solid var(--grey-1)';
24
+ grok.shell.newView('Demo, loader, wait, waitBox', [wait, waitBox, loader]);
@@ -1,3 +1,14 @@
1
+ const fruits = [{name: 'apple', price: 5}, {name: 'banana', price: 6}, {name: "orange", price: 7}];
2
+
1
3
  grok.shell.topMenu
4
+ .item('Foo!', () => grok.shell.info('Foo clicked'))
5
+ .separator()
2
6
  .group('Custom')
3
- .item('Foo!', () => grok.shell.info('Foo clicked'));
7
+ .items(fruits, item => grok.shell.info(item), {
8
+ getTooltip: item => `${item.name} ${item.price}`,
9
+ isChecked: item => item.name === 'apple',
10
+ isValid: item => item.name === 'orange' ? 'Oranges are not allowed' : null,
11
+ onMouseEnter: item => grok.shell.info(item.name),
12
+ toString: item => item.name
13
+ })
14
+ .endGroup();
@@ -0,0 +1,27 @@
1
+ // dynamically create properties and edit objects in the property grid
2
+
3
+ let person = {name: 'John', sex: 'M', weight: 67.2, age: 32, checked: true }
4
+
5
+ // generate properties
6
+ let name = DG.Property.string('name', x => x.name, (x, v) => x.name = v, '');
7
+ let sex = DG.Property.string('sex', x => x.sex, (x, v) => x.sex = v, '');
8
+
9
+ // shorter notation for JS properties
10
+ let width = DG.Property.jsFloat('weight');
11
+ let age = DG.Property.jsInt('age');
12
+ let checked = DG.Property.jsBool('checked');
13
+
14
+ // change properties if you wish
15
+ sex.choices = ['M', 'F'];
16
+
17
+ let propGrid = new DG.PropertyGrid();
18
+ propGrid.update(person, [name, sex, width, age, checked]);
19
+
20
+ //ui.dialog().add(propGrid).show({width: 400, height: 250});
21
+
22
+ ui.dialog()
23
+ .add(ui.h1('Property grid'))
24
+ .add(propGrid)
25
+ .add(ui.h1('Form'))
26
+ .add(ui.input.form(person, [name, sex, width, age, checked]))
27
+ .show({width: 350, height: 500});
@@ -2,14 +2,14 @@
2
2
 
3
3
  let v = grok.shell.newView('Tabs');
4
4
 
5
+ let tabControl = ui.tabControl({
6
+ 'FIRST': ui.panel('First panel', {style :{backgroundColor: '#EFE'}}), // an element
7
+ 'SECOND': () => ui.panel('Second panel', {style :{backgroundColor: '#EEF'}}) // a function that returns an element
8
+ });
9
+
5
10
  // Simple API
6
11
  v.append(ui.h1('Horizontal'));
7
- v.append(
8
- ui.tabControl({
9
- 'FIRST': ui.panel('First panel', {style :{backgroundColor: '#EFE'}}), // an element
10
- 'SECOND': () => ui.panel('Second panel', {style :{backgroundColor: '#EEF'}}) // a function that returns an element
11
- })
12
- );
12
+ v.append(tabControl);
13
13
 
14
14
  // Detailed API
15
15
  v.append(ui.h1('Vertical'));
@@ -17,3 +17,6 @@ let tabsV = ui.tabControl(null, true);
17
17
  tabsV.addPane('FIRST', () => ui.panel('First panel', {style :{backgroundColor: '#EFE'}}));
18
18
  tabsV.addPane('SECOND', () => ui.panel('Second panel', {style :{backgroundColor: '#EEF'}}));
19
19
  v.append(tabsV);
20
+
21
+ // events
22
+ tabControl.onTabChanged.subscribe((_) => grok.shell.info(tabControl.currentPane.name));
@@ -0,0 +1,9 @@
1
+ let apple = { name: 'apple', type: 'fruit', color: 'red' };
2
+ let cherry = { name: 'cherry', type: 'fruit', color: 'red' };
3
+ let banana = { name: 'banana', type: 'fruit', color: 'orange' }
4
+ let ferrari = { name: 'ferrari', type: 'car', color: 'red' }
5
+ let items = [apple, cherry, banana, ferrari];
6
+
7
+ DG.TreeViewNode.fromItemCategories(items,
8
+ ['color', 'type'],
9
+ { itemToString: (x) => x.name }).root
@@ -0,0 +1,15 @@
1
+ // Creating custom dialogs, and add the help url
2
+
3
+ let name = ui.stringInput('Title', '');
4
+ let type = ui.choiceInput('Type', 'Bio', ['Bio', 'Chem']);
5
+
6
+ new DG.Wizard({title: 'Onboard a model'})
7
+ .page({
8
+ caption: 'Details',
9
+ root: ui.inputs([name, type]),
10
+ validate: () => name.value !== '' ? null : 'Please provide a name'
11
+ })
12
+ .page({ caption: 'Model Source', root: ui.divText('Second page') })
13
+ .page({ caption: 'Finalize', root: ui.divText('Finish') })
14
+ .onOK(() => {})
15
+ .show({width: 500, height: 300});
@@ -7,6 +7,7 @@ let date = ui.dateInput('Birthday', DG.DateTime.fromDate(new Date(1970, 5, 10)))
7
7
  let alien = ui.boolInput('Alien', false);
8
8
  let friends = ui.multiChoiceInput('Friends', ['Ford', 'Fenchurch'], ['Ford', 'Fenchurch', 'Zaphod', 'Slartibartfast']);
9
9
  let active = ui.switchInput('Active', true);
10
+ let color = ui.colorInput('Favorite color', '#ff0000');
10
11
 
11
12
  let inputs = [name, age, sex, date, alien, friends, active];
12
13
  let container = ui.div();
@@ -0,0 +1,4 @@
1
+ // Create inputs dynamically for columns
2
+
3
+ let t = grok.data.demo.molecules();
4
+ ui.divV(t.columns.toList().map(c => DG.InputBase.forColumn(c)))
@@ -0,0 +1,40 @@
1
+ // Create inputs dynamically for properties
2
+
3
+ const properties = [
4
+ {
5
+ "name": "reactorType",
6
+ "type": "string",
7
+ "choices": ["Experimental", "Production"]
8
+ },
9
+ {
10
+ "name": "structure",
11
+ "type": "string",
12
+ "semType": "Molecule"
13
+ },
14
+ {
15
+ "name": "weight",
16
+ "type": DG.TYPE.FLOAT,
17
+ "valueValidators": [(w) => w > 10]
18
+ },
19
+ {
20
+ "name": "started",
21
+ "type": DG.TYPE.DATE_TIME,
22
+ },
23
+ {
24
+ "name": "rating",
25
+ "type": "int",
26
+ "editor": "slider",
27
+ "min": 0,
28
+ "max": 10,
29
+ }];
30
+
31
+ let props = properties.map((p) => DG.Property.fromOptions(p))
32
+
33
+ let object = {
34
+ reactorType: 'Production',
35
+ structure: 'CC(=O)OC1=CC=CC=C1C(=O)O',
36
+ rating: 7,
37
+ department: 'IT'
38
+ };
39
+
40
+ ui.input.form(object, props)
@@ -0,0 +1,25 @@
1
+ // Create inputs dynamically for properties
2
+
3
+ const properties = [
4
+ {
5
+ "name": "name",
6
+ "type": "string",
7
+ },
8
+ {
9
+ "name": "structure",
10
+ "type": "string",
11
+ "semType": "Molecule"
12
+ }];
13
+
14
+ let props = properties.map((p) => DG.Property.fromOptions(p));
15
+
16
+ let objects = [{
17
+ name: 'aspirin',
18
+ structure: 'CC(=O)OC1=CC=CC=C1C(=O)O',
19
+ },
20
+ {
21
+ name: 'coffee',
22
+ structure: 'CN1C=NC2=C1C(=O)N(C(=O)N2C)C',
23
+ }];
24
+
25
+ ui.tableFromProperties(objects, props)
@@ -0,0 +1,3 @@
1
+ let t = grok.data.demo.demog();
2
+ t.col('weight').tags['.default-axis-type'] = 'logarithmic';
3
+ grok.shell.addTableView(t).scatterPlot();
@@ -0,0 +1,11 @@
1
+ // creating viewers dynamically
2
+
3
+ let t = grok.data.demo.demog();
4
+
5
+ // dynamically
6
+ let scatterPlot = DG.Viewer.fromType(DG.VIEWER.SCATTER_PLOT, t);
7
+
8
+ // fluent API
9
+ let barChart = t.plot.bar();
10
+
11
+ ui.divV([scatterPlot.root, barChart.root])
@@ -0,0 +1,4 @@
1
+ let tv = grok.shell.addTableView(grok.data.demo.demog());
2
+ tv.filters({filters: [
3
+ {type: 'Widgets:radioButtonFilter', columnName: 'race'},
4
+ ]});
@@ -0,0 +1,7 @@
1
+ let tv = grok.shell.addTableView(grok.data.demo.demog());
2
+ tv.filters({filters: [
3
+ {type: DG.FILTER_TYPE.HISTOGRAM, column: 'height', min: 120, max: 150},
4
+ {type: DG.FILTER_TYPE.FREE_TEXT},
5
+ {type: DG.FILTER_TYPE.MULTI_VALUE, column: 'sex', selected: 'F'},
6
+ {type: DG.FILTER_TYPE.CATEGORICAL, column: 'disease'},
7
+ ]});
@@ -0,0 +1,5 @@
1
+ let df = grok.data.demo.demog();
2
+ df.tags[DG.TAGS.TOOLTIP] = 'weight\nheight\nsex\nage'; // all viewers inherit it
3
+ let view = grok.shell.addTableView(df);
4
+ view.scatterPlot({title: 'Custom tooltip', rowTooltip: 'age\nsex'}); // override
5
+ view.scatterPlot({title: 'Derived from table'});
@@ -0,0 +1,16 @@
1
+ // a view that hosts multiple other views
2
+
3
+ let custom = DG.View.fromRoot(ui.div([]));
4
+ custom.toolbox = ui.divText('my toolbox');
5
+ custom.setRibbonPanels([[ui.button('hey')]]);
6
+
7
+ let multiView = new DG.MultiView({
8
+ viewFactories: {
9
+ 'custom': () => custom,
10
+ 'demog': () => DG.TableView.create(grok.data.demo.demog(), false),
11
+ 'apps': () => DG.View.createByType(DG.View.APPS),
12
+ 'users': () => DG.View.createByType(DG.View.USERS),
13
+ }
14
+ });
15
+
16
+ grok.shell.addView(multiView);
@@ -1,6 +1,7 @@
1
1
  //Example "Link table" dialog layout
2
2
 
3
3
  let table = grok.data.testData('demog', 10000);
4
+ grok.shell.addTableView(table);
4
5
  let tables = grok.shell.tables;
5
6
 
6
7
  let linkTablesDlg = ui.dialog('Link Tables');
@@ -1,163 +0,0 @@
1
-
2
- let demog = grok.data.demo.demog(100);
3
-
4
- /**
5
- * An example of adding a line with a complete set of parameters.
6
- * Only one parameter ("equation") is required.
7
- * All other parameters have their default values.
8
- */
9
- demog.meta.addLine({
10
- title: 'Red Line', // Short title.
11
- description: 'Description', // Detailed description.
12
- // Equation for line.
13
- // There should be one column to the left of the "=". And any formula using the second column on the right side.
14
- // The equation uses syntax and formulas similar to the "Add New Column" form.
15
- equation: '${height} = 0.69 * max($[weight])',
16
- zindex: -45, // Line depth. The viewer's chart has a depth of 0.
17
- color: "#ff0000", // Line color.
18
- visible: true, // Visibility.
19
- opacity: 0.8, // Opacity [0..1], where 0 - invisible, 1 - opaque.
20
- // Line boundaries along the value axis. In this example, the line will be drawn for a "Weight" between 50 and 300 kg.
21
- min: 50,
22
- max: 300,
23
- // Parameters specific to Lines:
24
- width: 2, // Line width in pixels.
25
- spline: 0.9, // Smoothness of curve line [0..1], where 0 - no smoothing, 1 - max smoothing.
26
- });
27
-
28
- /**
29
- * An example of adding a band. Most of the parameters are the same as for lines.
30
- * There are two required parameters here - "column" and "equation".
31
- * All other parameters have their default values.
32
- */
33
- demog.meta.addBand({
34
- title: 'My first Band', // Short title.
35
- description: 'Band is a rectangle', // Detailed description.
36
- // Band boundary formula.
37
- // The formula can contain expressions of the form: "< 200", "> 50", "in(18, 60)", "in(q1, q3)".
38
- // The numbers are specified in the units of the column. in this case in centimeters.
39
- equation: 'in(175, 185)',
40
- zindex: -15, // Line depth. The viewer's chart has a depth of 0.
41
- color: "#FFD700", // Band background color.
42
- max: 160, // Maximum band size.
43
- // Parameters specific to Bands:
44
- column: "${height}", // Column for which the band is set.
45
- column2: "${weight}", // Second column for which the band will be drawn.
46
- });
47
-
48
- demog.meta.addLine({
49
- title: 'Blue Line',
50
- equation: '${weight} = 180',
51
- color: "#0000ff",
52
- width: 4,
53
- opacity: 0.5
54
- });
55
-
56
- demog.meta.addLine({
57
- title: 'Y = X',
58
- description: 'Some description',
59
- equation: '${weight} = ${height}',
60
- width: 1
61
- });
62
-
63
- demog.meta.addLine({
64
- title: 'Parabola',
65
- equation: '${height} = 180 + 0.01 * ${weight} * ${weight} - 1.5 * ${weight}',
66
- zindex: -30,
67
- color: "#FFA500",
68
- width: 2,
69
- visible: true,
70
- });
71
-
72
- demog.meta.addLine({
73
- title: 'Green Line',
74
- equation: '${height} = 140 + ${weight} * 0',
75
- zindex: -20,
76
- color: "#00ff00",
77
- width: 6,
78
- max: 200
79
- });
80
-
81
- demog.meta.addLine({
82
- title: 'Sinusoid',
83
- equation: '${height} = 90 + max($[age]) + 4 * sin(0.2 * ${weight} + 60)',
84
- zindex: -45,
85
- color: "#00BFFF",
86
- width: 3,
87
- visible: true,
88
- max: 200
89
- });
90
-
91
- demog.meta.addLine({
92
- title: 'Hidden Line',
93
- equation: '${height} = 2 * ${weight}',
94
- zindex: -45,
95
- width: 1,
96
- visible: false, // This line will not be displayed.
97
- opacity: 0.8
98
- });
99
-
100
- demog.meta.addLine({
101
- title: 'Circle Top',
102
- description: 'Description of circle',
103
- equation: '${height} = 181.2 + sqrt(pow(25, 2) - pow((${weight} - 108.75), 2)) * 0.34',
104
- zindex: -40,
105
- color: "#5F9EA0",
106
- width: 6
107
- });
108
-
109
- demog.meta.addLine({
110
- title: 'Circle Bottom',
111
- equation: '${height} = 178.8 - sqrt(pow(25, 2) - pow((${weight} - 108.75), 2)) * 0.34',
112
- zindex: -40,
113
- color: "#5F9EA0",
114
- width: 6
115
- });
116
-
117
- demog.meta.addLine({
118
- title: 'X Top',
119
- equation: '${height} = 115 + sqrt(pow(20, 2) - pow((${weight} - 188.95), 2)) * 1.0',
120
- zindex: -45,
121
- color: "#228B22",
122
- width: 4
123
- });
124
-
125
- demog.meta.addLine({
126
- title: 'X Bottom',
127
- equation: '${height} = 147 - sqrt(pow(20, 2) - pow((${weight} - 188.95), 2)) * 1.0',
128
- zindex: -45,
129
- color: "#228B22",
130
- width: 4
131
- });
132
-
133
- demog.meta.addBand({
134
- title: 'Band 2',
135
- description: 'Second band',
136
- column: "${weight}",
137
- equation: '< 80',
138
- column2: "${height}",
139
- zindex: -45,
140
- color: "#FFC0CB",
141
- opacity: 0.3,
142
- min: 130
143
- });
144
-
145
- demog.meta.addBand({
146
- title: 'Band 3',
147
- description: 'Another band',
148
- column: "${weight}",
149
- equation: '> max',
150
- column2: "${height}",
151
- zindex: -45,
152
- color: "#7FFFD4",
153
- opacity: 0.3,
154
- max: 160
155
- });
156
-
157
- let view = grok.shell.addTableView(demog);
158
-
159
- let plot = view.scatterPlot({
160
- x: 'weight',
161
- y: 'height',
162
- showLinesByEquations: true // This option allows to hide or show all lines and bands at once.
163
- });