@gravity-ui/charts 1.38.4 → 1.38.6

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/ChartInner/index.js +7 -3
  2. package/dist/cjs/components/ChartInner/useLegend.js +4 -7
  3. package/dist/cjs/components/ChartInner/utils.d.ts +1 -1
  4. package/dist/cjs/components/ChartInner/utils.js +7 -5
  5. package/dist/cjs/hooks/useAxis/index.js +1 -2
  6. package/dist/cjs/hooks/useSeries/index.js +13 -3
  7. package/dist/cjs/hooks/useShapes/bar-x/prepare-data.js +0 -1
  8. package/dist/cjs/hooks/useShapes/pie/prepare-data.js +0 -1
  9. package/dist/cjs/hooks/useShapes/pie/utils.d.ts +0 -1
  10. package/dist/cjs/hooks/useShapes/pie/utils.js +0 -1
  11. package/dist/cjs/hooks/useShapes/sankey/prepare-data.js +1 -1
  12. package/dist/cjs/types/chart/area.d.ts +10 -12
  13. package/dist/cjs/types/chart/axis.d.ts +55 -37
  14. package/dist/cjs/types/chart/bar-x.d.ts +7 -10
  15. package/dist/cjs/types/chart/bar-y.d.ts +7 -10
  16. package/dist/cjs/types/chart/base.d.ts +6 -7
  17. package/dist/cjs/types/chart/heatmap.d.ts +0 -2
  18. package/dist/cjs/types/chart/legend.d.ts +14 -26
  19. package/dist/cjs/types/chart/line.d.ts +4 -4
  20. package/dist/cjs/types/chart/pie.d.ts +6 -12
  21. package/dist/cjs/types/chart/scatter.d.ts +0 -2
  22. package/dist/cjs/types/chart/series.d.ts +49 -56
  23. package/dist/cjs/types/chart/title.d.ts +4 -2
  24. package/dist/cjs/types/chart/tooltip.d.ts +8 -4
  25. package/dist/cjs/types/chart/treemap.d.ts +7 -5
  26. package/dist/cjs/types/chart/waterfall.d.ts +0 -1
  27. package/dist/cjs/types/chart/zoom.d.ts +0 -3
  28. package/dist/cjs/types/index.d.ts +3 -3
  29. package/dist/cjs/utils/chart/get-closest-data.d.ts +1 -0
  30. package/dist/cjs/utils/chart/get-closest-data.js +29 -7
  31. package/dist/cjs/utils/chart/math.d.ts +2 -3
  32. package/dist/cjs/utils/chart/math.js +2 -3
  33. package/dist/cjs/utils/chart/series-type-guards.d.ts +0 -1
  34. package/dist/cjs/utils/chart/series-type-guards.js +0 -1
  35. package/dist/esm/components/ChartInner/index.js +7 -3
  36. package/dist/esm/components/ChartInner/useLegend.js +4 -7
  37. package/dist/esm/components/ChartInner/utils.d.ts +1 -1
  38. package/dist/esm/components/ChartInner/utils.js +7 -5
  39. package/dist/esm/hooks/useAxis/index.js +1 -2
  40. package/dist/esm/hooks/useSeries/index.js +13 -3
  41. package/dist/esm/hooks/useShapes/bar-x/prepare-data.js +0 -1
  42. package/dist/esm/hooks/useShapes/pie/prepare-data.js +0 -1
  43. package/dist/esm/hooks/useShapes/pie/utils.d.ts +0 -1
  44. package/dist/esm/hooks/useShapes/pie/utils.js +0 -1
  45. package/dist/esm/hooks/useShapes/sankey/prepare-data.js +1 -1
  46. package/dist/esm/types/chart/area.d.ts +10 -12
  47. package/dist/esm/types/chart/axis.d.ts +55 -37
  48. package/dist/esm/types/chart/bar-x.d.ts +7 -10
  49. package/dist/esm/types/chart/bar-y.d.ts +7 -10
  50. package/dist/esm/types/chart/base.d.ts +6 -7
  51. package/dist/esm/types/chart/heatmap.d.ts +0 -2
  52. package/dist/esm/types/chart/legend.d.ts +14 -26
  53. package/dist/esm/types/chart/line.d.ts +4 -4
  54. package/dist/esm/types/chart/pie.d.ts +6 -12
  55. package/dist/esm/types/chart/scatter.d.ts +0 -2
  56. package/dist/esm/types/chart/series.d.ts +49 -56
  57. package/dist/esm/types/chart/title.d.ts +4 -2
  58. package/dist/esm/types/chart/tooltip.d.ts +8 -4
  59. package/dist/esm/types/chart/treemap.d.ts +7 -5
  60. package/dist/esm/types/chart/waterfall.d.ts +0 -1
  61. package/dist/esm/types/chart/zoom.d.ts +0 -3
  62. package/dist/esm/types/index.d.ts +3 -3
  63. package/dist/esm/utils/chart/get-closest-data.d.ts +1 -0
  64. package/dist/esm/utils/chart/get-closest-data.js +29 -7
  65. package/dist/esm/utils/chart/math.d.ts +2 -3
  66. package/dist/esm/utils/chart/math.js +2 -3
  67. package/dist/esm/utils/chart/series-type-guards.d.ts +0 -1
  68. package/dist/esm/utils/chart/series-type-guards.js +0 -1
  69. package/package.json +17 -15
