@datagrok/curves 1.2.15 → 1.2.16
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 +13 -1
- package/README.md +9 -1
- 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/multi-curve-viewer.gif +0 -0
- package/package.json +6 -6
- package/src/fit/fit-grid-cell-handler.ts +30 -64
- package/src/fit/fit-renderer.ts +8 -5
- package/src/package.ts +75 -2
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/curves",
|
|
3
3
|
"friendlyName": "Curves",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.16",
|
|
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.
|
|
12
|
-
"@datagrok-libraries/utils": "^4.1.
|
|
11
|
+
"@datagrok-libraries/statistics": "^1.2.12",
|
|
12
|
+
"@datagrok-libraries/utils": "^4.1.45",
|
|
13
13
|
"@types/wu": "^2.1.42",
|
|
14
|
-
"cash-dom": "
|
|
15
|
-
"datagrok-api": "^1.
|
|
14
|
+
"cash-dom": "^8.0.0",
|
|
15
|
+
"datagrok-api": "^1.18.0",
|
|
16
16
|
"dayjs": "^1.11.7",
|
|
17
|
-
"rxjs": "6.5.5"
|
|
17
|
+
"rxjs": "^6.5.5"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"css-loader": "^5.0.0",
|
|
@@ -11,22 +11,18 @@ import {
|
|
|
11
11
|
getChartBounds,
|
|
12
12
|
} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
13
13
|
import {statisticsProperties, fitSeriesProperties, fitChartDataProperties, FIT_CELL_TYPE, TAG_FIT, IFitChartData, IFitSeries, IFitChartOptions, FIT_SEM_TYPE, IFitSeriesOptions, FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
14
|
-
import {TAG_FIT_CHART_FORMAT, TAG_FIT_CHART_FORMAT_3DX, getChartData, isColorValid, mergeProperties} from './fit-renderer';
|
|
14
|
+
import {TAG_FIT_CHART_FORMAT, TAG_FIT_CHART_FORMAT_3DX, getChartData, isColorValid, mergeProperties, substituteZeroes} from './fit-renderer';
|
|
15
15
|
import {CellRenderViewer} from './cell-render-viewer';
|
|
16
16
|
import {convertXMLToIFitChartData} from './fit-parser';
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
const SOURCE_COLUMN_TAG = '.sourceColumn';
|
|
20
|
-
const SERIES_NUMBER_TAG = '.seriesNumber';
|
|
21
|
-
const SERIES_AGGREGATION_TAG = '.seriesAggregation';
|
|
22
|
-
const STATISTICS_TAG = '.statistics';
|
|
23
19
|
const CHART_OPTIONS = 'chartOptions';
|
|
24
20
|
const SERIES_OPTIONS = 'seriesOptions';
|
|
25
21
|
enum MANIPULATION_LEVEL {
|
|
26
22
|
DATAFRAME = 'Dataframe',
|
|
27
23
|
COLUMN = 'Column',
|
|
28
24
|
CELL = 'Cell'
|
|
29
|
-
}
|
|
25
|
+
}
|
|
30
26
|
const AGGREGATION_TYPES: {[key: string]: string} = {
|
|
31
27
|
'count': 'totalCount',
|
|
32
28
|
'nulls': 'missingValueCount',
|
|
@@ -90,51 +86,6 @@ export function getChartDataAggrStats(chartData: IFitChartData, aggrType: string
|
|
|
90
86
|
};
|
|
91
87
|
}
|
|
92
88
|
|
|
93
|
-
function addStatisticsColumn(chartColumn: DG.GridColumn, p: DG.Property, series: IFitSeries, seriesNumber: number): void {
|
|
94
|
-
const grid = chartColumn.grid;
|
|
95
|
-
const column = DG.Column.float(`${chartColumn.name}_${series.name}_${p.name}`, chartColumn.column?.length);
|
|
96
|
-
column.tags[SOURCE_COLUMN_TAG] = chartColumn.name;
|
|
97
|
-
column.tags[SERIES_NUMBER_TAG] = seriesNumber;
|
|
98
|
-
column.tags[STATISTICS_TAG] = p.name;
|
|
99
|
-
|
|
100
|
-
column
|
|
101
|
-
.init((i) => {
|
|
102
|
-
const gridCell = DG.GridCell.fromColumnRow(grid, chartColumn.name, grid.tableRowToGrid(i));
|
|
103
|
-
if (gridCell.cell.value === '')
|
|
104
|
-
return null;
|
|
105
|
-
const chartData = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
106
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
107
|
-
if (chartData.series![seriesNumber] === undefined || chartData.series![seriesNumber].points.every((p) => p.outlier))
|
|
108
|
-
return null;
|
|
109
|
-
const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
|
|
110
|
-
const fitResult = calculateSeriesStats(chartData.series![seriesNumber], chartLogOptions);
|
|
111
|
-
return p.get(fitResult);
|
|
112
|
-
});
|
|
113
|
-
grid.dataFrame.columns.insert(column, chartColumn.idx);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function addAggrStatisticsColumn(chartColumn: DG.GridColumn, p: DG.Property, aggrType: string): void {
|
|
117
|
-
const grid = chartColumn.grid;
|
|
118
|
-
const column = DG.Column.float(`${chartColumn.name}_${aggrType}_${p.name}`, chartColumn.column?.length);
|
|
119
|
-
column.tags[SOURCE_COLUMN_TAG] = chartColumn.name;
|
|
120
|
-
column.tags[SERIES_AGGREGATION_TAG] = aggrType;
|
|
121
|
-
column.tags[STATISTICS_TAG] = p.name;
|
|
122
|
-
|
|
123
|
-
column
|
|
124
|
-
.init((i) => {
|
|
125
|
-
const gridCell = DG.GridCell.fromColumnRow(grid, chartColumn.name, grid.tableRowToGrid(i));
|
|
126
|
-
if (gridCell.cell.value === '')
|
|
127
|
-
return null;
|
|
128
|
-
const chartData = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
129
|
-
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
130
|
-
if (chartData.series?.every((series) => series.points.every((p) => p.outlier)))
|
|
131
|
-
return null;
|
|
132
|
-
const fitResult = getChartDataAggrStats(chartData, aggrType);
|
|
133
|
-
return p.get(fitResult);
|
|
134
|
-
});
|
|
135
|
-
grid.dataFrame.columns.insert(column, chartColumn.idx);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
89
|
function changePlotOptions(chartData: IFitChartData, inputBase: DG.InputBase, options: string): void {
|
|
139
90
|
const propertyName = inputBase.property.name as string;
|
|
140
91
|
if (options === CHART_OPTIONS) {
|
|
@@ -315,6 +266,17 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
315
266
|
}
|
|
316
267
|
}
|
|
317
268
|
|
|
269
|
+
if (!isColorValid(dfChartOptions.seriesOptions?.outlierColor) && !isColorValid(columnChartOptions.seriesOptions?.outlierColor)) {
|
|
270
|
+
if (chartData.seriesOptions) {
|
|
271
|
+
if (!isColorValid(chartData.seriesOptions.outlierColor))
|
|
272
|
+
chartData.seriesOptions.outlierColor = DG.Color.toHtml(DG.Color.red);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
if (!isColorValid(chartData.series ? chartData.series![0].outlierColor : ''))
|
|
276
|
+
chartData.series![0].outlierColor = DG.Color.toHtml(DG.Color.red);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
318
280
|
mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, chartData.seriesOptions ? chartData.seriesOptions :
|
|
319
281
|
chartData.series ? chartData.series[0] ?? {} : {});
|
|
320
282
|
mergeProperties(fitSeriesProperties, dfChartOptions.seriesOptions, chartData.seriesOptions ? chartData.seriesOptions :
|
|
@@ -324,13 +286,15 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
324
286
|
mergeProperties(fitChartDataProperties, dfChartOptions.chartOptions,
|
|
325
287
|
chartData.chartOptions ? chartData.chartOptions : {});
|
|
326
288
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
289
|
+
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
290
|
+
chartData.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
291
|
+
substituteZeroes(chartData);
|
|
292
|
+
|
|
293
|
+
const form = ui.form([switchLevelInput]);
|
|
294
|
+
const fitSeriesChildren = fitSeriesProperties.map((p) => ui.input.forProperty(p, chartData.seriesOptions ? chartData.seriesOptions : chartData.series![0], seriesOptionsRefresh));
|
|
295
|
+
ui.forms.addGroup(form, 'Series options', fitSeriesChildren);
|
|
296
|
+
ui.forms.addGroup(form, 'Chart options', fitChartDataProperties.map((p) => ui.input.forProperty(p, chartData.chartOptions, chartOptionsRefresh)));
|
|
297
|
+
acc.addPane('Options', () => form);
|
|
334
298
|
|
|
335
299
|
const seriesStatsProperty = DG.Property.js('series', DG.TYPE.STRING,
|
|
336
300
|
{description: 'Controls whether to show series statistics or aggregated statistics',
|
|
@@ -362,9 +326,10 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
362
326
|
host.appendChild(ui.panel([
|
|
363
327
|
ui.h1(series.name ?? 'series ' + i, {style: {color: color}}),
|
|
364
328
|
ui.input.form(seriesStatistics, statisticsProperties, {
|
|
365
|
-
onCreated: (input) => input.root.appendChild(
|
|
366
|
-
|
|
367
|
-
|
|
329
|
+
onCreated: (input) => input.root.appendChild(ui.iconFA('plus', async () => {
|
|
330
|
+
const funcParams = {df: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, seriesName: series.name, seriesNumber: i};
|
|
331
|
+
await DG.Func.find({name: 'addStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false})
|
|
332
|
+
}, `Calculate ${input.property.name} for the whole column`))
|
|
368
333
|
})
|
|
369
334
|
]));
|
|
370
335
|
}
|
|
@@ -374,9 +339,10 @@ export class FitGridCellHandler extends DG.ObjectHandler {
|
|
|
374
339
|
host.appendChild(ui.panel([
|
|
375
340
|
ui.h1(`series ${aggrTypeInput.stringValue}`),
|
|
376
341
|
ui.input.form(seriesStatistics, statisticsProperties, {
|
|
377
|
-
onCreated: (input) => input.root.appendChild(
|
|
378
|
-
|
|
379
|
-
|
|
342
|
+
onCreated: (input) => input.root.appendChild(ui.iconFA('plus', async () => {
|
|
343
|
+
const funcParams = {df: gridCell.cell.dataFrame, colName: gridCell.gridColumn.name, propName: input.property.name, aggrType: aggrTypeInput.stringValue};
|
|
344
|
+
await DG.Func.find({name: 'addAggrStatisticsColumn'})[0].prepare(funcParams).call(undefined, undefined, {processed: false});
|
|
345
|
+
}, `Calculate ${input.property.name} ${aggrTypeInput.stringValue} for the whole column`))
|
|
380
346
|
})
|
|
381
347
|
]));
|
|
382
348
|
}
|
package/src/fit/fit-renderer.ts
CHANGED
|
@@ -155,11 +155,12 @@ function drawCandlestick(g: CanvasRenderingContext2D, x: number, boxPlotStats: B
|
|
|
155
155
|
|
|
156
156
|
/** Performs points drawing */
|
|
157
157
|
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
158
|
-
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number): void {
|
|
158
|
+
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number, outlierColor: number): void {
|
|
159
159
|
for (let i = 0; i < series.points.length!; i++) {
|
|
160
160
|
const p = series.points[i];
|
|
161
|
-
const color = p.outlier ? DG.Color.
|
|
162
|
-
|
|
161
|
+
const color = p.outlier ? (p.outlierColor ? DG.Color.fromHtml(p.outlierColor) ?
|
|
162
|
+
DG.Color.fromHtml(p.outlierColor) : outlierColor : outlierColor) : p.color ? DG.Color.fromHtml(p.color) ?
|
|
163
|
+
DG.Color.fromHtml(p.color) : pointColor : pointColor;
|
|
163
164
|
const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
|
|
164
165
|
const size = p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio;
|
|
165
166
|
DG.Paint.marker(g,
|
|
@@ -274,7 +275,7 @@ function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue:
|
|
|
274
275
|
}
|
|
275
276
|
|
|
276
277
|
/** Performs x zeroes substitution if log x */
|
|
277
|
-
function substituteZeroes(data: IFitChartData): void {
|
|
278
|
+
export function substituteZeroes(data: IFitChartData): void {
|
|
278
279
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
279
280
|
const series = data.series![i];
|
|
280
281
|
if (series.points.every((p) => p.x !== 0))
|
|
@@ -455,9 +456,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
455
456
|
if (series.showPoints ?? 'points') {
|
|
456
457
|
const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
|
|
457
458
|
series.pointColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
459
|
+
const outlierColor = series.outlierColor ? DG.Color.fromHtml(series.outlierColor) ?
|
|
460
|
+
DG.Color.fromHtml(series.outlierColor) : DG.Color.red : DG.Color.red;
|
|
458
461
|
g.strokeStyle = pointColor;
|
|
459
462
|
if (series.showPoints === 'points')
|
|
460
|
-
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor));
|
|
463
|
+
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor), outlierColor);
|
|
461
464
|
else if (['candlesticks', 'both'].includes(series.showPoints!))
|
|
462
465
|
drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
|
|
463
466
|
}
|
package/src/package.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
/* Do not change these import lines to match external modules in webpack configuration */
|
|
2
2
|
import * as DG from 'datagrok-api/dg';
|
|
3
3
|
|
|
4
|
-
import {FitGridCellHandler} from './fit/fit-grid-cell-handler';
|
|
5
|
-
import {FitChartCellRenderer} from './fit/fit-renderer';
|
|
4
|
+
import {FitGridCellHandler, calculateSeriesStats, getChartDataAggrStats} from './fit/fit-grid-cell-handler';
|
|
5
|
+
import {FitChartCellRenderer, TAG_FIT_CHART_FORMAT, TAG_FIT_CHART_FORMAT_3DX, getChartData, substituteZeroes} from './fit/fit-renderer';
|
|
6
6
|
import {MultiCurveViewer} from './fit/multi-curve-viewer';
|
|
7
7
|
import {curveDemo} from './fit/fit-demo';
|
|
8
|
+
import {convertXMLToIFitChartData} from './fit/fit-parser';
|
|
9
|
+
import {LogOptions} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
10
|
+
import {FitStatistics} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
export const _package = new DG.Package();
|
|
14
|
+
const SOURCE_COLUMN_TAG = '.sourceColumn';
|
|
15
|
+
const SERIES_NUMBER_TAG = '.seriesNumber';
|
|
16
|
+
const SERIES_AGGREGATION_TAG = '.seriesAggregation';
|
|
17
|
+
const STATISTICS_TAG = '.statistics';
|
|
11
18
|
|
|
12
19
|
|
|
13
20
|
//name: Fit
|
|
@@ -39,3 +46,69 @@ export async function curveFitDemo(): Promise<void> {
|
|
|
39
46
|
export function _initCurves(): void {
|
|
40
47
|
DG.ObjectHandler.register(new FitGridCellHandler());
|
|
41
48
|
}
|
|
49
|
+
|
|
50
|
+
//name: addStatisticsColumn
|
|
51
|
+
//tags: Transform
|
|
52
|
+
//input: dataframe df
|
|
53
|
+
//input: string colName
|
|
54
|
+
//input: string propName
|
|
55
|
+
//input: string seriesName
|
|
56
|
+
//input: int seriesNumber
|
|
57
|
+
export function addStatisticsColumn(df: DG.DataFrame, colName: string, propName: string, seriesName: string, seriesNumber: number): void {
|
|
58
|
+
const grid = DG.Viewer.grid(df);
|
|
59
|
+
const chartColumn = grid.col(colName)!;
|
|
60
|
+
const column = DG.Column.float(`${colName}_${seriesName}_${propName}`, chartColumn.column?.length);
|
|
61
|
+
column.tags[SOURCE_COLUMN_TAG] = colName;
|
|
62
|
+
column.tags[SERIES_NUMBER_TAG] = seriesNumber;
|
|
63
|
+
column.tags[STATISTICS_TAG] = propName;
|
|
64
|
+
|
|
65
|
+
column
|
|
66
|
+
.init((i) => {
|
|
67
|
+
const gridCell = DG.GridCell.fromColumnRow(grid, colName, grid.tableRowToGrid(i));
|
|
68
|
+
if (gridCell.cell.value === '')
|
|
69
|
+
return null;
|
|
70
|
+
const chartData = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
71
|
+
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
72
|
+
if (chartData.series![seriesNumber] === undefined || chartData.series![seriesNumber].points.every((p) => p.outlier))
|
|
73
|
+
return null;
|
|
74
|
+
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
75
|
+
chartData.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
76
|
+
substituteZeroes(chartData);
|
|
77
|
+
const chartLogOptions: LogOptions = {logX: chartData.chartOptions?.logX, logY: chartData.chartOptions?.logY};
|
|
78
|
+
const fitResult = calculateSeriesStats(chartData.series![seriesNumber], chartLogOptions);
|
|
79
|
+
return fitResult[propName as keyof FitStatistics];
|
|
80
|
+
});
|
|
81
|
+
df.columns.insert(column, chartColumn.idx);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//name: addAggrStatisticsColumn
|
|
85
|
+
//tags: Transform
|
|
86
|
+
//input: dataframe df
|
|
87
|
+
//input: string colName
|
|
88
|
+
//input: string propName
|
|
89
|
+
//input: string aggrType
|
|
90
|
+
export function addAggrStatisticsColumn(df: DG.DataFrame, colName: string, propName: string, aggrType: string): void {
|
|
91
|
+
const grid = DG.Viewer.grid(df);
|
|
92
|
+
const chartColumn = grid.col(colName)!;
|
|
93
|
+
const column = DG.Column.float(`${colName}_${aggrType}_${propName}`, chartColumn.column?.length);
|
|
94
|
+
column.tags[SOURCE_COLUMN_TAG] = colName;
|
|
95
|
+
column.tags[SERIES_AGGREGATION_TAG] = aggrType;
|
|
96
|
+
column.tags[STATISTICS_TAG] = propName;
|
|
97
|
+
|
|
98
|
+
column
|
|
99
|
+
.init((i) => {
|
|
100
|
+
const gridCell = DG.GridCell.fromColumnRow(grid, colName, grid.tableRowToGrid(i));
|
|
101
|
+
if (gridCell.cell.value === '')
|
|
102
|
+
return null;
|
|
103
|
+
const chartData = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
104
|
+
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
105
|
+
if (chartData.series?.every((series) => series.points.every((p) => p.outlier)))
|
|
106
|
+
return null;
|
|
107
|
+
if (chartData.chartOptions?.allowXZeroes && chartData.chartOptions?.logX &&
|
|
108
|
+
chartData.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
109
|
+
substituteZeroes(chartData);
|
|
110
|
+
const fitResult = getChartDataAggrStats(chartData, aggrType);
|
|
111
|
+
return fitResult[propName as keyof FitStatistics];
|
|
112
|
+
});
|
|
113
|
+
df.columns.insert(column, chartColumn.idx);
|
|
114
|
+
}
|