@gravity-ui/charts 1.34.7 → 1.34.9

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 (69) hide show
  1. package/dist/cjs/components/AxisX/AxisX.js +0 -1
  2. package/dist/cjs/components/AxisX/prepare-axis-data.js +4 -23
  3. package/dist/cjs/components/AxisX/types.d.ts +1 -9
  4. package/dist/cjs/components/AxisY/prepare-axis-title.js +3 -34
  5. package/dist/cjs/components/AxisY/types.d.ts +1 -9
  6. package/dist/cjs/components/ChartInner/index.js +6 -6
  7. package/dist/cjs/components/ChartInner/useChartInnerProps.d.ts +0 -1
  8. package/dist/cjs/components/ChartInner/useChartInnerProps.js +16 -6
  9. package/dist/cjs/components/ChartInner/useChartInnerState.d.ts +2 -3
  10. package/dist/cjs/components/ChartInner/useChartInnerState.js +14 -22
  11. package/dist/cjs/components/RangeSlider/index.d.ts +0 -1
  12. package/dist/cjs/components/RangeSlider/index.js +1 -8
  13. package/dist/cjs/components/types/index.d.ts +9 -0
  14. package/dist/cjs/components/types/index.js +1 -0
  15. package/dist/cjs/components/utils/axis-title.d.ts +6 -0
  16. package/dist/cjs/components/utils/axis-title.js +39 -0
  17. package/dist/cjs/components/{utils.d.ts → utils/index.d.ts} +3 -3
  18. package/dist/cjs/components/{utils.js → utils/index.js} +1 -1
  19. package/dist/cjs/hooks/useAxisScales/index.js +3 -1
  20. package/dist/cjs/hooks/useAxisScales/x-scale.d.ts +0 -6
  21. package/dist/cjs/hooks/useAxisScales/x-scale.js +12 -35
  22. package/dist/cjs/hooks/useAxisScales/y-scale.js +2 -7
  23. package/dist/cjs/hooks/useRangeSlider/types.d.ts +1 -1
  24. package/dist/cjs/hooks/useSeries/prepare-legend.js +2 -1
  25. package/dist/cjs/hooks/useShapes/area/index.js +13 -4
  26. package/dist/cjs/hooks/useShapes/area/prepare-data.js +3 -2
  27. package/dist/cjs/hooks/useShapes/bar-x/index.js +13 -4
  28. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +15 -6
  29. package/dist/cjs/hooks/useShapes/line/index.js +13 -4
  30. package/dist/cjs/hooks/useShapes/line/prepare-data.js +4 -2
  31. package/dist/cjs/hooks/useShapes/waterfall/index.js +13 -4
  32. package/dist/cjs/utils/chart/get-closest-data.js +39 -35
  33. package/dist/cjs/utils/chart/zoom.d.ts +2 -1
  34. package/dist/cjs/utils/chart/zoom.js +9 -0
  35. package/dist/esm/components/AxisX/AxisX.js +0 -1
  36. package/dist/esm/components/AxisX/prepare-axis-data.js +4 -23
  37. package/dist/esm/components/AxisX/types.d.ts +1 -9
  38. package/dist/esm/components/AxisY/prepare-axis-title.js +3 -34
  39. package/dist/esm/components/AxisY/types.d.ts +1 -9
  40. package/dist/esm/components/ChartInner/index.js +6 -6
  41. package/dist/esm/components/ChartInner/useChartInnerProps.d.ts +0 -1
  42. package/dist/esm/components/ChartInner/useChartInnerProps.js +16 -6
  43. package/dist/esm/components/ChartInner/useChartInnerState.d.ts +2 -3
  44. package/dist/esm/components/ChartInner/useChartInnerState.js +14 -22
  45. package/dist/esm/components/RangeSlider/index.d.ts +0 -1
  46. package/dist/esm/components/RangeSlider/index.js +1 -8
  47. package/dist/esm/components/types/index.d.ts +9 -0
  48. package/dist/esm/components/types/index.js +1 -0
  49. package/dist/esm/components/utils/axis-title.d.ts +6 -0
  50. package/dist/esm/components/utils/axis-title.js +39 -0
  51. package/dist/esm/components/{utils.d.ts → utils/index.d.ts} +3 -3
  52. package/dist/esm/components/{utils.js → utils/index.js} +1 -1
  53. package/dist/esm/hooks/useAxisScales/index.js +3 -1
  54. package/dist/esm/hooks/useAxisScales/x-scale.d.ts +0 -6
  55. package/dist/esm/hooks/useAxisScales/x-scale.js +12 -35
  56. package/dist/esm/hooks/useAxisScales/y-scale.js +2 -7
  57. package/dist/esm/hooks/useRangeSlider/types.d.ts +1 -1
  58. package/dist/esm/hooks/useSeries/prepare-legend.js +2 -1
  59. package/dist/esm/hooks/useShapes/area/index.js +13 -4
  60. package/dist/esm/hooks/useShapes/area/prepare-data.js +3 -2
  61. package/dist/esm/hooks/useShapes/bar-x/index.js +13 -4
  62. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +15 -6
  63. package/dist/esm/hooks/useShapes/line/index.js +13 -4
  64. package/dist/esm/hooks/useShapes/line/prepare-data.js +4 -2
  65. package/dist/esm/hooks/useShapes/waterfall/index.js +13 -4
  66. package/dist/esm/utils/chart/get-closest-data.js +39 -35
  67. package/dist/esm/utils/chart/zoom.d.ts +2 -1
  68. package/dist/esm/utils/chart/zoom.js +9 -0
  69. package/package.json +1 -1
