@datagrok/api-samples 1.0.6 → 1.0.8

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 (152) hide show
  1. package/.eslintrc.json +47 -0
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +8 -8
  4. package/dist/package-test.js +2 -2
  5. package/files.js +39 -0
  6. package/package.json +18 -9
  7. package/scripts/dapi/groups.js +3 -0
  8. package/scripts/dapi/users.js +1 -1
  9. package/scripts/data-access/db-master-details-manual.js +3 -3
  10. package/scripts/data-access/parameterized-query.js +3 -3
  11. package/scripts/data-frame/bitset/similarity-metrics.js +3 -3
  12. package/scripts/data-frame/construction/create-from-csv-format.js +3 -3
  13. package/scripts/data-frame/filtering/update-filter-state.js +13 -0
  14. package/scripts/data-frame/modification/remove-where.js +8 -0
  15. package/scripts/data-frame/row-matching/patterns.js +1 -3
  16. package/scripts/domains/chem/chem-benchmark.js +26 -26
  17. package/scripts/domains/chem/descriptors.js +1 -2
  18. package/scripts/domains/chem/diversity-search.js +3 -5
  19. package/scripts/domains/chem/inspect-molecule.js +1 -1
  20. package/scripts/domains/chem/mcs.js +2 -3
  21. package/scripts/domains/chem/mol-atoms-bonds.js +1 -2
  22. package/scripts/domains/chem/mol-panel.js +0 -1
  23. package/scripts/domains/chem/mol-rendering-canvas.js +4 -6
  24. package/scripts/domains/chem/mol-rendering.js +0 -1
  25. package/scripts/domains/chem/r-group.js +3 -5
  26. package/scripts/domains/chem/similarity-scoring-scores.js +0 -3
  27. package/scripts/domains/chem/similarity-scoring-sorted.js +0 -3
  28. package/scripts/domains/chem/substructure-search-benchmark.js +5 -8
  29. package/scripts/domains/chem/substructure-search-smarts-molfile-als.js +6 -9
  30. package/scripts/domains/chem/substructure-search-smarts.js +4 -7
  31. package/scripts/domains/chem/substructure-search.js +1 -4
  32. package/scripts/domains/data-science/predictive-model.js +2 -3
  33. package/scripts/functions/caching-results.js +36 -0
  34. package/scripts/functions/calling.js +2 -2
  35. package/scripts/functions/discover-functions.js +1 -1
  36. package/scripts/functions/func-call.js +18 -0
  37. package/scripts/functions/progress.js +2 -7
  38. package/scripts/grid/advanced/charts-in-cells.js +16 -14
  39. package/scripts/grid/advanced/link-click.js +19 -0
  40. package/scripts/grid/advanced/pinned-columns.js +7 -0
  41. package/scripts/grid/advanced/pinned-rows.js +8 -0
  42. package/scripts/grid/advanced/visible-cells.js +3 -4
  43. package/scripts/grid/scroll-to-pixels.js +9 -4
  44. package/scripts/misc/audit/activity-today.js +3 -3
  45. package/scripts/misc/audit/errors-summary.js +2 -4
  46. package/scripts/misc/audit/test-tracking.js +2 -4
  47. package/scripts/misc/audit/users-today.js +6 -7
  48. package/scripts/misc/package-credentials.js +2 -4
  49. package/scripts/misc/sdtm.js +8 -10
  50. package/scripts/misc/utils/hide-empty-columns.js +17 -4
  51. package/scripts/performance/all-chembl-structures.js +1 -1
  52. package/scripts/scripting/grok-scripting.js +1 -1
  53. package/scripts/scripting/scripting.js +2 -2
  54. package/scripts/shell/last-error.js +0 -4
  55. package/scripts/shell/windows/shell-windows.js +6 -0
  56. package/scripts/ui/components/balloons.js +4 -1
  57. package/scripts/ui/{elements → components}/color-palettes.js +4 -4
  58. package/scripts/ui/components/html-tables.js +27 -0
  59. package/scripts/ui/components/loading-indicators.js +4 -6
  60. package/scripts/ui/components/menu-customization.js +18 -0
  61. package/scripts/ui/components/property-grid.js +10 -10
  62. package/scripts/ui/{layouts → containers}/splitters.js +3 -3
  63. package/scripts/ui/css.js +20 -0
  64. package/scripts/ui/inputs/advanced/all-input-types.js +47 -0
  65. package/scripts/ui/inputs/{for-properties.js → advanced/for-properties.js} +17 -2
  66. package/scripts/ui/inputs/advanced/input-form.js +10 -0
  67. package/scripts/ui/inputs/forms.js +35 -0
  68. package/scripts/ui/inputs/grid-input.js +14 -0
  69. package/scripts/ui/inputs/inputs.js +24 -0
  70. package/scripts/ui/{elements/inputs → inputs}/table-input.js +1 -2
  71. package/scripts/ui/inputs/typeahead-input.js +19 -0
  72. package/scripts/ui/viewers/custom-scatterplot-rendering.js +1 -1
  73. package/scripts/ui/viewers/custom-viewer-properties.js +5 -5
  74. package/scripts/ui/viewers/js viewers/chord-viewer.js +3 -0
  75. package/scripts/ui/viewers/js viewers/globe-viewer.js +13 -0
  76. package/scripts/ui/viewers/js viewers/radar-viewer.js +9 -0
  77. package/scripts/ui/viewers/js viewers/sankey-viewer.js +4 -0
  78. package/scripts/ui/viewers/js viewers/sunburst-viewer.js +3 -0
  79. package/scripts/ui/viewers/js viewers/surface-plot.js +2 -0
  80. package/scripts/ui/viewers/js viewers/timelines-viewer.js +3 -0
  81. package/scripts/ui/viewers/js viewers/tree-viewer.js +3 -0
  82. package/scripts/ui/viewers/js viewers/word-cloud.js +5 -0
  83. package/scripts/ui/viewers/trellis-plot-with-summary-viewer.js +14 -0
  84. package/scripts/ui/views/currently-open-views.js +5 -5
  85. package/src/package-test.ts +40 -1
  86. package/scripts/dapi/files.js +0 -39
  87. package/scripts/misc/audit/errors.js +0 -4
  88. package/scripts/misc/audit/event-types-summary.js +0 -4
  89. package/scripts/misc/audit/rolling-events.js +0 -11
  90. package/scripts/ui/apps/color-checker.js +0 -328
  91. package/scripts/ui/components/panels.js +0 -19
  92. package/scripts/ui/docking/README.md +0 -16
  93. package/scripts/ui/elements/html-tables.js +0 -24
  94. package/scripts/ui/elements/inputs/inputs.js +0 -46
  95. package/scripts/ui/elements/inputs/typeahead-input.js +0 -8
  96. package/scripts/ui/layouts/templates/2 Column.js +0 -14
  97. package/scripts/ui/layouts/templates/3 Column.js +0 -15
  98. package/scripts/ui/layouts/templates/Flex box.js +0 -16
  99. package/scripts/ui/layouts/templates/Fluid layout.js +0 -19
  100. package/scripts/ui/layouts/templates/Gallery grid.js +0 -18
  101. package/scripts/ui/layouts/templates/Splitter (1 Column 2 Row).js +0 -19
  102. package/scripts/ui/layouts/templates/Splitter (2 Column).js +0 -16
  103. package/scripts/ui/layouts/templates/Splitter (2 Row).js +0 -18
  104. package/scripts/ui/layouts/templates/Splitter (2-3 Column).js +0 -23
  105. package/scripts/ui/layouts/templates/Tabs 2 column.js +0 -19
  106. package/scripts/ui/layouts/templates/Tabs navbar.js +0 -16
  107. package/scripts/ui/viewers/types/google-map.js +0 -5
  108. package/scripts/ux/Dialogs/add-new-column-dlg.js +0 -58
  109. package/scripts/ux/Dialogs/link-table-dlg.js +0 -23
  110. package/scripts/ux/Filters/data-filtering.js +0 -99
  111. package/scripts/ux/Input forms/form-types.js +0 -133
  112. package/scripts/ux/Input forms/misc.js +0 -52
  113. package/scripts/ux/Layouts/example-1.js +0 -50
  114. package/scripts/ux/Layouts/example-2.js +0 -63
  115. package/scripts/ux/Layouts/example-3.js +0 -192
  116. package/scripts/ux/Layouts/example-4.js +0 -51
  117. package/scripts/ux/Managing Collections/datasource-view.js +0 -47
  118. package/scripts/ux/Views/property-panel.js +0 -120
  119. package/scripts/ux/Views/toolbar.js +0 -131
  120. package/scripts/ux/Views/toolbox.js +0 -124
  121. /package/scripts/ui/{elements → components}/buttons.js +0 -0
  122. /package/scripts/ui/{elements → components}/icons.js +0 -0
  123. /package/scripts/ui/{elements → components}/image.js +0 -0
  124. /package/scripts/ui/{elements → components}/list.js +0 -0
  125. /package/scripts/ui/{elements → components}/range-slider.js +0 -0
  126. /package/scripts/ui/{cards → components}/summary-card.js +0 -0
  127. /package/scripts/ui/{elements → components}/typography.js +0 -0
  128. /package/scripts/ui/{layouts → containers}/blocks.js +0 -0
  129. /package/scripts/ui/{layouts → containers}/box.js +0 -0
  130. /package/scripts/ui/{layouts → containers}/containers.js +0 -0
  131. /package/scripts/ui/{layouts → containers}/flexbox.js +0 -0
  132. /package/scripts/ui/{layouts → containers}/panels.js +0 -0
  133. /package/scripts/ui/inputs/{custom-inputs.js → advanced/custom-inputs.js} +0 -0
  134. /package/scripts/ui/inputs/{for-columns.js → advanced/for-columns.js} +0 -0
  135. /package/scripts/ui/inputs/{input-events.js → advanced/input-events.js} +0 -0
  136. /package/scripts/ui/inputs/{master-details.js → advanced/master-details.js} +0 -0
  137. /package/scripts/ui/{elements/inputs → inputs}/choice-input.js +0 -0
  138. /package/scripts/ui/{elements/inputs → inputs}/column-combo-box.js +0 -0
  139. /package/scripts/ui/{elements/inputs → inputs}/column-inputs.js +0 -0
  140. /package/scripts/ui/{elements/inputs → inputs}/inputs-events.js +0 -0
  141. /package/scripts/ui/{elements/inputs → inputs}/inputs-extended.js +0 -0
  142. /package/scripts/ui/{elements/inputs → inputs}/molecule-input.js +0 -0
  143. /package/scripts/ui/{elements/inputs → inputs}/tags-input.js +0 -0
  144. /package/scripts/{ux/Interactivity → ui/interactivity}/drag-and-drop.js +0 -0
  145. /package/scripts/{ux/Interactivity → ui/interactivity}/hints.js +0 -0
  146. /package/scripts/{ux/Interactivity → ui/interactivity}/wizard-hints.js +0 -0
  147. /package/scripts/{ux/Rendering → ui/rendering}/render-items.js +0 -0
  148. /package/scripts/ui/{components/tooltips → tooltips}/row-group-tooltips.js +0 -0
  149. /package/scripts/ui/{components/tooltips → tooltips}/tooltip-events.js +0 -0
  150. /package/scripts/ui/{components/tooltips → tooltips}/tooltips.js +0 -0
  151. /package/scripts/{ux/Navigations → ui/views}/navigation.js +0 -0
  152. /package/scripts/{ux/Managing Collections → ui/views}/virtual-view.js +0 -0
