@datagrok/curves 1.2.16 → 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.
@@ -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,43 +26,24 @@ 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';
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';
38
37
 
39
38
 
40
- export const TAG_FIT_CHART_FORMAT = '.fitChartFormat';
41
- export const TAG_FIT_CHART_FORMAT_3DX = '3dx';
42
- const MIN_CELL_RENDERER_PX_WIDTH = 20;
43
- const MIN_CELL_RENDERER_PX_HEIGHT = 10;
44
- const MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH = 70;
45
- const MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT = 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_DROPLINES_VISIBILITY_PX_WIDTH = 120;
56
- const MIN_DROPLINES_VISIBILITY_PX_HEIGHT = 110;
57
- const AXES_LEFT_PX_MARGIN = 38;
58
- const AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS = 45;
59
- const AXES_TOP_PX_MARGIN = 5;
60
- const AXES_TOP_PX_MARGIN_WITH_TITLE = 25;
61
- const AXES_RIGHT_PX_MARGIN = 18;
62
- const AXES_BOTTOM_PX_MARGIN = 15;
63
- const AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS = 30;
64
- const CANDLESTICK_BORDER_PX_SIZE = 4;
65
- const CANDLESTICK_MEDIAN_PX_SIZE = 3.5;
66
- const CANDLESTICK_OUTLIER_PX_SIZE = 6;
67
- export const INFLATE_SIZE = -12;
68
- export const LINE_STYLES: {[key: string]: number[]} = {
69
- 'solid': [],
70
- 'dotted': [1, 1],
71
- 'dashed': [5, 5],
72
- 'dashdotted': [5, 5, 2, 5],
73
- };
39
+ function clamp(value: number, min: number, max: number): number {
40
+ return Math.min(Math.max(value, min), max);
41
+ }
74
42
 
43
+ function showIncorrectFitCell(g: CanvasRenderingContext2D, screenBounds: DG.Rect): void {
44
+ DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER, screenBounds.midX, screenBounds.midY, DG.Color.red,
45
+ clamp(Math.min(screenBounds.width, screenBounds.height) * 0.8,0, 30));
46
+ }
75
47
 
76
48
  /** Merges properties of the two objects by iterating over the specified {@link properties}
77
49
  * and assigning properties from {@link source} to {@link target} only when
@@ -86,6 +58,86 @@ export function mergeProperties(properties: DG.Property[], source: any, target:
86
58
  }
87
59
  }
88
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
+
113
+ export function mergeSeries(series: IFitSeries[]): IFitSeries | null {
114
+ if (series.length === 0)
115
+ return null;
116
+ const mergedSeries: IFitSeries = {
117
+ points: [],
118
+ name: series[0].name,
119
+ fitFunction: series[0].fitFunction,
120
+ markerType: series[0].markerType,
121
+ lineStyle: series[0].lineStyle,
122
+ pointColor: series[0].pointColor,
123
+ fitLineColor: series[0].fitLineColor,
124
+ confidenceIntervalColor: series[0].confidenceIntervalColor,
125
+ outlierColor: series[0].outlierColor,
126
+ connectDots: series[0].connectDots,
127
+ showFitLine: series[0].showFitLine,
128
+ showPoints: series[0].showPoints,
129
+ showCurveConfidenceInterval: series[0].showCurveConfidenceInterval,
130
+ errorModel: series[0].errorModel,
131
+ clickToToggle: series[0].clickToToggle,
132
+ labels: series[0].labels,
133
+ droplines: series[0].droplines,
134
+ columnName: series[0].columnName,
135
+ };
136
+ for (const s of series)
137
+ mergedSeries.points = [...mergedSeries.points, ...s.points];
138
+ return mergedSeries;
139
+ }
140
+
89
141
  /** Constructs {@link IFitChartData} from the grid cell, taking into account
90
142
  * chart and fit settings potentially defined on the dataframe and column level. */
