@datagrok/curves 1.5.0 → 1.8.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/README.md +36 -8
- 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/img/plate-dose-response-series.gif +0 -0
- package/img/plate-readers.gif +0 -0
- package/package.json +13 -11
- package/src/fit/const.ts +3 -2
- package/src/fit/fit-grid-cell-handler.ts +64 -59
- package/src/fit/fit-renderer.ts +142 -79
- package/src/fit/multi-curve-viewer.ts +32 -11
- package/src/fit/render-utils.ts +196 -138
- package/src/package-test.ts +7 -1
- package/src/package.g.ts +8 -0
- package/src/package.ts +253 -10
- package/src/plate/excel-plates.ts +112 -0
- package/src/plate/plate-cell-renderer.ts +40 -0
- package/src/plate/plate-reader.ts +28 -0
- package/src/plate/plate-widget.ts +478 -0
- package/src/plate/plate.ts +446 -0
- package/src/plate/readers/bmg-pherastar-96.ts +42 -0
- package/src/plate/readers/delfia-envision-96-max-rlu.ts +15 -0
- package/src/plate/readers/delfia-envision-by-row.ts +18 -0
- package/src/plate/readers/spectramax.ts +43 -0
- package/src/plate/utils.ts +129 -0
- package/src/tests/curves-cell-renderer-tests.ts +41 -22
- package/src/tests/fit-tests.ts +46 -11
- package/src/tests/plate-tests.ts +154 -0
- package/src/tests/transform-tests.ts +2 -2
- package/src/fit/cell-render-viewer.ts +0 -54
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/curves",
|
|
3
3
|
"friendlyName": "Curves",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.8.0",
|
|
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.
|
|
12
|
-
"@datagrok-libraries/utils": "^4.
|
|
11
|
+
"@datagrok-libraries/statistics": "^1.7.0",
|
|
12
|
+
"@datagrok-libraries/utils": "^4.5.0",
|
|
13
13
|
"@types/wu": "^2.1.42",
|
|
14
14
|
"cash-dom": "^8.0.0",
|
|
15
|
-
"datagrok-api": "^1.
|
|
15
|
+
"datagrok-api": "^1.25.0",
|
|
16
16
|
"dayjs": "^1.11.7",
|
|
17
|
-
"rxjs": "^6.5.5"
|
|
17
|
+
"rxjs": "^6.5.5",
|
|
18
|
+
"jstat": "^1.9.6",
|
|
19
|
+
"exceljs": "^4.3.0"
|
|
18
20
|
},
|
|
19
21
|
"devDependencies": {
|
|
20
22
|
"datagrok-tools": "latest",
|
|
21
23
|
"css-loader": "^5.0.0",
|
|
22
24
|
"source-map-loader": "^4.0.1",
|
|
23
25
|
"style-loader": "^2.0.0",
|
|
24
|
-
"ts-loader": "
|
|
25
|
-
"typescript": "
|
|
26
|
-
"webpack": "
|
|
27
|
-
"webpack-cli": "
|
|
26
|
+
"ts-loader": "^9.5.1",
|
|
27
|
+
"typescript": "^5.6.3",
|
|
28
|
+
"webpack": "^5.95.0",
|
|
29
|
+
"webpack-cli": "^5.1.4"
|
|
28
30
|
},
|
|
29
31
|
"scripts": {
|
|
30
32
|
"link-all": "npm link datagrok-api @datagrok-libraries/utils @datagrok-libraries/statistics",
|
|
@@ -41,7 +43,7 @@
|
|
|
41
43
|
"build-all": "npm --prefix ./../../js-api run build && npm --prefix ./../../libraries/utils run build && npm --prefix ./../../libraries/statistics run build && npm run build"
|
|
42
44
|
},
|
|
43
45
|
"canEdit": [
|
|
44
|
-
"
|
|
46
|
+
"Administrators"
|
|
45
47
|
],
|
|
46
48
|
"canView": [
|
|
47
49
|
"All users"
|
|
@@ -52,4 +54,4 @@
|
|
|
52
54
|
"directory": "packages/Curves"
|
|
53
55
|
},
|
|
54
56
|
"category": "Visualizations"
|
|
55
|
-
}
|
|
57
|
+
}
|
package/src/fit/const.ts
CHANGED
|
@@ -9,8 +9,8 @@ export class FitConstants {
|
|
|
9
9
|
|
|
10
10
|
static CELL_DEFAULT_WIDTH = 230;
|
|
11
11
|
static CELL_DEFAULT_HEIGHT = 160;
|
|
12
|
-
static MIN_CELL_RENDERER_PX_WIDTH =
|
|
13
|
-
static MIN_CELL_RENDERER_PX_HEIGHT =
|
|
12
|
+
static MIN_CELL_RENDERER_PX_WIDTH = 10;
|
|
13
|
+
static MIN_CELL_RENDERER_PX_HEIGHT = 5;
|
|
14
14
|
static MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH = 70;
|
|
15
15
|
static MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT = 45;
|
|
16
16
|
static MIN_AXES_CELL_PX_WIDTH = 100;
|
|
@@ -40,6 +40,7 @@ export class FitConstants {
|
|
|
40
40
|
static CANDLESTICK_MEDIAN_PX_SIZE = 3.5;
|
|
41
41
|
static CANDLESTICK_OUTLIER_PX_SIZE = 6;
|
|
42
42
|
static INFLATE_SIZE = -12 / 2;
|
|
43
|
+
static MIN_INFLATE_SIZE = -4 / 2;
|
|
43
44
|
static LEGEND_RECORD_PX_HEIGHT = 18;
|
|
44
45
|
static LEGEND_RECORD_LINE_PX_WIDTH = 20;
|
|
45
46
|
static LEGEND_RECORD_LINE_RIGHT_PX_MARGIN = 5;
|
|
@@ -2,24 +2,33 @@ import * as DG from 'datagrok-api/dg';
|
|
|
2
2
|
import * as ui from 'datagrok-api/ui';
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
fitSeries,
|
|
6
5
|
getSeriesStatistics,
|
|
7
6
|
getSeriesFitFunction,
|
|
8
7
|
LogOptions,
|
|
9
8
|
getChartBounds,
|
|
10
9
|
} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
11
|
-
import {statisticsProperties, fitSeriesProperties, fitChartDataProperties, IFitChartData, IFitSeries, IFitChartOptions, IFitSeriesOptions, FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
12
10
|
import {
|
|
13
|
-
|
|
11
|
+
statisticsProperties,
|
|
12
|
+
fitSeriesProperties,
|
|
13
|
+
fitChartDataProperties,
|
|
14
|
+
IFitChartData,
|
|
15
|
+
IFitSeries,
|
|
16
|
+
IFitChartOptions,
|
|
17
|
+
IFitSeriesOptions,
|
|
18
|
+
FitStatistics,
|
|
19
|
+
FIT_FUNCTION_4PL_REGRESSION, FIT_FUNCTION_SIGMOID,
|
|
20
|
+
} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
21
|
+
import {
|
|
22
|
+
getOrCreateParsedChartData,
|
|
14
23
|
getColumnChartOptions,
|
|
15
24
|
getDataFrameChartOptions,
|
|
16
25
|
isColorValid,
|
|
17
26
|
mergeProperties,
|
|
18
|
-
substituteZeroes
|
|
27
|
+
substituteZeroes, getOrCreateCachedFitCurve, getOrCreateCachedCurvesDataPoints, FitChartCellRenderer
|
|
19
28
|
} from './fit-renderer';
|
|
20
|
-
import {CellRenderViewer} from './cell-render-viewer';
|
|
21
29
|
import {convertXMLToIFitChartData} from './fit-parser';
|
|
22
30
|
import {FitConstants} from './const';
|
|
31
|
+
import {ColorType, getSeriesColor} from './render-utils';
|
|
23
32
|
|
|
24
33
|
|
|
25
34
|
const CHART_OPTIONS = 'chartOptions';
|
|
@@ -49,7 +58,8 @@ const AGGREGATION_TYPES: {[key: string]: string} = {
|
|
|
49
58
|
};
|
|
50
59
|
|
|
51
60
|
|
|
52
|
-
export function calculateSeriesStats(series: IFitSeries, chartLogOptions: LogOptions
|
|
61
|
+
export function calculateSeriesStats(series: IFitSeries, seriesIdx: number, chartLogOptions: LogOptions,
|
|
62
|
+
gridCell: DG.GridCell): FitStatistics {
|
|
53
63
|
const fitFunction = getSeriesFitFunction(series);
|
|
54
64
|
if (series.parameters) {
|
|
55
65
|
if (chartLogOptions.logX)
|
|
@@ -57,22 +67,25 @@ export function calculateSeriesStats(series: IFitSeries, chartLogOptions: LogOpt
|
|
|
57
67
|
series.parameters[2] = Math.log10(series.parameters[2]);
|
|
58
68
|
}
|
|
59
69
|
else {
|
|
60
|
-
const params =
|
|
70
|
+
const params = getOrCreateCachedFitCurve(series, seriesIdx, fitFunction, chartLogOptions, gridCell).parameters;
|
|
61
71
|
series.parameters = [...params];
|
|
62
72
|
}
|
|
63
73
|
|
|
64
|
-
const seriesStatistics = getSeriesStatistics(series, fitFunction,
|
|
74
|
+
const seriesStatistics = getSeriesStatistics(series, fitFunction,
|
|
75
|
+
getOrCreateCachedCurvesDataPoints(series, seriesIdx, chartLogOptions, false, gridCell), chartLogOptions);
|
|
76
|
+
if ([FIT_FUNCTION_4PL_REGRESSION, FIT_FUNCTION_SIGMOID].includes(fitFunction.name) && chartLogOptions.logX && seriesStatistics.interceptX !== undefined && seriesStatistics.interceptX < 0)
|
|
77
|
+
seriesStatistics.interceptX = Math.pow(10, seriesStatistics.interceptX);
|
|
65
78
|
return seriesStatistics;
|
|
66
79
|
}
|
|
67
80
|
|
|
68
|
-
export function getChartDataAggrStats(chartData: IFitChartData, aggrType: string): FitStatistics {
|
|
81
|
+
export function getChartDataAggrStats(chartData: IFitChartData, aggrType: string, gridCell: DG.GridCell): FitStatistics {
|
|
69
82
|
const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
|
|
70
83
|
const rSquaredValues: number[] = [], aucValues: number[] = [], interceptXValues: number[] = [], interceptYValues: number[] = [],
|
|
71
84
|
slopeValues: number[] = [], topValues: number[] = [], bottomValues: number[] = [];
|
|
72
85
|
for (let i = 0, j = 0; i < chartData.series?.length!; i++) {
|
|
73
86
|
if (chartData.series![i].points.every((p) => p.outlier))
|
|
74
87
|
continue;
|
|
75
|
-
const seriesStats = calculateSeriesStats(chartData.series![i], chartLogOptions);
|
|
88
|
+
const seriesStats = calculateSeriesStats(chartData.series![i], i, chartLogOptions, gridCell);
|
|
76
89
|
rSquaredValues[j] = seriesStats.rSquared!;
|
|
77
90
|
aucValues[j] = seriesStats.auc!;
|
|
78
91
|
interceptXValues[j] = seriesStats.interceptX!;
|
|
@@ -185,7 +198,7 @@ function changeCurvesOptions(gridCell: DG.GridCell, inputBase: DG.InputBase, opt
|
|
|
185
198
|
gridCell.cell.column.tags[FitConstants.TAG_FIT] = JSON.stringify(chartOptions);
|
|
186
199
|
columns = [gridCell.cell.column];
|
|
187
200
|
}
|
|
188
|
-
|
|
201
|
+
|
|
189
202
|
for (let i = 0; i < columns.length; i++) {
|
|
190
203
|
if (manipulationLevel === MANIPULATION_LEVEL.DATAFRAME) {
|
|
191
204
|
const columnChartOptions = getColumnChartOptions(columns[i]);
|
|
@@ -234,7 +247,7 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
234
247
|
isApplicable(x: any): boolean {
|
|
235
248
|
return x instanceof DG.GridCell && x.cellType === FitConstants.FIT_CELL_TYPE;
|
|
236
249
|
}
|
|
237
|
-
|
|
250
|
+
|
|
238
251
|
// TODO: add aspect ratio for the cell
|
|
239
252
|
// TODO: add legend
|
|
240
253
|
// TODO: add the table for the values on the cell or don't render it at all
|
|
@@ -250,47 +263,34 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
250
263
|
// temporarily because input doesn't show the tooltip
|
|
251
264
|
ui.tooltip.bind(switchLevelInput.captionLabel, 'Controls the level at which properties will be switched');
|
|
252
265
|
|
|
253
|
-
const chartData =
|
|
266
|
+
const chartData = getOrCreateParsedChartData(gridCell);
|
|
254
267
|
const columnChartOptions = getColumnChartOptions(gridCell.cell.column);
|
|
255
268
|
const dfChartOptions = getDataFrameChartOptions(gridCell.cell.dataFrame);
|
|
256
269
|
|
|
257
|
-
const seriesOptionsRefresh = {onValueChanged: (inputBase: DG.InputBase) =>
|
|
270
|
+
const seriesOptionsRefresh = {onValueChanged: (v: any, inputBase: DG.InputBase) =>
|
|
258
271
|
changeCurvesOptions(gridCell, inputBase, SERIES_OPTIONS, switchLevelInput.value)};
|
|
259
|
-
const chartOptionsRefresh = {onValueChanged: (inputBase: DG.InputBase) =>
|
|
272
|
+
const chartOptionsRefresh = {onValueChanged: (v: any, inputBase: DG.InputBase) =>
|
|
260
273
|
changeCurvesOptions(gridCell, inputBase, CHART_OPTIONS, switchLevelInput.value)};
|
|
261
274
|
|
|
262
|
-
|
|
263
|
-
if (
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (!isColorValid(chartData.seriesOptions.fitLineColor))
|
|
276
|
-
chartData.seriesOptions.fitLineColor = DG.Color.toHtml(DG.Color.getCategoricalColor(0));
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
if (!isColorValid(chartData.series ? chartData.series![0].fitLineColor : ''))
|
|
280
|
-
chartData.series![0].fitLineColor = DG.Color.toHtml(DG.Color.getCategoricalColor(0));
|
|
275
|
+
const setValidColors = (colorFieldName: string) => {
|
|
276
|
+
if (dfChartOptions.seriesOptions && !isColorValid(dfChartOptions.seriesOptions[colorFieldName]) &&
|
|
277
|
+
columnChartOptions.seriesOptions && !isColorValid(columnChartOptions.seriesOptions[colorFieldName])) {
|
|
278
|
+
if (chartData.seriesOptions) {
|
|
279
|
+
if (!isColorValid(chartData.seriesOptions[colorFieldName]))
|
|
280
|
+
chartData.seriesOptions[colorFieldName] = DG.Color.toHtml(colorFieldName === 'outlierColor' ?
|
|
281
|
+
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));
|
|
287
|
+
}
|
|
281
288
|
}
|
|
282
289
|
}
|
|
283
290
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
chartData.seriesOptions.outlierColor = DG.Color.toHtml(DG.Color.red);
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
if (!isColorValid(chartData.series ? chartData.series![0].outlierColor : ''))
|
|
291
|
-
chartData.series![0].outlierColor = DG.Color.toHtml(DG.Color.red);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
291
|
+
setValidColors('pointColor');
|
|
292
|
+
setValidColors('fitLineColor');
|
|
293
|
+
setValidColors('outlierColor');
|
|
294
294
|
|
|
295
295
|
mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, chartData.seriesOptions ? chartData.seriesOptions :
|
|
296
296
|
chartData.series ? chartData.series[0] ?? {} : {});
|
|
@@ -311,21 +311,24 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
311
311
|
ui.forms.addGroup(form, 'Chart options', fitChartDataProperties.map((p) => ui.input.forProperty(p, chartData.chartOptions, chartOptionsRefresh)));
|
|
312
312
|
acc.addPane('Options', () => form);
|
|
313
313
|
|
|
314
|
+
const choices = (chartData.series?.length ?? 0) > 1 ? ['all', 'aggregated'] : ['all'];
|
|
314
315
|
const seriesStatsProperty = DG.Property.js('series', DG.TYPE.STRING,
|
|
315
316
|
{description: 'Controls whether to show series statistics or aggregated statistics',
|
|
316
|
-
defaultValue: '
|
|
317
|
-
const seriesStatsInput = ui.input.forProperty(seriesStatsProperty, null, {onValueChanged(
|
|
317
|
+
defaultValue: 'all', choices: choices, nullable: false});
|
|
318
|
+
const seriesStatsInput = ui.input.forProperty(seriesStatsProperty, null, {onValueChanged: () => {
|
|
318
319
|
acc.getPane('Fit').root.lastElementChild!.replaceChildren(createFitPane());
|
|
319
320
|
}});
|
|
320
321
|
const aggrTypeProperty = DG.Property.js('aggregation type', DG.TYPE.STRING,
|
|
321
322
|
{description: 'Controls which aggregation to use on the series statistics',
|
|
322
323
|
defaultValue: 'med', choices: Object.values(DG.STATS), nullable: false});
|
|
323
|
-
const aggrTypeInput = ui.input.forProperty(aggrTypeProperty, null, {onValueChanged(
|
|
324
|
+
const aggrTypeInput = ui.input.forProperty(aggrTypeProperty, null, {onValueChanged: () => {
|
|
324
325
|
acc.getPane('Fit').root.lastElementChild!.replaceChildren(createFitPane());
|
|
325
326
|
}});
|
|
326
327
|
|
|
327
328
|
function createFitPane(): HTMLElement {
|
|
328
|
-
const
|
|
329
|
+
const hostItems = (chartData.series?.length ?? 0) > 1 ? seriesStatsInput.stringValue === 'aggregated' ?
|
|
330
|
+
[seriesStatsInput.root, aggrTypeInput.root] : [seriesStatsInput.root] : null;
|
|
331
|
+
const host = ui.divV(hostItems!);
|
|
329
332
|
const dataBounds = getChartBounds(chartData);
|
|
330
333
|
if (dataBounds.x <= 0 && chartData.chartOptions) chartData.chartOptions.logX = false;
|
|
331
334
|
if (dataBounds.y <= 0 && chartData.chartOptions) chartData.chartOptions.logY = false;
|
|
@@ -334,15 +337,15 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
334
337
|
const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
|
|
335
338
|
for (let i = 0; i < chartData.series!.length; i++) {
|
|
336
339
|
const series = chartData.series![i];
|
|
337
|
-
const seriesStatistics = calculateSeriesStats(series, chartLogOptions);
|
|
338
|
-
|
|
339
|
-
const color = series
|
|
340
|
-
|
|
340
|
+
const seriesStatistics = calculateSeriesStats(series, i, chartLogOptions, gridCell);
|
|
341
|
+
|
|
342
|
+
const color = getSeriesColor(series, i, ColorType.FIT_LINE);
|
|
343
|
+
const seriesName = series.name ?? 'series ' + i;
|
|
341
344
|
host.appendChild(ui.panel([
|
|
342
|
-
ui.h1(
|
|
345
|
+
ui.h1(seriesName, {style: {color: color}}),
|
|
343
346
|
ui.input.form(seriesStatistics, statisticsProperties, {
|
|
344
347
|
onCreated: (input) => input.root.appendChild(ui.iconFA('plus', async () => {
|
|
345
|
-
const funcParams = {df: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, seriesName:
|
|
348
|
+
const funcParams = {df: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, seriesName: seriesName, seriesNumber: i};
|
|
346
349
|
await DG.Func.find({name: 'addStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false});
|
|
347
350
|
}, `Calculate ${input.property.name} for the whole column`))
|
|
348
351
|
})
|
|
@@ -350,7 +353,7 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
350
353
|
}
|
|
351
354
|
}
|
|
352
355
|
else {
|
|
353
|
-
const seriesStatistics = getChartDataAggrStats(chartData, aggrTypeInput.stringValue);
|
|
356
|
+
const seriesStatistics = getChartDataAggrStats(chartData, aggrTypeInput.stringValue, gridCell);
|
|
354
357
|
host.appendChild(ui.panel([
|
|
355
358
|
ui.h1(`series ${aggrTypeInput.stringValue}`),
|
|
356
359
|
ui.input.form(seriesStatistics, statisticsProperties, {
|
|
@@ -365,11 +368,13 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
365
368
|
return host;
|
|
366
369
|
}
|
|
367
370
|
|
|
368
|
-
acc.addPane('
|
|
369
|
-
|
|
370
|
-
|
|
371
|
+
const chartPane = acc.addPane('Chart', () => DG.GridCellWidget.fromGridCell(gridCell).root);
|
|
372
|
+
const screenBounds = FitChartCellRenderer.inflateScreenBounds(gridCell.bounds);
|
|
373
|
+
if (screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
374
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT)
|
|
375
|
+
chartPane.expanded = true;
|
|
371
376
|
|
|
372
|
-
acc.addPane('
|
|
377
|
+
acc.addPane('Fit', () => createFitPane());
|
|
373
378
|
|
|
374
379
|
return acc.root;
|
|
375
380
|
}
|