@datagrok/api-samples 1.0.3 → 1.0.4

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 (50) hide show
  1. package/README.md +2 -2
  2. package/dist/package-test.js +519 -0
  3. package/dist/package.js +30 -0
  4. package/package.json +38 -4
  5. package/package.png +0 -0
  6. package/scripts/dapi/projects-list.js +1 -1
  7. package/scripts/dapi/users.js +0 -1
  8. package/scripts/data-frame/advanced/qualified-numbers.js +1 -1
  9. package/scripts/data-frame/advanced/virtual-int-column.js +1 -1
  10. package/scripts/data-frame/bitset/and-or-xor.js +2 -2
  11. package/scripts/data-frame/bitset/select-rows-fast.js +1 -1
  12. package/scripts/data-frame/construction/create-from-csv.js +1 -1
  13. package/scripts/data-frame/row-matching/select-rows.js +1 -1
  14. package/scripts/demo/stock-broker.js +2 -3
  15. package/scripts/domains/chem/chem-benchmark.js +137 -0
  16. package/scripts/domains/chem/substructure-search-benchmark.js +45 -0
  17. package/scripts/domains/chem/substructure-search-smarts-molfile-als.js +33 -0
  18. package/scripts/domains/chem/substructure-search-smarts.js +12 -0
  19. package/scripts/domains/chem/substructure-search.js +8 -42
  20. package/scripts/events/tree-view-events.js +29 -0
  21. package/scripts/functions/calling.js +1 -1
  22. package/scripts/functions/progress.js +2 -0
  23. package/scripts/functions/register-function.js +2 -2
  24. package/scripts/grid/color-coding-conditional.js +8 -0
  25. package/scripts/grid/html-cells/html-markup-cells.js +1 -1
  26. package/scripts/shell/ui-parts.js +1 -0
  27. package/scripts/ui/components/file-browser.js +8 -0
  28. package/scripts/ui/dialogs/dialogs-advanced.js +1 -1
  29. package/scripts/ui/dialogs/modal.js +5 -7
  30. package/scripts/ui/elements/inputs/inputs-events.js +1 -1
  31. package/scripts/ui/elements/inputs/inputs.js +36 -9
  32. package/scripts/ui/inputs/custom-inputs.js +11 -0
  33. package/scripts/ui/inputs/input-events.js +22 -0
  34. package/scripts/ui/ui-events.js +0 -1
  35. package/scripts/ui/viewers/advanced/attached-properties.js +20 -0
  36. package/scripts/ui/viewers/advanced/default-properties.js +17 -0
  37. package/scripts/ui/viewers/custom-viewer-properties.js +1 -1
  38. package/scripts/ui/viewers/filter-select-highlight.js +19 -0
  39. package/scripts/ui/viewers/types/surface-plot.js +24 -0
  40. package/scripts/ui/views/files-view.js +6 -0
  41. package/scripts/ui/views/views.js +2 -0
  42. package/scripts/ux/Interactivity/hints.js +22 -0
  43. package/src/package-test.ts +17 -0
  44. package/src/package.ts +4 -0
  45. package/src/tests/test.ts +11 -0
  46. package/tsconfig.json +71 -0
  47. package/webpack.config.js +37 -0
  48. package/package.js +0 -3
  49. package/scripts/domains/chem/substructure-search-graph.js +0 -11
  50. package/scripts/domains/chem/substructure-search-library.js +0 -11
