@datagrok/curves 1.3.0 → 1.4.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 +19 -0
- package/README.md +2 -3
- 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/const.ts +72 -0
- package/src/fit/fit-demo.ts +6 -3
- package/src/fit/fit-grid-cell-handler.ts +40 -25
- package/src/fit/fit-renderer.ts +177 -427
- package/src/fit/multi-curve-viewer.ts +55 -10
- package/src/fit/render-utils.ts +430 -0
- package/src/package.ts +4 -3
- package/src/tests/curves-cell-renderer-tests.ts +3 -2
- package/src/tests/detector-tests.ts +6 -7
- package/src/tests/fit-tests.ts +24 -20
- package/src/tests/transform-tests.ts +3 -2
- package/webpack.config.js +3 -0
package/src/fit/fit-renderer.ts
CHANGED
|
@@ -3,83 +3,41 @@ import * as grok from 'datagrok-api/grok';
|
|
|
3
3
|
import * as ui from 'datagrok-api/ui';
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
|
-
statisticsProperties,
|
|
7
|
-
FitConfidenceIntervals,
|
|
8
6
|
IFitChartData,
|
|
9
|
-
CONFIDENCE_INTERVAL_FILL_COLOR,
|
|
10
|
-
CONFIDENCE_INTERVAL_STROKE_COLOR,
|
|
11
|
-
CURVE_CONFIDENCE_INTERVAL_BOUNDS,
|
|
12
|
-
FIT_CELL_TYPE,
|
|
13
7
|
IFitSeries,
|
|
14
8
|
FitStatistics,
|
|
15
9
|
fitChartDataProperties,
|
|
16
|
-
fitSeriesProperties,
|
|
10
|
+
fitSeriesProperties, IFitChartOptions, IFitPoint,
|
|
17
11
|
} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
18
|
-
import {BoxPlotStatistics, calculateBoxPlotStatistics} from '@datagrok-libraries/statistics/src/box-plot-statistics';
|
|
19
12
|
import {Viewport} from '@datagrok-libraries/utils/src/transform';
|
|
20
|
-
import {StringUtils} from '@datagrok-libraries/utils/src/string-utils';
|
|
21
13
|
|
|
22
14
|
import {
|
|
23
15
|
fitSeries,
|
|
24
16
|
createDefaultChartData,
|
|
25
17
|
getChartBounds,
|
|
26
18
|
getSeriesFitFunction,
|
|
27
|
-
getSeriesConfidenceInterval,
|
|
28
|
-
getSeriesStatistics,
|
|
29
19
|
getCurve,
|
|
30
|
-
getColumnChartOptions,
|
|
31
20
|
LogOptions,
|
|
32
|
-
getDataFrameChartOptions
|
|
33
21
|
} from '@datagrok-libraries/statistics/src/fit/fit-data';
|
|
34
22
|
|
|
35
23
|
import {convertXMLToIFitChartData} from './fit-parser';
|
|
36
24
|
import {CellRenderViewer} from './cell-render-viewer';
|
|
37
25
|
import { calculateSeriesStats, getChartDataAggrStats } from './fit-grid-cell-handler';
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const OUTLIER_PX_SIZE = 12;
|
|
47
|
-
const POINT_PX_SIZE = 4;
|
|
48
|
-
const OUTLIER_HITBOX_RADIUS = 2;
|
|
49
|
-
const MIN_AXES_CELL_PX_WIDTH = 100;
|
|
50
|
-
const MIN_AXES_CELL_PX_HEIGHT = 55;
|
|
51
|
-
const MIN_TITLE_PX_WIDTH = 275;
|
|
52
|
-
const MIN_TITLE_PX_HEIGHT = 225;
|
|
53
|
-
const MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH = 180;
|
|
54
|
-
const MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT = 140;
|
|
55
|
-
const MIN_LEGEND_PX_WIDTH = 325;
|
|
56
|
-
const MIN_LEGEND_PX_HEIGHT = 275;
|
|
57
|
-
const MIN_DROPLINES_VISIBILITY_PX_WIDTH = 120;
|
|
58
|
-
const MIN_DROPLINES_VISIBILITY_PX_HEIGHT = 110;
|
|
59
|
-
const AXES_LEFT_PX_MARGIN = 38;
|
|
60
|
-
const AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS = 45;
|
|
61
|
-
const AXES_TOP_PX_MARGIN = 5;
|
|
62
|
-
const AXES_TOP_PX_MARGIN_WITH_TITLE = 25;
|
|
63
|
-
const AXES_RIGHT_PX_MARGIN = 18;
|
|
64
|
-
const AXES_BOTTOM_PX_MARGIN = 15;
|
|
65
|
-
const AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS = 30;
|
|
66
|
-
const CANDLESTICK_BORDER_PX_SIZE = 4;
|
|
67
|
-
const CANDLESTICK_MEDIAN_PX_SIZE = 3.5;
|
|
68
|
-
const CANDLESTICK_OUTLIER_PX_SIZE = 6;
|
|
69
|
-
export const INFLATE_SIZE = -12;
|
|
70
|
-
export const LINE_STYLES: {[key: string]: number[]} = {
|
|
71
|
-
'solid': [],
|
|
72
|
-
'dotted': [1, 1],
|
|
73
|
-
'dashed': [5, 5],
|
|
74
|
-
'dashdotted': [5, 5, 2, 5],
|
|
75
|
-
};
|
|
26
|
+
import {FitConstants} from './const';
|
|
27
|
+
import {
|
|
28
|
+
assignSeriesColors, renderAxesLabels,
|
|
29
|
+
renderConfidenceIntervals, renderConnectDots,
|
|
30
|
+
renderDroplines,
|
|
31
|
+
renderFitLine, renderLegend,
|
|
32
|
+
renderPoints, renderStatistics, renderTitle
|
|
33
|
+
} from './render-utils';
|
|
76
34
|
|
|
77
35
|
|
|
78
36
|
function clamp(value: number, min: number, max: number): number {
|
|
79
37
|
return Math.min(Math.max(value, min), max);
|
|
80
38
|
}
|
|
81
39
|
|
|
82
|
-
function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect
|
|
40
|
+
function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect): void {
|
|
83
41
|
DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER, screenBounds.midX, screenBounds.midY, DG.Color.red,
|
|
84
42
|
clamp(Math.min(screenBounds.width, screenBounds.height) * 0.8,0, 30));
|
|
85
43
|
}
|
|
@@ -97,6 +55,58 @@ export function mergeProperties(properties: DG.Property[], source: any, target:
|
|
|
97
55
|
}
|
|
98
56
|
}
|
|
99
57
|
|
|
58
|
+
export function mergeChartOptions(chartOptions: IFitChartOptions[]): IFitChartOptions {
|
|
59
|
+
if (chartOptions.length === 0)
|
|
60
|
+
return {};
|
|
61
|
+
|
|
62
|
+
let minX = Number.MAX_VALUE;
|
|
63
|
+
let minY = Number.MAX_VALUE;
|
|
64
|
+
let maxX = Number.MIN_VALUE;
|
|
65
|
+
let maxY = Number.MIN_VALUE;
|
|
66
|
+
let xAxisName: string | undefined;
|
|
67
|
+
let yAxisName: string | undefined;
|
|
68
|
+
let title: string | undefined;
|
|
69
|
+
let logX: boolean = false;
|
|
70
|
+
let logY: boolean = false;
|
|
71
|
+
let allowXZeroes: boolean = false;
|
|
72
|
+
|
|
73
|
+
for (const options of chartOptions) {
|
|
74
|
+
if (options.minX !== null && options.minX !== undefined)
|
|
75
|
+
minX = Math.min(minX, options.minX);
|
|
76
|
+
if (options.minY !== null && options.minY !== undefined)
|
|
77
|
+
minY = Math.min(minY, options.minY);
|
|
78
|
+
if (options.maxX !== null && options.maxX !== undefined)
|
|
79
|
+
maxX = Math.max(maxX, options.maxX);
|
|
80
|
+
if (options.maxY !== null && options.maxY !== undefined)
|
|
81
|
+
maxY = Math.max(maxY, options.maxY);
|
|
82
|
+
if (options.title !== null && options.title !== undefined)
|
|
83
|
+
title ??= options.title;
|
|
84
|
+
if (options.xAxisName !== null && options.xAxisName !== undefined)
|
|
85
|
+
xAxisName ??= options.xAxisName;
|
|
86
|
+
if (options.yAxisName !== null && options.yAxisName !== undefined)
|
|
87
|
+
yAxisName ??= options.yAxisName;
|
|
88
|
+
if (options.logX !== null && options.logX !== undefined && options.logX)
|
|
89
|
+
logX = true;
|
|
90
|
+
if (options.logY !== null && options.logY !== undefined && options.logY)
|
|
91
|
+
logY = true;
|
|
92
|
+
if (options.allowXZeroes !== null && options.allowXZeroes !== undefined && options.allowXZeroes)
|
|
93
|
+
allowXZeroes = true;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
minX: minX === Number.MAX_VALUE ? undefined : minX,
|
|
98
|
+
minY: minY === Number.MAX_VALUE ? undefined : minY,
|
|
99
|
+
maxX: maxX === Number.MIN_VALUE ? undefined : maxX,
|
|
100
|
+
maxY: maxY === Number.MIN_VALUE ? undefined : maxY,
|
|
101
|
+
title: title,
|
|
102
|
+
xAxisName: xAxisName,
|
|
103
|
+
yAxisName: yAxisName,
|
|
104
|
+
logX: logX,
|
|
105
|
+
logY: logY,
|
|
106
|
+
allowXZeroes: allowXZeroes,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
100
110
|
export function mergeSeries(series: IFitSeries[]): IFitSeries | null {
|
|
101
111
|
if (series.length === 0)
|
|
102
112
|
return null;
|
|
@@ -133,7 +143,7 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
|
133
143
|
if (cellValue.includes('|'))
|
|
134
144
|
cellValue = cellValue.replaceAll('|', '');
|
|
135
145
|
const cellChartData: IFitChartData = gridCell.cell?.column?.type === DG.TYPE.STRING ?
|
|
136
|
-
(gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
146
|
+
(gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
137
147
|
convertXMLToIFitChartData(cellValue) :
|
|
138
148
|
JSON.parse(cellValue ?? '{}') ?? {}) : createDefaultChartData();
|
|
139
149
|
|
|
@@ -147,6 +157,7 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
|
147
157
|
mergeProperties(fitChartDataProperties, columnChartOptions.chartOptions, cellChartData.chartOptions);
|
|
148
158
|
mergeProperties(fitChartDataProperties, dfChartOptions.chartOptions, cellChartData.chartOptions);
|
|
149
159
|
for (const series of cellChartData.series) {
|
|
160
|
+
mergeProperties(fitSeriesProperties, cellChartData.seriesOptions, series);
|
|
150
161
|
mergeProperties(fitSeriesProperties, columnChartOptions.seriesOptions, series);
|
|
151
162
|
mergeProperties(fitSeriesProperties, dfChartOptions.seriesOptions, series);
|
|
152
163
|
}
|
|
@@ -154,17 +165,27 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
|
154
165
|
return cellChartData;
|
|
155
166
|
}
|
|
156
167
|
|
|
168
|
+
/** Returns existing, or creates new dataframe default chart options. */
|
|
169
|
+
export function getDataFrameChartOptions(df: DG.DataFrame): IFitChartData {
|
|
170
|
+
return JSON.parse(df.tags[FitConstants.TAG_FIT] ??= JSON.stringify(createDefaultChartData()));
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Returns existing, or creates new column default chart options. */
|
|
174
|
+
export function getColumnChartOptions(column: DG.Column): IFitChartData {
|
|
175
|
+
return JSON.parse(column.tags[FitConstants.TAG_FIT] ??= JSON.stringify(createDefaultChartData()));
|
|
176
|
+
}
|
|
177
|
+
|
|
157
178
|
/** Performs a chart layout, returning [viewport, xAxis, yAxis] */
|
|
158
179
|
export function layoutChart(rect: DG.Rect, showAxesLabels: boolean, showTitle: boolean): [DG.Rect, DG.Rect?, DG.Rect?] {
|
|
159
|
-
if (rect.width < MIN_AXES_CELL_PX_WIDTH || rect.height < MIN_AXES_CELL_PX_HEIGHT)
|
|
180
|
+
if (rect.width < FitConstants.MIN_AXES_CELL_PX_WIDTH || rect.height < FitConstants.MIN_AXES_CELL_PX_HEIGHT)
|
|
160
181
|
return [rect, undefined, undefined];
|
|
161
|
-
const axesLeftPxMargin = showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
|
|
162
|
-
const axesBottomPxMargin = showAxesLabels ? AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS : AXES_BOTTOM_PX_MARGIN;
|
|
163
|
-
const axesTopPxMargin = showTitle ? AXES_TOP_PX_MARGIN_WITH_TITLE : AXES_TOP_PX_MARGIN;
|
|
182
|
+
const axesLeftPxMargin = showAxesLabels ? FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN;
|
|
183
|
+
const axesBottomPxMargin = showAxesLabels ? FitConstants.AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_BOTTOM_PX_MARGIN;
|
|
184
|
+
const axesTopPxMargin = showTitle ? FitConstants.AXES_TOP_PX_MARGIN_WITH_TITLE : FitConstants.AXES_TOP_PX_MARGIN;
|
|
164
185
|
return [
|
|
165
|
-
rect.cutLeft(axesLeftPxMargin).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin).cutRight(AXES_RIGHT_PX_MARGIN),
|
|
166
|
-
rect.getBottom(axesBottomPxMargin).getTop(axesTopPxMargin).cutLeft(axesLeftPxMargin).cutRight(AXES_RIGHT_PX_MARGIN),
|
|
167
|
-
rect.getLeft(axesLeftPxMargin).getRight(AXES_RIGHT_PX_MARGIN).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin)
|
|
186
|
+
rect.cutLeft(axesLeftPxMargin).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin).cutRight(FitConstants.AXES_RIGHT_PX_MARGIN),
|
|
187
|
+
rect.getBottom(axesBottomPxMargin).getTop(axesTopPxMargin).cutLeft(axesLeftPxMargin).cutRight(FitConstants.AXES_RIGHT_PX_MARGIN),
|
|
188
|
+
rect.getLeft(axesLeftPxMargin).getRight(FitConstants.AXES_RIGHT_PX_MARGIN).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin)
|
|
168
189
|
];
|
|
169
190
|
}
|
|
170
191
|
|
|
@@ -175,144 +196,6 @@ export function isColorValid(color: string | null | undefined): boolean {
|
|
|
175
196
|
return DG.Color.fromHtml(color) !== undefined;
|
|
176
197
|
}
|
|
177
198
|
|
|
178
|
-
/** Performs candlestick border drawing */
|
|
179
|
-
function drawCandlestickBorder(g: CanvasRenderingContext2D, x: number, adjacentValue: number, transform: Viewport): void {
|
|
180
|
-
g.moveTo(transform.xToScreen(x) - (CANDLESTICK_BORDER_PX_SIZE / 2), transform.yToScreen(adjacentValue));
|
|
181
|
-
g.lineTo(transform.xToScreen(x) + (CANDLESTICK_BORDER_PX_SIZE / 2), transform.yToScreen(adjacentValue));
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/** Performs candlestick drawing */
|
|
185
|
-
function drawCandlestick(g: CanvasRenderingContext2D, x: number, boxPlotStats: BoxPlotStatistics,
|
|
186
|
-
transform: Viewport, ratio: number, markerColor: number): void {
|
|
187
|
-
drawCandlestickBorder(g, x, boxPlotStats.lowerAdjacentValue, transform);
|
|
188
|
-
g.moveTo(transform.xToScreen(x), transform.yToScreen(boxPlotStats.lowerAdjacentValue));
|
|
189
|
-
g.lineTo(transform.xToScreen(x), transform.yToScreen(boxPlotStats.upperAdjacentValue));
|
|
190
|
-
drawCandlestickBorder(g, x, boxPlotStats.upperAdjacentValue, transform);
|
|
191
|
-
DG.Paint.marker(g, DG.MARKER_TYPE.CIRCLE, transform.xToScreen(x), transform.yToScreen(boxPlotStats.q2),
|
|
192
|
-
markerColor, CANDLESTICK_MEDIAN_PX_SIZE * ratio);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/** Performs points drawing */
|
|
196
|
-
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
197
|
-
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number, outlierColor: number): void {
|
|
198
|
-
for (let i = 0; i < series.points.length!; i++) {
|
|
199
|
-
const p = series.points[i];
|
|
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;
|
|
203
|
-
const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
|
|
204
|
-
const size = !series.connectDots ? p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio : POINT_PX_SIZE * ratio;
|
|
205
|
-
DG.Paint.marker(g,
|
|
206
|
-
!series.connectDots ? p.outlier ? DG.MARKER_TYPE.OUTLIER : marker : marker,
|
|
207
|
-
transform.xToScreen(p.x), transform.yToScreen(p.y), color, size);
|
|
208
|
-
if (p.stdev && !p.outlier) {
|
|
209
|
-
g.strokeStyle = DG.Color.toHtml(color);
|
|
210
|
-
g.beginPath();
|
|
211
|
-
g.moveTo(transform.xToScreen(p.x), transform.yToScreen(p.y + p.stdev));
|
|
212
|
-
g.lineTo(transform.xToScreen(p.x), transform.yToScreen(p.y - p.stdev));
|
|
213
|
-
g.stroke();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/** Performs candles drawing */
|
|
219
|
-
function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
220
|
-
transform: Viewport, ratio: number, markerColor: number) : void {
|
|
221
|
-
for (let i = 0, candleStart = null; i < series.points.length!; i++) {
|
|
222
|
-
const p = series.points[i];
|
|
223
|
-
if (p.outlier)
|
|
224
|
-
continue;
|
|
225
|
-
const nextSame = i + 1 < series.points.length && series.points[i + 1].x === p.x;
|
|
226
|
-
if (!candleStart && nextSame)
|
|
227
|
-
candleStart = i;
|
|
228
|
-
else if (candleStart !== null && !nextSame) {
|
|
229
|
-
const values: number[] = [];
|
|
230
|
-
for (let j = candleStart, ind = 0; j <= i; j++, ind++) {
|
|
231
|
-
values[ind] = series.points[j].y;
|
|
232
|
-
}
|
|
233
|
-
const boxPlotStats = calculateBoxPlotStatistics(values);
|
|
234
|
-
|
|
235
|
-
g.beginPath();
|
|
236
|
-
drawCandlestick(g, p.x, boxPlotStats, transform, ratio, markerColor);
|
|
237
|
-
g.stroke();
|
|
238
|
-
|
|
239
|
-
if (series.showPoints === 'both') {
|
|
240
|
-
for (let ind = 0; ind < values.length; ind++) {
|
|
241
|
-
if (values[ind] < boxPlotStats.lowerAdjacentValue || values[ind] > boxPlotStats.upperAdjacentValue) {
|
|
242
|
-
DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER,
|
|
243
|
-
transform.xToScreen(p.x), transform.yToScreen(values[ind]),
|
|
244
|
-
series.pointColor ? DG.Color.fromHtml(series.pointColor) : DG.Color.scatterPlotMarker,
|
|
245
|
-
CANDLESTICK_OUTLIER_PX_SIZE * ratio);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
candleStart = null;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/** Performs a curve confidence interval drawing */
|
|
256
|
-
function drawConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals, screenBounds: DG.Rect,
|
|
257
|
-
transform: Viewport, confidenceType: string, showAxes: boolean, showAxesLabels: boolean, logOptions: LogOptions): void {
|
|
258
|
-
g.beginPath();
|
|
259
|
-
const axesLeftPxMargin = showAxes ? showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN : 0;
|
|
260
|
-
const axesRightPxMargin = showAxes ? AXES_RIGHT_PX_MARGIN : 0;
|
|
261
|
-
const confIntervalFunc = confidenceType === CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
|
|
262
|
-
confIntervals.confidenceTop : confIntervals.confidenceBottom;
|
|
263
|
-
for (let i = axesLeftPxMargin; i <= screenBounds.width - axesRightPxMargin; i++) {
|
|
264
|
-
const x = screenBounds.x + i;
|
|
265
|
-
const xForY = logOptions.logX ? Math.log10(transform.xToWorld(x)) : transform.xToWorld(x);
|
|
266
|
-
const y = logOptions.logY ? transform.yToScreen(Math.pow(10, confIntervalFunc(xForY))) : transform.yToScreen(confIntervalFunc(xForY));
|
|
267
|
-
if (i === axesLeftPxMargin)
|
|
268
|
-
g.moveTo(x, y);
|
|
269
|
-
else
|
|
270
|
-
g.lineTo(x, y);
|
|
271
|
-
}
|
|
272
|
-
g.stroke();
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/** Performs a curve confidence interval color filling */
|
|
276
|
-
function fillConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals, screenBounds: DG.Rect,
|
|
277
|
-
transform: Viewport, showAxes: boolean, showAxesLabels: boolean, logOptions: LogOptions): void {
|
|
278
|
-
g.beginPath();
|
|
279
|
-
const axesLeftPxMargin = showAxes ? showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN : 0;
|
|
280
|
-
const axesRightPxMargin = showAxes ? AXES_RIGHT_PX_MARGIN : 0;
|
|
281
|
-
for (let i = axesLeftPxMargin; i <= screenBounds.width - axesRightPxMargin; i++) {
|
|
282
|
-
const x = screenBounds.x + i;
|
|
283
|
-
const xForY = logOptions.logX ? Math.log10(transform.xToWorld(x)) : transform.xToWorld(x);
|
|
284
|
-
const y = logOptions.logY ? transform.yToScreen(Math.pow(10, confIntervals.confidenceTop(xForY))) :
|
|
285
|
-
transform.yToScreen(confIntervals.confidenceTop(xForY));
|
|
286
|
-
if (i === axesLeftPxMargin)
|
|
287
|
-
g.moveTo(x, y);
|
|
288
|
-
else
|
|
289
|
-
g.lineTo(x, y);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// reverse traverse to make a shape of confidence interval to fill it
|
|
293
|
-
for (let i = screenBounds.width - axesRightPxMargin; i >= axesLeftPxMargin; i--) {
|
|
294
|
-
const x = screenBounds.x + i;
|
|
295
|
-
const xForY = logOptions.logX ? Math.log10(transform.xToWorld(x)) : transform.xToWorld(x);
|
|
296
|
-
const y = logOptions.logY ? transform.yToScreen(Math.pow(10, confIntervals.confidenceBottom(xForY))) :
|
|
297
|
-
transform.yToScreen(confIntervals.confidenceBottom(xForY));
|
|
298
|
-
g.lineTo(x, y);
|
|
299
|
-
}
|
|
300
|
-
g.closePath();
|
|
301
|
-
g.fill();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/** Performs a dropline drawing */
|
|
305
|
-
function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue: number, dataBounds: DG.Rect,
|
|
306
|
-
curve: (x: number) => number, logOptions: LogOptions): void {
|
|
307
|
-
if (logOptions.logX)
|
|
308
|
-
xValue = Math.pow(10, xValue);
|
|
309
|
-
const xForY = logOptions.logX ? Math.log10(xValue) : xValue;
|
|
310
|
-
const y = logOptions.logY ? Math.pow(10, curve(xForY)) : curve(xForY);
|
|
311
|
-
g.moveTo(transform.xToScreen(dataBounds.minX), transform.yToScreen(y));
|
|
312
|
-
g.lineTo(transform.xToScreen(xValue), transform.yToScreen(y));
|
|
313
|
-
g.lineTo(transform.xToScreen(xValue), transform.yToScreen(dataBounds.minY));
|
|
314
|
-
}
|
|
315
|
-
|
|
316
199
|
/** Performs x zeroes substitution if log x */
|
|
317
200
|
export function substituteZeroes(data: IFitChartData): void {
|
|
318
201
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
@@ -342,62 +225,43 @@ export function substituteZeroes(data: IFitChartData): void {
|
|
|
342
225
|
}
|
|
343
226
|
|
|
344
227
|
export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
345
|
-
get name() { return FIT_CELL_TYPE; }
|
|
228
|
+
get name() { return FitConstants.FIT_CELL_TYPE; }
|
|
346
229
|
|
|
347
|
-
get cellType() { return FIT_CELL_TYPE; }
|
|
230
|
+
get cellType() { return FitConstants.FIT_CELL_TYPE; }
|
|
348
231
|
|
|
349
232
|
getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
|
|
350
|
-
return {width:
|
|
233
|
+
return {width: FitConstants.CELL_DEFAULT_WIDTH, height: FitConstants.CELL_DEFAULT_HEIGHT};
|
|
351
234
|
}
|
|
352
235
|
|
|
353
236
|
onClick(gridCell: DG.GridCell, e: MouseEvent): void {
|
|
354
237
|
if (!gridCell.cell.value)
|
|
355
238
|
return;
|
|
356
239
|
|
|
357
|
-
const data = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX
|
|
358
|
-
|
|
359
|
-
: getChartData(gridCell);
|
|
360
|
-
|
|
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'}});
|
|
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
|
-
}
|
|
240
|
+
const data = gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
241
|
+
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
375
242
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
243
|
+
for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
244
|
+
if (condition(data.series)) {
|
|
245
|
+
grok.shell.o = ui.divText(message, {style: {color: 'red'}});
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
379
248
|
}
|
|
380
249
|
|
|
381
250
|
grok.shell.o = gridCell;
|
|
382
251
|
|
|
383
|
-
const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
const dataBox = layoutChart(screenBounds, showAxesLabels, showTitle)[0];
|
|
252
|
+
const screenBounds = gridCell.bounds.inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
|
|
253
|
+
const dataBox = layoutChart(screenBounds, this.areAxesLabelsShown(screenBounds, data),
|
|
254
|
+
this.isTitleShown(screenBounds, data))[0];
|
|
387
255
|
const dataBounds = getChartBounds(data);
|
|
388
256
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
389
257
|
|
|
390
258
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
391
259
|
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)
|
|
260
|
+
screenBounds.width < FitConstants.MIN_AXES_CELL_PX_WIDTH || screenBounds.height < FitConstants.MIN_AXES_CELL_PX_HEIGHT)
|
|
393
261
|
continue;
|
|
394
262
|
for (let j = 0; j < data.series![i].points.length!; j++) {
|
|
395
263
|
const p = data.series![i].points[j];
|
|
396
|
-
|
|
397
|
-
const screenY = viewport.yToScreen(p.y);
|
|
398
|
-
const pxPerMarkerType = ((p.outlier ? OUTLIER_PX_SIZE : POINT_PX_SIZE) / 2) + OUTLIER_HITBOX_RADIUS;
|
|
399
|
-
if (e.offsetX >= screenX - pxPerMarkerType && e.offsetX <= screenX + pxPerMarkerType &&
|
|
400
|
-
e.offsetY >= screenY - pxPerMarkerType && e.offsetY <= screenY + pxPerMarkerType) {
|
|
264
|
+
if (this.hitTest(e, p, viewport)) {
|
|
401
265
|
p.outlier = !p.outlier;
|
|
402
266
|
const columns = gridCell.grid.dataFrame.columns.byTags({'.sourceColumn': gridCell.cell.column.name});
|
|
403
267
|
if (columns) {
|
|
@@ -413,7 +277,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
413
277
|
}
|
|
414
278
|
|
|
415
279
|
// temporarily works only for JSON structure
|
|
416
|
-
if (gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) !== TAG_FIT_CHART_FORMAT_3DX) {
|
|
280
|
+
if (gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) !== FitConstants.TAG_FIT_CHART_FORMAT_3DX) {
|
|
417
281
|
const gridCellValue = JSON.parse(gridCell.cell.value) as IFitChartData;
|
|
418
282
|
gridCellValue.series![i].points[j].outlier = p.outlier;
|
|
419
283
|
gridCell.cell.value = JSON.stringify(gridCellValue);
|
|
@@ -450,28 +314,45 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
450
314
|
});
|
|
451
315
|
}
|
|
452
316
|
|
|
453
|
-
|
|
317
|
+
areAxesShown(screenBounds: DG.Rect): boolean {
|
|
318
|
+
return screenBounds.width >= FitConstants.MIN_AXES_CELL_PX_WIDTH && screenBounds.height >= FitConstants.MIN_AXES_CELL_PX_HEIGHT;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
areAxesLabelsShown(screenBounds: DG.Rect, data: IFitChartData): boolean {
|
|
322
|
+
// TODO: make bigger sizes
|
|
323
|
+
return screenBounds.width >= FitConstants.MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH &&
|
|
324
|
+
screenBounds.height >= FitConstants.MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT && !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
isTitleShown(screenBounds: DG.Rect, data: IFitChartData): boolean {
|
|
328
|
+
return screenBounds.width >= FitConstants.MIN_TITLE_PX_WIDTH && screenBounds.height >= FitConstants.MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
isLegendShown(screenBounds: DG.Rect): boolean {
|
|
332
|
+
return screenBounds.width >= FitConstants.MIN_LEGEND_PX_WIDTH && screenBounds.height >= FitConstants.MIN_LEGEND_PX_HEIGHT;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
areDroplinesShown(screenBounds: DG.Rect): boolean {
|
|
336
|
+
return screenBounds.width >= FitConstants.MIN_DROPLINES_VISIBILITY_PX_WIDTH && screenBounds.height >= FitConstants.MIN_DROPLINES_VISIBILITY_PX_HEIGHT;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
renderCurves(g: CanvasRenderingContext2D, screenBounds: DG.Rect, data: IFitChartData): void {
|
|
454
340
|
g.save();
|
|
455
341
|
g.beginPath();
|
|
456
|
-
g.rect(x, y,
|
|
342
|
+
g.rect(screenBounds.x, screenBounds.y, screenBounds.width, screenBounds.height);
|
|
457
343
|
g.clip();
|
|
458
344
|
|
|
459
|
-
if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX &&
|
|
345
|
+
if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX &&
|
|
346
|
+
data.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
460
347
|
substituteZeroes(data);
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
// TODO: make bigger sizes
|
|
464
|
-
const showAxesLabels = w >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && h >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT
|
|
465
|
-
&& !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
|
|
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;
|
|
468
|
-
const showDroplines = w >= MIN_DROPLINES_VISIBILITY_PX_WIDTH && h >= MIN_DROPLINES_VISIBILITY_PX_HEIGHT;
|
|
469
|
-
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxesLabels, showTitle);
|
|
348
|
+
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds,
|
|
349
|
+
this.areAxesLabelsShown(screenBounds, data), this.isTitleShown(screenBounds, data));
|
|
470
350
|
|
|
471
351
|
const dataBounds = getChartBounds(data);
|
|
472
352
|
if ((dataBounds.x < 0 && data.chartOptions) || (dataBounds.x === 0 && data.chartOptions && !data.chartOptions.allowXZeroes))
|
|
473
353
|
data.chartOptions.logX = false;
|
|
474
|
-
if (dataBounds.y <= 0 && data.chartOptions)
|
|
354
|
+
if (dataBounds.y <= 0 && data.chartOptions)
|
|
355
|
+
data.chartOptions.logY = false;
|
|
475
356
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
476
357
|
const minSize = Math.min(dataBox.width, dataBox.height);
|
|
477
358
|
// TODO: make thinner
|
|
@@ -487,31 +368,14 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
487
368
|
const series = data.series![i];
|
|
488
369
|
if (series.points.some((point) => point.x === undefined || point.y === undefined))
|
|
489
370
|
continue;
|
|
490
|
-
if (
|
|
371
|
+
if (screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
372
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
491
373
|
series.showPoints = '';
|
|
492
374
|
if (data.chartOptions)
|
|
493
375
|
data.chartOptions.showStatistics = [];
|
|
494
376
|
}
|
|
495
377
|
series.points.sort((a, b) => a.x - b.x);
|
|
496
378
|
|
|
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
|
-
|
|
515
379
|
let userParamsFlag = true;
|
|
516
380
|
const fitFunc = getSeriesFitFunction(series);
|
|
517
381
|
let curve: ((x: number) => number) | null = null;
|
|
@@ -526,186 +390,78 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
526
390
|
else {
|
|
527
391
|
const fitResult = fitSeries(series, fitFunc, chartLogOptions);
|
|
528
392
|
curve = fitResult.fittedCurve;
|
|
529
|
-
|
|
393
|
+
const params = [...fitResult.parameters]
|
|
394
|
+
series.parameters = params;
|
|
530
395
|
userParamsFlag = false;
|
|
531
396
|
}
|
|
532
397
|
}
|
|
533
398
|
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
if (series.showFitLine ?? true) {
|
|
549
|
-
const lineColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
|
|
550
|
-
series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
551
|
-
g.save();
|
|
552
|
-
g.strokeStyle = lineColor;
|
|
553
|
-
g.lineWidth = 2 * ratio;
|
|
554
|
-
|
|
555
|
-
g.beginPath();
|
|
556
|
-
if (series.lineStyle)
|
|
557
|
-
g.setLineDash(LINE_STYLES[series.lineStyle]);
|
|
558
|
-
const axesLeftPxMargin = showAxes ? showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN : 0;
|
|
559
|
-
const axesRightPxMargin = showAxes ? AXES_RIGHT_PX_MARGIN : 0;
|
|
560
|
-
for (let j = axesLeftPxMargin; j <= screenBounds.width - axesRightPxMargin; j++) {
|
|
561
|
-
const x = screenBounds.x + j;
|
|
562
|
-
const xForY = data.chartOptions?.logX ? Math.log10(viewport.xToWorld(x)) : viewport.xToWorld(x);
|
|
563
|
-
const y = data.chartOptions?.logY ? viewport.yToScreen(Math.pow(10, curve!(xForY))) : viewport.yToScreen(curve!(xForY));
|
|
564
|
-
if (j === axesLeftPxMargin)
|
|
565
|
-
g.moveTo(x, y);
|
|
566
|
-
else
|
|
567
|
-
g.lineTo(x, y);
|
|
568
|
-
}
|
|
569
|
-
g.stroke();
|
|
570
|
-
g.restore();
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
|
|
574
|
-
g.strokeStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_STROKE_COLOR;
|
|
575
|
-
g.fillStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_FILL_COLOR;
|
|
576
|
-
|
|
577
|
-
const confidenceIntervals = getSeriesConfidenceInterval(series, fitFunc, userParamsFlag, chartLogOptions);
|
|
578
|
-
drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport,
|
|
579
|
-
CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP, showAxes, showAxesLabels, chartLogOptions);
|
|
580
|
-
drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport,
|
|
581
|
-
CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM, showAxes, showAxesLabels, chartLogOptions);
|
|
582
|
-
fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, showAxes, showAxesLabels, chartLogOptions);
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if ((series.showFitLine ?? true) && series.droplines && showDroplines) {
|
|
586
|
-
g.save();
|
|
587
|
-
g.strokeStyle = 'blue';
|
|
588
|
-
g.lineWidth = ratio;
|
|
589
|
-
g.beginPath();
|
|
590
|
-
g.setLineDash([5, 5]);
|
|
591
|
-
for (let j = 0; j < series.droplines.length; j++) {
|
|
592
|
-
const droplineName = series.droplines[j];
|
|
593
|
-
if (droplineName === 'IC50')
|
|
594
|
-
drawDropline(g, viewport, series.parameters![2], dataBounds, curve!, chartLogOptions);
|
|
595
|
-
}
|
|
596
|
-
g.stroke();
|
|
597
|
-
g.restore();
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
if ((series.showFitLine ?? true) && data.chartOptions?.showStatistics) {
|
|
601
|
-
const statistics = getSeriesStatistics(series, fitFunc, chartLogOptions);
|
|
602
|
-
for (let j = 0; j < data.chartOptions.showStatistics.length; j++) {
|
|
603
|
-
const statName = data.chartOptions.showStatistics[j];
|
|
604
|
-
const prop = statisticsProperties.find(p => p.name === statName);
|
|
605
|
-
if (prop) {
|
|
606
|
-
const s = StringUtils.formatNumber(prop.get(statistics));
|
|
607
|
-
const statColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
|
|
608
|
-
series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
609
|
-
g.fillStyle = statColor;
|
|
610
|
-
g.textAlign = 'left';
|
|
611
|
-
g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 * j);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
}
|
|
399
|
+
assignSeriesColors(series, i);
|
|
400
|
+
renderConnectDots(g, series, {viewport, ratio});
|
|
401
|
+
renderPoints(g, series, {viewport, ratio});
|
|
402
|
+
renderFitLine(g, series, {viewport, ratio, logOptions: chartLogOptions, showAxes: this.areAxesShown(screenBounds),
|
|
403
|
+
showAxesLabels: this.areAxesLabelsShown(screenBounds, data), screenBounds, curveFunc: curve!});
|
|
404
|
+
renderConfidenceIntervals(g, series, {viewport, logOptions: chartLogOptions, showAxes: this.areAxesShown(screenBounds),
|
|
405
|
+
showAxesLabels: this.areAxesLabelsShown(screenBounds, data), screenBounds, fitFunc, userParamsFlag});
|
|
406
|
+
renderDroplines(g, series, {viewport, ratio, showDroplines: this.areDroplinesShown(screenBounds),
|
|
407
|
+
xValue: series.parameters![2], dataBounds, curveFunc: curve!, logOptions: chartLogOptions});
|
|
408
|
+
renderStatistics(g, series, {statistics: data.chartOptions?.showStatistics, fitFunc,
|
|
409
|
+
logOptions: chartLogOptions, dataBox});
|
|
615
410
|
}
|
|
616
411
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
if (showAxesLabels) {
|
|
625
|
-
g.font = '11px Roboto, "Roboto Local"';
|
|
626
|
-
g.textAlign = 'center';
|
|
627
|
-
g.fillStyle = 'black';
|
|
628
|
-
g.fillText(data.chartOptions?.xAxisName!, dataBox.midX - 5, y + h - 10);
|
|
629
|
-
g.translate(x, y);
|
|
630
|
-
g.rotate(-Math.PI / 2);
|
|
631
|
-
const axesTopPxMargin = showTitle ? AXES_TOP_PX_MARGIN_WITH_TITLE : AXES_TOP_PX_MARGIN;
|
|
632
|
-
g.fillText(data.chartOptions?.yAxisName!, -(dataBox.height / 2 + axesTopPxMargin + 15), 15);
|
|
633
|
-
g.restore();
|
|
634
|
-
}
|
|
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
|
-
}
|
|
412
|
+
renderTitle(g, {showTitle: this.isTitleShown(screenBounds, data), title: data.chartOptions?.title, dataBox, screenBounds});
|
|
413
|
+
renderAxesLabels(g, {showTitle: this.isTitleShown(screenBounds, data), dataBox, screenBounds,
|
|
414
|
+
showAxesLabels: this.areAxesLabelsShown(screenBounds, data), xAxisName: data.chartOptions?.xAxisName,
|
|
415
|
+
yAxisName: data.chartOptions?.yAxisName});
|
|
416
|
+
renderLegend(g, data, {showLegend: this.isLegendShown(screenBounds), dataBox, ratio});
|
|
659
417
|
|
|
660
418
|
g.restore();
|
|
661
419
|
}
|
|
662
420
|
|
|
421
|
+
// TODO: Curves: make less margins in the right, also in the left
|
|
422
|
+
// TODO: Curves: add a warning or error in top right if some mistakes in data
|
|
663
423
|
render(g: CanvasRenderingContext2D,
|
|
664
424
|
x: number, y: number, w: number, h: number,
|
|
665
425
|
gridCell: DG.GridCell, cellStyle: DG.GridCellStyle): void {
|
|
666
|
-
if (w < MIN_CELL_RENDERER_PX_WIDTH || h < MIN_CELL_RENDERER_PX_HEIGHT)
|
|
667
|
-
return;
|
|
668
|
-
|
|
669
426
|
if (!gridCell.cell.value)
|
|
670
427
|
return;
|
|
671
|
-
|
|
672
|
-
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
673
|
-
: getChartData(gridCell);
|
|
674
|
-
|
|
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');
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
if (data.series?.some((series) => series.points.length === 0)) {
|
|
683
|
-
showIncorrectFitCell(g, screenBounds, 'There were series with no points');
|
|
428
|
+
if (w < FitConstants.MIN_CELL_RENDERER_PX_WIDTH || h < FitConstants.MIN_CELL_RENDERER_PX_HEIGHT)
|
|
684
429
|
return;
|
|
685
|
-
}
|
|
686
430
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
431
|
+
const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
432
|
+
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
433
|
+
const screenBounds = new DG.Rect(x, y, w, h).inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
|
|
691
434
|
|
|
692
|
-
|
|
693
|
-
|
|
435
|
+
for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
436
|
+
if (condition(data.series)) {
|
|
437
|
+
showIncorrectFitCell(g, screenBounds);
|
|
694
438
|
return;
|
|
439
|
+
}
|
|
695
440
|
}
|
|
696
441
|
|
|
697
442
|
data.series?.forEach((series) => series.columnName = gridCell.cell.column.name);
|
|
698
443
|
if (data.chartOptions?.mergeSeries)
|
|
699
444
|
data.series = [mergeSeries(data.series!)!];
|
|
700
445
|
|
|
701
|
-
this.renderCurves(g,
|
|
446
|
+
this.renderCurves(g, screenBounds, data);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
hitTest(e: MouseEvent, point: IFitPoint, viewport: Viewport): boolean {
|
|
450
|
+
const screenX = viewport.xToScreen(point.x);
|
|
451
|
+
const screenY = viewport.yToScreen(point.y);
|
|
452
|
+
const pxPerMarkerType = ((point.outlier ? FitConstants.OUTLIER_PX_SIZE : FitConstants.POINT_PX_SIZE) / 2) + FitConstants.OUTLIER_HITBOX_RADIUS;
|
|
453
|
+
const pointRect = new DG.Rect(screenX - pxPerMarkerType, screenY - pxPerMarkerType,
|
|
454
|
+
2 * pxPerMarkerType, 2 * pxPerMarkerType);
|
|
455
|
+
return pointRect.containsPoint(new DG.Point(e.offsetX, e.offsetY));
|
|
702
456
|
}
|
|
703
457
|
|
|
704
458
|
onMouseMove(gridCell: DG.GridCell, e: MouseEvent): void {
|
|
705
459
|
if (!gridCell.cell.value)
|
|
706
460
|
return;
|
|
707
461
|
|
|
708
|
-
|
|
462
|
+
const screenBounds = gridCell.bounds.inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
|
|
463
|
+
if (screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
464
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
709
465
|
const canvas = ui.canvas(300, 200);
|
|
710
466
|
this.render(canvas.getContext('2d')!, 0, 0, 300, 200, gridCell, null as any);
|
|
711
467
|
const content = ui.divV([canvas]);
|
|
@@ -713,15 +469,13 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
713
469
|
}
|
|
714
470
|
|
|
715
471
|
// TODO: add caching
|
|
716
|
-
const data = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX
|
|
472
|
+
const data = gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX
|
|
717
473
|
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
718
474
|
: getChartData(gridCell);
|
|
719
475
|
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
const
|
|
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];
|
|
476
|
+
if (screenBounds.width >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH &&
|
|
477
|
+
screenBounds.height >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
478
|
+
const dataBox = layoutChart(screenBounds, this.areAxesLabelsShown(screenBounds, data), this.isTitleShown(screenBounds, data))[0];
|
|
725
479
|
const dataBounds = getChartBounds(data);
|
|
726
480
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
727
481
|
|
|
@@ -730,15 +484,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
730
484
|
continue;
|
|
731
485
|
for (let j = 0; j < data.series![i].points.length!; j++) {
|
|
732
486
|
const p = data.series![i].points[j];
|
|
733
|
-
|
|
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) {
|
|
487
|
+
if (this.hitTest(e, p, viewport)) {
|
|
738
488
|
ui.tooltip.show(ui.divV([ui.divText(`x: ${DG.format(p.x, '#0.000')}`),
|
|
739
489
|
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)
|
|
490
|
+
if (!data.series![i].connectDots && data.series![i].clickToToggle && screenBounds.width >= FitConstants.MIN_AXES_CELL_PX_WIDTH &&
|
|
491
|
+
screenBounds.height >= FitConstants.MIN_AXES_CELL_PX_HEIGHT)
|
|
742
492
|
document.body.style.cursor = 'pointer';
|
|
743
493
|
return;
|
|
744
494
|
}
|