@datagrok/curves 1.2.3 → 1.2.4
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 +16 -0
- package/README.md +3 -1
- package/dist/package-test.js +114 -69
- package/dist/package-test.js.map +1 -1
- package/dist/package.js +108 -63
- package/dist/package.js.map +1 -1
- package/package.json +4 -3
- package/src/fit/fit-demo.js +1 -0
- package/src/fit/fit-demo.js.map +1 -1
- package/src/fit/fit-demo.ts +1 -0
- package/src/fit/fit-renderer.js +102 -58
- package/src/fit/fit-renderer.js.map +1 -1
- package/src/fit/fit-renderer.ts +100 -52
- package/src/tests/transform-tests.js +7 -7
- package/src/tests/transform-tests.js.map +1 -1
- package/src/tests/transform-tests.ts +7 -7
package/src/fit/fit-renderer.ts
CHANGED
|
@@ -46,14 +46,21 @@ const POINT_PX_SIZE = 4;
|
|
|
46
46
|
const OUTLIER_HITBOX_RADIUS = 2;
|
|
47
47
|
const MIN_AXES_CELL_PX_WIDTH = 70;
|
|
48
48
|
const MIN_AXES_CELL_PX_HEIGHT = 55;
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
49
|
+
const MIN_TITLE_PX_WIDTH = 350;
|
|
50
|
+
const MIN_TITLE_PX_HEIGHT = 250;
|
|
51
|
+
const MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH = 180;
|
|
52
|
+
const MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT = 140;
|
|
53
|
+
const AXES_LEFT_PX_MARGIN = 38;
|
|
54
|
+
const AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS = 45;
|
|
52
55
|
const AXES_TOP_PX_MARGIN = 5;
|
|
56
|
+
const AXES_TOP_PX_MARGIN_WITH_TITLE = 25;
|
|
57
|
+
const AXES_RIGHT_PX_MARGIN = 18;
|
|
53
58
|
const AXES_BOTTOM_PX_MARGIN = 15;
|
|
59
|
+
const AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS = 30;
|
|
54
60
|
const CANDLESTICK_BORDER_PX_SIZE = 4;
|
|
55
61
|
const CANDLESTICK_MEDIAN_PX_SIZE = 3.5;
|
|
56
62
|
const CANDLESTICK_OUTLIER_PX_SIZE = 6;
|
|
63
|
+
export const INFLATE_SIZE = -12;
|
|
57
64
|
|
|
58
65
|
|
|
59
66
|
/** Merges properties of the two objects by iterating over the specified {@link properties}
|
|
@@ -91,13 +98,16 @@ export function getChartData(gridCell: DG.GridCell): IFitChartData {
|
|
|
91
98
|
}
|
|
92
99
|
|
|
93
100
|
/** Performs a chart layout, returning [viewport, xAxis, yAxis] */
|
|
94
|
-
export function layoutChart(rect: DG.Rect): [DG.Rect, DG.Rect?, DG.Rect?] {
|
|
101
|
+
export function layoutChart(rect: DG.Rect, showAxes: boolean, showTitle: boolean): [DG.Rect, DG.Rect?, DG.Rect?] {
|
|
95
102
|
if (rect.width < MIN_AXES_CELL_PX_WIDTH || rect.height < MIN_AXES_CELL_PX_HEIGHT)
|
|
96
103
|
return [rect, undefined, undefined];
|
|
104
|
+
const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
|
|
105
|
+
const axesBottomPxMargin = showAxes ? AXES_BOTTOM_PX_MARGIN_WITH_AXES_LABELS : AXES_BOTTOM_PX_MARGIN;
|
|
106
|
+
const axesTopPxMargin = showTitle ? AXES_TOP_PX_MARGIN_WITH_TITLE : AXES_TOP_PX_MARGIN;
|
|
97
107
|
return [
|
|
98
|
-
rect.cutLeft(
|
|
99
|
-
rect.getBottom(
|
|
100
|
-
rect.getLeft(
|
|
108
|
+
rect.cutLeft(axesLeftPxMargin).cutBottom(axesLeftPxMargin).cutTop(axesTopPxMargin).cutRight(AXES_RIGHT_PX_MARGIN),
|
|
109
|
+
rect.getBottom(axesBottomPxMargin).getTop(axesTopPxMargin).cutLeft(axesLeftPxMargin).cutRight(AXES_RIGHT_PX_MARGIN),
|
|
110
|
+
rect.getLeft(axesLeftPxMargin).getRight(AXES_RIGHT_PX_MARGIN).cutBottom(axesBottomPxMargin).cutTop(axesTopPxMargin)
|
|
101
111
|
];
|
|
102
112
|
}
|
|
103
113
|
|
|
@@ -120,12 +130,10 @@ function drawCandlestick(g: CanvasRenderingContext2D, x: number, boxPlotStats: B
|
|
|
120
130
|
|
|
121
131
|
/** Performs points drawing */
|
|
122
132
|
function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
123
|
-
transform: Viewport, ratio: number, logOptions: LogOptions): void {
|
|
133
|
+
transform: Viewport, ratio: number, logOptions: LogOptions, pointColor: number): void {
|
|
124
134
|
for (let i = 0; i < series.points.length!; i++) {
|
|
125
135
|
const p = series.points[i];
|
|
126
|
-
const color = p.outlier ? DG.Color.red :
|
|
127
|
-
series.pointColor ? DG.Color.fromHtml(series.pointColor) ?? DG.Color.scatterPlotMarker :
|
|
128
|
-
DG.Color.scatterPlotMarker;
|
|
136
|
+
const color = p.outlier ? DG.Color.red : pointColor;
|
|
129
137
|
DG.Paint.marker(g,
|
|
130
138
|
p.outlier ? DG.MARKER_TYPE.OUTLIER : (series.markerType as DG.MARKER_TYPE),
|
|
131
139
|
transform.xToScreen(p.x), transform.yToScreen(p.y), color,
|
|
@@ -135,7 +143,7 @@ function drawPoints(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
|
135
143
|
|
|
136
144
|
/** Performs candles drawing */
|
|
137
145
|
function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
138
|
-
transform: Viewport, ratio: number) : void {
|
|
146
|
+
transform: Viewport, ratio: number, markerColor: number) : void {
|
|
139
147
|
for (let i = 0, candleStart = null; i < series.points.length!; i++) {
|
|
140
148
|
const p = series.points[i];
|
|
141
149
|
if (p.outlier)
|
|
@@ -151,8 +159,7 @@ function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
|
151
159
|
const boxPlotStats = calculateBoxPlotStatistics(values);
|
|
152
160
|
|
|
153
161
|
g.beginPath();
|
|
154
|
-
drawCandlestick(g, p.x, boxPlotStats, transform, ratio,
|
|
155
|
-
DG.Color.fromHtml(series.pointColor) : DG.Color.scatterPlotMarker);
|
|
162
|
+
drawCandlestick(g, p.x, boxPlotStats, transform, ratio, markerColor);
|
|
156
163
|
g.stroke();
|
|
157
164
|
|
|
158
165
|
if (series.showPoints === 'both') {
|
|
@@ -173,14 +180,15 @@ function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
|
|
|
173
180
|
|
|
174
181
|
/** Performs a curve confidence interval drawing */
|
|
175
182
|
function drawConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals,
|
|
176
|
-
screenBounds: DG.Rect, transform: Viewport, confidenceType: string): void {
|
|
183
|
+
screenBounds: DG.Rect, transform: Viewport, confidenceType: string, showAxes: boolean): void {
|
|
177
184
|
g.beginPath();
|
|
178
|
-
|
|
185
|
+
const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
|
|
186
|
+
for (let i = axesLeftPxMargin; i <= screenBounds.width - AXES_RIGHT_PX_MARGIN; i++) {
|
|
179
187
|
const x = screenBounds.x + i;
|
|
180
188
|
const y = confidenceType === CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
|
|
181
189
|
transform.yToScreen(confIntervals.confidenceTop(transform.xToWorld(x))) :
|
|
182
190
|
transform.yToScreen(confIntervals.confidenceBottom(transform.xToWorld(x)));
|
|
183
|
-
if (i ===
|
|
191
|
+
if (i === axesLeftPxMargin)
|
|
184
192
|
g.moveTo(x, y);
|
|
185
193
|
else
|
|
186
194
|
g.lineTo(x, y);
|
|
@@ -190,19 +198,20 @@ function drawConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitC
|
|
|
190
198
|
|
|
191
199
|
/** Performs a curve confidence interval color filling */
|
|
192
200
|
function fillConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals,
|
|
193
|
-
screenBounds: DG.Rect, transform: Viewport): void {
|
|
201
|
+
screenBounds: DG.Rect, transform: Viewport, showAxes: boolean): void {
|
|
194
202
|
g.beginPath();
|
|
195
|
-
|
|
203
|
+
const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
|
|
204
|
+
for (let i = axesLeftPxMargin; i <= screenBounds.width - AXES_RIGHT_PX_MARGIN; i++) {
|
|
196
205
|
const x = screenBounds.x + i;
|
|
197
206
|
const y = transform.yToScreen(confIntervals.confidenceTop(transform.xToWorld(x)));
|
|
198
|
-
if (i ===
|
|
207
|
+
if (i === axesLeftPxMargin)
|
|
199
208
|
g.moveTo(x, y);
|
|
200
209
|
else
|
|
201
210
|
g.lineTo(x, y);
|
|
202
211
|
}
|
|
203
212
|
|
|
204
213
|
// reverse traverse to make a shape of confidence interval to fill it
|
|
205
|
-
for (let i = screenBounds.width; i >=
|
|
214
|
+
for (let i = screenBounds.width - AXES_RIGHT_PX_MARGIN; i >= axesLeftPxMargin; i--) {
|
|
206
215
|
const x = screenBounds.x + i;
|
|
207
216
|
const y = transform.yToScreen(confIntervals.confidenceBottom(transform.xToWorld(x)));
|
|
208
217
|
g.lineTo(x, y);
|
|
@@ -225,7 +234,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
225
234
|
get cellType() { return FIT_CELL_TYPE; }
|
|
226
235
|
|
|
227
236
|
getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
|
|
228
|
-
return {width:
|
|
237
|
+
return {width: 220, height: 150};
|
|
229
238
|
}
|
|
230
239
|
|
|
231
240
|
onClick(gridCell: DG.GridCell, e: MouseEvent): void {
|
|
@@ -238,8 +247,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
238
247
|
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
239
248
|
: getChartData(gridCell);
|
|
240
249
|
|
|
241
|
-
const screenBounds = gridCell.bounds.inflate(
|
|
242
|
-
const
|
|
250
|
+
const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
251
|
+
const showAxes = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
|
|
252
|
+
const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
|
|
253
|
+
const dataBox = layoutChart(screenBounds, showAxes, showTitle)[0];
|
|
243
254
|
const dataBounds = getChartBounds(data);
|
|
244
255
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
245
256
|
|
|
@@ -289,8 +300,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
289
300
|
g.rect(x, y, w, h);
|
|
290
301
|
g.clip();
|
|
291
302
|
|
|
292
|
-
const screenBounds = new DG.Rect(x, y, w, h).inflate(
|
|
293
|
-
const
|
|
303
|
+
const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
304
|
+
const showAxes = w >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && h >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT
|
|
305
|
+
&& !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
|
|
306
|
+
const showTitle = w >= MIN_TITLE_PX_WIDTH && h >= MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
|
|
307
|
+
const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxes, showTitle);
|
|
294
308
|
|
|
295
309
|
const dataBounds = getChartBounds(data);
|
|
296
310
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
@@ -298,9 +312,13 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
298
312
|
const ratio = minSize > 100 ? 1 : 0.2 + (minSize / 100) * 0.8;
|
|
299
313
|
const chartLogOptions: LogOptions = {logX: data.chartOptions?.logX, logY: data.chartOptions?.logY};
|
|
300
314
|
|
|
315
|
+
g.save();
|
|
316
|
+
g.font = '11px Roboto, "Roboto Local"';
|
|
301
317
|
viewport.drawCoordinateGrid(g, xAxisBox, yAxisBox);
|
|
318
|
+
g.restore();
|
|
302
319
|
|
|
303
|
-
for (
|
|
320
|
+
for (let i = 0; i < data.series?.length!; i++) {
|
|
321
|
+
const series = data.series![i];
|
|
304
322
|
if (w < MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH || h < MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
|
|
305
323
|
series.showPoints = '';
|
|
306
324
|
if (data.chartOptions)
|
|
@@ -321,50 +339,56 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
321
339
|
series.parameters = fitResult.parameters;
|
|
322
340
|
userParamsFlag = false;
|
|
323
341
|
}
|
|
324
|
-
|
|
342
|
+
|
|
325
343
|
if (series.showPoints ?? 'points') {
|
|
326
|
-
|
|
344
|
+
const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
|
|
345
|
+
series.pointColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
346
|
+
g.strokeStyle = pointColor;
|
|
327
347
|
if (series.showPoints === 'points')
|
|
328
|
-
drawPoints(g, series, viewport, ratio, chartLogOptions);
|
|
348
|
+
drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor));
|
|
329
349
|
else if (['candlesticks', 'both'].includes(series.showPoints!))
|
|
330
|
-
drawCandles(g, series, viewport, ratio);
|
|
350
|
+
drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
|
|
331
351
|
}
|
|
332
|
-
|
|
352
|
+
|
|
333
353
|
if (series.showFitLine ?? true) {
|
|
334
|
-
|
|
354
|
+
const lineColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
|
|
355
|
+
series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
356
|
+
g.strokeStyle = lineColor;
|
|
335
357
|
g.lineWidth = 2 * ratio;
|
|
336
|
-
|
|
358
|
+
|
|
337
359
|
g.beginPath();
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const
|
|
360
|
+
const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
|
|
361
|
+
for (let j = axesLeftPxMargin; j <= screenBounds.width - AXES_RIGHT_PX_MARGIN; j++) {
|
|
362
|
+
const x = screenBounds.x + j;
|
|
363
|
+
const xForY = data.chartOptions?.logX ? Math.log10(viewport.xToWorld(x)) : viewport.xToWorld(x);
|
|
364
|
+
const y = data.chartOptions?.logY ? viewport.yToScreen(Math.pow(10, curve(xForY))) : viewport.yToScreen(curve(xForY));
|
|
341
365
|
viewport.yToScreen(curve(viewport.xToWorld(x)));
|
|
342
|
-
if (
|
|
366
|
+
if (j === axesLeftPxMargin)
|
|
343
367
|
g.moveTo(x, y);
|
|
344
368
|
else
|
|
345
369
|
g.lineTo(x, y);
|
|
346
370
|
}
|
|
347
371
|
g.stroke();
|
|
348
372
|
}
|
|
349
|
-
|
|
373
|
+
|
|
350
374
|
if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
|
|
351
375
|
g.strokeStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_STROKE_COLOR;
|
|
352
376
|
g.fillStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_FILL_COLOR;
|
|
353
|
-
|
|
377
|
+
|
|
354
378
|
const confidenceIntervals = getSeriesConfidenceInterval(series, fitFunc, userParamsFlag);
|
|
355
|
-
drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP);
|
|
356
|
-
drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM);
|
|
357
|
-
fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport);
|
|
379
|
+
drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP, showAxes);
|
|
380
|
+
drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM, showAxes);
|
|
381
|
+
fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, showAxes);
|
|
358
382
|
}
|
|
359
|
-
|
|
383
|
+
|
|
360
384
|
if (series.droplines) {
|
|
361
385
|
g.save();
|
|
362
386
|
g.strokeStyle = 'blue';
|
|
363
387
|
g.lineWidth = ratio;
|
|
364
388
|
g.beginPath();
|
|
365
389
|
g.setLineDash([5, 5]);
|
|
366
|
-
for (let
|
|
367
|
-
const droplineName = series.droplines[
|
|
390
|
+
for (let j = 0; j < series.droplines.length; j++) {
|
|
391
|
+
const droplineName = series.droplines[j];
|
|
368
392
|
if (droplineName === 'IC50')
|
|
369
393
|
drawDropline(g, viewport, series.parameters[2], dataBounds, curve);
|
|
370
394
|
}
|
|
@@ -374,18 +398,40 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
374
398
|
|
|
375
399
|
if (data.chartOptions?.showStatistics) {
|
|
376
400
|
const statistics = getSeriesStatistics(series, fitFunc);
|
|
377
|
-
for (let
|
|
378
|
-
const statName = data.chartOptions.showStatistics[
|
|
401
|
+
for (let j = 0; j < data.chartOptions.showStatistics.length; j++) {
|
|
402
|
+
const statName = data.chartOptions.showStatistics[j];
|
|
379
403
|
const prop = statisticsProperties.find(p => p.name === statName);
|
|
380
404
|
if (prop) {
|
|
381
405
|
const s = StringUtils.formatNumber(prop.get(statistics));
|
|
382
|
-
|
|
406
|
+
const statColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
|
|
407
|
+
series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
|
|
408
|
+
g.fillStyle = statColor;
|
|
383
409
|
g.textAlign = 'left';
|
|
384
|
-
g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 *
|
|
410
|
+
g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 * j);
|
|
385
411
|
}
|
|
386
412
|
}
|
|
387
413
|
}
|
|
388
414
|
}
|
|
415
|
+
|
|
416
|
+
if (showTitle) {
|
|
417
|
+
g.font = '12px Roboto, "Roboto Local"';
|
|
418
|
+
g.textAlign = 'center';
|
|
419
|
+
g.fillStyle = 'black';
|
|
420
|
+
g.fillText(data.chartOptions?.title!, dataBox.midX - 5, y + 15);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (showAxes) {
|
|
424
|
+
g.font = '11px Roboto, "Roboto Local"';
|
|
425
|
+
g.textAlign = 'center';
|
|
426
|
+
g.fillStyle = 'black';
|
|
427
|
+
g.fillText(data.chartOptions?.xAxisName!, dataBox.midX - 5, y + h - 10);
|
|
428
|
+
g.translate(x, y);
|
|
429
|
+
g.rotate(-Math.PI / 2);
|
|
430
|
+
const axesTopPxMargin = showTitle ? AXES_TOP_PX_MARGIN_WITH_TITLE : AXES_TOP_PX_MARGIN;
|
|
431
|
+
g.fillText(data.chartOptions?.yAxisName!, -(dataBox.height / 2 + axesTopPxMargin + 15), 15);
|
|
432
|
+
g.restore();
|
|
433
|
+
}
|
|
434
|
+
|
|
389
435
|
g.restore();
|
|
390
436
|
}
|
|
391
437
|
|
|
@@ -420,8 +466,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
|
|
|
420
466
|
? convertXMLToIFitChartData(gridCell.cell.value)
|
|
421
467
|
: getChartData(gridCell);
|
|
422
468
|
|
|
423
|
-
const screenBounds = gridCell.bounds.inflate(
|
|
424
|
-
const
|
|
469
|
+
const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
470
|
+
const showAxes = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
|
|
471
|
+
const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
|
|
472
|
+
const dataBox = layoutChart(screenBounds, showAxes, showTitle)[0];
|
|
425
473
|
const dataBounds = getChartBounds(data);
|
|
426
474
|
const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
|
|
427
475
|
|
|
@@ -9,18 +9,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import * as DG from 'datagrok-api/dg';
|
|
11
11
|
import { Viewport } from '@datagrok-libraries/utils/src/transform';
|
|
12
|
-
import { layoutChart } from '../fit/fit-renderer';
|
|
12
|
+
import { layoutChart, INFLATE_SIZE } from '../fit/fit-renderer';
|
|
13
13
|
import { category, expect, test } from '@datagrok-libraries/utils/src/test';
|
|
14
14
|
category('viewport', () => {
|
|
15
15
|
test('viewportMethods', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const screenBounds = new DG.Rect(120, 20, 160, 100).inflate(
|
|
17
|
-
const [dataBox] = layoutChart(screenBounds);
|
|
16
|
+
const screenBounds = new DG.Rect(120, 20, 160, 100).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
17
|
+
const [dataBox] = layoutChart(screenBounds, false, false);
|
|
18
18
|
const dataBounds = new DG.Rect(0.1, 0.06, 7, 5.94);
|
|
19
19
|
const viewport = new Viewport(dataBounds, dataBox, false, false);
|
|
20
|
-
expect(viewport.xToScreen(1.5),
|
|
21
|
-
expect(viewport.yToScreen(2.33),
|
|
22
|
-
expect(viewport.xToWorld(150), -0.
|
|
23
|
-
expect(viewport.yToWorld(67),
|
|
20
|
+
expect(viewport.xToScreen(1.5), 182.4);
|
|
21
|
+
expect(viewport.yToScreen(2.33), 58.803030303030305);
|
|
22
|
+
expect(viewport.xToWorld(150), -0.9652173913043479);
|
|
23
|
+
expect(viewport.yToWorld(67), 1.2479999999999998);
|
|
24
24
|
}));
|
|
25
25
|
});
|
|
26
26
|
//# sourceMappingURL=transform-tests.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-tests.js","sourceRoot":"","sources":["transform-tests.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAAC,QAAQ,EAAC,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"transform-tests.js","sourceRoot":"","sources":["transform-tests.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAEtC,OAAO,EAAC,QAAQ,EAAC,MAAM,yCAAyC,CAAC;AACjE,OAAO,EAAC,WAAW,EAAE,YAAY,EAAC,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,oCAAoC,CAAC;AAG1E,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;IACxB,IAAI,CAAC,iBAAiB,EAAE,GAAS,EAAE;QACjC,MAAM,YAAY,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,GAAG,CAAC,EAAE,YAAY,GAAG,CAAC,CAAC,CAAC;QAChG,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,YAAY,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1D,MAAM,UAAU,GAAG,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAEnE,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;QACvC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,kBAAkB,CAAC,CAAC;QACrD,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,kBAAkB,CAAC,CAAC;IAClD,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import * as DG from 'datagrok-api/dg';
|
|
2
2
|
|
|
3
3
|
import {Viewport} from '@datagrok-libraries/utils/src/transform';
|
|
4
|
-
import {layoutChart} from '../fit/fit-renderer';
|
|
4
|
+
import {layoutChart, INFLATE_SIZE} from '../fit/fit-renderer';
|
|
5
5
|
|
|
6
6
|
import {category, expect, test} from '@datagrok-libraries/utils/src/test';
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
category('viewport', () => {
|
|
10
10
|
test('viewportMethods', async () => {
|
|
11
|
-
const screenBounds = new DG.Rect(120, 20, 160, 100).inflate(
|
|
12
|
-
const [dataBox] = layoutChart(screenBounds);
|
|
11
|
+
const screenBounds = new DG.Rect(120, 20, 160, 100).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
|
|
12
|
+
const [dataBox] = layoutChart(screenBounds, false, false);
|
|
13
13
|
const dataBounds = new DG.Rect(0.1, 0.06, 7, 5.94);
|
|
14
14
|
const viewport = new Viewport(dataBounds, dataBox, false, false);
|
|
15
15
|
|
|
16
|
-
expect(viewport.xToScreen(1.5),
|
|
17
|
-
expect(viewport.yToScreen(2.33),
|
|
18
|
-
expect(viewport.xToWorld(150), -0.
|
|
19
|
-
expect(viewport.yToWorld(67),
|
|
16
|
+
expect(viewport.xToScreen(1.5), 182.4);
|
|
17
|
+
expect(viewport.yToScreen(2.33), 58.803030303030305);
|
|
18
|
+
expect(viewport.xToWorld(150), -0.9652173913043479);
|
|
19
|
+
expect(viewport.yToWorld(67), 1.2479999999999998);
|
|
20
20
|
});
|
|
21
21
|
});
|