@@ -0,0 +1,30 @@
1
+ var apisamples;
2
+ /******/ (() => { // webpackBootstrap
3
+ /******/ "use strict";
4
+ /******/ // The require scope
5
+ /******/ var __webpack_require__ = {};
6
+ /******/
7
+ /************************************************************************/
8
+ /******/ /* webpack/runtime/make namespace object */
9
+ /******/ (() => {
10
+ /******/ // define __esModule on exports
11
+ /******/ __webpack_require__.r = (exports) => {
12
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
13
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
14
+ /******/ }
15
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
16
+ /******/ };
17
+ /******/ })();
18
+ /******/
19
+ /************************************************************************/
20
+ var __webpack_exports__ = {};
21
+ /*!************************!*\
22
+ !*** ./src/package.ts ***!
23
+ \************************/
24
+ __webpack_require__.r(__webpack_exports__);
25
+
26
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFja2FnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInBhY2thZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbIi8qIERvIG5vdCBjaGFuZ2UgdGhlc2UgaW1wb3J0IGxpbmVzLiBEYXRhZ3JvayB3aWxsIGltcG9ydCBBUEkgbGlicmFyeSBpbiBleGFjdGx5IHRoZSBzYW1lIG1hbm5lciAqL1xuaW1wb3J0ICogYXMgZ3JvayBmcm9tICdkYXRhZ3Jvay1hcGkvZ3Jvayc7XG5pbXBvcnQgKiBhcyB1aSBmcm9tICdkYXRhZ3Jvay1hcGkvdWknO1xuaW1wb3J0ICogYXMgREcgZnJvbSAnZGF0YWdyb2stYXBpL2RnJztcbiJdfQ==
27
+ apisamples = __webpack_exports__;
28
+ /******/ })()
29
+ ;
30
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGFja2FnZS5qcyIsIm1hcHBpbmdzIjoiOzs7VUFBQTtVQUNBOzs7OztXQ0RBO1dBQ0E7V0FDQTtXQUNBLHVEQUF1RCxpQkFBaUI7V0FDeEU7V0FDQSxnREFBZ0QsYUFBYTtXQUM3RDs7Ozs7Ozs7O0FDTlU7QUFDViwyQ0FBMkMsdWQiLCJzb3VyY2VzIjpbIndlYnBhY2s6Ly9hcGlzYW1wbGVzL3dlYnBhY2svYm9vdHN0cmFwIiwid2VicGFjazovL2FwaXNhbXBsZXMvd2VicGFjay9ydW50aW1lL21ha2UgbmFtZXNwYWNlIG9iamVjdCIsIndlYnBhY2s6Ly9hcGlzYW1wbGVzLy4vc3JjL3BhY2thZ2UudHMiXSwic291cmNlc0NvbnRlbnQiOlsiLy8gVGhlIHJlcXVpcmUgc2NvcGVcbnZhciBfX3dlYnBhY2tfcmVxdWlyZV9fID0ge307XG5cbiIsIi8vIGRlZmluZSBfX2VzTW9kdWxlIG9uIGV4cG9ydHNcbl9fd2VicGFja19yZXF1aXJlX18uciA9IChleHBvcnRzKSA9PiB7XG5cdGlmKHR5cGVvZiBTeW1ib2wgIT09ICd1bmRlZmluZWQnICYmIFN5bWJvbC50b1N0cmluZ1RhZykge1xuXHRcdE9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCBTeW1ib2wudG9TdHJpbmdUYWcsIHsgdmFsdWU6ICdNb2R1bGUnIH0pO1xuXHR9XG5cdE9iamVjdC5kZWZpbmVQcm9wZXJ0eShleHBvcnRzLCAnX19lc01vZHVsZScsIHsgdmFsdWU6IHRydWUgfSk7XG59OyIsImV4cG9ydCB7fTtcbi8vIyBzb3VyY2VNYXBwaW5nVVJMPWRhdGE6YXBwbGljYXRpb24vanNvbjtiYXNlNjQsZXlKMlpYSnphVzl1SWpvekxDSm1hV3hsSWpvaWNHRmphMkZuWlM1cWN5SXNJbk52ZFhKalpWSnZiM1FpT2lJaUxDSnpiM1Z5WTJWeklqcGJJbkJoWTJ0aFoyVXVkSE1pWFN3aWJtRnRaWE1pT2x0ZExDSnRZWEJ3YVc1bmN5STZJaUlzSW5OdmRYSmpaWE5EYjI1MFpXNTBJanBiSWk4cUlFUnZJRzV2ZENCamFHRnVaMlVnZEdobGMyVWdhVzF3YjNKMElHeHBibVZ6TGlCRVlYUmhaM0p2YXlCM2FXeHNJR2x0Y0c5eWRDQkJVRWtnYkdsaWNtRnllU0JwYmlCbGVHRmpkR3g1SUhSb1pTQnpZVzFsSUcxaGJtNWxjaUFxTDF4dWFXMXdiM0owSUNvZ1lYTWdaM0p2YXlCbWNtOXRJQ2RrWVhSaFozSnZheTFoY0drdlozSnZheWM3WEc1cGJYQnZjblFnS2lCaGN5QjFhU0JtY205dElDZGtZWFJoWjNKdmF5MWhjR2t2ZFdrbk8xeHVhVzF3YjNKMElDb2dZWE1nUkVjZ1puSnZiU0FuWkdGMFlXZHliMnN0WVhCcEwyUm5KenRjYmlKZGZRPT0iXSwibmFtZXMiOltdLCJzb3VyY2VSb290IjoiIn0=
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@datagrok/api-samples",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
+ "author": {
5
+ "name": "Alexander Paramonov",
6
+ "email": "aparamonov@datagrok.ai"
7
+ },
8
+ "dependencies": {
9
+ "@datagrok-libraries/utils": "^1.15.5",
10
+ "cash-dom": "^8.1.1",
11
+ "datagrok-api": "^1.12.0",
12
+ "dayjs": "latest",
13
+ "rxjs": "^6.6.7",
14
+ "wu": "latest"
15
+ },
16
+ "devDependencies": {
17
+ "@types/wu": "^2.1.42",
18
+ "@typescript-eslint/eslint-plugin": "^5.26.0",
19
+ "@typescript-eslint/parser": "^5.26.0",
20
+ "datagrok-tools": "^4.7.2",
21
+ "eslint": "^8.16.0",
22
+ "eslint-config-google": "^0.14.0",
23
+ "@types/js-yaml": "^4.0.5",
24
+ "js-yaml": "^4.1.0",
25
+ "puppeteer": "^13.7.0",
26
+ "root-require": "latest",
27
+ "ts-loader": "^9.2.6",
28
+ "typescript": "^4.4.4",
29
+ "webpack": "^5.59.1",
30
+ "webpack-cli": "^4.9.1",
31
+ "@types/node-fetch": "^2.6.2",
32
+ "node-fetch": "^2.6.7"
33
+ },
4
34
  "friendlyName": "API Samples",
