@datagrok/compute 0.7.2 → 0.9.0

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,13 +1,18 @@
1
1
  {
2
2
  "name": "@datagrok/compute",
3
3
  "friendlyName": "Compute",
4
- "version": "0.7.2",
5
- "description": "",
4
+ "version": "0.9.0",
5
+ "description": "Provides additional analytical and UI blocks for [Datagrok scientific computing](../../help/compute/compute.md)",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/datagrok-ai/public.git",
9
+ "directory": "packages/Compute"
10
+ },
6
11
  "dependencies": {
7
- "@datagrok-libraries/utils": "^0.2.4",
12
+ "@datagrok-libraries/utils": "^0.5.0",
8
13
  "cash-dom": "latest",
9
14
  "codemirror": "^5.64.0",
10
- "datagrok-api": "^0.148.1",
15
+ "datagrok-api": "^1.4.4",
11
16
  "dayjs": "latest",
12
17
  "exceljs": "^4.3.0",
13
18
  "file-saver": "^2.0.5",
@@ -33,8 +38,8 @@
33
38
  "link-api": "npm link datagrok-api",
34
39
  "link-utils": "npm link @datagrok-libraries/utils",
35
40
  "link-all": "npm link datagrok-api @datagrok-libraries/utils",
36
- "debug-compute": "webpack & grok publish dev --release",
37
- "release-compute": "grok publish --rebuild --release",
41
+ "debug-compute": "webpack & grok publish localhost --release",
42
+ "release-compute": "webpack && grok publish localhost --release",
38
43
  "build-compute": "webpack",
39
44
  "build": "webpack",
40
45
  "build-compute-local": "npm --prefix ./../../js-api run build && npm --prefix ./../../libraries/utils run build && npm run build",
@@ -52,5 +57,6 @@
52
57
  ],
53
58
  "canView": [
54
59
  "All users"
55
- ]
60
+ ],
61
+ "category": "Machine Learning"
56
62
  }
package/package.png CHANGED
Binary file
@@ -1,8 +1,9 @@
1
1
  #name: Fab Arm Exchange
2
2
  #language: python
3
- #tags: model, simulation
4
- #meta.modality: Antibody
5
- #meta.domain: Manufacturing
3
+ #tags: antibody-eng
4
+ #meta.department: BTDS
5
+ #meta.status: Upstream
6
+ #meta.group: Bioengineering process
6
7
  #input: double meaConcentration = 60 {category:FAE Reaction Parameters; units:mM; caption:2-MEA Concentration} [2-MEA Concentration]
7
8
  #input: double phOfFaeReaction = 7.5 {category:FAE Reaction Parameters; caption:pH of FAE Reaction} [pH of FAE Reaction]
8
9
  #input: double faeReactionTime = 3 {category:FAE Reaction Parameters; units:hr; caption:FAE Reaction Time} [FAE Reaction Time]
@@ -1,7 +1,6 @@
1
1
  //name: Heat Exchange
2
2
  //language: javascript
3
- //tags: model, simulation
4
- //meta.modality: Small molecule
3
+ //tags: simulation
5
4
  //input: int len = 1000
6
5
  //input: double k = 1.2
7
6
  //output: dataframe simulation {viewer: Line Chart(multiAxis: "true")}
@@ -9,6 +8,7 @@
9
8
  //output: double finalSaturation
10
9
  //output: double finalConcentration
11
10
  //meta.domain: Manufacturing
11
+ //meta.modality: Small molecule
12
12
 
