@octanejs/recharts 0.1.62 → 0.1.64
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/package.json +5 -5
- package/src/animation/AnimatedItems.tsrx +36 -31
- package/src/animation/CSSTransitionAnimate.tsrx +1 -2
- package/src/animation/JavascriptAnimate.tsrx +1 -2
- package/src/cartesian/Area.tsrx +414 -386
- package/src/cartesian/AreaRevealShape.tsrx +103 -84
- package/src/cartesian/Bar.tsrx +343 -317
- package/src/cartesian/BarStack.tsrx +33 -28
- package/src/cartesian/CartesianAxis.tsrx +168 -165
- package/src/cartesian/CartesianGrid.tsrx +256 -272
- package/src/cartesian/ErrorBar.tsrx +108 -104
- package/src/cartesian/Funnel.tsrx +405 -382
- package/src/cartesian/GraphicalItemClipPath.tsrx +4 -8
- package/src/cartesian/Line.tsrx +190 -177
- package/src/cartesian/LineDrawShape.tsrx +14 -15
- package/src/cartesian/ReferenceLine.tsrx +119 -105
- package/src/cartesian/Scatter.tsrx +416 -398
- package/src/cartesian/XAxis.tsrx +39 -32
- package/src/cartesian/YAxis.tsrx +47 -37
- package/src/cartesian/ZAxis.tsrx +76 -73
- package/src/chart/AreaChart.tsrx +15 -11
- package/src/chart/BarChart.tsrx +15 -11
- package/src/chart/CategoricalChart.tsrx +32 -26
- package/src/chart/ComposedChart.tsrx +15 -11
- package/src/chart/FunnelChart.tsrx +15 -11
- package/src/chart/LineChart.tsrx +15 -11
- package/src/chart/PieChart.tsrx +15 -11
- package/src/chart/PolarChart.tsrx +45 -48
- package/src/chart/RadarChart.tsrx +38 -32
- package/src/chart/RadialBarChart.tsrx +15 -11
- package/src/chart/RechartsWrapper.tsrx +214 -162
- package/src/chart/Sankey.tsrx +412 -378
- package/src/chart/ScatterChart.tsrx +15 -11
- package/src/chart/SunburstChart.tsrx +162 -155
- package/src/component/ActivePoints.tsrx +19 -13
- package/src/component/Cursor.tsrx +25 -18
- package/src/component/DefaultLegendContent.tsrx +131 -127
- package/src/component/DefaultTooltipContent.tsrx +46 -42
- package/src/component/Dots.tsrx +11 -5
- package/src/component/Label.tsrx +69 -55
- package/src/component/LabelList.tsrx +32 -27
- package/src/component/Legend.tsrx +120 -123
- package/src/component/ResponsiveContainer.tsrx +18 -11
- package/src/component/Text.tsrx +50 -43
- package/src/component/Tooltip.tsrx +234 -223
- package/src/component/TooltipBoundingBox.tsrx +34 -34
- package/src/container/ClipPathProvider.tsrx +1 -3
- package/src/container/Layer.tsrx +5 -1
- package/src/container/RootSurface.tsrx +31 -21
- package/src/container/Surface.tsrx +15 -13
- package/src/context/ErrorBarContext.tsrx +5 -5
- package/src/polar/Pie.tsrx +541 -487
- package/src/polar/PolarAngleAxis.tsrx +245 -227
- package/src/polar/PolarGrid.tsrx +139 -127
- package/src/polar/PolarRadiusAxis.tsrx +204 -185
- package/src/polar/Radar.tsrx +274 -264
- package/src/polar/RadialBar.tsrx +408 -361
- package/src/shape/Cross.tsrx +13 -7
- package/src/shape/Curve.tsrx +54 -44
- package/src/shape/Dot.tsrx +10 -8
- package/src/shape/Polygon.tsrx +38 -29
- package/src/shape/Rectangle.tsrx +73 -28
- package/src/shape/Sector.tsrx +30 -18
- package/src/shape/Symbols.tsrx +13 -11
- package/src/shape/Trapezoid.tsrx +16 -11
- package/src/state/RechartsStoreProvider.tsrx +5 -1
- package/src/synchronisation/useChartSynchronisation.tsrx +8 -7
- package/src/util/BarUtils.tsrx +43 -40
- package/src/util/FunnelUtils.tsrx +5 -5
- package/src/util/RadialBarUtils.tsrx +3 -4
- package/src/util/ScatterUtils.tsrx +13 -8
- package/src/zIndex/ZIndexLayer.tsrx +2 -2
- package/src/zIndex/ZIndexPortal.tsrx +2 -8
package/src/component/Text.tsrx
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
|
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[] =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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>) =>
|
|
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
|
-
|
|
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(' +
|
|
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
|
-
>
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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<
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
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
|
-
|
|
328
|
-
) ??
|
|
329
|
-
{};
|
|
332
|
+
useAppSelector((state) =>
|
|
333
|
+
selectIsTooltipActive(state, tooltipEventType, trigger, defaultIndexAsString),
|
|
334
|
+
) ?? {};
|
|
330
335
|
|
|
331
|
-
const payloadFromRedux = useAppSelector(
|
|
332
|
-
|
|
336
|
+
const payloadFromRedux = useAppSelector((state) =>
|
|
337
|
+
selectTooltipPayload(state, tooltipEventType, trigger, defaultIndexAsString),
|
|
333
338
|
);
|
|
334
339
|
|
|
335
|
-
const labelFromRedux = useAppSelector(
|
|
336
|
-
|
|
340
|
+
const labelFromRedux = useAppSelector((state) =>
|
|
341
|
+
selectActiveLabel(state, tooltipEventType, trigger, defaultIndexAsString),
|
|
337
342
|
);
|
|
338
343
|
|
|
339
|
-
const coordinate: Coordinate | undefined = useAppSelector(
|
|
340
|
-
|
|
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
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
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 =
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
}
|