5
35
  "description": "API Samples",
6
36
  "repository": {
@@ -10,8 +40,12 @@
10
40
  },
11
41
  "sources": [],
12
42
  "scripts": {
13
- "samples-upload": "datagrok-upload http://localhost:8082 deploy",
14
- "publish samples local": "grok publish local"
43
+ "publish samples local": "grok publish local",
44
+ "publish samples localhost": "grok publish localhost",
45
+ "build": "webpack",
46
+ "test": "grok test",
47
+ "test-dev": "grok test --host dev",
48
+ "test-local": "grok test --host localhost"
15
49
  },
16
50
  "canEdit": [
17
51
  "Developers"
@@ -19,5 +53,5 @@
19
53
  "canView": [
20
54
  "All users"
21
55
  ],
22
- "category": "Dev"
56
+ "category": "Development"
23
57
  }
package/package.png CHANGED
Binary file
@@ -1,5 +1,5 @@
1
1
  //tags: Project
2
- //help-url: https://datagrok.ai/help/overview/project
2
+ //help-url: https://datagrok.ai/help/datagrok/project
3
3
  // gets #demo project list and shows them in the view
4
4
 
5
5
  let view = grok.shell.newView('projects');
@@ -1,6 +1,5 @@
1
1
  let user = DG.User.create();
2
2
  user.login = 'newlogin';
3
- user.status = USER_STATUS.STATUS_NEW;
4
3
  user.firstName = 'new';
5
4
  user.lastName = 'user';
6
5
 
@@ -4,7 +4,7 @@
4
4
  let manual = DG.Column.qnum('manual', 3);
5
5
  manual.set(0, DG.Qnum.greater(5));
6
6
  manual.set(1, DG.Qnum.exact(5));
7
- manual.set(1, DG.Qnum.less(5));
7
+ manual.set(2, DG.Qnum.less(5));
8
8
 
9
9
  // Method 2: initialize with exact values (last parameter set to true)
10
10
  // When last parameter is set to true, the last two bits of each number get set
@@ -3,4 +3,4 @@
3
3
 
4
4
  let table = grok.data.demo.demog();
5
5
  table.columns.addNewVirtual('car', (i) => i * 2, DG.TYPE.INT);
6
- grok.shell.add(table);
6
+ grok.shell.addTableView(table);
@@ -1,11 +1,11 @@
1
- // Bitwise AND, OR, XOR, and AND_OR opetations
1
+ // Bitwise AND, OR, XOR, and AND_NOT operations
2
2
 
3
3
  let bs1 = DG.BitSet.fromString('11100');
4
4
  let bs2 = DG.BitSet.fromString('00111');
5
5
 