@@ -47,19 +47,53 @@ export function getClosestPoints(args) {
47
47
  const [pointerX, pointerY] = position;
48
48
  const result = [];
49
49
  const groups = groupBy(shapesData, getSeriesType);
50
+ const closestPointsByXValue = [];
50
51
  // eslint-disable-next-line complexity
51
52
  Object.entries(groups).forEach(([seriesType, list]) => {
52
53
  var _a, _b, _c, _d, _e;
53
54
  switch (seriesType) {
55
+ case 'line': {
56
+ const linePoints = list.reduce((acc, d) => {
57
+ acc.push(...d.points.reduce((accPoints, p) => {
58
+ if (p.y !== null && p.x !== null) {
59
+ accPoints.push({
60
+ data: p.data,
61
+ series: p.series,
62
+ x: p.x,
63
+ y0: p.y,
64
+ y1: p.y,
65
+ });
66
+ }
67
+ return accPoints;
68
+ }, []));
69
+ return acc;
70
+ }, []);
71
+ closestPointsByXValue.push(...linePoints);
72
+ break;
73
+ }
74
+ case 'area': {
75
+ const areaPoints = list.reduce((acc, d) => {
76
+ Array.prototype.push.apply(acc, d.points.map((p) => ({
77
+ data: p.data,
78
+ series: p.series,
79
+ x: p.x,
80
+ y0: p.y0,
81
+ y1: p.y,
82
+ })));
83
+ return acc;
84
+ }, []);
85
+ closestPointsByXValue.push(...areaPoints);
86
+ break;
87
+ }
54
88
  case 'bar-x': {
55
- const points = list.map((d) => ({
89
+ const barXPoints = list.map((d) => ({
56
90
  data: d.data,
57
91
  series: d.series,
58
92
  x: d.x + d.width / 2,
59
93
  y0: d.y,
60
94
  y1: d.y + d.height,
61
95
  }));
62
- result.push(...getClosestPointsByXValue(pointerX, pointerY, points));
96
+ closestPointsByXValue.push(...barXPoints);
63
97
  break;
64
98
  }
65
99
  case 'waterfall': {
@@ -74,39 +108,6 @@ export function getClosestPoints(args) {
74
108
  result.push(...getClosestPointsByXValue(pointerX, pointerY, points));
75
109
  break;
76
110
  }
77
- case 'area': {
78
- const points = list.reduce((acc, d) => {
79
- Array.prototype.push.apply(acc, d.points.map((p) => ({
80
- data: p.data,
81
- series: p.series,
82
- x: p.x,
83
- y0: p.y0,
84
- y1: p.y,
85
- })));
86
- return acc;
87
- }, []);
88
- result.push(...getClosestPointsByXValue(pointerX, pointerY, points));
89
- break;
90
- }
91
- case 'line': {
92
- const points = list.reduce((acc, d) => {
93
- acc.push(...d.points.reduce((accPoints, p) => {
94
- if (p.y !== null && p.x !== null) {
95
- accPoints.push({
96
- data: p.data,
97
- series: p.series,
98
- x: p.x,
99
- y0: p.y,
100
- y1: p.y,
101
- });
102
- }
103
- return accPoints;
104
- }, []));
105
- return acc;
106
- }, []);
107
- result.push(...getClosestPointsByXValue(pointerX, pointerY, points));
108
- break;
109
- }
110
111
  case 'bar-y': {
111
112
  const points = list;
112
113
  const sorted = sort(points, (p) => p.y);
@@ -267,6 +268,9 @@ export function getClosestPoints(args) {
267
268
  }
268
269
  }
269
270
  });
271
+ if (closestPointsByXValue.length) {
272
+ result.push(...getClosestPointsByXValue(pointerX, pointerY, closestPointsByXValue));
273
+ }
270
274
  return result;
271
275
  }
272
276
  function isInsidePath(args) {
@@ -1,4 +1,4 @@
1
- import type { PreparedSeries, PreparedXAxis, PreparedYAxis } from '../../hooks';
1
+ import type { PreparedSeries, PreparedXAxis, PreparedYAxis, RangeSliderState } from '../../hooks';
2
2
  import type { ZoomState } from '../../hooks/useZoom/types';
3
3
  import type { ChartXAxis, ChartYAxis } from '../../types';
4
4
  export declare function getZoomedSeriesData(args: {
@@ -10,3 +10,4 @@ export declare function getZoomedSeriesData(args: {
10
10
  preparedSeries: PreparedSeries[];
11
11
  preparedShapesSeries: PreparedSeries[];
12
12
  };
13
+ export declare function getEffectiveXRange(zoomStateX: [number, number] | undefined, rangeSliderState: RangeSliderState | undefined): [number, number] | undefined;
@@ -123,3 +123,12 @@ export function getZoomedSeriesData(args) {
123
123
  preparedShapesSeries: zoomedShapesSeriesData,
124
124
  };
125
125
  }
126
+ export function getEffectiveXRange(zoomStateX, rangeSliderState) {
127
+ if (zoomStateX && rangeSliderState) {
128
+ return [
129
+ Math.max(zoomStateX[0], rangeSliderState.min),
130
+ Math.min(zoomStateX[1], rangeSliderState.max),
131
+ ];
132
+ }
133
+ return (zoomStateX !== null && zoomStateX !== void 0 ? zoomStateX : (rangeSliderState ? [rangeSliderState.min, rangeSliderState.max] : undefined));
134
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/charts",
3
- "version": "1.34.7",
3
+ "version": "1.34.9",
4
4
  "description": "A flexible JavaScript library for data visualization and chart rendering using React",
5
5
  "license": "MIT",
6
6
  "main": "dist/cjs/index.js",