@datagrok/curves 1.8.0 → 1.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.
Files changed (54) hide show
  1. package/.eslintrc.json +39 -0
  2. package/.vscode/launch.json +10 -9
  3. package/.vscode/tasks.json +14 -0
  4. package/CHANGELOG.md +33 -0
  5. package/databases/plates/0000_init.sql +167 -0
  6. package/detectors.js +2 -2
  7. package/dist/package-test.js +15930 -1
  8. package/dist/package-test.js.map +1 -1
  9. package/dist/package.js +13750 -1
  10. package/dist/package.js.map +1 -1
  11. package/package.json +12 -8
  12. package/queries/plates-crud.sql +148 -0
  13. package/src/fit/const.ts +60 -60
  14. package/src/fit/data-to-curves.ts +220 -0
  15. package/src/fit/fit-demo.ts +6 -6
  16. package/src/fit/fit-grid-cell-handler.ts +48 -44
  17. package/src/fit/fit-renderer.ts +56 -55
  18. package/src/fit/multi-curve-viewer.ts +38 -18
  19. package/src/fit/render-utils.ts +315 -315
  20. package/src/package-api.ts +167 -0
  21. package/src/package-test.ts +1 -1
  22. package/src/package.g.ts +133 -3
  23. package/src/package.ts +198 -299
  24. package/src/plate/excel-plates.ts +1 -1
  25. package/src/plate/plate-cell-renderer.ts +20 -12
  26. package/src/plate/plate-drc-analysis.ts +262 -0
  27. package/src/plate/plate-reader.ts +5 -5
  28. package/src/plate/plate-well-validators.ts +41 -0
  29. package/src/plate/plate-widget.ts +132 -368
  30. package/src/plate/plate.ts +168 -57
  31. package/src/plate/plates-folder-preview.ts +63 -0
  32. package/src/plate/readers/bmg-pherastar-96.ts +7 -7
  33. package/src/plate/readers/delfia-envision-96-max-rlu.ts +4 -3
  34. package/src/plate/readers/delfia-envision-by-row.ts +3 -3
  35. package/src/plate/readers/spectramax.ts +7 -8
  36. package/src/plate/utils.ts +22 -10
  37. package/src/plates/numeric_matcher.ts +191 -0
  38. package/src/plates/objects/plate-template-handler.ts +48 -0
  39. package/src/plates/plates-app.ts +64 -0
  40. package/src/plates/plates-crud.ts +502 -0
  41. package/src/plates/plates-demo.ts +107 -0
  42. package/src/plates/plates.sql +169 -0
  43. package/src/plates/views/plates-create-view.ts +123 -0
  44. package/src/plates/views/plates-schema-view.ts +58 -0
  45. package/src/plates/views/plates-search-view.ts +137 -0
  46. package/src/plates/views/plates-templates-view.ts +38 -0
  47. package/src/tests/curves-cell-renderer-tests.ts +93 -92
  48. package/src/tests/detector-tests.ts +3 -2
  49. package/src/tests/fit-tests.ts +199 -198
  50. package/src/tests/plate-tests.ts +6 -7
  51. package/src/tests/transform-tests.ts +4 -4
  52. package/test-console-output-1.log +435 -0
  53. package/test-record-1.mp4 +0 -0
  54. package/tsconfig.json +1 -1
@@ -1,5 +1,7 @@
1
+ /* eslint-disable max-len */
1
2
  import * as DG from 'datagrok-api/dg';
2
3
  import * as ui from 'datagrok-api/ui';
4
+ import * as grok from 'datagrok-api/grok';
3
5
 