6
6
  let s = `
7
7
  b1: ${bs1.toBinaryString()}
8
- b2: ${bs1.toBinaryString()}
8
+ b2: ${bs2.toBinaryString()}
9
9
  and: ${bs1.clone().and(bs2).toBinaryString()}
10
10
  or: ${bs1.clone().or(bs2).toBinaryString()}
11
11
  xor: ${bs1.clone().xor(bs2).toBinaryString()}
@@ -2,7 +2,7 @@
2
2
 
3
3
  let demog = grok.data.demo.demog();
4
4
  let selection = demog.selection;
5
- grok.shell.add(demog);
5
+ grok.shell.addTableView(demog);
6
6
 
7
7
  // method 1: init(predicate)
8
8
  selection.init((i) => i % 2 === 0);
@@ -8,6 +8,6 @@ Honda, Accord, 6, 1.8, 20000
8
8
  BMW, 328i, 4, 1.7, 60000
9
9
  BMW, 535i, 6, 1.5, 35000
10
10
  Tesla, Roadster, , 1.6, 100000
11
- Tesla, Model S, , 1.6, 120000`, {columnImportOptions: [{name: 'model', semType: 'carModel'}]}););
11
+ Tesla, Model S, , 1.6, 120000`, {columnImportOptions: [{name: 'model', semType: 'carModel'}]});
12
12
 
13
13
  grok.shell.addTableView(table);
@@ -3,4 +3,4 @@
3
3
  let demog = grok.data.demo.demog();
4
4
  demog.rows.select((row) => row.sex === 'M');
5
5
  demog.rows.filter((row) => row.age > 42);
6
- grok.shell.add(demog);
6
+ grok.shell.addTableView(demog);
@@ -18,8 +18,7 @@ function runStockBroker() {
18
18
  df.columns.addNew('up', DG.TYPE.STRING);
19
19
 
20
20
  let addMilliseconds = function (time, ms) {
21
- time.setMilliseconds(time.getMilliseconds() + ms);
22
- return time;
21
+ return dayjs(time).add(ms, 'millisecond').toDate();
23
22
  };
24
23
 
25
24
  let tick = 20; // ms
@@ -30,7 +29,7 @@ function runStockBroker() {
30
29
  return v;
31
30
  };
32
31
  let upDown = () => Math.random() > 0.5 ? '▲' : '▼';
33
- let getValues = (symbol, time) => [symbol, DG.DateTime.fromDate(time).d, next(symbol), Math.round(Math.random() * 10000), upDown()];
32
+ let getValues = (symbol, time) => [symbol, dayjs(time).toDate().toLocaleString('en-US'), next(symbol), Math.round(Math.random() * 10000), upDown()];
34
33
 
35
34
  let addTick = function (time) {
36
35
  for (let symbol in tickers)
@@ -0,0 +1,137 @@
1
+ //name: chemBenchmark
2
+ //language: javascript
3
+
4
+ // https://stackoverflow.com/a/47593316
5
+ 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
+ }
12
+ }
13
+ var rand = mulberry32(42); // seed = 42
14
+
15
+ const randomInt = (min, max) => min + Math.floor((max - min) * rand());
16
+ const range = (l, r) => new Array(r - l).fill().map((_, k) => k + l);
17
+
18
+ function getIdxRandomSubset(N, n) {
19
+ let arr = range(0, N);
20
+ let shuffled = arr.slice(0);
21
+ let i = arr.length, temp, index;
22
+ while (i--) {
23
+ index = randomInt(0, i + 1);
24
+ temp = shuffled[index];
25
+ shuffled[index] = shuffled[i];
26
+ shuffled[i] = temp;
27
+ }
28
+ return shuffled.slice(0, n);
29
+ }
30
+
31
+ function getIdxRandomSubarray(N, n) {
32
+ const from = randomInt(0, N - 1 - n);
33
+ const to = from + n;
34
+ return range(from, to);
35
+ }
36
+
37
+ let caseCntr = 0;
38
+
39
+ async function testCase(title, f) {
40
+ let msg = await DG.timeAsync(++caseCntr + '. ' + title, f);
41
+ if (typeof msg === 'string')
42
+ console.log(" " + msg);
43
+ }
44
+
45
+ (async () => {
46
+
47
+ const nSearch = 25000;
48
+ const nRender = 1000;
49
+ const nScroll = 20;
50
+ const tScroll = 100;
51
+ const nSample = 10;
52
+
53
+ let df = await grok.data.getDemoTable('chem/chembl/chembl-100k.csv');
54
+ // For using with your HOME files in Datagrok:
55
+ // let df = (await grok.functions.eval('OpenServerFile("UserName:Home/Chembl_100K.csv")'))[0];
56
+ // An alternative data source for testing (~40K+ molecules): chem/zbb/99_p3_4.5-6.csv
57
+ if (nSearch < df.rowCount)
58
+ df.rows.removeAt(nSearch, df.rowCount - nSearch, false);
59
+ const colName = 'smiles';
60
+ let col = df.col(colName);
61
+
62
+ console.clear();
63
+ console.log('Chem Benchmark');
64
+
65
+ let rdKitCellRenderer = await grok.functions.call('Chem:rdKitCellRenderer');
66
+ let grid = DG.Viewer.grid(df);
67
+ let canvas = grid.canvas;
68
+ let ctx = canvas.getContext('2d');
69
+ let rowsInd = null;
70
+
71
+ const render = (i) => rdKitCellRenderer.render(
72
+ ctx, 0, 0, 200, 100, grid.cell(colName, i), null);
73
+
74
+ rowsInd = getIdxRandomSubarray(nSearch, nRender);
75
+ await testCase(`Rendering a ${rowsInd.length} random molecules`, () => {
76
+ for (i of rowsInd) {
77
+ render(i);
78
+ }
79
+ });
80
+
81
+ rowsInd = getIdxRandomSubarray(nSearch, nScroll);
82
+ await testCase(`Horizontal scrolling (${rowsInd.length} random molecules, ${tScroll} times)`, () => {
83
+ for (let t = 0; t < tScroll; ++t) {
84
+ for (let i of rowsInd) {
85
+ render(i);
86
+ }
87
+ }
88
+ });
89
+
90
+ rowsInd = getIdxRandomSubarray(nSearch, nScroll + tScroll);
91
+ await testCase(`Vertical scrolling (${nScroll} random molecules, ${tScroll} times)`, () => {
92
+ for (let t = 0; t < tScroll; ++t) {
93
+ for (let i of rowsInd.slice(t, t + nScroll)) {
94
+ render(i);
95
+ }
96
+ }
97
+ });
98
+
99
+ const searchFor = [
100
+ 'c1ccccc1', // Benzene https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL277500/
101
+ 'CC(=O)Oc1ccccc1C(=O)O', // Aspirin https://www.ebi.ac.uk/chembl/compound_report_card/CHEMBL25/
102
+ '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/
104
+ ];
105
+
106
+ const searchForNames = ['Benzene', 'Aspirin', 'Stearic acid', 'Lusine'];
107
+
108
+ await testCase(`Substructure search, building a library of ${col.length} molecules`, async () =>
109
+ await grok.chem.searchSubstructure(col));
110
+
111
+
112
+ for (let i = 0; i < searchFor.length; ++i)
113
+ 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]}`; });
115
+
116
+ await testCase(`Similarity scoring, building a library of ${col.length} molecules`, async () =>
117
+ await grok.chem.getSimilarities(col));
118
+ const queryIdx = getIdxRandomSubset(nSearch, nSample);
119
+ await testCase(`Similarity scoring, search for ${queryIdx.length} samples in ${nSearch} molecules`, async () => {
120
+ for (let i of queryIdx) {
121
+ await grok.chem.getSimilarities(col, col.get(i));
122
+ }
123
+ });
124
+
125
+ await testCase(`Substructure search (server), searching benzene in ${nSearch} molecules`, async () =>
126
+ await grok.chem.searchSubstructureServer(col, searchFor[0]), false);
127
+ await testCase(`Substructure search (server), searching aspirin in ${nSearch} molecules`, async () =>
128
+ await grok.chem.searchSubstructureServer(col, searchFor[1]), false);
129
+
130
+ /*
131
+ await testCase(`Similarity scoring (server), search for ${queryIdx.length} samples in ${nSearch} molecules`, async () => {
132
+ await grok.chem.findSimilarServer(col, searchFor[0]);
133
+ });
134
+ */
135
+
136
+
137
+ })();
@@ -0,0 +1,45 @@
1
+ //name: testSubstructureSearch
2
+ //description: Substructure search via RDKit
3
+ //language: javascript
4
+
5
+ async function time(name, n, f) {
6
+ let start = new Date();
7
+ for (let k = 0; k < n; ++k) {
8
+ await f();
9
+ }
10
+ let stop = new Date();
11
+ console.log(`${name}: ${(stop - start) / n} ms`);
12
+ }
13
+
14
+ (async () => {
15
+
16
+ const n = 5;
17
+ const N = 2000;
18
+ let searchFor = ['c1ccccc1', 'C1CCCCC1', 'CC'];
19
+
20
+ let df = await grok.data.getDemoTable('chem/zbb/99_p3_4.5-6.csv');
21
+ if (N < df.rowCount)
22
+ df.rows.removeAt(N, df.rowCount - N, false);
23
+ let col = df.col('smiles');
24
+
25
+ console.log('Substructure search microbenchmark');
26
+
27
+ await time(`Graph-based search on ${df.rowCount} molecules`, n, async () => {
28
+ for (let s of searchFor) {
29
+ let result = await grok.chem.searchSubstructure(col, s, {substructLibrary: false});
30
+ // console.log(s + ": " + result.toString());
31
+ }
32
+ });
33
+
34
+ await time(`Building a library for ${df.rowCount} molecules`, 1, async () => {
35
+ await grok.chem.searchSubstructure(col);
36
+ });
37
+
38
+ await time(`Searching the library on ${searchFor.length} molecules`, n, async () => {
39
+ for (let s of searchFor) {
40
+ let result = await grok.chem.searchSubstructure(col, s);
41
+ // console.log(s + ": " + result.toString());
42
+ }
43
+ });
44
+
45
+ })();
@@ -0,0 +1,33 @@
1
+ //name: testSubstructureSearchSmarts
2
+ //language: javascript
3
+
4
+ // An example of using substructure search with SMARTS pattern,
5
+ // encoded through an ALS parameter block of a MolFile
6
+
7
+ grok.data.getDemoTable('chem/smiles.csv')
8
+ .then(t => grok.chem.searchSubstructure(
9
+ t.col('canonical_smiles'), `
10
+ MJ201900
11
+
12
+ 6 6 1 0 0 0 0 0 0 0999 V2000
13
+ -1.9420 0.9589 0.0000 L 0 0 0 0 0 0 0 0 0 0 0 0
14
+ -2.6564 0.5464 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
15
+ -2.6564 -0.2786 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
16
+ -1.9420 -0.6911 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
17
+ -1.2275 -0.2786 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
18
+ -1.2275 0.5464 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
19
+ 2 3 1 0 0 0 0
20
+ 3 4 2 0 0 0 0
21
+ 4 5 1 0 0 0 0
22
+ 5 6 2 0 0 0 0
23
+ 1 2 2 0 0 0 0
24
+ 6 1 1 0 0 0 0
25
+ 1 T 2 6 7
26
+ M ALS 1 2 T C N
27
+ M END
28
+ `
29
+ )
30
+ .then(function (bs) {
31
+ t.filter.copyFrom(bs);
32
+ grok.shell.addTableView(t);
33
+ }));
@@ -0,0 +1,12 @@
1
+ //name: testSubstructureSearchSmarts
2
+ //language: javascript
3
+
4
+ // An example of using substructure search with SMARTS pattern
5
+
6
+ grok.data.getDemoTable('chem/smiles.csv')
7
+ .then(t => grok.chem.searchSubstructure(
8
+ 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
+ }));
@@ -1,45 +1,11 @@
1
- //name: testSubstructureSearch
2
- //description: Substructure search via RDKit
1
+ //name: testSubstructureSearchLibrary
3
2
  //language: javascript
