@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.
Files changed (57) hide show
  1. package/dist/cjs/components/ChartInner/useChartInnerProps.js +35 -11
  2. package/dist/cjs/components/Tooltip/DefaultContent.js +4 -4
  3. package/dist/cjs/hooks/useAxisScales/index.js +15 -6
  4. package/dist/cjs/hooks/useSeries/index.d.ts +1 -19
  5. package/dist/cjs/hooks/useSeries/index.js +7 -25
  6. package/dist/cjs/hooks/useSeries/prepare-area.js +1 -2
  7. package/dist/cjs/hooks/useShapes/area/prepare-data.js +2 -1
  8. package/dist/cjs/hooks/useShapes/line/prepare-data.js +3 -2
  9. package/dist/cjs/hooks/useShapes/utils.d.ts +6 -0
  10. package/dist/cjs/hooks/useShapes/utils.js +29 -4
  11. package/dist/cjs/hooks/useShapes/waterfall/index.js +1 -1
  12. package/dist/cjs/libs/format-number/index.d.ts +7 -3
  13. package/dist/cjs/libs/format-number/index.js +8 -3
  14. package/dist/cjs/libs/format-number/types.d.ts +0 -1
  15. package/dist/cjs/types/chart/tooltip.d.ts +1 -0
  16. package/dist/cjs/types/formatter.d.ts +0 -1
  17. package/dist/cjs/utils/chart/get-closest-data.d.ts +1 -0
  18. package/dist/cjs/utils/chart/get-closest-data.js +2 -5
  19. package/dist/cjs/utils/chart/index.d.ts +1 -0
  20. package/dist/cjs/utils/chart/index.js +3 -2
  21. package/dist/cjs/utils/chart/series/index.d.ts +1 -0
  22. package/dist/cjs/utils/chart/series/index.js +1 -0
  23. package/dist/cjs/utils/chart/series/sorting.d.ts +2 -0
  24. package/dist/cjs/utils/chart/series/sorting.js +12 -0
  25. package/dist/{esm/hooks/hooks-utils → cjs/utils/chart}/zoom.d.ts +5 -2
  26. package/dist/{esm/hooks/hooks-utils → cjs/utils/chart}/zoom.js +36 -9
  27. package/dist/esm/components/ChartInner/useChartInnerProps.js +35 -11
  28. package/dist/esm/components/Tooltip/DefaultContent.js +4 -4
  29. package/dist/esm/hooks/useAxisScales/index.js +15 -6
  30. package/dist/esm/hooks/useSeries/index.d.ts +1 -19
  31. package/dist/esm/hooks/useSeries/index.js +7 -25
  32. package/dist/esm/hooks/useSeries/prepare-area.js +1 -2
  33. package/dist/esm/hooks/useShapes/area/prepare-data.js +2 -1
  34. package/dist/esm/hooks/useShapes/line/prepare-data.js +3 -2
  35. package/dist/esm/hooks/useShapes/utils.d.ts +6 -0
  36. package/dist/esm/hooks/useShapes/utils.js +29 -4
  37. package/dist/esm/hooks/useShapes/waterfall/index.js +1 -1
  38. package/dist/esm/libs/format-number/index.d.ts +7 -3
  39. package/dist/esm/libs/format-number/index.js +8 -3
  40. package/dist/esm/libs/format-number/types.d.ts +0 -1
  41. package/dist/esm/types/chart/tooltip.d.ts +1 -0
  42. package/dist/esm/types/formatter.d.ts +0 -1
  43. package/dist/esm/utils/chart/get-closest-data.d.ts +1 -0
  44. package/dist/esm/utils/chart/get-closest-data.js +2 -5
  45. package/dist/esm/utils/chart/index.d.ts +1 -0
  46. package/dist/esm/utils/chart/index.js +3 -2
  47. package/dist/esm/utils/chart/series/index.d.ts +1 -0
  48. package/dist/esm/utils/chart/series/index.js +1 -0
  49. package/dist/esm/utils/chart/series/sorting.d.ts +2 -0
  50. package/dist/esm/utils/chart/series/sorting.js +12 -0
  51. package/dist/{cjs/hooks/hooks-utils → esm/utils/chart}/zoom.d.ts +5 -2
  52. package/dist/{cjs/hooks/hooks-utils → esm/utils/chart}/zoom.js +36 -9
  53. package/package.json +1 -1
  54. package/dist/cjs/hooks/hooks-utils/index.d.ts +0 -1
  55. package/dist/cjs/hooks/hooks-utils/index.js +0 -1
  56. package/dist/esm/hooks/hooks-utils/index.d.ts +0 -1
  57. 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
- }): ChartSeries[];
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 < 0) {
45
- return seriesData;
46
+ if (Object.keys(zoomState).length <= 0) {
47
+ return { zoomedSeriesData: seriesData, zoomedShapesSeriesData: seriesData };
46
48
  }
47
- return seriesData.map((seriesItem) => {
48
- const filteredData = seriesItem.data.reduce((acc, point) => {
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
- if (inXRange && inYRange) {
75
- acc.push(point);
87
+ currentPointInRange = inXRange && inYRange;
88
+ if (currentPointInRange) {
89
+ filteredData.push(point);
76
90
  }
77
- return acc;
78
- }, []);
79
- return Object.assign(Object.assign({}, seriesItem), { data: filteredData });
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,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.11.1",
3
+ "version": "1.11.2",
4
4
  "description": "React component used to render charts",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",
@@ -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';