@datagrok/api-samples 1.0.5 → 1.0.7

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 (165) hide show
  1. package/.eslintrc.json +47 -0
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +11 -9
  4. package/dist/package-test.js +2 -519
  5. package/dist/package.js +2 -30
  6. package/layouts/demog-table-layout.json +236 -0
  7. package/package.json +15 -13
  8. package/scripts/dapi/files.js +12 -12
  9. package/scripts/dapi/groups.js +3 -0
  10. package/scripts/dapi/users.js +1 -1
  11. package/scripts/data-access/db/db-edit.js +27 -0
  12. package/scripts/data-access/db-master-details-manual.js +3 -3
  13. package/scripts/data-access/dynamic-query.js +13 -0
  14. package/scripts/data-access/output-layouts.js +5 -0
  15. package/scripts/data-access/parameterized-query.js +3 -3
  16. package/scripts/data-frame/bitset/similarity-metrics.js +3 -3
  17. package/scripts/data-frame/construction/create-from-csv-format.js +3 -3
  18. package/scripts/data-frame/events/calculated-columns/update.js +1 -1
  19. package/scripts/data-frame/join-link/join-tables.js +5 -6
  20. package/scripts/data-frame/modification/remove-where.js +8 -0
  21. package/scripts/data-frame/row-matching/patterns.js +1 -3
  22. package/scripts/domains/chem/chem-benchmark.js +26 -26
  23. package/scripts/domains/chem/descriptors.js +1 -2
  24. package/scripts/domains/chem/diversity-search.js +3 -5
  25. package/scripts/domains/chem/inspect-molecule.js +1 -1
  26. package/scripts/domains/chem/mcs.js +2 -3
  27. package/scripts/domains/chem/mol-atoms-bonds.js +1 -2
  28. package/scripts/domains/chem/mol-panel.js +0 -1
  29. package/scripts/domains/chem/mol-rendering-canvas.js +4 -6
  30. package/scripts/domains/chem/mol-rendering.js +0 -1
  31. package/scripts/domains/chem/r-group.js +3 -5
  32. package/scripts/domains/chem/similarity-scoring-scores.js +0 -3
  33. package/scripts/domains/chem/similarity-scoring-sorted.js +0 -3
  34. package/scripts/domains/chem/substructure-search-benchmark.js +5 -8
  35. package/scripts/domains/chem/substructure-search-smarts-molfile-als.js +6 -9
  36. package/scripts/domains/chem/substructure-search-smarts.js +4 -7
  37. package/scripts/domains/chem/substructure-search.js +1 -4
  38. package/scripts/domains/data-science/predictive-model.js +2 -3
  39. package/scripts/functions/caching-results.js +36 -0
  40. package/scripts/functions/calling.js +2 -2
  41. package/scripts/functions/discover-functions.js +1 -1
  42. package/scripts/functions/func-call.js +18 -0
  43. package/scripts/functions/progress.js +2 -7
  44. package/scripts/grid/advanced/charts-in-cells.js +16 -14
  45. package/scripts/grid/advanced/link-click.js +19 -0
  46. package/scripts/grid/advanced/pinned-columns.js +7 -0
  47. package/scripts/grid/advanced/pinned-rows.js +8 -0
  48. package/scripts/grid/advanced/visible-cells.js +3 -4
  49. package/scripts/grid/scroll-to-pixels.js +9 -4
  50. package/scripts/misc/audit/activity-today.js +3 -3
  51. package/scripts/misc/audit/errors-summary.js +2 -4
  52. package/scripts/misc/audit/test-tracking.js +2 -4
  53. package/scripts/misc/audit/users-today.js +6 -7
  54. package/scripts/misc/package-credentials.js +2 -4
  55. package/scripts/misc/paint/paint.js +14 -0
  56. package/scripts/misc/sdtm.js +8 -10
  57. package/scripts/misc/utils/hide-empty-columns.js +19 -0
  58. package/scripts/scripting/grok-scripting.js +1 -1
  59. package/scripts/scripting/scripting.js +2 -2
  60. package/scripts/shell/current-object.js +1 -1
  61. package/scripts/shell/last-error.js +0 -4
  62. package/scripts/shell/windows/shell-windows.js +6 -0
  63. package/scripts/ui/components/balloons.js +9 -0
  64. package/scripts/ui/components/breadcrumbs.js +4 -0
  65. package/scripts/ui/{elements → components}/color-palettes.js +4 -4
  66. package/scripts/ui/components/drop-down.js +7 -0
  67. package/scripts/ui/components/html-tables.js +27 -0
  68. package/scripts/ui/components/loading-indicators.js +4 -6
  69. package/scripts/ui/components/menu-customization.js +18 -0
  70. package/scripts/ui/components/property-grid.js +10 -10
  71. package/scripts/ui/{layouts → containers}/splitters.js +3 -3
  72. package/scripts/ui/css.js +20 -0
  73. package/scripts/ui/docking/README.md +3 -3
  74. package/scripts/ui/handlers/handlers.js +1 -1
  75. package/scripts/ui/inputs/advanced/all-input-types.js +47 -0
  76. package/scripts/ui/inputs/{for-properties.js → advanced/for-properties.js} +17 -2
  77. package/scripts/ui/inputs/advanced/input-form.js +10 -0
  78. package/scripts/ui/inputs/forms.js +35 -0
  79. package/scripts/ui/inputs/grid-input.js +14 -0
  80. package/scripts/ui/inputs/inputs.js +24 -0
  81. package/scripts/ui/{elements/inputs → inputs}/table-input.js +1 -2
  82. package/scripts/ui/inputs/tags-input.js +12 -0
  83. package/scripts/ui/inputs/typeahead-input.js +19 -0
  84. package/scripts/ui/interactivity/hints.js +25 -0
  85. package/scripts/ui/interactivity/wizard-hints.js +15 -0
  86. package/scripts/ui/viewers/advanced/sketch-form.js +9 -0
  87. package/scripts/ui/viewers/custom-scatterplot-rendering.js +1 -1
  88. package/scripts/ui/viewers/custom-viewer-properties.js +5 -5
  89. package/scripts/ui/viewers/filters/custom-filters.js +8 -3
  90. package/scripts/ui/viewers/js viewers/chord-viewer.js +3 -0
  91. package/scripts/ui/viewers/js viewers/globe-viewer.js +13 -0
  92. package/scripts/ui/viewers/js viewers/radar-viewer.js +9 -0
  93. package/scripts/ui/viewers/js viewers/sankey-viewer.js +4 -0
  94. package/scripts/ui/viewers/js viewers/sunburst-viewer.js +3 -0
  95. package/scripts/ui/viewers/js viewers/surface-plot.js +2 -0
  96. package/scripts/ui/viewers/js viewers/timelines-viewer.js +3 -0
  97. package/scripts/ui/viewers/js viewers/tree-viewer.js +3 -0
  98. package/scripts/ui/viewers/js viewers/word-cloud.js +5 -0
  99. package/scripts/ui/viewers/trellis-plot-with-summary-viewer.js +14 -0
  100. package/scripts/ui/viewers/types/form-advanced.js +7 -0
  101. package/scripts/ui/views/currently-open-views.js +5 -5
  102. package/src/package-test.ts +31 -1
  103. package/tsconfig.json +1 -1
  104. package/scripts/misc/audit/errors.js +0 -4
  105. package/scripts/misc/audit/event-types-summary.js +0 -4
  106. package/scripts/misc/audit/rolling-events.js +0 -11
  107. package/scripts/ui/apps/color-checker.js +0 -328
  108. package/scripts/ui/components/panels.js +0 -19
  109. package/scripts/ui/elements/html-tables.js +0 -24
  110. package/scripts/ui/elements/inputs/inputs.js +0 -46
  111. package/scripts/ui/layouts/templates/2 Column.js +0 -14
  112. package/scripts/ui/layouts/templates/3 Column.js +0 -15
  113. package/scripts/ui/layouts/templates/Flex box.js +0 -16
  114. package/scripts/ui/layouts/templates/Fluid layout.js +0 -19
  115. package/scripts/ui/layouts/templates/Gallery grid.js +0 -18
  116. package/scripts/ui/layouts/templates/Splitter (1 Column 2 Row).js +0 -19
  117. package/scripts/ui/layouts/templates/Splitter (2 Column).js +0 -16
  118. package/scripts/ui/layouts/templates/Splitter (2 Row).js +0 -18
  119. package/scripts/ui/layouts/templates/Splitter (2-3 Column).js +0 -23
  120. package/scripts/ui/layouts/templates/Tabs 2 column.js +0 -19
  121. package/scripts/ui/layouts/templates/Tabs navbar.js +0 -16
  122. package/scripts/ui/viewers/types/google-map.js +0 -5
  123. package/scripts/ux/Dialogs/add-new-column-dlg.js +0 -58
  124. package/scripts/ux/Dialogs/link-table-dlg.js +0 -23
  125. package/scripts/ux/Filters/data-filtering.js +0 -99
  126. package/scripts/ux/Input forms/form-types.js +0 -133
  127. package/scripts/ux/Input forms/misc.js +0 -52
  128. package/scripts/ux/Interactivity/hints.js +0 -22
  129. package/scripts/ux/Layouts/example-1.js +0 -50
  130. package/scripts/ux/Layouts/example-2.js +0 -63
  131. package/scripts/ux/Layouts/example-3.js +0 -192
  132. package/scripts/ux/Layouts/example-4.js +0 -51
  133. package/scripts/ux/Managing Collections/datasource-view.js +0 -47
  134. package/scripts/ux/Views/property-panel.js +0 -120
  135. package/scripts/ux/Views/toolbar.js +0 -146
  136. package/scripts/ux/Views/toolbox.js +0 -124
  137. /package/scripts/ui/{elements → components}/buttons.js +0 -0
  138. /package/scripts/ui/{elements → components}/icons.js +0 -0
  139. /package/scripts/ui/{elements → components}/image.js +0 -0
  140. /package/scripts/ui/{elements → components}/list.js +0 -0
  141. /package/scripts/ui/{elements → components}/range-slider.js +0 -0
  142. /package/scripts/ui/{cards → components}/summary-card.js +0 -0
  143. /package/scripts/ui/{elements → components}/typography.js +0 -0
  144. /package/scripts/ui/{layouts → containers}/blocks.js +0 -0
  145. /package/scripts/ui/{layouts → containers}/box.js +0 -0
  146. /package/scripts/ui/{layouts → containers}/containers.js +0 -0
  147. /package/scripts/ui/{layouts → containers}/flexbox.js +0 -0
  148. /package/scripts/ui/{layouts → containers}/panels.js +0 -0
  149. /package/scripts/ui/inputs/{custom-inputs.js → advanced/custom-inputs.js} +0 -0
  150. /package/scripts/ui/inputs/{for-columns.js → advanced/for-columns.js} +0 -0
  151. /package/scripts/ui/inputs/{input-events.js → advanced/input-events.js} +0 -0
  152. /package/scripts/ui/inputs/{master-details.js → advanced/master-details.js} +0 -0
  153. /package/scripts/ui/{elements/inputs → inputs}/choice-input.js +0 -0
  154. /package/scripts/ui/{elements/inputs → inputs}/column-combo-box.js +0 -0
  155. /package/scripts/ui/{elements/inputs → inputs}/column-inputs.js +0 -0
  156. /package/scripts/ui/{elements/inputs → inputs}/inputs-events.js +0 -0
  157. /package/scripts/ui/{elements/inputs → inputs}/inputs-extended.js +0 -0
  158. /package/scripts/ui/{elements/inputs → inputs}/molecule-input.js +0 -0
  159. /package/scripts/{ux/Interactivity → ui/interactivity}/drag-and-drop.js +0 -0
  160. /package/scripts/{ux/Rendering → ui/rendering}/render-items.js +0 -0
  161. /package/scripts/ui/{components/tooltips → tooltips}/row-group-tooltips.js +0 -0
  162. /package/scripts/ui/{components/tooltips → tooltips}/tooltip-events.js +0 -0
  163. /package/scripts/ui/{components/tooltips → tooltips}/tooltips.js +0 -0
  164. /package/scripts/{ux/Navigations → ui/views}/navigation.js +0 -0
  165. /package/scripts/{ux/Managing Collections → ui/views}/virtual-view.js +0 -0