13
13
  function sigmoid(z) {
14
14
  return 1 / (1 + Math.exp(-z));
@@ -1,7 +1,6 @@
1
1
  #name: IntervalsFromECG
2
2
  #description: Identify the beats in an ECG signal and compute the IBIs
3
3
  #language: python
4
- #tags: model
5
4
  #input: double samplingFrequency = 2048
6
5
  #input: int bpmMax = 120 [Maximal expected heart rate (in beats per minute): (1 < bpm_max <= 400)]
7
6
  #input: double delta = 0 [Threshold for the peak detection. By default it is computed from the signal (adaptive thresholding)]
@@ -1,5 +1,5 @@
1
1
  //name: Logistic Map
2
- //tags: model, simulation
2
+ //tags: simulation
3
3
  //description: Archetypal example of how complex, chaotic behaviour can arise from very simple non-linear dynamical equations.
4
4
  //language: javascript
5
5
  //input: int iterations = 1000 [Number of iterations per point]
@@ -1,5 +1,5 @@
1
1
  //name: Lorenz Attractor
2
- //tags: model, simulation
2
+ //tags: simulation
3
3
  //meta.domain: Nonlinear dynamics
4
4
  //description: Set of chaotic solutions of the system for weather prediction. It illustrates the phenomenon known as the Butterfly effect or (more technically) sensitive dependence on initial conditions
5
5
  //language: javascript
@@ -1,5 +1,5 @@
1
1
  //name: Lotka-Volterra
2
- //tags: model, simulation
2
+ //tags: simulation
3
3
  //meta.domain: Nonlinear dynamics
4
4
  //description: Model describes the dynamics of biological systems in which two species interact, one as a predator and the other as prey.
5
5
  //language: javascript
@@ -14,6 +14,7 @@
14
14
  //input: double timeStop = 18
15
15
  //output: dataframe df {viewer: Line Chart(x: "Time", multiAxis: "true", title: "Lotka-Volterra Model")}
16
16
 
17
+
17
18
  function sumArrays(...arrays) {
18
19
  return Array.from({ length: 2 })
19
20
  .map((_, i) => arrays
@@ -1,7 +1,6 @@
1
1
  #name: Vmax
2
2
  #description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
3
3
  #language: r
4
- #tags: model
5
4
  #input: dataframe test_data {editor: Compute:manualOutlierSelectionDialog; editor-button: Outliers...}
6
5
  #input: double test_area = 3.5 {caption: Filter Area; units: cm²} [Filter area]
7
6
  #input: double vbatch = 25 {caption: VBatch; units: L} [Desired batch size to process]
@@ -0,0 +1,53 @@
1
+ #name: Default complex script
2
+ #description: Shows that default view works (or not)
3
+ #language: octave
4
+ #tags: bioreactor
5
+ #input: dataframe test { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) }
6
+ #input: double UA = 424.2832 {caption: UA; units: ft² * BTU / hr °F}
7
+ #input: double CoolingWaterFlow = 12 {caption: Coolant flowrate; units: L/min}
8
+ #input: double Tcoolingin = -2 {caption: Coolant temp.; units: °C}
9
+ #input: double VCD = 5 {caption: Target VCD; units: cells/mL}
10
+ #input: double VL = 210.5 {caption: Final Volume; units: L}
11
+ #input: double IC = 31.1 {caption: Culture temp.; units: °C}
12
+ #output: dataframe tempOnTime { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate }
13
+ #output: double IC2 {caption: Culture temp.; units: °C; category: Cooling rate}
14
+ #output: dataframe tempOnTime2 { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) | Grid(block: 50); category: Cooling rate 2 }
15
+ #output: dataframe tempOnTime3 { viewer: Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) | Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate 3 }
16
+ #output: dataframe tempOnTime4 { viewer: Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate 3 }
17
+ #output: dataframe tempOnTime5 { viewer: Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false) | Line chart(block: 50, x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate 3 }
18
+ #output: double IC3 {caption: Culture temp.; units: °C; category: Cooling rate 3}
19
+ #editor: Compute:FunctionViewEditor
20
+
21
+ pkg load symbolic
22
+
23
+ ## Conversion
24
+ CalperBTU = 252;
25
+ CalperhourperWatt = 3600/4.183076;
26
+ Cp = 1;
27
+ CoolingFactor = 56.5;
28
+
29
+ ## Explicit Equation
30
+ ##specificenthalpyreaction = 3.7136 * exp(0.0652*Tsub);
31
+ ##Qrxn = VCD * 10^6 * VL * specificenthalpyofreaction/10^9;
32
+ ##LMTD = (Tcoolingin-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/log((Tsub-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/(Tsub-Tcoolingin));
33
+ ##Tcoolingout = Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)));
34
+ ## Differential equation
35
+ syms Tsub;
36
+
37
+ F1 = @(t, Tsub) -UA * (CoolingFactor / 100) * ((Tcoolingin - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / log((Tsub - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / (Tsub - Tcoolingin))) * 1.8 * CalperBTU / (VL * Cp * 1000) + (VCD * 10^6 * VL * 3.7136 * exp(0.0652 * Tsub) / 10^9) * CalperhourperWatt / (VL * Cp * 1000);
38
+
39
+ ## Change the time here
40
+ t = 3;
41
+ dt = 3/20;
42
+
43
+ ## Solving the differential equations
44
+ [tt, Sol] = ode45(F1, 0:dt:t, IC);
45
+ labels = {"Time (hours)", "Temperature (°C)"};
46
+ tempOnTime = [labels; num2cell([tt, Sol])];
47
+ tempOnTime2 = tempOnTime;
48
+ tempOnTime3 = tempOnTime;
49
+ tempOnTime4 = tempOnTime;
50
+ tempOnTime5 = tempOnTime;
51
+
52
+ IC2 = IC
53
+ IC3 = IC
@@ -0,0 +1,39 @@
1
+ #name: Default simple script
2
+ #description: Shows that default view works (or not)
3
+ #language: octave
4
+ #tags: bioreactor
5
+ #input: double UA = 424.2832 {caption: UA; units: ft² * BTU / hr °F}
6
+ #input: double CoolingWaterFlow = 12 {caption: Coolant flowrate; units: L/min}
7
+ #input: double Tcoolingin = -2 {caption: Coolant temp.; units: °C}
8
+ #input: double VCD = 5 {caption: Target VCD; units: cells/mL}
9
+ #input: double VL = 210.5 {caption: Final Volume; units: L}
10
+ #input: double IC = 31.1 {caption: Culture temp.; units: °C}
11
+ #output: dataframe tempOnTime { viewer: Line chart(x: "Time (hours)", y: "Temperature (°C)", showSplitSelector: false); category: Cooling rate }
12
+ #editor: Compute:FunctionViewEditor
13
+
14
+ pkg load symbolic
15
+
16
+ ## Conversion
17
+ CalperBTU = 252;
18
+ CalperhourperWatt = 3600/4.183076;
19
+ Cp = 1;
20
+ CoolingFactor = 56.5;
21
+
22
+ ## Explicit Equation
23
+ ##specificenthalpyreaction = 3.7136 * exp(0.0652*Tsub);
24
+ ##Qrxn = VCD * 10^6 * VL * specificenthalpyofreaction/10^9;
25
+ ##LMTD = (Tcoolingin-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/log((Tsub-(Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)))))/(Tsub-Tcoolingin));
26
+ ##Tcoolingout = Tsub + (Tcoolingin-Tsub)/(exp(UA*(CoolingFactor/100)*1.8*CalperBTU/(CoolingWaterFlow*Cp*60*1000)));
27
+ ## Differential equation
28
+ syms Tsub;
29
+
30
+ F1 = @(t, Tsub) -UA * (CoolingFactor / 100) * ((Tcoolingin - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / log((Tsub - (Tsub + (Tcoolingin - Tsub) / (exp(UA * (CoolingFactor / 100) * 1.8 * CalperBTU / (CoolingWaterFlow * Cp * 60 * 1000))))) / (Tsub - Tcoolingin))) * 1.8 * CalperBTU / (VL * Cp * 1000) + (VCD * 10^6 * VL * 3.7136 * exp(0.0652 * Tsub) / 10^9) * CalperhourperWatt / (VL * Cp * 1000);
31
+
32
+ ## Change the time here
33
+ t = 3;
34
+ dt = 3/20;
35
+
36
+ ## Solving the differential equations
37
+ [tt, Sol] = ode45(F1, 0:dt:t, IC);
38
+ labels = {"Time (hours)", "Temperature (°C)"};
39
+ tempOnTime = [labels; num2cell([tt, Sol])];
package/scripts/pkpd.R CHANGED
@@ -12,7 +12,6 @@
12
12
  #input: double effect = 8 {category: PD parameters} [EC50]
13
13
  #output: graphics PKPD
14
14
  #output: double Cmax {units: nM}
15
- #tags: model
16
15
  #meta.domain: PKPD
17
16
 
18
17
  require("ggplot2")
package/scripts/popPK.R CHANGED
@@ -10,7 +10,6 @@
10
10
  #input: double perV = 30 {category: PK parameters} [peripheral compartment volume]
11
11
  #input: double interRate = 1 {category: PK parameters} [intercompartmental rate]
12
12
  #output: graphics popPK
13
- #tags: model
14
13
  #meta.domain: PKPD
15
14
 
16
15
  require("ggplot2")
package/scripts/trig.js CHANGED
@@ -1,7 +1,6 @@
1
1
  //name: trig
2
2
  //description: Returns sin, cos, and tan
3
3
  //language: javascript
4
- //tags: model
5
4
  //input: double x
6
5
  //output: double sin
7
6
  //output: double cos
package/scripts/vmax.js CHANGED
@@ -1,7 +1,9 @@
1
1
  //name: Vmax
2
2
  //description: Predict the minimum filter size required for the separation of effluent from bioreactors, given the constraints of batch size and total batch time based on a training dataset of time vs filtrate volume for a given filter type, filter area and pressure
3
3
  //language: javascript
4
- //tags: model, filtration
4
+ //tags: filtration, scale-up
5
+ //meta.department: BTDS
6
+ //meta.status: Upstream
5
7
  //input: dataframe inputTable {caption: Input table; viewer: OutliersSelectionViewer(block: 25) | Scatter Plot(y: "t/V (hr/(L/m²))", block: 75, filter: "!${isOutlier}", showFilteredOutPoints: "true", filteredOutRowsColor: 4293991195, showRegressionLine: "true", markers: "isOutlier", lassoTool: "true", legendVisibility: "Never", filterByZoom: "false")}
6
8
  //input: dataframe reportingParameters {caption: Reporting parameters; viewer: Grid()}
7
9
  //input: double testFilterArea = 3.5 {caption: Test filter area; units: cm²} [Test filter area]
@@ -16,7 +18,7 @@
16
18
  //output: dataframe recommendations {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Recommendations; category: OUTPUT}
17
19
  //output: dataframe sampleCharacteristics {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Sample characteristics; category: OUTPUT}
18
20
  //output: dataframe filter {viewer: Grid(block: 25, showColumnLabels: false, showRowHeader: false); caption: Filter; category: OUTPUT}
19
-
21
+ //editor: Compute:ComputationView
20
22
  // inputTable = grok.shell.tables[0]; reportingParameters = grok.shell.tables[1];
21
23
  // testFilterArea = 3.5; desiredVolumeOfBatch = 25; desiredProcessTime = 0.5; sf = 1.5;
22
24
 
@@ -1,8 +1,8 @@
1
1
  //name: wrapper
2
2
  //language: javascript
3
3
  //output: view v
4
- //tags: model
5
4
  //meta.domain: math
5
+ //meta.direction: up
6
6
 
7
7
  v = grok.shell.newView('Wrapper', [ui.div(['hello world'])]);
8
8
  // here, launch the app
@@ -0,0 +1,61 @@
1
+ .model-catalog-view .d4-gallery-card.entity-model i {
2
+ height: 64px;
3
+ width: 64px;
4
+ position: initial;
5
+ flex-shrink: 0;
6
+ }
7
+
8
+ .model-catalog-view .d4-gallery-card.entity-model .d4-link-label i.grok-icon + label {
9
+ margin-left: 6px;
10
+ align-items: center;
11
+ display: inline-flex;
12
+ white-space: normal;
13
+ }
14
+
15
+ .model-catalog-view .d4-gallery-card.entity-model {
16
+ padding: 0 8px;
17
+ align-items: center;
18
+ display: flex;
19
+ margin: 0;
20
+ height: 94px;
21
+ }
22
+
23
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .grok-gallery-grid {
24
+ flex-direction: row!important;
25
+ }
26
+
27
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .d4-link-label i.grok-icon {
28
+ width: 32px;
29
+ height: 32px;
30
+ position: initial;
31
+ }
32
+
33
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .d4-link-label label {
34
+ margin-left: 8px;
35
+ }
36
+
37
+ .model-catalog-view .grok-gallery-grid[mode="Brief"] .grok-gallery-grid .d4-link-label {
38
+ min-width: 250px;
39
+ margin-bottom: 9px;
40
+ color: var(--grey-6);
41
+ padding: 10px;
42
+ width: initial;
43
+ }
44
+
45
+ .model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-node {
46
+ font-size: 20px;
47
+ padding: 4px 0;
48
+ color: var(--grey-6);
49
+ }
50
+
51
+ .model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-node {
52
+ font-size: 16px;
53
+ padding: 4px 0;
54
+ color: var(--grey-6);
55
+ }
56
+
57
+ .model-catalog-view .d4-tree-view-root > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group > .d4-tree-view-group-host > .d4-tree-view-group .d4-tree-view-node {
58
+ font-size: 14px;
59
+ padding: 4px 0;
60
+ color: var(--grey-6);
61
+ }
@@ -3,38 +3,72 @@ import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
4
  import {ModelHandler} from './model-handler';
5
5
  import {onboardModel} from './onboard-model';
6
+ import {Subscription} from "rxjs";
6
7
 
7
8
  /* eslint-disable */
8
9
 
10
+ let propsSub: Subscription;
11
+
9
12
  export class ModelCatalogView extends DG.CustomCardView {
10
13
 
11
14
  constructor() {
12
15
  super({dataSource: grok.dapi.functions, permanentFilter: '#model'});
13
16
 
17
+ this.root.classList.add('model-catalog-view');
14
18
  this.meta = new ModelHandler();
15
19
  this.name = 'Models';
16
20
  this.permanentFilter = '#model';
21
+ this.renderMode = DG.RENDER_MODE.BRIEF;
22
+
23
+ this.objectType = 'Func';
24
+ this.categoryFilters = {
25
+ 'options.department': 'Department',
26
+ 'options.group': 'Group',
27
+ 'options.process': 'Process',
28
+ 'tag': 'Tags'
29
+ };
30
+
31
+ this.filters = {
32
+ 'All': '',
33
+ 'Favorites': 'starredBy = @current',
34
+ 'Used by me': 'usedBy = @current'
35
+ };
36
+
37
+ this.hierarchy = [
38
+ 'options.department',
39
+ 'options.group',
40
+ 'options.process'
41
+ ];
17
42
 
18
- this.objectType = 'Script';
19
- this.categoryFilters = {
20
- 'language': 'Language',
21
- 'tag': 'Tags',
22
- 'createdOn': 'Created',
23
- 'author.id': 'Author'
43
+ this.hierarchyProperties = {
44
+ 'options.department': 'Department',
45
+ 'options.group': 'Group',
46
+ 'options.process': 'Process'
24
47
  };
48
+
49
+ this.showTree = true;
25
50
  this.initRibbon();
26
51
  this.initMenu();
52
+ this.currentCall = grok.functions.getCurrentCall();
53
+ if (propsSub == null && window.localStorage.getItem('ModelCatalogShowProperties') == null) { // @ts-ignore
54
+ propsSub = grok.events.onCurrentObjectChanged.subscribe((o) => {
55
+ if (new ModelHandler().isApplicable(o.sender)) {
56
+ grok.shell.windows.showProperties = true;
57
+ window.localStorage.setItem('ModelCatalogShowProperties', 'false');
58
+ propsSub.unsubscribe();
59
+ }
60
+ })
61
+ }
27
62
  }
28
63
 
64
+ currentCall: DG.FuncCall;
65
+
29
66
  initRibbon() {
30
- this.setRibbonPanels([[ui.icons.add(() => onboardModel())]]);
67
+ this.setRibbonPanels([[ui.icons.sync(() => this.refresh())]]);
31
68
  }
32
69
 
33
70
  initMenu() {
34
71
  this.ribbonMenu
35
- .group('Models')
36
- .item('Add New...', () => onboardModel())
37
- .endGroup()
38
72
  .group('Help')
39
73
  .item('Compute Engine', () => window.open('https://github.com/datagrok-ai/public/tree/master/packages/Compute', '_blank'))
40
74
  .item('Developing Models', () => window.open('https://datagrok.ai/help/compute/scripting', '_blank'))
@@ -1,9 +1,8 @@
1
1
  import * as grok from 'datagrok-api/grok';
2
2
  import * as ui from 'datagrok-api/ui';
3
3
  import * as DG from 'datagrok-api/dg';
4
+ import wu from "wu";
4
5
  import {ModelCatalogView} from "./model-catalog-view";
5
- import {TYPE} from "datagrok-api/dg";
6
- import {FunctionView} from '@datagrok-libraries/utils/src/function-view';
7
6
 
8
7
  export class ModelHandler extends DG.ObjectHandler {
9
8
  get type() {
@@ -11,14 +10,11 @@ export class ModelHandler extends DG.ObjectHandler {
11
10
  }
12
11
 
13
12
  async getById(id: string): Promise<DG.Func> {
14
- console.log('id:', id);
15
13
  return await grok.dapi.functions.find(id);
16
14
  }
17
15
 
18
16
  async refresh(x: DG.Script): Promise<DG.Func> {
19
- let script = await this.getById(x.id);
20
- console.log('script:', script);
21
- return script;
17
+ return await this.getById(x.id);
22
18
  }
23
19
 
24
20
  getLanguageIcon(language: string) {
@@ -33,55 +29,120 @@ export class ModelHandler extends DG.ObjectHandler {
33
29
  }
34
30
 
35
31
  renderIcon(x: DG.Func, context: any = null): HTMLElement {
36
- return x instanceof DG.Script ? this.getLanguageIcon(x.language) : ui.iconFA('lightning');
32
+ if (x.options['icon'] != null && (x.options['icon'].startsWith('http://') || x.options['icon'].startsWith('https://'))) {
33
+ return ui.iconImage('model-icon', x.options['icon']);
34
+ }
35
+ if (x instanceof DG.Script) {
36
+ return this.getLanguageIcon(x.language);
37
+ }
38
+ let iconUrl = x.package.getIconUrl();
39
+ if (x.options['icon'] != null) {
40
+ let packagePathSegments = iconUrl.split('/');
41
+ packagePathSegments.pop();
42
+ packagePathSegments.push(x.options['icon']);
43
+ iconUrl = packagePathSegments.join('/')
44
+ }
45
+ return ui.iconImage(x.package.name, iconUrl);
37
46
  }
38
47
 
39
48
  renderMarkup(x: DG.Func): HTMLElement {
40
- return ui.span([this.renderIcon(x), ui.label(x.friendlyName, {style: {marginLeft: '4px'}})], {style: {display: 'inline-flex'}});
49
+ let markup = ui.span([this.renderIcon(x), ui.label(x.friendlyName)]);
50
+ let c = grok.functions.getCurrentCall();
51
+ markup.ondblclick = (e) => {
52
+ ModelHandler.openModel(x, c); }
53
+ return markup;
41
54
  }
42
55
 
43
56
  renderProperties(x: DG.Func) {
44
- const a = ui.accordion();
57
+ const a = ui.accordion('ComputeModel');
45
58
  a.context = x;
46
59
  a.addTitle(ui.span([this.renderIcon(x), ui.label(x.friendlyName), ui.contextActions(x), ui.star(x.id)]));
47
60
  a.addPane('Details', () => {
48
61
  return this.renderDetails(x);
49
- });
50
- a.addCountPane('Usage', () => {
51
- return ui.span(['Usage statistics']);
52
- }, () => 99);
62
+ }, true);
53
63
  a.end();
54
64
  return a.root;
55
65
  }
56
66
 
57
67
  renderDetails(x: DG.Func) {
58
- return ui.divV([ui.render(x.author), ui.render(x.createdOn)], {style: {lineHeight: '150%'}});
68
+ let educationLink = ui.link('Education materials', x.options['education']);
69
+ ui.setDisplay(educationLink, x.options['education'] != null);
70
+ let video = ui.link('Video', x.options['video']);
71
+ ui.setDisplay(video, x.options['video'] != null);
72
+ let status = ui.markdown(`Status: ${x.options['dev.status']}`);
73
+ ui.setDisplay(status, x.options['dev.status'] != null);
74
+ return ui.divV([
75
+ status,
76
+ ui.markdown(x.description),
77
+ ui.tags(x),
78
+ educationLink,
79
+ video
80
+ ], {style: {lineHeight: '150%'}});
59
81
  }
60
82
 
61
83
  renderTooltip(x: DG.Func) {
62
- return ui.divText(`${x.friendlyName}`);
84
+ let h = this.renderMarkup(x);
85
+ h.classList.add('d4-link-label');
86
+ let card = ui.bind(x, ui.divV([
87
+ ui.h2(h),
88
+ ui.divV([ui.divText(x.description, 'ui-description')], {style: {lineHeight: '150%'}})
89
+ ]));
90
+ let c = grok.functions.getCurrentCall();
91
+ card.ondblclick = (e) => { ModelHandler.openModel(x, c); }
92
+ return card;
63
93
  }
64
94
 
65
95
  renderCard(x: DG.Func, context?: any): HTMLElement {
66
- let card = ui.bind(x, ui.divV([
67
- ui.h2(this.renderMarkup(x)),
68
- ui.divText(x.description, 'ui-description'),
69
- this.renderDetails(x),
70
- ], 'd4-gallery-item'), {contextMenu: false});
96
+ let h = this.renderMarkup(x);
97
+ h.classList.add('d4-link-label');
98
+ let card = ui.bind(x, ui.h2(h));
71
99
  let c = grok.functions.getCurrentCall();
72
- card.ondblclick = (e) => {
73
- ModelHandler.openModel(x, c);
74
- }
100
+ card.ondblclick = (e) => { ModelHandler.openModel(x, c); }
75
101
  return card;
76
102
  }
77
103
 
104
+ static getModelCatalogView(): ModelCatalogView {
105
+ let modelsView = this.findModelCatalogView();
106
+ if (modelsView == null) {
107
+ let mc: DG.Func = DG.Func.find({package:'Compute', name: 'ModelCatalog'})[0];
108
+ let fc = mc.prepare();
109
+ let view = new ModelCatalogView();
110
+ view.name = 'Models';
111
+ view.parentCall = fc;
112
+ grok.shell.addView(view);
113
+ }
114
+ modelsView = this.findModelCatalogView();
115
+ return modelsView as ModelCatalogView;
116
+ }
117
+
118
+ static findModelCatalogView(): ModelCatalogView | undefined {
119
+ return wu(grok.shell.views).find((v) => v.parentCall?.func.name == 'modelCatalog') as ModelCatalogView;
120
+ }
121
+
78
122
  static openModel(x: DG.Func, parentCall?: DG.FuncCall) {
79
123
  let fc = x.prepare();
80
- if (parentCall != null)
81
- fc.parentCall = parentCall;
82
124
  fc.edit();
83
125
  }
84
126
 
127
+ static bindModel(fc: DG.FuncCall) {
128
+ let modelsView = ModelHandler.getModelCatalogView();
129
+ fc.aux['showOnTaskBar'] = false;
130
+ if (modelsView != null) {
131
+ let parentCall = modelsView.parentCall;
132
+ if (parentCall != null) {
133
+ parentCall.aux['view'] = modelsView;
134
+ fc.parentCall = parentCall;
135
+ }
136
+ }
137
+ }
138
+
85
139
  init() {
140
+ setTimeout(() => {
141
+ grok.functions.onBeforeRunAction.subscribe((fc) => {
142
+ if (fc.func.hasTag('model') || fc.func.hasTag('model-editor')) {
143
+ ModelHandler.bindModel(fc);
144
+ }
145
+ });
146
+ });
86
147
  }
87
148
  }
@@ -7,6 +7,7 @@ import $ from 'cash-dom';
7
7
  import {FunctionView} from "@datagrok-libraries/utils/src/function-view";
8
8
  const api = <any>window;
9
9
 
10
+ /*
10
11
 
11
12
  export class ModelsWidget extends DG.Widget {
12
13
  caption: string;
@@ -116,4 +117,4 @@ export class ModelsWidget extends DG.Widget {
116
117
  }
117
118
  }
118
119
 
119
- }
120
+ } */