@@ -3,9 +3,8 @@ export interface ChartLegendItem {
3
3
  enabled?: boolean;
4
4
  /**
5
5
  * Defines the pixel distance between each legend item
6
- *
7
6
  * @default 20
8
- * */
7
+ */
9
8
  itemDistance?: number;
10
9
  /** CSS styles for each legend item */
11
10
  itemStyle?: BaseTextStyle;
@@ -15,32 +14,27 @@ export interface ChartLegend extends ChartLegendItem {
15
14
  * Different types for different color schemes.
16
15
  * If the color scheme is continuous, a gradient legend will be drawn.
17
16
  * Otherwise, samples for different point values
18
- *
19
17
  * @default 'discrete'
20
18
  */
21
19
  type?: 'discrete' | 'continuous';
22
20
  /**
23
21
  * The horizontal alignment of the legend box within the chart area.
24
- *
25
22
  * @default center
26
- * */
23
+ */
27
24
  align?: 'left' | 'center' | 'right';
28
25
  /**
29
26
  * The vertical alignment of the legend box within the chart area.
30
27
  * Only applies when position is 'left' or 'right'.
31
- *
32
28
  * @default top
33
- * */
29
+ */
34
30
  verticalAlign?: 'top' | 'center' | 'bottom';
35
31
  /**
36
32
  * Defines how items should be positioned in the legend when overflowing (moving to the next line).
37
- *
38
33
  * @default center
39
- * */
34
+ */
40
35
  justifyContent?: 'start' | 'center';
41
36
  /**
42
37
  * The space between the legend and the axis labels or chart area.
43
- *
44
38
  * @default 15
45
39
  */
46
40
  margin?: number;
@@ -48,10 +42,11 @@ export interface ChartLegend extends ChartLegendItem {
48
42
  text?: string;
49
43
  /** CSS styles for the title */
50
44
  style?: Partial<BaseTextStyle>;
51
- /** The distance(in pixels) between the main content of the legend and its title
45
+ /**
46
+ * The distance(in pixels) between the main content of the legend and its title
52
47
  *
53
48
  * Defaults to 4 for horizontal axes, 8 for vertical.
54
- * */
49
+ */
55
50
  margin?: number;
56
51
  /** The horizontal alignment of the title. */
57
52
  align?: 'left' | 'center' | 'right';
@@ -64,37 +59,32 @@ export interface ChartLegend extends ChartLegendItem {
64
59
  width?: number;
65
60
  /**
66
61
  * Allows to use any html-tags to display the content.
67
- *
68
62
  * @default false
69
- * */
63
+ */
70
64
  html?: boolean;
71
65
  /**
72
66
  * The position of the legend box within the chart area.
73
- *
74
67
  * @default 'bottom'
75
- * */
68
+ */
76
69
  position?: 'top' | 'bottom' | 'left' | 'right';
77
70
  }
78
71
  export interface BaseLegendSymbol {
79
72
  /**
80
73
  * The pixel padding between the legend item symbol and the legend item text.
81
- *
82
74
  * @default 5
83
- * */
75
+ */
84
76
  padding?: number;
85
77
  }
86
78
  export interface RectLegendSymbolOptions extends BaseLegendSymbol {
87
79
  /**
88
80
  * The pixel width of the symbol for series types that use a rectangle in the legend
89
- *
90
81
  * @default 10
91
- * */
82
+ */
92
83
  width?: number;
93
84
  /**
94
85
  * The pixel width of the symbol for series types that use a rectangle in the legend
95
- *
96
86
  * @default 10
97
- * */
87
+ */
98
88
  height?: number;
99
89
  /**
100
90
  * The border radius of the symbol for series types that use a rectangle in the legend.
@@ -106,16 +96,14 @@ export interface RectLegendSymbolOptions extends BaseLegendSymbol {
106
96
  export interface PathLegendSymbolOptions extends BaseLegendSymbol {
107
97
  /**
108
98
  * The pixel width of the symbol for series types that use a path in the legend
109
- *
110
99
  * @default 16
111
- * */
100
+ */
112
101
  width?: number;
113
102
  }
114
103
  export interface SymbolLegendSymbolOptions extends BaseLegendSymbol {
115
104
  /**
116
105
  * The pixel width of the symbol for series types that use a symbol in the legend
117
- *
118
106
  * @default 8
119
- * */
107
+ */
120
108
  width?: number;
121
109
  }
@@ -30,13 +30,14 @@ export interface LineSeriesData<T = MeaningfulAny> extends BaseSeriesData<T> {
30
30
  };
31
31
  }
32
32
  export interface LineSeriesLineBaseStyle {
33
- /** Pixel width of the graph line.
34
- *
33
+ /**
34
+ * Pixel width of the graph line.
35
35
  * @default 1 (for individual series).
36
36
  * For series within the range slider, values are inherited from the individual series by default.
37
37
  */
38
38
  lineWidth?: number;
39
- /** Individual opacity for the line.
39
+ /**
40
+ * Individual opacity for the line.
40
41
  *
41
42
  * For series within the range slider, values are inherited from the individual series by default.
42
43
  */
@@ -69,7 +70,6 @@ export interface LineSeries<T = MeaningfulAny> extends BaseSeries, LineSeriesLin
69
70
  * - `'connect'`: Connect points across null values (skip nulls in rendering)
70
71
  * - `'zero'`: Treat null values as zero
71
72
  * - `'skip'`: Omit the data point (creates gap in line)
72
- *
73
73
  * @default 'skip'
74
74
  */
75
75
  nullMode?: 'connect' | 'zero' | 'skip';
@@ -61,28 +61,24 @@ export interface PieSeries<T = MeaningfulAny> extends BaseSeries {
61
61
  dataLabels?: BaseSeries['dataLabels'] & {
62
62
  /**
63
63
  * The distance of the data label from the pie's edge.
64
- *
65
64
  * @default 30
66
- * */
65
+ */
67
66
  distance?: number;
68
67
  /**
69
68
  * The distance from the data label to the connector.
70
- *
71
69
  * @default 5
72
- * */
70
+ */
73
71
  connectorPadding?: number;
74
72
  /**
75
73
  * The method that is used to generate the connector path.
76
- *
77
74
  * @default 'polyline'
78
- * */
75
+ */
79
76
  connectorShape?: ConnectorShape;
80
77
  /**
81
78
  * How to interpolate between two-dimensional [x, y] points for a connector.
82
79
  * Works only if connectorShape equals to 'polyline'
83
- *
84
80
  * @default 'basic'
85
- * */
81
+ */
86
82
  connectorCurve?: ConnectorCurve;
87
83
  };
88
84
  /** Individual series legend options. Has higher priority than legend options in chart data */
@@ -91,9 +87,8 @@ export interface PieSeries<T = MeaningfulAny> extends BaseSeries {
91
87
  };
92
88
  /**
93
89
  * Function for adding custom svg nodes for a series
94
- *
95
- * @return BaseType
96
- * */
90
+ * @returns BaseType
91
+ */
97
92
  renderCustomShape?: (args: {
98
93
  series: {
99
94
  innerRadius: number;
@@ -104,7 +99,6 @@ export interface PieSeries<T = MeaningfulAny> extends BaseSeries {
104
99
  *
105
100
  * - `'zero'`: Treat null values as zero
106
101
  * - `'skip'`: Omit segments with null values (don't render them)
107
- *
108
102
  * @default 'skip'
109
103
  */
110
104
  nullMode?: 'zero' | 'skip';
@@ -20,7 +20,6 @@ export interface ScatterSeriesData<T = MeaningfulAny> extends BaseSeriesData<T>
20
20
  y?: string | number | null;
21
21
  /**
22
22
  * Corresponding value of axis category.
23
- *
24
23
  * @deprecated use `x` or `y` instead
25
24
  */
26
25
  category?: string;
@@ -49,7 +48,6 @@ export interface ScatterSeries<T = MeaningfulAny> extends BaseSeries {
49
48
  *
50
49
  * - `'zero'`: Treat null values as zero
51
50
  * - `'skip'`: Omit data points with null values (don't render them)
52
- *
53
51
  * @default 'skip'
54
52
  */
55
53
  nullMode?: 'zero' | 'skip';
@@ -23,16 +23,14 @@ export interface DataLabelRendererData<T = MeaningfulAny> {
23
23
  export interface BasicHoverState {
24
24
  /**
25
25
  * Enable separate styles for the hovered series.
26
- *
27
26
  * @default true
28
- * */
27
+ */
29
28
  enabled?: boolean;
30
29
  /**
31
30
  * How much to brighten/darken the point on hover. Use positive to brighten, negative to darken.
32
31
  * The behavior of this property is dependent on the implementing color space ([more details](https://d3js.org/d3-color#color_brighter)).
33
32
  * For example in case of using rgb color you can use floating point number from `-5.0` to `5.0`.
34
33
  * Rgb color space is used by default.
35
- *
36
34
  * @default 0.3
37
35
  */
38
36
  brightness?: number;
@@ -40,15 +38,13 @@ export interface BasicHoverState {
40
38
  export interface BasicInactiveState {
41
39
  /**
42
40
  * Enable separate styles for the inactive series.
43
- *
44
41
  * @default true
45
- * */
42
+ */
46
43
  enabled?: boolean;
47
44
  /**
48
45
  * Opacity of series elements (bars, data labels)
49
- *
50
46
  * @default 0.5
51
- * */
47
+ */
52
48
  opacity?: number;
53
49
  }
54
50
  export interface ChartSeriesOptions {
@@ -60,19 +56,19 @@ export interface ChartSeriesOptions {
60
56
  renderer?: (args: DataLabelRendererData) => React.SVGTextElementAttributes<SVGTextElement>;
61
57
  };
62
58
  'bar-x'?: {
63
- /** The maximum allowed pixel width for a column.
59
+ /**
60
+ * The maximum allowed pixel width for a column.
64
61
  * This prevents the columns from becoming too wide when there is a small number of points in the chart.
65
- *
66
62
  * @default 50
67
63
  */
68
64
  barMaxWidth?: number;
69
- /** Padding between each column or bar, in x axis units.
70
- *
65
+ /**
66
+ * Padding between each column or bar, in x axis units.
71
67
  * @default 0.1
72
- * */
68
+ */
73
69
  barPadding?: number;
74
- /** Padding between each value groups, in x axis units
75
- *
70
+ /**
71
+ * Padding between each value groups, in x axis units
76
72
  * @default 0.2
77
73
  */
78
74
  groupPadding?: number;
@@ -87,16 +83,16 @@ export interface ChartSeriesOptions {
87
83
  */
88
84
  stackGap?: number;
89
85
  dataSorting?: {
90
- /** Determines what data value should be used to sort by.
86
+ /**
87
+ * Determines what data value should be used to sort by.
91
88
  * Possible values are undefined to disable, "name" to sort by series name or "y"
92
- *
93
89
  * @default undefined
94
- * */
90
+ */
95
91
  key?: 'name' | 'y' | undefined;
96
- /** Sorting direction.
97
- *
92
+ /**
93
+ * Sorting direction.
98
94
  * @default 'asc'
99
- * */
95
+ */
100
96
  direction?: 'asc' | 'desc';
101
97
  };
102
98
  /** Options for the series states that provide additional styling information to the series. */
@@ -106,25 +102,24 @@ export interface ChartSeriesOptions {
106
102
  };
107
103
  };
108
104
  'bar-y'?: {
109
- /** The maximum allowed pixel width for a column.
105
+ /**
106
+ * The maximum allowed pixel width for a column.
110
107
  * This prevents the columns from becoming too wide when there is a small number of points in the chart.
111
- *
112
108
  * @default 50
113
109
  */
114
110
  barMaxWidth?: number;
115
- /** Padding between each column or bar, in x axis units.
116
- *
111
+ /**
112
+ * Padding between each column or bar, in x axis units.
117
113
  * @default 0.1
118
- * */
114
+ */
119
115
  barPadding?: number;
120
- /** Padding between each value groups, in x axis units
121
- *
116
+ /**
117
+ * Padding between each value groups, in x axis units
122
118
  * @default 0.2
123
119
  */
124
120
  groupPadding?: number;
125
121
  /**
126
122
  * The width of the border surrounding each bar.
127
- *
128
123
  * @default 0
129
124
  */
130
125
  borderWidth?: number;
@@ -143,16 +138,16 @@ export interface ChartSeriesOptions {
143
138
  */
144
139
  stackGap?: number;
145
140
  dataSorting?: {
146
- /** Determines what data value should be used to sort by.
141
+ /**
142
+ * Determines what data value should be used to sort by.
147
143
  * Possible values are undefined to disable, "name" to sort by series name or "x"
148
- *
149
144
  * @default undefined
150
- * */
145
+ */
151
146
  key?: 'name' | 'x' | undefined;
152
- /** Sorting direction.
153
- *
147
+ /**
148
+ * Sorting direction.
154
149
  * @default 'asc'
155
- * */
150
+ */
156
151
  direction?: 'asc' | 'desc';
157
152
  };
158
153
  /** Options for the series states that provide additional styling information to the series. */
@@ -184,10 +179,10 @@ export interface ChartSeriesOptions {
184
179
  };
185
180
  };
186
181
  line?: {
187
- /** Pixel width of the graph line.
188
- *
182
+ /**
183
+ * Pixel width of the graph line.
189
184
  * @default 1
190
- * */
185
+ */
191
186
  lineWidth?: number;
192
187
  /** Options for the series states that provide additional styling information to the series. */
193
188
  states?: {
@@ -201,27 +196,27 @@ export interface ChartSeriesOptions {
201
196
  };
202
197
  /** Options for the point markers of line series */
203
198
  marker?: PointMarkerOptions;
204
- /** Options for line style
205
- *
199
+ /**
200
+ * Options for line style
206
201
  * @default 'Solid'
207
- * */
202
+ */
208
203
  dashStyle?: DashStyle;
209
- /** Options for line cap style
210
- *
204
+ /**
205
+ * Options for line cap style
211
206
  * @default 'round' when dashStyle is not 'solid', 'none' when dashStyle is not 'solid'
212
- * */
207
+ */
213
208
  linecap?: `${LineCap}`;
214
- /** Defines the shape to be used at the corners of the line
215
- *
209
+ /**
210
+ * Defines the shape to be used at the corners of the line
216
211
  * @default 'round' when dashStyle is not 'solid', 'unset' when dashStyle is not 'solid'
217
- * */
212
+ */
218
213
  linejoin?: `${LineJoin}`;
219
214
  };
220
215
  area?: {
221
- /** Pixel width of the graph line.
222
- *
216
+ /**
217
+ * Pixel width of the graph line.
223
218
  * @default 1
224
- * */
219
+ */
225
220
  lineWidth?: number;
226
221
  /** Options for the series states that provide additional styling information to the series. */
227
222
  states?: {
@@ -244,16 +239,16 @@ export interface ChartSeriesOptions {
244
239
  };
245
240
  };
246
241
  waterfall?: {
247
- /** The maximum allowed pixel width for a column.
242
+ /**
243
+ * The maximum allowed pixel width for a column.
248
244
  * This prevents the columns from becoming too wide when there is a small number of points in the chart.
249
- *
250
245
  * @default 50
251
246
  */
252
247
  barMaxWidth?: number;
253
- /** Padding between each column or bar, in x axis units.
254
- *
248
+ /**
249
+ * Padding between each column or bar, in x axis units.
255
250
  * @default 0.1
256
- * */
251
+ */
257
252
  barPadding?: number;
258
253
  /** Options for the series states that provide additional styling information to the series. */
259
254
  states?: {
@@ -282,7 +277,6 @@ export interface ChartSeriesOptions {
282
277
  };
283
278
  /**
284
279
  * The width of the border surrounding each cell.
285
- *
286
280
  * @default 0
287
281
  */
288
282
  borderWidth?: number;
@@ -301,7 +295,6 @@ export interface ChartSeriesOptions {
301
295
  export type ChartSeriesRangeSliderOptions = {
302
296
  /**
303
297
  * Enable or disable the visibility of this series in the Range Slider.
304
- *
305
298
  * @default true
306
299
  */
307
300
  visible?: boolean;
@@ -2,7 +2,9 @@ import type { BaseTextStyle } from './base';
2
2
  export interface ChartTitle {
3
3
  text: string;
4
4
  style?: Partial<BaseTextStyle>;
5
- /** Can be used for the UI automated test.
6
- * It is assigned as a data-qa attribute to an element. */
5
+ /**
6
+ * Can be used for the UI automated test.
7
+ * It is assigned as a data-qa attribute to an element.
8
+ */
7
9
  qa?: string;
8
10
  }
@@ -119,9 +119,11 @@ export interface ChartTooltip<T = MeaningfulAny> {
119
119
  enabled?: boolean;
120
120
  /** Specifies the renderer for the tooltip. If returned null default tooltip renderer will be used. */
121
121
  renderer?: (args: ChartTooltipRendererArgs<T>) => React.ReactElement | null;
122
- /** Defines the way a single data/series is displayed (corresponding to a separate selected point/ruler/shape on the chart).
122
+ /**
123
+ * Defines the way a single data/series is displayed (corresponding to a separate selected point/ruler/shape on the chart).
123
124
  * It is useful in cases where you need to display additional information, but keep the general format of the tooltip.
124
- * If a string is returned, it will be interpreted as raw HTML and inserted without escaping. */
125
+ * If a string is returned, it will be interpreted as raw HTML and inserted without escaping.
126
+ */
125
127
  rowRenderer?: ((args: ChartTooltipRowRendererArgs) => React.ReactElement | string) | null;
126
128
  pin?: {
127
129
  enabled?: boolean;
@@ -151,7 +153,9 @@ export interface ChartTooltip<T = MeaningfulAny> {
151
153
  /** Formatting settings for totals tooltip value. */
152
154
  valueFormat?: ValueFormat;
153
155
  };
154
- /** Can be used for the UI automated test.
155
- * It is assigned as a data-qa attribute to an element. */
156
+ /**
157
+ * Can be used for the UI automated test.
158
+ * It is assigned as a data-qa attribute to an element.
159
+ */
156
160
  qa?: string;
157
161
  }
@@ -38,18 +38,20 @@ export interface TreemapSeries<T = MeaningfulAny> extends BaseSeries {
38
38
  layoutAlgorithm?: `${LayoutAlgorithm}`;
39
39
  /**
40
40
  * Options for the series data labels, appearing next to each data point.
41
- * */
41
+ */
42
42
  dataLabels?: BaseSeries['dataLabels'] & {
43
43
  /** Horizontal alignment of the data label inside the tile. */
44
44
  align?: 'left' | 'center' | 'right';
45
45
  };
46
- /** Data sorting settings (affects the order in which blocks are displayed inside the chart).
47
- * If the option is not specified, the data is displayed in the order defined by the user. */
46
+ /**
47
+ * Data sorting settings (affects the order in which blocks are displayed inside the chart).
48
+ * If the option is not specified, the data is displayed in the order defined by the user.
49
+ */
48
50
  sorting?: {
49
51
  /** Enable or disable sorting. */
50
52
  enabled?: boolean;
51
- /** The sorting direction.
52
- *
53
+ /**
54
+ * The sorting direction.
53
55
  * @default: 'desc'
54
56
  */
55
57
  direction?: 'asc' | 'desc';
@@ -51,7 +51,6 @@ export interface WaterfallSeries<T = MeaningfulAny> extends BaseSeries {
51
51
  *
52
52
  * - `'zero'`: Treat null values as zero
53
53
  * - `'skip'`: Omit data points with null values (don't render them)
54
- *
55
54
  * @default 'skip'
56
55
  */
57
56
  nullMode?: 'zero' | 'skip';
@@ -38,13 +38,11 @@ export interface ChartZoom {
38
38
  resetButton?: {
39
39
  /**
40
40
  * The alignment of the button.
41
- *
42
41
  * @default 'top-right'
43
42
  */
44
43
  align?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
45
44
  /**
46
45
  * The offset of the button.
47
- *
48
46
  * @default {x: 0, y: 0}
49
47
  */
50
48
  offset?: {
@@ -55,7 +53,6 @@ export interface ChartZoom {
55
53
  * The box to which the button is positioned relative to.
56
54
  * - `chart-box` refers to the entire chart area, including titles and legends.
57
55
  * - `plot-box` refers to the area where the series are drawn.
58
- *
59
56
  * @default 'chart-box'
60
57
  */
61
58
  relativeTo?: 'chart-box' | 'plot-box';
@@ -75,10 +75,10 @@ export interface ChartData<T = MeaningfulAny> {
75
75
  * It can be used to visualize related information on multiple charts.
76
76
  */
77
77
  split?: ChartSplit;
78
- /** The color list of palette.
78
+ /**
79
+ * The color list of palette.
79
80
  * If no color is set in series, the colors would be adopted sequentially and circularly from this list as the colors of series.
80
- *
81
81
  * @default ['#4DA2F1', '#FF3D64', '#8AD554', '#FFC636', '#FFB9DD', '#84D1EE', '#FF91A1', '#54A520', '#DB9100', '#BA74B3', '#1F68A9', '#ED65A9', '#0FA08D', '#FF7E00', '#E8B0A4', '#52A6C5', '#BE2443', '#70C1AF', '#FFB46C', '#DCA3D7']
82
- * */
82
+ */
83
83
  colors?: string[];
84
84
  }
@@ -13,6 +13,7 @@ export type ShapePoint = {
13
13
  data: ChartSeriesData;
14
14
  series: ChartSeries;
15
15
  subTotal?: number;
16
+ sourceX?: number;
16
17
  };
17
18
  export declare function getClosestPoints(args: GetClosestPointsArgs): TooltipDataChunk[];
18
19
  export {};
@@ -21,6 +21,7 @@ function getClosestYIndex(items, y) {
21
21
  return closestYIndex;
22
22
  }
23
23
  function getClosestPointsByXValue(x, y, points) {
24
+ var _a;
24
25
  const sorted = sort(points, (p) => p.x);
25
26
  const closestXIndex = bisector((p) => p.x).center(sorted, x);
26
27
  if (sorted.length === 0 || closestXIndex === -1) {
@@ -34,6 +35,18 @@ function getClosestPointsByXValue(x, y, points) {
34
35
  return sortedByY[index === -1 ? 0 : index];
35
36
  });
36
37
  const closestPoints = sort(groupedBySeries, (p) => p.y0);
38
+ const pointsWithSourceX = closestPoints.filter((p) => p.sourceX !== undefined);
39
+ const uniqueSourceX = new Set(pointsWithSourceX.map((p) => p.sourceX));
40
+ if (pointsWithSourceX.length > 1 && uniqueSourceX.size > 1) {
41
+ const sortedBySourceX = sort(pointsWithSourceX, (p) => { var _a; return (_a = p.sourceX) !== null && _a !== void 0 ? _a : 0; });
42
+ const closestSourceXIdx = bisector((p) => { var _a; return (_a = p.sourceX) !== null && _a !== void 0 ? _a : 0; }).center(sortedBySourceX, x);
43
+ const closestSourceX = (_a = sortedBySourceX[closestSourceXIdx]) === null || _a === void 0 ? void 0 : _a.sourceX;
44
+ const candidates = closestPoints.filter((p) => p.sourceX === undefined || p.sourceX === closestSourceX);
45
+ const sortedCandidates = sort(candidates, (p) => p.y0);
46
+ const winnerIdx = getClosestYIndex(sortedCandidates, y);
47
+ const winner = sortedCandidates[winnerIdx === -1 ? 0 : winnerIdx];
48
+ return closestPoints.map((p) => (Object.assign(Object.assign({}, p), { closest: p === winner })));
49
+ }
37
50
  const closestYIndex = getClosestYIndex(closestPoints, y);
38
51
  return closestPoints.map((p, i) => (Object.assign(Object.assign({}, p), { closest: i === closestYIndex })));
39
52
  }
@@ -86,13 +99,22 @@ export function getClosestPoints(args) {
86
99
  break;
87
100
  }
88
101
  case 'bar-x': {
89
- const barXPoints = list.map((d) => ({
90
- data: d.data,
91
- series: d.series,
92
- x: d.x + d.width / 2,
93
- y0: d.y,
94
- y1: d.y + d.height,
95
- }));
102
+ const barXList = list;
103
+ const barXGroups = groupBy(barXList, (d) => String(d.data.x));
104
+ const barXPoints = [];
105
+ Object.values(barXGroups).forEach((group) => {
106
+ const groupCenterX = group.reduce((sum, d) => sum + d.x + d.width / 2, 0) / group.length;
107
+ group.forEach((d) => {
108
+ barXPoints.push({
109
+ data: d.data,
110
+ series: d.series,
111
+ x: groupCenterX,
112
+ y0: d.y,
113
+ y1: d.y + d.height,
114
+ sourceX: d.x + d.width / 2,
115
+ });
116
+ });
117
+ });
96
118
  closestPointsByXValue.push(...barXPoints);
97
119
  break;
98
120
  }
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Calculates a numeric property based on the given arguments.
3
- *
4
- * @param {Object} args - The arguments for the calculation.
3
+ * @param {object} args - The arguments for the calculation.
5
4
  * @param {string | number | null} args.value - The value to calculate the property for.
6
5
  * @param {number} args.base - The base value to use in the calculation.
7
- * @return {number | undefined} The calculated numeric property, or undefined if the value is invalid.
6
+ * @returns {number | undefined} The calculated numeric property, or undefined if the value is invalid.
8
7
  * @example
9
8
  * const result1 = calculateNumericProperty({value: 1});
10
9
  * console.log(result1); // Output: 1
@@ -7,11 +7,10 @@ const isStringValueInPixel = (value = '') => {
7
7
  };
8
8
  /**
9
9
  * Calculates a numeric property based on the given arguments.
10
- *
11
- * @param {Object} args - The arguments for the calculation.
10
+ * @param {object} args - The arguments for the calculation.
12
11
  * @param {string | number | null} args.value - The value to calculate the property for.
13
12
  * @param {number} args.base - The base value to use in the calculation.
14
- * @return {number | undefined} The calculated numeric property, or undefined if the value is invalid.
13
+ * @returns {number | undefined} The calculated numeric property, or undefined if the value is invalid.
15
14
  * @example
16
15
  * const result1 = calculateNumericProperty({value: 1});
17
16
  * console.log(result1); // Output: 1
@@ -5,7 +5,6 @@ export type UnknownSeries = {
5
5
  };
6
6
  /**
7
7
  * Checks whether the series should be drawn with axes.
8
- *
9
8
  * @param series - The series object to check.
10
9
  * @returns `true` if the series should be drawn with axes, `false` otherwise.
11
10
  */