91
143
  export function getChartData(gridCell: DG.GridCell): IFitChartData {
@@ -94,7 +146,7 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
94
146
  if (cellValue.includes('|'))
95
147
  cellValue = cellValue.replaceAll('|', '');
96
148
  const cellChartData: IFitChartData = gridCell.cell?.column?.type === DG.TYPE.STRING ?
97
- (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 ?
98
150
  convertXMLToIFitChartData(cellValue) :
99
151
  JSON.parse(cellValue ?? '{}') ?? {}) : createDefaultChartData();
100
152
 
@@ -117,15 +169,15 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
117
169
 
118
170
  /** Performs a chart layout, returning [viewport, xAxis, yAxis] */
119
171
  export function layoutChart(rect: DG.Rect, showAxesLabels: boolean, showTitle: boolean): [DG.Rect, DG.Rect?, DG.Rect?] {
120
- 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)
121
173
  return [rect, undefined, undefined];
122
- const axesLeftPxMargin = showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
123
- const axesBottomPxMargin = showAxesLabels ? AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS : AXES_BOTTOM_PX_MARGIN;
124
- 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;
125
177
  return [
126
- rect.cutLeft(axesLeftPxMargin).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin).cutRight(AXES_RIGHT_PX_MARGIN),
127
- rect.getBottom(axesBottomPxMargin).getTop(axesTopPxMargin).cutLeft(axesLeftPxMargin).cutRight(AXES_RIGHT_PX_MARGIN),
128
- 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)
129
181
  ];
130
182
  }
131
183
 
@@ -136,144 +188,6 @@ export function isColorValid(color: string | null | undefined): boolean {
136
188
  return DG.Color.fromHtml(color) !== undefined;
137
189
  }
138
190
 