@@ -1,16 +1,14 @@
1
- //name: chemBenchmark
2
- //language: javascript
3
-
4
1
  // https://stackoverflow.com/a/47593316
2
+
5
3
  function mulberry32(a) {
6
- return function() {
7
- var t = a += 0x6D2B79F5;
8
- t = Math.imul(t ^ t >>> 15, t | 1);
9
- t ^= t + Math.imul(t ^ t >>> 7, t | 61);
10
- return ((t ^ t >>> 14) >>> 0) / 4294967296;
11
- }
4
+ return function() {
5
+ let t = a += 0x6D2B79F5;
6
+ t = Math.imul(t ^ t >>> 15, t | 1);
7
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
8
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
9
+ };
12
10
  }
13
- var rand = mulberry32(42); // seed = 42
11
+ let rand = mulberry32(42); // seed = 42
14
12
 
15
13
  const randomInt = (min, max) => min + Math.floor((max - min) * rand());
16
14
  const range = (l, r) => new Array(r - l).fill().map((_, k) => k + l);
@@ -18,7 +16,7 @@ const range = (l, r) => new Array(r - l).fill().map((_, k) => k + l);
18
16
  function getIdxRandomSubset(N, n) {
19
17
  let arr = range(0, N);
20
18
  let shuffled = arr.slice(0);
21
- let i = arr.length, temp, index;
19
+ let i = arr.length; let temp; let index;
22
20
  while (i--) {
23
21
  index = randomInt(0, i + 1);
24
22
  temp = shuffled[index];
@@ -39,7 +37,7 @@ let caseCntr = 0;
39
37
  async function testCase(title, f) {
40
38
  let msg = await DG.timeAsync(++caseCntr + '. ' + title, f);
41
39
  if (typeof msg === 'string')
42
- console.log(" " + msg);
40
+ console.log(' ' + msg);
43
41
  }
44
42
 
45
43
  (async () => {
@@ -73,26 +71,26 @@ async function testCase(title, f) {
73
71
 
74
72
  rowsInd = getIdxRandomSubarray(nSearch, nRender);
75
73
  await testCase(`Rendering a ${rowsInd.length} random molecules`, () => {
76
- for (i of rowsInd) {
74
+ for (i of rowsInd)
77
75
  render(i);
78
- }
76
+
79
77
  });
80
78
 
81
79
  rowsInd = getIdxRandomSubarray(nSearch, nScroll);
82
80
  await testCase(`Horizontal scrolling (${rowsInd.length} random molecules, ${tScroll} times)`, () => {
83
81
  for (let t = 0; t < tScroll; ++t) {
84
- for (let i of rowsInd) {
82
+ for (let i of rowsInd)
85
83
  render(i);
86
- }
84
+
87
85
  }
88
86
  });
89
87
 
90
88
  rowsInd = getIdxRandomSubarray(nSearch, nScroll + tScroll);
91
89
  await testCase(`Vertical scrolling (${nScroll} random molecules, ${tScroll} times)`, () => {
92
90
  for (let t = 0; t < tScroll; ++t) {
93
- for (let i of rowsInd.slice(t, t + nScroll)) {
91
+ for (let i of rowsInd.slice(t, t + nScroll))
94
92
  render(i);
95
- }
93
+
96
94
  }
97
95
  });
98
96
 
@@ -100,7 +98,7 @@ async function testCase(title, f) {
100
98
  'c1ccccc1', // Benzene https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL277500/
101
99
  'CC(=O)Oc1ccccc1C(=O)O', // Aspirin https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL25/
102
100
  'CCCCCCCCCCCCCCCCCC(=O)O', // Stearic acid https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL46403/
103
- 'NCCCC[C@H](N)C(=O)O' // Lusine https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL8085/
101
+ 'NCCCC[C@H](N)C(=O)O', // Lusine https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL8085/
104
102
  ];
105
103
 
106
104
  const searchForNames = ['Benzene', 'Aspirin', 'Stearic acid', 'Lusine'];
@@ -109,17 +107,20 @@ async function testCase(title, f) {
109
107
  await grok.chem.searchSubstructure(col));
110
108
 
111
109
 
112
- for (let i = 0; i < searchFor.length; ++i)
110
+ for (let i = 0; i < searchFor.length; ++i) {
113
111
  await testCase(`Substructure search, searching ${searchForNames[i]} in ${nSearch} molecules`, async () => {
114
- let s = await grok.chem.searchSubstructure(col, searchFor[i]); return `Found ${s.trueCount} molecules for ${searchFor[i]}`; });
112
+ let s = await grok.chem.searchSubstructure(col, searchFor[i]);
113
+ return `Found ${s.trueCount} molecules for ${searchFor[i]}`;
114
+ });
115
+ }
115
116
 
116
117
  await testCase(`Similarity scoring, building a library of ${col.length} molecules`, async () =>
117
118
  await grok.chem.getSimilarities(col));
118
119
  const queryIdx = getIdxRandomSubset(nSearch, nSample);
119
120
  await testCase(`Similarity scoring, search for ${queryIdx.length} samples in ${nSearch} molecules`, async () => {
120
- for (let i of queryIdx) {
121
+ for (let i of queryIdx)
121
122
  await grok.chem.getSimilarities(col, col.get(i));
122
- }
123
+
123
124
  });
124
125
 
125
126
  await testCase(`Substructure search (server), searching benzene in ${nSearch} molecules`, async () =>
@@ -128,10 +129,9 @@ async function testCase(title, f) {
128
129
  await grok.chem.searchSubstructureServer(col, searchFor[1]), false);
129
130
 
130
131
  /*
131
- await testCase(`Similarity scoring (server), search for ${queryIdx.length} samples in ${nSearch} molecules`, async () => {
132
+ await testCase(`Similarity scoring (server), search for ${
133
+ queryIdx.length} samples in ${nSearch} molecules`, async () => {
132
134
  await grok.chem.findSimilarServer(col, searchFor[0]);
133
135
  });
134
136
  */
135
-
136
-
137
137
  })();
@@ -1,9 +1,8 @@
1
1
  // An example of using diversity search.
2
- //
3
2
  // https://datagrok.ai/help/domains/chem/descriptors
4
3
 
5
4
  grok.chem.descriptors(grok.data.testData('molecules', 100), 'smiles', ['MolWt', 'Lipinski'])
6
- .then(function (table) {
5
+ .then(function(table) {
7
6
  grok.shell.addTableView(table);
8
7
  });
9
8
 
@@ -1,9 +1,7 @@
1
1
  // An example of using diversity search.
2
- //
3
2
  // https://datagrok.ai/help/domains/chem/diversity-search
4
3
 
5
4
  grok.chem.diversitySearch(grok.data.testData('molecules', 100).col('smiles'))
6
- .then(function (mols) {
7
- let col = DG.Column.fromStrings('smiles', mols);
8
- grok.shell.addTableView(DG.DataFrame.fromColumns([col]));
9
- });
5
+ .then(function(mols) {
6
+ grok.shell.addTableView(mols);
7
+ });
@@ -1 +1 @@
1
- grok.shell.o = DG.SemanticValue.fromValueType('Fc1cc(Cl)ccc1Br', 'Molecule')
1
+ grok.shell.o = DG.SemanticValue.fromValueType('Fc1cc(Cl)ccc1Br', 'Molecule');
@@ -1,6 +1,5 @@
1
1
  // An example of getting Maximum Common Substructure (MCS).
2
2
 
3
3
  grok.data.loadTable('https://public.datagrok.ai/demo/sar_small.csv')
4
- .then(t => grok.chem.mcs(t.col('smiles'))
5
- .then(mcs => grok.shell.info(mcs)));
6
-
4
+ .then(t => grok.chem.mcs(t, 'smiles')
5
+ .then(mcs => grok.shell.info(mcs)));
@@ -1,5 +1,4 @@
1
1
  // Atom manipulations
2
- //
3
2
  // Original example: http://www.cheminfo.org/Chemistry/Cheminformatics/OpenChemLib_js/index.html
4
3
  // For more details, visit https://github.com/cheminfo/openchemlib-js
5
4
 
@@ -31,7 +30,7 @@ for (let i = 0; i < m.getAllAtoms(); i++) {
31
30
  atom.queryFeatures = m.getAtomQueryFeatures(i);
32
31
  atom.radical = m.getAtomRadical(i);
33
32
  atom.x = m.getAtomX(i);
34
- atom.y = m.getAtomY(i)
33
+ atom.y = m.getAtomY(i);
35
34
  atom.z = m.getAtomZ(i);
36
35
  atom.allConnected = m.getAllConnAtoms(i);
37
36
  atom.hydrogens = m.getAllHydrogens(i);
@@ -1,7 +1,6 @@
1
1
  // Register a function that provides an information panel for a molecule.
2
2
  // It gets natively integrated with the platform's data augmentation system.
3
3
  // To see the panel in action, open a file containing molecules, and click on a molecule.
4
- //
5
4
  // See also: https://datagrok.ai/help/discover/info-panels
6
5
 
7
6
  grok.functions.register({
@@ -1,6 +1,4 @@
1
- //name: chemTestCanvasMol
2
- //description: Test rendering a single molecule to a canvas with an optional SMARTS-scaffold
3
- //language: javascript
1
+ // Test rendering a single molecule to a canvas with an optional SMARTS-scaffold
4
2
 
5
3
  (async () => {
6
4
  let root = ui.div();
@@ -22,7 +20,7 @@
22
20
  0, 0, width, height, canvas2,
23
21
  'CN1CCC(O)(CC1)c2ccccc2');
24
22
  ui
25
- .dialog({title:'Test molecule'})
26
- .add(root)
27
- .show();
23
+ .dialog({title: 'Test molecule'})
24
+ .add(root)
25
+ .show();
28
26
  })();
@@ -1,5 +1,4 @@
1
1
  // Different ways to render a molecule using the openchemlib library
2
- //
3
2
  // For more details, visit https://github.com/cheminfo/openchemlib-js
4
3
 
5
4
  grok.shell.newView('chem rendering').root.appendChild(ui.div([
@@ -1,8 +1,6 @@
1
- // An example of getting R-Groups.
2
- //
1
+ // An example of getting R-Groups
3
2
  // https://datagrok.ai/help/domains/chem/r-group-analysis
4
3
 
5
4
  grok.data.loadTable('https://public.datagrok.ai/demo/sar_small.csv')
6
- .then(t => grok.chem.rGroup(t, 'smiles', 'O=C1CN=C(C2CCCCC2)C2:C:C:C:C:C:2N1')
7
- .then(t => grok.shell.addTableView(t)));
8
-
5
+ .then(t => grok.chem.rGroup(t, 'smiles', 'O=C1Nc2ccccc2C(C2CCCCC2)=NC1')
6
+ .then(t => grok.shell.addTableView(t)));
@@ -1,6 +1,3 @@
1
- //name: testSimilarityScoringScores
2
- //language: javascript
3
-
4
1
  grok.data.loadTable('https://public.datagrok.ai/demo/sar_small.csv').then(molecules =>
5
2
  grok.chem.getSimilarities(molecules.col('smiles'), 'O=C1CN=C(C2CCCCC2)C2:C:C:C:C:C:2N1').then(similar =>
6
3
  grok.shell.addTableView(DG.DataFrame.fromColumns([similar]))
@@ -1,6 +1,3 @@
1
- //name: testSimilarityScoringSorted
2
- //language: javascript
3
-
4
1
  grok.data.loadTable('https://public.datagrok.ai/demo/sar_small.csv').then(molecules =>
5
2
  grok.chem.findSimilar(molecules.col('smiles'), 'O=C1CN=C(C2CCCCC2)C2:C:C:C:C:C:2N1').then(similar =>
6
3
  grok.shell.addTableView(similar)
@@ -1,12 +1,10 @@
1
- //name: testSubstructureSearch
2
- //description: Substructure search via RDKit
3
- //language: javascript
1
+ // Substructure search via RDKit
4
2
 
5
3
  async function time(name, n, f) {
6
4
  let start = new Date();
7
- for (let k = 0; k < n; ++k) {
5
+ for (let k = 0; k < n; ++k)
8
6
  await f();
9
- }
7
+
10
8
  let stop = new Date();
11
9
  console.log(`${name}: ${(stop - start) / n} ms`);
12
10
  }
@@ -26,7 +24,7 @@ async function time(name, n, f) {
26
24
 
27
25
  await time(`Graph-based search on ${df.rowCount} molecules`, n, async () => {
28
26
  for (let s of searchFor) {
29
- let result = await grok.chem.searchSubstructure(col, s, {substructLibrary: false});
27
+ await grok.chem.searchSubstructure(col, s, {substructLibrary: false});
30
28
  // console.log(s + ": " + result.toString());
31
29
  }
32
30
  });
@@ -37,9 +35,8 @@ async function time(name, n, f) {
37
35
 
38
36
  await time(`Searching the library on ${searchFor.length} molecules`, n, async () => {
39
37
  for (let s of searchFor) {
40
- let result = await grok.chem.searchSubstructure(col, s);
38
+ await grok.chem.searchSubstructure(col, s);
41
39
  // console.log(s + ": " + result.toString());
42
40
  }
43
41
  });
44
-
45
42
  })();
@@ -1,6 +1,3 @@
1
- //name: testSubstructureSearchSmarts
2
- //language: javascript
3
-
4
1
  // An example of using substructure search with SMARTS pattern,
5
2
  // encoded through an ALS parameter block of a MolFile
6
3
 
@@ -25,9 +22,9 @@ grok.data.getDemoTable('chem/smiles.csv')
25
22
  1 T 2 6 7
26
23
  M ALS 1 2 T C N
27
24
  M END
28
- `
29
- )
30
- .then(function (bs) {
31
- t.filter.copyFrom(bs);
32
- grok.shell.addTableView(t);
33
- }));
25
+ `,
26
+ )
27
+ .then(function(bs) {
28
+ t.filter.copyFrom(bs);
29
+ grok.shell.addTableView(t);
30
+ }));
@@ -1,12 +1,9 @@
1
- //name: testSubstructureSearchSmarts
2
- //language: javascript
3
-
4
1
  // An example of using substructure search with SMARTS pattern
5
2
 
6
3
  grok.data.getDemoTable('chem/smiles.csv')
7
4
  .then(t => grok.chem.searchSubstructure(
8
5
  t.col('canonical_smiles'), '[!#6&!#7]1:[#6]:[#6]:[#6]:[#6]:[#6]:1')
9
- .then(function (bs) {
10
- t.filter.copyFrom(bs);
11
- grok.shell.addTableView(t);
12
- }));
6
+ .then(function(bs) {
7
+ t.filter.copyFrom(bs);
8
+ grok.shell.addTableView(t);
9
+ }));
@@ -1,11 +1,8 @@
1
- //name: testSubstructureSearchLibrary
2
- //language: javascript
3
-
4
1
  // An example of using substructure search
5
2
 
6
3
  grok.data.loadTable('https://public.datagrok.ai/demo/sar_small.csv')
7
4
  .then(t => grok.chem.searchSubstructure(t.col('smiles'), 'O=C1CN=C(C2CCCCC2)C2:C:C:C:C:C:2N1')
8
- .then(function (bs) {
5
+ .then(function(bs) {
9
6
  t.filter.copyFrom(bs);
10
7
  grok.shell.addTableView(t);
11
8
  }));
@@ -1,7 +1,6 @@
1
1
  // An example of using predictive models.
2
- //
3
2
  // https://datagrok.ai/help/learn/predictive-modeling
4
3
 
5
4
  grok.data.loadTable('https://public.datagrok.ai/demo/demog.csv')
6
- .then(t => grok.ml.applyModel('Demo:PredictSexByBasicDemographics', t)
7
- .then(t => grok.shell.addTableView(t)));
5
+ .then(t => grok.ml.applyModel('Samples:Models:PredictSexByBasicDemographics', t)
6
+ .then(t => grok.shell.addTableView(t)));
@@ -0,0 +1,36 @@
1
+ // Demonstrates function result caching.
2
+ // The following code uses dynamic function registration, for package functions you can do that:
3
+ // //input: int x
4
+ // //output: int bar
5
+ // //meta.cache: true
6
+
7
+ //grok.functions.clientCache.clear();
8
+ let counts = {};
9
+
10
+ grok.functions.register({
11
+ signature: 'int bar(int x)',
12
+ run: (x) => {
13
+ grok.shell.info('Evaluating bar(' + x + ')');
14
+ return x * x;
15
+ },
16
+ options: { cache: 'true', 'cache.invalidateOn': '* * * * *'} // invalidate every minute
17
+ });
18
+
19
+ grok.functions.register({
20
+ signature: 'int foo(int x)',
21
+ run: (x) => { grok.shell.info('Evaluating foo(' + x + ')'); return x; },
22
+ options: { cache: 'true'}
23
+ });
24
+
25
+ // results are cached
26
+ grok.functions.call('bar', {x: 7}).then((result) => grok.shell.info(result));
27
+ grok.functions.call('bar', {x: 7}).then((result) => grok.shell.info(result));
28
+ grok.functions.call('bar', {x: 7}).then((result) => grok.shell.info(result));
29
+
30
+ grok.functions.call('bar', {x: 8}).then((result) => grok.shell.info(result));
31
+ grok.functions.call('bar', {x: 8}).then((result) => grok.shell.info(result));
32
+
33
+ grok.functions.call('foo', {x: 12}).then((result) => grok.shell.info(result));
34
+ grok.functions.call('foo', {x: 12}).then((result) => grok.shell.info(result));
35
+
36
+ grok.shell.info(counts);
@@ -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/DemoScripts/scripts/r/r_dup.R
7
+ // https://github.com/datagrok-ai/public/blob/master/packages/Demo/scripts/r/r_dup.R
8
8
  grok.functions
9
- .call("DemoScripts:RDup", {s: "Foo"})
9
+ .call("Samples:RDup", {s: "Foo"})
10
10
  .then((res) => {
11
11
  grok.shell.info(res);
12
12
  });
@@ -4,4 +4,4 @@ let widgetFunctions = DG.Func.find({returnType: 'widget'});
4
4
 
5
5
  let dialog = ui.dialog().show();
6
6
  for (let f of widgetFunctions)
7
- f.apply().then((w) => dialog.add(w));
7
+ dialog.add(ui.render(f));
@@ -0,0 +1,18 @@
1
+ let f = DG.Func.find({name: 'Sin'})[0];
2
+
3
+ // inspect function parameters
4
+ let inputs = f.inputs.map(input => input.propertyType + ' ' + input.name);
5
+ let outputs = f.outputs.map(output => output.propertyType + ' ' + output.name);
6
+ grok.shell.info(f.name + '(' + inputs + ')' + ': ' + outputs);
7
+
8
+ // simple way: f.apply
9
+ f.apply({x: 0.5}).then((result) => grok.shell.info(result));
10
+
11
+ // more complex: preparing a FuncCall that lets you track inputs and outputs, intercept execution, etc
12
+ let fc = f.prepare({"x": 0.5});
13
+
14
+ grok.shell.info('Input name and type: ' + fc.inputParams['x'].name + ' ' + fc.inputParams['x'].property.propertyType);
15
+ grok.shell.info('Input value:' + fc.inputs['x']);
16
+
17
+ grok.shell.info(fc.inputs['x']);
18
+ fc.call().then((call) => grok.shell.info(call.outputs['result']));
@@ -1,15 +1,10 @@
1
- //tags: Func
2
- // See Discovery:countToTen function:
3
- // https://github.com/datagrok-ai/public/blob/master/packages/Discovery/src/package.js
4
-
5
1
  let p = DG.ProgressIndicator.create();
6
2
  p.onProgressUpdated.subscribe((p) => grok.shell.info(p.percent));
7
3
  p.onLogUpdated.subscribe((line) => console.log(line));
8
4
  p.update(50, "Loading foo.csv");
9
5
 
10
-
11
- grok.functions.call("Discovery:countToTen",
12
- {s: "a"}, true, p)
6
+ grok.functions.call("Samples:RDup",
7
+ {s: "hi"}, true, p)
13
8
  .then((res) => {
14
9
  grok.shell.info(res);
15
10
  });
@@ -6,23 +6,25 @@ let tv = grok.shell.addTableView(t);
6
6
  tv.grid.columns.byName('ic50').cellType = 'html';
7
7
  tv.grid.columns.byName('hist').cellType = 'html';
8
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
- };
9
+ tv.grid.columns.byName('hist').width = 300;
23
10
 
24
11
  tv.grid.setOptions({rowHeight: 200});
12
+
25
13
  tv.grid.onCellPrepare((gc) => {
14
+ const lineOptions = {
15
+ xColumnName: 'concentration [ug/ml]',
16
+ yColumnNames: ['viability [%]'],
17
+ splitColumnName: 'compound',
18
+ xAxisType: 'logarithmic',
19
+ style: 'dashboard',
20
+ showTopPanel: 'false',
21
+ showSplitSelector: 'false',
22
+ legendVisibility: 'Never',
23
+ showXAxis: 'false',
24
+ showYAxis: 'false',
25
+ showLegend: 'false'
26
+ };
27
+
26
28
  if (gc.isTableCell && gc.gridColumn.name === 'ic50' && gc.cell.value != null)
27
29
  gc.style.element = gc.cell.value.plot.line(lineOptions).root;
28
30
  if (gc.isTableCell && gc.gridColumn.name === 'hist' && gc.cell.value != null)
@@ -0,0 +1,19 @@
1
+ // Demonstrates different link click modes in grid
2
+
3
+ const df = DG.DataFrame.fromColumns([
4
+ DG.Column.fromList(DG.TYPE.STRING, 'open in new tab', ['To learn more about Datagrok open https://datagrok.ai/help/home']),
5
+ DG.Column.fromList(DG.TYPE.STRING, 'open in context panel', ['To learn more about Datagrok open https://datagrok.ai/help/home']),
6
+ DG.Column.fromList(DG.TYPE.STRING, 'custom', ['To learn more about Datagrok open https://datagrok.ai/help/home'])
7
+ ]);
8
+ grok.shell.addTableView(df);
9
+
10
+ // Setting the column tags
11
+
12
+ df.col('open in new tab').tags[DG.TAGS.LINK_CLICK_BEHAVIOR] = 'Open in new tab';
13
+ df.col('open in context panel').tags[DG.TAGS.LINK_CLICK_BEHAVIOR] = 'Open in context panel';
14
+ df.col('custom').tags[DG.TAGS.LINK_CLICK_BEHAVIOR] = 'Custom';
15
+
16
+ // Displaying the clicked link - global and local grid events
17
+
18
+ grok.events.onGridCellLinkClicked.subscribe(eventData => grok.shell.info(`Global event - ${eventData.args.link}`)); // global
19
+ grok.shell.tv.grid.onGridCellLinkClicked.subscribe(eventData => grok.shell.info(`Local grid event - ${eventData.args.link}`)); // local
@@ -0,0 +1,7 @@
1
+ const df = grok.data.demo.demog();
2
+ const tv = grok.shell.addTableView(df);
3
+
4
+ const pinnedColumn = tv.grid.columns.byName('subj');
5
+
6
+ // calling the function from the PowerGrid package
7
+ await grok.functions.call('PowerGrid:addPinnedColumn', {gridCol: pinnedColumn});
@@ -0,0 +1,8 @@
1
+ const df = grok.data.demo.demog();
2
+ const tv = grok.shell.addTableView(df);
3
+
4
+ // setting the column-value pairs
5
+ tv.grid.setOptions({
6
+ pinnedRowValues: ['1', '0', '4'],
7
+ pinnedRowColumnNames: ['subj', 'subj', 'subj'],
8
+ });
@@ -1,8 +1,7 @@
1
1
  // grid.getVisibleBounds
2
2
 
3
3
  let grid = grok.shell.addTableView(grok.data.demo.demog()).grid;
4
-
5
- setInterval(() => {
4
+ grid.onAfterDrawContent.subscribe(() => setTimeout(() => {
6
5
  let g = grid.canvas.getContext('2d');
7
6
 
8
7
  g.strokeStyle = 'green';
@@ -12,5 +11,5 @@ setInterval(() => {
12
11
  g.strokeStyle = 'blue';
13
12
  for (let cell of grid.columns.byName('age').getVisibleCells())
14
13
  g.strokeRect(cell.bounds.x, cell.bounds.y, cell.bounds.width, cell.bounds.height);
15
-
16
- }, 1000);
14
+
15
+ }, 300));
@@ -1,6 +1,11 @@
1
1
  // Scroll to pixels.
2
2
 
3
- let grid = grok.shell.addTableView(grok.data.demo.randomWalk(100, 100)).grid;
4
- rxjs.interval(1000).pipe(rxjs.operators.startWith(0)).subscribe((i) => {
5
- grid.scrollToPixels(i, i);
6
- });
3
+ const grid = grok.shell.addTableView(grok.data.demo.randomWalk(100, 100)).grid;
4
+ let cntr = 0;
5
+
6
+ ui.dialog('Scroll')
7
+ .add(ui.button('Scroll by 10 pixels', () => {
8
+ cntr += 10;
9
+ grid.scrollToPixels(cntr, 0);
10
+ }))
11
+ .show();
@@ -1,4 +1,4 @@
1
- let view = grok.shell.newView('Usage');
1
+ const view = grok.shell.newView('Usage');
2
2
 
3
- grok.data.query('UsageAnalysis:EventsOnDate', {'date': 'today'})
4
- .then(t => view.append(DG.Viewer.scatterPlot(t).root));
3
+ grok.data.query('UsageAnalysis:TopFunctions', {date: 'today', users: ['all']})
4
+ .then((t) => view.append(ui.block(DG.Viewer.scatterPlot(t).root)));
@@ -1,4 +1,2 @@
1
- let view = grok.shell.newView('Usage');
2
-
3
- grok.data.query('UsageAnalysis:ErrorsSummaryOnDate', {'date': 'this year'})
4
- .then(t => grok.shell.addTableView(t));
1
+ grok.data.query('UsageAnalysis:TopPackageErrors', {date: 'this week', users: ['all']})
2
+ .then((t) => grok.shell.addTableView(t));
@@ -1,4 +1,2 @@
1
- let view = grok.shell.newView('Usage');
2
-
3
- grok.data.query('TestTrack:ManualActivityByDate', {'date': 'today'})
4
- .then(t => view.append(DG.Viewer.grid(t).root));
1
+ const df = await grok.data.query('UsageAnalysis:TestsToday');
2
+ grok.shell.addTableView(df);
@@ -1,9 +1,8 @@
1
- //tags: User
2
1
  //help-url: https://datagrok.ai/help/govern/user
3
- let view = grok.shell.newView('Usage');
2
+ const view = grok.shell.newView('Usage');
4
3
 
5
- grok.data.query('UsageAnalysis:UniqueUsersByDate', {'date': 'today'})
6
- .then(t => {
7
- let ids = Array.from(t.getCol('id').values());
8
- grok.dapi.getEntities(ids).then((users) => view.append(ui.list(users)));
9
- });
4
+ grok.data.query('UsageAnalysis:Usage', {date: 'today', users: ['all']})
5
+ .then((t) => {
6
+ const ids = new Set(t.getCol('user_id').toList());
7
+ grok.dapi.getEntities([...ids]).then((users) => view.append(ui.list(users)));
8
+ });
@@ -2,7 +2,5 @@
2
2
  //help-url: https://datagrok.ai/help/develop/develop#packages
3
3
  // Read more about package credentials: https://datagrok.ai/help/develop/how-to/manage-credentials
4
4
 
5
- let p = new DG.Package();
6
- p.name = "ApiSamples";
7
-
8
- p.getCredentials().then((c) => grok.shell.info(c.parameters['test']));
5
+ let p = await grok.dapi.packages.filter('Api Samples').first();
6
+ p.getCredentials().then((c) => grok.shell.info(c ? c : 'Credentials are not set.'));
@@ -0,0 +1,14 @@
1
+ // Helper methods for rendering on canvas
2
+
3
+ const canvas = ui.canvas(200, 200);
4
+
5
+ const g = canvas.getContext("2d");
6
+ DG.Paint.horzAxis(g, 0, 100, 30, 170, 160, 30);
7
+ DG.Paint.vertAxis(g, 0, 100, 0, 10, 30, 160);
8
+
9
+ for (let i = 0; i < 100; i++)
10
+ DG.Paint.marker(g, DG.MARKER_TYPE.CIRCLE,
11
+ Math.random() * 160 + 30, Math.random() * 160 + 10,
12
+ DG.Color.filteredRows, 5);
13
+
14
+ canvas