@datagrok/api-samples 1.0.8 → 1.0.12
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.
- package/CHANGELOG.md +9 -0
- package/dist/package-test.js +2 -2
- package/files/viewer-events/bar-chart/on-category-clicked.js +1 -0
- package/files/viewer-events/grid/on-cell-clicked.js +1 -0
- package/files/viewer-events/pc-plot/on-line-clicked.js +1 -0
- package/files/viewer-events/pie-chart/on-segment-clicked.js +1 -0
- package/files/viewer-events/scatter-plot/on-point-clicked.js +1 -0
- package/files/viewer-events/scatter-plot/on-rendered.js +1 -0
- package/layouts/demog-table-layout.json +329 -181
- package/package.json +17 -15
- package/scripts/dapi/files.js +40 -0
- package/scripts/dapi/projects-open.js +1 -1
- package/scripts/dapi/sticky-meta-1-tags.js +54 -0
- package/scripts/dapi/sticky-meta-2-semtype.js +33 -0
- package/scripts/data-access/db-master-details-manual.js +3 -2
- package/scripts/data-access/external/stock-prices.js +1 -1
- package/scripts/data-access/open-table-by-id.js +11 -3
- package/scripts/data-access/output-layouts.js +3 -1
- package/scripts/data-frame/advanced/data-frames-in-columns.js +4 -1
- package/scripts/data-frame/advanced/virtual-columns.js +1 -1
- package/scripts/data-frame/aggregation/unpivot.js +1 -1
- package/scripts/data-frame/column-access.js +1 -3
- package/scripts/data-frame/compare-tables.js +3 -2
- package/scripts/data-frame/construction/create-from-csv-format.js +3 -3
- package/scripts/data-frame/construction/create-from-typed-arrays.js +7 -2
- package/scripts/data-frame/construction/export-to-csv-advanced.js +14 -4
- package/scripts/data-frame/construction/export-to-csv-molblock.js +3 -0
- package/scripts/data-frame/construction/export-to-csv.js +1 -1
- package/scripts/data-frame/events/calculated-columns/creation.js +1 -1
- package/scripts/data-frame/events/calculated-columns/deletion.js +1 -1
- package/scripts/data-frame/events/calculated-columns/update.js +1 -1
- package/scripts/data-frame/join-link/link-tables-dynamic.js +3 -5
- package/scripts/data-frame/metadata/dataframe-meta.js +1 -1
- package/scripts/data-frame/modification/add-columns.js +1 -1
- package/scripts/data-frame/modification/append.js +1 -1
- package/scripts/data-frame/modification/calculated-columns/edit-formula.js +2 -2
- package/scripts/data-frame/modification/double-precision.js +26 -0
- package/scripts/data-frame/modification/manipulate.js +3 -3
- package/scripts/domains/chem/sketcher.js +2 -2
- package/scripts/events/form-creation.js +2 -2
- package/scripts/events/global-events.js +1 -1
- package/scripts/events/layout-events.js +5 -6
- package/scripts/events/viewer-data-events.js +11 -0
- package/scripts/functions/func-call.js +5 -0
- package/scripts/grid/advanced/cell-renderer.js +1 -1
- package/scripts/grid/advanced/format-formula.js +7 -0
- package/scripts/grid/advanced/link-click.js +3 -3
- package/scripts/grid/advanced/markup-link.js +6 -0
- package/scripts/grid/advanced/paint-counts.js +4 -1
- package/scripts/grid/{color-coding-conditional.js → color-coding/color-coding-conditional.js} +17 -10
- package/scripts/grid/color-coding/color-coding.js +5 -9
- package/scripts/grid/color-coding/get-cell-color.js +3 -5
- package/scripts/grid/column-cell-styles.js +10 -0
- package/scripts/grid/column-controlled-values.js +2 -2
- package/scripts/grid/data-format.js +4 -4
- package/scripts/grid/hit-test.js +1 -1
- package/scripts/grid/html-cells/html-table-cells.js +1 -1
- package/scripts/misc/audit/test-tracking.js +1 -1
- package/scripts/misc/user-settings-storage.js +48 -0
- package/scripts/scripting/files-for-scripting.js +24 -0
- package/scripts/scripting/grok-scripting.js +1 -1
- package/scripts/shell/last-error.js +1 -1
- package/scripts/shell/ui-parts.js +9 -9
- package/scripts/shell/windows/browse/customize-tree.js +3 -0
- package/scripts/ui/apps/bioreactor.js +5 -5
- package/scripts/ui/components/accordion.js +3 -3
- package/scripts/ui/components/tree-view-adv.js +4 -2
- package/scripts/ui/containers/splitters.js +13 -13
- package/scripts/ui/dialogs/wizard.js +8 -8
- package/scripts/ui/docking/docking.js +4 -1
- package/scripts/ui/handlers/markup-handlers.js +61 -0
- package/scripts/ui/inputs/advanced/all-input-types.js +37 -24
- package/scripts/ui/inputs/advanced/input-api.js +39 -0
- package/scripts/ui/inputs/advanced/input-events.js +10 -10
- package/scripts/ui/inputs/advanced/input-form.js +8 -8
- package/scripts/ui/inputs/choice-input.js +5 -5
- package/scripts/ui/inputs/column-combo-box.js +3 -3
- package/scripts/ui/inputs/column-inputs.js +3 -3
- package/scripts/ui/inputs/forms.js +10 -10
- package/scripts/ui/inputs/helm-input-ui.js +7 -0
- package/scripts/ui/inputs/inputs-events.js +8 -8
- package/scripts/ui/inputs/inputs-extended.js +2 -2
- package/scripts/ui/inputs/inputs.js +17 -15
- package/scripts/ui/inputs/molecule-input.js +1 -1
- package/scripts/ui/inputs/table-input.js +1 -1
- package/scripts/ui/inputs/tags-input.js +2 -2
- package/scripts/ui/inputs/typeahead-input.js +16 -17
- package/scripts/ui/inputs/validation/input-validators.js +11 -0
- package/scripts/ui/inputs/validation/script-param-validation.js +6 -0
- package/scripts/ui/inputs/validation/visible-enabled.js +9 -0
- package/scripts/ui/interactivity/drag-and-drop.js +3 -3
- package/scripts/ui/tooltips/tooltips.js +6 -2
- package/scripts/ui/viewers/advanced/attached-properties.js +5 -5
- package/scripts/ui/viewers/advanced/default-axis-type.js +1 -1
- package/scripts/ui/viewers/advanced/init-function.js +21 -0
- package/scripts/ui/viewers/advanced/init-script.js +15 -0
- package/scripts/ui/viewers/filters/add-single-filter.js +5 -5
- package/scripts/ui/viewers/filters/custom-filters.js +3 -3
- package/scripts/ui/viewers/filters/filter-group.js +6 -1
- package/scripts/ui/viewers/filters/multi-value-filter.js +1 -1
- package/scripts/ui/viewers/js viewers/chord-viewer.js +1 -1
- package/scripts/ui/viewers/js viewers/sankey-viewer.js +1 -1
- package/scripts/ui/viewers/js viewers/word-cloud.js +1 -1
- package/scripts/ui/viewers/scatter-plot-events.js +6 -1
- package/scripts/ui/viewers/trellis-plot-with-summary-viewer.js +3 -1
- package/scripts/ui/viewers/types/markup-advanced.js +1 -1
- package/scripts/ui/viewers/types/trellis-plot.js +13 -1
- package/scripts/ui/viewers/types/word-cloud.js +1 -1
- package/scripts/ui/views/default-views.js +3 -3
- package/scripts/ui/views/layouts.js +16 -17
- package/scripts/ui/views/multi-view.js +1 -1
- package/src/global.d.ts +13 -0
- package/src/package-test.ts +106 -16
- package/webpack.config.js +4 -1
- package/files.js +0 -39
- package/scripts/misc/user-data-storage.js +0 -49
- /package/scripts/scripting/{scripting.js → package-scripting.js} +0 -0
- /package/{scripts/ui/handlers → to fix}/dynamic-loading.js +0 -0
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
let df = grok.data.demo.demog();
|
|
6
6
|
let view = grok.shell.addTableView(df);
|
|
7
7
|
|
|
8
|
-
df.col('age').
|
|
9
|
-
df.col('height').
|
|
10
|
-
df.col('weight').
|
|
11
|
-
df.col('started').
|
|
8
|
+
df.col('age').meta.format = 'compact simple currency';
|
|
9
|
+
df.col('height').meta.format = 'scientific';
|
|
10
|
+
df.col('weight').meta.format = '#.0000';
|
|
11
|
+
df.col('started').meta.format = 'dd.MM.yyyy';
|
|
12
12
|
|
|
13
13
|
// NUMBER FORMATS (https://datagrok.ai/help/discover/tags#numbers)
|
|
14
14
|
// The usual formats, such as "0.000" or "#.0000", are supported.
|
package/scripts/grid/hit-test.js
CHANGED
|
@@ -4,5 +4,5 @@ let table = grok.data.demo.demog();
|
|
|
4
4
|
let view = grok.shell.addTableView(table);
|
|
5
5
|
rxjs.fromEvent(view.grid.overlay, 'mousemove').subscribe((mm) => {
|
|
6
6
|
let cell = view.grid.hitTest(mm.offsetX, mm.offsetY);
|
|
7
|
-
grok.shell.o = cell.gridColumn
|
|
7
|
+
grok.shell.o = cell.gridColumn;
|
|
8
8
|
});
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const df = await grok.data.query('UsageAnalysis:
|
|
1
|
+
const df = await grok.data.query('UsageAnalysis:Tests');
|
|
2
2
|
grok.shell.addTableView(df);
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// User settings storage demo: Saving values to storage
|
|
2
|
+
|
|
3
|
+
const STORAGE_NAME = 'user-data-storage-demo';
|
|
4
|
+
|
|
5
|
+
let v = grok.shell.newView('demo: user data storage');
|
|
6
|
+
|
|
7
|
+
let age = ui.input.int('Age', {value: 30});
|
|
8
|
+
let sex = ui.input.choice('Sex', {items: ['Male', 'Female'], value: 'Male'});
|
|
9
|
+
let music = ui.input.multiChoice('Music genres', {items: ['Classic', 'Rock', 'Pop', 'Jazz']});
|
|
10
|
+
|
|
11
|
+
let inputs = [age, sex, music];
|
|
12
|
+
v.append(ui.inputs(inputs));
|
|
13
|
+
|
|
14
|
+
let storageButton = ui.iconFA('database', () => {
|
|
15
|
+
let entities = grok.userSettings.get(STORAGE_NAME);
|
|
16
|
+
if (entities !== null && Object.keys(entities).length === 0)
|
|
17
|
+
grok.shell.info('Storage is empty. Try to post something to the storage');
|
|
18
|
+
else {
|
|
19
|
+
let menu = DG.Menu.popup();
|
|
20
|
+
for (let time of Object.keys(entities)) {
|
|
21
|
+
let values = JSON.parse(entities[time]);
|
|
22
|
+
menu.item(values.map(v => `${v.caption}: ${v.value}`).join(', '), () => {
|
|
23
|
+
for (let input of values)
|
|
24
|
+
inputs.find(i => i.caption === input.caption).load(input.value);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
menu.show();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
storageButton.style.margin = '8px 24px 0 24px';
|
|
32
|
+
|
|
33
|
+
let postButton = ui.button('Post to storage', () => {
|
|
34
|
+
grok.shell.info(inputs.map((i) => `${i.caption}: ${i.stringValue}`).join('<br>'));
|
|
35
|
+
grok.userSettings.add(STORAGE_NAME, `${Math.floor(Math.random() * Math.floor(1000))}`, JSON.stringify(inputs.map(i => {
|
|
36
|
+
return {caption: i.caption, value: i.save()};
|
|
37
|
+
})));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
let clearButton = ui.button('Clear storage', () => {
|
|
41
|
+
grok.userSettings.delete(STORAGE_NAME, null);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
v.append(ui.divH([
|
|
45
|
+
storageButton,
|
|
46
|
+
postButton,
|
|
47
|
+
clearButton
|
|
48
|
+
]));
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//tags: Script, Files
|
|
2
|
+
//help-url: https://datagrok.ai/help/compute/scripting
|
|
3
|
+
// An example of using files in a script
|
|
4
|
+
|
|
5
|
+
async function logFileContentAsString(fileInfo) {
|
|
6
|
+
let data = await fileInfo.readAsString();
|
|
7
|
+
grok.shell.info(data);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async function logFileContentAsBytes(fileInfo) {
|
|
11
|
+
let data = await fileInfo.readAsBytes();
|
|
12
|
+
grok.shell.info(data);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// these values are the same for utf-8
|
|
16
|
+
var line = 'test how script uses files'
|
|
17
|
+
var fileName = 'text.txt'
|
|
18
|
+
var bytes = new Uint8Array([0x74, 0x65, 0x73, 0x74, 0x20, 0x68, 0x6F, 0x77, 0x20, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x20, 0x75, 0x73, 0x65, 0x73, 0x20, 0x66, 0x69, 0x6C, 0x65, 0x73])
|
|
19
|
+
var fileInfo = DG.FileInfo.fromString(fileName, line);
|
|
20
|
+
logFileContentAsString(fileInfo);
|
|
21
|
+
logFileContentAsBytes(fileInfo);
|
|
22
|
+
fileInfo = DG.FileInfo.fromBytes(fileName, bytes);
|
|
23
|
+
logFileContentAsString(fileInfo);
|
|
24
|
+
logFileContentAsBytes(fileInfo);
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
let windows = grok.shell.windows;
|
|
4
4
|
ui.dialog('Windows')
|
|
5
|
-
.add(ui.
|
|
6
|
-
.add(ui.
|
|
7
|
-
.add(ui.
|
|
8
|
-
.add(ui.
|
|
9
|
-
.add(ui.
|
|
10
|
-
.add(ui.
|
|
11
|
-
.add(ui.
|
|
12
|
-
.add(ui.
|
|
13
|
-
.add(ui.
|
|
5
|
+
.add(ui.input.bool('help', {value: windows.showHelp, onValueChanged: (x) => windows.showHelp = x}))
|
|
6
|
+
.add(ui.input.bool('sidebar', {value: windows.showSidebar, onValueChanged: (x) => windows.showSidebar = x}))
|
|
7
|
+
.add(ui.input.bool('toolbox', {value: windows.showToolbox, onValueChanged: (x) => windows.showToolbox = x}))
|
|
8
|
+
.add(ui.input.bool('status bar', {value: windows.showStatusBar, onValueChanged: (x) => windows.showStatusBar = x}))
|
|
9
|
+
.add(ui.input.bool('console', {value: windows.showConsole, onValueChanged: (x) => windows.showConsole = x}))
|
|
10
|
+
.add(ui.input.bool('properties', {value: windows.showProperties, onValueChanged: (x) => windows.showProperties = x}))
|
|
11
|
+
.add(ui.input.bool('tables', {value: windows.showTables, onValueChanged: (x) => windows.showTables = x}))
|
|
12
|
+
.add(ui.input.bool('columns', {value: windows.showColumns, onValueChanged: (x) => windows.showColumns = x}))
|
|
13
|
+
.add(ui.input.bool('variables', {value: windows.showVariables, onValueChanged: (x) => windows.showVariables = x}))
|
|
14
14
|
.show();
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Bioreactor simulation wireframe
|
|
2
2
|
|
|
3
|
-
let view = grok.shell.newView(
|
|
3
|
+
let view = grok.shell.newView('Flowrate');
|
|
4
4
|
let progressDiv = ui.divText('Ready');
|
|
5
5
|
view.setRibbonPanels([[progressDiv]]);
|
|
6
6
|
|
|
7
7
|
let data = grok.data.demo.randomWalk();
|
|
8
8
|
|
|
9
|
-
let reactorInput = ui.
|
|
10
|
-
let productInput = ui.
|
|
11
|
-
let controlRunInput = ui.
|
|
12
|
-
let daysInput = ui.
|
|
9
|
+
let reactorInput = ui.input.choice('Reactor', {items: ['Biotek 15kL SS'], value: 'Biotek 15kL SS'});
|
|
10
|
+
let productInput = ui.input.choice('Product', {items: ['BAR FOO56545'], value: 'BAR FOO56545'});
|
|
11
|
+
let controlRunInput = ui.input.choice('Control Run', {items: ['15FDX006'], value: '15FDX006'});
|
|
12
|
+
let daysInput = ui.input.int('Process days', {value: 12});
|
|
13
13
|
|
|
14
14
|
let topGrid = ui.divV([
|
|
15
15
|
ui.divH([
|
|
@@ -53,15 +53,15 @@ acc.addPane('menus', () => ui.button('SHOW', () => {
|
|
|
53
53
|
});
|
|
54
54
|
}));
|
|
55
55
|
|
|
56
|
-
acc.addPane('text area', () => ui.
|
|
56
|
+
acc.addPane('text area', () => ui.input.textArea('', {value: 'multi\nline\ntext'}).root);
|
|
57
57
|
|
|
58
58
|
acc.addPane('range ', () => ui.rangeSlider(0, 10, 2, 5).root);
|
|
59
59
|
|
|
60
60
|
let persistentAcc = ui.accordion('keyThatGivesPersistence');
|
|
61
61
|
|
|
62
62
|
persistentAcc.addPane('persistent pane', () =>
|
|
63
|
-
|
|
63
|
+
ui.divText('If this pane is expanded, then it will be expanded next time'));
|
|
64
64
|
|
|
65
65
|
//v.root.appendChild(acc.root);
|
|
66
66
|
v.append(acc.root);
|
|
67
|
-
v.append(persistentAcc.root)
|
|
67
|
+
v.append(persistentAcc.root);
|
|
@@ -4,6 +4,8 @@ let banana = { name: 'banana', type: 'fruit', color: 'orange' }
|
|
|
4
4
|
let ferrari = { name: 'ferrari', type: 'car', color: 'red' }
|
|
5
5
|
let items = [apple, cherry, banana, ferrari];
|
|
6
6
|
|
|
7
|
-
DG.
|
|
7
|
+
const tree = DG.TreeViewGroup.fromItemCategories(items,
|
|
8
8
|
['color', 'type'],
|
|
9
|
-
{ itemToString: (x) => x.name }).root
|
|
9
|
+
{ itemToString: (x) => x.name }).root
|
|
10
|
+
|
|
11
|
+
grok.shell.newView('Tree', [tree]);
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
let t = grok.data.demo.demog();
|
|
4
4
|
let block = ui.splitV([
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
ui.splitH([
|
|
6
|
+
ui.inputs([
|
|
7
|
+
ui.input.string('Input'),
|
|
8
|
+
ui.input.choice('Select', {items: ['item 1', 'item 2'], value: 'item 1'}),
|
|
9
|
+
ui.input.textArea('text', {value: ' multi line /n text input'}),
|
|
10
|
+
]),
|
|
11
|
+
DG.Viewer.grid(t).root
|
|
12
|
+
], {}, true),
|
|
13
|
+
ui.splitH([
|
|
14
|
+
DG.Viewer.scatterPlot(t).root,
|
|
15
|
+
DG.Viewer.histogram(t).root
|
|
16
|
+
], {}, true)
|
|
17
|
+
], {}, true);
|
|
18
18
|
|
|
19
19
|
let view = grok.shell.newView('Splitters');
|
|
20
20
|
view.box = true;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// Creating custom dialogs, and add the help url
|
|
2
2
|
|
|
3
|
-
let name = ui.
|
|
4
|
-
let type = ui.
|
|
3
|
+
let name = ui.input.string('Title');
|
|
4
|
+
let type = ui.input.choice('Type', {items: ['Bio', 'Chem'], value: 'Bio'});
|
|
5
5
|
|
|
6
6
|
new DG.Wizard({title: 'Onboard a model'})
|
|
7
7
|
.page({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.page({
|
|
13
|
-
.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
14
|
.onOK(() => {})
|
|
15
15
|
.show({width: 500, height: 300});
|
|
@@ -10,4 +10,7 @@ let node2 = grok.shell.dockManager.dock(ui.divText('second'), 'down', node1, 'Se
|
|
|
10
10
|
let node3 = grok.shell.dockManager.dock(ui.divText('third'), 'fill', node2, 'Third');
|
|
11
11
|
|
|
12
12
|
// to the bottom of the current document
|
|
13
|
-
grok.shell.dockManager.dock(ui.divText('bottom'), 'down', grok.shell.v.dockNode, 'Bottom');
|
|
13
|
+
grok.shell.dockManager.dock(ui.divText('bottom'), 'down', grok.shell.v.dockNode, 'Bottom');
|
|
14
|
+
|
|
15
|
+
// handling events
|
|
16
|
+
grok.shell.dockManager.onClosed.subscribe((e) => grok.shell.info(e));
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//name: markup-handlers
|
|
2
|
+
//tags: demo
|
|
3
|
+
//language: javascript
|
|
4
|
+
// Custom markup handlers
|
|
5
|
+
// Allows logging and audit of events linked to in-app objects
|
|
6
|
+
|
|
7
|
+
// Defines a sample class
|
|
8
|
+
class Fruit {
|
|
9
|
+
constructor(name, color) {
|
|
10
|
+
this.name = name;
|
|
11
|
+
this.color = color;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Defines the way Datagrok handles entities of the specified type
|
|
16
|
+
// Shortened version of a sample handlers.js
|
|
17
|
+
class FruitHandler extends DG.ObjectHandler {
|
|
18
|
+
get type() { return 'fruit' }
|
|
19
|
+
|
|
20
|
+
// Checks whether this is the handler for [x]
|
|
21
|
+
isApplicable(x) { return x instanceof Fruit; }
|
|
22
|
+
|
|
23
|
+
renderIcon(x) { return ui.iconFA(`apple-alt`); }
|
|
24
|
+
renderMarkup(x) { let m = ui.span([this.renderIcon(x), ui.label(x.name)]); $(m).css('color', x.color); return m; }
|
|
25
|
+
|
|
26
|
+
// Is used by platform to detect markup description of Fruit
|
|
27
|
+
get markupRegexp() {
|
|
28
|
+
return "fruit\\.([a-zA-Z]+)\\.([a-zA-Z]+)";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Converts fruit to markup description
|
|
32
|
+
toMarkup(x) {
|
|
33
|
+
return `fruit.${x.name}.${x.color}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Deserialize object from parsed markup
|
|
37
|
+
// Accepts list of strings, that comes from regexp group matches
|
|
38
|
+
// In our case, matches = ["fruit.apple.red", "apple", "red"]
|
|
39
|
+
fromMarkup(matches) {
|
|
40
|
+
var name = matches[1];
|
|
41
|
+
var color = matches[2];
|
|
42
|
+
return new Fruit(name, color);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Register handler with the platform
|
|
47
|
+
var handler = new FruitHandler();
|
|
48
|
+
DG.ObjectHandler.register(handler);
|
|
49
|
+
|
|
50
|
+
// Create some fruits
|
|
51
|
+
let apple = new Fruit('apple', 'red');
|
|
52
|
+
let orange = new Fruit('orange', 'orange');
|
|
53
|
+
|
|
54
|
+
// Log usage of the fruit.
|
|
55
|
+
// Highlight custom markup objects with "#"
|
|
56
|
+
grok.log.usage('@user liked #fruit', {'user': DG.User.current(), '#fruit': apple});
|
|
57
|
+
grok.log.usage('@user disliked #fruit', {'user': DG.User.current(), '#fruit': orange});
|
|
58
|
+
|
|
59
|
+
grok.dapi.log.filter('description = "@user liked #fruit"').first().then((logObject) => {
|
|
60
|
+
grok.shell.info(ui.render(logObject));
|
|
61
|
+
});
|
|
@@ -2,46 +2,59 @@ const df = grok.data.demo.demog();
|
|
|
2
2
|
grok.shell.addTable(df);
|
|
3
3
|
|
|
4
4
|
const properties = [
|
|
5
|
-
{
|
|
6
|
-
{
|
|
7
|
-
{
|
|
8
|
-
{
|
|
9
|
-
{
|
|
10
|
-
{
|
|
11
|
-
{
|
|
12
|
-
{
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
{
|
|
16
|
-
{
|
|
17
|
-
{
|
|
18
|
-
{
|
|
19
|
-
{
|
|
20
|
-
{
|
|
21
|
-
{
|
|
5
|
+
{'name': 'int', 'inputType': 'Int', 'showPlusMinus': true},
|
|
6
|
+
{'name': 'bigInt', 'inputType': 'BigInt'},
|
|
7
|
+
{'name': 'float', 'inputType': 'Float', min: 0, max: 10, 'showSlider': true},
|
|
8
|
+
{'name': 'qnum', 'inputType': 'QNum'},
|
|
9
|
+
{'name': 'slider', 'inputType': 'Slider', 'min': 0, 'max': 10},
|
|
10
|
+
{'name': 'bool', 'inputType': 'Bool'},
|
|
11
|
+
{'name': 'switch', 'inputType': 'Switch'},
|
|
12
|
+
{'name': 'textArea', 'inputType': 'TextArea'},
|
|
13
|
+
{'name': 'text', 'inputType': 'Text'},
|
|
14
|
+
{'name': 'search', 'inputType': 'Search'},
|
|
15
|
+
{'name': 'date', 'inputType': 'Date'},
|
|
16
|
+
//{'name': 'map', 'inputType': 'Map'},
|
|
17
|
+
{'name': 'list', 'inputType': 'List'},
|
|
18
|
+
{'name': 'color', 'inputType': 'Color'},
|
|
19
|
+
{'name': 'table', 'inputType': 'Table'},
|
|
20
|
+
{'name': 'column', 'inputType': 'Column'},
|
|
21
|
+
{'name': 'radio', 'inputType': 'Radio', choices: ['Apple', 'Banana']},
|
|
22
|
+
{'name': 'choice', 'inputType': 'Choice', choices: ['Apple', 'Banana']},
|
|
23
|
+
{'name': 'multiChoice', 'inputType': 'MultiChoice', choices: ['Apple', 'Banana']},
|
|
24
|
+
//{'name': 'file', 'inputType': 'File'},
|
|
25
|
+
{'name': 'user', 'inputType': 'User'},
|
|
26
|
+
{'name': 'userGroups', 'inputType': 'UserGroups'},
|
|
22
27
|
];
|
|
23
28
|
|
|
24
29
|
let props = properties.map((p) => DG.Property.fromOptions(p))
|
|
25
30
|
let object = {
|
|
26
31
|
int: 12,
|
|
27
|
-
bigInt:
|
|
32
|
+
//bigInt: '12345678901234567890',
|
|
28
33
|
float: 4.5,
|
|
29
34
|
qnum: DG.Qnum.less(5),
|
|
30
35
|
slider: 10,
|
|
31
36
|
bool: true,
|
|
32
|
-
|
|
37
|
+
switch: true,
|
|
38
|
+
textArea: 'Bins rise and they fall,\nDistribution\'s gentle dance,\nHistogram unveils',
|
|
33
39
|
text: 'Only text',
|
|
40
|
+
search: '',
|
|
34
41
|
//date: '2023/10/30', //dayjs(1977, 10, 2),
|
|
35
|
-
map: { key1: 'value1', key2: 'value2'},
|
|
36
|
-
color: '#e66465',
|
|
42
|
+
//map: { key1: 'value1', key2: 'value2'},
|
|
37
43
|
list: ['1', '2', '4'],
|
|
44
|
+
color: '#e66465',
|
|
38
45
|
table: df,
|
|
39
46
|
column: df.columns.byName('race'),
|
|
40
|
-
choice: 'Apple',
|
|
41
47
|
radio: 'Apple',
|
|
48
|
+
choice: 'Apple',
|
|
49
|
+
multiChoice: ['Apple'],
|
|
50
|
+
//file: '',
|
|
51
|
+
users: [DG.User.current()],
|
|
52
|
+
userGroups: [DG.User.current()],
|
|
42
53
|
};
|
|
43
54
|
|
|
44
|
-
ui.divV([
|
|
55
|
+
const div = ui.divV([
|
|
45
56
|
ui.input.form(object, props),
|
|
46
57
|
ui.button('Show', () => grok.shell.info(JSON.stringify(object)))
|
|
47
|
-
])
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
grok.shell.newView('Inputs', [div]);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const df = grok.data.demo.demog();
|
|
2
|
+
grok.shell.addTable(df);
|
|
3
|
+
|
|
4
|
+
const inputs = [
|
|
5
|
+
ui.input.int('int', {value: 6, nullable: false, min: 2, max: 12, step: 2, showPlusMinus: true}),
|
|
6
|
+
// ui.input.bigInt('bigInt', {value: '12345678901234567890'}), // doesn't work yet with value
|
|
7
|
+
ui.input.float('float', {value: 6.5758, min: 0, max: 10, step: 0.5, format: '#0.000', showSlider: true}),
|
|
8
|
+
ui.input.qNum('qNum', {value: 5.959}),
|
|
9
|
+
ui.input.slider('slider', {value: 6, min: 0, max: 20, step: 2}),
|
|
10
|
+
ui.input.bool('bool', {value: false, tooltipText: 'Bool input tooltip'}),
|
|
11
|
+
ui.input.toggle('toggle', {value: true, tooltipText: 'Toggle input tooltip'}),
|
|
12
|
+
ui.input.textArea('textArea', {value: 'Text area', size: {width: 150, height: 35}}),
|
|
13
|
+
ui.input.string('string', {value: 'Text', placeholder: 'Text', clearIcon: true, escClears: true, icon: ui.iconFA('square')}),
|
|
14
|
+
ui.input.search('search', {value: 'Search'}),
|
|
15
|
+
ui.input.date('date', {value: dayjs('1970-5-10')}),
|
|
16
|
+
// ui.input.map('map'), // doesn't work yet
|
|
17
|
+
ui.input.file('file', {value: (await grok.dapi.files.list('System:AppData/ApiTests/datasets/'))[1]}),
|
|
18
|
+
ui.input.list('list', {value: [1, 2, 3]}),
|
|
19
|
+
ui.input.color('color', {value: '#e66465'}),
|
|
20
|
+
ui.input.column('column', {value: df.col('height'), table: df, filter: (col) => col.type === DG.COLUMN_TYPE.FLOAT}),
|
|
21
|
+
ui.input.columns('columns', {table: df, value: df.columns.byNames(['weight', 'age']), available: ['height', 'weight', 'age']}),
|
|
22
|
+
// ui.input.columnsMap('columnsMap'), // doesn't work yet
|
|
23
|
+
ui.input.radio('radio', {items: ['apple', 'orange'], value: 'apple'}),
|
|
24
|
+
ui.input.choice('choice', {items: ['apple', 'orange'], value: 'apple'}),
|
|
25
|
+
ui.input.multiChoice('multiChoice', {items: ['apple', 'orange', 'pear'], value: ['apple', 'orange']}),
|
|
26
|
+
ui.input.table('table', {value: df}),
|
|
27
|
+
ui.input.molecule('molecule', {value: 'CN1CCC(O)(CC1)c2ccccc2'}),
|
|
28
|
+
ui.input.user('user', {value: [DG.User.current()]}),
|
|
29
|
+
ui.input.userGroups('userGroups', {value: [DG.User.current()]}),
|
|
30
|
+
ui.input.image('image', {value: 'https://datagrok.ai/img/logo.svg'}),
|
|
31
|
+
ui.input.tags('tags', {tags: ['Tag 1', 'Tag2', 'Tag3'], showButton: true}),
|
|
32
|
+
ui.input.code('code', {script: 'print(\'Hello world!\')', mode: 'python', placeholder: 'print(\'Hello world!\')'}),
|
|
33
|
+
await ui.input.markdown('markdown'),
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const form = DG.InputForm.forInputs(inputs);
|
|
37
|
+
form.onInputChanged.subscribe((ed) => grok.shell.info(`Input - ${ed.args.input.caption}, new value - ${ed.args.input.value}`));
|
|
38
|
+
|
|
39
|
+
grok.shell.newView('Inputs', [form.root]);
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// Manual handling of input-originated events
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const medication = {name: 'Aspirin', quantity: '20 mg'};
|
|
4
4
|
|
|
5
5
|
// Core value input implemented in Dart
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
nameEditor.onChanged((
|
|
9
|
-
nameEditor.onInput((_) => grok.shell.info('name input: ' + nameEditor.value));
|
|
6
|
+
const nameProp = DG.Property.js('name', DG.TYPE.STRING);
|
|
7
|
+
const nameEditor = DG.InputBase.forProperty(nameProp, medication);
|
|
8
|
+
nameEditor.onChanged.subscribe((value) => grok.shell.info('name changed: ' + value));
|
|
9
|
+
nameEditor.onInput.subscribe((_) => grok.shell.info('name input: ' + nameEditor.value));
|
|
10
10
|
|
|
11
11
|
// 'foo' editor is defined in the Widgets package.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
quantityEditor.onChanged((
|
|
15
|
-
quantityEditor.onInput((_) => grok.shell.info('quantity input: ' + quantityEditor.value));
|
|
12
|
+
const fooProp = DG.Property.fromOptions({name: 'quantity', type: DG.TYPE.STRING, semType: 'foo'});
|
|
13
|
+
const quantityEditor = DG.InputBase.forProperty(fooProp, medication);
|
|
14
|
+
quantityEditor.onChanged.subscribe((value) => grok.shell.info('quantity changed: ' + value));
|
|
15
|
+
quantityEditor.onInput.subscribe((_) => grok.shell.info('quantity input: ' + quantityEditor.value));
|
|
16
16
|
|
|
17
|
-
quantityEditor.onInput((_) => grok.shell.o = medication);
|
|
17
|
+
quantityEditor.onInput.subscribe((_) => grok.shell.o = medication);
|
|
18
18
|
|
|
19
19
|
ui.dialog()
|
|
20
20
|
.add(ui.form([nameEditor, quantityEditor]))
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// creating a form, and accessing its individual inputs
|
|
2
2
|
|
|
3
|
-
DG.Func.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
3
|
+
const sin = DG.Func.find({name: 'Sin'});
|
|
4
|
+
|
|
5
|
+
let fc = sin[0].prepare({dosage: 77});
|
|
6
|
+
DG.InputForm.forFuncCall(fc).then((inputForm) => {
|
|
7
|
+
inputForm.getInput('x').addPostfix('foo');
|
|
8
|
+
inputForm.onInputChanged.subscribe((_) => grok.shell.info('changed'));
|
|
9
|
+
grok.shell.o = inputForm.root;
|
|
10
|
+
});
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
// Method #1. Using grok's wrapper classes only
|
|
4
4
|
let v = grok.shell.newView('Demo');
|
|
5
|
-
let choices = ui.
|
|
5
|
+
let choices = ui.input.choice('Value', {items: ['A', 'B', 'C'], value: 'A'});
|
|
6
6
|
let container = ui.div();
|
|
7
7
|
v.append(container);
|
|
8
8
|
let inputs = ui.inputs([choices]);
|
|
9
9
|
container.appendChild(inputs);
|
|
10
|
-
let
|
|
11
|
-
inputs.replaceChild(
|
|
12
|
-
choices =
|
|
13
|
-
choices.onChanged((v) => {
|
|
10
|
+
let choicesNew = ui.input.choice('Value', {items: ['B', 'C', 'D'], value: 'B'});
|
|
11
|
+
inputs.replaceChild(choicesNew.root, choices.root);
|
|
12
|
+
choices = choicesNew;
|
|
13
|
+
choices.onChanged.subscribe((v) => {
|
|
14
14
|
grok.shell.info('The selected value is changed');
|
|
15
15
|
});
|
|
16
16
|
choices.value = 'C';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Adds a view with a column combo box with int columns
|
|
1
|
+
// Adds a view with a column combo box with int and float columns
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const ccb = DG.ColumnComboBox.create(grok.data.demo.demog(), (c) => ['int', 'double'].includes(c.type));
|
|
4
|
+
grok.shell.newView('demo: column combo box', [ccb]);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
let v = grok.shell.newView('demo: column inputs');
|
|
2
2
|
let t = grok.data.testData('demog', 100);
|
|
3
3
|
|
|
4
|
-
let predict = ui.
|
|
5
|
-
let features = ui.
|
|
4
|
+
let predict = ui.input.column('Predict', {value: t.col('age'), table: t});
|
|
5
|
+
let features = ui.input.columns('Features', {table: t});
|
|
6
6
|
features.value = [t.col('height'), t.col('weight')];
|
|
7
7
|
|
|
8
8
|
// events
|
|
9
|
-
features.onInput(() => grok.shell.info(features.value.map((col) => col.name).join()));
|
|
9
|
+
features.onInput.subscribe(() => grok.shell.info(features.value.map((col) => col.name).join()));
|
|
10
10
|
|
|
11
11
|
let inputs = [predict, features];
|
|
12
12
|
let container = ui.div();
|
|
@@ -6,25 +6,25 @@ let v = grok.shell.newView('demo: form types');
|
|
|
6
6
|
//To set labels aligned to left add class .ui-form-left
|
|
7
7
|
let form = ui.form([
|
|
8
8
|
ui.h1('Basic form'),
|
|
9
|
-
ui.
|
|
10
|
-
ui.
|
|
11
|
-
ui.
|
|
9
|
+
ui.input.string('First name', {value: 'Arthur'}),
|
|
10
|
+
ui.input.string('Last name', {value: 'Dent'}),
|
|
11
|
+
ui.input.int('Age', {value: 30}),
|
|
12
12
|
]);
|
|
13
13
|
|
|
14
14
|
//Add class .ui-form-wide to make the form wide
|
|
15
15
|
let wideForm = ui.form([
|
|
16
16
|
ui.h1('Wide form'),
|
|
17
|
-
ui.
|
|
18
|
-
ui.
|
|
19
|
-
ui.
|
|
17
|
+
ui.input.string('First name', {value: 'Arthur'}),
|
|
18
|
+
ui.input.string('Last name', {value: 'Dent'}),
|
|
19
|
+
ui.input.int('Age', {value: 30}),
|
|
20
20
|
], 'ui-form-wide');
|
|
21
21
|
|
|
22
22
|
//Condensed form. You can also use .ui-form-condensed
|
|
23
23
|
let narrowForm = ui.narrowForm([
|
|
24
24
|
ui.h1('Condensed form'),
|
|
25
|
-
ui.
|
|
26
|
-
ui.
|
|
27
|
-
ui.
|
|
25
|
+
ui.input.string('First name', {value: 'Arthur'}),
|
|
26
|
+
ui.input.string('Last name', {value: 'Dent'}),
|
|
27
|
+
ui.input.int('Age', {value: 30}),
|
|
28
28
|
]);
|
|
29
29
|
v.append(ui.panel([narrowForm]));
|
|
30
30
|
|
|
@@ -32,4 +32,4 @@ v.append(ui.divV([
|
|
|
32
32
|
form,
|
|
33
33
|
wideForm,
|
|
34
34
|
narrowForm,
|
|
35
|
-
]))
|
|
35
|
+
]));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const view = grok.shell.newView('demo: inputs');
|
|
2
|
+
|
|
3
|
+
const helmValue = 'PEPTIDE1{[D-Pyr].Y.C.A.T.P.F.G.T.S.R.T}$PEPTIDE1,PEPTIDE1,3:R3-12:R2$$$V2.0';
|
|
4
|
+
view.append(ui.inputs([await ui.input.helmAsync('Macromolecule', {value: helmValue})]));
|
|
5
|
+
|
|
6
|
+
view.append(ui.inputs([await grok.functions.call(
|
|
7
|
+
'Helm:helmInput', {name: 'Macromolecule', options: {value: helmValue}})]));
|