@datagrok/curves 1.2.3 → 1.2.5

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.
@@ -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 MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH = 150;
50
- const MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT = 100;
51
- const AXES_LEFT_PX_MARGIN = 30;
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(AXES_LEFT_PX_MARGIN).cutBottom(AXES_BOTTOM_PX_MARGIN).cutTop(AXES_TOP_PX_MARGIN),
99
- rect.getBottom(AXES_BOTTOM_PX_MARGIN).getTop(AXES_TOP_PX_MARGIN).cutLeft(AXES_LEFT_PX_MARGIN),
100
- rect.getLeft(AXES_LEFT_PX_MARGIN).cutBottom(AXES_BOTTOM_PX_MARGIN).cutTop(AXES_TOP_PX_MARGIN)
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,22 +130,29 @@ 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
136
  const color = p.outlier ? DG.Color.red :
127
- series.pointColor ? DG.Color.fromHtml(series.pointColor) ?? DG.Color.scatterPlotMarker :
128
- DG.Color.scatterPlotMarker;
137
+ p.color ? DG.Color.fromHtml(p.color) ? DG.Color.fromHtml(p.color) : pointColor : pointColor;
138
+ const marker = p.marker ? p.marker as DG.MARKER_TYPE : series.markerType as DG.MARKER_TYPE;
139
+ const size = p.outlier ? OUTLIER_PX_SIZE * ratio : p.size ? p.size : POINT_PX_SIZE * ratio;
129
140
  DG.Paint.marker(g,
130
- p.outlier ? DG.MARKER_TYPE.OUTLIER : (series.markerType as DG.MARKER_TYPE),
131
- transform.xToScreen(p.x), transform.yToScreen(p.y), color,
132
- (p.outlier ? OUTLIER_PX_SIZE : POINT_PX_SIZE) * ratio);
141
+ p.outlier ? DG.MARKER_TYPE.OUTLIER : marker,
142
+ transform.xToScreen(p.x), transform.yToScreen(p.y), color, size);
143
+ if (p.stdev && !p.outlier) {
144
+ g.strokeStyle = DG.Color.toHtml(color);
145
+ g.beginPath();
146
+ g.moveTo(transform.xToScreen(p.x), transform.yToScreen(p.y + p.stdev));
147
+ g.lineTo(transform.xToScreen(p.x), transform.yToScreen(p.y - p.stdev));
148
+ g.stroke();
149
+ }
133
150
  }
134
151
  }
135
152
 
136
153
  /** Performs candles drawing */
137
154
  function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
