@octanejs/recharts 0.1.62 → 0.1.63

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 (73) hide show
  1. package/package.json +5 -5
  2. package/src/animation/AnimatedItems.tsrx +36 -31
  3. package/src/animation/CSSTransitionAnimate.tsrx +1 -2
  4. package/src/animation/JavascriptAnimate.tsrx +1 -2
  5. package/src/cartesian/Area.tsrx +414 -386
  6. package/src/cartesian/AreaRevealShape.tsrx +103 -84
  7. package/src/cartesian/Bar.tsrx +343 -317
  8. package/src/cartesian/BarStack.tsrx +33 -28
  9. package/src/cartesian/CartesianAxis.tsrx +168 -165
  10. package/src/cartesian/CartesianGrid.tsrx +256 -272
  11. package/src/cartesian/ErrorBar.tsrx +108 -104
  12. package/src/cartesian/Funnel.tsrx +405 -382
  13. package/src/cartesian/GraphicalItemClipPath.tsrx +4 -8
  14. package/src/cartesian/Line.tsrx +190 -177
  15. package/src/cartesian/LineDrawShape.tsrx +14 -15
  16. package/src/cartesian/ReferenceLine.tsrx +119 -105
  17. package/src/cartesian/Scatter.tsrx +416 -398
  18. package/src/cartesian/XAxis.tsrx +39 -32
  19. package/src/cartesian/YAxis.tsrx +47 -37
  20. package/src/cartesian/ZAxis.tsrx +76 -73
  21. package/src/chart/AreaChart.tsrx +15 -11
  22. package/src/chart/BarChart.tsrx +15 -11
  23. package/src/chart/CategoricalChart.tsrx +32 -26
  24. package/src/chart/ComposedChart.tsrx +15 -11
  25. package/src/chart/FunnelChart.tsrx +15 -11
  26. package/src/chart/LineChart.tsrx +15 -11
  27. package/src/chart/PieChart.tsrx +15 -11
  28. package/src/chart/PolarChart.tsrx +45 -48
  29. package/src/chart/RadarChart.tsrx +38 -32
  30. package/src/chart/RadialBarChart.tsrx +15 -11
  31. package/src/chart/RechartsWrapper.tsrx +214 -162
  32. package/src/chart/Sankey.tsrx +412 -378
  33. package/src/chart/ScatterChart.tsrx +15 -11
  34. package/src/chart/SunburstChart.tsrx +162 -155
  35. package/src/component/ActivePoints.tsrx +19 -13
  36. package/src/component/Cursor.tsrx +25 -18
  37. package/src/component/DefaultLegendContent.tsrx +131 -127
  38. package/src/component/DefaultTooltipContent.tsrx +46 -42
  39. package/src/component/Dots.tsrx +11 -5
  40. package/src/component/Label.tsrx +69 -55
  41. package/src/component/LabelList.tsrx +32 -27
  42. package/src/component/Legend.tsrx +120 -123
  43. package/src/component/ResponsiveContainer.tsrx +18 -11
  44. package/src/component/Text.tsrx +50 -43
  45. package/src/component/Tooltip.tsrx +234 -223
  46. package/src/component/TooltipBoundingBox.tsrx +34 -34
  47. package/src/container/ClipPathProvider.tsrx +1 -3
  48. package/src/container/Layer.tsrx +5 -1
  49. package/src/container/RootSurface.tsrx +31 -21
  50. package/src/container/Surface.tsrx +15 -13
  51. package/src/context/ErrorBarContext.tsrx +5 -5
  52. package/src/polar/Pie.tsrx +541 -487
  53. package/src/polar/PolarAngleAxis.tsrx +245 -227
  54. package/src/polar/PolarGrid.tsrx +139 -127
  55. package/src/polar/PolarRadiusAxis.tsrx +204 -185
  56. package/src/polar/Radar.tsrx +274 -264
  57. package/src/polar/RadialBar.tsrx +408 -361
  58. package/src/shape/Cross.tsrx +13 -7
  59. package/src/shape/Curve.tsrx +54 -44
  60. package/src/shape/Dot.tsrx +10 -8
  61. package/src/shape/Polygon.tsrx +38 -29
  62. package/src/shape/Rectangle.tsrx +73 -28
  63. package/src/shape/Sector.tsrx +30 -18
  64. package/src/shape/Symbols.tsrx +13 -11
  65. package/src/shape/Trapezoid.tsrx +16 -11
  66. package/src/state/RechartsStoreProvider.tsrx +5 -1
  67. package/src/synchronisation/useChartSynchronisation.tsrx +8 -7
  68. package/src/util/BarUtils.tsrx +43 -40
  69. package/src/util/FunnelUtils.tsrx +5 -5
  70. package/src/util/RadialBarUtils.tsrx +3 -4
  71. package/src/util/ScatterUtils.tsrx +13 -8
  72. package/src/zIndex/ZIndexLayer.tsrx +2 -2
  73. package/src/zIndex/ZIndexPortal.tsrx +2 -8