139
- /** Performs candlestick border drawing */
140
- function drawCandlestickBorder(g: CanvasRenderingContext2D, x: number, adjacentValue: number, transform: Viewport): void {
141
- g.moveTo(transform.xToScreen(x) - (CANDLESTICK_BORDER_PX_SIZE / 2), transform.yToScreen(adjacentValue));
142
- g.lineTo(transform.xToScreen(x) + (CANDLESTICK_BORDER_PX_SIZE / 2), transform.yToScreen(adjacentValue));
143
- }
144
-
145
- /** Performs candlestick drawing */
146
- function drawCandlestick(g: CanvasRenderingContext2D, x: number, boxPlotStats: BoxPlotStatistics,
147
- transform: Viewport, ratio: number, markerColor: number): void {
148
- drawCandlestickBorder(g, x, boxPlotStats.lowerAdjacentValue, transform);
149
- g.moveTo(transform.xToScreen(x), transform.yToScreen(boxPlotStats.lowerAdjacentValue));
150
- g.lineTo(transform.xToScreen(x), transform.yToScreen(boxPlotStats.upperAdjacentValue));
151
- drawCandlestickBorder(g, x, boxPlotStats.upperAdjacentValue, transform);
152
- DG.Paint.marker(g, DG.MARKER_TYPE.CIRCLE, transform.xToScreen(x), transform.yToScreen(boxPlotStats.q2),
153
- markerColor, CANDLESTICK_MEDIAN_PX_SIZE * ratio);
154
- }
155
-
156
- /** Performs points drawing */
157
- function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
158
- transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number, outlierColor: number): void {
159
- for (let i = 0; i < series.points.length!; i++) {
160
- const p = series.points[i];
161
- const color = p.outlier ? (p.outlierColor ? DG.Color.fromHtml(p.outlierColor) ?
162
- DG.Color.fromHtml(p.outlierColor) : outlierColor : outlierColor) : p.color ? DG.Color.fromHtml(p.color) ?
163
- DG.Color.fromHtml(p.color) : pointColor : pointColor;
164
- const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
165
- const size = p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio;
166
- DG.Paint.marker(g,
167
- p.outlier ? DG.MARKER_TYPE.OUTLIER : marker,
168
- transform.xToScreen(p.x), transform.yToScreen(p.y), color, size);
169
- if (p.stdev && !p.outlier) {
170
- g.strokeStyle = DG.Color.toHtml(color);
171
- g.beginPath();
172
- g.moveTo(transform.xToScreen(p.x), transform.yToScreen(p.y + p.stdev));
173
- g.lineTo(transform.xToScreen(p.x), transform.yToScreen(p.y - p.stdev));
174
- g.stroke();
175
- }
176
- }
177
- }
178
-
179
- /** Performs candles drawing */
180
- function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
181
- transform: Viewport, ratio: number, markerColor: number) : void {
182
- for (let i = 0, candleStart = null; i < series.points.length!; i++) {
183
- const p = series.points[i];
184
- if (p.outlier)
185
- continue;
186
- const nextSame = i + 1 < series.points.length && series.points[i + 1].x === p.x;
187
- if (!candleStart && nextSame)
188
- candleStart = i;
189
- else if (candleStart !== null && !nextSame) {
190
- const values: number[] = [];
191
- for (let j = candleStart, ind = 0; j <= i; j++, ind++) {
192
- values[ind] = series.points[j].y;
193
- }
194
- const boxPlotStats = calculateBoxPlotStatistics(values);
195
-
196
- g.beginPath();
197
- drawCandlestick(g, p.x, boxPlotStats, transform, ratio, markerColor);
198
- g.stroke();
199
-
200
- if (series.showPoints === 'both') {
201
- for (let ind = 0; ind < values.length; ind++) {
202
- if (values[ind] < boxPlotStats.lowerAdjacentValue || values[ind] > boxPlotStats.upperAdjacentValue) {
203
- DG.Paint.marker(g, DG.MARKER_TYPE.OUTLIER,
204
- transform.xToScreen(p.x), transform.yToScreen(values[ind]),
205
- series.pointColor ? DG.Color.fromHtml(series.pointColor) : DG.Color.scatterPlotMarker,
206
- CANDLESTICK_OUTLIER_PX_SIZE * ratio);
207
- }
208
- }
209
- }
210
-
211
- candleStart = null;
212
- }
213
- }
214
- }
215
-
216
- /** Performs a curve confidence interval drawing */
217
- function drawConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals, screenBounds: DG.Rect,
218
- transform: Viewport, confidenceType: string, showAxes: boolean, showAxesLabels: boolean, logOptions: LogOptions): void {
219
- g.beginPath();
220
- const axesLeftPxMargin = showAxes ? showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN : 0;
221
- const axesRightPxMargin = showAxes ? AXES_RIGHT_PX_MARGIN : 0;
222
- const confIntervalFunc = confidenceType === CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
223
- confIntervals.confidenceTop : confIntervals.confidenceBottom;
224
- for (let i = axesLeftPxMargin; i <= screenBounds.width - axesRightPxMargin; i++) {
225
- const x = screenBounds.x + i;
226
- const xForY = logOptions.logX ? Math.log10(transform.xToWorld(x)) : transform.xToWorld(x);
227
- const y = logOptions.logY ? transform.yToScreen(Math.pow(10, confIntervalFunc(xForY))) : transform.yToScreen(confIntervalFunc(xForY));
228
- if (i === axesLeftPxMargin)
229
- g.moveTo(x, y);
230
- else
231
- g.lineTo(x, y);
232
- }
233
- g.stroke();
234
- }
235
-
236
- /** Performs a curve confidence interval color filling */
237
- function fillConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals, screenBounds: DG.Rect,
238
- transform: Viewport, showAxes: boolean, showAxesLabels: boolean, logOptions: LogOptions): void {
239
- g.beginPath();
240
- const axesLeftPxMargin = showAxes ? showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN : 0;
241
- const axesRightPxMargin = showAxes ? AXES_RIGHT_PX_MARGIN : 0;
242
- for (let i = axesLeftPxMargin; i <= screenBounds.width - axesRightPxMargin; i++) {
243
- const x = screenBounds.x + i;
244
- const xForY = logOptions.logX ? Math.log10(transform.xToWorld(x)) : transform.xToWorld(x);
245
- const y = logOptions.logY ? transform.yToScreen(Math.pow(10, confIntervals.confidenceTop(xForY))) :
246
- transform.yToScreen(confIntervals.confidenceTop(xForY));
247
- if (i === axesLeftPxMargin)
248
- g.moveTo(x, y);
249
- else
250
- g.lineTo(x, y);
251
- }
252
-
253
- // reverse traverse to make a shape of confidence interval to fill it
254
- for (let i = screenBounds.width - axesRightPxMargin; i >= axesLeftPxMargin; i--) {
255
- const x = screenBounds.x + i;
256
- const xForY = logOptions.logX ? Math.log10(transform.xToWorld(x)) : transform.xToWorld(x);
257
- const y = logOptions.logY ? transform.yToScreen(Math.pow(10, confIntervals.confidenceBottom(xForY))) :
258
- transform.yToScreen(confIntervals.confidenceBottom(xForY));
259
- g.lineTo(x, y);
260
- }
261
- g.closePath();
262
- g.fill();
263
- }
264
-
265
- /** Performs a dropline drawing */
266
- function drawDropline(g: CanvasRenderingContext2D, transform: Viewport, xValue: number, dataBounds: DG.Rect,
267
- curve: (x: number) => number, logOptions: LogOptions): void {
268
- if (logOptions.logX)
269
- xValue = Math.pow(10, xValue);
270
- const xForY = logOptions.logX ? Math.log10(xValue) : xValue;
271
- const y = logOptions.logY ? Math.pow(10, curve(xForY)) : curve(xForY);
272
- g.moveTo(transform.xToScreen(dataBounds.minX), transform.yToScreen(y));
273
- g.lineTo(transform.xToScreen(xValue), transform.yToScreen(y));
274
- g.lineTo(transform.xToScreen(xValue), transform.yToScreen(dataBounds.minY));
275
- }
276
-
277
191
  /** Performs x zeroes substitution if log x */