138
- transform: Viewport, ratio: number) : void {
155
+ transform: Viewport, ratio: number, markerColor: number) : void {
139
156
  for (let i = 0, candleStart = null; i < series.points.length!; i++) {
140
157
  const p = series.points[i];
141
158
  if (p.outlier)
@@ -151,8 +168,7 @@ function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
151
168
  const boxPlotStats = calculateBoxPlotStatistics(values);
152
169
 
153
170
  g.beginPath();
154
- drawCandlestick(g, p.x, boxPlotStats, transform, ratio, series.pointColor ?
155
- DG.Color.fromHtml(series.pointColor) : DG.Color.scatterPlotMarker);
171
+ drawCandlestick(g, p.x, boxPlotStats, transform, ratio, markerColor);
156
172
  g.stroke();
157
173
 
158
174
  if (series.showPoints === 'both') {
@@ -173,14 +189,15 @@ function drawCandles(g: CanvasRenderingContext2D, series: IFitSeries,
173
189
 
174
190
  /** Performs a curve confidence interval drawing */
175
191
  function drawConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals,
176
- screenBounds: DG.Rect, transform: Viewport, confidenceType: string): void {
192
+ screenBounds: DG.Rect, transform: Viewport, confidenceType: string, showAxes: boolean): void {
177
193
  g.beginPath();
178
- for (let i = AXES_LEFT_PX_MARGIN; i <= screenBounds.width; i++) {
194
+ const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
195
+ for (let i = axesLeftPxMargin; i <= screenBounds.width - AXES_RIGHT_PX_MARGIN; i++) {
179
196
  const x = screenBounds.x + i;
180
197
  const y = confidenceType === CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP ?
181
198
  transform.yToScreen(confIntervals.confidenceTop(transform.xToWorld(x))) :
182
199
  transform.yToScreen(confIntervals.confidenceBottom(transform.xToWorld(x)));
183
- if (i === AXES_LEFT_PX_MARGIN)
200
+ if (i === axesLeftPxMargin)
184
201
  g.moveTo(x, y);
185
202
  else
186
203
  g.lineTo(x, y);
@@ -190,19 +207,20 @@ function drawConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitC
190
207
 
191
208
  /** Performs a curve confidence interval color filling */
192
209
  function fillConfidenceInterval(g: CanvasRenderingContext2D, confIntervals: FitConfidenceIntervals,
193
- screenBounds: DG.Rect, transform: Viewport): void {
210
+ screenBounds: DG.Rect, transform: Viewport, showAxes: boolean): void {
194
211
  g.beginPath();
195
- for (let i = AXES_LEFT_PX_MARGIN; i <= screenBounds.width; i++) {
212
+ const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
213
+ for (let i = axesLeftPxMargin; i <= screenBounds.width - AXES_RIGHT_PX_MARGIN; i++) {
196
214
  const x = screenBounds.x + i;
197
215
  const y = transform.yToScreen(confIntervals.confidenceTop(transform.xToWorld(x)));
198
- if (i === AXES_LEFT_PX_MARGIN)
216
+ if (i === axesLeftPxMargin)
199
217
  g.moveTo(x, y);
200
218
  else
201
219
  g.lineTo(x, y);
202
220
  }
203
221
 
204
222
  // reverse traverse to make a shape of confidence interval to fill it
205
- for (let i = screenBounds.width; i >= AXES_LEFT_PX_MARGIN; i--) {
223
+ for (let i = screenBounds.width - AXES_RIGHT_PX_MARGIN; i >= axesLeftPxMargin; i--) {
206
224
  const x = screenBounds.x + i;
207
225
  const y = transform.yToScreen(confIntervals.confidenceBottom(transform.xToWorld(x)));
208
226
  g.lineTo(x, y);
@@ -225,7 +243,7 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
225
243
  get cellType() { return FIT_CELL_TYPE; }
226
244
 
227
245
  getDefaultSize(gridColumn: DG.GridColumn): {width?: number | null, height?: number | null} {
228
- return {width: 160, height: 120};
246
+ return {width: 220, height: 150};
229
247
  }
230
248
 
231
249
  onClick(gridCell: DG.GridCell, e: MouseEvent): void {
@@ -238,8 +256,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
238
256
  ? convertXMLToIFitChartData(gridCell.cell.value)
239
257
  : getChartData(gridCell);
240
258
 
241
- const screenBounds = gridCell.bounds.inflate(-6, -6);
242
- const dataBox = layoutChart(screenBounds)[0];
259
+ const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
260
+ const showAxes = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
261
+ const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
262
+ const dataBox = layoutChart(screenBounds, showAxes, showTitle)[0];
243
263
  const dataBounds = getChartBounds(data);
244
264
  const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
245
265
 
@@ -289,8 +309,11 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
289
309
  g.rect(x, y, w, h);
290
310
  g.clip();
291
311
 
292
- const screenBounds = new DG.Rect(x, y, w, h).inflate(-6, -6);
293
- const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds);
312
+ const screenBounds = new DG.Rect(x, y, w, h).inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
313
+ const showAxes = w >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && h >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT
314
+ && !!data.chartOptions?.xAxisName && !!data.chartOptions.yAxisName;
315
+ const showTitle = w >= MIN_TITLE_PX_WIDTH && h >= MIN_TITLE_PX_HEIGHT && !!data.chartOptions?.title;
316
+ const [dataBox, xAxisBox, yAxisBox] = layoutChart(screenBounds, showAxes, showTitle);
294
317
 
295
318
  const dataBounds = getChartBounds(data);
296
319
  const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
@@ -298,9 +321,13 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
298
321
  const ratio = minSize > 100 ? 1 : 0.2 + (minSize / 100) * 0.8;
299
322
  const chartLogOptions: LogOptions = {logX: data.chartOptions?.logX, logY: data.chartOptions?.logY};
300
323
 
324
+ g.save();
325
+ g.font = '11px Roboto, "Roboto Local"';
301
326
  viewport.drawCoordinateGrid(g, xAxisBox, yAxisBox);
327
+ g.restore();
302
328
 
303
- for (const series of data.series!) {
329
+ for (let i = 0; i < data.series?.length!; i++) {
330
+ const series = data.series![i];
304
331
  if (w < MIN_POINTS_AND_STATS_VISIBILITY_PX_WIDTH || h < MIN_POINTS_AND_STATS_VISIBILITY_PX_HEIGHT) {
305
332
  series.showPoints = '';
306
333
  if (data.chartOptions)
@@ -321,50 +348,56 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
321
348
  series.parameters = fitResult.parameters;
322
349
  userParamsFlag = false;
323
350
  }
324
-
351
+
325
352
  if (series.showPoints ?? 'points') {
326
- g.strokeStyle = series.pointColor ?? '0xFF40699c';
353
+ const pointColor = series.pointColor ? DG.Color.fromHtml(series.pointColor) ?
354
+ series.pointColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
355
+ g.strokeStyle = pointColor;
327
356
  if (series.showPoints === 'points')
328
- drawPoints(g, series, viewport, ratio, chartLogOptions);
357
+ drawPoints(g, series, viewport, ratio, chartLogOptions, DG.Color.fromHtml(pointColor));
329
358
  else if (['candlesticks', 'both'].includes(series.showPoints!))
330
- drawCandles(g, series, viewport, ratio);
359
+ drawCandles(g, series, viewport, ratio, DG.Color.fromHtml(pointColor));
331
360
  }
332
-
361
+
333
362
  if (series.showFitLine ?? true) {
334
- g.strokeStyle = series.fitLineColor ?? 'black';
363
+ const lineColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
364
+ series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
365
+ g.strokeStyle = lineColor;
335
366
  g.lineWidth = 2 * ratio;
336
-
367
+
337
368
  g.beginPath();
338
- for (let i = AXES_LEFT_PX_MARGIN; i <= screenBounds.width; i++) {
339
- const x = screenBounds.x + i;
340
- const y = data.chartOptions?.logX ? viewport.yToScreen(Math.pow(10, curve(Math.log10(viewport.xToWorld(x))))) :
369
+ const axesLeftPxMargin = showAxes ? AXES_LEFT_PX_MARGIN_WITH_AXES_LABELS : AXES_LEFT_PX_MARGIN;
370
+ for (let j = axesLeftPxMargin; j <= screenBounds.width - AXES_RIGHT_PX_MARGIN; j++) {
371
+ const x = screenBounds.x + j;
372
+ const xForY = data.chartOptions?.logX ? Math.log10(viewport.xToWorld(x)) : viewport.xToWorld(x);
373
+ const y = data.chartOptions?.logY ? viewport.yToScreen(Math.pow(10, curve(xForY))) : viewport.yToScreen(curve(xForY));
341
374
  viewport.yToScreen(curve(viewport.xToWorld(x)));
342
- if (i === AXES_LEFT_PX_MARGIN)
375
+ if (j === axesLeftPxMargin)
343
376
  g.moveTo(x, y);
344
377
  else
345
378
  g.lineTo(x, y);
346
379
  }
347
380
  g.stroke();
348
381
  }
349
-
382
+
350
383
  if ((series.showFitLine ?? true) && (series.showCurveConfidenceInterval ?? false)) {
351
384
  g.strokeStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_STROKE_COLOR;
352
385
  g.fillStyle = series.confidenceIntervalColor ?? CONFIDENCE_INTERVAL_FILL_COLOR;
353
-
386
+
354
387
  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);
388
+ drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, CURVE_CONFIDENCE_INTERVAL_BOUNDS.TOP, showAxes);
389
+ drawConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, CURVE_CONFIDENCE_INTERVAL_BOUNDS.BOTTOM, showAxes);
390
+ fillConfidenceInterval(g, confidenceIntervals, screenBounds, viewport, showAxes);
358
391
  }
359
-
392
+
360
393
  if (series.droplines) {
361
394
  g.save();
362
395
  g.strokeStyle = 'blue';
363
396
  g.lineWidth = ratio;
364
397
  g.beginPath();
365
398
  g.setLineDash([5, 5]);
366
- for (let i = 0; i < series.droplines.length; i++) {
367
- const droplineName = series.droplines[i];
399
+ for (let j = 0; j < series.droplines.length; j++) {
400
+ const droplineName = series.droplines[j];
368
401
  if (droplineName === 'IC50')
369
402
  drawDropline(g, viewport, series.parameters[2], dataBounds, curve);
370
403
  }
@@ -374,18 +407,40 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
374
407
 
375
408
  if (data.chartOptions?.showStatistics) {
376
409
  const statistics = getSeriesStatistics(series, fitFunc);
377
- for (let i = 0; i < data.chartOptions.showStatistics.length; i++) {
378
- const statName = data.chartOptions.showStatistics[i];
410
+ for (let j = 0; j < data.chartOptions.showStatistics.length; j++) {
411
+ const statName = data.chartOptions.showStatistics[j];
379
412
  const prop = statisticsProperties.find(p => p.name === statName);
380
413
  if (prop) {
381
414
  const s = StringUtils.formatNumber(prop.get(statistics));
382
- g.fillStyle = series.fitLineColor ?? 'black';
415
+ const statColor = series.fitLineColor ? DG.Color.fromHtml(series.fitLineColor) ?
416
+ series.fitLineColor : DG.Color.toHtml(DG.Color.getCategoricalColor(i)) : DG.Color.toHtml(DG.Color.getCategoricalColor(i));
417
+ g.fillStyle = statColor;
383
418
  g.textAlign = 'left';
384
- g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 * i);
419
+ g.fillText(prop.name + ': ' + s, dataBox.x + 5, dataBox.y + 20 + 20 * j);
385
420
  }
386
421
  }
387
422
  }
388
423
  }
424
+
425
+ if (showTitle) {
426
+ g.font = '12px Roboto, "Roboto Local"';
427
+ g.textAlign = 'center';
428
+ g.fillStyle = 'black';
429
+ g.fillText(data.chartOptions?.title!, dataBox.midX - 5, y + 15);
430
+ }
431
+
432
+ if (showAxes) {
433
+ g.font = '11px Roboto, "Roboto Local"';
434
+ g.textAlign = 'center';
435
+ g.fillStyle = 'black';
436
+ g.fillText(data.chartOptions?.xAxisName!, dataBox.midX - 5, y + h - 10);
437
+ g.translate(x, y);
438
+ g.rotate(-Math.PI / 2);
439
+ const axesTopPxMargin = showTitle ? AXES_TOP_PX_MARGIN_WITH_TITLE : AXES_TOP_PX_MARGIN;
440
+ g.fillText(data.chartOptions?.yAxisName!, -(dataBox.height / 2 + axesTopPxMargin + 15), 15);
441
+ g.restore();
442
+ }
443
+
389
444
  g.restore();
390
445
  }
391
446
 
@@ -420,8 +475,10 @@ export class FitChartCellRenderer extends DG.GridCellRenderer {
420
475
  ? convertXMLToIFitChartData(gridCell.cell.value)
421
476
  : getChartData(gridCell);
422
477
 
423
- const screenBounds = gridCell.bounds.inflate(-6, -6);
424
- const dataBox = layoutChart(screenBounds)[0];
478
+ const screenBounds = gridCell.bounds.inflate(INFLATE_SIZE / 2, INFLATE_SIZE / 2);
479
+ const showAxes = gridCell.bounds.width >= MIN_X_AXIS_NAME_VISIBILITY_PX_WIDTH && gridCell.bounds.height >= MIN_Y_AXIS_NAME_VISIBILITY_PX_HEIGHT;
480
+ const showTitle = gridCell.bounds.width >= MIN_TITLE_PX_WIDTH && gridCell.bounds.height >= MIN_TITLE_PX_HEIGHT;
481
+ const dataBox = layoutChart(screenBounds, showAxes, showTitle)[0];
425
482
  const dataBounds = getChartBounds(data);
426
483
  const viewport = new Viewport(dataBounds, dataBox, data.chartOptions?.logX ?? false, data.chartOptions?.logY ?? false);
427
484
 
@@ -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(-6, -6);
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), 179.6);
21
- expect(viewport.yToScreen(2.33), 73.01346801346801);
22
- expect(viewport.xToWorld(150), -0.2559322033898306);
23
- expect(viewport.yToWorld(67), 2.855294117647059);
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;AAEhD,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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QACpE,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;QAC5C,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,iBAAiB,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC,kBAAkB,CAAC,CAAC;QACpD,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,iBAAiB,CAAC,CAAC;IACjD,CAAC,CAAA,CAAC,CAAC;AACL,CAAC,CAAC,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(-6, -6);
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), 179.6);
17
- expect(viewport.yToScreen(2.33), 73.01346801346801);
18
- expect(viewport.xToWorld(150), -0.2559322033898306);
19
- expect(viewport.yToWorld(67), 2.855294117647059);
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
  });