@datagrok/curves 1.2.15 → 1.3.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/CHANGELOG.md +38 -1
- package/README.md +15 -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/icons/multi-curve-viewer.png +0 -0
- 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 +184 -48
- package/src/fit/multi-curve-viewer.ts +53 -14
- package/src/package.ts +76 -2
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagrok/curves",
|
|
3
3
|
"friendlyName": "Curves",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.3.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.2.
|
|
12
|
-
"@datagrok-libraries/utils": "^4.1.
|
|
11
|
+
"@datagrok-libraries/statistics": "^1.2.13",
|
|
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
|
@@ -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_LEGEND_PX_WIDTH = 325;
|
|
56
|
+
const MIN_LEGEND_PX_HEIGHT = 275;
|
|
55
57
|
const MIN_DROPLINES_VISIBILITY_PX_WIDTH = 120;
|
|
56
58
|
const MIN_DROPLINES_VISIBILITY_PX_HEIGHT = 110;
|
|
57
59
|
const AXES_LEFT_PX_MARGIN = 38;
|
|
@@ -73,6 +75,15 @@ export const LINE_STYLES: {[key: string]: number[]} = {
|
|
|
73
75
|
};
|
|
74
76
|
|
|
75
77
|
|
|
78
|
+
function clamp(value: number, min: number, max: number): number {
|
|
79
|
+
return Math.min(Math.max(value, min), max);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect, message: string): void {
|
|
83
|
+
DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER, screenBounds.midX, screenBounds.midY, DG.Color.red,
|
|
84
|
+
clamp(Math.min(screenBounds.width, screenBounds.height) * 0.8,0, 30));
|
|
85
|
+
}
|
|
86
|
+
|
|
76
87
|
/** Merges properties of the two objects by iterating over the specified {@link properties}
|
|
77
88
|
* and assigning properties from {@link source} to {@link target} only when
|
|
78
89
|
* the property is not defined in target and is defined in source. */
|
|
@@ -86,6 +97,34 @@ export function mergeProperties(properties: DG.Property[], source: any, target:
|
|
|
86
97
|
}
|
|
87
98
|
}
|
|
88
99
|
|
|
100
|
+
export function mergeSeries(series: IFitSeries[]): IFitSeries | null {
|
|
101
|
+
if (series.length === 0)
|
|
102
|
+
return null;
|
|
103
|
+
const mergedSeries: IFitSeries = {
|
|
104
|
+
points: [],
|
|
105
|
+
name: series[0].name,
|
|
106
|
+
fitFunction: series[0].fitFunction,
|
|
107
|
+
markerType: series[0].markerType,
|
|
108
|
+
lineStyle: series[0].lineStyle,
|
|
109
|
+
pointColor: series[0].pointColor,
|
|
110
|
+
fitLineColor: series[0].fitLineColor,
|
|
111
|
+
confidenceIntervalColor: series[0].confidenceIntervalColor,
|
|
112
|
+
outlierColor: series[0].outlierColor,
|
|
113
|
+
connectDots: series[0].connectDots,
|
|
114
|
+
showFitLine: series[0].showFitLine,
|
|
115
|
+
showPoints: series[0].showPoints,
|
|
116
|
+
showCurveConfidenceInterval: series[0].showCurveConfidenceInterval,
|
|
117
|
+
errorModel: series[0].errorModel,
|
|
118
|
+
clickToToggle: series[0].clickToToggle,
|
|
119
|
+
labels: series[0].labels,
|
|
120
|
+
droplines: series[0].droplines,
|
|
121
|
+
columnName: series[0].columnName,
|
|
122
|
+
};
|
|
123
|
+
for (const s of series)
|
|
124
|
+
mergedSeries.points = [...mergedSeries.points, ...s.points];
|
|
125
|
+
return mergedSeries;
|
|
126
|
+
}
|
|
127
|
+
|
|
89
128
|
/** Constructs {@link IFitChartData} from the grid cell, taking into account
|
|
90
129
|
* chart and fit settings potentially defined on the dataframe and column level. */
|
|
91
130
|
export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
@@ -155,15 +194,16 @@ function drawCandlestick(g: CanvasRenderingContext2D, x: number, boxPlotStats: B
|
|
|
155
194
|
|
|
156
195
|
/** Performs points drawing */
|
|
157
196
|
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
158
|
-
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number): void {
|
|
197
|
+
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number, outlierColor: number): void {
|
|
159
198
|
for (let i = 0; i < series.points.length!; i++) {
|
|
160
199
|
const p = series.points[i];
|
|
161
|
-
const color = p.outlier ? DG.Color.
|
|
162
|
-
|
|
200
|
+
const color = !series.connectDots ? p.outlier ? (p.outlierColor ? DG.Color.fromHtml(p.outlierColor) ?
|
|
201
|
+
DG.Color.fromHtml(p.outlierColor) : outlierColor : outlierColor) : p.color ? DG.Color.fromHtml(p.color) ?
|
|
202
|
+
DG.Color.fromHtml(p.color) : pointColor : pointColor : pointColor;
|
|
163
203
|
const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
|
|
164
|
-
const size = p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio;
|
|
204
|
+
const size = !series.connectDots ? p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio : POINT_PX_SIZE * ratio;
|
|
165
205
|
DG.Paint.marker(g,
|
|
166
|
-
p.outlier ? DG.MARKER_TYPE.OUTLIER : marker,
|
|
206
|
+
!series.connectDots ? p.outlier ? DG.MARKER_TYPE.OUTLIER : marker : marker,
|
|
167
207
|
transform.xToScreen(p.x), transform.yToScreen(p.y), color, size);
|
|
168
208
|
if (p.stdev && !p.outlier) {
|
|
169
209
|
g.strokeStyle = DG.Color.toHtml(color);
|
|
@@ -274,7 +314,7 @@ function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue:
|
|
|
274
314
|
}
|
|
275
315
|
|
|
276
316
|
/** Performs x zeroes substitution if log x */
|
|
277
|
-
function substituteZeroes(data: IFitChartData): void {
|
|
317
|
+
export function substituteZeroes(data: IFitChartData): void {
|
|
278
318
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
279
319
|
const series = data.series![i];
|
|
280
320
|
if (series.points.every((p) => p.x !== 0))
|
|
@@ -318,8 +358,25 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
318
358
|
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
319
359
|
: getChartData(gridCell);
|
|
320
360
|
|
|
321
|
-
if (data.series?.
|
|
361
|
+
if (data.series?.length === 0) {
|
|
362
|
+
grok.shell.o = ui.divText('No series to show', {style: {color: 'red'}});
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (data.series?.some((series) => series.points.length === 0)) {
|
|
367
|
+
grok.shell.o = ui.divText('There were series with no points', {style: {color: 'red'}});
|
|
322
368
|
return;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (data.series?.some((series) => series.points.every((point) => point.x === 0))) {
|
|
372
|
+
grok.shell.o = ui.divText('There were series with all x zeroes', {style: {color: 'red'}});
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (data.series?.some((series) => series.points.every((point) => point.y === 0))) {
|
|
377
|
+
grok.shell.o = ui.divText('There were series with all y zeroes', {style: {color: 'red'}});
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
323
380
|
|
|
324
381
|
grok.shell.o = gridCell;
|
|
325
382
|
|
|
@@ -331,8 +388,8 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
331
388
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
332
389
|
|
|
333
390
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
334
|
-
if (!data.series![i].clickToToggle || data.series![i].showPoints !== 'points' ||
|
|
335
|
-
screenBounds.height < MIN_AXES_CELL_PX_HEIGHT)
|
|
391
|
+
if (data.series![i].connectDots || !data.series![i].clickToToggle || data.series![i].showPoints !== 'points' ||
|
|
392
|
+
screenBounds.width < MIN_AXES_CELL_PX_WIDTH || screenBounds.height < MIN_AXES_CELL_PX_HEIGHT)
|
|
336
393
|
continue;
|
|
337
394
|
for (let j = 0; j < data.series![i].points.length!; j++) {
|
|
338
395
|
const p = data.series![i].points[j];
|
|
@@ -407,6 +464,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
407
464
|
const showAxesLabels = w >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && h >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT
|
|
408
465
|
&& !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
|
|
409
466
|
const showTitle = w >= MIN_TITLE_PX_WIDTH && h >= MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
|
|
467
|
+
const showLegend = w >= MIN_LEGEND_PX_WIDTH && h >= MIN_LEGEND_PX_HEIGHT;
|
|
410
468
|
const showDroplines = w >= MIN_DROPLINES_VISIBILITY_PX_WIDTH && h >= MIN_DROPLINES_VISIBILITY_PX_HEIGHT;
|
|
411
469
|
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxesLabels, showTitle);
|
|
412
470
|
|
|
@@ -435,29 +493,54 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
435
493
|
data.chartOptions.showStatistics = [];
|
|
436
494
|
}
|
|
437
495
|
series.points.sort((a, b) => a.x - b.x);
|
|
496
|
+
|
|
497
|
+
if (series.connectDots ?? false) {
|
|
498
|
+
g.strokeStyle = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
|
|
499
|
+
series.pointColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
500
|
+
g.lineWidth = 2 * ratio;
|
|
501
|
+
g.beginPath();
|
|
502
|
+
for (let j = 0; j < series.points.length; j++) {
|
|
503
|
+
const x = series.points[j].x;
|
|
504
|
+
const y = series.points[j].y;
|
|
505
|
+
const screenX = viewport.xToScreen(x);
|
|
506
|
+
const screenY = viewport.yToScreen(y);
|
|
507
|
+
if (j === 0)
|
|
508
|
+
g.moveTo(screenX, screenY);
|
|
509
|
+
else
|
|
510
|
+
g.lineTo(screenX, screenY);
|
|
511
|
+
}
|
|
512
|
+
g.stroke();
|
|
513
|
+
}
|
|
514
|
+
|
|
438
515
|
let userParamsFlag = true;
|
|
439
516
|
const fitFunc = getSeriesFitFunction(series);
|
|
440
|
-
let curve: (x: number) => number;
|
|
441
|
-
if (series.
|
|
442
|
-
if (
|
|
443
|
-
if (
|
|
444
|
-
series.parameters[2]
|
|
517
|
+
let curve: ((x: number) => number) | null = null;
|
|
518
|
+
if (!(series.connectDots && !series.showFitLine)) {
|
|
519
|
+
if (series.parameters) {
|
|
520
|
+
if (data.chartOptions?.logX) {
|
|
521
|
+
if (series.parameters[2] > 0)
|
|
522
|
+
series.parameters[2] = Math.log10(series.parameters[2]);
|
|
523
|
+
}
|
|
524
|
+
curve = getCurve(series, fitFunc);
|
|
525
|
+
}
|
|
526
|
+
else {
|
|
527
|
+
const fitResult = fitSeries(series, fitFunc, chartLogOptions);
|
|
528
|
+
curve = fitResult.fittedCurve;
|
|
529
|
+
series.parameters = fitResult.parameters;
|
|
530
|
+
userParamsFlag = false;
|
|
445
531
|
}
|
|
446
|
-
curve = getCurve(series, fitFunc);
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
const fitResult = fitSeries(series, fitFunc, chartLogOptions);
|
|
450
|
-
curve = fitResult.fittedCurve;
|
|
451
|
-
series.parameters = fitResult.parameters;
|
|
452
|
-
userParamsFlag = false;
|
|
453
532
|
}
|
|
454
|
-
|
|
533
|
+
|
|
455
534
|
if (series.showPoints ?? 'points') {
|
|
456
535
|
const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
|
|
457
536
|
series.pointColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
537
|
+
const outlierColor = series.outlierColor ? DG.Color.fromHtml(series.outlierColor) ?
|
|
538
|
+
DG.Color.fromHtml(series.outlierColor) : DG.Color.red : DG.Color.red;
|
|
458
539
|
g.strokeStyle = pointColor;
|
|
459
|
-
if (series.showPoints
|
|
460
|
-
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor));
|
|
540
|
+
if (series.connectDots && series.showPoints != '')
|
|
541
|
+
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor), outlierColor);
|
|
542
|
+
else if (series.showPoints === 'points')
|
|
543
|
+
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor), outlierColor);
|
|
461
544
|
else if (['candlesticks', 'both'].includes(series.showPoints!))
|
|
462
545
|
drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
|
|
463
546
|
}
|
|
@@ -477,7 +560,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
477
560
|
for (let j = axesLeftPxMargin; j <= screenBounds.width - axesRightPxMargin; j++) {
|
|
478
561
|
const x = screenBounds.x + j;
|
|
479
562
|
const xForY = data.chartOptions?.logX ? Math.log10(viewport.xToWorld(x)) : viewport.xToWorld(x);
|
|
480
|
-
const y = data.chartOptions?.logY ? viewport.yToScreen(Math.pow(10, curve(xForY))) : viewport.yToScreen(curve(xForY));
|
|
563
|
+
const y = data.chartOptions?.logY ? viewport.yToScreen(Math.pow(10, curve!(xForY))) : viewport.yToScreen(curve!(xForY));
|
|
481
564
|
if (j === axesLeftPxMargin)
|
|
482
565
|
g.moveTo(x, y);
|
|
483
566
|
else
|
|
@@ -499,7 +582,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
499
582
|
fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, showAxes, showAxesLabels, chartLogOptions);
|
|
500
583
|
}
|
|
501
584
|
|
|
502
|
-
if (series.droplines && showDroplines) {
|
|
585
|
+
if ((series.showFitLine ?? true) && series.droplines && showDroplines) {
|
|
503
586
|
g.save();
|
|
504
587
|
g.strokeStyle = 'blue';
|
|
505
588
|
g.lineWidth = ratio;
|
|
@@ -508,13 +591,13 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
508
591
|
for (let j = 0; j < series.droplines.length; j++) {
|
|
509
592
|
const droplineName = series.droplines[j];
|
|
510
593
|
if (droplineName === 'IC50')
|
|
511
|
-
drawDropline(g, viewport, series.parameters[2], dataBounds, curve
|
|
594
|
+
drawDropline(g, viewport, series.parameters![2], dataBounds, curve!, chartLogOptions);
|
|
512
595
|
}
|
|
513
596
|
g.stroke();
|
|
514
597
|
g.restore();
|
|
515
598
|
}
|
|
516
599
|
|
|
517
|
-
if (data.chartOptions?.showStatistics) {
|
|
600
|
+
if ((series.showFitLine ?? true) && data.chartOptions?.showStatistics) {
|
|
518
601
|
const statistics = getSeriesStatistics(series, fitFunc, chartLogOptions);
|
|
519
602
|
for (let j = 0; j < data.chartOptions.showStatistics.length; j++) {
|
|
520
603
|
const statName = data.chartOptions.showStatistics[j];
|
|
@@ -550,6 +633,30 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
550
633
|
g.restore();
|
|
551
634
|
}
|
|
552
635
|
|
|
636
|
+
if (showLegend) {
|
|
637
|
+
g.font = '11px Roboto, "Roboto Local"';
|
|
638
|
+
for (let i = 0; i < data.series?.length!; i++) {
|
|
639
|
+
g.beginPath();
|
|
640
|
+
const series = data.series![i];
|
|
641
|
+
const lineColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
|
|
642
|
+
series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
643
|
+
const markerColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
|
|
644
|
+
DG.Color.fromHtml(series.pointColor) : DG.Color.getCategoricalColor(i) : DG.Color.getCategoricalColor(i);
|
|
645
|
+
g.strokeStyle = lineColor;
|
|
646
|
+
g.lineWidth = 2 * ratio;
|
|
647
|
+
const text = `${data.chartOptions?.showColumnLabel ? series.columnName ?? '' : ''} ${series.name ?? ''}`;
|
|
648
|
+
const textWidth = g.measureText(text).width;
|
|
649
|
+
g.moveTo(dataBox.maxX - textWidth - 25, dataBox.y + 20 - 4 + 20 * i);
|
|
650
|
+
g.lineTo(dataBox.maxX - textWidth - 5, dataBox.y + 20 - 4 + 20 * i);
|
|
651
|
+
const marker = series.markerType ? series.markerType as DG.MARKER_TYPE : DG.MARKER_TYPE.CIRCLE;
|
|
652
|
+
DG.Paint.marker(g, marker, dataBox.maxX - textWidth - 25 + (20 / 2), dataBox.y + 20 - 4 + 20 * i, markerColor, POINT_PX_SIZE * ratio);
|
|
653
|
+
g.fillStyle = 'black';
|
|
654
|
+
g.fillText(text, dataBox.maxX - textWidth, dataBox.y + 20 + 20 * i);
|
|
655
|
+
g.stroke();
|
|
656
|
+
}
|
|
657
|
+
g.restore();
|
|
658
|
+
}
|
|
659
|
+
|
|
553
660
|
g.restore();
|
|
554
661
|
}
|
|
555
662
|
|
|
@@ -565,8 +672,31 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
565
672
|
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
566
673
|
: getChartData(gridCell);
|
|
567
674
|
|
|
568
|
-
|
|
675
|
+
const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
676
|
+
|
|
677
|
+
if (data.series?.length === 0) {
|
|
678
|
+
showIncorrectFitCell(g, screenBounds,'No series to show');
|
|
569
679
|
return;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
if (data.series?.some((series) => series.points.length === 0)) {
|
|
683
|
+
showIncorrectFitCell(g, screenBounds, 'There were series with no points');
|
|
684
|
+
return;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
if (data.series?.some((series) => series.points.every((point) => point.x === 0))) {
|
|
688
|
+
showIncorrectFitCell(g, screenBounds, 'There were series with all x zeroes');
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if (data.series?.some((series) => series.points.every((point) => point.y === 0))) {
|
|
693
|
+
showIncorrectFitCell(g, screenBounds, 'There were series with all y zeroes');
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
data.series?.forEach((series) => series.columnName = gridCell.cell.column.name);
|
|
698
|
+
if (data.chartOptions?.mergeSeries)
|
|
699
|
+
data.series = [mergeSeries(data.series!)!];
|
|
570
700
|
|
|
571
701
|
this.renderCurves(g, x, y, w, h, data);
|
|
572
702
|
}
|
|
@@ -588,27 +718,33 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
588
718
|
: getChartData(gridCell);
|
|
589
719
|
|
|
590
720
|
const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
721
|
+
if (screenBounds.width >= MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH && screenBounds.height >= MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
722
|
+
const showAxesLabels = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
|
|
723
|
+
const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
|
|
724
|
+
const dataBox = layoutChart(screenBounds, showAxesLabels, showTitle)[0];
|
|
725
|
+
const dataBounds = getChartBounds(data);
|
|
726
|
+
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
727
|
+
|
|
728
|
+
for (let i = 0; i < data.series?.length!; i++) {
|
|
729
|
+
if (data.series![i].showPoints !== 'points')
|
|
730
|
+
continue;
|
|
731
|
+
for (let j = 0; j < data.series![i].points.length!; j++) {
|
|
732
|
+
const p = data.series![i].points[j];
|
|
733
|
+
const screenX = viewport.xToScreen(p.x);
|
|
734
|
+
const screenY = viewport.yToScreen(p.y);
|
|
735
|
+
const pxPerMarkerType = ((p.outlier ? OUTLIER_PX_SIZE : POINT_PX_SIZE) / 2) + OUTLIER_HITBOX_RADIUS;
|
|
736
|
+
if (e.offsetX >= screenX - pxPerMarkerType && e.offsetX <= screenX + pxPerMarkerType &&
|
|
737
|
+
e.offsetY >= screenY - pxPerMarkerType && e.offsetY <= screenY + pxPerMarkerType) {
|
|
738
|
+
ui.tooltip.show(ui.divV([ui.divText(`x: ${DG.format(p.x, '#0.000')}`),
|
|
739
|
+
ui.divText(`y: ${DG.format(p.y, '#0.000')}`)]), e.x + 16, e.y + 16);
|
|
740
|
+
if (!data.series![i].connectDots && data.series![i].clickToToggle && screenBounds.width >= MIN_AXES_CELL_PX_WIDTH &&
|
|
741
|
+
screenBounds.height >= MIN_AXES_CELL_PX_HEIGHT)
|
|
742
|
+
document.body.style.cursor = 'pointer';
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
610
745
|
}
|
|
611
746
|
}
|
|
747
|
+
ui.tooltip.hide();
|
|
612
748
|
}
|
|
613
749
|
document.body.style.cursor = 'default';
|
|
614
750
|
}
|