@gravity-ui/charts 1.24.1 → 1.24.2

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.
@@ -217,9 +217,9 @@ function isSeriesWithXAxisOffset(series) {
217
217
  const types = [SERIES_TYPE.Heatmap];
218
218
  return series.some((s) => types.includes(s.type));
219
219
  }
220
- function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, maxPadding, }) {
220
+ function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, }) {
221
221
  const xAxisZoomPadding = boundsWidth * X_AXIS_ZOOM_PADDING;
222
- const xRange = [0, boundsWidth - maxPadding];
222
+ const xRange = [0, boundsWidth];
223
223
  const xRangeZoom = [0 + xAxisZoomPadding, boundsWidth - xAxisZoomPadding];
224
224
  const range = hasZoomX ? xRangeZoom : xRange;
225
225
  const barXSeries = series.filter((s) => s.type === SERIES_TYPE.BarX);
@@ -227,7 +227,7 @@ function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, ma
227
227
  const groupedData = groupBarXDataByXValue(barXSeries, axis);
228
228
  if (Object.keys(groupedData).length > 1) {
229
229
  const { bandSize } = getBarXLayoutForNumericScale({
230
- plotWidth: boundsWidth - maxPadding,
230
+ plotWidth: boundsWidth,
231
231
  groupedData,
232
232
  seriesOptions,
233
233
  });
@@ -264,7 +264,6 @@ export function createXScale(args) {
264
264
  seriesOptions,
265
265
  hasZoomX,
266
266
  axis,
267
- maxPadding: xAxisMaxPadding,
268
267
  });
269
268
  switch (axis.order) {
270
269
  case 'sortDesc':
@@ -310,7 +309,7 @@ export function createXScale(args) {
310
309
  const scaleFn = xType === 'logarithmic' ? scaleLog : scaleLinear;
311
310
  const scale = scaleFn().domain([xMin, xMax]).range(range);
312
311
  let offsetMin = 0;
313
- let offsetMax = 0;
312
+ let offsetMax = xAxisMaxPadding;
314
313
  const hasOffset = isSeriesWithXAxisOffset(series);
315
314
  if (hasOffset) {
316
315
  if (domainData.length > 1) {
@@ -324,10 +323,15 @@ export function createXScale(args) {
324
323
  }
325
324
  const domainOffsetMin = Math.abs(scale.invert(offsetMin) - scale.invert(0));
326
325
  const domainOffsetMax = Math.abs(scale.invert(offsetMax) - scale.invert(0));
326
+ // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
327
+ const nicedDomain = scale.copy().nice(Math.max(10, domainData.length)).domain();
327
328
  scale.domain([xMin - domainOffsetMin, xMax + domainOffsetMax]);
328
- if (!hasZoomX && !hasOffset) {
329
- // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
330
- scale.nice(Math.max(10, domainData.length));
329
+ if (!hasZoomX && !hasOffset && nicedDomain.length === 2) {
330
+ const domainWithOffset = scale.domain();
331
+ scale.domain([
332
+ Math.min(nicedDomain[0], domainWithOffset[0]),
333
+ Math.max(nicedDomain[1], domainWithOffset[1]),
334
+ ]);
331
335
  }
332
336
  return scale;
333
337
  }
@@ -371,7 +375,7 @@ export function createXScale(args) {
371
375
  domain = [xMin, xMax];
372
376
  const scale = scaleUtc().domain(domain).range(range);
373
377
  let offsetMin = 0;
374
- let offsetMax = 0;
378
+ let offsetMax = xAxisMaxPadding;
375
379
  const hasOffset = isSeriesWithXAxisOffset(series);
376
380
  if (hasOffset) {
377
381
  if (domainData.length > 1) {
@@ -385,10 +389,15 @@ export function createXScale(args) {
385
389
  }
386
390
  const domainOffsetMin = Math.abs(scale.invert(offsetMin).getTime() - scale.invert(0).getTime());
387
391
  const domainOffsetMax = Math.abs(scale.invert(offsetMax).getTime() - scale.invert(0).getTime());
392
+ // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
393
+ const nicedDomain = scale.copy().nice(Math.max(10, domainData.length)).domain();
388
394
  scale.domain([xMin - domainOffsetMin, xMax + domainOffsetMax]);
389
- if (!hasZoomX && !hasOffset) {
390
- // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
391
- scale.nice(Math.max(10, domainData.length));
395
+ if (!hasZoomX && !hasOffset && nicedDomain.length === 2) {
396
+ const domainWithOffset = scale.domain();
397
+ scale.domain([
398
+ Math.min(Number(nicedDomain[0]), Number(domainWithOffset[0])),
399
+ Math.max(Number(nicedDomain[1]), Number(domainWithOffset[1])),
400
+ ]);
392
401
  }
393
402
  return scale;
394
403
  }
@@ -76,7 +76,7 @@ export const prepareAreaData = async (args) => {
76
76
  var _a, _b;
77
77
  const { series, xAxis, xScale, yAxis, yScale, boundsHeight: plotHeight, split, isOutsideBounds, } = args;
78
78
  const [_xMin, xRangeMax] = xScale.range();
79
- const xMax = xRangeMax / (1 - xAxis.maxPadding);
79
+ const xMax = xRangeMax;
80
80
  const result = [];
81
81
  const dataByPlots = Array.from(group(series, (s) => {
82
82
  const yAxisIndex = s.yAxis;
@@ -16,7 +16,7 @@ export const prepareLineData = async (args) => {
16
16
  var _a;
17
17
  const { series, xAxis, yAxis, xScale, yScale, split, isOutsideBounds } = args;
18
18
  const [_xMin, xRangeMax] = xScale.range();
19
- const xMax = xRangeMax / (1 - xAxis.maxPadding);
19
+ const xMax = xRangeMax;
20
20
  const acc = [];
21
21
  for (let i = 0; i < series.length; i++) {
22
22
  const s = series[i];
@@ -217,9 +217,9 @@ function isSeriesWithXAxisOffset(series) {
217
217
  const types = [SERIES_TYPE.Heatmap];
218
218
  return series.some((s) => types.includes(s.type));
219
219
  }
220
- function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, maxPadding, }) {
220
+ function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, }) {
221
221
  const xAxisZoomPadding = boundsWidth * X_AXIS_ZOOM_PADDING;
222
- const xRange = [0, boundsWidth - maxPadding];
222
+ const xRange = [0, boundsWidth];
223
223
  const xRangeZoom = [0 + xAxisZoomPadding, boundsWidth - xAxisZoomPadding];
224
224
  const range = hasZoomX ? xRangeZoom : xRange;
225
225
  const barXSeries = series.filter((s) => s.type === SERIES_TYPE.BarX);
@@ -227,7 +227,7 @@ function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, ma
227
227
  const groupedData = groupBarXDataByXValue(barXSeries, axis);
228
228
  if (Object.keys(groupedData).length > 1) {
229
229
  const { bandSize } = getBarXLayoutForNumericScale({
230
- plotWidth: boundsWidth - maxPadding,
230
+ plotWidth: boundsWidth,
231
231
  groupedData,
232
232
  seriesOptions,
233
233
  });
@@ -264,7 +264,6 @@ export function createXScale(args) {
264
264
  seriesOptions,
265
265
  hasZoomX,
266
266
  axis,
267
- maxPadding: xAxisMaxPadding,
268
267
  });
269
268
  switch (axis.order) {
270
269
  case 'sortDesc':
@@ -310,7 +309,7 @@ export function createXScale(args) {
310
309
  const scaleFn = xType === 'logarithmic' ? scaleLog : scaleLinear;
311
310
  const scale = scaleFn().domain([xMin, xMax]).range(range);
312
311
  let offsetMin = 0;
313
- let offsetMax = 0;
312
+ let offsetMax = xAxisMaxPadding;
314
313
  const hasOffset = isSeriesWithXAxisOffset(series);
315
314
  if (hasOffset) {
316
315
  if (domainData.length > 1) {
@@ -324,10 +323,15 @@ export function createXScale(args) {
324
323
  }
325
324
  const domainOffsetMin = Math.abs(scale.invert(offsetMin) - scale.invert(0));
326
325
  const domainOffsetMax = Math.abs(scale.invert(offsetMax) - scale.invert(0));
326
+ // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
327
+ const nicedDomain = scale.copy().nice(Math.max(10, domainData.length)).domain();
327
328
  scale.domain([xMin - domainOffsetMin, xMax + domainOffsetMax]);
328
- if (!hasZoomX && !hasOffset) {
329
- // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
330
- scale.nice(Math.max(10, domainData.length));
329
+ if (!hasZoomX && !hasOffset && nicedDomain.length === 2) {
330
+ const domainWithOffset = scale.domain();
331
+ scale.domain([
332
+ Math.min(nicedDomain[0], domainWithOffset[0]),
333
+ Math.max(nicedDomain[1], domainWithOffset[1]),
334
+ ]);
331
335
  }
332
336
  return scale;
333
337
  }
@@ -371,7 +375,7 @@ export function createXScale(args) {
371
375
  domain = [xMin, xMax];
372
376
  const scale = scaleUtc().domain(domain).range(range);
373
377
  let offsetMin = 0;
374
- let offsetMax = 0;
378
+ let offsetMax = xAxisMaxPadding;
375
379
  const hasOffset = isSeriesWithXAxisOffset(series);
376
380
  if (hasOffset) {
377
381
  if (domainData.length > 1) {
@@ -385,10 +389,15 @@ export function createXScale(args) {
385
389
  }
386
390
  const domainOffsetMin = Math.abs(scale.invert(offsetMin).getTime() - scale.invert(0).getTime());
387
391
  const domainOffsetMax = Math.abs(scale.invert(offsetMax).getTime() - scale.invert(0).getTime());
392
+ // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
393
+ const nicedDomain = scale.copy().nice(Math.max(10, domainData.length)).domain();
388
394
  scale.domain([xMin - domainOffsetMin, xMax + domainOffsetMax]);
389
- if (!hasZoomX && !hasOffset) {
390
- // 10 is the default value for the number of ticks. Here, to preserve the appearance of a series with a small number of points
391
- scale.nice(Math.max(10, domainData.length));
395
+ if (!hasZoomX && !hasOffset && nicedDomain.length === 2) {
396
+ const domainWithOffset = scale.domain();
397
+ scale.domain([
398
+ Math.min(Number(nicedDomain[0]), Number(domainWithOffset[0])),
399
+ Math.max(Number(nicedDomain[1]), Number(domainWithOffset[1])),
400
+ ]);
392
401
  }
393
402
  return scale;
394
403
  }
@@ -76,7 +76,7 @@ export const prepareAreaData = async (args) => {
76
76
  var _a, _b;
77
77
  const { series, xAxis, xScale, yAxis, yScale, boundsHeight: plotHeight, split, isOutsideBounds, } = args;
78
78
  const [_xMin, xRangeMax] = xScale.range();
79
- const xMax = xRangeMax / (1 - xAxis.maxPadding);
79
+ const xMax = xRangeMax;
80
80
  const result = [];
81
81
  const dataByPlots = Array.from(group(series, (s) => {
82
82
  const yAxisIndex = s.yAxis;
@@ -16,7 +16,7 @@ export const prepareLineData = async (args) => {
16
16
  var _a;
17
17
  const { series, xAxis, yAxis, xScale, yScale, split, isOutsideBounds } = args;
18
18
  const [_xMin, xRangeMax] = xScale.range();
19
- const xMax = xRangeMax / (1 - xAxis.maxPadding);
19
+ const xMax = xRangeMax;
20
20
  const acc = [];
21
21
  for (let i = 0; i < series.length; i++) {
22
22
  const s = series[i];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.24.1",
3
+ "version": "1.24.2",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",