4
3
 
5
- async function time(name, n, f) {
6
- let start = new Date();
7
- for (let k = 0; k < n; ++k) {
8
- await f();
9
- }
10
- let stop = new Date();
11
- console.log(`${name}: ${(stop - start) / n} ms`);
12
- }
4
+ // An example of using substructure search
13
5
 
14
- (async () => {
15
-
16
- const n = 5;
17
- const N = 2000;
18
- let searchFor = ['c1ccccc1', 'C1CCCCC1', 'CC'];
19
-
20
- let df = await grok.data.getDemoTable('chem/zbb/99_p3_4.5-6.csv');
21
- if (N < df.rowCount)
22
- df.rows.removeAt(N, df.rowCount - N, false);
23
- let col = df.col('smiles');
24
-
25
- console.log('Substructure search microbenchmark');
26
-
27
- await time(`Graph-based search on ${df.rowCount} molecules`, n, async () => {
28
- for (let s of searchFor) {
29
- let result = await grok.chem.searchSubstructure(col, s, {substructLibrary: false});
30
- // console.log(s + ": " + result.toString());
31
- }
32
- });
33
-
34
- await time(`Building a library for ${df.rowCount} molecules`, 1, async () => {
35
- await grok.chem.searchSubstructure(col);
36
- });
37
-
38
- await time(`Searching the library on ${searchFor.length} molecules`, n, async () => {
39
- for (let s of searchFor) {
40
- let result = await grok.chem.searchSubstructure(col, s);
41
- // console.log(s + ": " + result.toString());
42
- }
43
- });
44
-
45
- })();
6
+ grok.data.loadTable('https://public.datagrok.ai/demo/sar_small.csv')
7
+ .then(t => grok.chem.searchSubstructure(t.col('smiles'), 'O=C1CN=C(C2CCCCC2)C2:C:C:C:C:C:2N1')
8
+ .then(function (bs) {
9
+ t.filter.copyFrom(bs);
10
+ grok.shell.addTableView(t);
11
+ }));
@@ -0,0 +1,29 @@
1
+ /* Demonstrates TreeView events */
2
+
3
+ const tree = ui.tree();
4
+
5
+ const g1 = tree.group('group 1', {val: 1}, false);
6
+ g1.enableCheckBox();
7
+
8
+ g1.onNodeAdded.subscribe(_ => grok.shell.info(`Node added g1`));
9
+ tree.onChildNodeExpanding.subscribe(_ => grok.shell.info(`Child node expanding tree`));
10
+ tree.onChildNodeExpandedChanged.subscribe(_ => grok.shell.info(`Child node expanded changed tree`));
11
+ g1.onNodeCheckBoxToggled.subscribe(_ => grok.shell.info(`Node checkbox toggled g1`));
12
+ g1.onNodeContextMenu.subscribe(_ => grok.shell.info(`Node context menu g1`));
13
+ g1.onNodeEnter.subscribe(_ => grok.shell.info(`Node entered g1`));
14
+ tree.onNodeMouseEnter.subscribe(_ => grok.shell.info(`Node mouse enter tree`));
15
+ tree.onNodeMouseLeave.subscribe(_ => grok.shell.info(`Node mouse leave tree`));
16
+ tree.onSelectedNodeChanged.subscribe(_ => grok.shell.info(`Selected node changed tree`));
17
+
18
+ const i101 = g1.item('item 1.0.1');
19
+ i101.onSelected.subscribe(_ => grok.shell.info(`Node selected i101`));
20
+
21
+ const i102 = g1.item('item 1.0.2');
22
+ i102.enableCheckBox();
23
+ const g11 = g1.group('group 1.1', {val: 1.1}, false);
24
+ g11.item('item 1.1.1');
25
+ g11.item('item 1.1.2');
26
+
27
+ g1.onNodeExpanding.subscribe(_ => grok.shell.info(`Node expanding g1`));
28
+
29
+ grok.shell.newView('TreeView Demo', [tree.root]);
@@ -1,5 +1,5 @@
1
1
  //tags: Func
