@datagrok/api-samples 1.0.8 → 1.2.1

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 (218) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/README.md +2 -2
  3. package/dist/package-test.js +1848 -2
  4. package/dist/package.js +30 -2
  5. package/files/viewer-events/bar-chart/on-category-clicked.js +1 -0
  6. package/files/viewer-events/grid/on-cell-clicked.js +1 -0
  7. package/files/viewer-events/pc-plot/on-line-clicked.js +1 -0
  8. package/files/viewer-events/pie-chart/on-segment-clicked.js +1 -0
  9. package/files/viewer-events/scatter-plot/on-point-clicked.js +1 -0
  10. package/files/viewer-events/scatter-plot/on-rendered.js +1 -0
  11. package/layouts/demog-table-layout.json +329 -181
  12. package/package.json +23 -20
  13. package/scripts/dapi/admin.js +5 -5
  14. package/scripts/dapi/applicable-layouts.js +3 -1
  15. package/scripts/dapi/fetch.js +8 -6
  16. package/scripts/dapi/files.js +45 -0
  17. package/scripts/dapi/projects-list.js +3 -3
  18. package/scripts/dapi/projects-open.js +4 -4
  19. package/scripts/dapi/sticky-meta-1-tags.js +54 -0
  20. package/scripts/dapi/sticky-meta-2-semtype.js +33 -0
  21. package/scripts/dapi/who-am-i.js +10 -10
  22. package/scripts/data-access/db/ad-hoc-query.js +16 -0
  23. package/scripts/data-access/db/db-edit.js +6 -9
  24. package/scripts/data-access/{parameterized-query.js → db/parameterized-query.js} +3 -2
  25. package/scripts/data-access/db/query_builder_join.js +15 -0
  26. package/scripts/data-access/db/query_builder_simple.js +15 -0
  27. package/scripts/data-access/db-master-details-manual.js +10 -12
  28. package/scripts/data-access/external/stock-prices.js +2 -2
  29. package/scripts/data-access/files/file-exists.js +10 -0
  30. package/scripts/data-access/files/read-file.js +19 -0
  31. package/scripts/data-access/load-csv.js +2 -2
  32. package/scripts/data-access/open-table-by-id.js +11 -3
  33. package/scripts/data-access/output-layouts.js +3 -1
  34. package/scripts/data-access/save-and-load-df.js +6 -5
  35. package/scripts/data-frame/advanced/data-frames-in-columns.js +4 -1
  36. package/scripts/data-frame/advanced/virtual-columns.js +1 -1
  37. package/scripts/data-frame/aggregation/unpivot.js +1 -1
  38. package/scripts/data-frame/column-access.js +5 -3
  39. package/scripts/data-frame/columns-ordering.js +4 -0
  40. package/scripts/data-frame/compare-tables.js +3 -2
  41. package/scripts/data-frame/construction/add-new-column.js +13 -0
  42. package/scripts/data-frame/construction/create-from-columns.js +4 -4
  43. package/scripts/data-frame/construction/create-from-csv-format.js +3 -3
  44. package/scripts/data-frame/construction/create-from-typed-arrays.js +7 -2
  45. package/scripts/data-frame/construction/date-time.js +24 -0
  46. package/scripts/data-frame/construction/export-to-csv-advanced.js +14 -4
  47. package/scripts/data-frame/construction/export-to-csv-molblock.js +3 -0
  48. package/scripts/data-frame/construction/export-to-csv.js +1 -1
  49. package/scripts/data-frame/events/calculated-columns/creation.js +1 -1
  50. package/scripts/data-frame/events/calculated-columns/deletion.js +1 -1
  51. package/scripts/data-frame/events/calculated-columns/update.js +1 -1
  52. package/scripts/data-frame/join-link/link-tables-dynamic.js +11 -12
  53. package/scripts/data-frame/join-link/link-tables.js +12 -8
  54. package/scripts/data-frame/metadata/dataframe-meta.js +1 -1
  55. package/scripts/data-frame/modification/add-columns.js +1 -1
  56. package/scripts/data-frame/modification/append.js +1 -1
  57. package/scripts/data-frame/modification/calculated-columns/edit-formula.js +2 -2
  58. package/scripts/data-frame/modification/double-precision.js +26 -0
  59. package/scripts/data-frame/modification/manipulate.js +3 -3
  60. package/scripts/demo/med-chem.js +103 -0
  61. package/scripts/demo/stock-broker.js +1 -1
  62. package/scripts/domains/chem/chem-benchmark.js +0 -5
  63. package/scripts/domains/chem/descriptors.js +2 -4
  64. package/scripts/domains/chem/diversity-search.js +2 -4
  65. package/scripts/domains/chem/mcs.js +3 -3
  66. package/scripts/domains/chem/r-group.js +3 -3
  67. package/scripts/domains/chem/similarity-scoring-scores.js +3 -5
  68. package/scripts/domains/chem/similarity-scoring-sorted.js +3 -5
  69. package/scripts/domains/chem/sketcher.js +2 -2
  70. package/scripts/domains/chem/substructure-search-smarts-molfile-als.js +11 -12
  71. package/scripts/domains/chem/substructure-search-smarts.js +4 -7
  72. package/scripts/domains/chem/substructure-search.js +5 -6
  73. package/scripts/domains/data-science/cluster.js +8 -10
  74. package/scripts/domains/data-science/missing-values-imputation.js +3 -3
  75. package/scripts/domains/data-science/pca.js +3 -3
  76. package/scripts/domains/data-science/predictive-model.js +4 -4
  77. package/scripts/domains/data-science/random-data.js +5 -6
  78. package/scripts/events/form-creation.js +2 -2
  79. package/scripts/events/function-events.js +1 -1
  80. package/scripts/events/global-events.js +1 -1
  81. package/scripts/events/layout-events.js +5 -6
  82. package/scripts/events/viewer-data-events.js +11 -0
  83. package/scripts/functions/caching-results.js +8 -9
  84. package/scripts/functions/calling.js +7 -10
  85. package/scripts/functions/func-call.js +9 -2
  86. package/scripts/functions/param-editor.js +1 -1
  87. package/scripts/functions/progress.js +2 -5
  88. package/scripts/functions/register-function.js +1 -1
  89. package/scripts/grid/advanced/cell-renderer.js +1 -1
  90. package/scripts/grid/advanced/column-groups.js +8 -0
  91. package/scripts/grid/advanced/dynamic-value-retrieval.js +12 -0
  92. package/scripts/grid/advanced/format-formula.js +7 -0
  93. package/scripts/grid/{hit-test.js → advanced/hit-test.js} +1 -1
  94. package/scripts/grid/advanced/link-click.js +3 -3
  95. package/scripts/grid/advanced/markup-link.js +6 -0
  96. package/scripts/grid/advanced/paint-counts.js +4 -1
  97. package/scripts/grid/cell-types/tags-multi-cell.js +18 -0
  98. package/scripts/grid/{color-coding-conditional.js → color-coding/color-coding-conditional.js} +17 -10
  99. package/scripts/grid/color-coding/color-coding.js +8 -9
  100. package/scripts/grid/color-coding/get-cell-color.js +3 -5
  101. package/scripts/grid/html-cells/html-table-cells.js +1 -1
  102. package/scripts/grid/styles/column-cell-styles.js +10 -0
  103. package/scripts/grid/{column-controlled-values.js → styles/column-controlled-values.js} +2 -2
  104. package/scripts/grid/{data-format.js → styles/data-format.js} +4 -4
  105. package/scripts/misc/audit/errors-summary.js +2 -2
  106. package/scripts/misc/audit/test-tracking.js +2 -2
  107. package/scripts/misc/audit/users-today.js +3 -5
  108. package/scripts/misc/package-credentials.js +2 -1
  109. package/scripts/misc/user-settings-storage.js +48 -0
  110. package/scripts/performance/all-chembl-structures.js +2 -1
  111. package/scripts/scripting/files-for-scripting.js +24 -0
  112. package/scripts/scripting/grok-scripting.js +2 -3
  113. package/scripts/scripting/package-scripting.js +8 -0
  114. package/scripts/shell/last-error.js +1 -1
  115. package/scripts/shell/ui-parts.js +9 -9
  116. package/scripts/shell/windows/browse/customize-tree.js +3 -0
  117. package/scripts/ui/apps/bioreactor.js +5 -5
  118. package/scripts/ui/components/accordion.js +3 -3
  119. package/scripts/ui/components/drop-down.js +8 -5
  120. package/scripts/ui/components/icons.js +7 -7
  121. package/scripts/ui/components/menu-advanced.js +85 -0
  122. package/scripts/ui/components/popup-menu.js +6 -5
  123. package/scripts/ui/components/summary-card.js +4 -3
  124. package/scripts/ui/components/tree-view-adv.js +4 -2
  125. package/scripts/ui/containers/splitters.js +12 -20
  126. package/scripts/ui/dialogs/wizard.js +8 -8
  127. package/scripts/ui/docking/docking.js +4 -1
  128. package/scripts/ui/handlers/markup-handlers.js +60 -0
  129. package/scripts/ui/inputs/advanced/all-input-types.js +47 -29
  130. package/scripts/ui/inputs/advanced/for-properties.js +1 -1
  131. package/scripts/ui/inputs/advanced/input-api.js +38 -0
  132. package/scripts/ui/inputs/advanced/input-events.js +10 -10
  133. package/scripts/ui/inputs/advanced/input-form.js +8 -8
  134. package/scripts/ui/inputs/choice-input.js +5 -5
  135. package/scripts/ui/inputs/column-combo-box.js +3 -3
  136. package/scripts/ui/inputs/column-inputs.js +3 -3
  137. package/scripts/ui/inputs/forms.js +15 -16
  138. package/scripts/ui/inputs/helm-input-ui.js +7 -0
  139. package/scripts/ui/inputs/inputs-events.js +8 -8
  140. package/scripts/ui/inputs/inputs-extended.js +2 -2
  141. package/scripts/ui/inputs/inputs.js +17 -15
  142. package/scripts/ui/inputs/molecule-input.js +1 -1
  143. package/scripts/ui/inputs/table-input.js +1 -1
  144. package/scripts/ui/inputs/tags-input.js +2 -2
  145. package/scripts/ui/inputs/typeahead-input.js +16 -17
  146. package/scripts/ui/inputs/validation/input-validators.js +11 -0
  147. package/scripts/ui/inputs/validation/parameter-expressions.js +9 -0
  148. package/scripts/ui/inputs/validation/parameter-validation.js +6 -0
  149. package/scripts/ui/interactivity/drag-and-drop.js +3 -3
  150. package/scripts/ui/rendering/render-items.js +9 -9
  151. package/scripts/ui/tooltips/tooltip-events.js +2 -1
  152. package/scripts/ui/tooltips/tooltips.js +11 -2
  153. package/scripts/ui/viewers/advanced/attached-properties.js +5 -5
  154. package/scripts/ui/viewers/advanced/default-axis-type.js +1 -1
  155. package/scripts/ui/viewers/advanced/descriptors.js +14 -0
  156. package/scripts/ui/viewers/advanced/init-function.js +21 -0
  157. package/scripts/ui/viewers/advanced/init-script.js +15 -0
  158. package/scripts/ui/viewers/filters/add-single-filter.js +5 -5
  159. package/scripts/ui/viewers/filters/custom-filters.js +7 -6
  160. package/scripts/ui/viewers/filters/filter-group.js +6 -1
  161. package/scripts/ui/viewers/filters/multi-value-filter.js +1 -1
  162. package/scripts/ui/viewers/js viewers/chord-viewer.js +1 -1
  163. package/scripts/ui/viewers/js viewers/globe-viewer.js +7 -7
  164. package/scripts/ui/viewers/js viewers/sankey-viewer.js +1 -1
  165. package/scripts/ui/viewers/js viewers/surface-plot.js +19 -1
  166. package/scripts/ui/viewers/js viewers/word-cloud.js +1 -1
  167. package/scripts/ui/viewers/scatter-plot-events.js +6 -1
  168. package/scripts/ui/viewers/trellis-plot-with-summary-viewer.js +3 -1
  169. package/scripts/ui/viewers/types/globe.js +2 -3
  170. package/scripts/ui/viewers/types/markup-advanced.js +2 -2
  171. package/scripts/ui/viewers/types/markup-eeg.js +5 -5
  172. package/scripts/ui/viewers/types/shape-map.js +4 -4
  173. package/scripts/ui/viewers/types/trellis-plot.js +13 -1
  174. package/scripts/ui/viewers/types/word-cloud.js +1 -1
  175. package/scripts/ui/viewers/viewer-tooltips.js +1 -1
  176. package/scripts/ui/views/default-views.js +8 -7
  177. package/scripts/ui/views/layouts.js +16 -17
  178. package/scripts/ui/views/multi-view.js +1 -1
  179. package/scripts/ui/widgets/widgets-tree.js +32 -0
  180. package/src/package-api.ts +8 -0
  181. package/src/package-test.ts +117 -14
  182. package/src/tests/owners.ts +8 -0
  183. package/test-console-output-1.log +6957 -0
  184. package/test-console-output-2.log +371 -0
  185. package/test-console-output-3.log +887 -0
  186. package/test-console-output-4.log +1085 -0
  187. package/test-console-output-5.log +944 -0
  188. package/test-console-output-6.log +2 -0
  189. package/test-record-1.mp4 +0 -0
  190. package/test-record-2.mp4 +0 -0
  191. package/test-record-3.mp4 +0 -0
  192. package/test-record-4.mp4 +0 -0
  193. package/test-record-5.mp4 +0 -0
  194. package/test-record-6.mp4 +0 -0
  195. package/to fix/dynamic-loading.js +13 -0
  196. package/tsconfig.json +1 -1
  197. package/webpack.config.js +4 -1
  198. package/files.js +0 -39
  199. package/scripts/misc/audit/activity-today.js +0 -4
  200. package/scripts/misc/user-data-storage.js +0 -49
  201. package/scripts/scripting/scripting.js +0 -6
  202. package/scripts/ui/handlers/dynamic-loading.js +0 -13
  203. /package/scripts/data-access/{dynamic-query.js → db/dynamic-query.js} +0 -0
  204. /package/scripts/grid/{cell-bounds.js → advanced/cell-bounds.js} +0 -0
  205. /package/scripts/grid/{category-colors.js → color-coding/category-colors.js} +0 -0
  206. /package/scripts/grid/{custom-cell-prepare.js → events/custom-cell-prepare.js} +0 -0
  207. /package/scripts/grid/{custom-cell-rendering-indexes.js → events/custom-cell-rendering-indexes.js} +0 -0
  208. /package/scripts/grid/{custom-cell-rendering.js → events/custom-cell-rendering.js} +0 -0
  209. /package/scripts/grid/{custom-cell-tooltip.js → events/custom-cell-tooltip.js} +0 -0
  210. /package/scripts/grid/{scroll-bars.js → navigate/scroll-bars.js} +0 -0
  211. /package/scripts/grid/{scroll-to-cell.js → navigate/scroll-to-cell.js} +0 -0
  212. /package/scripts/grid/{scroll-to-pixels.js → navigate/scroll-to-pixels.js} +0 -0
  213. /package/scripts/grid/{order-columns.js → order/order-columns.js} +0 -0
  214. /package/scripts/grid/{order-rows-by-comparer.js → order/order-rows-by-comparer.js} +0 -0
  215. /package/scripts/grid/{order-rows.js → order/order-rows.js} +0 -0
  216. /package/scripts/grid/{hide-columns.js → resize/hide-columns.js} +0 -0
  217. /package/scripts/grid/{resize-columns.js → resize/resize-columns.js} +0 -0
  218. /package/scripts/grid/{resize-events.js → resize/resize-events.js} +0 -0
