@datagrok/compute 0.6.7 → 0.7.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.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/compute",
|
|
3
3
|
"friendlyName": "Compute",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.1",
|
|
5
5
|
"description": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"cash-dom": "latest",
|
|
@@ -42,5 +42,7 @@
|
|
|
42
42
|
"release-compute-localhost": "grok publish localhost --rebuild --release",
|
|
43
43
|
"debug-compute-compose": "grok publish compose --rebuild",
|
|
44
44
|
"release-compute-compose": "grok publish compose --rebuild --release"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"canEdit": [ "Developers" ],
|
|
47
|
+
"canView": [ "All users" ]
|
|
46
48
|
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as grok from 'datagrok-api/grok';
|
|
2
|
+
import * as DG from "datagrok-api/dg";
|
|
3
|
+
import * as ui from "datagrok-api/ui";
|
|
4
|
+
import $ from 'cash-dom';
|
|
5
|
+
|
|
6
|
+
export class ModelsWidget extends DG.Widget {
|
|
7
|
+
caption: string;
|
|
8
|
+
order: string;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super(ui.panel());
|
|
12
|
+
this.caption = super.addProperty('caption', DG.TYPE.STRING, 'Model catalog');
|
|
13
|
+
this.order = super.addProperty('order', DG.TYPE.STRING, '0');
|
|
14
|
+
this.getModels();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async getModels(){
|
|
18
|
+
let count = (await grok.dapi.scripts.filter('#model').list()).length;
|
|
19
|
+
let titles = [ui.h3('Simulation'), ui.h3('Other')];
|
|
20
|
+
for (let i in titles){
|
|
21
|
+
titles[i].style.color = 'var(--grey-3)';
|
|
22
|
+
titles[i].style.fontSize = '12px';
|
|
23
|
+
titles[i].style.textTransform = 'uppercase';
|
|
24
|
+
titles[i].style.letterSpacing = '1px';
|
|
25
|
+
titles[i].style.margin = '5px 0';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let modelsList = ui.divV([
|
|
29
|
+
titles[0],
|
|
30
|
+
ui.divV([],'models-widget-group'),
|
|
31
|
+
titles[1],
|
|
32
|
+
ui.divV([],'models-widget-group'),
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
grok.dapi.scripts
|
|
36
|
+
.filter('#model')
|
|
37
|
+
.list()
|
|
38
|
+
.then((scripts) => scripts.map((p) => {
|
|
39
|
+
if(p.tags.includes("simulation")){
|
|
40
|
+
let div = ui.link('', p.path, undefined, null);
|
|
41
|
+
div.append(modelData(p))
|
|
42
|
+
$(modelsList).find('.models-widget-group')[0]?.append(div);
|
|
43
|
+
}else{
|
|
44
|
+
let div = ui.link('', p.path, undefined, null);
|
|
45
|
+
div.append(modelData(p))
|
|
46
|
+
$(modelsList).find('.models-widget-group')[1]?.append(div);
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
this.root.appendChild(modelsList);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function modelData(p: any){
|
|
55
|
+
let img = ui.iconImage('logo', `/images/entities/${p.language}.png`);
|
|
56
|
+
img.style.width = '30px';
|
|
57
|
+
img.style.height = '30px';
|
|
58
|
+
img.style.border = 'none';
|
|
59
|
+
let card = ui.cards.summary(
|
|
60
|
+
img,
|
|
61
|
+
[
|
|
62
|
+
ui.div(ui.link(p.friendlyName, p, undefined, null)),
|
|
63
|
+
ui.div([p.updatedOn], {style:{color:'var(--grey-4)'}})
|
|
64
|
+
]);
|
|
65
|
+
ui.tooltip.bind(card, p);
|
|
66
|
+
return card;
|
|
67
|
+
}
|
|
@@ -7,23 +7,17 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
7
7
|
super();
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
onFrameAttached(dataFrame: DG.DataFrame): void {
|
|
11
|
+
this.dataFrame = dataFrame;
|
|
12
|
+
this.render();
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
onTableAttached() {
|
|
16
|
-
|
|
17
|
-
this.initialRender();
|
|
18
|
-
}
|
|
15
|
+
onTableAttached(): void {
|
|
16
|
+
this.render();
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
render() {
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
initialRender() {
|
|
26
|
-
if (!this.dataFrame) {
|
|
20
|
+
if (!this.dataFrame || this.dataFrame.rowCount <= 0) {
|
|
27
21
|
this.root.innerHTML = '';
|
|
28
22
|
return;
|
|
29
23
|
}
|
|
@@ -33,8 +27,6 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
33
27
|
const OUTLIER_RATIONALE_COL_LABEL = 'Rationale';
|
|
34
28
|
const OUTLIER_COUNT_COL_LABEL = 'Count';
|
|
35
29
|
const IS_GROUP_CONFIRMED_LABEL = 'isConfirmed';
|
|
36
|
-
const FLUX = 't/V (hr/(L/m²))';
|
|
37
|
-
const DEFAULT_TEST_AREA = 3.5;
|
|
38
30
|
|
|
39
31
|
if (!inputData.columns.byName(IS_OUTLIER_COL_LABEL)) {
|
|
40
32
|
inputData.columns
|
|
@@ -46,11 +38,8 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
46
38
|
.add(DG.Column.fromStrings(OUTLIER_RATIONALE_COL_LABEL, Array.from({length: inputData.rowCount}, () => '')));
|
|
47
39
|
}
|
|
48
40
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const initialData = inputData.clone();
|
|
41
|
+
//@ts-ignore
|
|
42
|
+
inputData.col(IS_OUTLIER_COL_LABEL)?.markers.assign('true', DG.MARKER_TYPE.OUTLIER);
|
|
54
43
|
|
|
55
44
|
const clearTable = () => {
|
|
56
45
|
return DG.DataFrame.fromColumns([
|
|
@@ -190,7 +179,8 @@ export class OutliersSelectionViewer extends DG.JsViewer {
|
|
|
190
179
|
// );
|
|
191
180
|
// info.style.marginBottom = '0px';
|
|
192
181
|
|
|
193
|
-
this.root.
|
|
182
|
+
this.root.innerHTML = '';
|
|
183
|
+
this.root.append(
|
|
194
184
|
ui.divV([
|
|
195
185
|
ui.divV([
|
|
196
186
|
groupsListGrid.root,
|
package/src/package.ts
CHANGED
|
@@ -7,17 +7,12 @@ import {exportFuncCall} from './export-funccall';
|
|
|
7
7
|
import {_functionParametersGrid} from './function-views/function-parameters-grid';
|
|
8
8
|
import {ModelCatalogView} from './model-catalog-view';
|
|
9
9
|
import wu from 'wu';
|
|
10
|
-
import {_functionEditor} from './function-editor/function-editor';
|
|
11
10
|
import {OutliersSelectionViewer} from './outliers-selection/outliers-selection-viewer';
|
|
11
|
+
import {ModelsWidget} from './models-widget'
|
|
12
12
|
|
|
13
13
|
let initCompleted: boolean = false;
|
|
14
14
|
export const _package = new DG.Package();
|
|
15
15
|
|
|
16
|
-
//name: test
|
|
17
|
-
export function test() {
|
|
18
|
-
grok.shell.info(_package.webRoot);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
16
|
//name: OutliersSelectionViewer
|
|
22
17
|
//description: Creates an outliers selection viewer
|
|
23
18
|
//tags: viewer
|
|
@@ -26,6 +21,13 @@ export function OutliersSelection() {
|
|
|
26
21
|
return new OutliersSelectionViewer();
|
|
27
22
|
}
|
|
28
23
|
|
|
24
|
+
|
|
25
|
+
//output: widget result
|
|
26
|
+
//tags: dashboard
|
|
27
|
+
export function modelsWidget(): DG.Widget {
|
|
28
|
+
return new ModelsWidget();
|
|
29
|
+
}
|
|
30
|
+
|
|
29
31
|
//name: Export to Excel
|
|
30
32
|
//input: funccall call
|
|
31
33
|
//tags: export
|
|
@@ -33,75 +35,6 @@ export function exportToExcel(call: DG.FuncCall) {
|
|
|
33
35
|
exportFuncCall(call);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
//name: Function Editor
|
|
37
|
-
export function functionEditor() {
|
|
38
|
-
const sampleScript = `
|
|
39
|
-
#name: Chemical Space Using tSNE
|
|
40
|
-
#description: Chemical space using t-distributed Stochastic Neighbor Embedding
|
|
41
|
-
#help-url: https://datagrok.ai/help/domains/chem/functions/tsne
|
|
42
|
-
#language: python
|
|
43
|
-
#sample: chem/smiles_coordinates.csv
|
|
44
|
-
#tags: demo, chem, rdkit
|
|
45
|
-
#input: dataframe t1 {columns: numerical; category: test} [first input data table]
|
|
46
|
-
#input: dataframe t2 {columns: numerical} [second input data table]
|
|
47
|
-
#input: column x {type: numerical; table: t1} [x axis column name]
|
|
48
|
-
#input: column y {type: numerical} [y axis column name]
|
|
49
|
-
#input: column date {type: datetime; format: mm/dd/yyyy} [date column name]
|
|
50
|
-
#input: column_list numdata {type :numerical; table:t1} [numerical columns names]
|
|
51
|
-
#input: int numcomp = 2 {min: 2; max: 7; units: mm} [number of components]
|
|
52
|
-
#input: bool center = true [number of components]
|
|
53
|
-
#input: string type = high {choices: ["high", "low"]} [type of filter]
|
|
54
|
-
#output: dataframe result {action: join(t1)} [pca components]
|
|
55
|
-
#output: graphics scatter [scatter plot]
|
|
56
|
-
|
|
57
|
-
import numba
|
|
58
|
-
import hdbscan
|
|
59
|
-
import numpy as np
|
|
60
|
-
import matplotlib.pyplot as plt
|
|
61
|
-
from sklearn.manifold import TSNE
|
|
62
|
-
from rdkit import Chem
|
|
63
|
-
from rdkit.Chem import AllChem
|
|
64
|
-
from rdkit.Chem import Draw
|
|
65
|
-
from rdkit.Chem import DataStructs
|
|
66
|
-
|
|
67
|
-
smiles = data[smiles]
|
|
68
|
-
mols = [Chem.MolFromSmiles(mol) for mol in smiles]
|
|
69
|
-
mols = [mol for mol in mols if mol is not None]
|
|
70
|
-
for mol in mols:
|
|
71
|
-
AllChem.Compute2DCoords(mol)
|
|
72
|
-
X = []
|
|
73
|
-
for mol in mols:
|
|
74
|
-
arr = np.zeros((0,))
|
|
75
|
-
fp = AllChem.GetMorganFingerprintAsBitVect(mol, 2)
|
|
76
|
-
DataStructs.ConvertToNumpyArray(fp, arr)
|
|
77
|
-
X.append(arr)
|
|
78
|
-
|
|
79
|
-
@numba.njit()
|
|
80
|
-
def tanimoto_dist(a, b):
|
|
81
|
-
dotprod = np.dot(a, b)
|
|
82
|
-
tc = dotprod / (np.sum(a) + np.sum(b) - dotprod)
|
|
83
|
-
return 1.0 - tc
|
|
84
|
-
|
|
85
|
-
tsne = TSNE(n_components=components, metric=tanimoto_dist)
|
|
86
|
-
tsne_X = tsne.fit_transform(X)
|
|
87
|
-
cluster_tsne = hdbscan.HDBSCAN(min_cluster_size=minClusterSize, gen_min_span_tree=True)
|
|
88
|
-
cluster_tsne.fit(tsne_X)
|
|
89
|
-
|
|
90
|
-
plt.figure(0)
|
|
91
|
-
cluster_tsne.minimum_spanning_tree_.plot(
|
|
92
|
-
edge_cmap='viridis', edge_alpha=0.6,
|
|
93
|
-
node_size=90, edge_linewidth=2)
|
|
94
|
-
|
|
95
|
-
plt.figure(1)
|
|
96
|
-
cluster_tsne.single_linkage_tree_.plot(cmap='viridis', colorbar=True)
|
|
97
|
-
|
|
98
|
-
plt.figure(2)
|
|
99
|
-
plt.scatter(tsne_X.T[0], tsne_X.T[1], c=cluster_tsne.labels_, cmap='plasma')
|
|
100
|
-
plt.title('Chemical space')
|
|
101
|
-
`;
|
|
102
|
-
_functionEditor(sampleScript);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
38
|
/* eslint-disable */
|
|
106
39
|
|
|
107
40
|
//description: A spreadsheet that lets you interactively edit parameters and evaluate functions
|
package/detectors.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The class contains semantic type detectors.
|
|
3
|
-
* Detectors are functions tagged with `DG.FUNC_TYPES.SEM_TYPE_DETECTOR`.
|
|
4
|
-
* See also: https://datagrok.ai/help/develop/how-to/define-semantic-type-detectors
|
|
5
|
-
* The class name is comprised of <PackageName> and the `PackageDetectors` suffix.
|
|
6
|
-
* Follow this naming convention to ensure that your detectors are properly loaded.
|
|
7
|
-
*/
|
|
8
|
-
class ComputePackageDetectors extends DG.Package {
|
|
9
|
-
}
|
|
@@ -1,615 +0,0 @@
|
|
|
1
|
-
import * as grok from 'datagrok-api/grok';
|
|
2
|
-
import * as ui from 'datagrok-api/ui';
|
|
3
|
-
import * as DG from 'datagrok-api/dg';
|
|
4
|
-
import CodeMirror from 'codemirror';
|
|
5
|
-
import 'codemirror/lib/codemirror.css';
|
|
6
|
-
import {BehaviorSubject} from 'rxjs';
|
|
7
|
-
|
|
8
|
-
const enum FUNC_PROPS_FIELDS {
|
|
9
|
-
NAME = 'name',
|
|
10
|
-
DESCRIPTION = 'description',
|
|
11
|
-
LANGUAGE = 'language',
|
|
12
|
-
HELP_URL = 'helpUrl',
|
|
13
|
-
REFERENCE = 'reference',
|
|
14
|
-
LOGIN = 'author?.login',
|
|
15
|
-
SAMPLE = 'sample',
|
|
16
|
-
ENVIRONMENT = 'environment',
|
|
17
|
-
TAGS = 'tags'
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const obligatoryFuncProps = ['name', 'description', 'helpUrl', 'language'];
|
|
21
|
-
|
|
22
|
-
const functionPropsLabels = (key: FUNC_PROPS_FIELDS) => {
|
|
23
|
-
switch (key) {
|
|
24
|
-
case FUNC_PROPS_FIELDS.NAME: return 'Name';
|
|
25
|
-
case FUNC_PROPS_FIELDS.DESCRIPTION: return 'Description';
|
|
26
|
-
case FUNC_PROPS_FIELDS.LOGIN: return 'Author';
|
|
27
|
-
case FUNC_PROPS_FIELDS.HELP_URL: return 'Help URL';
|
|
28
|
-
case FUNC_PROPS_FIELDS.LANGUAGE: return 'Language';
|
|
29
|
-
case FUNC_PROPS_FIELDS.REFERENCE: return 'Reference';
|
|
30
|
-
case FUNC_PROPS_FIELDS.SAMPLE: return 'Sample';
|
|
31
|
-
case FUNC_PROPS_FIELDS.ENVIRONMENT: return 'Environment';
|
|
32
|
-
case FUNC_PROPS_FIELDS.TAGS: return 'Tags';
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const functionPropsCode = (key: string) => {
|
|
37
|
-
switch (key) {
|
|
38
|
-
case FUNC_PROPS_FIELDS.NAME: return 'name';
|
|
39
|
-
case FUNC_PROPS_FIELDS.DESCRIPTION: return 'description';
|
|
40
|
-
case FUNC_PROPS_FIELDS.LOGIN: return 'author';
|
|
41
|
-
case FUNC_PROPS_FIELDS.HELP_URL: return 'helpUrl';
|
|
42
|
-
case FUNC_PROPS_FIELDS.LANGUAGE: return 'language';
|
|
43
|
-
case FUNC_PROPS_FIELDS.REFERENCE: return 'reference';
|
|
44
|
-
case FUNC_PROPS_FIELDS.SAMPLE: return 'sample';
|
|
45
|
-
case FUNC_PROPS_FIELDS.ENVIRONMENT: return 'environment';
|
|
46
|
-
case FUNC_PROPS_FIELDS.TAGS: return 'tags';
|
|
47
|
-
}
|
|
48
|
-
}; ;
|
|
49
|
-
|
|
50
|
-
const funcParamTypes = [
|
|
51
|
-
DG.TYPE.BOOL,
|
|
52
|
-
DG.TYPE.COLUMN_LIST,
|
|
53
|
-
DG.TYPE.COLUMN,
|
|
54
|
-
DG.TYPE.DATA_FRAME,
|
|
55
|
-
DG.TYPE.DATE_TIME,
|
|
56
|
-
DG.TYPE.FLOAT,
|
|
57
|
-
DG.TYPE.GRAPHICS,
|
|
58
|
-
DG.TYPE.INT,
|
|
59
|
-
DG.TYPE.STRING,
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
const enum FUNC_PARAM_FIELDS {
|
|
63
|
-
DIRECTION = 'direction',
|
|
64
|
-
TYPE = 'propertyType',
|
|
65
|
-
NAME = 'name',
|
|
66
|
-
DEFAULT_VALUE = 'defaultValue',
|
|
67
|
-
DESCRIPTION = 'description',
|
|
68
|
-
CATEGORY = 'category',
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const enum DIRECTION {
|
|
72
|
-
INPUT= 'input',
|
|
73
|
-
OUTPUT= 'output',
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const functionParamsMapping = {
|
|
77
|
-
[FUNC_PARAM_FIELDS.DIRECTION]: 'Direction',
|
|
78
|
-
[FUNC_PARAM_FIELDS.TYPE]: 'Type',
|
|
79
|
-
[FUNC_PARAM_FIELDS.NAME]: 'Name',
|
|
80
|
-
[FUNC_PARAM_FIELDS.DEFAULT_VALUE]: 'Default value',
|
|
81
|
-
[FUNC_PARAM_FIELDS.DESCRIPTION]: 'Description',
|
|
82
|
-
[FUNC_PARAM_FIELDS.CATEGORY]: 'Category',
|
|
83
|
-
'Direction': FUNC_PARAM_FIELDS.DIRECTION,
|
|
84
|
-
'Type': FUNC_PARAM_FIELDS.TYPE,
|
|
85
|
-
'Name': FUNC_PARAM_FIELDS.NAME,
|
|
86
|
-
'Default value': FUNC_PARAM_FIELDS.DEFAULT_VALUE,
|
|
87
|
-
'Description': FUNC_PARAM_FIELDS.DESCRIPTION,
|
|
88
|
-
'Category': FUNC_PARAM_FIELDS.CATEGORY,
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
enum COMMON_TAG_NAME {
|
|
92
|
-
VALIDATORS = 'validators',
|
|
93
|
-
CAPTION = 'caption',
|
|
94
|
-
POSTFIX = 'postfix',
|
|
95
|
-
UNITS = 'units',
|
|
96
|
-
EDITOR = 'editor',
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
enum OPTIONAL_TAG_NAME {
|
|
100
|
-
COLUMNS = 'columns',
|
|
101
|
-
TYPE = 'type',
|
|
102
|
-
FORMAT = 'format',
|
|
103
|
-
ALLOW_NULLS = 'allowNulls',
|
|
104
|
-
ACTION = 'action',
|
|
105
|
-
CHOICES = 'choices',
|
|
106
|
-
SUGGESTIONS = 'suggestions',
|
|
107
|
-
SEM_TYPE = 'semType',
|
|
108
|
-
MIN = 'min',
|
|
109
|
-
MAX = 'max',
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
type DF_TAG_NAME = COMMON_TAG_NAME | OPTIONAL_TAG_NAME.COLUMNS;
|
|
113
|
-
type COLUMN_TAG_NAME = COMMON_TAG_NAME |
|
|
114
|
-
OPTIONAL_TAG_NAME.COLUMNS | OPTIONAL_TAG_NAME.FORMAT |
|
|
115
|
-
OPTIONAL_TAG_NAME.ALLOW_NULLS | OPTIONAL_TAG_NAME.ACTION | OPTIONAL_TAG_NAME.SEM_TYPE
|
|
116
|
-
|
|
117
|
-
type STRING_TAG_NAME = COMMON_TAG_NAME |
|
|
118
|
-
OPTIONAL_TAG_NAME.CHOICES | OPTIONAL_TAG_NAME.SUGGESTIONS
|
|
119
|
-
|
|
120
|
-
type INT_TAG_NAME = COMMON_TAG_NAME | OPTIONAL_TAG_NAME.MIN | OPTIONAL_TAG_NAME.MAX
|
|
121
|
-
|
|
122
|
-
const COMMON_TAG_NAMES = [...Object.values(COMMON_TAG_NAME)];
|
|
123
|
-
const DF_TAG_NAMES = [
|
|
124
|
-
...Object.values(COMMON_TAG_NAME),
|
|
125
|
-
OPTIONAL_TAG_NAME.COLUMNS,
|
|
126
|
-
OPTIONAL_TAG_NAME.ACTION];
|
|
127
|
-
const COLUMN_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.TYPE, OPTIONAL_TAG_NAME.FORMAT,
|
|
128
|
-
OPTIONAL_TAG_NAME.ALLOW_NULLS, OPTIONAL_TAG_NAME.ACTION, OPTIONAL_TAG_NAME.SEM_TYPE];
|
|
129
|
-
const STRING_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.CHOICES, OPTIONAL_TAG_NAME.SUGGESTIONS];
|
|
130
|
-
const INT_TAG_NAMES = [...Object.values(COMMON_TAG_NAME), OPTIONAL_TAG_NAME.MIN, OPTIONAL_TAG_NAME.MAX];
|
|
131
|
-
|
|
132
|
-
type FuncParamBase = {
|
|
133
|
-
direction: DIRECTION,
|
|
134
|
-
name?: string,
|
|
135
|
-
defaultValue?: string,
|
|
136
|
-
description?: string
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
type FuncParam =
|
|
140
|
-
FuncParamBase & {
|
|
141
|
-
type: DG.TYPE.BOOL | DG.TYPE.DATE_TIME | DG.TYPE.FLOAT | DG.TYPE.GRAPHICS
|
|
142
|
-
options?: {tag: COMMON_TAG_NAME, value: string}[]
|
|
143
|
-
} | FuncParamBase & {
|
|
144
|
-
type: DG.TYPE.INT
|
|
145
|
-
options?: {tag: INT_TAG_NAME, value: string}[]
|
|
146
|
-
} | FuncParamBase & {
|
|
147
|
-
type: DG.TYPE.DATA_FRAME,
|
|
148
|
-
options?: {tag: DF_TAG_NAME, value: string}[]
|
|
149
|
-
} | FuncParamBase & {
|
|
150
|
-
type: DG.TYPE.COLUMN_LIST | DG.TYPE.COLUMN,
|
|
151
|
-
options?: {tag: COLUMN_TAG_NAME, value: string}[]
|
|
152
|
-
} | FuncParamBase & {
|
|
153
|
-
type: DG.TYPE.STRING
|
|
154
|
-
options?: {tag: STRING_TAG_NAME, value: string}[]
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const optionTags = ((param: DG.Property) => {
|
|
158
|
-
switch (param.propertyType) {
|
|
159
|
-
case DG.TYPE.INT:
|
|
160
|
-
return INT_TAG_NAMES;
|
|
161
|
-
case DG.TYPE.DATA_FRAME:
|
|
162
|
-
return DF_TAG_NAMES;
|
|
163
|
-
case DG.TYPE.COLUMN_LIST:
|
|
164
|
-
case DG.TYPE.COLUMN:
|
|
165
|
-
return COLUMN_TAG_NAMES;
|
|
166
|
-
case DG.TYPE.STRING:
|
|
167
|
-
return STRING_TAG_NAMES;
|
|
168
|
-
default:
|
|
169
|
-
return COMMON_TAG_NAMES;
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
const generateParamLine = (param: DG.Property, direction: string) => {
|
|
174
|
-
const optionTagsPreview = optionTags(param)
|
|
175
|
-
.map((tag) => {
|
|
176
|
-
return {tag: tag, val: param.options[tag]};
|
|
177
|
-
})
|
|
178
|
-
.filter((value) => !!value.val)
|
|
179
|
-
.map(({tag, val}) => `${tag}: ${val}`)
|
|
180
|
-
.concat(...param.category ? [`category: ${param.category}`]:[])
|
|
181
|
-
.join('; ');
|
|
182
|
-
const result =`#${direction}: ${param.propertyType} ${param.name? `${param.name} ` : ''}${param.defaultValue ? `= ${param.defaultValue} ` : ''}${!!optionTagsPreview.length ? `{${optionTagsPreview}} ` : ''}${param.description ? `[${param.description}]` : ''}\n`;
|
|
183
|
-
return result;
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
export function _functionEditor(functionCode: string) {
|
|
187
|
-
const inputScriptCopy = DG.Script.create(functionCode);
|
|
188
|
-
|
|
189
|
-
const editorView = DG.View.create();
|
|
190
|
-
editorView.name = 'Function Editor';
|
|
191
|
-
|
|
192
|
-
const updateFuncPropValue = (param: DG.Property, propName: string, v: any) => {
|
|
193
|
-
(inputScriptCopy as any)[propName] = v;
|
|
194
|
-
refreshPreview();
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
const functionProps = {
|
|
198
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.NAME)]: DG.Property.create(
|
|
199
|
-
FUNC_PROPS_FIELDS.NAME, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.NAME],
|
|
200
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.NAME, v),
|
|
201
|
-
'',
|
|
202
|
-
),
|
|
203
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.DESCRIPTION)]: DG.Property.create(
|
|
204
|
-
FUNC_PROPS_FIELDS.DESCRIPTION, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.DESCRIPTION],
|
|
205
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.DESCRIPTION, v),
|
|
206
|
-
'',
|
|
207
|
-
),
|
|
208
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.LANGUAGE)]: (() => {
|
|
209
|
-
const temp = DG.Property.create(
|
|
210
|
-
FUNC_PROPS_FIELDS.LANGUAGE, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.LANGUAGE],
|
|
211
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.LANGUAGE, v),
|
|
212
|
-
'');
|
|
213
|
-
temp.fromOptions({choices: ['javascript', 'python', 'r', 'julia', 'octave', 'nodejs', 'grok']});
|
|
214
|
-
return temp;
|
|
215
|
-
})(),
|
|
216
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.HELP_URL)]: DG.Property.create(
|
|
217
|
-
FUNC_PROPS_FIELDS.HELP_URL, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.HELP_URL],
|
|
218
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.HELP_URL, v),
|
|
219
|
-
'',
|
|
220
|
-
),
|
|
221
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.REFERENCE)]: DG.Property.create(
|
|
222
|
-
FUNC_PROPS_FIELDS.REFERENCE, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.REFERENCE],
|
|
223
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.REFERENCE, v),
|
|
224
|
-
'',
|
|
225
|
-
),
|
|
226
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.LOGIN)]: DG.Property.create(
|
|
227
|
-
FUNC_PROPS_FIELDS.LOGIN, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.LOGIN],
|
|
228
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.LOGIN, v),
|
|
229
|
-
'',
|
|
230
|
-
),
|
|
231
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.SAMPLE)]: DG.Property.create(
|
|
232
|
-
FUNC_PROPS_FIELDS.SAMPLE, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.SAMPLE],
|
|
233
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.SAMPLE, v),
|
|
234
|
-
'',
|
|
235
|
-
),
|
|
236
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.ENVIRONMENT)]: DG.Property.create(
|
|
237
|
-
FUNC_PROPS_FIELDS.ENVIRONMENT, DG.TYPE.STRING, (x: any) => x[FUNC_PROPS_FIELDS.ENVIRONMENT],
|
|
238
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.ENVIRONMENT, v),
|
|
239
|
-
'',
|
|
240
|
-
),
|
|
241
|
-
[functionPropsLabels(FUNC_PROPS_FIELDS.TAGS)]: DG.Property.create(
|
|
242
|
-
FUNC_PROPS_FIELDS.TAGS, DG.TYPE.LIST,
|
|
243
|
-
(x: any) => x[FUNC_PROPS_FIELDS.TAGS],
|
|
244
|
-
(x: any, v) => updateFuncPropValue(x, FUNC_PROPS_FIELDS.TAGS, v),
|
|
245
|
-
[],
|
|
246
|
-
),
|
|
247
|
-
};
|
|
248
|
-
|
|
249
|
-
const getNewProps = () => {
|
|
250
|
-
const newProps = [];
|
|
251
|
-
for (const prop of Object.values(functionProps)) {
|
|
252
|
-
if (!prop.get(inputScriptCopy) && !(inputScriptCopy as any)[prop.name]) {
|
|
253
|
-
newProps.push(prop);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return newProps;
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
let addButton = ui.div();
|
|
260
|
-
let propsForm = ui.div();
|
|
261
|
-
let inputs: HTMLElement = ui.div();
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const functionPropsInput = (prop: DG.Property) => {
|
|
265
|
-
switch (prop.name) {
|
|
266
|
-
case FUNC_PROPS_FIELDS.LANGUAGE:
|
|
267
|
-
return ui.choiceInput(
|
|
268
|
-
functionPropsLabels(prop.name as FUNC_PROPS_FIELDS),
|
|
269
|
-
prop.get(inputScriptCopy) || (inputScriptCopy as any)[prop.name],
|
|
270
|
-
prop.choices,
|
|
271
|
-
);
|
|
272
|
-
// case FUNC_PROPS_FIELDS.TAGS:
|
|
273
|
-
// return ui.multiChoiceInput(
|
|
274
|
-
// functionPropsLabels(prop.name as FUNC_PROPS_FIELDS),
|
|
275
|
-
// prop.get(inputScriptCopy) || (inputScriptCopy as any)[prop.name],
|
|
276
|
-
// prop.choices,
|
|
277
|
-
// );
|
|
278
|
-
default:
|
|
279
|
-
return ui.stringInput(functionPropsLabels(prop.name as FUNC_PROPS_FIELDS),
|
|
280
|
-
prop.get(inputScriptCopy) || (inputScriptCopy as any)[prop.name]);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
const renderAddPropButton = () => {
|
|
285
|
-
if (!getNewProps().length) return ui.div();
|
|
286
|
-
|
|
287
|
-
const onItemClick = (item: DG.Property) => {
|
|
288
|
-
item.set(inputScriptCopy, ' ');
|
|
289
|
-
const newInputs = ui.inputs(
|
|
290
|
-
Object.values(functionProps)
|
|
291
|
-
.filter((prop) => !!prop.get(inputScriptCopy) || !!(inputScriptCopy as any)[prop.name])
|
|
292
|
-
.map((prop) => addFullWidthInput(
|
|
293
|
-
functionPropsInput(prop),
|
|
294
|
-
prop,
|
|
295
|
-
)),
|
|
296
|
-
);
|
|
297
|
-
inputs.replaceWith(newInputs);
|
|
298
|
-
inputs = newInputs;
|
|
299
|
-
refreshPreview();
|
|
300
|
-
const newAddButton = renderAddPropButton();
|
|
301
|
-
addButton.replaceWith(newAddButton);
|
|
302
|
-
addButton = newAddButton;
|
|
303
|
-
};
|
|
304
|
-
const menu = DG.Menu.popup();
|
|
305
|
-
getNewProps().forEach(
|
|
306
|
-
(prop) => menu.item(functionPropsLabels(prop.name as FUNC_PROPS_FIELDS), () => onItemClick(prop)),
|
|
307
|
-
);
|
|
308
|
-
|
|
309
|
-
const shevron = ui.iconFA('chevron-down');
|
|
310
|
-
const button = ui.button([ui.icons.add(()=>{}), shevron], () => {
|
|
311
|
-
menu.show();
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
const div = ui.div([button]);
|
|
315
|
-
div.style.cssText += 'margin-left: 152px';
|
|
316
|
-
return div;
|
|
317
|
-
};
|
|
318
|
-
|
|
319
|
-
const addFullWidthInput = (input: DG.InputBase, prop: DG.Property) => {
|
|
320
|
-
(input.root.lastChild as HTMLElement).style.cssText+='width: 400px; max-width: inherit;';
|
|
321
|
-
input.onInput(() => {
|
|
322
|
-
prop.set(inputScriptCopy, input.stringValue);
|
|
323
|
-
refreshPreview();
|
|
324
|
-
});
|
|
325
|
-
(input.root as HTMLInputElement).placeholder = 'Enter your value...';
|
|
326
|
-
input.root.append(ui.button(ui.icons.delete(()=>{}), () => {
|
|
327
|
-
prop.set(inputScriptCopy, prop.defaultValue);
|
|
328
|
-
refreshPreview();
|
|
329
|
-
input.root.remove();
|
|
330
|
-
const newAddButton = renderAddPropButton();
|
|
331
|
-
addButton.replaceWith(newAddButton);
|
|
332
|
-
addButton = newAddButton;
|
|
333
|
-
}));
|
|
334
|
-
(input.root.lastChild as HTMLElement).style.cssText+='display: inline-flex; justify-content: center; flex-direction: column';
|
|
335
|
-
if (obligatoryFuncProps.includes(prop.name)) {
|
|
336
|
-
input.root.style.cssText += 'padding-right: 35.375px';
|
|
337
|
-
(input.root.lastChild as HTMLElement).style.cssText+='display: none;';
|
|
338
|
-
}
|
|
339
|
-
return input;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
const functionPropsForm = () => {
|
|
343
|
-
addButton = renderAddPropButton();
|
|
344
|
-
|
|
345
|
-
inputs = ui.inputs(
|
|
346
|
-
Object.values(functionProps)
|
|
347
|
-
.filter((prop) => !!prop.get(inputScriptCopy) || !!(inputScriptCopy as any)[prop.name])
|
|
348
|
-
.map((prop) => addFullWidthInput(
|
|
349
|
-
functionPropsInput(prop),
|
|
350
|
-
prop,
|
|
351
|
-
)),
|
|
352
|
-
);
|
|
353
|
-
return ui.panel([
|
|
354
|
-
ui.divV([
|
|
355
|
-
inputs,
|
|
356
|
-
addButton,
|
|
357
|
-
]),
|
|
358
|
-
]);
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
const functionInputParamsCopy = inputScriptCopy.inputs;
|
|
362
|
-
const functionOutputParamsCopy = inputScriptCopy.outputs;
|
|
363
|
-
|
|
364
|
-
const onFunctionParamClick = (paramName: string, direction: DIRECTION) => {
|
|
365
|
-
let paramIndex: number;
|
|
366
|
-
let param: DG.Property;
|
|
367
|
-
|
|
368
|
-
if (direction === DIRECTION.INPUT) {
|
|
369
|
-
paramIndex = functionInputParamsCopy.findIndex((input) => input.name === paramName);
|
|
370
|
-
param = functionInputParamsCopy[paramIndex];
|
|
371
|
-
} else {
|
|
372
|
-
paramIndex= functionOutputParamsCopy.findIndex((input) => input.name === paramName);
|
|
373
|
-
param = functionOutputParamsCopy[paramIndex];
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
if (!param) return ui.div('');
|
|
377
|
-
|
|
378
|
-
const result = ui.input.form(param, optionalFuncParamsProps.filter(
|
|
379
|
-
(prop) => optionTags(param).includes(prop.name as OPTIONAL_TAG_NAME)),
|
|
380
|
-
);
|
|
381
|
-
|
|
382
|
-
grok.shell.o = ui.divV([ui.h1(`Param: ${paramName}`), ui.block75([result])]);
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
const updateValue = (param: DG.Property, propName: string, v: any) => {
|
|
386
|
-
(param as any)[propName] = v;
|
|
387
|
-
const globalParam = functionOutputParamsCopy.find((input) => input.name === param.name) ||
|
|
388
|
-
functionInputParamsCopy.find((input) => input.name === param.name);
|
|
389
|
-
if (globalParam) globalParam.options[propName] = v;
|
|
390
|
-
functionInputParamsState.next(functionInputParamsCopy);
|
|
391
|
-
functionOutputParamsState.next(functionOutputParamsCopy);
|
|
392
|
-
refreshPreview();
|
|
393
|
-
};
|
|
394
|
-
|
|
395
|
-
const obligatoryFuncParamsProps: DG.Property[] = [
|
|
396
|
-
DG.Property.create(FUNC_PARAM_FIELDS.NAME, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.NAME],
|
|
397
|
-
(x: any, v) => updateValue(x, FUNC_PARAM_FIELDS.NAME, v), ''),
|
|
398
|
-
(() => {
|
|
399
|
-
const temp = DG.Property.create(FUNC_PARAM_FIELDS.TYPE, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.TYPE], (x: any, v) => updateValue(x, FUNC_PARAM_FIELDS.TYPE, v), '');
|
|
400
|
-
temp.fromOptions({choices: funcParamTypes});
|
|
401
|
-
return temp;
|
|
402
|
-
})(),
|
|
403
|
-
DG.Property.create(FUNC_PARAM_FIELDS.DEFAULT_VALUE, DG.TYPE.OBJECT, (x: any) => x[FUNC_PARAM_FIELDS.DEFAULT_VALUE], (x: any, v) => updateValue(x, FUNC_PARAM_FIELDS.DEFAULT_VALUE, v), ''),
|
|
404
|
-
(() => {
|
|
405
|
-
const temp = DG.Property.create(FUNC_PARAM_FIELDS.DESCRIPTION, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.DESCRIPTION], (x: any, v) => updateValue(x, FUNC_PARAM_FIELDS.DESCRIPTION, v), '');
|
|
406
|
-
temp.fromOptions({editor: 'textarea'});
|
|
407
|
-
return temp;
|
|
408
|
-
})(),
|
|
409
|
-
DG.Property.create(FUNC_PARAM_FIELDS.CATEGORY, DG.TYPE.STRING, (x: any) => x[FUNC_PARAM_FIELDS.CATEGORY], (x: any, v) => updateValue(x, FUNC_PARAM_FIELDS.CATEGORY, v), ''),
|
|
410
|
-
];
|
|
411
|
-
|
|
412
|
-
const optionalFuncParamsProps: DG.Property[] = [
|
|
413
|
-
DG.Property.create(OPTIONAL_TAG_NAME.ACTION, DG.TYPE.STRING,
|
|
414
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.ACTION],
|
|
415
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.ACTION, v), ''),
|
|
416
|
-
|
|
417
|
-
DG.Property.create(OPTIONAL_TAG_NAME.ALLOW_NULLS, DG.TYPE.BOOL,
|
|
418
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.ALLOW_NULLS],
|
|
419
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.ALLOW_NULLS, v), ''),
|
|
420
|
-
|
|
421
|
-
DG.Property.create(OPTIONAL_TAG_NAME.CHOICES, DG.TYPE.LIST,
|
|
422
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.CHOICES],
|
|
423
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.CHOICES, v), ''),
|
|
424
|
-
|
|
425
|
-
(() => {
|
|
426
|
-
const temp = DG.Property.create(OPTIONAL_TAG_NAME.COLUMNS, DG.TYPE.STRING,
|
|
427
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.COLUMNS],
|
|
428
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.COLUMNS, v), '');
|
|
429
|
-
temp.fromOptions({choices: ['numerical', 'categorical']});
|
|
430
|
-
return temp;
|
|
431
|
-
})(),
|
|
432
|
-
|
|
433
|
-
DG.Property.create(OPTIONAL_TAG_NAME.FORMAT, DG.TYPE.STRING,
|
|
434
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.FORMAT],
|
|
435
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.FORMAT, v), ''),
|
|
436
|
-
|
|
437
|
-
DG.Property.create(OPTIONAL_TAG_NAME.MAX, DG.TYPE.INT,
|
|
438
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.MAX],
|
|
439
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.MAX, v), ''),
|
|
440
|
-
|
|
441
|
-
DG.Property.create(OPTIONAL_TAG_NAME.MIN, DG.TYPE.INT,
|
|
442
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.MIN],
|
|
443
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.MIN, v), ''),
|
|
444
|
-
|
|
445
|
-
DG.Property.create(OPTIONAL_TAG_NAME.SEM_TYPE, DG.TYPE.STRING,
|
|
446
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.SEM_TYPE],
|
|
447
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.SEM_TYPE, v), ''),
|
|
448
|
-
|
|
449
|
-
DG.Property.create(OPTIONAL_TAG_NAME.SUGGESTIONS, DG.TYPE.STRING,
|
|
450
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.SUGGESTIONS],
|
|
451
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.SUGGESTIONS, v), ''),
|
|
452
|
-
|
|
453
|
-
(() => {
|
|
454
|
-
const temp = DG.Property.create(OPTIONAL_TAG_NAME.TYPE, DG.TYPE.STRING,
|
|
455
|
-
(x: any) => x.options[OPTIONAL_TAG_NAME.TYPE],
|
|
456
|
-
(x: any, v) => updateValue(x, OPTIONAL_TAG_NAME.TYPE, v), '');
|
|
457
|
-
temp.fromOptions({choices: ['numerical', 'categorical', 'dateTime']});
|
|
458
|
-
return temp;
|
|
459
|
-
})(),
|
|
460
|
-
];
|
|
461
|
-
|
|
462
|
-
const inputParamsDF = DG.DataFrame.create(functionInputParamsCopy.length);
|
|
463
|
-
for (const p of obligatoryFuncParamsProps) {
|
|
464
|
-
(inputParamsDF.columns as DG.ColumnList)
|
|
465
|
-
.addNew(functionParamsMapping[p.name as keyof typeof functionParamsMapping], p.propertyType as DG.ColumnType)
|
|
466
|
-
.init((i: number) => {
|
|
467
|
-
return p.get(functionInputParamsCopy[i]) || (p as any)[functionInputParamsCopy[i].name];
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
const inputParamGrid = DG.Grid.create(inputParamsDF);
|
|
471
|
-
inputParamGrid.root.style.width = '100%';
|
|
472
|
-
inputParamGrid.dataFrame?.getCol(functionParamsMapping[FUNC_PARAM_FIELDS.TYPE as keyof typeof functionParamsMapping])
|
|
473
|
-
.setTag(DG.TAGS.CHOICES, `["${funcParamTypes.join(`", "`)}"]`);
|
|
474
|
-
inputParamsDF.onCurrentRowChanged.subscribe(() => onFunctionParamClick((inputParamsDF.currentRow as any)['Name'], DIRECTION.INPUT));
|
|
475
|
-
|
|
476
|
-
const outputParamsDF = DG.DataFrame.create(functionOutputParamsCopy.length);
|
|
477
|
-
for (const p of obligatoryFuncParamsProps) {
|
|
478
|
-
(outputParamsDF.columns as DG.ColumnList)
|
|
479
|
-
.addNew(functionParamsMapping[p.name as keyof typeof functionParamsMapping], p.propertyType as DG.ColumnType)
|
|
480
|
-
.init((i: number) => p.get(functionInputParamsCopy[i]) || (p as any)[functionInputParamsCopy[i].name]);
|
|
481
|
-
}
|
|
482
|
-
const outputParamGrid = DG.Grid.create(outputParamsDF);
|
|
483
|
-
outputParamGrid.dataFrame?.getCol(functionParamsMapping[FUNC_PARAM_FIELDS.TYPE as keyof typeof functionParamsMapping])
|
|
484
|
-
.setTag(DG.TAGS.CHOICES, `["${funcParamTypes.join(`", "`)}"]`);
|
|
485
|
-
outputParamsDF.onCurrentRowChanged.subscribe(() => onFunctionParamClick((outputParamsDF.currentRow as any)['Name'], DIRECTION.OUTPUT));
|
|
486
|
-
outputParamGrid.root.style.width = '100%';
|
|
487
|
-
|
|
488
|
-
const area = ui.textInput('', '');
|
|
489
|
-
const myCM = CodeMirror.fromTextArea((area.input as HTMLTextAreaElement));
|
|
490
|
-
|
|
491
|
-
const previewDiv = ui.panel([ui.divV([ui.h1('Code preview'), area])]);
|
|
492
|
-
previewDiv.style.flexGrow = '1';
|
|
493
|
-
|
|
494
|
-
propsForm = functionPropsForm();
|
|
495
|
-
|
|
496
|
-
const renderAddParamButton = () => {
|
|
497
|
-
const paramProps = obligatoryFuncParamsProps
|
|
498
|
-
.filter((param) => param.name !== FUNC_PARAM_FIELDS.DIRECTION);
|
|
499
|
-
|
|
500
|
-
const newParam = {
|
|
501
|
-
[FUNC_PARAM_FIELDS.NAME]: '',
|
|
502
|
-
[FUNC_PARAM_FIELDS.TYPE]: DG.TYPE.BOOL,
|
|
503
|
-
[FUNC_PARAM_FIELDS.DEFAULT_VALUE]: false,
|
|
504
|
-
[FUNC_PARAM_FIELDS.DESCRIPTION]: '',
|
|
505
|
-
[FUNC_PARAM_FIELDS.CATEGORY]: '',
|
|
506
|
-
};
|
|
507
|
-
|
|
508
|
-
const onItemClick = () => {
|
|
509
|
-
ui.dialog('Add parameter')
|
|
510
|
-
.add(ui.input.form(newParam, paramProps))
|
|
511
|
-
.onOK(() => {
|
|
512
|
-
inputParamsDF.rows.addNew(paramProps.map((prop) => prop.get(newParam)));
|
|
513
|
-
refreshPreview();
|
|
514
|
-
})
|
|
515
|
-
.show();
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
const menu = DG.Menu.popup().items(funcParamTypes, onItemClick);
|
|
519
|
-
|
|
520
|
-
const shevron = ui.iconFA('chevron-down');
|
|
521
|
-
const button = ui.button([ui.icons.add(()=>{}), shevron], () => {
|
|
522
|
-
menu.show();
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
const div = ui.div([button]);
|
|
526
|
-
return div;
|
|
527
|
-
};
|
|
528
|
-
const addInputButton = renderAddParamButton();
|
|
529
|
-
const addOutputButton = renderAddParamButton();
|
|
530
|
-
|
|
531
|
-
const tabs = ui.tabControl({
|
|
532
|
-
'PROPERTIES': propsForm,
|
|
533
|
-
'PARAMETERS': ui.divV([
|
|
534
|
-
ui.div(ui.h1('Input: '), {style: {'padding': '12px 12px 0px 12px'}}),
|
|
535
|
-
inputParamGrid.root,
|
|
536
|
-
addInputButton,
|
|
537
|
-
ui.div(ui.h1('Output: '), {style: {'padding': '12px 12px 0px 12px'}}),
|
|
538
|
-
outputParamGrid.root,
|
|
539
|
-
addOutputButton,
|
|
540
|
-
]),
|
|
541
|
-
});
|
|
542
|
-
tabs.root.style.width = '100%';
|
|
543
|
-
tabs.root.style.flexGrow = '3';
|
|
544
|
-
|
|
545
|
-
editorView.append(
|
|
546
|
-
ui.divV([
|
|
547
|
-
tabs,
|
|
548
|
-
previewDiv,
|
|
549
|
-
]),
|
|
550
|
-
);
|
|
551
|
-
editorView.box = true;
|
|
552
|
-
editorView.setRibbonPanels([
|
|
553
|
-
[
|
|
554
|
-
ui.iconFA('eye', () => {
|
|
555
|
-
previewDiv.hidden ? previewDiv.hidden = false : previewDiv.hidden = true;
|
|
556
|
-
}),
|
|
557
|
-
ui.bigButton('Save', () => grok.shell.info('plus')),
|
|
558
|
-
],
|
|
559
|
-
]);
|
|
560
|
-
|
|
561
|
-
const refreshPreview = () => {
|
|
562
|
-
let result = '';
|
|
563
|
-
Object.values(functionProps).map((propField) => {
|
|
564
|
-
const propValue = propField.get(inputScriptCopy) || (inputScriptCopy as any)[propField.name];
|
|
565
|
-
if (!!propValue && !!propValue.length) {
|
|
566
|
-
result += `#${functionPropsCode(propField.name as FUNC_PROPS_FIELDS)}: ${propValue}\n`;
|
|
567
|
-
}
|
|
568
|
-
});
|
|
569
|
-
functionInputParamsCopy.map((param) => {
|
|
570
|
-
result += generateParamLine(param, DIRECTION.INPUT);
|
|
571
|
-
});
|
|
572
|
-
functionOutputParamsCopy.map((param) => {
|
|
573
|
-
result += generateParamLine(param, DIRECTION.OUTPUT);
|
|
574
|
-
});
|
|
575
|
-
myCM.setValue(result);
|
|
576
|
-
};
|
|
577
|
-
|
|
578
|
-
grok.shell.addView(editorView);
|
|
579
|
-
refreshPreview();
|
|
580
|
-
|
|
581
|
-
const functionInputParamsState = new BehaviorSubject(functionInputParamsCopy);
|
|
582
|
-
functionInputParamsState.subscribe(() => {
|
|
583
|
-
for (const p of obligatoryFuncParamsProps) {
|
|
584
|
-
(inputParamsDF.columns as DG.ColumnList)
|
|
585
|
-
.byName(functionParamsMapping[p.name as keyof typeof functionParamsMapping])
|
|
586
|
-
.init((i: number) => {
|
|
587
|
-
return p.get(functionInputParamsCopy[i]) || (functionInputParamsCopy[i] as any)[p.name];
|
|
588
|
-
});
|
|
589
|
-
}
|
|
590
|
-
refreshPreview();
|
|
591
|
-
});
|
|
592
|
-
|
|
593
|
-
const functionOutputParamsState = new BehaviorSubject(functionOutputParamsCopy);
|
|
594
|
-
functionOutputParamsState.subscribe(() => {
|
|
595
|
-
for (const p of obligatoryFuncParamsProps) {
|
|
596
|
-
(outputParamsDF.columns as DG.ColumnList)
|
|
597
|
-
.byName(functionParamsMapping[p.name as keyof typeof functionParamsMapping])
|
|
598
|
-
.init((i: number) => {
|
|
599
|
-
return p.get(functionOutputParamsCopy[i]) || (functionOutputParamsCopy[i] as any)[p.name];
|
|
600
|
-
});
|
|
601
|
-
}
|
|
602
|
-
refreshPreview();
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
inputParamGrid.onCellValueEdited.subscribe((editedCell)=> {
|
|
606
|
-
(functionInputParamsCopy[editedCell.cell.rowIndex] as any)
|
|
607
|
-
[functionParamsMapping[editedCell.cell.column.name as keyof typeof functionParamsMapping]] = editedCell.cell.value;
|
|
608
|
-
functionInputParamsState.next(functionInputParamsCopy);
|
|
609
|
-
});
|
|
610
|
-
outputParamGrid.onCellValueEdited.subscribe((editedCell)=> {
|
|
611
|
-
(functionOutputParamsCopy[editedCell.cell.rowIndex] as any)
|
|
612
|
-
[functionParamsMapping[editedCell.cell.column.name as keyof typeof functionParamsMapping]] = editedCell.cell.value;
|
|
613
|
-
functionOutputParamsState.next(functionOutputParamsCopy);
|
|
614
|
-
});
|
|
615
|
-
}
|