278
192
  export function substituteZeroes(data: IFitChartData): void {
279
193
  for (let i = 0; i < data.series?.length!; i++) {
@@ -308,40 +222,38 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
308
222
  get cellType() { return FIT_CELL_TYPE; }
309
223
 
310
224
  getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
311
- return {width: 220, height: 150};
225
+ return {width: FitConstants.CELL_DEFAULT_WIDTH, height: FitConstants.CELL_DEFAULT_HEIGHT};
312
226
  }
313
227
 
314
228
  onClick(gridCell: DG.GridCell, e: MouseEvent): void {
315
229
  if (!gridCell.cell.value)
316
230
  return;
317
231
 
318
- const data = gridCell.cell.column.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX
319
- ? convertXMLToIFitChartData(gridCell.cell.value)
320
- : getChartData(gridCell);
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);
321
234
 
322
- if (data.series?.some((series) => series.points.length === 0))
323
- return;
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
+ }
240
+ }
324
241
 
325
242
  grok.shell.o = gridCell;
326
243
 
327
- const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
328
- const showAxesLabels = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
329
- const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
330
- 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];
331
247
  const dataBounds = getChartBounds(data);
332
248
  const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
333
249
 
334
250
  for (let i = 0; i < data.series?.length!; i++) {
335
- if (!data.series![i].clickToToggle || data.series![i].showPoints !== 'points' || screenBounds.width < MIN_AXES_CELL_PX_WIDTH ||
336
- screenBounds.height < MIN_AXES_CELL_PX_HEIGHT)
251
+ if (data.series![i].connectDots || !data.series![i].clickToToggle || data.series![i].showPoints !== 'points' ||
252
+ screenBounds.width < FitConstants.MIN_AXES_CELL_PX_WIDTH || screenBounds.height < FitConstants.MIN_AXES_CELL_PX_HEIGHT)
337
253
  continue;
338
254
  for (let j = 0; j < data.series![i].points.length!; j++) {
339
255
  const p = data.series![i].points[j];
340
- const screenX = viewport.xToScreen(p.x);
341
- const screenY = viewport.yToScreen(p.y);
342
- const pxPerMarkerType = ((p.outlier ? OUTLIER_PX_SIZE : POINT_PX_SIZE) / 2) + OUTLIER_HITBOX_RADIUS;
343
- if (e.offsetX >= screenX - pxPerMarkerType && e.offsetX <= screenX + pxPerMarkerType &&
344
- e.offsetY >= screenY - pxPerMarkerType && e.offsetY <= screenY + pxPerMarkerType) {
256
+ if (this.hitTest(e, p, viewport)) {
345
257
  p.outlier = !p.outlier;
346
258
  const columns = gridCell.grid.dataFrame.columns.byTags({'.sourceColumn': gridCell.cell.column.name});
347
259
  if (columns) {
@@ -357,7 +269,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
357
269
  }
358
270
 
359
271
  // temporarily works only for JSON structure
360
- 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) {
361
273
  const gridCellValue = JSON.parse(gridCell.cell.value) as IFitChartData;
362
274
  gridCellValue.series![i].points[j].outlier = p.outlier;
363
275
  gridCell.cell.value = JSON.stringify(gridCellValue);
@@ -394,27 +306,45 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
394
306
  });
395
307
  }
396
308
 
397
- renderCurves(g: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, data: IFitChartData): void {
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 {
398
332
  g.save();
399
333
  g.beginPath();
400
- g.rect(x, y, w, h);
334
+ g.rect(screenBounds.x, screenBounds.y, screenBounds.width, screenBounds.height);
401
335
  g.clip();
402
336
 
403
- if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX && data.series?.some((series) => series.points.some((p) => p.x === 0)))
337
+ if (data.chartOptions?.allowXZeroes && data.chartOptions?.logX &&
338
+ data.series?.some((series) => series.points.some((p) => p.x === 0)))
404
339
  substituteZeroes(data);
405
- const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
406
- const showAxes = screenBounds.width >= MIN_AXES_CELL_PX_WIDTH && screenBounds.height >= MIN_AXES_CELL_PX_HEIGHT;
407
- // TODO: make bigger sizes
408
- const showAxesLabels = w >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && h >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT
409
- && !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
410
- const showTitle = w >= MIN_TITLE_PX_WIDTH && h >= MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
411
- const showDroplines = w >= MIN_DROPLINES_VISIBILITY_PX_WIDTH && h >= MIN_DROPLINES_VISIBILITY_PX_HEIGHT;
412
- const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxesLabels, showTitle);
340
+ const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds,
341
+ this.areAxesLabelsShown(screenBounds, data), this.isTitleShown(screenBounds, data));
413
342
 
