@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.
- package/dist/cjs/hooks/useAxisScales/index.js +21 -12
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +1 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +1 -1
- package/dist/esm/hooks/useAxisScales/index.js +21 -12
- package/dist/esm/hooks/useShapes/area/prepare-data.js +1 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.js +1 -1
- package/package.json +1 -1
|
@@ -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,
|
|
220
|
+
function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, }) {
|
|
221
221
|
const xAxisZoomPadding = boundsWidth * X_AXIS_ZOOM_PADDING;
|
|
222
|
-
const xRange = [0, boundsWidth
|
|
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
|
|
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 =
|
|
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
|
-
|
|
330
|
-
scale.
|
|
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 =
|
|
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
|
-
|
|
391
|
-
scale.
|
|
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
|
|
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
|
|
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,
|
|
220
|
+
function getXScaleRange({ boundsWidth, series, seriesOptions, hasZoomX, axis, }) {
|
|
221
221
|
const xAxisZoomPadding = boundsWidth * X_AXIS_ZOOM_PADDING;
|
|
222
|
-
const xRange = [0, boundsWidth
|
|
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
|
|
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 =
|
|
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
|
-
|
|
330
|
-
scale.
|
|
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 =
|
|
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
|
-
|
|
391
|
-
scale.
|
|
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
|
|
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
|
|
19
|
+
const xMax = xRangeMax;
|
|
20
20
|
const acc = [];
|
|
21
21
|
for (let i = 0; i < series.length; i++) {
|
|
22
22
|
const s = series[i];
|