@@ -0,0 +1,3 @@
1
+ const df = await grok.data.files.openTable('Samples:Files/energy_uk.csv');
2
+ let view = grok.shell.addTableView(df);
3
+ view.addViewer('chord');
@@ -0,0 +1,13 @@
1
+ // https://datagrok.ai/help/visualize/viewers/globe
2
+
3
+ let view = grok.shell.addTableView(grok.data.demo.geo());
4
+
5
+ view.addViewer('globe', {
6
+ "latitudeColumnName": "lat",
7
+ "longitudeColumnName": "lng",
8
+ "magnitudeColumnName": "",
9
+ "colorByColumnName": "value",
10
+ "pointRadius": 15,
11
+ "pointAltitude": 50,
12
+ "autorotation": false
13
+ });
@@ -0,0 +1,9 @@
1
+ // https://datagrok.ai/help/visualize/viewers/radar
2
+
3
+ let view = grok.shell.addTableView(grok.data.demo.demog());
4
+
5
+ view.addViewer('radar', {
6
+ split: 'race',
7
+ value: 'age',
8
+ valueAggrType: 'avg'
9
+ });
@@ -0,0 +1,4 @@
1
+
2
+ const df = await grok.data.files.openTable('Samples:Files/energy_uk.csv');
3
+ let view = grok.shell.addTableView(df);
4
+ view.addViewer('sankey');
@@ -0,0 +1,3 @@
1
+ let view = grok.shell.addTableView(grok.data.demo.demog());
2
+
3
+ view.addViewer('sunburst');
@@ -0,0 +1,2 @@
1
+ let view = grok.shell.addTableView(grok.data.demo.demog());
2
+ view.addViewer('surface plot');
@@ -0,0 +1,3 @@
1
+ const df = await grok.data.files.openTable("System:AppData/ClinicalCase/ae.csv");
2
+ let view = grok.shell.addTableView(df);
3
+ view.addViewer('timelines');
@@ -0,0 +1,3 @@
1
+ let view = grok.shell.addTableView(grok.data.demo.demog());
2
+
3
+ view.addViewer('tree');
@@ -0,0 +1,5 @@
1
+ const df = await grok.data.files.openTable('Samples:Files/word_cloud.csv');
2
+
3
+ let view = grok.shell.addTableView(df);
4
+
5
+ view.addViewer('word cloud');
@@ -0,0 +1,14 @@
1
+ const df = grok.data.demo.demog();
2
+ const tv = grok.shell.addTableView(df);
3
+
4
+ tv.addViewer(DG.VIEWER.TRELLIS_PLOT, {
5
+ viewerType: 'Summary',
6
+ innerViewerLook: {
7
+ columnNames: ['weight', 'height'],
8
+ aggregations: [DG.STATS.MIN, DG.STATS.MED],
9
+ visualizationType: 'bars',
10
+ colorColumnName: 'age',
11
+ colorAggrType: 'stdev',
12
+ invertColorScheme: true
13
+ }
14
+ });
@@ -1,15 +1,15 @@
1
1
  //tags: View