@@ -34,8 +34,10 @@ interface TextProps {
34
34
  }
35
35
  export type Props = Omit<SVGProps<SVGTextElement>, 'textAnchor' | 'verticalAnchor'> & TextProps;
36
36
  type CalculateWordsByLinesProps = Pick<Props, 'maxLines' | 'children' | 'style' | 'breakAll'>;
37
- type GetWordsByLinesProps =
38
- Pick<Props, 'width' | 'scaleToFit' | 'children' | 'style' | 'breakAll' | 'maxLines'>;
37
+ type GetWordsByLinesProps = Pick<
38
+ Props,
39
+ 'width' | 'scaleToFit' | 'children' | 'style' | 'breakAll' | 'maxLines'
40
+ >;
39
41
  // Port of component/Text.tsx — the SVG text renderer with word wrapping,
40
42
  // maxLines binary-search truncation, scaleToFit, and rotation. Measurement
41
43
  // runs through the vendored getStringSize (0×0 under SSR, so SSR renders the
@@ -66,12 +68,10 @@ const calculateWordWidths = ({
66
68
  words = children.toString().split(BREAKING_SPACES);
67
69
  }
68
70
  }
69
- const wordsWithComputedWidth = words.map(
70
- (word) => ({
71
- word,
72
- width: getStringSize(word, style).width,
73
- }),
74
- );
71
+ const wordsWithComputedWidth = words.map((word) => ({
72
+ word,
73
+ width: getStringSize(word, style).width,
74
+ }));
75
75
  const spaceWidth = breakAll ? 0 : getStringSize(' ', style).width;
76
76
  return { wordsWithComputedWidth, spaceWidth };
77
77
  } catch {
@@ -84,8 +84,9 @@ export function isValidTextAnchor(value: string | undefined): value is TextAncho
84
84
  }
85
85
 
86
86
  export function isRenderableText(val: unknown): val is RenderableText {
87
- return isNullish(val) || typeof val === 'string' || typeof val === 'number' ||
88
- typeof val === 'boolean';
87
+ return (
88
+ isNullish(val) || typeof val === 'string' || typeof val === 'number' || typeof val === 'boolean'
89
+ );
89
90
  }
90
91
 