@@ -1,16 +1,16 @@
1
1
  // Icons
2
2
 
3
3
  let view = ui.divV([
4
- ui.h2('Font Awesome icons'),
5
- ui.divH([
4
+ ui.h2('Font Awesome'),
5
+ ui.ribbonPanel([
6
6
  ui.iconFA('question'),
7
7
  ui.iconFA('info'),
8
8
  ui.iconFA('cogs'),
9
9
  ui.iconFA('folder-open'),
10
10
  ui.iconFA('save')
11
- ], {style:{justifyContent:'space-around'}}),
12
- ui.h2('Special items'),
13
- ui.divH([
11
+ ]),
12
+ ui.h2('Special'),
13
+ ui.ribbonPanel([
14
14
  ui.icons.settings(() => grok.shell.info('click'), 'Settings'),
15
15
  ui.icons.help(() => grok.shell.info('click'), 'Help'),
16
16
  ui.icons.close(() => grok.shell.info('click'), 'Close'),
@@ -25,9 +25,9 @@ let view = ui.divV([
25
25
  ui.icons.info(() => grok.shell.info('click'), 'Info'),
26
26
  ui.icons.search(() => grok.shell.info('click'), 'Search'),
27
27
  ui.icons.filter(() => grok.shell.info('click'), 'Filter')
28
- ], {style:{justifyContent:'space-around'}})
28
+ ])
29
29
  ]);
30
- view.style.minWidth = '250px';
30
+
31
31
  ui.dialog('Icons')
32
32
  .add(view)
33
33
  .show();
@@ -0,0 +1,85 @@
1
+ // Menu advanced item customization. For top menu, see menu.js
2
+
3
+ // Generate a dataframe for column selectors
4
+ const dataFrame = grok.data.testData('demog', 50);
5
+ const columnNames = dataFrame.columns.toList().map(c => c.name);
6
+ const numericalColumnNames = columnNames.filter(c => dataFrame.columns.byName(c).isNumerical);
7
+
8
+ // Create menu and disable immediate close after the first click
9
+ const menu = DG.Menu.popup();
10
+ menu.closeOnClick = false;
11
+
12
+ // Store selected items
13
+ let selectedContinuousPaletteIndex = -1;
14
+ let selectedCategoricalPaletteIndex = -1;
15
+ let lastHoveredCategoricalPaletteIndex = -1;
16
+ let selectedMultipleColumns = [];
17
+ let selectedSingleColumn = null;
18
+ let lastHoveredSingleColumn = null;
19
+
20
+ menu
21
+ // Add header with no extra options.
22
+ .header('Default header')
23
+ .separator()
24
+ // Add continuous color palette on the same menu level which stores and displays selected palette index.
25
+ .colorPalette(DG.Color.continuousSchemes, {
26
+ onSelect: color => {
27
+ selectedContinuousPaletteIndex = DG.Color.continuousSchemes.indexOf(color);
28
+ grok.shell.info(`Selected continuous palette: ${selectedContinuousPaletteIndex + 1}`);
29
+ },
30
+ })
31
+ .separator()
32
+ // Add categorical color palette which stores and displays selected palette index,
33
+ // has hover and reset after hover effects. Placed in a nested 'Categorical Colors' group.
34
+ .colorPalette(DG.Color.categoricalSchemes, {
35
+ categorical: true, // the way how colors are displayed
36
+ asGroup: 'Categorical Colors', // nested submenu group name
37
+ getInitial: () => DG.Color.categoricalSchemes[0], // initial value on menu open
38
+ onPreview: color => {
39
+ lastHoveredCategoricalPaletteIndex = DG.Color.categoricalSchemes.indexOf(color);
40
+ grok.shell.info('Preview categorical palette: ' + (lastHoveredCategoricalPaletteIndex + 1));
41
+ },
42
+ onSelect: color => {
43
+ selectedCategoricalPaletteIndex = DG.Color.categoricalSchemes.indexOf(color);
44
+ grok.shell.info(`Selected categorical palette: ${selectedCategoricalPaletteIndex + 1}`);
45
+ },
46
+ })
47
+ .separator()
48
+ // Sdd header with some additional options
49
+ .header('Clickable header', {
50
+ hasHoverEffect: true, // enable effects on hover
51
+ onClick: () => grok.shell.info('Clicked on header!'), // add click action
52
+ getDescription: () => 'Click me!', // add description on hover
53
+ })
54
+ .separator()
55
+ // Add multi-column selector which allows to select column name array.
56
+ // Displays current action (select/deselect, or dragging)
57
+ // Placed in a nested 'multiColumSelector' group.
58
+ .multiColumnSelector(dataFrame, {
59
+ asGroup: 'multiColumSelector',
60
+ initialValue: columnNames.slice(0, 5), // select first 5 columns by default
61
+ onChange: grid => {
62
+ const previousLength = selectedMultipleColumns.length;
63
+ selectedMultipleColumns = grid.getCheckedColumnNames();
64
+ grok.shell.info( previousLength !== selectedMultipleColumns.length
65
+ ? `${selectedMultipleColumns.length} columns selected` // if size is changed, then some column either added or removed
66
+ : `"${grid.currentColumn}" column drag and dropped`); // otherwise refresh fired because of drag and drop action
67
+ },
68
+ })
69
+ .separator()
70
+ // Add single-column selector which on the same menu
71
+ // which stores and displays selected and last hovered column name.
72
+ .singleColumnSelector(dataFrame, {
73
+ initialValue: numericalColumnNames.at(-2), // select 2nd from the end of numerical columns by default
74
+ onChange (grid, column, currentRowChanged) {
75
+ if (currentRowChanged) { // if current row is changed on click
76
+ selectedSingleColumn = column;
77
+ grok.shell.info( `"${column.name}" column selected`);
78
+ } else { // otherwise on hover
79
+ lastHoveredSingleColumn = grid.mouseOverColumn;
80
+ grok.shell.info(`"${lastHoveredSingleColumn?.name ?? '[none]'}" column hovered`);
81
+ }
82
+ },
83
+ columnFilter: (c) => c.isNumerical, // show only numerical columns
84
+ })
85
+ .show();
@@ -1,5 +1,3 @@
1
- let v = grok.shell.newView('demo: context menu');
2
-
3
1
  let showMenu = () => {
4
2
  let showBalloon = (item) => grok.shell.info(item);
5
3
 
@@ -7,9 +5,12 @@ let showMenu = () => {
7
5
  .item('Show info', () => grok.shell.info('Info'))
8
6
  .separator()
9
7
  .items(['First', 'Second'], showBalloon)
8
+ .group('Group')
9
+ .item('Inner item', () => grok.shell.info('item click'))
10
+ .endGroup()
10
11
  .show();
11
12
  };
12
13
 
13
- let text = ui.divText('Clickable');
14
- v.append(text);
15
- text.addEventListener("click", showMenu);
14
+ let text = ui.divText('Click me');
15
+ text.onclick = () => showMenu();
16
+ text
@@ -6,7 +6,8 @@ let card = (project) => ui.cards.summary(
6
6
  ]
7
7
  );
8
8
 
9
- grok.dapi.projects
9
+ grok.shell.windows.showProperties = true;
10
+ let projects = await grok.dapi.projects
10
11
  .filter('#demo')
11
- .list({pageSize: 5})
12
- .then((projects) => grok.shell.o = ui.divV(projects.map(card)));
12
+ .list({pageSize: 5});
13
+ grok.shell.o = ui.divV(projects.map(card));
@@ -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.TreeViewNode.fromItemCategories(items,
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]);
@@ -1,21 +1,13 @@
1
- // Splitters
1
+ // Use splitV and splitH to divide the area into resizable containers
2
+ // If you want a non-even split, specify it (in pixels - this is important) in the element width or height style.
2
3
 
3
- let t = grok.data.demo.demog();
4
- let block = ui.splitV([
5
- ui.splitH([
6
- ui.inputs([
7
- ui.stringInput('Input',''),
8
- ui.choiceInput('Select', 'item 1', ['item 1', 'item 2']),
9
- ui.textInput('text',' 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
-
19
- let view = grok.shell.newView('Splitters');
20
- view.box = true;
21
- view.append(block);
4
+ ui.splitV([
5
+ ui.splitH([
6
+ ui.divText('Top Left', { style: { width: '100px'}}),
7
+ ui.divText('Top Right'),
8
+ ], { style: { height: '40px'}}, true),
9
+ ui.splitH([
10
+ ui.divText('Panel 1'),
11
+ ui.divText('Panel 2')
12
+ ], {}, true)
13
+ ], {}, true)
@@ -1,15 +1,15 @@
1
1
  // Creating custom dialogs, and add the help url
2
2
 
3
- let name = ui.stringInput('Title', '');
4
- let type = ui.choiceInput('Type', 'Bio', ['Bio', 'Chem']);
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
- 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') })
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,60 @@
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
+ let logObject = await grok.dapi.log.filter('description = "@user liked #fruit"').first();
60
+ grok.shell.info(ui.render(logObject));
@@ -2,46 +2,64 @@ const df = grok.data.demo.demog();
2
2
  grok.shell.addTable(df);
3
3
 
4
4
  const properties = [
5
- { "name": "int", "inputType": "Int", "showPlusMinus": true },
6
- { "name": "float", "inputType": "Float", min: 0, max: 10, "showSlider": true},
7
- { "name": "bigInt", "inputType": "BigInt"},
8
- { "name": "qnum", "inputType": "QNum"},
9
- { "name": "slider", "inputType": "Slider", "min": 0, "max": 10},
10
- { "name": "bool", "inputType": "Bool"},
11
- { "name": "textArea", "inputType": "TextArea"},
12
- { "name": "text", "inputType": "Text"},
13
- { "name": "date", "inputType": "Date"},
14
- //{ "name": "map", "inputType": "Map"},
15
- { "name": "list", "inputType": "List"},
16
- { "name": "color", "inputType": "Color"},
17
- { "name": "table", "inputType": "Table"},
18
- { "name": "column", "inputType": "Column"},
19
- { "name": "radio", "inputType": "Radio", choices: ["Apple", "Banana"]},
20
- { "name": "choice", "inputType": "Choice", choices: ["Apple", "Banana"]},
21
- { "name": "multiChoice", "inputType": "MultiChoice", choices: ["Apple", "Banana"]},
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': 'user', 'inputType': 'User'},
22
+ {'name': 'userGroups', 'inputType': 'UserGroups'},
23
+ {'name': 'radio', 'inputType': 'Radio', choices: ['Apple', 'Banana']},
24
+ {'name': 'choice', 'inputType': 'Choice', choices: ['Apple', 'Banana']},
25
+ {'name': 'multiChoice', 'inputType': 'MultiChoice', choices: ['Apple', 'Banana']},
26
+ {'name': 'file', 'inputType': 'File'},
22
27
  ];
23
28
 
24
- let props = properties.map((p) => DG.Property.fromOptions(p))
25
- let object = {
29
+ const props = properties.map((p) => DG.Property.fromOptions(p));
30
+ const object = {
26
31
  int: 12,
27
- bigInt: "12345678901234567890",
32
+ //bigInt: '123456789012345678',
28
33
  float: 4.5,
29
- qnum: DG.Qnum.less(5),
34
+ qnum: DG.Qnum.greater(5),
30
35
  slider: 10,
31
36
  bool: true,
32
- textArea: "Bins rise and they fall,\nDistribution's gentle dance,\nHistogram unveils",
37
+ switch: true,
38
+ textArea: 'Bins rise and they fall,\nDistribution\'s gentle dance,\nHistogram unveils',
33
39
  text: 'Only text',
34
- //date: '2023/10/30', //dayjs(1977, 10, 2),
35
- map: { key1: 'value1', key2: 'value2'},
36
- color: '#e66465',
40
+ search: '',
41
+ date: dayjs('2003-05-05').utc(true),
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',
47
+ user: [DG.User.system],
48
+ userGroups: [DG.Group.developers],
41
49
  radio: 'Apple',
50
+ choice: 'Banana',
51
+ multiChoice: ['Apple'],
52
+ file: (await grok.dapi.files.list('System:DemoFiles/', true, 'curves'))[0],
42
53
  };
43
54
 
44
- ui.divV([
55
+ const div = ui.divV([
45
56
  ui.input.form(object, props),
46
- ui.button('Show', () => grok.shell.info(JSON.stringify(object)))
47
- ])
57
+ ui.button('Show values', () => {
58
+ let msg = '';
59
+ for (const [key, value] of Object.entries(object))
60
+ msg += `${key}: ${value}\n`;
61
+ grok.shell.info(msg);
62
+ })
63
+ ]);
64
+
65
+ grok.shell.newView('Inputs', [div]);
@@ -9,7 +9,7 @@ const properties = [
9
9
  {
10
10
  "name": "structure",
11
11
  "type": "string",
12
- //"semType": "Molecule"
12
+ "semType": "Molecule"
13
13
  },
14
14
  {
15
15
  "name": "weight",
@@ -0,0 +1,38 @@
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', {value: {key1: 'value1', key2: 'value2'}}),
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.radio('radio', {items: ['apple', 'orange'], value: 'apple'}),
23
+ ui.input.choice('choice', {items: ['apple', 'orange'], value: 'apple'}),
24
+ ui.input.multiChoice('multiChoice', {items: ['apple', 'orange', 'pear'], value: ['apple', 'orange']}),
25
+ ui.input.table('table', {value: df}),
26
+ ui.input.molecule('molecule', {value: 'CN1CCC(O)(CC1)c2ccccc2'}),
27
+ ui.input.user('user', {value: [DG.User.system]}),
28
+ ui.input.userGroups('userGroups', {value: [DG.Group.developers]}),
29
+ ui.input.image('image', {value: 'https://datagrok.ai/img/logo.svg'}),
30
+ ui.input.tags('tags', {tags: ['Tag 1', 'Tag2', 'Tag3'], showButton: true}),
31
+ ui.input.code('code', {script: 'print(\'Hello world!\')', mode: 'python', placeholder: 'print(\'Hello world!\')'}),
32
+ ui.input.markdown('markdown', {value: await grok.dapi.files.readAsText('System:DemoFiles/bio/ngl-formats/README.md')}),
33
+ ];
34
+
35
+ const form = DG.InputForm.forInputs(inputs);
36
+ form.onInputChanged.subscribe((ed) => grok.shell.info(`Input - ${ed.args.input.caption}, new value - ${ed.args.input.value}`));
37
+
38
+ grok.shell.newView('Inputs', [form.root]);
@@ -1,20 +1,20 @@
1
1
  // Manual handling of input-originated events
2
2
 
3
- var medication = { name: 'Aspirin', quantity: '20 mg'};
3
+ const medication = {name: 'Aspirin', quantity: '20 mg'};
4
4
 
5
5
  // Core value input implemented in Dart
6
- var nameProp = DG.Property.js('name', DG.TYPE.STRING);
7
- var nameEditor = DG.InputBase.forProperty(nameProp, medication);
8
- nameEditor.onChanged((_) => grok.shell.info('name changed: ' + nameEditor.value));
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
- var fooProp = DG.Property.fromOptions({name: 'quantity', type: DG.TYPE.STRING, semType: 'foo'});
13
- var quantityEditor = DG.InputBase.forProperty(fooProp, medication);
14
- quantityEditor.onChanged((_) => grok.shell.info('quantity changed: ' + quantityEditor.value));
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.findAll({name: 'Pkpd'}).then((fs) => {
4
- let fc = fs[0].prepare({dosage: 77});
5
- DG.InputForm.forFuncCall(fc).then((inputForm) => {
6
- inputForm.getInput('Clearance').addPostfix('foo');
7
- inputForm.onInputChanged.subscribe((_) => grok.shell.info('changed'));
8
- grok.shell.o = inputForm.root;
9
- });
10
- });
3
+ const sin = DG.Func.find({name: 'Sin'});
4
+
5
+ let fc = sin[0].prepare({dosage: 77});
6
+ let inputForm = await DG.InputForm.forFuncCall(fc);
7
+
8
+ inputForm.getInput('x').addPostfix('foo');
9
+ inputForm.onInputChanged.subscribe((_) => grok.shell.info('changed'));
10
+ grok.shell.o = inputForm.root;
@@ -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.choiceInput('Value', 'A', ['A', 'B', 'C']);
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 choices_new = ui.choiceInput('Value', 'B', ['B', 'C', 'D']);
11
- inputs.replaceChild(choices_new.root, choices.root);
12
- choices = choices_new;
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
- let ccb = DG.ColumnComboBox.create(grok.data.demo.demog(), (c) => c.type === 'int');
4
- let v = grok.shell.newView('demo: column combo box', [ccb]);
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.columnInput('Predict', t, t.col('age'));
5
- let features = ui.columnsInput('Features', t);
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();
@@ -5,31 +5,30 @@ let v = grok.shell.newView('demo: form types');
5
5
  //Basic form
6
6
  //To set labels aligned to left add class .ui-form-left
7
7
  let form = ui.form([
8
- ui.h1('Basic form'),
9
- ui.stringInput('First name', 'Arthur'),
10
- ui.stringInput('Last name', 'Dent'),
11
- ui.intInput('Age', 30)
8
+ ui.input.string('First name', {value: 'Arthur'}),
9
+ ui.input.string('Last name', {value: 'Dent'}),
10
+ ui.input.int('Age', {value: 30}),
12
11
  ]);
13
12
 
14
13
  //Add class .ui-form-wide to make the form wide
15
- let wideForm = ui.form([
16
- ui.h1('Wide form'),
17
- ui.stringInput('First name', 'Arthur'),
18
- ui.stringInput('Last name', 'Dent'),
19
- ui.intInput('Age', 30)
20
- ], 'ui-form-wide');
14
+ let wideForm = ui.wideForm([
15
+ ui.input.string('First name', {value: 'Arthur'}),
16
+ ui.input.string('Last name', {value: 'Dent'}),
17
+ ui.input.int('Age', {value: 30}),
18
+ ]);
21
19
 
22
20
  //Condensed form. You can also use .ui-form-condensed
23
21
  let narrowForm = ui.narrowForm([
24
- ui.h1('Condensed form'),
25
- ui.stringInput('First name', 'Arthur'),
26
- ui.stringInput('Last name', 'Dent'),
27
- ui.intInput('Age', 30)
22
+ ui.input.string('First name', {value: 'Arthur'}),
23
+ ui.input.string('Last name', {value: 'Dent'}),
24
+ ui.input.int('Age', {value: 30}),
28
25
  ]);
29
- v.append(ui.panel([narrowForm]));
30
26
 
31
27
  v.append(ui.divV([
28
+ ui.h1('Basic form'),
32
29
  form,
30
+ ui.h1('Wide form'),
33
31
  wideForm,
32
+ ui.h1('Condensed form'),
34
33
  narrowForm,
35
- ]))
34
+ ]));
@@ -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}})]));
@@ -2,14 +2,14 @@ let v = grok.shell.newView('demo: inputs-events');
2
2
 
3
3
  const msg = (v) => grok.shell.info(v);
4
4
 
5
- let name = ui.stringInput('Name', 'Arthur Dent', v => msg(v));
6
- let age = ui.intInput('Age', 30, v => msg(v));
7
- let sex = ui.choiceInput('Sex', 'Male', ['Male', 'Female'], v => msg(v));
8
- let date = ui.dateInput('Birthday', dayjs('1970-5-10'), v => msg(v));
9
- let alien = ui.boolInput('Alien', false, v => msg(v));
10
- let friends = ui.multiChoiceInput('Friends',
11
- ['Ford', 'Fenchurch'], ['Ford', 'Fenchurch', 'Zaphod', 'Slartibartfast'], v => msg(v));
12
- let active = ui.switchInput('Active', true, (v)=>msg(v));
5
+ let name = ui.input.string('Name', {value: 'Arthur Dent', onValueChanged: (v) => msg(v)});
6
+ let age = ui.input.int('Age', {value: 30, onValueChanged: (v) => msg(v)});
7
+ let sex = ui.input.choice('Sex', {items: ['Male', 'Female'], value: 'Male', onValueChanged: (v) => msg(v)});
8
+ let date = ui.input.date('Birthday', {value: dayjs('1970-5-10'), onValueChanged: (v) => msg(v)});
9
+ let alien = ui.input.bool('Alien', {value: false, onValueChanged: (v) => msg(v)});
10
+ let friends = ui.input.multiChoice('Friends', {items: ['Ford', 'Fenchurch', 'Zaphod', 'Slartibartfast'],
11
+ value: ['Ford', 'Fenchurch'], onValueChanged: (v) => msg(v)});
12
+ let active = ui.input.toggle('Active', {value: true, onValueChanged: (v) => msg(v)});
13
13
 
14
14
  let inputs = [name, age, sex, date, alien, friends, active];
15
15
  let container = ui.div();