@datagrok/api-samples 1.0.7 → 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 -13
- package/scripts/dapi/files.js +14 -13
- 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/filtering/update-filter-state.js +13 -0
- 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/calling.js +1 -1
- 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/performance/all-chembl-structures.js +1 -1
- package/scripts/scripting/files-for-scripting.js +24 -0
- package/scripts/scripting/grok-scripting.js +1 -1
- package/scripts/scripting/package-scripting.js +6 -0
- 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 +121 -22
- package/webpack.config.js +4 -1
- package/scripts/misc/user-data-storage.js +0 -49
- package/scripts/scripting/scripting.js +0 -6
- package/scripts/ui/docking/README.md +0 -16
- /package/{scripts/ui/handlers → to fix}/dynamic-loading.js +0 -0
package/scripts/dapi/files.js
CHANGED
|
@@ -7,33 +7,34 @@
|
|
|
7
7
|
let res = null;
|
|
8
8
|
|
|
9
9
|
// Write files
|
|
10
|
-
await grok.dapi.files.write('
|
|
11
|
-
await grok.dapi.files.writeAsText('
|
|
10
|
+
await grok.dapi.files.write('System:AppData/Samples/testFile.dat', [0, 1, 2]);
|
|
11
|
+
await grok.dapi.files.writeAsText('System:AppData/Samples/testFile.txt', 'testString');
|
|
12
12
|
|
|
13
13
|
// Rename
|
|
14
|
-
await grok.dapi.files.writeAsText('
|
|
15
|
-
await grok.dapi.files.rename('
|
|
14
|
+
await grok.dapi.files.writeAsText('System:AppData/Samples/forRename.txt', 'testString');
|
|
15
|
+
await grok.dapi.files.rename('System:AppData/Samples/forRename.txt', 'renamed.txt');
|
|
16
16
|
|
|
17
17
|
// Read files
|
|
18
|
-
res = await grok.dapi.files.readAsBytes('
|
|
18
|
+
res = await grok.dapi.files.readAsBytes('System:AppData/Samples/testFile.dat');
|
|
19
19
|
console.log(`readAsBytes: ${res}`);
|
|
20
|
-
res = await grok.dapi.files.readAsText('
|
|
20
|
+
res = await grok.dapi.files.readAsText('System:AppData/Samples/testFile.txt');
|
|
21
21
|
console.log(`readAsText: ${res}`);
|
|
22
|
-
res = await grok.dapi.files.exists('
|
|
22
|
+
res = await grok.dapi.files.exists('System:AppData/Samples/testFile.dat');
|
|
23
23
|
console.log(`testFile.dat exists: ${res}`);
|
|
24
24
|
|
|
25
25
|
// Search files
|
|
26
26
|
let recursive = true;
|
|
27
|
-
let searchPattern = '
|
|
28
|
-
res = await grok.dapi.files.list('
|
|
27
|
+
let searchPattern = 'test';
|
|
28
|
+
res = await grok.dapi.files.list('System:AppData/Samples/', recursive, searchPattern);
|
|
29
29
|
console.log(`list: ${res}`);
|
|
30
30
|
|
|
31
31
|
// Move files
|
|
32
|
-
await grok.dapi.files.move(['
|
|
33
|
-
res = await grok.dapi.files.exists('
|
|
32
|
+
await grok.dapi.files.move(['System:AppData/Samples/testFile.txt'], 'Samples/geo');
|
|
33
|
+
res = await grok.dapi.files.exists('System:AppData/Samples/geo/testFile.txt');
|
|
34
34
|
console.log(`testFile.txt was moved to geo: ${res}`);
|
|
35
35
|
|
|
36
36
|
// Delete files
|
|
37
|
-
await grok.dapi.files.delete('
|
|
38
|
-
await grok.dapi.files.delete('
|
|
37
|
+
await grok.dapi.files.delete('System:AppData/Samples/geo/testFile.txt');
|
|
38
|
+
await grok.dapi.files.delete('System:AppData/Samples/testFile.dat');
|
|
39
|
+
await grok.dapi.files.delete('System:AppData/Samples/renamed.txt');
|
|
39
40
|
})();
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//name: sticky-meta-1-tags
|
|
2
|
+
//tags: demo
|
|
3
|
+
//language: javascript
|
|
4
|
+
|
|
5
|
+
// uniqueName ensures that created sticky meta configuration will be unique.
|
|
6
|
+
const uniqueName = (prefix) => 'apisamples-' + prefix + '-' + (Math.random() + 1).toString(36).substring(7);
|
|
7
|
+
|
|
8
|
+
// In this sample we will attach metadata to experiments
|
|
9
|
+
// They will be identified through strings: [experiment 1, experiment 2, ..., experiment 6].
|
|
10
|
+
const experiments = DG.Column.fromStrings('experiment', Array.from(Array(6).keys()).map((idx) => 'experiment ' + (idx + 1)));
|
|
11
|
+
|
|
12
|
+
// Objects that store sticky meta should be identifiable through tags or semtypes.
|
|
13
|
+
// We will use tag named "source".
|
|
14
|
+
const experimentTag = uniqueName('experiment-tag');
|
|
15
|
+
experiments.setTag('source', experimentTag);
|
|
16
|
+
|
|
17
|
+
// Authors of experiments.
|
|
18
|
+
// We will save them as metadata related to experiment.
|
|
19
|
+
const authors = DG.DataFrame.fromCsv(
|
|
20
|
+
`name,email,age
|
|
21
|
+
Joey,joey@datagrok.ai,25
|
|
22
|
+
Ross,ross@datagrok.ai,26
|
|
23
|
+
Rachel,rachel@datagrok.ai,24
|
|
24
|
+
Chandler,chandler@datagrok.ai,26
|
|
25
|
+
Monica,monica@datagrok.ai,24
|
|
26
|
+
Phoebe,phoebe@datagrok.ai,26`
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// Create a schema named Author.
|
|
31
|
+
// Author is connected with experiments and has 3 properties of different types
|
|
32
|
+
const schema = await grok.dapi.stickyMeta.createSchema(
|
|
33
|
+
uniqueName('Author'),
|
|
34
|
+
[{name: uniqueName('Experiment'), matchBy: 'source=' + experimentTag}],
|
|
35
|
+
[{name: 'name', type: 'string'}, {name: 'email', type: 'string'}, {name: 'age', type: 'int'}]
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// Save sticky meta values.
|
|
39
|
+
await grok.dapi.stickyMeta.setAllValues(schema, experiments, authors);
|
|
40
|
+
|
|
41
|
+
// Create test data with tagged column of experiment identifiers.
|
|
42
|
+
const testDf = DG.DataFrame.fromCsv(`experiment
|
|
43
|
+
experiment 1
|
|
44
|
+
experiment 3`
|
|
45
|
+
);
|
|
46
|
+
testDf.columns.byName('experiment').setTag('source', experimentTag);
|
|
47
|
+
|
|
48
|
+
// Fetch sticky meta related to the test dataframe.
|
|
49
|
+
const metaDataframe = await grok.dapi.stickyMeta.getAllValues(schema, testDf.columns.byName('experiment'));
|
|
50
|
+
|
|
51
|
+
// Show the result
|
|
52
|
+
for (var col of metaDataframe.columns)
|
|
53
|
+
testDf.columns.add(col);
|
|
54
|
+
grok.shell.addTableView(testDf);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//name: sticky-meta-2-semtype
|
|
2
|
+
//tags: demo
|
|
3
|
+
//language: javascript
|
|
4
|
+
|
|
5
|
+
// uniqueName ensures that created sticky meta configuration will be unique.
|
|
6
|
+
var uniqueName = (prefix) => 'apisamples-' + prefix + '-' + (Math.random() + 1).toString(36).substring(7);
|
|
7
|
+
|
|
8
|
+
// Create sample dataset of molecules.
|
|
9
|
+
var df = grok.data.testData('molecules', 3);
|
|
10
|
+
|
|
11
|
+
// Create a schema named Date, connected with molecules, and having 1 parameter "int-meta".
|
|
12
|
+
var schema = await grok.dapi.stickyMeta.createSchema(
|
|
13
|
+
uniqueName('int-meta'),
|
|
14
|
+
[{name: uniqueName('Molecule'), matchBy: 'semtype=molecule'}],
|
|
15
|
+
[{name: 'int-meta', type: 'int'}]
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
// Open dataframe in a view.
|
|
19
|
+
var startView = grok.shell.addTableView(df);
|
|
20
|
+
|
|
21
|
+
// We wait for Chem package to apply its semtype detector on an opened dataframe.
|
|
22
|
+
df.onSemanticTypeDetected.subscribe(async (_) => {
|
|
23
|
+
|
|
24
|
+
// Create sample values column. Name of the column matches name of the property.
|
|
25
|
+
var valuesColumn = DG.Column.fromList('int', 'int-meta', [1, 2, 3]);
|
|
26
|
+
|
|
27
|
+
// Save date as sticky meta.
|
|
28
|
+
await grok.dapi.stickyMeta.setAllValues(schema, df.columns.byName('smiles'), DG.DataFrame.fromColumns([valuesColumn]));
|
|
29
|
+
|
|
30
|
+
// Trigger cell redraw to redraw grid so grid shows correct sticky meta indication.
|
|
31
|
+
// This action can be replaced by manual scroll of grid or column width resize.
|
|
32
|
+
startView.grid.invalidate();
|
|
33
|
+
});
|
|
@@ -6,10 +6,11 @@ grok.data.query('Samples:Countries', {}).then((countries) => {
|
|
|
6
6
|
grok.shell.addTableView(countries);
|
|
7
7
|
countries.onCurrentRowChanged.subscribe((_) => {
|
|
8
8
|
grok.data.query('Samples:CustomersInCountry', {country: countries.currentRow['country']}).then((t) => {
|
|
9
|
-
if (customersView === null)
|
|
9
|
+
//if (customersView === null)
|
|
10
10
|
customersView = grok.shell.addTableView(t);
|
|
11
11
|
customersView.dataFrame = t;
|
|
12
12
|
});
|
|
13
|
-
grok.shell.addTableView(
|
|
13
|
+
//grok.shell.addTableView(t);
|
|
14
14
|
})
|
|
15
15
|
});
|
|
16
|
+
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
grok.data.loadTable('https://
|
|
1
|
+
grok.data.loadTable('https://calmcode.io/static/data/bigmac.csv')
|
|
2
2
|
.then(t => grok.shell.addTableView(t));
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// Adds table and search it by id
|
|
2
|
+
|
|
3
|
+
let df = grok.data.demo.demog();
|
|
4
|
+
let view = grok.shell.addTableView(df);
|
|
5
|
+
|
|
6
|
+
const tableInfo = df.getTableInfo();
|
|
7
|
+
const table = await grok.dapi.tables.save(tableInfo);
|
|
8
|
+
let tableSearchRes = await grok.data.openTable(table.id);
|
|
9
|
+
|
|
10
|
+
grok.shell.info(tableSearchRes.name);
|
|
11
|
+
await grok.dapi.tables.delete(table);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
//name: output-layouts
|
|
2
|
+
//language: javascript
|
|
1
3
|
//output: dataframe result {layout: ApiSamples:DemogTableLayout}
|
|
2
4
|
|
|
3
5
|
// Also, you can use layout ID. Create a layout first, then get it's ID or name
|
|
4
6
|
// Make sure you run this script from scripts, not from js examples
|
|
5
|
-
result = grok.data.testData(
|
|
7
|
+
result = grok.data.testData('demog');
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
let dataFrameColumn = DG.Column.dataFrame('tables', 5);
|
|
2
2
|
let t = DG.DataFrame.fromColumns([dataFrameColumn]);
|
|
3
3
|
dataFrameColumn.set(1, grok.data.demo.demog());
|
|
4
|
-
grok.shell.addTableView(t);
|
|
4
|
+
let grid = grok.shell.addTableView(t).grid;
|
|
5
|
+
|
|
6
|
+
grid.col('tables').width = 500;
|
|
7
|
+
grid.props.rowHeight = 300;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// The following example shows tables compare feature.
|
|
2
2
|
//
|
|
3
|
-
// https://datagrok.ai/help/
|
|
3
|
+
// https://datagrok.ai/help/transform/compare-tables
|
|
4
4
|
|
|
5
5
|
let t1 = grok.data.testData('demog', 10000);
|
|
6
6
|
t1.name = 'demog1';
|
|
@@ -15,4 +15,5 @@ t2.set('weight', 2, 80.5);
|
|
|
15
15
|
grok.shell.addTableView(t2);
|
|
16
16
|
|
|
17
17
|
let values = t1.columns.names().filter(name => name !== 'subj');
|
|
18
|
-
grok.data.compareTables(t1, t2, ['subj'], ['subj'], values, values);
|
|
18
|
+
let diffTable = grok.data.compareTables(t1, t2, ['subj'], ['subj'], values, values).diffTable;
|
|
19
|
+
grok.shell.addTableView(diffTable);
|
|
@@ -13,6 +13,6 @@ Zambia, Africa, 1992, 46.1, 8381163, 1210.8846436
|
|
|
13
13
|
`);
|
|
14
14
|
|
|
15
15
|
let view = grok.shell.addTableView(table);
|
|
16
|
-
grok.shell.info(`Format detected on 'gdpPercap': ${table.getCol('gdpPercap').
|
|
17
|
-
grok.shell.info(`Format detected on 'lifeExp': ${table.getCol('lifeExp').
|
|
18
|
-
grok.shell.info(`Max significant digits detected for 'lifeExp': ${table.getCol('lifeExp').
|
|
16
|
+
grok.shell.info(`Format detected on 'gdpPercap': ${table.getCol('gdpPercap').meta.format}`);
|
|
17
|
+
grok.shell.info(`Format detected on 'lifeExp': ${table.getCol('lifeExp').meta.format}`);
|
|
18
|
+
grok.shell.info(`Max significant digits detected for 'lifeExp': ${table.getCol('lifeExp').meta.sourcePrecision}`);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
//tags: DataFrame, Column, construction
|
|
2
2
|
// This is the fastest way of creating numerical columns
|
|
3
|
-
// The following example creates a table with 100 million rows and
|
|
3
|
+
// The following example creates a table with 100 million rows and three columns
|
|
4
4
|
// See also: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Typed_arrays
|
|
5
5
|
|
|
6
6
|
let len = 100000000;
|
|
7
7
|
let ints = new Int32Array(len);
|
|
8
8
|
let floats = new Float32Array(len);
|
|
9
|
+
let floats64 = new Float64Array(len);
|
|
9
10
|
|
|
10
11
|
for (let i = 0; i < len; i++)
|
|
11
12
|
ints[i] = i;
|
|
@@ -13,9 +14,13 @@ for (let i = 0; i < len; i++)
|
|
|
13
14
|
for (let i = 0; i < len; i++)
|
|
14
15
|
floats[i] = i / 10;
|
|
15
16
|
|
|
17
|
+
for (let i = 0; i < len; i++)
|
|
18
|
+
floats64[i] = i + i / len;
|
|
19
|
+
|
|
16
20
|
let table = DG.DataFrame.fromColumns([
|
|
17
21
|
DG.Column.fromInt32Array('ints', ints),
|
|
18
|
-
DG.Column.fromFloat32Array('floats', floats)
|
|
22
|
+
DG.Column.fromFloat32Array('floats', floats),
|
|
23
|
+
DG.Column.fromFloat64Array('floats64', floats64)
|
|
19
24
|
]);
|
|
20
25
|
|
|
21
26
|
grok.shell.addTableView(table);
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const nums = ['>5.13257', '6.016544', '<7.02'];
|
|
2
|
+
const t = DG.DataFrame.fromColumns([
|
|
3
3
|
DG.Column.qnum('qnum', 3).init((i) => DG.Qnum.parse(nums[i]))
|
|
4
4
|
]);
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// NUMBER FORMATS (https://datagrok.ai/help/discover/tags#numbers)
|
|
7
|
+
// The usual formats, such as "0.000" or "#.0000", are supported.
|
|
8
|
+
const columnFormats = {'qnum': '#0.000'};
|
|
9
|
+
const csv = t.toCsv({filteredRowsOnly: true, qualifierAsColumn: true, columnFormats: columnFormats});
|
|
10
|
+
const df1 = DG.DataFrame.fromCsv(csv);
|
|
11
|
+
const tv = grok.shell.addTableView(df1);
|
|
12
|
+
|
|
13
|
+
const grid = tv.grid;
|
|
14
|
+
grid.sort(['qnum'], [false]);
|
|
15
|
+
grid.col('qual(qnum)').visible = false;
|
|
16
|
+
// if grid is specified, row sorting will be applied as well
|
|
17
|
+
console.log(df1.toCsv({visibleColumnsOnly: true}, grid));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const t = grok.data.demo.demog(5);
|
|
2
2
|
console.log(t.toCsv({delimiter: ' - '}));
|
|
@@ -8,7 +8,7 @@ let df = DG.DataFrame.fromColumns([
|
|
|
8
8
|
df.onColumnsAdded
|
|
9
9
|
.subscribe((data) => {
|
|
10
10
|
data.args.columns
|
|
11
|
-
.filter((col) => col.
|
|
11
|
+
.filter((col) => col.meta.formula != null)
|
|
12
12
|
.forEach((col) => grok.shell.info(`Added ${col.name}`));
|
|
13
13
|
});
|
|
14
14
|
|
|
@@ -11,7 +11,7 @@ grok.shell.addTableView(df);
|
|
|
11
11
|
df.onColumnsRemoved
|
|
12
12
|
.subscribe((data) => {
|
|
13
13
|
data.args.columns
|
|
14
|
-
.filter((col) => col.
|
|
14
|
+
.filter((col) => col.meta.formula != null)
|
|
15
15
|
.forEach((col) => grok.shell.info(`Removed calculated column ${col.name}`));
|
|
16
16
|
});
|
|
17
17
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//updating state of opened filter
|
|
2
|
+
let beer = await grok.data.getDemoTable('beer.csv');
|
|
3
|
+
let view = grok.shell.addTableView(beer)
|
|
4
|
+
|
|
5
|
+
setTimeout(function(){
|
|
6
|
+
let filters = view.filters()
|
|
7
|
+
filters.updateOrAdd({
|
|
8
|
+
type: "text",
|
|
9
|
+
column: "Flavor",
|
|
10
|
+
gridNames: ['malt'],
|
|
11
|
+
value: "sour"
|
|
12
|
+
})
|
|
13
|
+
}, 500)
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
// Master-detail table linking feature with dynamic data loading (see also link-tables.js).
|
|
2
2
|
|
|
3
3
|
let tickers = DG.DataFrame.fromCsv(
|
|
4
|
-
`
|
|
5
|
-
|
|
6
|
-
TSLA
|
|
7
|
-
MSFT`);
|
|
4
|
+
`chickweight
|
|
5
|
+
fish`);
|
|
8
6
|
grok.shell.addTableView(tickers);
|
|
9
7
|
|
|
10
8
|
let detailsView = null;
|
|
11
9
|
|
|
12
10
|
tickers.onCurrentRowChanged.subscribe((_) => {
|
|
13
|
-
grok.data.loadTable(`https://
|
|
11
|
+
grok.data.loadTable(`https://calmcode.io/static/data/${tickers.currentRow.ticker}.csv`)
|
|
14
12
|
.then(function (t) {
|
|
15
13
|
if (detailsView === null)
|
|
16
14
|
detailsView = grok.shell.addTableView(t);
|
|
@@ -9,11 +9,11 @@ let col = await df.columns.addNewCalculated('new', '0');
|
|
|
9
9
|
grok.shell.addTableView(df);
|
|
10
10
|
|
|
11
11
|
// Changes a column's formula programmatically. Note that setting a new value
|
|
12
|
-
// to
|
|
12
|
+
// to column.meta.formula will not trigger re-calculation of values in the column.
|
|
13
13
|
// See also:
|
|
14
14
|
// https://dev.datagrok.ai/js/samples/data-frame/modification/calculated-columns/apply-formula
|
|
15
15
|
// https://dev.datagrok.ai/js/samples/data-frame/events/calculated-columns/update
|
|
16
16
|
col = await col.applyFormula('${x}+${y}-${z}');
|
|
17
17
|
|
|
18
18
|
// Opens a dialog to edit a calculated column
|
|
19
|
-
col.dialogs.editFormula();
|
|
19
|
+
col.meta.dialogs.editFormula();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//tags: DataFrame, Column, modification
|
|
2
|
+
|
|
3
|
+
// Smallest number > 1 representable as 64 bit floating point number precisely
|
|
4
|
+
// See https://en.wikipedia.org/wiki/Double-precision_floating-point_format for more details
|
|
5
|
+
let preciseNumber = 1.0000000000000002;
|
|
6
|
+
|
|
7
|
+
let floats32 = new Float32Array(1);
|
|
8
|
+
let floats64 = new Float64Array(1);
|
|
9
|
+
floats32[0] = preciseNumber;
|
|
10
|
+
floats64[0] = preciseNumber;
|
|
11
|
+
|
|
12
|
+
let table = DG.DataFrame.fromColumns([
|
|
13
|
+
DG.Column.fromFloat32Array('compact_floats', floats32),
|
|
14
|
+
DG.Column.fromFloat64Array('precise_floats', floats64)
|
|
15
|
+
]);
|
|
16
|
+
|
|
17
|
+
console.log(table.get('compact_floats', 0)); // 1
|
|
18
|
+
console.log(table.get('precise_floats', 0)); // 1.0000000000000002
|
|
19
|
+
|
|
20
|
+
// Bump float column to double precision
|
|
21
|
+
table.columns.byName('compact_floats').doublePrecision = true;
|
|
22
|
+
table.set('compact_floats', 0, preciseNumber);
|
|
23
|
+
|
|
24
|
+
console.log(table.get('compact_floats', 0)); // 1.0000000000000002
|
|
25
|
+
console.log(table.get('precise_floats', 0)); // 1.0000000000000002
|
|
26
|
+
|
|
@@ -25,8 +25,8 @@ demog.selection.set(5, false);
|
|
|
25
25
|
demog.selection.findNext(0, false);
|
|
26
26
|
|
|
27
27
|
// tags
|
|
28
|
-
demog.columns.byName('height').
|
|
29
|
-
demog.columns.byName('weight').
|
|
30
|
-
foo = demog.columns.byName('height').
|
|
28
|
+
demog.columns.byName('height').meta.units = 'm';
|
|
29
|
+
demog.columns.byName('weight').meta.units = 'kg';
|
|
30
|
+
foo = demog.columns.byName('height').meta.units;
|
|
31
31
|
|
|
32
32
|
grok.shell.addTableView(demog);
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
const df = await grok.data.getDemoTable('chem/smiles.csv');
|
|
4
4
|
const view = grok.shell.addTableView(df);
|
|
5
5
|
|
|
6
|
-
grok.events.onFormCreating.subscribe((data) => {
|
|
7
|
-
data.columns = data.
|
|
6
|
+
grok.events.onFormCreating.subscribe((data) => {
|
|
7
|
+
data.columns = data.filter((col) => col.semType === DG.SEMTYPE.MOLECULE);
|
|
8
8
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
//tags: ViewLayout
|
|
2
1
|
// open a table, then do View | Layout | Clone
|
|
3
2
|
|
|
4
|
-
function
|
|
5
|
-
grok.shell.info(`${action}: ${
|
|
3
|
+
function showInfo(action, info) {
|
|
4
|
+
grok.shell.info(`${action}: ${info.viewState}`);
|
|
6
5
|
}
|
|
7
6
|
|
|
8
|
-
grok.events.onViewLayoutGenerated.subscribe((
|
|
7
|
+
grok.events.onViewLayoutGenerated.subscribe((info) => showInfo('generated', info));
|
|
9
8
|
|
|
10
|
-
grok.events.onViewLayoutApplying.subscribe((
|
|
9
|
+
grok.events.onViewLayoutApplying.subscribe((info) => showInfo('applying', info));
|
|
11
10
|
|
|
12
|
-
grok.events.onViewLayoutApplied.subscribe((
|
|
11
|
+
grok.events.onViewLayoutApplied.subscribe((info) => showInfo('applied', info));
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//name: viewer-data-events
|
|
2
|
+
//language: javascript
|
|
3
|
+
//description: Handling viewer events: onDataEvent, onDataSelected, onDataHovered, onDataRowClicked.
|
|
4
|
+
let view = grok.shell.addTableView(grok.data.demo.demog());
|
|
5
|
+
let viewers = [view.scatterPlot(), view.histogram(), view.pieChart(), view.barChart(), view.pcPlot()];
|
|
6
|
+
|
|
7
|
+
for (let v of viewers)
|
|
8
|
+
v.onDataEvent.subscribe((e) =>
|
|
9
|
+
grok.shell.info(e.type + ': ' + (e.row ? (e.row + ' row') : (e.bitset.trueCount + ' rows'))));
|
|
10
|
+
|
|
11
|
+
grok.shell.info('Hover or click data to see event details. Different viewers provide different details.');
|
|
@@ -4,7 +4,7 @@
|
|
|
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/
|
|
7
|
+
// https://github.com/datagrok-ai/public/blob/master/packages/Samples/scripts/r/r_dup.R
|
|
8
8
|
grok.functions
|
|
9
9
|
.call("Samples:RDup", {s: "Foo"})
|
|
10
10
|
.then((res) => {
|
|
@@ -6,8 +6,13 @@ let outputs = f.outputs.map(output => output.propertyType + ' ' + output.name);
|
|
|
6
6
|
grok.shell.info(f.name + '(' + inputs + ')' + ': ' + outputs);
|
|
7
7
|
|
|
8
8
|
// simple way: f.apply
|
|
9
|
+
// Any function can be called asynchronously
|
|
9
10
|
f.apply({x: 0.5}).then((result) => grok.shell.info(result));
|
|
10
11
|
|
|
12
|
+
// If we know that this is sync function, AND it's either a core function or a plugin is loaded already,
|
|
13
|
+
// then we can call it synchronously using applySync:
|
|
14
|
+
grok.shell.info('Sync call: ' + f.applySync({x: 0.5}));
|
|
15
|
+
|
|
11
16
|
// more complex: preparing a FuncCall that lets you track inputs and outputs, intercept execution, etc
|
|
12
17
|
let fc = f.prepare({"x": 0.5});
|
|
13
18
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Reusing core grid renderers
|
|
2
2
|
|
|
3
3
|
let view = grok.shell.addTableView(grok.data.demo.molecules());
|
|
4
|
-
view.dataFrame.col('logD').colors.setLinear();
|
|
4
|
+
view.dataFrame.col('logD').meta.colors.setLinear();
|
|
5
5
|
let canvas = ui.canvas(300, 200);
|
|
6
6
|
|
|
7
7
|
view.grid.onCurrentCellChanged.subscribe((gridCell) =>
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Ability to render values from other columns (useful for hyperlinks, etc)
|
|
2
|
+
// Not that other than formatting, the column would still
|
|
3
|
+
// work just like the regular column when sorting, editing, etc
|
|
4
|
+
const view = grok.shell.addTableView( grok.data.demo.demog(5));
|
|
5
|
+
const df =view.dataFrame;
|
|
6
|
+
df.getCol('race').tags['%formatFormula'] = '${sex} text [${age}](https://google.com/search?q=${race})';
|
|
7
|
+
|
|
@@ -9,9 +9,9 @@ grok.shell.addTableView(df);
|
|
|
9
9
|
|
|
10
10
|
// Setting the column tags
|
|
11
11
|
|
|
12
|
-
df.col('open in new tab').
|
|
13
|
-
df.col('open in context panel').
|
|
14
|
-
df.col('custom').
|
|
12
|
+
df.col('open in new tab').meta.linkClickBehavior = DG.LINK_CLICK_BEHAVIOR.OPEN_IN_NEW_TAB;
|
|
13
|
+
df.col('open in context panel').meta.linkClickBehavior = DG.LINK_CLICK_BEHAVIOR.OPEN_IN_CONTEXT_PANEL;
|
|
14
|
+
df.col('custom').meta.linkClickBehavior = DG.LINK_CLICK_BEHAVIOR.CUSTOM;
|
|
15
15
|
|
|
16
16
|
// Displaying the clicked link - global and local grid events
|
|
17
17
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Demonstrates markdown-like link in grid
|
|
2
|
+
|
|
3
|
+
const df = DG.DataFrame.fromColumns([
|
|
4
|
+
DG.Column.fromList(DG.TYPE.STRING, 'markdown link', ['To learn more about [Datagrok](https://datagrok.ai/) open the [platform help](https://datagrok.ai/help/home)']),
|
|
5
|
+
]);
|
|
6
|
+
grok.shell.addTableView(df);
|
|
@@ -4,4 +4,7 @@ grid.onCellPrepare(function (gc) {
|
|
|
4
4
|
let xy = `${gc.gridColumn.name}_${gc.gridRow}`;
|
|
5
5
|
counts[xy] = counts[xy] == null ? 1 : counts[xy] + 1;
|
|
6
6
|
gc.customText = `${counts[xy]}`;
|
|
7
|
-
});
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// here's how you can refresh a specific cell
|
|
10
|
+
setInterval(() => { grid.cell('race', 4).render() }, 1000);
|
package/scripts/grid/{color-coding-conditional.js → color-coding/color-coding-conditional.js}
RENAMED
|
@@ -1,17 +1,24 @@
|
|
|
1
|
+
// Set color coding
|
|
2
|
+
|
|
1
3
|
let t = grok.data.demo.demog();
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
t.col('height').
|
|
5
|
+
// Linear or conditional color coding for numerical or datetime columns
|
|
6
|
+
t.col('height').meta.colors.setConditional({"20-170": "#00FF00", "170-190": "#220505"});
|
|
7
|
+
t.col('age').meta.colors.setLinear([DG.Color.orange, DG.Color.green]);
|
|
8
|
+
t.col('started').meta.colors.setLinear([DG.Color.white, DG.Color.red]);
|
|
9
|
+
t.col('weight').meta.colors.setConditional({'<100': DG.Color.green, '100-200': '#ff0000'});
|
|
10
|
+
|
|
11
|
+
// Categorical for string columns
|
|
12
|
+
t.col('site').meta.colors.setCategorical({'New York': DG.Color.orange});
|
|
13
|
+
|
|
14
|
+
// Additional matching options for categorical
|
|
15
|
+
t.col('race').meta.colors.setCategorical(
|
|
16
|
+
{'sian': DG.Color.orange},
|
|
17
|
+
{fallbackColor: 'black', matchType: "regex"});
|
|
5
18
|
|
|
6
|
-
|
|
7
|
-
t.col('age').tags[DG.TAGS.COLOR_CODING_LINEAR] = `[${DG.Color.orange}, ${DG.Color.green}]`;
|
|
19
|
+
grok.shell.addTableView(t);
|
|
8
20
|
|
|
21
|
+
// Get color coding programmatically
|
|
9
22
|
grok.shell.info(`Column 'subj' color coding: ${t.col('subj').meta.colors.getType()}`); // Off
|
|
10
23
|
grok.shell.info(`Column 'height' color coding: ${t.col('height').meta.colors.getType()}`); // Conditional
|
|
11
24
|
grok.shell.info(`Column 'age' color coding: ${t.col('age').meta.colors.getType()}`); // Linear
|
|
12
|
-
|
|
13
|
-
t.col('site').meta.colors.setCategorical({'New York': DG.Color.orange});
|
|
14
|
-
t.col('started').meta.colors.setLinear([DG.Color.white, DG.Color.red]);
|
|
15
|
-
t.col('weight').meta.colors.setConditional({'<100': DG.Color.green, '100-200': '#ff0000'});
|
|
16
|
-
|
|
17
|
-
grok.shell.addTableView(t);
|