414
343
  const dataBounds = getChartBounds(data);
415
344
  if ((dataBounds.x < 0 && data.chartOptions) || (dataBounds.x === 0 && data.chartOptions && !data.chartOptions.allowXZeroes))
416
345
  data.chartOptions.logX = false;
417
- if (dataBounds.y <= 0 && data.chartOptions) data.chartOptions.logY = false;
346
+ if (dataBounds.y <= 0 && data.chartOptions)
347
+ data.chartOptions.logY = false;
418
348
  const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
419
349
  const minSize = Math.min(dataBox.width, dataBox.height);
420
350
  // TODO: make thinner
@@ -430,155 +360,99 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
430
360
  const series = data.series![i];
431
361
  if (series.points.some((point) => point.x === undefined || point.y === undefined))
432
362
  continue;
433
- if (w < MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH || h < MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
363
+ if (screenBounds.width < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH ||
364
+ screenBounds.height < FitConstants.MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
434
365
  series.showPoints = '';
435
366
  if (data.chartOptions)
436
367
  data.chartOptions.showStatistics = [];
437
368
  }
438
369
  series.points.sort((a, b) => a.x - b.x);
370
+
439
371
  let userParamsFlag = true;
440
372
  const fitFunc = getSeriesFitFunction(series);
441
- let curve: (x: number) => number;
442
- if (series.parameters) {
443
- if (data.chartOptions?.logX) {
444
- if (series.parameters[2] > 0)
445
- series.parameters[2] = Math.log10(series.parameters[2]);
373
+ let curve: ((x: number) => number) | null = null;
374
+ if (!(series.connectDots && !series.showFitLine)) {
375
+ if (series.parameters) {
376
+ if (data.chartOptions?.logX) {
377
+ if (series.parameters[2] > 0)
378
+ series.parameters[2] = Math.log10(series.parameters[2]);
379
+ }
380
+ curve = getCurve(series, fitFunc);
446
381
  }
447
- curve = getCurve(series, fitFunc);
448
- }
449
- else {
450
- const fitResult = fitSeries(series, fitFunc, chartLogOptions);
451
- curve = fitResult.fittedCurve;
452
- series.parameters = fitResult.parameters;
453
- userParamsFlag = false;
454
- }
455
-
456
- if (series.showPoints ?? 'points') {
457
- const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
458
- series.pointColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
459
- const outlierColor = series.outlierColor ? DG.Color.fromHtml(series.outlierColor) ?
460
- DG.Color.fromHtml(series.outlierColor) : DG.Color.red : DG.Color.red;
461
- g.strokeStyle = pointColor;
462
- if (series.showPoints === 'points')
463
- drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor), outlierColor);
464
- else if (['candlesticks', 'both'].includes(series.showPoints!))
465
- drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
466
- }
467
-
468
- if (series.showFitLine ?? true) {
469
- const lineColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
470
- series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
471
- g.save();
472
- g.strokeStyle = lineColor;
473
- g.lineWidth = 2 * ratio;
474
-
475
- g.beginPath();
476
- if (series.lineStyle)
477
- g.setLineDash(LINE_STYLES[series.lineStyle]);
478
- const axesLeftPxMargin = showAxes ? showAxesLabels ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN : 0;
479
- const axesRightPxMargin = showAxes ? AXES_RIGHT_PX_MARGIN : 0;
480
- for (let j = axesLeftPxMargin; j <= screenBounds.width - axesRightPxMargin; j++) {
481
- const x = screenBounds.x + j;
482
- const xForY = data.chartOptions?.logX ? Math.log10(viewport.xToWorld(x)) : viewport.xToWorld(x);
483
- const y = data.chartOptions?.logY ? viewport.yToScreen(Math.pow(10, curve(xForY))) : viewport.yToScreen(curve(xForY));
484
- if (j === axesLeftPxMargin)
485
- g.moveTo(x, y);
486
- else
487
- g.lineTo(x, y);
382
+ else {
383
+ const fitResult = fitSeries(series, fitFunc, chartLogOptions);
384
+ curve = fitResult.fittedCurve;
385
+ series.parameters = fitResult.parameters;
386
+ userParamsFlag = false;
488
387
  }
489
- g.stroke();
490
- g.restore();
491
- }
492
-
493
- if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
494
- g.strokeStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_STROKE_COLOR;
495
- g.fillStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_FILL_COLOR;
496
-
497
- const confidenceIntervals = getSeriesConfidenceInterval(series, fitFunc, userParamsFlag, chartLogOptions);
498
- drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport,
499
- CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP, showAxes, showAxesLabels, chartLogOptions);
500
- drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport,
501
- CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM, showAxes, showAxesLabels, chartLogOptions);
502
- fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, showAxes, showAxesLabels, chartLogOptions);
503
- }
504
-
505
- if (series.droplines && showDroplines) {
506
- g.save();
507
- g.strokeStyle = 'blue';
508
- g.lineWidth = ratio;
509
- g.beginPath();
510
- g.setLineDash([5, 5]);
511
- for (let j = 0; j < series.droplines.length; j++) {
512
- const droplineName = series.droplines[j];
513
- if (droplineName === 'IC50')
514
- drawDropline(g, viewport, series.parameters[2], dataBounds, curve, chartLogOptions);
515
- }
516
- g.stroke();
517
- g.restore();
518
388
  }
