@octanejs/recharts 0.1.16 → 0.1.18
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 +4 -4
- package/src/animation/CSSTransitionAnimate.tsrx +142 -0
- package/src/cartesian/Area.tsrx +1096 -0
- package/src/cartesian/Area.tsrx.d.ts +340 -0
- package/src/cartesian/AreaRevealShape.tsrx +202 -0
- package/src/cartesian/CartesianGrid.tsrx +643 -0
- package/src/cartesian/CartesianGrid.tsrx.d.ts +219 -0
- package/src/cartesian/ErrorBar.tsrx +322 -0
- package/src/cartesian/ErrorBar.tsrx.d.ts +131 -0
- package/src/cartesian/Funnel.tsrx +833 -0
- package/src/cartesian/Funnel.tsrx.d.ts +274 -0
- package/src/cartesian/ReferenceLine.tsrx +452 -0
- package/src/cartesian/ReferenceLine.tsrx.d.ts +178 -0
- package/src/cartesian/Scatter.tsrx +1076 -0
- package/src/cartesian/Scatter.tsrx.d.ts +351 -0
- package/src/cartesian/ZAxis.tsrx +148 -0
- package/src/cartesian/ZAxis.tsrx.d.ts +102 -0
- package/src/chart/AreaChart.tsrx +22 -0
- package/src/chart/AreaChart.tsrx.d.ts +12 -0
- package/src/chart/ComposedChart.tsrx +22 -0
- package/src/chart/ComposedChart.tsrx.d.ts +12 -0
- package/src/chart/FunnelChart.tsrx +22 -0
- package/src/chart/FunnelChart.tsrx.d.ts +12 -0
- package/src/chart/PieChart.tsrx +31 -0
- package/src/chart/PieChart.tsrx.d.ts +31 -0
- package/src/chart/PolarChart.tsrx +121 -0
- package/src/chart/RadarChart.tsrx +53 -0
- package/src/chart/RadarChart.tsrx.d.ts +31 -0
- package/src/chart/RadialBarChart.tsrx +31 -0
- package/src/chart/RadialBarChart.tsrx.d.ts +31 -0
- package/src/chart/Sankey.tsrx +1542 -0
- package/src/chart/Sankey.tsrx.d.ts +253 -0
- package/src/chart/ScatterChart.tsrx +22 -0
- package/src/chart/ScatterChart.tsrx.d.ts +12 -0
- package/src/chart/SunburstChart.tsrx +495 -0
- package/src/chart/SunburstChart.tsrx.d.ts +146 -0
- package/src/chart/types.ts +19 -0
- package/src/component/Cursor.tsrx +157 -0
- package/src/component/DefaultLegendContent.tsrx +288 -0
- package/src/component/DefaultLegendContent.tsrx.d.ts +125 -0
- package/src/component/DefaultTooltipContent.tsrx +215 -0
- package/src/component/DefaultTooltipContent.tsrx.d.ts +87 -0
- package/src/component/Legend.tsrx +302 -0
- package/src/component/Legend.tsrx.d.ts +88 -0
- package/src/component/ResponsiveContainer.ts +1 -22
- package/src/component/ResponsiveContainer.tsrx +171 -0
- package/src/component/ResponsiveContainer.tsrx.d.ts +81 -0
- package/src/component/Tooltip.tsrx +425 -0
- package/src/component/Tooltip.tsrx.d.ts +246 -0
- package/src/component/TooltipBoundingBox.tsrx +135 -0
- package/src/context/CellsContext.ts +12 -0
- package/src/context/legendPayloadContext.tsrx +11 -0
- package/src/context/useTooltipAxis.ts +20 -0
- package/src/index.d.ts +236 -0
- package/src/index.ts +67 -0
- package/src/polar/Pie.tsrx +1224 -0
- package/src/polar/Pie.tsrx.d.ts +436 -0
- package/src/polar/PolarAngleAxis.tsrx +554 -0
- package/src/polar/PolarAngleAxis.tsrx.d.ts +215 -0
- package/src/polar/PolarGrid.tsrx +317 -0
- package/src/polar/PolarGrid.tsrx.d.ts +117 -0
- package/src/polar/PolarRadiusAxis.tsrx +463 -0
- package/src/polar/PolarRadiusAxis.tsrx.d.ts +209 -0
- package/src/polar/Radar.tsrx +696 -0
- package/src/polar/Radar.tsrx.d.ts +215 -0
- package/src/polar/RadialBar.tsrx +887 -0
- package/src/polar/RadialBar.tsrx.d.ts +340 -0
- package/src/state/ReportPolarOptions.tsrx +11 -0
- package/src/state/selectors/areaSelectors.ts +257 -0
- package/src/state/selectors/funnelSelectors.ts +86 -0
- package/src/state/selectors/pieSelectors.ts +134 -0
- package/src/state/selectors/polarGridSelectors.ts +43 -0
- package/src/state/selectors/polarScaleSelectors.ts +159 -0
- package/src/state/selectors/polarSelectors.ts +198 -0
- package/src/state/selectors/radarSelectors.ts +228 -0
- package/src/state/selectors/radialBarSelectors.ts +511 -0
- package/src/state/selectors/scatterSelectors.ts +168 -0
- package/src/util/FunnelUtils.tsrx +19 -0
- package/src/util/RadialBarUtils.tsrx +29 -0
- package/src/util/ScatterUtils.tsrx +34 -0
- package/src/util/cursor/getCursorPoints.ts +45 -0
- package/src/util/cursor/getCursorRectangle.ts +28 -0
- package/src/util/cursor/getRadialCursorPoints.ts +31 -0
- package/src/util/payload/getUniqPayload.ts +28 -0
- package/src/util/scale/CartesianScaleHelper.ts +71 -0
- package/src/util/tooltip/translate.ts +168 -0
- package/src/util/types.ts +3 -0
- package/src/util/useElementOffset.ts +147 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import * as React from 'octane';
|
|
2
|
+
import { CSSProperties, ReactElement, ReactNode } from 'octane';
|
|
3
|
+
import {
|
|
4
|
+
NameType,
|
|
5
|
+
Props as DefaultTooltipContentProps,
|
|
6
|
+
TooltipItemSorter,
|
|
7
|
+
ValueType,
|
|
8
|
+
} from './DefaultTooltipContent';
|
|
9
|
+
import { UniqueOption } from '../util/payload/getUniqPayload';
|
|
10
|
+
import { AllowInDimension, AnimationDuration, EasingInput, Coordinate } from '../util/types';
|
|
11
|
+
import { CursorDefinition } from './Cursor';
|
|
12
|
+
import { TooltipTrigger } from '../chart/types';
|
|
13
|
+
import { TooltipIndex, TooltipPayload, TooltipPayloadEntry } from '../state/tooltipSlice';
|
|
14
|
+
import { AxisId } from '../state/cartesianAxisSlice';
|
|
15
|
+
export type ContentType<TValue extends ValueType = ValueType, TName extends NameType = NameType> =
|
|
16
|
+
ReactElement | ((props: TooltipContentProps<TValue, TName>) => ReactNode);
|
|
17
|
+
export type TooltipContentProps<
|
|
18
|
+
TValue extends ValueType = ValueType,
|
|
19
|
+
TName extends NameType = NameType,
|
|
20
|
+
> = TooltipProps<TValue, TName> & {
|
|
21
|
+
label?: string | number;
|
|
22
|
+
payload: TooltipPayload;
|
|
23
|
+
coordinate: Coordinate | undefined;
|
|
24
|
+
active: boolean;
|
|
25
|
+
accessibilityLayer: boolean;
|
|
26
|
+
activeIndex: TooltipIndex | undefined;
|
|
27
|
+
};
|
|
28
|
+
type PropertiesReadFromContext =
|
|
29
|
+
'viewBox' | 'active' | 'payload' | 'coordinate' | 'label' | 'accessibilityLayer';
|
|
30
|
+
export type TooltipProps<
|
|
31
|
+
TValue extends ValueType = ValueType,
|
|
32
|
+
TName extends NameType = NameType,
|
|
33
|
+
> = Omit<DefaultTooltipContentProps<TValue, TName>, PropertiesReadFromContext> & {
|
|
34
|
+
/**
|
|
35
|
+
* If true, then Tooltip is always displayed, once an activeIndex is set by mouse over, or programmatically.
|
|
36
|
+
* If false, then Tooltip is never displayed.
|
|
37
|
+
* If undefined, Recharts will control when the Tooltip displays. This includes mouse and keyboard controls.
|
|
38
|
+
*/
|
|
39
|
+
active?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* This option allows the tooltip to extend beyond the viewBox of the chart itself.
|
|
42
|
+
* @defaultValue {"x":false,"y":false}
|
|
43
|
+
*/
|
|
44
|
+
allowEscapeViewBox?: AllowInDimension;
|
|
45
|
+
/**
|
|
46
|
+
* Specifies the duration of animation, the unit of this option is ms.
|
|
47
|
+
* @defaultValue 400
|
|
48
|
+
*/
|
|
49
|
+
animationDuration?: AnimationDuration;
|
|
50
|
+
/**
|
|
51
|
+
* The type of easing function.
|
|
52
|
+
* @defaultValue ease
|
|
53
|
+
*/
|
|
54
|
+
animationEasing?: EasingInput;
|
|
55
|
+
/**
|
|
56
|
+
* Tooltip always attaches itself to the "Tooltip" axis. Which axis is it? Depends on the layout:
|
|
57
|
+
* - horizontal layout -> X axis
|
|
58
|
+
* - vertical layout -> Y axis
|
|
59
|
+
* - radial layout -> radial axis
|
|
60
|
+
* - centric layout -> angle axis
|
|
61
|
+
*
|
|
62
|
+
* Tooltip will use the default axis for the layout, unless you specify an axisId.
|
|
63
|
+
*
|
|
64
|
+
* @defaultValue 0
|
|
65
|
+
*/
|
|
66
|
+
axisId?: AxisId;
|
|
67
|
+
/**
|
|
68
|
+
* Renders the content of the tooltip.
|
|
69
|
+
*
|
|
70
|
+
* This should return HTML elements, not SVG elements.
|
|
71
|
+
*
|
|
72
|
+
* - If not set, the {@link DefaultTooltipContent} component is used.
|
|
73
|
+
* - If set to a React element, this element will be cloned and extra props will be passed in.
|
|
74
|
+
* - If set to a function, the function will be called and should return HTML elements.
|
|
75
|
+
*
|
|
76
|
+
* @see {@link https://recharts.github.io/en-US/examples/CustomContentOfTooltip/ Example with custom content}
|
|
77
|
+
*/
|
|
78
|
+
content?: ContentType<TValue, TName>;
|
|
79
|
+
/**
|
|
80
|
+
* The style of tooltip content which is a dom element.
|
|
81
|
+
* @defaultValue {}
|
|
82
|
+
*/
|
|
83
|
+
contentStyle?: CSSProperties;
|
|
84
|
+
/**
|
|
85
|
+
* If set false, no cursor will be drawn when tooltip is active.
|
|
86
|
+
* If set a object, the option is the configuration of cursor.
|
|
87
|
+
* If set a React element, the option is the custom react element of drawing cursor.
|
|
88
|
+
* @defaultValue true
|
|
89
|
+
*/
|
|
90
|
+
cursor?: CursorDefinition;
|
|
91
|
+
defaultIndex?: number | TooltipIndex;
|
|
92
|
+
/**
|
|
93
|
+
* When an item of the payload has value null or undefined, this item won't be displayed.
|
|
94
|
+
* @defaultValue true
|
|
95
|
+
*/
|
|
96
|
+
filterNull?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Function to customize the value in the tooltip.
|
|
99
|
+
* If you return an array, the first entry will be the formatted "value", and the second entry will be the formatted "name"
|
|
100
|
+
*/
|
|
101
|
+
formatter?: (
|
|
102
|
+
value: TValue,
|
|
103
|
+
name: TName,
|
|
104
|
+
item: TooltipPayloadEntry,
|
|
105
|
+
index: number,
|
|
106
|
+
payload: TooltipPayload,
|
|
107
|
+
) => ReactNode | [ReactNode, ReactNode];
|
|
108
|
+
/**
|
|
109
|
+
* If true, the tooltip will display information about hidden series.
|
|
110
|
+
* Defaults to false.
|
|
111
|
+
* Interacting with the hide property of Area, Bar, Line, Scatter.
|
|
112
|
+
*
|
|
113
|
+
* @defaultValue false
|
|
114
|
+
*/
|
|
115
|
+
includeHidden?: boolean | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* If set false, animation of tooltip will be disabled.
|
|
118
|
+
* If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
|
|
119
|
+
* @defaultValue auto
|
|
120
|
+
*/
|
|
121
|
+
isAnimationActive?: boolean | 'auto';
|
|
122
|
+
/**
|
|
123
|
+
* Sorts tooltip items.
|
|
124
|
+
* Defaults to 'name' which means it sorts alphabetically by graphical item `name` property.
|
|
125
|
+
* @defaultValue name
|
|
126
|
+
*/
|
|
127
|
+
itemSorter?: TooltipItemSorter;
|
|
128
|
+
/**
|
|
129
|
+
* The style of default tooltip content item which is a li element.
|
|
130
|
+
* @defaultValue {}
|
|
131
|
+
*/
|
|
132
|
+
itemStyle?: CSSProperties;
|
|
133
|
+
/**
|
|
134
|
+
* The formatter function of label in tooltip.
|
|
135
|
+
*/
|
|
136
|
+
labelFormatter?: (label: any, payload: TooltipPayload) => ReactNode;
|
|
137
|
+
/**
|
|
138
|
+
* The style of default tooltip label which is a p element.
|
|
139
|
+
* @defaultValue {}
|
|
140
|
+
*/
|
|
141
|
+
labelStyle?: CSSProperties;
|
|
142
|
+
/**
|
|
143
|
+
* The offset size between the position of tooltip and the mouse cursor position.
|
|
144
|
+
* When a number is provided, the same offset is applied to both x and y axes.
|
|
145
|
+
*
|
|
146
|
+
* When a Coordinate object is provided, you can specify different offsets for each axis (x and y as numbers)
|
|
147
|
+
* @defaultValue 10
|
|
148
|
+
*/
|
|
149
|
+
offset?: number | Coordinate;
|
|
150
|
+
payloadUniqBy?: UniqueOption<TooltipPayloadEntry>;
|
|
151
|
+
/**
|
|
152
|
+
* If portal is defined, then Tooltip will use this element as a target
|
|
153
|
+
* for rendering using React Portal: https://react.dev/reference/react-dom/createPortal
|
|
154
|
+
*
|
|
155
|
+
* If this is undefined then Tooltip renders inside the recharts-wrapper element.
|
|
156
|
+
*/
|
|
157
|
+
portal?: HTMLElement | null;
|
|
158
|
+
/**
|
|
159
|
+
* If this field is set, the tooltip will be displayed at the specified position
|
|
160
|
+
* regardless of the mouse position.
|
|
161
|
+
*
|
|
162
|
+
* You can set a single field (x or y) and let the other field be calculated automatically based
|
|
163
|
+
* on the mouse position.
|
|
164
|
+
*/
|
|
165
|
+
position?: Partial<Coordinate>;
|
|
166
|
+
/**
|
|
167
|
+
* @defaultValue {"x":false,"y":false}
|
|
168
|
+
*/
|
|
169
|
+
reverseDirection?: AllowInDimension;
|
|
170
|
+
/**
|
|
171
|
+
* The separator between name and value.
|
|
172
|
+
* @defaultValue ' : '
|
|
173
|
+
*/
|
|
174
|
+
separator?: string;
|
|
175
|
+
/**
|
|
176
|
+
* Defines whether the tooltip is reacting to the current data point,
|
|
177
|
+
* or to all data points at the current axis coordinate.
|
|
178
|
+
*
|
|
179
|
+
* - `true`: tooltip will appear on top of all bars on an axis tick.
|
|
180
|
+
* - `false`: tooltip will appear on individual bars.
|
|
181
|
+
*
|
|
182
|
+
* Different chart types allow different modes, and have different defaults.
|
|
183
|
+
*
|
|
184
|
+
* @see {@link https://github.com/recharts/recharts/wiki/Tooltip-event-type-and-shared-prop Tooltip event type and shared prop wiki page}
|
|
185
|
+
*/
|
|
186
|
+
shared?: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* If `hover` then the Tooltip shows on mouse enter and hides on mouse leave.
|
|
189
|
+
*
|
|
190
|
+
* If `click` then the Tooltip shows after clicking and stays active.
|
|
191
|
+
*
|
|
192
|
+
* @defaultValue hover
|
|
193
|
+
*/
|
|
194
|
+
trigger?: TooltipTrigger;
|
|
195
|
+
/**
|
|
196
|
+
* @defaultValue false
|
|
197
|
+
*/
|
|
198
|
+
useTranslate3d?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* CSS styles to be applied to the wrapper `div` element.
|
|
201
|
+
*/
|
|
202
|
+
wrapperStyle?: CSSProperties;
|
|
203
|
+
};
|
|
204
|
+
export declare const defaultTooltipProps: {
|
|
205
|
+
readonly allowEscapeViewBox: {
|
|
206
|
+
readonly x: false;
|
|
207
|
+
readonly y: false;
|
|
208
|
+
};
|
|
209
|
+
readonly animationDuration: 400;
|
|
210
|
+
readonly animationEasing: 'ease';
|
|
211
|
+
readonly axisId: 0;
|
|
212
|
+
readonly contentStyle: {};
|
|
213
|
+
readonly cursor: true;
|
|
214
|
+
readonly filterNull: true;
|
|
215
|
+
readonly includeHidden: false;
|
|
216
|
+
readonly isAnimationActive: 'auto';
|
|
217
|
+
readonly itemSorter: 'name';
|
|
218
|
+
readonly itemStyle: {};
|
|
219
|
+
readonly labelStyle: {};
|
|
220
|
+
readonly offset: 10;
|
|
221
|
+
readonly reverseDirection: {
|
|
222
|
+
readonly x: false;
|
|
223
|
+
readonly y: false;
|
|
224
|
+
};
|
|
225
|
+
readonly separator: ' : ';
|
|
226
|
+
readonly trigger: 'hover';
|
|
227
|
+
readonly useTranslate3d: false;
|
|
228
|
+
readonly wrapperStyle: {};
|
|
229
|
+
};
|
|
230
|
+
/**
|
|
231
|
+
* The Tooltip component displays a floating box with data values when hovering over or clicking on chart elements.
|
|
232
|
+
*
|
|
233
|
+
* It can be configured to show information for individual data points or for all points at a specific axis coordinate.
|
|
234
|
+
* The appearance and content of the tooltip can be customized via props.
|
|
235
|
+
*
|
|
236
|
+
* @see {@link https://github.com/recharts/recharts/wiki/Tooltip-event-type-and-shared-prop Tooltip event type and shared prop wiki page}
|
|
237
|
+
* @see {@link https://recharts.github.io/en-US/guide/activeIndex/ Active index replacement when migrating from Recharts v2 to v3}
|
|
238
|
+
*
|
|
239
|
+
* @consumes CartesianChartContext
|
|
240
|
+
* @consumes PolarChartContext
|
|
241
|
+
* @consumes TooltipEntrySettings
|
|
242
|
+
*/
|
|
243
|
+
export declare function Tooltip(
|
|
244
|
+
outsideProps: TooltipProps<ValueType, NameType>,
|
|
245
|
+
): React.JSX.Element | null;
|
|
246
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import * as React from 'octane';
|
|
2
|
+
import type { OctaneNode } from 'octane';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AllowInDimension,
|
|
6
|
+
AnimationDuration,
|
|
7
|
+
EasingInput,
|
|
8
|
+
CartesianViewBox,
|
|
9
|
+
Coordinate,
|
|
10
|
+
PolarCoordinate,
|
|
11
|
+
} from '../util/types';
|
|
12
|
+
import { ElementOffset, SetElementOffset } from '../util/useElementOffset';
|
|
13
|
+
import { getTooltipTranslate } from '../util/tooltip/translate';
|
|
14
|
+
import { usePrefersReducedMotion } from '../util/usePrefersReducedMotion';
|
|
15
|
+
|
|
16
|
+
export type TooltipBoundingBoxProps = {
|
|
17
|
+
active: boolean;
|
|
18
|
+
allowEscapeViewBox: AllowInDimension;
|
|
19
|
+
animationDuration: AnimationDuration;
|
|
20
|
+
animationEasing: EasingInput;
|
|
21
|
+
children: OctaneNode;
|
|
22
|
+
coordinate: Coordinate | PolarCoordinate | undefined;
|
|
23
|
+
hasPayload: boolean;
|
|
24
|
+
isAnimationActive: boolean | 'auto';
|
|
25
|
+
offset: number | Coordinate;
|
|
26
|
+
position: Partial<Coordinate> | undefined;
|
|
27
|
+
reverseDirection: AllowInDimension;
|
|
28
|
+
useTranslate3d: boolean;
|
|
29
|
+
viewBox: CartesianViewBox;
|
|
30
|
+
wrapperStyle: React.CSSProperties;
|
|
31
|
+
lastBoundingBox: ElementOffset;
|
|
32
|
+
innerRef: SetElementOffset;
|
|
33
|
+
hasPortalFromProps: boolean;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function resolveTransitionProperty(args: {
|
|
37
|
+
prefersReducedMotion: boolean;
|
|
38
|
+
isAnimationActive: boolean | 'auto';
|
|
39
|
+
active: boolean;
|
|
40
|
+
animationDuration: number;
|
|
41
|
+
animationEasing: EasingInput;
|
|
42
|
+
}): `transform ${number}ms ${string}` | undefined {
|
|
43
|
+
if (args.prefersReducedMotion && args.isAnimationActive === 'auto') {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
if (args.isAnimationActive && args.active) {
|
|
47
|
+
const easing =
|
|
48
|
+
typeof args.animationEasing === 'string' ? args.animationEasing : 'ease';
|
|
49
|
+
return `transform ${args.animationDuration}ms ${easing}`;
|
|
50
|
+
}
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function TooltipBoundingBoxImpl(props: TooltipBoundingBoxProps) {
|
|
55
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
56
|
+
const [state, setState] = React.useState(
|
|
57
|
+
() => ({
|
|
58
|
+
dismissed: false,
|
|
59
|
+
dismissedAtCoordinate: { x: 0, y: 0 },
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
65
|
+
if (event.key === 'Escape') {
|
|
66
|
+
setState({
|
|
67
|
+
dismissed: true,
|
|
68
|
+
dismissedAtCoordinate: {
|
|
69
|
+
x: props.coordinate?.x ?? 0,
|
|
70
|
+
y: props.coordinate?.y ?? 0,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
76
|
+
return () => {
|
|
77
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
78
|
+
};
|
|
79
|
+
}, [props.coordinate?.x, props.coordinate?.y]);
|
|
80
|
+
|
|
81
|
+
if (
|
|
82
|
+
state.dismissed &&
|
|
83
|
+
((props.coordinate?.x ?? 0) !== state.dismissedAtCoordinate.x ||
|
|
84
|
+
(props.coordinate?.y ?? 0) !== state.dismissedAtCoordinate.y)
|
|
85
|
+
) {
|
|
86
|
+
setState({ ...state, dismissed: false });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const { cssClasses, cssProperties } = getTooltipTranslate({
|
|
90
|
+
allowEscapeViewBox: props.allowEscapeViewBox,
|
|
91
|
+
coordinate: props.coordinate,
|
|
92
|
+
offsetLeft: typeof props.offset === 'number' ? props.offset : props.offset.x,
|
|
93
|
+
offsetTop: typeof props.offset === 'number' ? props.offset : props.offset.y,
|
|
94
|
+
position: props.position,
|
|
95
|
+
reverseDirection: props.reverseDirection,
|
|
96
|
+
tooltipBox: {
|
|
97
|
+
height: props.lastBoundingBox.height,
|
|
98
|
+
width: props.lastBoundingBox.width,
|
|
99
|
+
},
|
|
100
|
+
useTranslate3d: props.useTranslate3d,
|
|
101
|
+
viewBox: props.viewBox,
|
|
102
|
+
});
|
|
103
|
+
const positionStyle: React.CSSProperties =
|
|
104
|
+
props.hasPortalFromProps
|
|
105
|
+
? {}
|
|
106
|
+
: {
|
|
107
|
+
transition: resolveTransitionProperty({
|
|
108
|
+
prefersReducedMotion,
|
|
109
|
+
isAnimationActive: props.isAnimationActive,
|
|
110
|
+
active: props.active,
|
|
111
|
+
animationDuration: props.animationDuration,
|
|
112
|
+
animationEasing: props.animationEasing,
|
|
113
|
+
}),
|
|
114
|
+
...cssProperties,
|
|
115
|
+
pointerEvents: 'none',
|
|
116
|
+
position: 'absolute',
|
|
117
|
+
top: 0,
|
|
118
|
+
left: 0,
|
|
119
|
+
};
|
|
120
|
+
const outerStyle: React.CSSProperties = {
|
|
121
|
+
...positionStyle,
|
|
122
|
+
visibility: !state.dismissed && props.active && props.hasPayload ? 'visible' : 'hidden',
|
|
123
|
+
...props.wrapperStyle,
|
|
124
|
+
};
|
|
125
|
+
return <div
|
|
126
|
+
// @ts-expect-error typescript library does not recognize xmlns attribute, but it's required for an HTML chunk inside SVG.
|
|
127
|
+
xmlns="http://www.w3.org/1999/xhtml"
|
|
128
|
+
tabIndex={-1}
|
|
129
|
+
className={cssClasses}
|
|
130
|
+
style={outerStyle}
|
|
131
|
+
ref={props.innerRef}
|
|
132
|
+
>{props.children}</div>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const TooltipBoundingBox = React.memo(TooltipBoundingBoxImpl);
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
// effects run in order), so indexes line up with data indexes exactly like the
|
|
9
9
|
// upstream element order did.
|
|
10
10
|
import { createContext, useContext, useMemo, useState } from 'octane';
|
|
11
|
+
import { shallowEqual } from '@octanejs/redux';
|
|
11
12
|
import { splitSlot, subSlot } from '../internal';
|
|
12
13
|
|
|
13
14
|
export interface CellRegistry {
|
|
@@ -58,6 +59,17 @@ export function useCellRegistry(...rest: any[]): [RegisteredCell[] | undefined,
|
|
|
58
59
|
};
|
|
59
60
|
return {
|
|
60
61
|
register(token: object, props: unknown) {
|
|
62
|
+
const previousProps = entries.get(token);
|
|
63
|
+
if (
|
|
64
|
+
entries.has(token) &&
|
|
65
|
+
previousProps != null &&
|
|
66
|
+
props != null &&
|
|
67
|
+
typeof previousProps === 'object' &&
|
|
68
|
+
typeof props === 'object' &&
|
|
69
|
+
shallowEqual(previousProps, props)
|
|
70
|
+
) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
61
73
|
entries.set(token, props);
|
|
62
74
|
publish();
|
|
63
75
|
},
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LegendPayload } from '../component/DefaultLegendContent';
|
|
2
|
+
import { useAppSelector } from '../state/hooks';
|
|
3
|
+
import { selectLegendPayload } from '../state/selectors/legendSelectors';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Use this hook in Legend, or anywhere else where you want to read the current Legend items.
|
|
7
|
+
* @return all Legend items ready to be rendered
|
|
8
|
+
*/
|
|
9
|
+
export function useLegendPayload(): ReadonlyArray<LegendPayload> | undefined {
|
|
10
|
+
return useAppSelector(selectLegendPayload);
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useAppSelector } from '../state/hooks';
|
|
2
|
+
import { getBandSizeOfAxis } from '../util/ChartUtils';
|
|
3
|
+
import { RenderableAxisSettings, selectTooltipAxis } from '../state/selectors/axisSelectors';
|
|
4
|
+
import {
|
|
5
|
+
selectTooltipAxisScale,
|
|
6
|
+
selectTooltipAxisTicks,
|
|
7
|
+
} from '../state/selectors/tooltipSelectors';
|
|
8
|
+
|
|
9
|
+
export const useTooltipAxis = (): RenderableAxisSettings | undefined =>
|
|
10
|
+
useAppSelector(selectTooltipAxis);
|
|
11
|
+
|
|
12
|
+
export const useTooltipAxisBandSize = (): number | undefined => {
|
|
13
|
+
const tooltipAxis = useTooltipAxis();
|
|
14
|
+
const tooltipTicks = useAppSelector(selectTooltipAxisTicks);
|
|
15
|
+
const tooltipAxisScale = useAppSelector(selectTooltipAxisScale);
|
|
16
|
+
if (!tooltipAxis || !tooltipAxisScale) {
|
|
17
|
+
return getBandSizeOfAxis(undefined, tooltipTicks);
|
|
18
|
+
}
|
|
19
|
+
return getBandSizeOfAxis({ ...tooltipAxis, scale: tooltipAxisScale }, tooltipTicks);
|
|
20
|
+
};
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import type { OctaneNode } from 'octane';
|
|
2
|
+
|
|
3
|
+
export type NameType = string | number;
|
|
4
|
+
export type ValueType = string | number | Array<string | number>;
|
|
5
|
+
type Render = OctaneNode | ((...args: any[]) => OctaneNode);
|
|
6
|
+
type Handler = (...args: any[]) => void;
|
|
7
|
+
|
|
8
|
+
export interface RechartsProps {
|
|
9
|
+
accessibilityLayer?: boolean;
|
|
10
|
+
allowDecimals?: boolean;
|
|
11
|
+
activeBar?: Render | Record<string, unknown>;
|
|
12
|
+
activeDot?: Render;
|
|
13
|
+
activeIndex?: number;
|
|
14
|
+
activeShape?: Render | Record<string, unknown>;
|
|
15
|
+
angle?: number;
|
|
16
|
+
animationBegin?: number;
|
|
17
|
+
animationDuration?: number;
|
|
18
|
+
animationEasing?: string;
|
|
19
|
+
aspect?: number;
|
|
20
|
+
axisLine?: boolean | Record<string, unknown>;
|
|
21
|
+
barCategoryGap?: number | string;
|
|
22
|
+
barGap?: number | string;
|
|
23
|
+
barSize?: number | string;
|
|
24
|
+
baseValue?: number | 'dataMin' | 'dataMax';
|
|
25
|
+
background?: Render | Record<string, unknown>;
|
|
26
|
+
children?: OctaneNode;
|
|
27
|
+
className?: string;
|
|
28
|
+
color?: string;
|
|
29
|
+
connectNulls?: boolean;
|
|
30
|
+
content?: Render | Record<string, unknown>;
|
|
31
|
+
cursor?: Render | Record<string, unknown>;
|
|
32
|
+
cx?: number | string;
|
|
33
|
+
cy?: number | string;
|
|
34
|
+
data?: readonly unknown[];
|
|
35
|
+
dataKey?: string | number | ((entry: unknown) => unknown);
|
|
36
|
+
debounce?: number;
|
|
37
|
+
domain?: readonly unknown[];
|
|
38
|
+
dot?: Render | Record<string, unknown>;
|
|
39
|
+
dy?: number | string;
|
|
40
|
+
endAngle?: number;
|
|
41
|
+
fill?: string;
|
|
42
|
+
fillOpacity?: number;
|
|
43
|
+
fontFamily?: string;
|
|
44
|
+
fontSize?: number | string;
|
|
45
|
+
formatter?: (...args: any[]) => OctaneNode;
|
|
46
|
+
height?: number | string;
|
|
47
|
+
hide?: boolean;
|
|
48
|
+
horizontal?: boolean;
|
|
49
|
+
id?: string;
|
|
50
|
+
innerRadius?: number | string;
|
|
51
|
+
interval?: number | string;
|
|
52
|
+
isAnimationActive?: boolean;
|
|
53
|
+
label?: Render | Record<string, unknown>;
|
|
54
|
+
labelLine?: boolean | Record<string, unknown>;
|
|
55
|
+
labelFormatter?: (...args: any[]) => OctaneNode;
|
|
56
|
+
layout?: 'horizontal' | 'vertical' | 'centric' | 'radial';
|
|
57
|
+
legendType?: string;
|
|
58
|
+
line?: boolean | Record<string, unknown>;
|
|
59
|
+
link?: Render | Record<string, unknown>;
|
|
60
|
+
linkCurvature?: number;
|
|
61
|
+
margin?: number | { top?: number; right?: number; bottom?: number; left?: number };
|
|
62
|
+
maxBarSize?: number;
|
|
63
|
+
maxHeight?: number;
|
|
64
|
+
minTickGap?: number;
|
|
65
|
+
minHeight?: number | string;
|
|
66
|
+
minPointSize?: number | ((value: unknown) => number);
|
|
67
|
+
minWidth?: number | string;
|
|
68
|
+
name?: string | number;
|
|
69
|
+
nameKey?: string | number | ((entry: unknown) => unknown);
|
|
70
|
+
node?: Render | Record<string, unknown>;
|
|
71
|
+
nodePadding?: number;
|
|
72
|
+
nodeWidth?: number;
|
|
73
|
+
onAnimationEnd?: Handler;
|
|
74
|
+
onAnimationStart?: Handler;
|
|
75
|
+
onClick?: Handler;
|
|
76
|
+
onMouseEnter?: Handler;
|
|
77
|
+
onMouseLeave?: Handler;
|
|
78
|
+
onResize?: (width: number, height: number) => void;
|
|
79
|
+
orientation?: string;
|
|
80
|
+
outerRadius?: number | string;
|
|
81
|
+
offset?: number;
|
|
82
|
+
paddingAngle?: number;
|
|
83
|
+
padding?: number | { top?: number; right?: number; bottom?: number; left?: number };
|
|
84
|
+
payload?: Record<string, any> | readonly Record<string, any>[];
|
|
85
|
+
position?: string | { x?: number; y?: number };
|
|
86
|
+
radius?: number | readonly number[];
|
|
87
|
+
range?: readonly number[];
|
|
88
|
+
ref?: unknown;
|
|
89
|
+
reversed?: boolean;
|
|
90
|
+
ringPadding?: number;
|
|
91
|
+
scale?: string | ((value: unknown) => unknown);
|
|
92
|
+
shape?: Render | Record<string, unknown>;
|
|
93
|
+
stackId?: string | number;
|
|
94
|
+
stackOffset?: string;
|
|
95
|
+
startAngle?: number;
|
|
96
|
+
stroke?: string;
|
|
97
|
+
strokeDasharray?: string | number;
|
|
98
|
+
strokeOpacity?: number;
|
|
99
|
+
strokeWidth?: number;
|
|
100
|
+
style?: object;
|
|
101
|
+
syncId?: string | number;
|
|
102
|
+
textAnchor?: string;
|
|
103
|
+
textOptions?: Record<string, unknown>;
|
|
104
|
+
tick?: Render | Record<string, unknown>;
|
|
105
|
+
tickCount?: number;
|
|
106
|
+
tickFormatter?: (value: any, index: number) => string;
|
|
107
|
+
tickLine?: boolean | Record<string, unknown>;
|
|
108
|
+
ticks?: readonly unknown[];
|
|
109
|
+
tooltipType?: string;
|
|
110
|
+
type?: string;
|
|
111
|
+
unit?: string | number;
|
|
112
|
+
valueKey?: string | number | ((entry: unknown) => unknown);
|
|
113
|
+
vertical?: boolean;
|
|
114
|
+
verticalAlign?: 'top' | 'middle' | 'bottom';
|
|
115
|
+
iterations?: number;
|
|
116
|
+
width?: number | string;
|
|
117
|
+
xAxisId?: string | number;
|
|
118
|
+
yAxisId?: string | number;
|
|
119
|
+
zAxisId?: string | number;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
type Component<Props> = (props: Props) => OctaneNode;
|
|
123
|
+
type ChartProps = Pick<
|
|
124
|
+
RechartsProps,
|
|
125
|
+
| 'accessibilityLayer'
|
|
126
|
+
| 'barCategoryGap'
|
|
127
|
+
| 'barGap'
|
|
128
|
+
| 'barSize'
|
|
129
|
+
| 'children'
|
|
130
|
+
| 'className'
|
|
131
|
+
| 'cx'
|
|
132
|
+
| 'cy'
|
|
133
|
+
| 'data'
|
|
134
|
+
| 'endAngle'
|
|
135
|
+
| 'height'
|
|
136
|
+
| 'innerRadius'
|
|
137
|
+
| 'layout'
|
|
138
|
+
| 'margin'
|
|
139
|
+
| 'maxBarSize'
|
|
140
|
+
| 'outerRadius'
|
|
141
|
+
| 'stackOffset'
|
|
142
|
+
| 'startAngle'
|
|
143
|
+
| 'style'
|
|
144
|
+
| 'syncId'
|
|
145
|
+
| 'width'
|
|
146
|
+
>;
|
|
147
|
+
|
|
148
|
+
export type AreaProps<DataPointType = unknown, ValueAxisType = unknown> = RechartsProps & {
|
|
149
|
+
data?: readonly DataPointType[];
|
|
150
|
+
baseValue?: number | 'dataMin' | 'dataMax' | ValueAxisType;
|
|
151
|
+
};
|
|
152
|
+
export type BarProps = RechartsProps;
|
|
153
|
+
export type BarShapeProps = Omit<RechartsProps, 'payload'> & {
|
|
154
|
+
payload?: Record<string, any>;
|
|
155
|
+
};
|
|
156
|
+
export type BrushProps = RechartsProps;
|
|
157
|
+
export type CartesianGridProps = RechartsProps;
|
|
158
|
+
export type DotProps = RechartsProps;
|
|
159
|
+
export type FunnelProps = RechartsProps;
|
|
160
|
+
export type LabelListProps = RechartsProps;
|
|
161
|
+
export type LabelProps = RechartsProps;
|
|
162
|
+
export type LegendProps = RechartsProps;
|
|
163
|
+
export type LineProps = RechartsProps;
|
|
164
|
+
export interface PieLabelRenderProps {
|
|
165
|
+
cx: number;
|
|
166
|
+
cy: number;
|
|
167
|
+
x: number;
|
|
168
|
+
y: number;
|
|
169
|
+
midAngle: number;
|
|
170
|
+
innerRadius: number;
|
|
171
|
+
outerRadius: number;
|
|
172
|
+
percent: number;
|
|
173
|
+
value: number;
|
|
174
|
+
name: NameType;
|
|
175
|
+
}
|
|
176
|
+
export type PieLabel = boolean | ((props: PieLabelRenderProps) => OctaneNode);
|
|
177
|
+
export type PieProps<DataPointType = unknown, DataValueType = unknown> = RechartsProps & {
|
|
178
|
+
data?: readonly DataPointType[];
|
|
179
|
+
valueKey?: keyof DataPointType | ((entry: DataPointType) => DataValueType);
|
|
180
|
+
};
|
|
181
|
+
export type PolarAngleAxisProps = RechartsProps;
|
|
182
|
+
export type PolarGridProps = RechartsProps;
|
|
183
|
+
export type PolarRadiusAxisProps = RechartsProps;
|
|
184
|
+
export type RadarProps = RechartsProps;
|
|
185
|
+
export type RadialBarProps = RechartsProps;
|
|
186
|
+
export type ReferenceLineProps = RechartsProps;
|
|
187
|
+
export type ResponsiveContainerProps = RechartsProps;
|
|
188
|
+
export type SankeyProps = RechartsProps;
|
|
189
|
+
export type ScatterProps = RechartsProps;
|
|
190
|
+
export type SunburstChartProps = RechartsProps;
|
|
191
|
+
export type TooltipProps<
|
|
192
|
+
TValue extends ValueType = ValueType,
|
|
193
|
+
TName extends NameType = NameType,
|
|
194
|
+
> = RechartsProps & {
|
|
195
|
+
formatter?: (value: TValue, name: TName, ...rest: any[]) => OctaneNode;
|
|
196
|
+
};
|
|
197
|
+
export type TreemapProps = RechartsProps;
|
|
198
|
+
export type XAxisProps = RechartsProps;
|
|
199
|
+
export type YAxisProps = RechartsProps;
|
|
200
|
+
export type ZAxisProps = RechartsProps;
|
|
201
|
+
|
|
202
|
+
export declare const Area: Component<AreaProps>;
|
|
203
|
+
export declare const AreaChart: Component<ChartProps>;
|
|
204
|
+
export declare const Bar: Component<BarProps>;
|
|
205
|
+
export declare const BarChart: Component<ChartProps>;
|
|
206
|
+
export declare const Brush: Component<BrushProps>;
|
|
207
|
+
export declare const CartesianGrid: Component<CartesianGridProps>;
|
|
208
|
+
export declare const ComposedChart: Component<ChartProps>;
|
|
209
|
+
export declare const Funnel: Component<FunnelProps>;
|
|
210
|
+
export declare const FunnelChart: Component<ChartProps>;
|
|
211
|
+
export declare const Label: Component<LabelProps>;
|
|
212
|
+
export declare const LabelList: Component<LabelListProps>;
|
|
213
|
+
export declare const Legend: Component<LegendProps>;
|
|
214
|
+
export declare const Line: Component<LineProps>;
|
|
215
|
+
export declare const LineChart: Component<ChartProps>;
|
|
216
|
+
export declare const Pie: Component<PieProps>;
|
|
217
|
+
export declare const PieChart: Component<ChartProps>;
|
|
218
|
+
export declare const PolarAngleAxis: Component<PolarAngleAxisProps>;
|
|
219
|
+
export declare const PolarGrid: Component<PolarGridProps>;
|
|
220
|
+
export declare const PolarRadiusAxis: Component<PolarRadiusAxisProps>;
|
|
221
|
+
export declare const Radar: Component<RadarProps>;
|
|
222
|
+
export declare const RadarChart: Component<ChartProps>;
|
|
223
|
+
export declare const RadialBar: Component<RadialBarProps>;
|
|
224
|
+
export declare const RadialBarChart: Component<ChartProps>;
|
|
225
|
+
export declare const Rectangle: Component<BarShapeProps>;
|
|
226
|
+
export declare const ReferenceLine: Component<ReferenceLineProps>;
|
|
227
|
+
export declare const ResponsiveContainer: Component<ResponsiveContainerProps>;
|
|
228
|
+
export declare const Sankey: Component<SankeyProps>;
|
|
229
|
+
export declare const Scatter: Component<ScatterProps>;
|
|
230
|
+
export declare const ScatterChart: Component<ChartProps>;
|
|
231
|
+
export declare const SunburstChart: Component<SunburstChartProps>;
|
|
232
|
+
export declare const Tooltip: Component<TooltipProps>;
|
|
233
|
+
export declare const Treemap: Component<TreemapProps>;
|
|
234
|
+
export declare const XAxis: Component<XAxisProps>;
|
|
235
|
+
export declare const YAxis: Component<YAxisProps>;
|
|
236
|
+
export declare const ZAxis: Component<ZAxisProps>;
|