2
2
  // Table views
3
- grok.shell.add(grok.data.demo.demog());
4
- grok.shell.add(grok.data.demo.wells());
3
+ grok.shell.addTableView(grok.data.demo.demog());
4
+ grok.shell.addTableView(grok.data.demo.wells());
5
5
 
6
6
  // Views
7
7
  grok.shell.newView('Test', [ui.h1('Regular View')]);
8
8
  grok.shell.addView(DG.View.createByType(DG.View.FUNCTIONS));
9
9
 
10
10
  // Iterate over table views and all views
11
- for (let tv of grok.shell.tableViews)
11
+ for (const tv of grok.shell.tableViews)
12
12
  grok.shell.info(`Table view: ${tv.name}`);
13
13
 
14
- for (let v of grok.shell.views)
15
- grok.shell.info(`View: ${v.name}`);
14
+ for (const v of grok.shell.views)
15
+ grok.shell.info(`View: ${v.name}`);
@@ -1,17 +1,56 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
2
  import * as grok from 'datagrok-api/grok';
3
- import {runTests, tests, TestContext} from '@datagrok-libraries/utils/src/test';
3
+ import {runTests, tests, TestContext, category, test as _test, delay} from '@datagrok-libraries/utils/src/test';
4
4
  export const _package = new DG.Package();
