@datagrok/curves 1.3.0 → 1.3.1
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 +2 -0
- 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 +1 -1
- package/src/fit/const.ts +96 -0
- package/src/fit/fit-grid-cell-handler.ts +5 -4
- package/src/fit/fit-renderer.ts +162 -421
- package/src/fit/multi-curve-viewer.ts +54 -9
- package/src/fit/render-utils.ts +476 -0
- package/src/package.ts +4 -3
- package/src/tests/curves-cell-renderer-tests.ts +3 -2
- package/src/tests/detector-tests.ts +2 -2
- package/src/tests/transform-tests.ts +3 -2
- package/webpack.config.js +3 -0
package/src/fit/fit-renderer.ts
CHANGED
|
@@ -3,29 +3,20 @@ 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
7
|
FIT_CELL_TYPE,
|
|
13
8
|
IFitSeries,
|
|
14
9
|
FitStatistics,
|
|
15
10
|
fitChartDataProperties,
|
|
16
|
-
fitSeriesProperties,
|
|
11
|
+
fitSeriesProperties, IFitChartOptions, IFitPoint,
|
|
17
12
|
} from '@datagrok-libraries/statistics/src/fit/fit-curve';
|
|
18
|
-
import {BoxPlotStatistics, calculateBoxPlotStatistics} from '@datagrok-libraries/statistics/src/box-plot-statistics';
|
|
19
13
|
import {Viewport} from '@datagrok-libraries/utils/src/transform';
|
|
20
|
-
import {StringUtils} from '@datagrok-libraries/utils/src/string-utils';
|
|
21
14
|
|
|
22
15
|
import {
|
|
23
16
|
fitSeries,
|
|
24
17
|
createDefaultChartData,
|
|
25
18
|
getChartBounds,
|
|
26
19
|
getSeriesFitFunction,
|
|
27
|
-
getSeriesConfidenceInterval,
|
|
28
|
-
getSeriesStatistics,
|
|
29
20
|
getCurve,
|
|
30
21
|
getColumnChartOptions,
|
|
31
22
|
LogOptions,
|
|
@@ -35,51 +26,21 @@ import {
|
|
|
35
26
|
import {convertXMLToIFitChartData} from './fit-parser';
|
|
36
27
|
import {CellRenderViewer} from './cell-render-viewer';
|
|
37
28
|
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
|
-
};
|
|
29
|
+
import {FitConstants} from './const';
|
|
30
|
+
import {
|
|
31
|
+
assignSeriesColors, renderAxesLabels,
|
|
32
|
+
renderConfidenceIntervals, renderConnectDots,
|
|
33
|
+
renderDroplines,
|
|
34
|
+
renderFitLine, renderLegend,
|
|
35
|
+
renderPoints, renderStatistics, renderTitle
|
|
36
|
+
} from './render-utils';
|
|
76
37
|
|
|
77
38
|
|
|
78
39
|
function clamp(value: number, min: number, max: number): number {
|
|
79
40
|
return Math.min(Math.max(value, min), max);
|
|
80
41
|
}
|
|
81
42
|
|
|
82
|
-
function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect
|
|
43
|
+
function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect): void {
|
|
83
44
|
DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER, screenBounds.midX, screenBounds.midY, DG.Color.red,
|
|
84
45
|
clamp(Math.min(screenBounds.width, screenBounds.height) * 0.8,0, 30));
|
|
85
46
|
}
|
|
@@ -97,6 +58,58 @@ export function mergeProperties(properties: DG.Property[], source: any, target:
|
|
|
97
58
|
}
|
|
98
59
|
}
|
|
99
60
|
|
|
61
|
+
export function mergeChartOptions(chartOptions: IFitChartOptions[]): IFitChartOptions {
|
|
62
|
+
if (chartOptions.length === 0)
|
|
63
|
+
return {};
|
|
64
|
+
|
|
65
|
+
let minX = Number.MAX_VALUE;
|
|
66
|
+
let minY = Number.MAX_VALUE;
|
|
67
|
+
let maxX = Number.MIN_VALUE;
|
|
68
|
+
let maxY = Number.MIN_VALUE;
|
|
69
|
+
let xAxisName: string | undefined;
|
|
70
|
+
let yAxisName: string | undefined;
|
|
71
|
+
let title: string | undefined;
|
|
72
|
+
let logX: boolean = false;
|
|
73
|
+
let logY: boolean = false;
|
|
74
|
+
let allowXZeroes: boolean = false;
|
|
75
|
+
|
|
76
|
+
for (const options of chartOptions) {
|
|
77
|
+
if (options.minX !== null && options.minX !== undefined)
|
|
78
|
+
minX = Math.min(minX, options.minX);
|
|
79
|
+
if (options.minY !== null && options.minY !== undefined)
|
|
80
|
+
minY = Math.min(minY, options.minY);
|
|
81
|
+
if (options.maxX !== null && options.maxX !== undefined)
|
|
82
|
+
maxX = Math.max(maxX, options.maxX);
|
|
83
|
+
if (options.maxY !== null && options.maxY !== undefined)
|
|
84
|
+
maxY = Math.max(maxY, options.maxY);
|
|
85
|
+
if (options.title !== null && options.title !== undefined)
|
|
86
|
+
title ??= options.title;
|
|
87
|
+
if (options.xAxisName !== null && options.xAxisName !== undefined)
|
|
88
|
+
xAxisName ??= options.xAxisName;
|
|
89
|
+
if (options.yAxisName !== null && options.yAxisName !== undefined)
|
|
90
|
+
yAxisName ??= options.yAxisName;
|
|
91
|
+
if (options.logX !== null && options.logX !== undefined && options.logX)
|
|
92
|
+
logX = true;
|
|
93
|
+
if (options.logY !== null && options.logY !== undefined && options.logY)
|
|
94
|
+
logY = true;
|
|
95
|
+
if (options.allowXZeroes !== null && options.allowXZeroes !== undefined && options.allowXZeroes)
|
|
96
|
+
allowXZeroes = true;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
minX: minX === Number.MAX_VALUE ? undefined : minX,
|
|
101
|
+
minY: minY === Number.MAX_VALUE ? undefined : minY,
|
|
102
|
+
maxX: maxX === Number.MIN_VALUE ? undefined : maxX,
|
|
103
|
+
maxY: maxY === Number.MIN_VALUE ? undefined : maxY,
|
|
104
|
+
title: title,
|
|
105
|
+
xAxisName: xAxisName,
|
|
106
|
+
yAxisName: yAxisName,
|
|
107
|
+
logX: logX,
|
|
108
|
+
logY: logY,
|
|
109
|
+
allowXZeroes: allowXZeroes,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
100
113
|
export function mergeSeries(series: IFitSeries[]): IFitSeries | null {
|
|
101
114
|
if (series.length === 0)
|
|
102
115
|
return null;
|
|
@@ -133,7 +146,7 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
|
133
146
|
if (cellValue.includes('|'))
|
|
134
147
|
cellValue = cellValue.replaceAll('|', '');
|
|
135
148
|
const cellChartData: IFitChartData = gridCell.cell?.column?.type === DG.TYPE.STRING ?
|
|
136
|
-
(gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX ?
|
|
149
|
+
(gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
137
150
|
convertXMLToIFitChartData(cellValue) :
|
|
138
151
|
JSON.parse(cellValue ?? '{}') ?? {}) : createDefaultChartData();
|
|
139
152
|
|
|
@@ -156,15 +169,15 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
|
156
169
|
|
|
157
170
|
/** Performs a chart layout, returning [viewport, xAxis, yAxis] */
|
|
158
171
|
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)
|
|
172
|
+
if (rect.width < FitConstants.MIN_AXES_CELL_PX_WIDTH || rect.height < FitConstants.MIN_AXES_CELL_PX_HEIGHT)
|
|
160
173
|
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;
|
|
174
|
+
const axesLeftPxMargin = showAxesLabels ? FitConstants.AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_LEFT_PX_MARGIN;
|
|
175
|
+
const axesBottomPxMargin = showAxesLabels ? FitConstants.AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS : FitConstants.AXES_BOTTOM_PX_MARGIN;
|
|
176
|
+
const axesTopPxMargin = showTitle ? FitConstants.AXES_TOP_PX_MARGIN_WITH_TITLE : FitConstants.AXES_TOP_PX_MARGIN;
|
|
164
177
|
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)
|
|
178
|
+
rect.cutLeft(axesLeftPxMargin).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin).cutRight(FitConstants.AXES_RIGHT_PX_MARGIN),
|
|
179
|
+
rect.getBottom(axesBottomPxMargin).getTop(axesTopPxMargin).cutLeft(axesLeftPxMargin).cutRight(FitConstants.AXES_RIGHT_PX_MARGIN),
|
|
180
|
+
rect.getLeft(axesLeftPxMargin).getRight(FitConstants.AXES_RIGHT_PX_MARGIN).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin)
|
|
168
181
|
];
|
|
169
182
|
}
|
|
170
183
|
|
|
@@ -175,144 +188,6 @@ export function isColorValid(color: string | null | undefined): boolean {
|
|
|
175
188
|
return DG.Color.fromHtml(color) !== undefined;
|
|
176
189
|
}
|
|
177
190
|
|
|
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
191
|
/** Performs x zeroes substitution if log x */
|
|
317
192
|
export function substituteZeroes(data: IFitChartData): void {
|
|
318
193
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
@@ -347,57 +222,38 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
347
222
|
get cellType() { return FIT_CELL_TYPE; }
|
|
348
223
|
|
|
349
224
|
getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
|
|
350
|
-
return {width:
|
|
225
|
+
return {width: FitConstants.CELL_DEFAULT_WIDTH, height: FitConstants.CELL_DEFAULT_HEIGHT};
|
|
351
226
|
}
|
|
352
227
|
|
|
353
228
|
onClick(gridCell: DG.GridCell, e: MouseEvent): void {
|
|
354
229
|
if (!gridCell.cell.value)
|
|
355
230
|
return;
|
|
356
231
|
|
|
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
|
-
}
|
|
232
|
+
const data = gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
233
|
+
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
375
234
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
235
|
+
for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
236
|
+
if (condition(data.series)) {
|
|
237
|
+
grok.shell.o = ui.divText(message, {style: {color: 'red'}});
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
379
240
|
}
|
|
380
241
|
|
|
381
242
|
grok.shell.o = gridCell;
|
|
382
243
|
|
|
383
|
-
const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE
|
|
384
|
-
const
|
|
385
|
-
|
|
386
|
-
const dataBox = layoutChart(screenBounds, showAxesLabels, showTitle)[0];
|
|
244
|
+
const screenBounds = gridCell.bounds.inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
|
|
245
|
+
const dataBox = layoutChart(screenBounds, this.areAxesLabelsShown(screenBounds, data),
|
|
246
|
+
this.isTitleShown(screenBounds, data))[0];
|
|
387
247
|
const dataBounds = getChartBounds(data);
|
|
388
248
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
389
249
|
|
|
390
250
|
for (let i = 0; i < data.series?.length!; i++) {
|
|
391
251
|
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)
|
|
252
|
+
screenBounds.width < FitConstants.MIN_AXES_CELL_PX_WIDTH || screenBounds.height < FitConstants.MIN_AXES_CELL_PX_HEIGHT)
|
|
393
253
|
continue;
|
|
394
254
|
for (let j = 0; j < data.series![i].points.length!; j++) {
|
|
395
255
|
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) {
|
|
256
|
+
if (this.hitTest(e, p, viewport)) {
|
|
401
257
|
p.outlier = !p.outlier;
|
|
402
258
|
const columns = gridCell.grid.dataFrame.columns.byTags({'.sourceColumn': gridCell.cell.column.name});
|
|
403
259
|
if (columns) {
|
|
@@ -413,7 +269,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
413
269
|
}
|
|
414
270
|
|
|
415
271
|
// temporarily works only for JSON structure
|
|
416
|
-
if (gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) !== TAG_FIT_CHART_FORMAT_3DX) {
|
|
272
|
+
if (gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) !== FitConstants.TAG_FIT_CHART_FORMAT_3DX) {
|
|
417
273
|
const gridCellValue = JSON.parse(gridCell.cell.value) as IFitChartData;
|
|
418
274
|
gridCellValue.series![i].points[j].outlier = p.outlier;
|
|
419
275
|
gridCell.cell.value = JSON.stringify(gridCellValue);
|
|
@@ -450,28 +306,45 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
450
306
|
});
|
|
451
307
|
}
|
|
452
308
|
|
|
453
|
-
|
|
309
|
+
areAxesShown(screenBounds: DG.Rect): boolean {
|
|
310
|
+
return screenBounds.width >= FitConstants.MIN_AXES_CELL_PX_WIDTH && screenBounds.height >= FitConstants.MIN_AXES_CELL_PX_HEIGHT;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
areAxesLabelsShown(screenBounds: DG.Rect, data: IFitChartData): boolean {
|
|
314
|
+
// TODO: make bigger sizes
|
|
315
|
+
return screenBounds.width >= FitConstants.MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH &&
|
|
316
|
+
screenBounds.height >= FitConstants.MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT && !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
isTitleShown(screenBounds: DG.Rect, data: IFitChartData): boolean {
|
|
320
|
+
return screenBounds.width >= FitConstants.MIN_TITLE_PX_WIDTH && screenBounds.height >= FitConstants.MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
isLegendShown(screenBounds: DG.Rect): boolean {
|
|
324
|
+
return screenBounds.width >= FitConstants.MIN_LEGEND_PX_WIDTH && screenBounds.height >= FitConstants.MIN_LEGEND_PX_HEIGHT;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
areDroplinesShown(screenBounds: DG.Rect): boolean {
|
|
328
|
+
return screenBounds.width >= FitConstants.MIN_DROPLINES_VISIBILITY_PX_WIDTH && screenBounds.height >= FitConstants.MIN_DROPLINES_VISIBILITY_PX_HEIGHT;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
renderCurves(g: CanvasRenderingContext2D, screenBounds: DG.Rect, data: IFitChartData): void {
|
|
454
332
|
g.save();
|
|
455
333
|
g.beginPath();
|
|
456
|
-
g.rect(x, y,
|
|
334
|
+
g.rect(screenBounds.x, screenBounds.y, screenBounds.width, screenBounds.height);
|
|
457
335
|
g.clip();
|
|
458
336
|
|
|
459
|
-
if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX &&
|
|
337
|
+
if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX &&
|
|
338
|
+
data.series?.some((series) => series.points.some((p) => p.x === 0)))
|
|
460
339
|
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);
|
|
340
|
+
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds,
|
|
341
|
+
this.areAxesLabelsShown(screenBounds, data), this.isTitleShown(screenBounds, data));
|
|
470
342
|
|
|
471
343
|
const dataBounds = getChartBounds(data);
|
|
472
344
|
if ((dataBounds.x < 0 && data.chartOptions) || (dataBounds.x === 0 && data.chartOptions && !data.chartOptions.allowXZeroes))
|
|
473
345
|
data.chartOptions.logX = false;
|
|
474
|
-
if (dataBounds.y <= 0 && data.chartOptions)
|
|
346
|
+
if (dataBounds.y <= 0 && data.chartOptions)
|
|
347
|
+
data.chartOptions.logY = false;
|
|
475
348
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
476
349
|
const minSize = Math.min(dataBox.width, dataBox.height);
|
|
477
350
|
// TODO: make thinner
|
|
@@ -487,31 +360,14 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
487
360
|
const series = data.series![i];
|
|
488
361
|
if (series.points.some((point) => point.x === undefined || point.y === undefined))
|
|
489
362
|
continue;
|
|
490
|
-
if (
|
|
363
|
+
if (screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
364
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
491
365
|
series.showPoints = '';
|
|
492
366
|
if (data.chartOptions)
|
|
493
367
|
data.chartOptions.showStatistics = [];
|
|
494
368
|
}
|
|
495
369
|
series.points.sort((a, b) => a.x - b.x);
|
|
496
370
|
|
|
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
371
|
let userParamsFlag = true;
|
|
516
372
|
const fitFunc = getSeriesFitFunction(series);
|
|
517
373
|
let curve: ((x: number) => number) | null = null;
|
|
@@ -531,181 +387,72 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
531
387
|
}
|
|
532
388
|
}
|
|
533
389
|
|
|
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
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
if (showTitle) {
|
|
618
|
-
g.font = '12px Roboto, "Roboto Local"';
|
|
619
|
-
g.textAlign = 'center';
|
|
620
|
-
g.fillStyle = 'black';
|
|
621
|
-
g.fillText(data.chartOptions?.title!, dataBox.midX - 5, y + 15);
|
|
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();
|
|
390
|
+
assignSeriesColors(series, i);
|
|
391
|
+
renderConnectDots(g, series, {viewport, ratio});
|
|
392
|
+
renderPoints(g, series, {viewport, ratio});
|
|
393
|
+
renderFitLine(g, series, {viewport, ratio, logOptions: chartLogOptions, showAxes: this.areAxesShown(screenBounds),
|
|
394
|
+
showAxesLabels: this.areAxesLabelsShown(screenBounds, data), screenBounds, curveFunc: curve!});
|
|
395
|
+
renderConfidenceIntervals(g, series, {viewport, logOptions: chartLogOptions, showAxes: this.areAxesShown(screenBounds),
|
|
396
|
+
showAxesLabels: this.areAxesLabelsShown(screenBounds, data), screenBounds, fitFunc, userParamsFlag});
|
|
397
|
+
renderDroplines(g, series, {viewport, ratio, showDroplines: this.areDroplinesShown(screenBounds),
|
|
398
|
+
xValue: series.parameters![2], dataBounds, curveFunc: curve!, logOptions: chartLogOptions});
|
|
399
|
+
renderStatistics(g, series, {statistics: data.chartOptions?.showStatistics, fitFunc,
|
|
400
|
+
logOptions: chartLogOptions, dataBox});
|
|
634
401
|
}
|
|
635
402
|
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
-
}
|
|
403
|
+
renderTitle(g, {showTitle: this.isTitleShown(screenBounds, data), title: data.chartOptions?.title, dataBox, screenBounds});
|
|
404
|
+
renderAxesLabels(g, {showTitle: this.isTitleShown(screenBounds, data), dataBox, screenBounds,
|
|
405
|
+
showAxesLabels: this.areAxesLabelsShown(screenBounds, data), xAxisName: data.chartOptions?.xAxisName,
|
|
406
|
+
yAxisName: data.chartOptions?.yAxisName});
|
|
407
|
+
renderLegend(g, data, {showLegend: this.isLegendShown(screenBounds), dataBox, ratio});
|
|
659
408
|
|
|
660
409
|
g.restore();
|
|
661
410
|
}
|
|
662
411
|
|
|
412
|
+
// TODO: Curves: make less margins in the right, also in the left
|
|
413
|
+
// TODO: Curves: add a warning or error in top right if some mistakes in data
|
|
663
414
|
render(g: CanvasRenderingContext2D,
|
|
664
415
|
x: number, y: number, w: number, h: number,
|
|
665
416
|
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
417
|
if (!gridCell.cell.value)
|
|
670
418
|
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');
|
|
419
|
+
if (w < FitConstants.MIN_CELL_RENDERER_PX_WIDTH || h < FitConstants.MIN_CELL_RENDERER_PX_HEIGHT)
|
|
684
420
|
return;
|
|
685
|
-
}
|
|
686
421
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
422
|
+
const data = gridCell.cell.column?.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX ?
|
|
423
|
+
convertXMLToIFitChartData(gridCell.cell.value) : getChartData(gridCell);
|
|
424
|
+
const screenBounds = new DG.Rect(x, y, w, h).inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
|
|
691
425
|
|
|
692
|
-
|
|
693
|
-
|
|
426
|
+
for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
|
|
427
|
+
if (condition(data.series)) {
|
|
428
|
+
showIncorrectFitCell(g, screenBounds);
|
|
694
429
|
return;
|
|
430
|
+
}
|
|
695
431
|
}
|
|
696
432
|
|
|
697
433
|
data.series?.forEach((series) => series.columnName = gridCell.cell.column.name);
|
|
698
434
|
if (data.chartOptions?.mergeSeries)
|
|
699
435
|
data.series = [mergeSeries(data.series!)!];
|
|
700
436
|
|
|
701
|
-
this.renderCurves(g,
|
|
437
|
+
this.renderCurves(g, screenBounds, data);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
hitTest(e: MouseEvent, point: IFitPoint, viewport: Viewport): boolean {
|
|
441
|
+
const screenX = viewport.xToScreen(point.x);
|
|
442
|
+
const screenY = viewport.yToScreen(point.y);
|
|
443
|
+
const pxPerMarkerType = ((point.outlier ? FitConstants.OUTLIER_PX_SIZE : FitConstants.POINT_PX_SIZE) / 2) + FitConstants.OUTLIER_HITBOX_RADIUS;
|
|
444
|
+
const pointRect = new DG.Rect(screenX - pxPerMarkerType, screenY - pxPerMarkerType,
|
|
445
|
+
2 * pxPerMarkerType, 2 * pxPerMarkerType);
|
|
446
|
+
return pointRect.containsPoint(new DG.Point(e.offsetX, e.offsetY));
|
|
702
447
|
}
|
|
703
448
|
|
|
704
449
|
onMouseMove(gridCell: DG.GridCell, e: MouseEvent): void {
|
|
705
450
|
if (!gridCell.cell.value)
|
|
706
451
|
return;
|
|
707
452
|
|
|
708
|
-
|
|
453
|
+
const screenBounds = gridCell.bounds.inflate(FitConstants.INFLATE_SIZE, FitConstants.INFLATE_SIZE);
|
|
454
|
+
if (screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
|
|
455
|
+
screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
709
456
|
const canvas = ui.canvas(300, 200);
|
|
710
457
|
this.render(canvas.getContext('2d')!, 0, 0, 300, 200, gridCell, null as any);
|
|
711
458
|
const content = ui.divV([canvas]);
|
|
@@ -713,15 +460,13 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
713
460
|
}
|
|
714
461
|
|
|
715
462
|
// TODO: add caching
|
|
716
|
-
const data = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX
|
|
463
|
+
const data = gridCell.cell.column.getTag(FitConstants.TAG_FIT_CHART_FORMAT) === FitConstants.TAG_FIT_CHART_FORMAT_3DX
|
|
717
464
|
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
718
465
|
: getChartData(gridCell);
|
|
719
466
|
|
|
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];
|
|
467
|
+
if (screenBounds.width >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH &&
|
|
468
|
+
screenBounds.height >= FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
469
|
+
const dataBox = layoutChart(screenBounds, this.areAxesLabelsShown(screenBounds, data), this.isTitleShown(screenBounds, data))[0];
|
|
725
470
|
const dataBounds = getChartBounds(data);
|
|
726
471
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
727
472
|
|
|
@@ -730,15 +475,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
730
475
|
continue;
|
|
731
476
|
for (let j = 0; j < data.series![i].points.length!; j++) {
|
|
732
477
|
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) {
|
|
478
|
+
if (this.hitTest(e, p, viewport)) {
|
|
738
479
|
ui.tooltip.show(ui.divV([ui.divText(`x: ${DG.format(p.x, '#0.000')}`),
|
|
739
480
|
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)
|
|
481
|
+
if (!data.series![i].connectDots && data.series![i].clickToToggle && screenBounds.width >= FitConstants.MIN_AXES_CELL_PX_WIDTH &&
|
|
482
|
+
screenBounds.height >= FitConstants.MIN_AXES_CELL_PX_HEIGHT)
|
|
742
483
|
document.body.style.cursor = 'pointer';
|
|
743
484
|
return;
|
|
744
485
|
}
|