91
92
  const calculate = (
@@ -93,26 +94,28 @@ const calculate = (
93
94
  lineWidth: number | string | undefined,
94
95
  spaceWidth: number,
95
96
  scaleToFit: boolean,
96
- ): WordsWithWidth[] => words.reduce<WordsWithWidth[]>((result, { word, width }) => {
97
- const currentLine = result[result.length - 1];
98
- if (
99
- currentLine && width != null &&
100
- (lineWidth == null || scaleToFit ||
97
+ ): WordsWithWidth[] =>
98
+ words.reduce<WordsWithWidth[]>((result, { word, width }) => {
99
+ const currentLine = result[result.length - 1];
100
+ if (
101
+ currentLine &&
102
+ width != null &&
103
+ (lineWidth == null ||
104
+ scaleToFit ||
101
105
  currentLine.width + width + spaceWidth < Number(lineWidth))
102
- ) {
103
- // Word can be added to an existing line
104
- currentLine.words.push(word);
105
- currentLine.width += width + spaceWidth;
106
- } else {
107
- // Add first word to line or word is too long to scaleToFit on existing line
108
- result.push({ words: [word], width });
109
- }
110
- return result;
111
- }, []);
106
+ ) {
107
+ // Word can be added to an existing line
108
+ currentLine.words.push(word);
109
+ currentLine.width += width + spaceWidth;
110
+ } else {
111
+ // Add first word to line or word is too long to scaleToFit on existing line
112
+ result.push({ words: [word], width });
113
+ }
114
+ return result;
115
+ }, []);
112
116
 
113
- const findLongestLine = (words: ReadonlyArray<WordsWithWidth>) => words.reduce(
114
- (a, b) => (a.width > b.width ? a : b),
115
- );
117
+ const findLongestLine = (words: ReadonlyArray<WordsWithWidth>) =>
118
+ words.reduce((a, b) => (a.width > b.width ? a : b));
116
119
 
117
120
  const suffix = '…';
118
121
 
@@ -210,11 +213,8 @@ const calculateWordsByLines = (
210
213
  };
211
214
 
212
215
  const getWordsWithoutCalculate = (children: OctaneNode) => {
213
- const words =
214
- !isNullish(children) ? children.toString().split(BREAKING_SPACES) : [];
215
- return [
216
- { words, width: undefined },
217
- ];
216
+ const words = !isNullish(children) ? children.toString().split(BREAKING_SPACES) : [];
217
+ return [{ words, width: undefined }];
218
218
  };
219
219
 
220
220
  export const getWordsByLines = ({
@@ -299,7 +299,12 @@ export function Text(outsideProps: Props) @{
299
299
  break;
300
300
  case 'middle':
301
301
  startDy = reduceCSSCalc(
302
- 'calc(' + (wordsByLines.length - 1) / 2 + ' * -' + lineHeight + ' + (' + capHeight +
302
+ 'calc(' +
303
+ (wordsByLines.length - 1) / 2 +
304
+ ' * -' +
305
+ lineHeight +
306
+ ' + (' +
307
+ capHeight +
303
308
  ' / 2))',
304
309
  );
305
310
  break;
@@ -330,15 +335,17 @@ export function Text(outsideProps: Props) @{
330
335
  class={clsx('recharts-text', className)}
331
336
  textAnchor={textAnchor}
332
337
  fill={fill.includes('url') ? DEFAULT_FILL : fill}
333
- >{wordsByLines.map((line, index) => {
334
- const words = line.words.join(breakAll ? '' : ' ');
335
- // duplicate words would cause duplicate keys — the index disambiguates
336
- return <tspan
337
- x={x}
338
- dy={index === 0 ? startDy : lineHeight}
339
- key={words + '-' + index}
340
- >{words}</tspan>;
341
- })}</text>
338
+ >
339
+ {wordsByLines.map((line, index) => {
340
+ const words = line.words.join(breakAll ? '' : ' ');
341
+ // duplicate words would cause duplicate keys — the index disambiguates
342
+ return (
343
+ <tspan x={x} dy={index === 0 ? startDy : lineHeight} key={words + '-' + index}>
344
+ {words}
345
+ </tspan>
346
+ );
347
+ })}
348
+ </text>
342
349
  }
343
350
 
344
351
  Text.displayName = 'Text';
@@ -48,15 +48,14 @@ function defaultUniqBy(entry: Payload<ValueType, NameType>) {
48
48
  export type TooltipContentProps<
49
49
  TValue extends ValueType = ValueType,
50
50
  TName extends NameType = NameType,
51
- > =
52
- TooltipProps<TValue, TName> & {
53
- label?: string | number;
54
- payload: TooltipPayload;
55
- coordinate: Coordinate | undefined;
56
- active: boolean;
57
- accessibilityLayer: boolean;
58
- activeIndex: TooltipIndex | undefined;
59
- };
51
+ > = TooltipProps<TValue, TName> & {
52
+ label?: string | number;
53
+ payload: TooltipPayload;
54
+ coordinate: Coordinate | undefined;
55
+ active: boolean;
56
+ accessibilityLayer: boolean;
57
+ activeIndex: TooltipIndex | undefined;
58
+ };
60
59
 
61
60
  function renderContent<TValue extends ValueType, TName extends NameType>(
62
61
  content: ContentType<TValue, TName> | undefined,
@@ -75,173 +74,180 @@ function renderContent<TValue extends ValueType, TName extends NameType>(
75
74
  type PropertiesReadFromContext =
76
75
  'viewBox' | 'active' | 'payload' | 'coordinate' | 'label' | 'accessibilityLayer';
77
76
 
78
- export type TooltipProps<TValue extends ValueType = ValueType, TName extends NameType = NameType> =
79
- Omit<DefaultTooltipContentProps<TValue, TName>, PropertiesReadFromContext> & {
80
- /**
81
- * If true, then Tooltip is always displayed, once an activeIndex is set by mouse over, or programmatically.
82
- * If false, then Tooltip is never displayed.
83
- * If undefined, Recharts will control when the Tooltip displays. This includes mouse and keyboard controls.
84
- */
85
- active?: boolean;
86
- /**
87
- * This option allows the tooltip to extend beyond the viewBox of the chart itself.
88
- * @defaultValue {"x":false,"y":false}
89
- */
90
- allowEscapeViewBox?: AllowInDimension;
91
- /**
92
- * Specifies the duration of animation, the unit of this option is ms.
93
- * @defaultValue 400
94
- */
95
- animationDuration?: AnimationDuration;
96
- /**
97
- * The type of easing function.
98
- * @defaultValue ease
99
- */
100
- animationEasing?: EasingInput;
101
- /**
102
- * Tooltip always attaches itself to the "Tooltip" axis. Which axis is it? Depends on the layout:
103
- * - horizontal layout -> X axis
104
- * - vertical layout -> Y axis
105
- * - radial layout -> radial axis
106
- * - centric layout -> angle axis
107
- *
108
- * Tooltip will use the default axis for the layout, unless you specify an axisId.
109
- *
110
- * @defaultValue 0
111
- */
112
- axisId?: AxisId;
113
- /**
114
- * Renders the content of the tooltip.
115
- *
116
- * This should return HTML elements, not SVG elements.
117
- *
118
- * - If not set, the {@link DefaultTooltipContent} component is used.
119
- * - If set to a React element, this element will be cloned and extra props will be passed in.
120
- * - If set to a function, the function will be called and should return HTML elements.
121
- *
122
- * @see {@link https://recharts.github.io/en-US/examples/CustomContentOfTooltip/ Example with custom content}
123
- */
124
- content?: ContentType<TValue, TName>;
125
- /**
126
- * The style of tooltip content which is a dom element.
127
- * @defaultValue {}
128
- */
129
- contentStyle?: CSSProperties;
130
- /**
131
- * If set false, no cursor will be drawn when tooltip is active.
132
- * If set a object, the option is the configuration of cursor.
133
- * If set a React element, the option is the custom react element of drawing cursor.
134
- * @defaultValue true
135
- */
136
- cursor?: CursorDefinition;
137
- defaultIndex?: number | TooltipIndex;
138
- /**
139
- * When an item of the payload has value null or undefined, this item won't be displayed.
140
- * @defaultValue true
141
- */
142
- filterNull?: boolean;
143
- /**
144
- * Function to customize the value in the tooltip.
145
- * If you return an array, the first entry will be the formatted "value", and the second entry will be the formatted "name"
146
- */
147
- formatter?: (value: TValue, name: TName, item: TooltipPayloadEntry, index: number, payload: TooltipPayload) => | OctaneNode
148
- | [OctaneNode, OctaneNode];
149
- /**
150
- * If true, the tooltip will display information about hidden series.
151
- * Defaults to false.
152
- * Interacting with the hide property of Area, Bar, Line, Scatter.
153
- *
154
- * @defaultValue false
155
- */
156
- includeHidden?: boolean | undefined;
157
- /**
158
- * If set false, animation of tooltip will be disabled.
159
- * If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
160
- * @defaultValue auto
161
- */
162
- isAnimationActive?: boolean | 'auto';
163
- /**
164
- * Sorts tooltip items.
165
- * Defaults to 'name' which means it sorts alphabetically by graphical item `name` property.
166
- * @defaultValue name
167
- */
168
- itemSorter?: TooltipItemSorter;
169
- /**
170
- * The style of default tooltip content item which is a li element.
171
- * @defaultValue {}
172
- */
173
- itemStyle?: CSSProperties;
174
- /**
175
- * The formatter function of label in tooltip.
176
- */
177
- labelFormatter?: (label: any, payload: TooltipPayload) => OctaneNode;
178
- /**
179
- * The style of default tooltip label which is a p element.
180
- * @defaultValue {}
181
- */
182
- labelStyle?: CSSProperties;
183
- /**
184
- * The offset size between the position of tooltip and the mouse cursor position.
185
- * When a number is provided, the same offset is applied to both x and y axes.
186
- *
187
- * When a Coordinate object is provided, you can specify different offsets for each axis (x and y as numbers)
188
- * @defaultValue 10
189
- */
190
- offset?: number | Coordinate;
191
- payloadUniqBy?: UniqueOption<TooltipPayloadEntry>;
192
- /**
193
- * If portal is defined, then Tooltip will use this element as a target
194
- * for rendering using React Portal: https://react.dev/reference/react-dom/createPortal
195
- *
196
- * If this is undefined then Tooltip renders inside the recharts-wrapper element.
197
- */
198
- portal?: HTMLElement | null;
199
- /**
200
- * If this field is set, the tooltip will be displayed at the specified position
201
- * regardless of the mouse position.
202
- *
203
- * You can set a single field (x or y) and let the other field be calculated automatically based
204
- * on the mouse position.
205
- */
206
- position?: Partial<Coordinate>;
207
- /**
208
- * @defaultValue {"x":false,"y":false}
209
- */
210
- reverseDirection?: AllowInDimension;
211
- /**
212
- * The separator between name and value.
213
- * @defaultValue ' : '
214
- */
215
- separator?: string;
216
- /**
217
- * Defines whether the tooltip is reacting to the current data point,
218
- * or to all data points at the current axis coordinate.
219
- *
220
- * - `true`: tooltip will appear on top of all bars on an axis tick.
221
- * - `false`: tooltip will appear on individual bars.
222
- *
223
- * Different chart types allow different modes, and have different defaults.
224
- *
225
- * @see {@link https://github.com/recharts/recharts/wiki/Tooltip-event-type-and-shared-prop Tooltip event type and shared prop wiki page}
226
- */
227
- shared?: boolean;
228
- /**
229
- * If `hover` then the Tooltip shows on mouse enter and hides on mouse leave.
230
- *
231
- * If `click` then the Tooltip shows after clicking and stays active.
232
- *
233
- * @defaultValue hover
234
- */
235
- trigger?: TooltipTrigger;
236
- /**
237
- * @defaultValue false
238
- */
239
- useTranslate3d?: boolean;
240
- /**
241
- * CSS styles to be applied to the wrapper `div` element.
242
- */
243
- wrapperStyle?: CSSProperties;
244
- };
77
+ export type TooltipProps<
78
+ TValue extends ValueType = ValueType,
79
+ TName extends NameType = NameType,
80
+ > = Omit<DefaultTooltipContentProps<TValue, TName>, PropertiesReadFromContext> & {
81
+ /**
82
+ * If true, then Tooltip is always displayed, once an activeIndex is set by mouse over, or programmatically.
83
+ * If false, then Tooltip is never displayed.
84
+ * If undefined, Recharts will control when the Tooltip displays. This includes mouse and keyboard controls.
85
+ */
86
+ active?: boolean;
87
+ /**
88
+ * This option allows the tooltip to extend beyond the viewBox of the chart itself.
89
+ * @defaultValue {"x":false,"y":false}
90
+ */
91
+ allowEscapeViewBox?: AllowInDimension;
92
+ /**
93
+ * Specifies the duration of animation, the unit of this option is ms.
94
+ * @defaultValue 400
95
+ */
96
+ animationDuration?: AnimationDuration;
97
+ /**
98
+ * The type of easing function.
99
+ * @defaultValue ease
100
+ */
101
+ animationEasing?: EasingInput;
102
+ /**
103
+ * Tooltip always attaches itself to the "Tooltip" axis. Which axis is it? Depends on the layout:
104
+ * - horizontal layout -> X axis
105
+ * - vertical layout -> Y axis
106
+ * - radial layout -> radial axis
107
+ * - centric layout -> angle axis
108
+ *
109
+ * Tooltip will use the default axis for the layout, unless you specify an axisId.
110
+ *
111
+ * @defaultValue 0
112
+ */
113
+ axisId?: AxisId;
114
+ /**
115
+ * Renders the content of the tooltip.
116
+ *
117
+ * This should return HTML elements, not SVG elements.
118
+ *
119
+ * - If not set, the {@link DefaultTooltipContent} component is used.
120
+ * - If set to a React element, this element will be cloned and extra props will be passed in.
121
+ * - If set to a function, the function will be called and should return HTML elements.
122
+ *
123
+ * @see {@link https://recharts.github.io/en-US/examples/CustomContentOfTooltip/ Example with custom content}
124
+ */
125
+ content?: ContentType<TValue, TName>;
126
+ /**
127
+ * The style of tooltip content which is a dom element.
128
+ * @defaultValue {}
129
+ */
130
+ contentStyle?: CSSProperties;
131
+ /**
132
+ * If set false, no cursor will be drawn when tooltip is active.
133
+ * If set a object, the option is the configuration of cursor.
134
+ * If set a React element, the option is the custom react element of drawing cursor.
135
+ * @defaultValue true
136
+ */
137
+ cursor?: CursorDefinition;
138
+ defaultIndex?: number | TooltipIndex;
139
+ /**
140
+ * When an item of the payload has value null or undefined, this item won't be displayed.
141
+ * @defaultValue true
142
+ */
143
+ filterNull?: boolean;
144
+ /**
145
+ * Function to customize the value in the tooltip.
146
+ * If you return an array, the first entry will be the formatted "value", and the second entry will be the formatted "name"
147
+ */
148
+ formatter?: (
149
+ value: TValue,
150
+ name: TName,
151
+ item: TooltipPayloadEntry,
152
+ index: number,
153
+ payload: TooltipPayload,
154
+ ) => OctaneNode | [OctaneNode, OctaneNode];
155
+ /**
156
+ * If true, the tooltip will display information about hidden series.
157
+ * Defaults to false.
158
+ * Interacting with the hide property of Area, Bar, Line, Scatter.
159
+ *
160
+ * @defaultValue false
161
+ */
162
+ includeHidden?: boolean | undefined;
163
+ /**
164
+ * If set false, animation of tooltip will be disabled.
165
+ * If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
166
+ * @defaultValue auto
167
+ */
168
+ isAnimationActive?: boolean | 'auto';
169
+ /**
170
+ * Sorts tooltip items.
171
+ * Defaults to 'name' which means it sorts alphabetically by graphical item `name` property.
172
+ * @defaultValue name
173
+ */
174
+ itemSorter?: TooltipItemSorter;
175
+ /**
176
+ * The style of default tooltip content item which is a li element.
177
+ * @defaultValue {}
178
+ */
179
+ itemStyle?: CSSProperties;
180
+ /**
181
+ * The formatter function of label in tooltip.
182
+ */
183
+ labelFormatter?: (label: any, payload: TooltipPayload) => OctaneNode;
184
+ /**
185
+ * The style of default tooltip label which is a p element.
186
+ * @defaultValue {}
187
+ */
188
+ labelStyle?: CSSProperties;
189
+ /**
190
+ * The offset size between the position of tooltip and the mouse cursor position.
191
+ * When a number is provided, the same offset is applied to both x and y axes.
192
+ *
193
+ * When a Coordinate object is provided, you can specify different offsets for each axis (x and y as numbers)
194
+ * @defaultValue 10
195
+ */
196
+ offset?: number | Coordinate;
197
+ payloadUniqBy?: UniqueOption<TooltipPayloadEntry>;
198
+ /**
199
+ * If portal is defined, then Tooltip will use this element as a target
200
+ * for rendering using React Portal: https://react.dev/reference/react-dom/createPortal
201
+ *
202
+ * If this is undefined then Tooltip renders inside the recharts-wrapper element.
203
+ */
204
+ portal?: HTMLElement | null;
205
+ /**
206
+ * If this field is set, the tooltip will be displayed at the specified position
207
+ * regardless of the mouse position.
208
+ *
209
+ * You can set a single field (x or y) and let the other field be calculated automatically based
210
+ * on the mouse position.
211
+ */
212
+ position?: Partial<Coordinate>;
213
+ /**
214
+ * @defaultValue {"x":false,"y":false}
215
+ */
216
+ reverseDirection?: AllowInDimension;
217
+ /**
218
+ * The separator between name and value.
219
+ * @defaultValue ' : '
220
+ */
221
+ separator?: string;
222
+ /**
223
+ * Defines whether the tooltip is reacting to the current data point,
224
+ * or to all data points at the current axis coordinate.
225
+ *
226
+ * - `true`: tooltip will appear on top of all bars on an axis tick.
227
+ * - `false`: tooltip will appear on individual bars.
228
+ *
229
+ * Different chart types allow different modes, and have different defaults.
230
+ *
231
+ * @see {@link https://github.com/recharts/recharts/wiki/Tooltip-event-type-and-shared-prop Tooltip event type and shared prop wiki page}
232
+ */
233
+ shared?: boolean;
234
+ /**
235
+ * If `hover` then the Tooltip shows on mouse enter and hides on mouse leave.
236
+ *
237
+ * If `click` then the Tooltip shows after clicking and stays active.
238
+ *
239
+ * @defaultValue hover
240
+ */
241
+ trigger?: TooltipTrigger;
242
+ /**
243
+ * @defaultValue false
244
+ */
245
+ useTranslate3d?: boolean;
246
+ /**
247
+ * CSS styles to be applied to the wrapper `div` element.
248
+ */
249
+ wrapperStyle?: CSSProperties;
250
+ };
245
251
 
246
252
  const emptyPayload: TooltipPayload = [];
247
253
 
@@ -323,34 +329,32 @@ export function Tooltip(outsideProps: TooltipProps<ValueType, NameType>) {
323
329
  const tooltipEventType = useTooltipEventType(shared);
324
330
 
325
331
  const { activeIndex, isActive } =
326
- useAppSelector(
327
- (state) => selectIsTooltipActive(state, tooltipEventType, trigger, defaultIndexAsString),
328
- ) ??
329
- {};
332
+ useAppSelector((state) =>
333
+ selectIsTooltipActive(state, tooltipEventType, trigger, defaultIndexAsString),
334
+ ) ?? {};
330
335
 
331
- const payloadFromRedux = useAppSelector(
332
- (state) => selectTooltipPayload(state, tooltipEventType, trigger, defaultIndexAsString),
336
+ const payloadFromRedux = useAppSelector((state) =>
337
+ selectTooltipPayload(state, tooltipEventType, trigger, defaultIndexAsString),
333
338
  );
334
339
 
335
- const labelFromRedux = useAppSelector(
336
- (state) => selectActiveLabel(state, tooltipEventType, trigger, defaultIndexAsString),
340
+ const labelFromRedux = useAppSelector((state) =>
341
+ selectActiveLabel(state, tooltipEventType, trigger, defaultIndexAsString),
337
342
  );
338
343
 
339
- const coordinate: Coordinate | undefined = useAppSelector(
340
- (state) => selectActiveCoordinate(state, tooltipEventType, trigger, defaultIndexAsString),
344
+ const coordinate: Coordinate | undefined = useAppSelector((state) =>
345
+ selectActiveCoordinate(state, tooltipEventType, trigger, defaultIndexAsString),
341
346
  );
342
347
  const payload: TooltipPayload | undefined = payloadFromRedux;
343
348
  const tooltipPortalFromContext = useTooltipPortal();
344
349
  /*
345
- * The user can set `active=true` on the Tooltip in which case the Tooltip will stay always active,
346
- * or `active=false` in which case the Tooltip never shows.
347
- *
348
- * If the `active` prop is not defined then it will show and hide based on mouse or keyboard activity.
349
- */
350
+ * The user can set `active=true` on the Tooltip in which case the Tooltip will stay always active,
351
+ * or `active=false` in which case the Tooltip never shows.
352
+ *
353
+ * If the `active` prop is not defined then it will show and hide based on mouse or keyboard activity.
354
+ */
350
355
  const finalIsActive: boolean = activeFromProps ?? isActive ?? false;
351
356
  const [lastBoundingBox, updateBoundingBox] = useElementOffset([payload, finalIsActive]);
352
- const finalLabel =
353
- tooltipEventType === 'axis' ? labelFromRedux : undefined;
357
+ const finalLabel = tooltipEventType === 'axis' ? labelFromRedux : undefined;
354
358
 
355
359
  useTooltipChartSynchronisation(
356
360
  tooltipEventType,
@@ -392,35 +396,42 @@ export function Tooltip(outsideProps: TooltipProps<ValueType, NameType>) {
392
396
  accessibilityLayer,
393
397
  };
394
398
 
395
- const tooltipElement = <TooltipBoundingBox
396
- allowEscapeViewBox={allowEscapeViewBox}
397
- animationDuration={animationDuration}
398
- animationEasing={animationEasing}
399
- isAnimationActive={isAnimationActive}
400
- active={finalIsActive}
401
- coordinate={coordinate}
402
- hasPayload={hasPayload}
403
- offset={offset}
404
- position={position}
405
- reverseDirection={reverseDirection}
406
- useTranslate3d={useTranslate3d}
407
- viewBox={viewBox}
408
- wrapperStyle={wrapperStyle}
409
- lastBoundingBox={lastBoundingBox}
410
- innerRef={updateBoundingBox}
411
- hasPortalFromProps={Boolean(portalFromProps)}
412
- >{renderContent(content, tooltipContentProps)}</TooltipBoundingBox>;
399
+ const tooltipElement = (
400
+ <TooltipBoundingBox
401
+ allowEscapeViewBox={allowEscapeViewBox}
402
+ animationDuration={animationDuration}
403
+ animationEasing={animationEasing}
404
+ isAnimationActive={isAnimationActive}
405
+ active={finalIsActive}
406
+ coordinate={coordinate}
407
+ hasPayload={hasPayload}
408
+ offset={offset}
409
+ position={position}
410
+ reverseDirection={reverseDirection}
411
+ useTranslate3d={useTranslate3d}
412
+ viewBox={viewBox}
413
+ wrapperStyle={wrapperStyle}
414
+ lastBoundingBox={lastBoundingBox}
415
+ innerRef={updateBoundingBox}
416
+ hasPortalFromProps={Boolean(portalFromProps)}
417
+ >
418
+ {renderContent(content, tooltipContentProps)}
419
+ </TooltipBoundingBox>
420
+ );
413
421
 
414
- return <>
415
- {/* Tooltip the HTML element renders through a React portal so that it escapes clipping, and it renders on top of everything else */}
416
- {createPortal(tooltipElement, tooltipPortal)}
417
- {finalIsActive &&
418
- <Cursor
419
- cursor={cursor}
420
- tooltipEventType={tooltipEventType}
421
- coordinate={coordinate}
422
- payload={finalPayload}
423
- index={activeIndex}
424
- />}
425
- </>;
422
+ return (
423
+ <>
424
+ {/* Tooltip the HTML element renders through a React portal so that it escapes clipping, and it renders on top of everything else */}
425
+ {createPortal(tooltipElement, tooltipPortal)}
426
+ {finalIsActive && (
427
+ <Cursor
428
+ cursor={cursor}
429
+ tooltipEventType={tooltipEventType}
430
+ coordinate={coordinate}
431
+ payload={finalPayload}
432
+ index={activeIndex}
433
+ />
434
+ )}
435
+ </>
436
+ );
426
437
  }