@datagrok/curves 1.2.14 → 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 +22 -0
- package/README.md +11 -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 +45 -7
- package/src/fit/multi-curve-viewer.ts +12 -0
- 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
|
@@ -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(
|
|
95
|
-
JSON.parse(
|
|
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) : {};
|
|
@@ -151,11 +155,12 @@ function drawCandlestick(g: CanvasRenderingContext2D, x: number, boxPlotStats: B
|
|
|
151
155
|
|
|
152
156
|
/** Performs points drawing */
|
|
153
157
|
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
154
|
-
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number): void {
|
|
158
|
+
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number, outlierColor: number): void {
|
|
155
159
|
for (let i = 0; i < series.points.length!; i++) {
|
|
156
160
|
const p = series.points[i];
|
|
157
|
-
const color = p.outlier ? DG.Color.
|
|
158
|
-
|
|
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;
|
|
159
164
|
const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
|
|
160
165
|
const size = p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio;
|
|
161
166
|
DG.Paint.marker(g,
|
|
@@ -269,6 +274,34 @@ function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue:
|
|
|
269
274
|
g.lineTo(transform.xToScreen(xValue), transform.yToScreen(dataBounds.minY));
|
|
270
275
|
}
|
|
271
276
|
|
|
277
|
+
/** Performs x zeroes substitution if log x */
|
|
278
|
+
export function substituteZeroes(data: IFitChartData): void {
|
|
279
|
+
for (let i = 0; i < data.series?.length!; i++) {
|
|
280
|
+
const series = data.series![i];
|
|
281
|
+
if (series.points.every((p) => p.x !== 0))
|
|
282
|
+
continue;
|
|
283
|
+
let minNonZeroX = Number.MAX_VALUE;
|
|
284
|
+
let maxNonZeroX = 0;
|
|
285
|
+
let countOfDistNonZeroX = 0;
|
|
286
|
+
const uniqueArr: number[] = [];
|
|
287
|
+
for (let j = 0; j < series.points.length; j++) {
|
|
288
|
+
if (series.points[j].x < minNonZeroX && series.points[j].x !== 0)
|
|
289
|
+
minNonZeroX = series.points[j].x;
|
|
290
|
+
if (series.points[j].x > maxNonZeroX && series.points[j].x !== 0)
|
|
291
|
+
maxNonZeroX = series.points[j].x;
|
|
292
|
+
if (!uniqueArr.includes(series.points[j].x)) {
|
|
293
|
+
uniqueArr[uniqueArr.length] = series.points[j].x;
|
|
294
|
+
countOfDistNonZeroX++;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const zeroSubstitute = Math.pow(10, Math.log10(minNonZeroX) - (Math.log10(maxNonZeroX) - Math.log10(minNonZeroX) / (countOfDistNonZeroX - 1)));
|
|
298
|
+
for (let j = 0; j < series.points.length; j++) {
|
|
299
|
+
if (series.points[j].x === 0)
|
|
300
|
+
series.points[j].x = zeroSubstitute;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
272
305
|
export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
273
306
|
get name() { return FIT_CELL_TYPE; }
|
|
274
307
|
|
|
@@ -367,6 +400,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
367
400
|
g.rect(x, y, w, h);
|
|
368
401
|
g.clip();
|
|
369
402
|
|
|
403
|
+
if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX && data.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
404
|
+
substituteZeroes(data);
|
|
370
405
|
const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
371
406
|
const showAxes = screenBounds.width >= MIN_AXES_CELL_PX_WIDTH && screenBounds.height >= MIN_AXES_CELL_PX_HEIGHT;
|
|
372
407
|
// TODO: make bigger sizes
|
|
@@ -377,7 +412,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
377
412
|
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxesLabels, showTitle);
|
|
378
413
|
|
|
379
414
|
const dataBounds = getChartBounds(data);
|
|
380
|
-
if (dataBounds.x
|
|
415
|
+
if ((dataBounds.x < 0 && data.chartOptions) || (dataBounds.x === 0 && data.chartOptions && !data.chartOptions.allowXZeroes))
|
|
416
|
+
data.chartOptions.logX = false;
|
|
381
417
|
if (dataBounds.y <= 0 && data.chartOptions) data.chartOptions.logY = false;
|
|
382
418
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
383
419
|
const minSize = Math.min(dataBox.width, dataBox.height);
|
|
@@ -420,9 +456,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
420
456
|
if (series.showPoints ?? 'points') {
|
|
421
457
|
const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
|
|
422
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;
|
|
423
461
|
g.strokeStyle = pointColor;
|
|
424
462
|
if (series.showPoints === 'points')
|
|
425
|
-
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor));
|
|
463
|
+
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor), outlierColor);
|
|
426
464
|
else if (['candlesticks', 'both'].includes(series.showPoints!))
|
|
427
465
|
drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
|
|
428
466
|
}
|
|
@@ -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);
|
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
|
+
}
|