4
6
  import {
5
7
  getSeriesStatistics,
@@ -59,33 +61,33 @@ const AGGREGATION_TYPES: {[key: string]: string} = {
59
61
 
60
62
 
61
63
  export function calculateSeriesStats(series: IFitSeries, seriesIdx: number, chartLogOptions: LogOptions,
62
- gridCell: DG.GridCell): FitStatistics {
64
+ tableCell: DG.Cell, useCache: boolean = true): FitStatistics {
63
65
  const fitFunction = getSeriesFitFunction(series);
64
66
  if (series.parameters) {
65
- if (chartLogOptions.logX)
67
+ if (chartLogOptions.logX) {
66
68
  if (series.parameters[2] > 0)
67
69
  series.parameters[2] = Math.log10(series.parameters[2]);
68
- }
69
- else {
70
- const params = getOrCreateCachedFitCurve(series, seriesIdx, fitFunction, chartLogOptions, gridCell).parameters;
70
+ }
71
+ } else {
72
+ const params = getOrCreateCachedFitCurve(series, seriesIdx, fitFunction, chartLogOptions, tableCell, useCache).parameters;
71
73
  series.parameters = [...params];
72
74
  }
73
75
 
74
76
  const seriesStatistics = getSeriesStatistics(series, fitFunction,
75
- getOrCreateCachedCurvesDataPoints(series, seriesIdx, chartLogOptions, false, gridCell), chartLogOptions);
77
+ getOrCreateCachedCurvesDataPoints(series, seriesIdx, chartLogOptions, false, tableCell), chartLogOptions);
76
78
  if ([FIT_FUNCTION_4PL_REGRESSION, FIT_FUNCTION_SIGMOID].includes(fitFunction.name) && chartLogOptions.logX && seriesStatistics.interceptX !== undefined && seriesStatistics.interceptX < 0)
77
79
  seriesStatistics.interceptX = Math.pow(10, seriesStatistics.interceptX);
78
80
  return seriesStatistics;
79
81
  }
80
82
 
81
- export function getChartDataAggrStats(chartData: IFitChartData, aggrType: string, gridCell: DG.GridCell): FitStatistics {
83
+ export function getChartDataAggrStats(chartData: IFitChartData, aggrType: string, tableCell: DG.Cell): FitStatistics {
82
84
  const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
83
- const rSquaredValues: number[] = [], aucValues: number[] = [], interceptXValues: number[] = [], interceptYValues: number[] = [],
84
- slopeValues: number[] = [], topValues: number[] = [], bottomValues: number[] = [];
85
+ const rSquaredValues: number[] = []; const aucValues: number[] = []; const interceptXValues: number[] = []; const interceptYValues: number[] = [];
86
+ const slopeValues: number[] = []; const topValues: number[] = []; const bottomValues: number[] = [];
85
87
  for (let i = 0, j = 0; i < chartData.series?.length!; i++) {
86
88
  if (chartData.series![i].points.every((p) => p.outlier))
87
89
  continue;
88
- const seriesStats = calculateSeriesStats(chartData.series![i], i, chartLogOptions, gridCell);
90
+ const seriesStats = calculateSeriesStats(chartData.series![i], i, chartLogOptions, tableCell);
89
91
  rSquaredValues[j] = seriesStats.rSquared!;
90
92
  aucValues[j] = seriesStats.auc!;
91
93
  interceptXValues[j] = seriesStats.interceptX!;
@@ -119,8 +121,7 @@ function changePlotOptions(chartData: IFitChartData, inputBase: DG.InputBase, op
119
121
  if (options === CHART_OPTIONS) {
120
122
  if (chartData.chartOptions === undefined) return;
121
123
  (chartData.chartOptions[propertyName as keyof IFitChartOptions] as any) = inputBase.value;
122
- }
123
- else if (options === SERIES_OPTIONS) {
124
+ } else if (options === SERIES_OPTIONS) {
124
125
  if (chartData.series === undefined) return;
125
126
  for (let i = 0; i < chartData.series.length; i++)
126
127
  (chartData.series[i][propertyName as keyof IFitSeries] as any) = inputBase.value;
@@ -187,14 +188,12 @@ function changeCurvesOptions(gridCell: DG.GridCell, inputBase: DG.InputBase, opt
187
188
  const chartData: IFitChartData = JSON.parse(value ?? '{}') ?? {};
188
189
  changePlotOptions(chartData, inputBase, options);
189
190
  gridCell.cell.value = JSON.stringify(chartData);
190
- }
191
- else {
191
+ } else {
192
192
  let columns: DG.Column[];
193
193
  if (manipulationLevel === MANIPULATION_LEVEL.DATAFRAME) {
194
194
  gridCell.cell.dataFrame.tags[FitConstants.TAG_FIT] = JSON.stringify(chartOptions);
195
195
  columns = gridCell.cell.dataFrame.columns.bySemTypeAll(FitConstants.FIT_SEM_TYPE);
196
- }
197
- else {
196
+ } else {
198
197
  gridCell.cell.column.tags[FitConstants.TAG_FIT] = JSON.stringify(chartOptions);
199
198
  columns = [gridCell.cell.column];
200
199
  }
@@ -217,15 +216,15 @@ function changeCurvesOptions(gridCell: DG.GridCell, inputBase: DG.InputBase, opt
217
216
  if (chartData.chartOptions[propertyName as keyof IFitChartOptions] === undefined)
218
217
  return value;
219
218
  delete chartData.chartOptions[propertyName as keyof IFitChartOptions];
220
- }
221
- else {
219
+ } else {
222
220
  if (chartData.series === undefined) return value;
223
221
  let isSeriesChanged = false;
224
- for (const series of chartData.series)
222
+ for (const series of chartData.series) {
225
223
  if (series[propertyName as keyof IFitSeriesOptions] !== undefined) {
226
224
  delete series[propertyName as keyof IFitSeriesOptions];
227
225
  isSeriesChanged = true;
228
226
  }
227
+ }
229
228
  if (chartData.seriesOptions)
230
229
  delete chartData.seriesOptions[propertyName as keyof IFitSeriesOptions];
231
230
  if (!isSeriesChanged) return value;
@@ -253,7 +252,7 @@ export class FitGridCellHandler extends DG.ObjectHandler {
253
252
  // TODO: add the table for the values on the cell or don't render it at all
254
253
  // TODO: fix the curves demo app
255
254
 
256
- renderProperties(gridCell: DG.GridCell, context: any = null): HTMLElement {
255
+ renderProperties(gridCell: DG.GridCell, _context: any = null): HTMLElement {
257
256
  const acc = ui.accordion('Curves property panel');
258
257
  // TODO: make just the base ui.input.choice after nullable option is added
259
258
  const switchProperty = DG.Property.js('level', DG.TYPE.STRING, {description: 'Controls the level at which properties will be switched',
@@ -263,7 +262,7 @@ export class FitGridCellHandler extends DG.ObjectHandler {
263
262
  // temporarily because input doesn't show the tooltip
264
263
  ui.tooltip.bind(switchLevelInput.captionLabel, 'Controls the level at which properties will be switched');
265
264
 
266
- const chartData = getOrCreateParsedChartData(gridCell);
265
+ const chartData = getOrCreateParsedChartData(gridCell.cell);
267
266
  const columnChartOptions = getColumnChartOptions(gridCell.cell.column);
268
267
  const dfChartOptions = getDataFrameChartOptions(gridCell.cell.dataFrame);
269
268
 
@@ -276,18 +275,19 @@ export class FitGridCellHandler extends DG.ObjectHandler {
276
275
  if (dfChartOptions.seriesOptions && !isColorValid(dfChartOptions.seriesOptions[colorFieldName]) &&
277
276
  columnChartOptions.seriesOptions && !isColorValid(columnChartOptions.seriesOptions[colorFieldName])) {
278
277
  if (chartData.seriesOptions) {
279
- if (!isColorValid(chartData.seriesOptions[colorFieldName]))
278
+ if (!isColorValid(chartData.seriesOptions[colorFieldName])) {
280
279
  chartData.seriesOptions[colorFieldName] = DG.Color.toHtml(colorFieldName === 'outlierColor' ?
281
280
  DG.Color.red : DG.Color.getCategoricalColor(0));
282
- }
283
- else {
284
- if (!isColorValid(chartData.series ? chartData.series[0][colorFieldName] : ''))
285
- chartData.series![0][colorFieldName] = DG.Color.toHtml(colorFieldName === 'outlierColor' ?
286
- DG.Color.red : DG.Color.getCategoricalColor(0));
281
+ }
282
+ } else {
283
+ if (!isColorValid(chartData.series ? chartData.series[0][colorFieldName] : '')) {
284
+ chartData.series![0][colorFieldName] = DG.Color.toHtml(colorFieldName === 'outlierColor' ?
285
+ DG.Color.red : DG.Color.getCategoricalColor(0));
286
+ }
287
287
  }
288
288
  }
289
- }
290
-
289
+ };
290
+ const tableCell = gridCell.cell;
291
291
  setValidColors('pointColor');
292
292
  setValidColors('fitLineColor');
293
293
  setValidColors('outlierColor');
@@ -337,7 +337,7 @@ export class FitGridCellHandler extends DG.ObjectHandler {
337
337
  const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
338
338
  for (let i = 0; i < chartData.series!.length; i++) {
339
339
  const series = chartData.series![i];
340
- const seriesStatistics = calculateSeriesStats(series, i, chartLogOptions, gridCell);
340
+ const seriesStatistics = calculateSeriesStats(series, i, chartLogOptions, tableCell);
341
341
 
342
342
  const color = getSeriesColor(series, i, ColorType.FIT_LINE);
343
343
  const seriesName = series.name ?? 'series ' + i;
@@ -345,24 +345,28 @@ export class FitGridCellHandler extends DG.ObjectHandler {
345
345
  ui.h1(seriesName, {style: {color: color}}),
346
346
  ui.input.form(seriesStatistics, statisticsProperties, {
347
347
  onCreated: (input) => input.root.appendChild(ui.iconFA('plus', async () => {
348
- const funcParams = {df: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, seriesName: seriesName, seriesNumber: i};
349
- await DG.Func.find({name: 'addStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false});
350
- }, `Calculate ${input.property.name} for the whole column`))
348
+ const funcParams = {table: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, seriesNumber: i};
349
+ await DG.Func.find({name: 'addStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false});
350
+ }, `Calculate ${input.property.name} for the whole column`))
351
+
352
+ // TODO: Replace with this one after dima merges his branch
353
+ // const newName = gridCell.cell.dataFrame.columns.getUnusedName(`${gridCell.gridColumn.name} ${seriesName} ${input.property.name}`);
354
+ // await gridCell.cell.dataFrame.columns.addNewCalculated(newName, `Curves:addStatisticsColumn("table", \$\{${gridCell.gridColumn.name}\}, "${input.property.name}", ${i})`, undefined, undefined, false);
355
+ // }, `Calculate ${input.property.name} for the whole column`))
351
356
  })
352
357
  ]));
353
358
  }
354
- }
355
- else {
356
- const seriesStatistics = getChartDataAggrStats(chartData, aggrTypeInput.stringValue, gridCell);
359
+ } else {
360
+ const seriesStatistics = getChartDataAggrStats(chartData, aggrTypeInput.stringValue, tableCell);
357
361
  host.appendChild(ui.panel([
358
- ui.h1(`series ${aggrTypeInput.stringValue}`),
359
- ui.input.form(seriesStatistics, statisticsProperties, {
360
- onCreated: (input) => input.root.appendChild(ui.iconFA('plus', async () => {
361
- const funcParams = {df: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, aggrType: aggrTypeInput.stringValue};
362
- await DG.Func.find({name: 'addAggrStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false});
363
- }, `Calculate ${input.property.name} ${aggrTypeInput.stringValue} for the whole column`))
364
- })
365
- ]));
362
+ ui.h1(`series ${aggrTypeInput.stringValue}`),
363
+ ui.input.form(seriesStatistics, statisticsProperties, {
364
+ onCreated: (input) => input.root.appendChild(ui.iconFA('plus', async () => {
365
+ const funcParams = {table: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, aggrType: aggrTypeInput.stringValue};
366
+ await DG.Func.find({name: 'addAggrStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false});
367
+ }, `Calculate ${input.property.name} ${aggrTypeInput.stringValue} for the whole column`))
368
+ })
369
+ ]));
366
370
  }
367
371
 
368
372
  return host;
@@ -1,3 +1,4 @@
1
+ /* eslint-disable max-len */
1
2
  import * as DG from 'datagrok-api/dg';
2
3
  import * as grok from 'datagrok-api/grok';
3
4
  import * as ui from 'datagrok-api/ui';
@@ -5,9 +6,9 @@ import * as ui from 'datagrok-api/ui';
5
6
  import {
6
7
  IFitChartData,
7
8
  IFitSeries,
8
- FitStatistics,
9
9
  fitChartDataProperties,
10
10
  fitSeriesProperties, IFitChartOptions, IFitPoint, FitCurve, FitFunction,
11
+ FitStatistics,
11
12
  } from '@datagrok-libraries/statistics/src/fit/fit-curve';
12
13
  import {Viewport} from '@datagrok-libraries/utils/src/transform';
13
14
 
@@ -21,7 +22,6 @@ import {
21
22
  } from '@datagrok-libraries/statistics/src/fit/fit-data';
22
23
 
23
24
  import {convertXMLToIFitChartData} from './fit-parser';
24
- import { calculateSeriesStats, getChartDataAggrStats } from './fit-grid-cell-handler';
25
25
  import {FitConstants} from './const';
26
26
  import {
27
27
  renderAxesLabels,
@@ -31,6 +31,7 @@ import {
31
31
  renderPoints, renderStatistics, renderTitle
32
32
  } from './render-utils';
33
33
  import {merge} from 'rxjs';
34
+ import {calculateSeriesStats, getChartDataAggrStats} from './fit-grid-cell-handler';
34
35
 
35
36
 
36
37
  export interface FitCellOutlierToggleArgs {
@@ -46,7 +47,7 @@ function clamp(value: number, min: number, max: number): number {
46
47
 
47
48
  function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect): void {
48
49
  DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER, screenBounds.midX, screenBounds.midY, DG.Color.red,
49
- clamp(Math.min(screenBounds.width, screenBounds.height) * 0.8,0, 30));
50
+ clamp(Math.min(screenBounds.width, screenBounds.height) * 0.8, 0, 30));
50
51
  }
51
52
 
52
53
  /** Merges properties of the two objects by iterating over the specified {@link properties}
@@ -142,30 +143,30 @@ export function mergeSeries(series: IFitSeries[]): IFitSeries | null {
142
143
  return mergedSeries;
143
144
  }
144
145
 
145
- /** Returns either cached or constructed chart data for the specified grid cell. */
146
- export function getOrCreateParsedChartData(gridCell: DG.GridCell, useCache = true): IFitChartData {
147
- const column = gridCell?.cell?.column;
148
- return (useCache && column && gridCell?.cell) ?
149
- FitChartCellRenderer.parsedCurves.getOrCreate(`tableId: ${column.dataFrame.id} || tableName: ${column.dataFrame.name} || colName: ${column.name} || colVersion: ${column.version} || rowIdx: ${gridCell?.tableRowIndex}`, () => {
150
- return getChartData(gridCell);
151
- }) : getChartData(gridCell);
146
+ /** Returns either cached or constructed chart data for the specified table cell. */
147
+ export function getOrCreateParsedChartData(tableCell: DG.Cell, useCache = true): IFitChartData {
148
+ const column = tableCell?.column;
149
+ return (useCache && column && tableCell) ?
150
+ FitChartCellRenderer.parsedCurves.getOrCreate(`tableId: ${column.dataFrame.id} || tableName: ${column.dataFrame.name} || colName: ${column.name} || colVersion: ${column.version} || rowIdx: ${tableCell?.rowIndex}`, () => {
151
+ return getChartData(tableCell);
152
+ }) : getChartData(tableCell);
152
153
  }
153
154
 
154
- /** Constructs {@link IFitChartData} from the grid cell, taking into account
155
+ /** Constructs {@link IFitChartData} from the table cell, taking into account
155
156
  * chart and fit settings potentially defined on the dataframe and column level. */
156
- function getChartData(gridCell: DG.GridCell): IFitChartData {
157
+ function getChartData(tableCell: DG.Cell): IFitChartData {
157
158
  // removing '|' from JSON (how did it get here?)
158
- let cellValue = gridCell.cell.value as string;
159
+ let cellValue = tableCell.value as string;
159
160
  if (cellValue.includes('|'))
160
161
  cellValue = cellValue.replaceAll('|', '');
161
- const column = gridCell.cell.column;
162
+ const column = tableCell.column;
162
163
  const cellChartData: IFitChartData = column ? (column.type === DG.TYPE.STRING ?
163
164
  (column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
164
165
  convertXMLToIFitChartData(cellValue) : JSON.parse(cellValue ?? '{}') ?? {}) :
165
166
  createDefaultChartData()) : JSON.parse(cellValue ?? '{}') ?? {};
166
167
 
167
- const columnChartOptions = gridCell.cell.column ? getColumnChartOptions(gridCell.cell.column) : {};
168
- const dfChartOptions = gridCell.cell.column ? getDataFrameChartOptions(gridCell.cell.dataFrame) : {};
168
+ const columnChartOptions = tableCell.column ? getColumnChartOptions(tableCell.column) : {};
169
+ const dfChartOptions = tableCell.column ? getDataFrameChartOptions(tableCell.dataFrame) : {};
169
170
 
170
171
  cellChartData.series ??= [];
171
172
  cellChartData.chartOptions ??= columnChartOptions.chartOptions;
@@ -184,22 +185,22 @@ function getChartData(gridCell: DG.GridCell): IFitChartData {
184
185
 
185
186
  /** Returns existing, or fits curve for the specified grid cell and series. */
186
187
  export function getOrCreateCachedFitCurve(series: IFitSeries, seriesIdx: number, fitFunc: FitFunction,
187
- chartLogOptions: LogOptions, gridCell?: DG.GridCell, useCache = true): FitCurve {
188
- const dataPoints = getOrCreateCachedCurvesDataPoints(series, seriesIdx, chartLogOptions, false, gridCell, useCache);
188
+ chartLogOptions: LogOptions, tableCell?: DG.Cell, useCache = true): FitCurve {
189
+ const dataPoints = getOrCreateCachedCurvesDataPoints(series, seriesIdx, chartLogOptions, false, tableCell, useCache);
189
190
  // don't refit when just rerender - using LruCache with key `cellValue_colName_colVersion`
190
- const column = gridCell?.cell?.column;
191
- return (useCache && column && gridCell?.cell) ?
192
- FitChartCellRenderer.fittedCurves.getOrCreate(`tableId: ${column.dataFrame.id} || tableName: ${column.dataFrame.name} || colName: ${column.name} || colVersion: ${column.version} || rowIdx: ${gridCell?.tableRowIndex}`, () => {
191
+ const column = tableCell?.column;
192
+ return (useCache && column && tableCell) ?
193
+ FitChartCellRenderer.fittedCurves.getOrCreate(`tableId: ${column.dataFrame.id} || tableName: ${column.dataFrame.name} || colName: ${column.name} || colVersion: ${column.version} || rowIdx: ${tableCell.rowIndex} || idx: ${seriesIdx}`, () => {
193
194
  return fitSeries(series, fitFunc, dataPoints, chartLogOptions);
194
195
  }) : fitSeries(series, fitFunc, dataPoints, chartLogOptions);
195
196
  }
196
197
 
197
198
  /** Returns existing, or maps new data points for the specified series. */
198
199
  export function getOrCreateCachedCurvesDataPoints(series: IFitSeries, idx: number, logOptions?: LogOptions,
199
- userParamsFlag?: boolean, gridCell?: DG.GridCell, useCache = true): {x: number[], y: number[]} {
200
- const column = gridCell?.cell?.column;
201
- return (useCache && column && gridCell?.cell) ?
202
- FitChartCellRenderer.curvesDataPoints.getOrCreate(`tableId: ${column.dataFrame.id} || tableName: ${column.dataFrame.name} || colName: ${column.name} || colVersion: ${column.version} || rowIdx: ${gridCell?.tableRowIndex} || idx: ${idx} || userParamsFlag: ${userParamsFlag}`, () => {
200
+ userParamsFlag?: boolean, tableCell?: DG.Cell, useCache = true): {x: number[], y: number[]} {
201
+ const column = tableCell?.column;
202
+ return (useCache && column && tableCell) ?
203
+ FitChartCellRenderer.curvesDataPoints.getOrCreate(`tableId: ${column.dataFrame.id} || tableName: ${column.dataFrame.name} || colName: ${column.name} || colVersion: ${column.version} || rowIdx: ${tableCell.rowIndex} || idx: ${idx} || userParamsFlag: ${userParamsFlag}`, () => {
203
204
  return getDataPoints(series, logOptions, userParamsFlag);
204
205
  }) : getDataPoints(series, logOptions, userParamsFlag);
205
206
  }
@@ -263,34 +264,34 @@ export function substituteZeroes(data: IFitChartData): void {
263
264
  }
264
265
  }
265
266
 
266
- export function setOutlier(gridCell: DG.GridCell, p: IFitPoint, seriesIdx: number, pointIdx: number, data?: IFitChartData) {
267
- data ??= gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
268
- convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell);
267
+ export function setOutlier(gridCell: DG.GridCell, p: IFitPoint, seriesIdx: number, pointIdx: number, _data?: IFitChartData) {
269
268
  p.outlier = !p.outlier;
270
269
  // temporarily works only for JSON structure
271
270
  if (gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) !== FitConstants.TAG_FIT_CHART_FORMAT_3DX) {
272
271
  const gridCellValue = JSON.parse(gridCell.cell.value) as IFitChartData;
273
272
  gridCellValue.series![seriesIdx].points[pointIdx].outlier = p.outlier;
274
- gridCell.cell.column.set(gridCell.cell.rowIndex, JSON.stringify(gridCellValue), false);
273
+ gridCell.cell.column.set(gridCell.cell.rowIndex, JSON.stringify(gridCellValue), true);
275
274
  grok.events.fireCustomEvent('fit-cell-outlier-toggle', {
276
275
  gridCell: gridCell,
277
276
  series: gridCellValue.series![seriesIdx],
278
277
  seriesIdx: seriesIdx,
279
278
  pointIdx: pointIdx,
280
279
  });
281
- const g = gridCell.grid.canvas.getContext('2d')!;
282
- gridCell.render({context: g, bounds: gridCell.bounds});
280
+ // const g = gridCell.grid.canvas.getContext('2d')!;
281
+ // gridCell.render({context: g, bounds: gridCell.bounds});
283
282
  }
284
283
  const columns = gridCell.grid.dataFrame.columns.byTags({'.sourceColumn': gridCell.cell.column.name});
285
284
  if (columns) {
285
+ _data ??= gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
286
+ convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell);
286
287
  for (const column of columns) {
287
- const chartLogOptions: LogOptions = {logX: data.chartOptions?.logX, logY: data.chartOptions?.logY};
288
+ const chartLogOptions: LogOptions = {logX: _data.chartOptions?.logX, logY: _data.chartOptions?.logY};
288
289
  const stats = column.tags['.seriesAggregation'] !== null ?
289
- getChartDataAggrStats(data, column.tags['.seriesAggregation'], gridCell) :
290
- column.tags['.seriesNumber'] === seriesIdx ? calculateSeriesStats(data.series![seriesIdx], seriesIdx, chartLogOptions, gridCell) : null;
290
+ getChartDataAggrStats(_data, column.tags['.seriesAggregation'], gridCell.cell) :
291
+ column.tags['.seriesNumber'] === seriesIdx.toString() ? calculateSeriesStats(_data.series![seriesIdx], seriesIdx, chartLogOptions, gridCell.cell) : null;
291
292
  if (stats === null)
292
293
  continue;
293
- column.set(gridCell.cell.rowIndex, stats[column.tags['.statistics'] as keyof FitStatistics]);
294
+ column.set(gridCell.cell.rowIndex, stats[column.tags['.statistics'] as unknown as keyof FitStatistics]);
294
295
  }
295
296
  }
296
297
  }
@@ -309,7 +310,7 @@ export function inspectCurve(gridCell: DG.GridCell, size?: Partial<DG.Size>, rer
309
310
 
310
311
  const dlg = ui.dialog({title: 'Edit chart'})
311
312
  .add(gridCellWidget.root)
312
- .show({resizable: true, width: size?.width ?? 350, height: size?.height ?? 300});
313
+ .show({resizable: true, width: size?.width ?? 500, height: size?.height ?? 430});
313
314
  if (rerenderOnChange)
314
315
  dlg.sub(merge(gridCell.grid.dataFrame.onDataChanged, gridCell.grid.dataFrame.onMetadataChanged).subscribe(() => gridCellWidget.render()));
315
316
  }
@@ -328,7 +329,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
328
329
 
329
330
  get defaultWidth() { return FitConstants.CELL_DEFAULT_WIDTH; }
330
331
 
331
- getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
332
+ getDefaultSize(_gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
332
333
  return {width: FitConstants.CELL_DEFAULT_WIDTH, height: FitConstants.CELL_DEFAULT_HEIGHT};
333
334
  }
334
335
 
@@ -346,7 +347,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
346
347
  return;
347
348
 
348
349
  const data = gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
349
- convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell);
350
+ convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, false);
350
351
 
351
352
  for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
352
353
  if (condition(data.series)) {
@@ -377,7 +378,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
377
378
  }
378
379
  }
379
380
 
380
- onDoubleClick(gridCell: DG.GridCell, e: MouseEvent): void {
381
+ onDoubleClick(gridCell: DG.GridCell, _e: MouseEvent): void {
381
382
  inspectCurve(gridCell);
382
383
  }
383
384
 
@@ -410,7 +411,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
410
411
  g.clip();
411
412
 
412
413
  const isRenderedOnGrid = gridCell?.grid && gridCell?.grid.dart && g.canvas === gridCell?.grid?.canvas; // only use cache for grid, because there is no guarantee that rowIdx will be correct for other places
413
-
414
+ const tableCell = gridCell?.cell;
414
415
  if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX &&
415
416
  data.series?.some((series) => series.points.some((p) => p.x === 0)))
416
417
  substituteZeroes(data);
@@ -450,11 +451,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
450
451
  series.parameters[2] = Math.log10(series.parameters[2]);
451
452
  }
452
453
  curve = getCurve(series, fitFunc);
453
- }
454
- else {
455
- const fitResult = getOrCreateCachedFitCurve(series, i, fitFunc, chartLogOptions, gridCell, isRenderedOnGrid);
454
+ } else {
455
+ const fitResult = getOrCreateCachedFitCurve(series, i, fitFunc, chartLogOptions, tableCell, isRenderedOnGrid);
456
456
  curve = fitResult.fittedCurve;
457
- const params = [...fitResult.parameters]
457
+ const params = [...fitResult.parameters];
458
458
  series.parameters = params;
459
459
  userParamsFlag = false;
460
460
  }
@@ -466,10 +466,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
466
466
  renderPoints(g, series, {viewport, ratio, screenBounds, seriesIdx: i});
467
467
  renderConfidenceIntervals(g, series, {viewport, logOptions: chartLogOptions, showAxes: this.areAxesShown(screenBounds),
468
468
  showAxesLabels: this.areAxesLabelsShown(screenBounds, data), screenBounds, fitFunc, userParamsFlag,
469
- dataPoints: getOrCreateCachedCurvesDataPoints(series, i, chartLogOptions, userParamsFlag, gridCell, isRenderedOnGrid)});
470
- if (series.parameters)
469
+ dataPoints: getOrCreateCachedCurvesDataPoints(series, i, chartLogOptions, userParamsFlag, tableCell, isRenderedOnGrid)});
470
+ if (series.parameters) {
471
471
  renderDroplines(g, series, {viewport, ratio, showDroplines: this.areDroplinesShown(screenBounds),
472
472
  xValue: series.parameters![2], dataBounds, curveFunc: curve!, logOptions: chartLogOptions});
473
+ }
473
474
  renderStatistics(g, series, {statistics: data.chartOptions?.showStatistics, fitFunc,
474
475
  logOptions: chartLogOptions, dataBox, screenBounds, seriesIdx: i});
475
476
  if (!containsParams)
@@ -488,8 +489,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
488
489
  // TODO: Curves: make less margins in the right, also in the left
489
490
  // TODO: Curves: add a warning or error in top right if some mistakes in data
490
491
  render(g: CanvasRenderingContext2D,
491
- x: number, y: number, w: number, h: number,
492
- gridCell: DG.GridCell, cellStyle: DG.GridCellStyle): void {
492
+ x: number, y: number, w: number, h: number,
493
+ gridCell: DG.GridCell, _cellStyle: DG.GridCellStyle): void {
493
494
  if (!gridCell.cell.value)
494
495
  return;
495
496
  if (w < FitConstants.MIN_CELL_RENDERER_PX_WIDTH || h < FitConstants.MIN_CELL_RENDERER_PX_HEIGHT)
@@ -497,10 +498,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
497
498
 
498
499
  const isRenderedOnGrid = gridCell?.grid && gridCell?.grid.dart && g.canvas === gridCell?.grid?.canvas; // only use cache for grid, because there is no guarantee that rowIdx will be correct for other places
499
500
  const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
500
- convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell, isRenderedOnGrid);
501
+ convertXMLToIFitChartData(gridCell.cell.value) : getOrCreateParsedChartData(gridCell.cell, isRenderedOnGrid);
501
502
  const screenBounds = FitChartCellRenderer.inflateScreenBounds(new DG.Rect(x, y, w, h));
502
503
 
503
- for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
504
+ for (const [_message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
504
505
  if (condition(data.series)) {
505
506
  showIncorrectFitCell(g, screenBounds);
506
507
  return;
@@ -526,7 +527,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
526
527
  }
527
528
 
528
529
  onMouseMove(gridCell: DG.GridCell, e: MouseEvent): void {
529
- if (!gridCell.cell.value)
530
+ if (!gridCell?.cell?.value)
530
531
  return;
531
532
 
532
533
  const screenBounds = FitChartCellRenderer.inflateScreenBounds(gridCell.bounds);
@@ -539,9 +540,9 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
539
540
  }
540
541
 
541
542
  // TODO: add caching
542
- const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX
543
- ? convertXMLToIFitChartData(gridCell.cell.value)
544
- : getOrCreateParsedChartData(gridCell);
543
+ const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
544
+ convertXMLToIFitChartData(gridCell.cell.value) :
545
+ getOrCreateParsedChartData(gridCell?.cell);
545
546
 
546
547
  if (screenBounds.width >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH &&
547
548
  screenBounds.height >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
@@ -570,7 +571,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
570
571
  }
571
572
  }
572
573
 
573
- const sample: IFitChartData = {
574
+ const _sample: IFitChartData = {
574
575
  // chartOptions could be retrieved either from the column, or from the cell
575
576
  'chartOptions': {
576
577
  'minX': 0, 'minY': 0, 'maxX': 5, 'maxY': 10,
@@ -1,3 +1,4 @@
1
+ /* eslint-disable max-len */
1
2
  import * as DG from 'datagrok-api/dg';
2
3
  import * as ui from 'datagrok-api/ui';
3
4
  import * as grok from 'datagrok-api/grok';
@@ -17,6 +18,7 @@ const ERROR_CLASS = 'd4-viewer-error';
17
18
  name: 'MultiCurveViewer',
18
19
  description: 'A viewer that superimposes multiple in-cell curves on one chart',
19
20
  icon: 'icons/multi-curve-viewer.png',
21
+ trellisable: true
20
22
  })
21
23
  export class MultiCurveViewer extends DG.JsViewer {
22
24
  [index: string]: any;
@@ -35,6 +37,20 @@ export class MultiCurveViewer extends DG.JsViewer {
35
37
  mergeCellSeries?: boolean;
36
38
  showColumnLabel?: boolean;
37
39
 
40
+
41
+ private isInTrellis(): boolean {
42
+ let curRoot = this.root;
43
+ let i = 0;
44
+ const maxDepth = 7;
45
+ while (curRoot && i < maxDepth) {
46
+ if (curRoot.classList.contains('d4-trellis-plot-cell'))
47
+ return true;
48
+ curRoot = curRoot.parentElement!;
49
+ i++;
50
+ }
51
+ return false;
52
+ }
53
+
38
54
  constructor() {
39
55
  super();
40
56
  this.gridCellWidget = DG.GridCellWidget.fromGridCell(this.createGridCell(''));
@@ -48,7 +64,7 @@ export class MultiCurveViewer extends DG.JsViewer {
48
64
 
49
65
  this.curvesColumnNames = this.addProperty('curvesColumnNames', DG.TYPE.COLUMN_LIST, [], {semType: FitConstants.FIT_SEM_TYPE});
50
66
 
51
- this.showSelectedRowsCurves = this.bool('showSelectedRowsCurves', false, { description: 'Adds curves from the selected rows'});
67
+ this.showSelectedRowsCurves = this.bool('showSelectedRowsCurves', false, {description: 'Adds curves from the selected rows'});
52
68
  this.showCurrentRowCurve = this.bool('showCurrentRowCurve', true);
53
69
  this.showMouseOverRowCurve = this.bool('showMouseOverRowCurve', true);
54
70
  this.mergeColumnSeries = this.bool('mergeColumnSeries', false);
@@ -58,7 +74,7 @@ export class MultiCurveViewer extends DG.JsViewer {
58
74
  }
59
75
 
60
76
  static fromChartData(chartData: IFitChartData): MultiCurveViewer {
61
- let viewer = new MultiCurveViewer();
77
+ const viewer = new MultiCurveViewer();
62
78
  viewer.data = chartData;
63
79
  viewer.render();
64
80
  return viewer;
@@ -95,27 +111,29 @@ export class MultiCurveViewer extends DG.JsViewer {
95
111
  return;
96
112
  this.rows.length = 0;
97
113
  let selectionStart = -1;
98
- if (this.showCurrentRowCurve && this.dataFrame.currentRowIdx !== -1)
99
- this.rows.push(this.dataFrame.currentRowIdx);
100
- if (this.showMouseOverRowCurve && this.dataFrame.mouseOverRowIdx !== -1)
101
- this.rows.push(this.dataFrame.mouseOverRowIdx);
102
- if (this.showSelectedRowsCurves && this.dataFrame.mouseOverRowIdx !== -1) {
103
- selectionStart = this.rows.length;
104
- this.rows.push(...this.dataFrame.selection.getSelectedIndexes());
114
+ if (this.isInTrellis()) { this.rows.push(...this.dataFrame.filter.getSelectedIndexes()); } else {
115
+ if (this.showCurrentRowCurve && this.dataFrame.currentRowIdx !== -1)
116
+ this.rows.push(this.dataFrame.currentRowIdx);
117
+ if (this.showMouseOverRowCurve && this.dataFrame.mouseOverRowIdx !== -1)
118
+ this.rows.push(this.dataFrame.mouseOverRowIdx);
119
+ if (this.showSelectedRowsCurves) {
120
+ selectionStart = this.rows.length;
121
+ this.rows.push(...this.dataFrame.selection.getSelectedIndexes());
122
+ }
105
123
  }
106
124
 
107
125
  this.data = new FitChartData();
108
- const grid = this.tableView?.grid!;
126
+ //const _grid = this.isInTrellis() ? grok.shell.tableView(this.dataFrame.name).grid : this.tableView?.grid!;
109
127
  const mergeCellSeries = this.props.get('mergeCellSeries') as unknown as boolean;
110
128
  const chartOptions: IFitChartOptions[] = [];
111
129
  for (const colName of this.curvesColumnNames!) {
112
130
  const series = [];
113
131
  for (const i of new Set(this.rows)) {
114
- const gridCell = grid.cell(colName, grid.tableRowToGrid(i));
115
- if (gridCell.cell.value === '')
132
+ const tableCell = this.dataFrame.cell(i, colName);
133
+ if (!tableCell || !tableCell.value)
116
134
  continue;
117
- const cellCurves = getOrCreateParsedChartData(gridCell);
118
- cellCurves.series?.forEach((series) => series.columnName = gridCell.cell.column.name);
135
+ const cellCurves = getOrCreateParsedChartData(tableCell);
136
+ cellCurves.series?.forEach((series) => series.columnName = tableCell.column.name);
119
137
  const currentChartOptions = cellCurves.chartOptions;
120
138
  if (currentChartOptions !== undefined && currentChartOptions !== null)
121
139
  chartOptions[chartOptions.length] = currentChartOptions;
@@ -168,14 +186,16 @@ export class MultiCurveViewer extends DG.JsViewer {
168
186
  if (fitCol !== null)
169
187
  this.curvesColumnNames = [fitCol.name];
170
188
 
171
- merge(this.dataFrame.onCurrentCellChanged, grid.onCellMouseEnter, this.dataFrame.onSelectionChanged)
172
- .pipe(debounce(_ => interval(50)))
173
- .subscribe(_ => {
189
+ merge(...[this.dataFrame.onCurrentCellChanged, ...(grid ? [grid.onCellMouseEnter] : []), this.dataFrame.onSelectionChanged])
190
+ .pipe(debounce((_) => interval(50)))
191
+ .subscribe((_) => {
174
192
  if (this.dataFrame) {
175
193
  this.createChartData();
176
194
  this.render();
177
195
  }
178
196
  });
197
+ if (this.isInTrellis())
198
+ this.createChartData();
179
199
  }
180
200
 
181
201
  _showErrorMessage(msg: string) {
@@ -189,7 +209,7 @@ export class MultiCurveViewer extends DG.JsViewer {
189
209
  }
190
210
 
191
211
  render(): void {
192
- const g = this.canvas.getContext('2d')!
212
+ const g = this.canvas.getContext('2d')!;
193
213
  g.clearRect(0, 0, this.canvas.width, this.canvas.height);
194
214
  this._removeErrorMessage();
195
215