5
5
  export {tests};
6
6
 
7
7
  import './tests/test';
8
8
 
9
+ const skip = [
10
+ // Skipped
11
+ 'function-events', 'demo', 'ui-events', 'last-error', 'chem-benchmark',
12
+ 'menu-customization', '10k-columns-updates', '100-million-rows',
13
+ 'files' /* do not test manually */,
14
+
15
+ // To fix
16
+ 'custom-viewer-properties',
17
+ 'open-table-by-id',
18
+ 'charts-in-cells',
19
+ 'property-grid',
20
+ 'tree-view-adv',
21
+ 'attached-properties',
22
+ 'all-input-types',
23
+ 'add-single-filter',
24
+ 'custom-filters',
25
+ 'filter-group',
26
+ 'dynamic-loading'
27
+ ];
28
+
9
29
  //name: test
10
30
  //input: string category {optional: true}
11
31
  //input: string test {optional: true}
12
32
  //input: object testContext {optional: true}
13
33
  //output: dataframe result
14
34
  export async function test(category: string, test: string, testContext: TestContext): Promise<DG.DataFrame> {
35
+ testContext = new TestContext(false, false);
15
36
  const data = await runTests({category, test, testContext});
16
37
  return DG.DataFrame.fromObjects(data)!;
17
38
  }
