@gravity-ui/charts 1.11.1 → 1.11.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/components/ChartInner/useChartInnerProps.js +35 -11
- package/dist/cjs/components/Tooltip/DefaultContent.js +4 -4
- package/dist/cjs/hooks/useAxisScales/index.js +15 -6
- package/dist/cjs/hooks/useSeries/index.d.ts +1 -19
- package/dist/cjs/hooks/useSeries/index.js +7 -25
- package/dist/cjs/hooks/useSeries/prepare-area.js +1 -2
- package/dist/cjs/hooks/useShapes/area/prepare-data.js +2 -1
- package/dist/cjs/hooks/useShapes/line/prepare-data.js +3 -2
- package/dist/cjs/hooks/useShapes/utils.d.ts +6 -0
- package/dist/cjs/hooks/useShapes/utils.js +29 -4
- package/dist/cjs/hooks/useShapes/waterfall/index.js +1 -1
- package/dist/cjs/libs/format-number/index.d.ts +7 -3
- package/dist/cjs/libs/format-number/index.js +8 -3
- package/dist/cjs/libs/format-number/types.d.ts +0 -1
- package/dist/cjs/types/chart/tooltip.d.ts +1 -0
- package/dist/cjs/types/formatter.d.ts +0 -1
- package/dist/cjs/utils/chart/get-closest-data.d.ts +1 -0
- package/dist/cjs/utils/chart/get-closest-data.js +2 -5
- package/dist/cjs/utils/chart/index.d.ts +1 -0
- package/dist/cjs/utils/chart/index.js +3 -2
- package/dist/cjs/utils/chart/series/index.d.ts +1 -0
- package/dist/cjs/utils/chart/series/index.js +1 -0
- package/dist/cjs/utils/chart/series/sorting.d.ts +2 -0
- package/dist/cjs/utils/chart/series/sorting.js +12 -0
- package/dist/{esm/hooks/hooks-utils → cjs/utils/chart}/zoom.d.ts +5 -2
- package/dist/{esm/hooks/hooks-utils → cjs/utils/chart}/zoom.js +36 -9
- package/dist/esm/components/ChartInner/useChartInnerProps.js +35 -11
- package/dist/esm/components/Tooltip/DefaultContent.js +4 -4
- package/dist/esm/hooks/useAxisScales/index.js +15 -6
- package/dist/esm/hooks/useSeries/index.d.ts +1 -19
- package/dist/esm/hooks/useSeries/index.js +7 -25
- package/dist/esm/hooks/useSeries/prepare-area.js +1 -2
- package/dist/esm/hooks/useShapes/area/prepare-data.js +2 -1
- package/dist/esm/hooks/useShapes/line/prepare-data.js +3 -2
- package/dist/esm/hooks/useShapes/utils.d.ts +6 -0
- package/dist/esm/hooks/useShapes/utils.js +29 -4
- package/dist/esm/hooks/useShapes/waterfall/index.js +1 -1
- package/dist/esm/libs/format-number/index.d.ts +7 -3
- package/dist/esm/libs/format-number/index.js +8 -3
- package/dist/esm/libs/format-number/types.d.ts +0 -1
- package/dist/esm/types/chart/tooltip.d.ts +1 -0
- package/dist/esm/types/formatter.d.ts +0 -1
- package/dist/esm/utils/chart/get-closest-data.d.ts +1 -0
- package/dist/esm/utils/chart/get-closest-data.js +2 -5
- package/dist/esm/utils/chart/index.d.ts +1 -0
- package/dist/esm/utils/chart/index.js +3 -2
- package/dist/esm/utils/chart/series/index.d.ts +1 -0
- package/dist/esm/utils/chart/series/index.js +1 -0
- package/dist/esm/utils/chart/series/sorting.d.ts +2 -0
- package/dist/esm/utils/chart/series/sorting.js +12 -0
- package/dist/{cjs/hooks/hooks-utils → esm/utils/chart}/zoom.d.ts +5 -2
- package/dist/{cjs/hooks/hooks-utils → esm/utils/chart}/zoom.js +36 -9
- package/package.json +1 -1
- package/dist/cjs/hooks/hooks-utils/index.d.ts +0 -1
- package/dist/cjs/hooks/hooks-utils/index.js +0 -1
- package/dist/esm/hooks/hooks-utils/index.d.ts +0 -1
- package/dist/esm/hooks/hooks-utils/index.js +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { sort } from 'd3';
|
|
2
|
+
import { SeriesType } from '../../../constants';
|
|
3
|
+
export function getSortedSeriesData(seriesData) {
|
|
4
|
+
return seriesData.map((s) => {
|
|
5
|
+
switch (s.type) {
|
|
6
|
+
case SeriesType.Area: {
|
|
7
|
+
s.data = sort(s.data, (d) => d.x);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return s;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { ZoomState } from '../../hooks/useZoom/types';
|
|
1
2
|
import type { ChartSeries, ChartXAxis, ChartYAxis } from '../../types';
|
|
2
|
-
import type { ZoomState } from '../useZoom/types';
|
|
3
3
|
export declare function getZoomedSeriesData(args: {
|
|
4
4
|
seriesData: ChartSeries[];
|
|
5
5
|
zoomState: Partial<ZoomState>;
|
|
6
6
|
xAxis?: ChartXAxis;
|
|
7
7
|
yAxes?: ChartYAxis[];
|
|
8
|
-
}):
|
|
8
|
+
}): {
|
|
9
|
+
zoomedSeriesData: ChartSeries[];
|
|
10
|
+
zoomedShapesSeriesData: ChartSeries[];
|
|
11
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SeriesType } from '../../constants';
|
|
2
|
+
const SERIES_TYPE_WITH_HIDDEN_POINTS = [SeriesType.Area, SeriesType.Line];
|
|
1
3
|
// eslint-disable-next-line complexity
|
|
2
4
|
function isValueInRange(args) {
|
|
3
5
|
const { axis, max, min, value } = args;
|
|
@@ -41,13 +43,24 @@ function isValueInRange(args) {
|
|
|
41
43
|
}
|
|
42
44
|
export function getZoomedSeriesData(args) {
|
|
43
45
|
const { seriesData, xAxis, yAxes, zoomState } = args;
|
|
44
|
-
if (Object.keys(zoomState).length
|
|
45
|
-
return seriesData;
|
|
46
|
+
if (Object.keys(zoomState).length <= 0) {
|
|
47
|
+
return { zoomedSeriesData: seriesData, zoomedShapesSeriesData: seriesData };
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const zoomedSeriesData = [];
|
|
50
|
+
const zoomedShapesSeriesData = [];
|
|
51
|
+
let prevPointInRange = false;
|
|
52
|
+
let currentPointInRange = false;
|
|
53
|
+
seriesData.forEach((seriesItem) => {
|
|
54
|
+
const filteredData = [];
|
|
55
|
+
const filteredShapesData = SERIES_TYPE_WITH_HIDDEN_POINTS.includes(seriesItem.type) && (xAxis === null || xAxis === void 0 ? void 0 : xAxis.type) !== 'category'
|
|
56
|
+
? []
|
|
57
|
+
: undefined;
|
|
58
|
+
seriesItem.data.forEach((point, i) => {
|
|
59
|
+
const prevPoint = seriesItem.data[i - 1];
|
|
60
|
+
const isFirstPoint = i === 0;
|
|
49
61
|
let inXRange = true;
|
|
50
62
|
let inYRange = true;
|
|
63
|
+
prevPointInRange = currentPointInRange;
|
|
51
64
|
if (zoomState.x) {
|
|
52
65
|
const [xMin, xMax] = zoomState.x;
|
|
53
66
|
const x = 'x' in point ? point.x : undefined;
|
|
@@ -71,11 +84,25 @@ export function getZoomedSeriesData(args) {
|
|
|
71
84
|
max: yMax,
|
|
72
85
|
});
|
|
73
86
|
}
|
|
74
|
-
|
|
75
|
-
|
|
87
|
+
currentPointInRange = inXRange && inYRange;
|
|
88
|
+
if (currentPointInRange) {
|
|
89
|
+
filteredData.push(point);
|
|
76
90
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
91
|
+
if (filteredShapesData) {
|
|
92
|
+
if (prevPointInRange && !currentPointInRange) {
|
|
93
|
+
filteredShapesData.push(point);
|
|
94
|
+
}
|
|
95
|
+
else if (!isFirstPoint && !prevPointInRange && currentPointInRange) {
|
|
96
|
+
filteredShapesData.push(prevPoint, point);
|
|
97
|
+
}
|
|
98
|
+
else if ((isFirstPoint || (!isFirstPoint && prevPointInRange)) &&
|
|
99
|
+
currentPointInRange) {
|
|
100
|
+
filteredShapesData.push(point);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
zoomedSeriesData.push(Object.assign(Object.assign({}, seriesItem), { data: filteredData }));
|
|
105
|
+
zoomedShapesSeriesData.push(Object.assign(Object.assign({}, seriesItem), { data: filteredShapesData || filteredData }));
|
|
80
106
|
});
|
|
107
|
+
return { zoomedSeriesData, zoomedShapesSeriesData };
|
|
81
108
|
}
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './zoom';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './zoom';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './zoom';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './zoom';
|