@datagrok/curves 1.2.13 → 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/CHANGELOG.md +16 -0
- package/README.md +2 -0
- package/dist/package-test.js +1 -1
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +1 -1
- package/dist/package.js.map +1 -1
- package/package.json +2 -2
- package/src/fit/fit-renderer.ts +42 -4
- package/src/fit/multi-curve-viewer.ts +12 -0
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/curves",
|
|
3
3
|
"friendlyName": "Curves",
|
|
4
|
-
"version": "1.2.
|
|
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.
|
|
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",
|
package/src/fit/fit-renderer.ts
CHANGED
|
@@ -52,6 +52,8 @@ const MIN_TITLE_PX_WIDTH = 275;
|
|
|
52
52
|
const MIN_TITLE_PX_HEIGHT = 225;
|
|
53
53
|
const MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH = 180;
|
|
54
54
|
const MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT = 140;
|
|
55
|
+
const MIN_DROPLINES_VISIBILITY_PX_WIDTH = 120;
|
|
56
|
+
const MIN_DROPLINES_VISIBILITY_PX_HEIGHT = 110;
|
|
55
57
|
const AXES_LEFT_PX_MARGIN = 38;
|
|
56
58
|
const AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS = 45;
|
|
57
59
|
const AXES_TOP_PX_MARGIN = 5;
|
|
@@ -87,10 +89,14 @@ export function mergeProperties(properties: DG.Property[], source: any, target:
|
|
|
87
89
|
/** Constructs {@link IFitChartData} from the grid cell, taking into account
|
|
88
90
|
* chart and fit settings potentially defined on the dataframe and column level. */
|
|
89
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('|', '');
|
|
90
96
|
const cellChartData: IFitChartData = gridCell.cell?.column?.type === DG.TYPE.STRING ?
|
|
91
97
|
(gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
92
|
-
convertXMLToIFitChartData(
|
|
93
|
-
JSON.parse(
|
|
98
|
+
convertXMLToIFitChartData(cellValue) :
|
|
99
|
+
JSON.parse(cellValue ?? '{}') ?? {}) : createDefaultChartData();
|
|
94
100
|
|
|
95
101
|
const columnChartOptions = gridCell.cell.column ? getColumnChartOptions(gridCell.cell.column) : {};
|
|
96
102
|
const dfChartOptions = gridCell.cell.column ? getDataFrameChartOptions(gridCell.cell.dataFrame) : {};
|
|
@@ -267,6 +273,34 @@ function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue:
|
|
|
267
273
|
g.lineTo(transform.xToScreen(xValue), transform.yToScreen(dataBounds.minY));
|
|
268
274
|
}
|
|
269
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
|
+
|
|
270
304
|
export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
271
305
|
get name() { return FIT_CELL_TYPE; }
|
|
272
306
|
|
|
@@ -365,16 +399,20 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
365
399
|
g.rect(x, y, w, h);
|
|
366
400
|
g.clip();
|
|
367
401
|
|
|
402
|
+
if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX && data.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
403
|
+
substituteZeroes(data);
|
|
368
404
|
const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
369
405
|
const showAxes = screenBounds.width >= MIN_AXES_CELL_PX_WIDTH && screenBounds.height >= MIN_AXES_CELL_PX_HEIGHT;
|
|
370
406
|
// TODO: make bigger sizes
|
|
371
407
|
const showAxesLabels = w >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && h >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT
|
|
372
408
|
&& !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
|
|
373
409
|
const showTitle = w >= MIN_TITLE_PX_WIDTH && h >= MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
|
|
410
|
+
const showDroplines = w >= MIN_DROPLINES_VISIBILITY_PX_WIDTH && h >= MIN_DROPLINES_VISIBILITY_PX_HEIGHT;
|
|
374
411
|
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxesLabels, showTitle);
|
|
375
412
|
|
|
376
413
|
const dataBounds = getChartBounds(data);
|
|
377
|
-
if (dataBounds.x
|
|
414
|
+
if ((dataBounds.x < 0 && data.chartOptions) || (dataBounds.x === 0 && data.chartOptions && !data.chartOptions.allowXZeroes))
|
|
415
|
+
data.chartOptions.logX = false;
|
|
378
416
|
if (dataBounds.y <= 0 && data.chartOptions) data.chartOptions.logY = false;
|
|
379
417
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
380
418
|
const minSize = Math.min(dataBox.width, dataBox.height);
|
|
@@ -461,7 +499,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
461
499
|
fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, showAxes, showAxesLabels, chartLogOptions);
|
|
462
500
|
}
|
|
463
501
|
|
|
464
|
-
if (series.droplines &&
|
|
502
|
+
if (series.droplines && showDroplines) {
|
|
465
503
|
g.save();
|
|
466
504
|
g.strokeStyle = 'blue';
|
|
467
505
|
g.lineWidth = ratio;
|
|
@@ -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);
|