39
+
40
+ //tags: init
41
+ export async function initTests() {
42
+ const scripts = await grok.dapi.scripts.filter('package.shortName = "ApiSamples"').list();
43
+ for (const script of scripts) {
44
+ category(('Scripts:' + script.options.path as string).replaceAll('/', ':'), () => {
45
+ _test(script.friendlyName, async () => {
46
+ await script.apply();
47
+ await delay(300);
48
+ // if (grok.shell.lastError) {
49
+ // const err = grok.shell.lastError;
50
+ // grok.shell.lastError = '';
51
+ // throw new Error(err);
52
+ // }
53
+ }, skip.includes(script.friendlyName) ? {skipReason: 'skip'} : undefined);
54
+ });
55
+ }
56
+ }
@@ -1,39 +0,0 @@
1
- //tags: FileInfo
2
- //help-url: https://datagrok.ai/help/develop/how-to/access-data
3
- // JS API methods for working with files
4
-
5
- (async () => {
6
-
7
- let res = null;
8
-
9
- // Write files
10
- await grok.dapi.files.write('Demo:TestJobs:Files:DemoFiles/testFile.dat', [0, 1, 2]);
11
- await grok.dapi.files.writeAsText('Demo:TestJobs:Files:DemoFiles/testFile.txt', 'testString');
12
-
13
- // Rename
14
- await grok.dapi.files.writeAsText('Demo:TestJobs:Files:DemoFiles/forRename.txt', 'testString');
15
- await grok.dapi.files.rename('Demo:TestJobs:Files:DemoFiles/forRename.txt', 'renamed.txt');
16
-
17
- // Read files
18
- res = await grok.dapi.files.readAsBytes('Demo:TestJobs:Files:DemoFiles/testFile.dat');
19
- console.log(`readAsBytes: ${res}`);
20
- res = await grok.dapi.files.readAsText('Demo:TestJobs:Files:DemoFiles/testFile.txt');
21
- console.log(`readAsText: ${res}`);
22
- res = await grok.dapi.files.exists('Demo:TestJobs:Files:DemoFiles/testFile.dat');
23
- console.log(`testFile.dat exists: ${res}`);
24
-
25
- // Search files
26
- let recursive = true;
27
- let searchPattern = 'world';
28
- res = await grok.dapi.files.list('Demo:TestJobs:Files:DemoFiles/geo', recursive, searchPattern);
29
- console.log(`list: ${res}`);
30
-
31
- // Move files
32
- await grok.dapi.files.move(['Demo:TestJobs:Files:DemoFiles/testFile.txt'], 'geo');
33
- res = await grok.dapi.files.exists('Demo:TestJobs:Files:DemoFiles/geo/testFile.txt');
34
- console.log(`testFile.txt was moved to geo: ${res}`);
35
-
36
- // Delete files
37
- await grok.dapi.files.delete('Demo:TestJobs:Files:DemoFiles/geo/testFile.txt');
38
- await grok.dapi.files.delete('Demo:TestJobs:Files:DemoFiles/testFile.dat');
39
- })();
@@ -1,4 +0,0 @@
1
- let view = grok.shell.newView('Usage');
2
-
3
- grok.data.query('UsageAnalysis:ErrorsOnDate', {'date': 'today'})
4
- .then(t => view.append(DG.Viewer.grid(t).root));
@@ -1,4 +0,0 @@
1
- let view = grok.shell.newView('Usage');
2
-
3
- grok.data.query('UsageAnalysis:EventsSummaryOnDate', {'date': 'today'})
4
- .then(t => view.append(DG.Viewer.barChart(t).root));
@@ -1,11 +0,0 @@
1
- let view = grok.shell.newView('Usage');
2
-
3
- let last = new Date();
4
- last.setHours(last.getHours() - 5);
5
-
6
- let timer = setInterval(function () {
7
- grok.data.query('UsageAnalysis:EventsOnDate', {'date': ('after ' + last.toLocaleString().replace(',', ''))})
8
- .then((t) => {
9
- grok.shell.addTableView(t);
10
- });
11
- }, 5000);
@@ -1,328 +0,0 @@
1
- //name: color-checker
2
- //description: color contrast and blindness check
3
- //language: javascript
4
-
5
- let view = grok.shell.newView('HexToRGB');
6
- view.box = true;
7
-
8
- let contrastBox = ui.div();
9
- contrastBox.style.padding = '5px';
10
- contrastBox.style.maxWidth = '150px';
11
- contrastBox.style.marginBottom = '10px';
12
-
13
- let hexActive = ui.boolInput('', true, v=>{
14
- if (v)
15
- colorHex.enabled = true;
16
- else
17
- colorHex.enabled = false;
18
- if ((v)&&(rgbActive.value)){
19
- rgbActive.value = false;
20
- }
21
- });
22
-
23
- let rgbActive = ui.boolInput('', false, v=>{
24
- if (v)
25
- colorRgb.enabled = true;
26
- else
27
- colorRgb.enabled = false;
28
- if ((v)&&(hexActive.value)){
29
- hexActive.value = false;
30
- }
31
- });
32
-
33
- let colorBox = ui.div();
34
- colorBox.style.marginBottom = '10px';
35
- colorBox.style.padding = '5px';
36
- colorBox.style.maxWidth = '150px';
37
-
38
- let colorBlidnessBox = ui.div();
39
- colorBlidnessBox.style.marginBottom = '10px';
40
- colorBlidnessBox.style.maxWidth = '150px';
41
-
42
- let inputColor = ui.element('input');
43
- inputColor.type = 'color';
44
- inputColor.style.width = '40px';
45
- inputColor.style.height = '20px';
46
- inputColor.style.marginLeft = '10px';
47
-
48
- inputColor.onchange = (e) =>{
49
- if (colorHex.enabled){
50
- colorHex.value = inputColor.value.substring(1);
51
- }else{
52
- let rgb = hexToRGB(inputColor.value.substring(1));
53
- colorRgb.value = rgb.R+','+rgb.G+','+rgb.B;
54
- }
55
-
56
- }
57
-
58
-
59
- let colorHex = ui.stringInput('HEX:', '', v=>{
60
- let result = colorHex.value.match(/[\d\w]{6}/);
61
- colorBox.innerHTML = '';
62
- contrastBox.innerHTML = '';
63
- saveBox.innerHTML = '';
64
- contrastBox.style.backgroundColor = 'white';
65
- colorBox.style.backgroundColor = 'white';
66
-
67
- if (result!=null){
68
- let rgb = hexToRGB(colorHex.value);
69
- if (colorHex.enabled){
70
- colorRgb.value = rgb.R+','+rgb.G+','+rgb.B;
71
- calcRatio(rgb);
72
- }
73
- }
74
- if ((colorHex.value =='')&&(colorRgb.value.length>0))
75
- colorRgb.value = '';
76
- });
77
-
78
- let colorRgb = ui.stringInput('RGB:', '', v=>{
79
- let result = colorRgb.value.match(/([\d]{1,3}\,[\d]{1,3}\,[\d]{1,3}){1,12}/);
80
- colorBox.innerHTML = '';
81
- contrastBox.innerHTML = '';
82
- saveBox.innerHTML = '';
83
- contrastBox.style.backgroundColor = 'white';
84
- colorBox.style.backgroundColor = 'white';
85
-
86
- if (result!=null){
87
- let hex = rgbToHex(result[0]);
88
- let rgbresult = colorRgb.value.split(',');
89
- let rgb = {
90
- 'R': rgbresult[0],
91
- 'G': rgbresult[1],
92
- 'B': rgbresult[2]
93
- };
94
- if (colorRgb.enabled){
95
- colorHex.value = hex;
96
- calcRatio(rgb);
97
- }
98
- }
99
- if (colorRgb.value == '')
100
- colorHex.value = '';
101
- });
102
- colorRgb.enabled = false;
103
- colorRgb.input.setAttribute('maxlength','11');
104
-
105
- let copyRGB = ui.button(ui.iconFA('copy'), ()=>{
106
- copyToClipboard(colorRgb.value);
107
- grok.shell.info(colorRgb.value);
108
- })
109
-
110
- let copyHEX = ui.button(ui.iconFA('copy'), ()=>{
111
- copyToClipboard(colorHex.value);
112
- grok.shell.info(colorHex.value);
113
- })
114
-
115
- view.box = true;
116
- let palette = ui.panel([
117
- ui.h2('Palette')
118
- ]);
119
- let saveBox = ui.div();
120
- view.append(ui.splitH([
121
- ui.panel([
122
- ui.divH([
123
- hexActive,
124
- colorHex,
125
- copyHEX
126
- ]),
127
- ui.divH([
128
- rgbActive,
129
- colorRgb,
130
- copyRGB
131
- ]),
132
- ui.divH([
133
- ui.div([],{style:{width:'35px'}}),
134
- ui.label('Picker'),
135
- inputColor
136
- ],{style:{alignItems:'center',margin:'10px 0'}}),
137
- ui.div([
138
- ui.label('Color:'),
139
- colorBox,
140
- ui.label('Contrast:'),
141
- contrastBox,
142
- ui.label('Color blindness:'),
143
- colorBlidnessBox,
144
- saveBox
145
- ],{style:{margin:'10px 0 0 35px'}})
146
- ]),
147
- palette
148
- ]));
149
-
150
-
151
- //calculation process
152
-
153
- function calcRatio(rgb){
154
-
155
- let textColor = colorBalance(rgb);
156
- let flag = '';
157
- colorBox.innerHTML = 'Text color';
158
- colorBlidnessBox.innerHTML = '';
159
- colorBox.style.color = textColor;
160
- colorBox.style.backgroundColor = '#'+colorHex.value;
161
-
162
- if (textColor == 'black'){
163
- textColor = [0,0,0];
164
- }else{
165
- textColor = [255,255,255];
166
- }
167
-
168
- let ratio = contrast(rgb, textColor).toFixed(2);
169
- let ratioResult = ui.h1(ratio);
170
- ratioResult.style.margin = '0px';
171
- if(ratio>7){
172
- flag = 'Good';
173
- contrastBox.style.color = 'var(--green-2)';
174
- contrastBox.style.backgroundColor = 'var(--green-1)';
175
- }else if ((ratio>4.5)&&(ratio<7)){
176
- flag = 'Avarage';
177
- contrastBox.style.color = 'var(--orange-2)';
178
- contrastBox.style.backgroundColor = 'var(--orange-1)';
179
- }else if(ratio<4.5){
180
- flag = 'Bad';
181
- contrastBox.style.color = 'var(--red-2)';
182
- contrastBox.style.backgroundColor = 'var(--red-1)';
183
- }
184
-
185
- contrastBox.append(
186
- ui.div([
187
- ratioResult,
188
- ui.divText(flag)
189
- ]));
190
-
191
- let protanopia = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Protanopia'));
192
- let protanomaly = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Protanomaly'));
193
- let deuteranopia = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Deuteranopia'));
194
- let deuteranomaly = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Deuteranomaly'));
195
- let tritanopia = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Tritanopia'));
196
- let tritanomaly = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Tritanomaly'));
197
- let achromatopsia = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Achromatopsia'));
198
- let achromatomaly = ColorMatrix({R:rgb.R,G:rgb.G,B:rgb.B,A:1},Blind('Achromatomaly'));
199
-
200
- colorBlidnessBox.append(
201
- ui.divH([
202
- ui.div(['Protanopia ('+contrast(protanopia, textColor).toFixed(2)+')'],{style:{margin:'0 10px'}}),
203
- ],{style:{minWidth:'200px',color:'rgb('+textColor+')',alignItems:'center',padding:'5px 0', backgroundColor:'rgb('+protanopia.R+','+protanopia.G+','+protanopia.B+')'}}),
204
- ui.divH([
205
- ui.div(['Protanomaly ('+contrast(protanomaly, textColor).toFixed(2)+')'],{style:{margin:'0 10px'}}),
206
- ],{style:{minWidth:'200px',color:'rgb('+textColor+')',alignItems:'center',padding:'5px 0', backgroundColor:'rgb('+protanomaly.R+','+protanomaly.G+','+protanomaly.B+')'}}),
207
- ui.divH([
208
- ui.div(['Deuteranopia ('+contrast(deuteranopia, textColor).toFixed(2)+')'],{style:{margin:'0 10px'}}),
209
- ],{style:{minWidth:'200px',color:'rgb('+textColor+')',alignItems:'center',padding:'5px 0', backgroundColor:'rgb('+deuteranopia.R+','+deuteranopia.G+','+deuteranopia.B+')'}}),
210
- ui.divH([
211
- ui.div(['Deuteranomaly ('+contrast(deuteranomaly, textColor).toFixed(2)+')'],{style:{margin:'0 10px'}}),
212
- ],{style:{minWidth:'200px',color:'rgb('+textColor+')',alignItems:'center',padding:'5px 0', backgroundColor:'rgb('+deuteranomaly.R+','+deuteranomaly.G+','+deuteranomaly.B+')'}}),
213
- ui.divH([
214
- ui.div(['Achromatopsia ('+contrast(achromatopsia, textColor).toFixed(2)+')'],{style:{margin:'0 10px'}}),
215
- ],{style:{minWidth:'200px',color:'rgb('+textColor+')',alignItems:'center',padding:'5px 0', backgroundColor:'rgb('+achromatopsia.R+','+achromatopsia.G+','+achromatopsia.B+')'}}),
216
- ui.divH([
217
- ui.div(['Achromatomaly ('+contrast(achromatomaly, textColor).toFixed(2)+')'],{style:{margin:'0 10px'}}),
218
- ],{style:{minWidth:'200px',color:'rgb('+textColor+')',alignItems:'center',padding:'5px 0', backgroundColor:'rgb('+achromatomaly.R+','+achromatomaly.G+','+achromatomaly.B+')'}}),
219
- );
220
-
221
- saveBox.append(ui.bigButton('Save color',()=>{
222
- let color = ui.divH([
223
- ui.div(['#'+colorHex.value],{style:{marginLeft:'10px'}}),
224
- ui.div([ratio+' - '+flag],{style:{margin:'0 20px'}}),
225
- ],{style:{alignItems:'center', minWidth:'200px', padding:'5px 0', backgroundColor:'#'+colorHex.value}});
226
- $(color).attr('data-id',colorHex.value);
227
- $(color).css('color','rgb('+textColor+')');
228
-
229
- palette.append(ui.divH([
230
- color,
231
- ui.button(ui.iconFA('copy'),()=>{
232
- copyToClipboard($(color).children().first().text().substring(1));
233
- grok.shell.info($(color).children().first().text().substring(1));
234
- }),
235
- ui.button(ui.iconFA('trash-alt'),()=>{
236
- $(color).parent().detach();
237
- })
238
- ]))
239
- }))
240
- }
241
-
242
- //color converting
243
- function hexToRGB(h) {
244
- let aRgbHex = [];
245
- if (h.length==3){
246
- aRgbHex = h.match(/.{1,1}/g);
247
- aRgbHex[0] = aRgbHex[0].toString().repeat(2);
248
- aRgbHex[1] = aRgbHex[1].toString().repeat(2);
249
- aRgbHex[2] = aRgbHex[2].toString().repeat(2);
250
- }
251
- else if (h.length==6)
252
- aRgbHex = h.match(/.{1,2}/g);
253
- var aRgb = {
254
- 'R': parseInt(aRgbHex[0], 16),
255
- 'G': parseInt(aRgbHex[1], 16),
256
- 'B': parseInt(aRgbHex[2], 16)
257
- };
258
- return aRgb
259
- }
260
-
261
- function rgbToHex(color) {
262
- let rgb = color.split(',')
263
- let hex = parseInt(rgb[0]).toString(16) + parseInt(rgb[1]).toString(16) + parseInt(rgb[2]).toString(16);
264
- return hex
265
- }
266
-
267
- //colorbalance
268
- function colorBalance(Color){
269
- let luma = ((0.299 * Color.R) + (0.587 * Color.G) + (0.114 * Color.B)) / 255;
270
- return luma > 0.5 ? 'black' : 'white';
271
- }
272
-
273
- //copy to clipboard
274
- function copyToClipboard(text) {
275
- var dummy = document.createElement("textarea");
276
- document.body.appendChild(dummy);
277
- dummy.value = text;
278
- dummy.select();
279
- document.execCommand("copy");
280
- document.body.removeChild(dummy);
281
- }
282
-
283
- //Contrast ratio
284
- function luminance(r, g, b) {
285
- var a = [r, g, b].map(function (v) {
286
- v /= 255;
287
- return v <= 0.03928
288
- ? v / 12.92
289
- : Math.pow( (v + 0.055) / 1.055, 2.4 );
290
- });
291
- return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
292
- }
293
- function contrast(rgbBg, rgbText) {
294
- var lum1 = luminance(rgbBg.R, rgbBg.G, rgbBg.B);
295
- var lum2 = luminance(rgbText[0], rgbText[1], rgbText[2]);
296
- var brightest = Math.max(lum1, lum2);
297
- var darkest = Math.min(lum1, lum2);
298
- return (brightest + 0.05)
299
- / (darkest + 0.05);
300
- }
301
-
302
- //*****************
303
- function ColorMatrix(o,m) { // takes: RGBA object, Matrix array
304
-
305
- function fu(n) { return(n<0?0:(n<255?n:255)); }
306
-
307
- var r=((o.R*m[0])+(o.G*m[1])+(o.B*m[2])+(o.A*m[3])+m[4]);
308
- var g=((o.R*m[5])+(o.G*m[6])+(o.B*m[7])+(o.A*m[8])+m[9]);
309
- var b=((o.R*m[10])+(o.G*m[11])+(o.B*m[12])+(o.A*m[13])+m[14]);
310
- var a=((o.R*m[15])+(o.G*m[16])+(o.B*m[17])+(o.A*m[18])+m[19]);
311
-
312
- return({'R':fu(r), 'G':fu(g), 'B':fu(b), 'A':fu(a)});
313
-
314
- };
315
-
316
- function Blind (v) { // this function just returns the Matrix
317
-
318
- return({'Normal':[1,0,0,0,0, 0,1,0,0,0, 0,0,1,0,0, 0,0,0,1,0, 0,0,0,0,1],
319
- 'Protanopia':[0.567,0.433,0,0,0, 0.558,0.442,0,0,0, 0,0.242,0.758,0,0, 0,0,0,1,0, 0,0,0,0,1],
320
- 'Protanomaly':[0.817,0.183,0,0,0, 0.333,0.667,0,0,0, 0,0.125,0.875,0,0, 0,0,0,1,0, 0,0,0,0,1],
321
- 'Deuteranopia':[0.625,0.375,0,0,0, 0.7,0.3,0,0,0, 0,0.3,0.7,0,0, 0,0,0,1,0, 0,0,0,0,1],
322
- 'Deuteranomaly':[0.8,0.2,0,0,0, 0.258,0.742,0,0,0, 0,0.142,0.858,0,0, 0,0,0,1,0, 0,0,0,0,1],
323
- 'Tritanopia':[0.95,0.05,0,0,0, 0,0.433,0.567,0,0, 0,0.475,0.525,0,0, 0,0,0,1,0, 0,0,0,0,1],
324
- 'Tritanomaly':[0.967,0.033,0,0,0, 0,0.733,0.267,0,0, 0,0.183,0.817,0,0, 0,0,0,1,0, 0,0,0,0,1],
325
- 'Achromatopsia':[0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0.299,0.587,0.114,0,0, 0,0,0,1,0, 0,0,0,0,1],
326
- 'Achromatomaly':[0.618,0.320,0.062,0,0, 0.163,0.775,0.062,0,0, 0.163,0.320,0.516,0,0,0,0,0,1,0,0,0,0,0]}[v]);
327
-
328
- };
@@ -1,19 +0,0 @@
1
- // Panels
2
-
3
- let v = grok.shell.newView('Tabs');
4
-
5
- // Simple API
6
- v.append(ui.div([
7
- ui.h1('First panel'),
8
- 'Panel content'
9
- ]));
10
-
11
- v.append(ui.div([
12
- ui.h1('Second panel'),
13
- ui.inputs([
14
- ui.stringInput('Name', 5),
15
- ui.choiceInput('Algorithm', 'SPE', ['SPE', 'PCA']),
16
- ui.intInput('Number of steps', 5)
17
- ]),
18
- ui.bigButton('RUN')
19
- ]));
@@ -1,16 +0,0 @@
1
- # Docking
2
-
3
- Datagrok provides a flexible window management system, where windows
4
- could be either dragged out and positioned manually, or set up automatically.
5
-
6
- ## Top-level window docking
7
-
8
- Use `grok.shell.dockManager` to dock, undock, or reposition windows.
9
- See also `View.dockNode`
10
-
11
- ## Nested docking
12
-
13
- Some of the views contain a nested docking manager, which allows to manage
14
- windows within that particular view (they cannot be undocked and docked on
15
- a top level, or within a different view). See `dockManager` property of the
16
- View class.
@@ -1,24 +0,0 @@
1
- // Creating HTML-driven tables
2
- // For high-performance grid, check out samples under /grid
3
-
4
- grok.shell.newView('table from map', [
5
- ui.tableFromMap({
6
- user: grok.shell.user.toMarkup(),
7
- project: grok.shell.project.toMarkup(),
8
- time: new Date(),
9
- })
10
- ]);
11
-
12
- let view = grok.shell.newView('table with renderer');
13
- var myList = [
14
- {key: 'first object', value: 5},
15
- {key: 'second object', value: false},
16
- {key: 'third object', value: false},
17
- ];
18
-
19
- let table = DG.HtmlTable.create(myList, (item, idx) => [item.key, item.value]);
20
-
21
- //and let's remove the third object from the table
22
- table.remove(myList[2]);
23
-
24
- view.root.appendChild(table.root);
@@ -1,46 +0,0 @@
1
- // Different input types
2
-
3
- // Adding an icon to each input that lets you inspect the value
4
- // grok.events.onInputCreated.subscribe(
5
- // (i) => i.root.appendChild(ui.iconFA('eye', () => grok.shell.o = i.value)));
6
-
7
- // Different input types
8
-
9
- // Adding an icon to each input that lets you inspect the value
10
- // grok.events.onInputCreated.subscribe(
11
- // (i) => i.root.appendChild(ui.iconFA('eye', () => grok.shell.o = i.value)));
12
-
13
- let v = grok.shell.newView('demo: inputs');
14
-
15
- let type = ui.choiceInput('Form type', 'Default', ['Default', 'Left', 'Wide', 'Condensed'], (x)=>{
16
- switch (x){
17
- case 'Default':
18
- form.className = 'ui-form';
19
- break;
20
- case 'Left':
21
- form.className = 'ui-form ui-form-left';
22
- break;
23
- case 'Wide':
24
- form.className = 'ui-form ui-form-wide';
25
- break;
26
- case 'Condensed':
27
- form.className = 'ui-form ui-form-condensed';
28
- break;
29
- default: form.className = '.ui-form';
30
- }
31
- });
32
-
33
- let name = ui.stringInput('Name', 'Arthur Dent');
34
- let age = ui.intInput('Age', 30);
35
- let date = ui.dateInput('Birthday', dayjs('1970-5-10'));
36
- let alien = ui.boolInput('Alien', false);
37
- let friends = ui.multiChoiceInput('Friends', ['Ford', 'Fenchurch'], ['Ford', 'Fenchurch', 'Zaphod', 'Slartibartfast']);
38
- let active = ui.switchInput('Active', true);
39
- let color = ui.colorInput('Favorite color', '#ff0000');
40
- let data = ui.tableInput('Details', null);
41
- let memo = ui.textInput('Memo', '');
42
-
43
- let form = ui.form([type, name, age, date, alien, friends, active, color, data, memo]);
44
-
45
- form.append(ui.buttonsInput([ui.bigButton('Submit', ()=>{grok.shell.info(form.className)})]));
46
- v.append(form);
@@ -1,8 +0,0 @@
1
- const typeAhead = ui.typeAhead('Countries', {source: {local: ['USA', 'Ukraine', 'Antigua', 'United Kingdom', 'United Arab Emirates']},
2
- minLength: 2, limit: 3, hint: true, autoSelect: true, highlight: true, diacritics: true,
3
- onSubmit: (event, value) => grok.shell.info(`The value is ${value?.label}`), debounceRemote: 100});
4
-
5
- typeAhead.onInput(() => grok.shell.info('input event'));
6
- typeAhead.onChanged(() => grok.shell.info('change event'));
7
-
8
- grok.shell.newView('TypeAhead', [ui.ribbonPanel([typeAhead.root])]);