2
- //help-url: https://datagrok.ai/help/overview/functions/function
2
+ //help-url: https://datagrok.ai/help/datagrok/functions/function
3
3
  // Executing functions
4
4
 
5
5
  // Calling "RDup" function that belongs to the "RSrcipts" package
@@ -5,6 +5,8 @@
5
5
  let p = DG.ProgressIndicator.create();
6
6
  p.onProgressUpdated.subscribe((p) => grok.shell.info(p.percent));
7
7
  p.onLogUpdated.subscribe((line) => console.log(line));
8
+ p.update(50, "Loading foo.csv");
9
+
8
10
 
9
11
  grok.functions.call("Discovery:countToTen",
10
12
  {s: "a"}, true, p)
@@ -3,10 +3,10 @@
3
3
  // in help, there could be an optional audit trail associated with the invocations, etc)
4
4
  //
5
5
  // The code below registers two functions, "jsConcat" and "jsWidget". To test
6
- // jsConcat, enter "jsConcat(42, 33)" in the console(https://datagrok.ai/help/overview/navigation#console).
6
+ // jsConcat, enter "jsConcat(42, 33)" in the console(https://datagrok.ai/help/datagrok/navigation#console).
7
7
  // To test jsWidget, create a new Dashboard, and click on "Widget" under "Widgets".