519
389
 
520
- if (data.chartOptions?.showStatistics) {
521
- const statistics = getSeriesStatistics(series, fitFunc, chartLogOptions);
522
- for (let j = 0; j < data.chartOptions.showStatistics.length; j++) {
523
- const statName = data.chartOptions.showStatistics[j];
524
- const prop = statisticsProperties.find(p => p.name === statName);
525
- if (prop) {
526
- const s = StringUtils.formatNumber(prop.get(statistics));
527
- const statColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
528
- series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
529
- g.fillStyle = statColor;
530
- g.textAlign = 'left';
531
- g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 * j);
532
- }
533
- }
534
- }
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});
535
401
  }
536
402
 
537
- if (showTitle) {
538
- g.font = '12px Roboto, "Roboto Local"';
539
- g.textAlign = 'center';
540
- g.fillStyle = 'black';
541
- g.fillText(data.chartOptions?.title!, dataBox.midX - 5, y + 15);
542
- }
543
-
544
- if (showAxesLabels) {
545
- g.font = '11px Roboto, "Roboto Local"';
546
- g.textAlign = 'center';
547
- g.fillStyle = 'black';
548
- g.fillText(data.chartOptions?.xAxisName!, dataBox.midX - 5, y + h - 10);
549
- g.translate(x, y);
550
- g.rotate(-Math.PI / 2);
551
- const axesTopPxMargin = showTitle ? AXES_TOP_PX_MARGIN_WITH_TITLE : AXES_TOP_PX_MARGIN;
552
- g.fillText(data.chartOptions?.yAxisName!, -(dataBox.height / 2 + axesTopPxMargin + 15), 15);
553
- g.restore();
554
- }
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});
555
408
 
556
409
  g.restore();
557
410
  }
