@datagrok/curves 1.2.14 → 1.2.15

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,14 +1,14 @@
1
1
  {
2
2
  "name": "@datagrok/curves",
3
3
  "friendlyName": "Curves",
4
- "version": "1.2.14",
4
+ "version": "1.2.15",
5
5
  "description": "Curves provides support for fitted curves (such as dose-response curves), including in-grid rendering, storing charts in cells, interactivity, and automatic fitting.",
6
6
  "author": {
7
7
  "name": "Dmytro Kovalyov",
8
8
  "email": "dkovalyov@datagrok.ai"
9
9
  },
10
10
  "dependencies": {
11
- "@datagrok-libraries/statistics": "^1.2.10",
11
+ "@datagrok-libraries/statistics": "^1.2.11",
12
12
  "@datagrok-libraries/utils": "^4.1.0",
13
13
  "@types/wu": "^2.1.42",
14
14
  "cash-dom": "latest",
@@ -89,10 +89,14 @@ export function mergeProperties(properties: DG.Property[], source: any, target:
89
89
  /** Constructs {@link IFitChartData} from the grid cell, taking into account
90
90
  * chart and fit settings potentially defined on the dataframe and column level. */
91
91
  export function getChartData(gridCell: DG.GridCell): IFitChartData {
92
+ // removing '|' from JSON (how did it get here?)
93
+ let cellValue = gridCell.cell.value as string;
94
+ if (cellValue.includes('|'))
95
+ cellValue = cellValue.replaceAll('|', '');
92
96
  const cellChartData: IFitChartData = gridCell.cell?.column?.type === DG.TYPE.STRING ?
93
97
  (gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
94
- convertXMLToIFitChartData(gridCell.cell.value) :
95
- JSON.parse(gridCell.cell.value ?? '{}') ?? {}) : createDefaultChartData();
98
+ convertXMLToIFitChartData(cellValue) :
99
+ JSON.parse(cellValue ?? '{}') ?? {}) : createDefaultChartData();
96
100
 
97
101
  const columnChartOptions = gridCell.cell.column ? getColumnChartOptions(gridCell.cell.column) : {};
98
102
  const dfChartOptions = gridCell.cell.column ? getDataFrameChartOptions(gridCell.cell.dataFrame) : {};
@@ -269,6 +273,34 @@ function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue:
269
273
  g.lineTo(transform.xToScreen(xValue), transform.yToScreen(dataBounds.minY));
270
274
  }
271
275
 
276
+ /** Performs x zeroes substitution if log x */
277
+ function substituteZeroes(data: IFitChartData): void {
278
+ for (let i = 0; i < data.series?.length!; i++) {
279
+ const series = data.series![i];
280
+ if (series.points.every((p) => p.x !== 0))
281
+ continue;
282
+ let minNonZeroX = Number.MAX_VALUE;
283
+ let maxNonZeroX = 0;
284
+ let countOfDistNonZeroX = 0;
285
+ const uniqueArr: number[] = [];
286
+ for (let j = 0; j < series.points.length; j++) {
287
+ if (series.points[j].x < minNonZeroX && series.points[j].x !== 0)
288
+ minNonZeroX = series.points[j].x;
289
+ if (series.points[j].x > maxNonZeroX && series.points[j].x !== 0)
290
+ maxNonZeroX = series.points[j].x;
291
+ if (!uniqueArr.includes(series.points[j].x)) {
292
+ uniqueArr[uniqueArr.length] = series.points[j].x;
293
+ countOfDistNonZeroX++;
294
+ }
295
+ }
296
+ const zeroSubstitute = Math.pow(10, Math.log10(minNonZeroX) - (Math.log10(maxNonZeroX) - Math.log10(minNonZeroX) / (countOfDistNonZeroX - 1)));
297
+ for (let j = 0; j < series.points.length; j++) {
298
+ if (series.points[j].x === 0)
299
+ series.points[j].x = zeroSubstitute;
300
+ }
301
+ }
302
+ }
303
+
272
304
  export class FitChartCellRenderer extends DG.GridCellRenderer {
273
305
  get name() { return FIT_CELL_TYPE; }
274
306
 
@@ -367,6 +399,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
367
399
  g.rect(x, y, w, h);
368
400
  g.clip();
369
401
 
402
+ if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX && data.series?.some((series) => series.points.some((p) => p.x === 0)))
403
+ substituteZeroes(data);
370
404
  const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
371
405
  const showAxes = screenBounds.width >= MIN_AXES_CELL_PX_WIDTH && screenBounds.height >= MIN_AXES_CELL_PX_HEIGHT;
372
406
  // TODO: make bigger sizes
@@ -377,7 +411,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
377
411
  const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxesLabels, showTitle);
378
412
 
379
413
  const dataBounds = getChartBounds(data);
380
- if (dataBounds.x <= 0 && data.chartOptions) data.chartOptions.logX = false;
414
+ if ((dataBounds.x < 0 && data.chartOptions) || (dataBounds.x === 0 && data.chartOptions && !data.chartOptions.allowXZeroes))
415
+ data.chartOptions.logX = false;
381
416
  if (dataBounds.y <= 0 && data.chartOptions) data.chartOptions.logY = false;
382
417
  const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
383
418
  const minSize = Math.min(dataBox.width, dataBox.height);
@@ -1,4 +1,5 @@
1
1
  import * as DG from 'datagrok-api/dg';
2
+ import * as ui from 'datagrok-api/ui';
2
3
 
3
4
  import {CellRenderViewer} from './cell-render-viewer';
4
5
  import {FitChartCellRenderer} from './fit-renderer';
@@ -42,6 +43,8 @@ export class MultiCurveViewer extends CellRenderViewer<FitChartCellRenderer> {
42
43
  }
43
44
 
44
45
  createChartData(): void {
46
+ if (!this.curvesColumnName)
47
+ return;
45
48
  this.rows.length = 0;
46
49
  if (this.showCurrentRowCurve && this.dataFrame.currentRowIdx !== -1)
47
50
  this.rows.push(this.dataFrame.currentRowIdx);
@@ -75,7 +78,16 @@ export class MultiCurveViewer extends CellRenderViewer<FitChartCellRenderer> {
75
78
  });
76
79
  }
77
80
 
81
+ _showErrorMessage(msg: string) {
82
+ this.root.appendChild(ui.divText(msg, 'd4-viewer-error'));
83
+ }
84
+
78
85
  render(): void {
86
+ if (!this.curvesColumnName) {
87
+ this._showErrorMessage('The MultiCurveViewer viewer requires a minimum of 1 curves column.');
88
+ return;
89
+ }
90
+
79
91
  const g = this.canvas.getContext('2d')!
80
92
  g.clearRect(0, 0, this.canvas.width, this.canvas.height);
81
93
  this.renderer.renderCurves(g, 0, 0, this.canvas.width, this.canvas.height, this.data);