8
8
  //
9
- // See also https://datagrok.ai/help/overview/functions/function,
9
+ // See also https://datagrok.ai/help/datagrok/functions/function,
10
10
  // https://datagrok.ai/help/develop/js-api#registering-functions
11
11
 
12
12
  grok.functions.register({
@@ -6,4 +6,12 @@ t.col('height').tags[DG.TAGS.COLOR_CODING_CONDITIONAL] = `{"20-170":"#00FF00","1
6
6
  t.col('age').tags[DG.TAGS.COLOR_CODING_TYPE] = 'Linear';
7
7
  t.col('age').tags[DG.TAGS.COLOR_CODING_LINEAR] = `[${DG.Color.orange}, ${DG.Color.green}]`;
8
8
 
9
+ grok.shell.info(`Column 'subj' color coding: ${t.col('subj').meta.colors.getType()}`); // Off
10
+ grok.shell.info(`Column 'height' color coding: ${t.col('height').meta.colors.getType()}`); // Conditional
11
+ grok.shell.info(`Column 'age' color coding: ${t.col('age').meta.colors.getType()}`); // Linear
12
+
13
+ t.col('site').meta.colors.setCategorical({'New York': DG.Color.orange});
14
+ t.col('started').meta.colors.setLinear([DG.Color.white, DG.Color.red]);
15
+ t.col('weight').meta.colors.setConditional({'<100': DG.Color.green, '100-200': '#ff0000'});
16
+
9
17
  grok.shell.addTableView(t);
@@ -1,6 +1,6 @@
1
1
  // HTML-based grid cells with the markup-driven content.
2
2
  // For code-driven rendering, check out "html-dynamic-cell.js" sample.
3
- // See also: https://datagrok.ai/help/overview/markup
3
+ // See also: https://datagrok.ai/help/datagrok/markup
4
4
 
5
5
  let view = grok.shell.addTableView(grok.data.demo.demog());
6
6
  let col = view.grid.columns.byName('disease');
@@ -5,6 +5,7 @@ ui.dialog('Windows')
5
5
  .add(ui.boolInput('help', windows.showHelp, (x) => windows.showHelp = x))
6
6
  .add(ui.boolInput('sidebar', windows.showSidebar, (x) => windows.showSidebar = x))
7
7
  .add(ui.boolInput('toolbox', windows.showToolbox, (x) => windows.showToolbox = x))
8
+ .add(ui.boolInput('status bar', windows.showStatusBar, (x) => windows.showStatusBar = x))
8
9
  .add(ui.boolInput('console', windows.showConsole, (x) => windows.showConsole = x))
9
10
  .add(ui.boolInput('properties', windows.showProperties, (x) => windows.showProperties = x))
10
11
  .add(ui.boolInput('tables', windows.showTables, (x) => windows.showTables = x))
@@ -0,0 +1,8 @@
1
+ // File browser widget
2
+ grok.shell.newView('Files', [ui.fileBrowser().root]);
3
+
4
+ // Accepts a full-qualified name (see [Entity.nqName]) in the path parameter
5
+ // and opens a directory in the files tree, if it is specified, e.g., 'System:AppData/Chem/tests'
6
+ const testConnection = await grok.dapi.connections.filter('shortName = "Home"').first();
7
+ const fb = ui.fileBrowser({path: testConnection.nqName});
8
+ grok.shell.newView(`${testConnection.name} files`, [fb.root]);
@@ -1,7 +1,7 @@
1
1
  // Creating custom dialogs
2
2
 
3
3
 
4
- var dlg = ui.dialog('Windows');
4
+ var dlg = ui.dialog({title: 'Boo', helpUrl: 'https://wikipedia.org'});
5
5
  dlg
6
6
  .add(ui.span(['People of Earth, your attention, please… ']))
7
7
  .onCancel(() => grok.shell.info('Cancel'))
@@ -1,8 +1,6 @@
1
- // Creating custom dialogs
1
+ // Custom dialogs
2
2
 
3
- ui.dialog('Windows')
4
- .add(ui.span(['People of Earth, your attention, please… ']))
5
- .onOK(() => {
6
- grok.shell.info('OK!');
7
- })
8
- .showModal();
3
+ ui.dialog({ showHeader: false, showFooter: false })
4
+ .add(ui.span(['Full-screen mode with no header or footer; click on the background, or press ESC to close.']))
5
+ .onOK(() => grok.shell.info('OK!'))
6
+ .showModal(true);
@@ -5,7 +5,7 @@ const msg = (v) => grok.shell.info(v);
5
5
  let name = ui.stringInput('Name', 'Arthur Dent', v => msg(v));
6
6
  let age = ui.intInput('Age', 30, v => msg(v));
7
7
  let sex = ui.choiceInput('Sex', 'Male', ['Male', 'Female'], v => msg(v));
8
- let date = ui.dateInput('Birthday', DG.DateTime.fromDate(new Date(1970, 5, 10)), v => msg(v));
8
+ let date = ui.dateInput('Birthday', dayjs('1970-5-10'), v => msg(v));
9
9
  let alien = ui.boolInput('Alien', false, v => msg(v));
10
10
  let friends = ui.multiChoiceInput('Friends',
11
11
  ['Ford', 'Fenchurch'], ['Ford', 'Fenchurch', 'Zaphod', 'Slartibartfast'], v => msg(v));