558
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
559
414
  render(g: CanvasRenderingContext2D,
560
415
  x: number, y: number, w: number, h: number,
561
416
  gridCell: DG.GridCell, cellStyle: DG.GridCellStyle): void {
562
- if (w < MIN_CELL_RENDERER_PX_WIDTH || h < MIN_CELL_RENDERER_PX_HEIGHT)
563
- return;
564
-
565
417
  if (!gridCell.cell.value)
566
418
  return;
567
- const data = gridCell.cell.column?.getTag(TAG_FIT_CHART_FORMAT) === TAG_FIT_CHART_FORMAT_3DX
568
- ? convertXMLToIFitChartData(gridCell.cell.value)
569
- : getChartData(gridCell);
570
-
571
- if (data.series?.some((series) => series.points.length === 0))
419
+ if (w < FitConstants.MIN_CELL_RENDERER_PX_WIDTH || h < FitConstants.MIN_CELL_RENDERER_PX_HEIGHT)
572
420
  return;
573
421
 
574
- this.renderCurves(g, x, y, w, h, data);
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);
425
+
426
+ for (const [message, condition] of Object.entries(FitConstants.CONDITION_MAP)) {
427
+ if (condition(data.series)) {
428
+ showIncorrectFitCell(g, screenBounds);
429
+ return;
430
+ }
431
+ }
432
+
433
+ data.series?.forEach((series) => series.columnName = gridCell.cell.column.name);
434
+ if (data.chartOptions?.mergeSeries)
435
+ data.series = [mergeSeries(data.series!)!];
436
+
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));
575
447
  }
576
448
 
577
449
  onMouseMove(gridCell: DG.GridCell, e: MouseEvent): void {
578
450
  if (!gridCell.cell.value)
579
451
  return;
580
452
 
581
- if (gridCell.bounds.width < MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH || gridCell.bounds.height < MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
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) {
582
456
  const canvas = ui.canvas(300, 200);
583
457
  this.render(canvas.getContext('2d')!, 0, 0, 300, 200, gridCell, null as any);
584
458
  const content = ui.divV([canvas]);
@@ -586,32 +460,32 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
586
460
  }
587
461
 
588
462
  // TODO: add caching
589
- 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
590
464
  ? convertXMLToIFitChartData(gridCell.cell.value)
591
465
  : getChartData(gridCell);
592
466
 
593
- const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
594
- const showAxesLabels = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
595
- const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
596
- const dataBox = layoutChart(screenBounds, showAxesLabels, showTitle)[0];
597
- const dataBounds = getChartBounds(data);
598
- const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
599
-
600
- for (let i = 0; i < data.series?.length!; i++) {
601
- if (!data.series![i].clickToToggle || data.series![i].showPoints !== 'points' || screenBounds.width < MIN_AXES_CELL_PX_WIDTH ||
602
- screenBounds.height < MIN_AXES_CELL_PX_HEIGHT)
603
- continue;
604
- for (let j = 0; j < data.series![i].points.length!; j++) {
605
- const p = data.series![i].points[j];
606
- const screenX = viewport.xToScreen(p.x);
607
- const screenY = viewport.yToScreen(p.y);
608
- const pxPerMarkerType = ((p.outlier ? OUTLIER_PX_SIZE : POINT_PX_SIZE) / 2) + OUTLIER_HITBOX_RADIUS;
609
- if (e.offsetX >= screenX - pxPerMarkerType && e.offsetX <= screenX + pxPerMarkerType &&
610
- e.offsetY >= screenY - pxPerMarkerType && e.offsetY <= screenY + pxPerMarkerType) {
611
- document.body.style.cursor = 'pointer';
612
- return;
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];
470
+ const dataBounds = getChartBounds(data);
471
+ const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
472
+
473
+ for (let i = 0; i < data.series?.length!; i++) {
474
+ if (data.series![i].showPoints !== 'points')
475
+ continue;
476
+ for (let j = 0; j < data.series![i].points.length!; j++) {
477
+ const p = data.series![i].points[j];
478
+ if (this.hitTest(e, p, viewport)) {
479
+ ui.tooltip.show(ui.divV([ui.divText(`x: ${DG.format(p.x, '#0.000')}`),
480
+ ui.divText(`y: ${DG.format(p.y, '#0.000')}`)]), e.x + 16, e.y + 16);
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)
483
+ document.body.style.cursor = 'pointer';
484
+ return;
485
+ }
613
486
  }
614
487
  }
488
+ ui.tooltip.hide();
615
489
  }
616
490
  document.body.style.cursor = 'default';
617
491
  }