@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.
Files changed (88) hide show
  1. package/package.json +4 -4
  2. package/src/animation/CSSTransitionAnimate.tsrx +142 -0
  3. package/src/cartesian/Area.tsrx +1096 -0
  4. package/src/cartesian/Area.tsrx.d.ts +340 -0
  5. package/src/cartesian/AreaRevealShape.tsrx +202 -0
  6. package/src/cartesian/CartesianGrid.tsrx +643 -0
  7. package/src/cartesian/CartesianGrid.tsrx.d.ts +219 -0
  8. package/src/cartesian/ErrorBar.tsrx +322 -0
  9. package/src/cartesian/ErrorBar.tsrx.d.ts +131 -0
  10. package/src/cartesian/Funnel.tsrx +833 -0
  11. package/src/cartesian/Funnel.tsrx.d.ts +274 -0
  12. package/src/cartesian/ReferenceLine.tsrx +452 -0
  13. package/src/cartesian/ReferenceLine.tsrx.d.ts +178 -0
  14. package/src/cartesian/Scatter.tsrx +1076 -0
  15. package/src/cartesian/Scatter.tsrx.d.ts +351 -0
  16. package/src/cartesian/ZAxis.tsrx +148 -0
  17. package/src/cartesian/ZAxis.tsrx.d.ts +102 -0
  18. package/src/chart/AreaChart.tsrx +22 -0
  19. package/src/chart/AreaChart.tsrx.d.ts +12 -0
  20. package/src/chart/ComposedChart.tsrx +22 -0
  21. package/src/chart/ComposedChart.tsrx.d.ts +12 -0
  22. package/src/chart/FunnelChart.tsrx +22 -0
  23. package/src/chart/FunnelChart.tsrx.d.ts +12 -0
  24. package/src/chart/PieChart.tsrx +31 -0
  25. package/src/chart/PieChart.tsrx.d.ts +31 -0
  26. package/src/chart/PolarChart.tsrx +121 -0
  27. package/src/chart/RadarChart.tsrx +53 -0
  28. package/src/chart/RadarChart.tsrx.d.ts +31 -0
  29. package/src/chart/RadialBarChart.tsrx +31 -0
  30. package/src/chart/RadialBarChart.tsrx.d.ts +31 -0
  31. package/src/chart/Sankey.tsrx +1542 -0
  32. package/src/chart/Sankey.tsrx.d.ts +253 -0
  33. package/src/chart/ScatterChart.tsrx +22 -0
  34. package/src/chart/ScatterChart.tsrx.d.ts +12 -0
  35. package/src/chart/SunburstChart.tsrx +495 -0
  36. package/src/chart/SunburstChart.tsrx.d.ts +146 -0
  37. package/src/chart/types.ts +19 -0
  38. package/src/component/Cursor.tsrx +157 -0
  39. package/src/component/DefaultLegendContent.tsrx +288 -0
  40. package/src/component/DefaultLegendContent.tsrx.d.ts +125 -0
  41. package/src/component/DefaultTooltipContent.tsrx +215 -0
  42. package/src/component/DefaultTooltipContent.tsrx.d.ts +87 -0
  43. package/src/component/Legend.tsrx +302 -0
  44. package/src/component/Legend.tsrx.d.ts +88 -0
  45. package/src/component/ResponsiveContainer.ts +1 -22
  46. package/src/component/ResponsiveContainer.tsrx +171 -0
  47. package/src/component/ResponsiveContainer.tsrx.d.ts +81 -0
  48. package/src/component/Tooltip.tsrx +425 -0
  49. package/src/component/Tooltip.tsrx.d.ts +246 -0
  50. package/src/component/TooltipBoundingBox.tsrx +135 -0
  51. package/src/context/CellsContext.ts +12 -0
  52. package/src/context/legendPayloadContext.tsrx +11 -0
  53. package/src/context/useTooltipAxis.ts +20 -0
  54. package/src/index.d.ts +236 -0
  55. package/src/index.ts +67 -0
  56. package/src/polar/Pie.tsrx +1224 -0
  57. package/src/polar/Pie.tsrx.d.ts +436 -0
  58. package/src/polar/PolarAngleAxis.tsrx +554 -0
  59. package/src/polar/PolarAngleAxis.tsrx.d.ts +215 -0
  60. package/src/polar/PolarGrid.tsrx +317 -0
  61. package/src/polar/PolarGrid.tsrx.d.ts +117 -0
  62. package/src/polar/PolarRadiusAxis.tsrx +463 -0
  63. package/src/polar/PolarRadiusAxis.tsrx.d.ts +209 -0
  64. package/src/polar/Radar.tsrx +696 -0
  65. package/src/polar/Radar.tsrx.d.ts +215 -0
  66. package/src/polar/RadialBar.tsrx +887 -0
  67. package/src/polar/RadialBar.tsrx.d.ts +340 -0
  68. package/src/state/ReportPolarOptions.tsrx +11 -0
  69. package/src/state/selectors/areaSelectors.ts +257 -0
  70. package/src/state/selectors/funnelSelectors.ts +86 -0
  71. package/src/state/selectors/pieSelectors.ts +134 -0
  72. package/src/state/selectors/polarGridSelectors.ts +43 -0
  73. package/src/state/selectors/polarScaleSelectors.ts +159 -0
  74. package/src/state/selectors/polarSelectors.ts +198 -0
  75. package/src/state/selectors/radarSelectors.ts +228 -0
  76. package/src/state/selectors/radialBarSelectors.ts +511 -0
  77. package/src/state/selectors/scatterSelectors.ts +168 -0
  78. package/src/util/FunnelUtils.tsrx +19 -0
  79. package/src/util/RadialBarUtils.tsrx +29 -0
  80. package/src/util/ScatterUtils.tsrx +34 -0
  81. package/src/util/cursor/getCursorPoints.ts +45 -0
  82. package/src/util/cursor/getCursorRectangle.ts +28 -0
  83. package/src/util/cursor/getRadialCursorPoints.ts +31 -0
  84. package/src/util/payload/getUniqPayload.ts +28 -0
  85. package/src/util/scale/CartesianScaleHelper.ts +71 -0
  86. package/src/util/tooltip/translate.ts +168 -0
  87. package/src/util/types.ts +3 -0
  88. package/src/util/useElementOffset.ts +147 -0
@@ -0,0 +1,495 @@
1
+ import * as React from 'octane';
2
+ import { CSSProperties, useState, type OctaneNode } from 'octane';
3
+ import { scaleLinear } from 'victory-vendor/d3-scale';
4
+ import { clsx } from 'clsx';
5
+ import get from 'es-toolkit/compat/get';
6
+ import { Surface } from '../container/Surface';
7
+ import { Layer } from '../container/Layer';
8
+ import { Sector } from '../shape/Sector';
9
+ import { Text, Props as TextProps } from '../component/Text';
10
+ import { polarToCartesian } from '../util/PolarUtils';
11
+ import {
12
+ ReportChartMargin,
13
+ ReportChartSize,
14
+ useChartHeight,
15
+ useChartWidth,
16
+ } from '../context/chartLayoutContext';
17
+ import { TooltipPortalContext } from '../context/tooltipPortalContext';
18
+ import { RechartsWrapper } from './RechartsWrapper';
19
+ import {
20
+ mouseLeaveItem,
21
+ setActiveClickItemIndex,
22
+ setActiveMouseOverItemIndex,
23
+ TooltipIndex,
24
+ TooltipPayloadConfiguration,
25
+ TooltipPayloadSearcher,
26
+ } from '../state/tooltipSlice';
27
+ import { SetTooltipEntrySettings } from '../state/SetTooltipEntrySettings';
28
+ import { RechartsStoreProvider } from '../state/RechartsStoreProvider';
29
+ import { ReportEventSettings } from '../state/ReportEventSettings';
30
+ import { ChartCoordinate, DataKey, EventThrottlingProps, Margin, Percent } from '../util/types';
31
+ import { useAppDispatch } from '../state/hooks';
32
+ import { RechartsRootState } from '../state/store';
33
+ import { RegisterGraphicalItemId } from '../context/RegisterGraphicalItemId';
34
+ import { WithIdRequired } from '../util/useUniqueId';
35
+ import { RequiresDefaultProps, resolveDefaultProps } from '../util/resolveDefaultProps';
36
+ import { initialEventSettingsState } from '../state/eventSettingsSlice';
37
+
38
+ export interface SunburstData {
39
+ [key: string]: any;
40
+ name: string;
41
+ value?: number;
42
+ fill?: string;
43
+ tooltipIndex?: TooltipIndex;
44
+ children?: SunburstData[];
45
+ }
46
+
47
+ /**
48
+ * We require tooltipIndex on each node internally to track which node is active in the tooltip.
49
+ * This is not required from the outside user - we can calculate it as we traverse the tree.
50
+ */
51
+ interface SunburstNode extends SunburstData {
52
+ tooltipIndex: TooltipIndex;
53
+ }
54
+
55
+ export interface SunburstChartProps extends EventThrottlingProps {
56
+ className?: string;
57
+ /**
58
+ * The source data. Each element should be an object.
59
+ * The properties of each object represent the values of different data dimensions.
60
+ *
61
+ * Use the `dataKey` prop to specify which properties to use.
62
+ *
63
+ * @example data={[{ name: 'a', value: 12, fill: '#8884d8' }, { name: 'b', value: 5, fill: '#83a6ed' }]}
64
+ */
65
+ data: SunburstData;
66
+ /**
67
+ * The width of chart container.
68
+ * Can be a number or a percent string like "100%".
69
+ *
70
+ * @see {@link https://recharts.github.io/en-US/guide/sizes/ Chart sizing guide}
71
+ */
72
+ width?: number | Percent;
73
+ /**
74
+ * The height of chart container.
75
+ * Can be a number or a percent string like "100%".
76
+ *
77
+ * @see {@link https://recharts.github.io/en-US/guide/sizes/ Chart sizing guide}
78
+ */
79
+ height?: number | Percent;
80
+ /**
81
+ * If true, then it will listen to container size changes and adapt the SVG chart accordingly.
82
+ * If false, then it renders the chart at the specified width and height and will stay that way
83
+ * even if the container size changes.
84
+ *
85
+ * This is similar to ResponsiveContainer but without the need for an extra wrapper component.
86
+ * The `responsive` prop also uses standard CSS sizing rules, instead of custom resolution logic (like ResponsiveContainer does).
87
+ * @default false
88
+ */
89
+ responsive?: boolean;
90
+ /**
91
+ * Distance between sectors.
92
+ *
93
+ * @defaultValue 2
94
+ */
95
+ padding?: number;
96
+ /**
97
+ * Decides how to extract value from the data.
98
+ *
99
+ * @defaultValue value
100
+ */
101
+ dataKey?: string;
102
+ /**
103
+ * Name represents each sector in the tooltip.
104
+ * This allows you to extract the name from the data:
105
+ *
106
+ * - `string`: the name of the field in the data object;
107
+ * - `number`: the index of the field in the data;
108
+ * - `function`: a function that receives the data object and returns the name.
109
+ *
110
+ * @defaultValue name
111
+ */
112
+ nameKey?: DataKey<any>;
113
+ /**
114
+ * Padding between each hierarchical level.
115
+ */
116
+ ringPadding?: number;
117
+ /**
118
+ * The radius of the inner circle at the center of the chart.
119
+ *
120
+ * @defaultValue 50
121
+ */
122
+ innerRadius?: number;
123
+ /**
124
+ * Outermost edge of the chart.
125
+ * Defaults to the max possible radius for a circle inscribed in the chart container
126
+ */
127
+ outerRadius?: number;
128
+ /**
129
+ * The x-coordinate of center in pixels.
130
+ * If undefined, it will be set to half of the chart width.
131
+ */
132
+ cx?: number;
133
+ /**
134
+ * The y-coordinate of center in pixels.
135
+ * If undefined, it will be set to half of the chart height.
136
+ */
137
+ cy?: number;
138
+ /** Angle in degrees from which the chart should start. */
139
+ startAngle?: number;
140
+ /** Angle, in degrees, at which the chart should end. */
141
+ endAngle?: number;
142
+ children?: OctaneNode;
143
+ fill?: string;
144
+ stroke?: string;
145
+ /**
146
+ * An object with svg text options to control the appearance of the chart labels.
147
+ */
148
+ textOptions?: TextProps;
149
+ onMouseEnter?: (node: SunburstData, e: React.MouseEvent) => void;
150
+ onMouseLeave?: (node: SunburstData, e: React.MouseEvent) => void;
151
+ onClick?: (node: SunburstData) => void;
152
+ style?: CSSProperties;
153
+ id?: string;
154
+ }
155
+
156
+ interface DrawArcOptions {
157
+ radius: number;
158
+ innerR: number;
159
+ initialAngle: number;
160
+ childColor?: string;
161
+ nestedActiveTooltipIndex?: TooltipIndex | undefined;
162
+ }
163
+
164
+ const defaultTextProps = {
165
+ fontWeight: 'bold',
166
+ paintOrder: 'stroke fill',
167
+ fontSize: '.75rem',
168
+ stroke: '#FFF',
169
+ fill: 'black',
170
+ pointerEvents: 'none',
171
+ };
172
+
173
+ function getMaxDepthOf(node: SunburstData): number {
174
+ if (!node.children || node.children.length === 0) return 1;
175
+
176
+ // Calculate depth for each child and find the maximum
177
+ const childDepths = node.children.map((d) => getMaxDepthOf(d));
178
+ return 1 + Math.max(...childDepths);
179
+ }
180
+
181
+ const SetSunburstTooltipEntrySettings = React.memo(({
182
+ dataKey,
183
+ nameKey,
184
+ data,
185
+ stroke,
186
+ fill,
187
+ positions,
188
+ id,
189
+ }: Pick<
190
+ WithIdRequired<SunburstChartProps>,
191
+ 'dataKey' | 'data' | 'stroke' | 'fill' | 'nameKey' | 'id'
192
+ > & {
193
+ positions: SunburstPositionMap;
194
+ }) => {
195
+ const tooltipEntrySettings: TooltipPayloadConfiguration = {
196
+ dataDefinedOnItem: data.children,
197
+ getPosition: (index) => positions.get(index),
198
+ // Sunburst does not support many of the properties as other charts do so there's plenty of defaults here
199
+ settings: {
200
+ stroke,
201
+ strokeWidth: undefined,
202
+ fill,
203
+ nameKey,
204
+ dataKey,
205
+ // if there is a nameKey use it, otherwise make the name of the tooltip the dataKey itself
206
+ name: nameKey ? undefined : dataKey,
207
+ hide: false,
208
+ type: undefined,
209
+ color: fill,
210
+ unit: '',
211
+ graphicalItemId: id,
212
+ },
213
+ };
214
+ return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings} />;
215
+ });
216
+
217
+ // Why is margin not a sunburst prop? No clue. Probably it should be
218
+ const defaultSunburstMargin: Margin = {
219
+ top: 0,
220
+ right: 0,
221
+ bottom: 0,
222
+ left: 0,
223
+ };
224
+
225
+ export const payloadSearcher: TooltipPayloadSearcher = (
226
+ data: unknown,
227
+ activeIndex: TooltipIndex,
228
+ ): unknown => {
229
+ if (activeIndex == null) {
230
+ return undefined;
231
+ }
232
+ return get(data, activeIndex);
233
+ };
234
+
235
+ const addToSunburstNodeIndex = (
236
+ indexInChildrenArr: number,
237
+ activeTooltipIndexSoFar: TooltipIndex | undefined = '',
238
+ ): TooltipIndex => {
239
+ return `${activeTooltipIndexSoFar}children[${indexInChildrenArr}]`;
240
+ };
241
+
242
+ const preloadedState: Partial<RechartsRootState> = {
243
+ options: {
244
+ validateTooltipEventTypes: ['item'],
245
+ defaultTooltipEventType: 'item',
246
+ chartName: 'Sunburst',
247
+ tooltipPayloadSearcher: payloadSearcher,
248
+ eventEmitter: undefined,
249
+ },
250
+ };
251
+
252
+ type SunburstPositionMap = Map<string, ChartCoordinate>;
253
+
254
+ export const defaultSunburstChartProps = {
255
+ padding: 2,
256
+ dataKey: 'value',
257
+ nameKey: 'name',
258
+ ringPadding: 2,
259
+ innerRadius: 50,
260
+ fill: '#333',
261
+ stroke: '#FFF',
262
+ textOptions: defaultTextProps,
263
+ startAngle: 0,
264
+ endAngle: 360,
265
+ responsive: false,
266
+ ...initialEventSettingsState,
267
+ } as const satisfies Partial<SunburstChartProps>;
268
+
269
+ type InternalSunburstChartProps =
270
+ WithIdRequired<RequiresDefaultProps<SunburstChartProps, typeof defaultSunburstChartProps>>;
271
+
272
+ const SunburstChartImpl = ({
273
+ className,
274
+ data,
275
+ children,
276
+ padding,
277
+ dataKey,
278
+ nameKey,
279
+ ringPadding,
280
+ innerRadius,
281
+ fill,
282
+ stroke,
283
+ textOptions,
284
+ outerRadius: outerRadiusFromProps,
285
+ cx: cxFromProps,
286
+ cy: cyFromProps,
287
+ startAngle,
288
+ endAngle,
289
+ onClick,
290
+ onMouseEnter,
291
+ onMouseLeave,
292
+ id,
293
+ }: InternalSunburstChartProps) => {
294
+ const dispatch = useAppDispatch();
295
+
296
+ const width = useChartWidth();
297
+ const height = useChartHeight();
298
+
299
+ if (width == null || height == null) {
300
+ return null;
301
+ }
302
+
303
+ const outerRadius = outerRadiusFromProps ?? Math.min(width, height) / 2;
304
+ const cx = cxFromProps ?? width / 2;
305
+ const cy = cyFromProps ?? height / 2;
306
+
307
+ const rScale = scaleLinear([0, data[dataKey]], [0, endAngle]);
308
+ const treeDepth = getMaxDepthOf(data);
309
+ const thickness = (outerRadius - innerRadius) / treeDepth;
310
+
311
+ const sectors: OctaneNode[] = [];
312
+ const positions: SunburstPositionMap = new Map<string, ChartCoordinate>([]);
313
+
314
+ // event handlers
315
+ function handleMouseEnter(node: SunburstNode, e: React.MouseEvent) {
316
+ if (onMouseEnter) onMouseEnter(node, e);
317
+
318
+ dispatch(
319
+ setActiveMouseOverItemIndex({
320
+ activeIndex: node.tooltipIndex,
321
+ activeDataKey: dataKey,
322
+ activeCoordinate: positions.get(node.name),
323
+ activeGraphicalItemId: id,
324
+ }),
325
+ );
326
+ }
327
+
328
+ function handleMouseLeave(node: SunburstNode, e: React.MouseEvent) {
329
+ if (onMouseLeave) onMouseLeave(node, e);
330
+
331
+ dispatch(mouseLeaveItem());
332
+ }
333
+
334
+ function handleClick(node: SunburstNode) {
335
+ if (onClick) onClick(node);
336
+
337
+ dispatch(
338
+ setActiveClickItemIndex({
339
+ activeIndex: node.tooltipIndex,
340
+ activeDataKey: dataKey,
341
+ activeCoordinate: positions.get(node.name),
342
+ activeGraphicalItemId: id,
343
+ }),
344
+ );
345
+ }
346
+
347
+ // recursively add nodes for each data point and its children
348
+ function drawArcs(
349
+ childNodes: SunburstData[] | undefined,
350
+ options: DrawArcOptions,
351
+ depth: number = 1,
352
+ ): void {
353
+ const { radius, innerR, initialAngle, childColor, nestedActiveTooltipIndex } = options;
354
+
355
+ let currentAngle = initialAngle;
356
+
357
+ if (!childNodes) return; // base case: no children of this node
358
+
359
+ childNodes.forEach((d, i) => {
360
+ const currentTooltipIndex =
361
+ depth === 1 ? `[${i}]` : addToSunburstNodeIndex(i, nestedActiveTooltipIndex);
362
+ const nodeWithIndex: SunburstNode = { ...d, tooltipIndex: currentTooltipIndex };
363
+
364
+ const arcLength = rScale(d[dataKey]);
365
+ const start = currentAngle;
366
+ // color priority - if there's a color on the individual point use that, otherwise use parent color or default
367
+ const fillColor = d?.fill ?? childColor ?? fill;
368
+ const { x: textX, y: textY } = polarToCartesian(
369
+ 0,
370
+ 0,
371
+ innerR + radius / 2,
372
+ -(start + arcLength - arcLength / 2),
373
+ );
374
+ currentAngle += arcLength;
375
+ sectors.push(
376
+ <g key={`sunburst-sector-${d.name}-${i}`}>
377
+ <Sector
378
+ onClick={() => handleClick(nodeWithIndex)}
379
+ onMouseEnter={(e) => handleMouseEnter(nodeWithIndex, e)}
380
+ onMouseLeave={(e) => handleMouseLeave(nodeWithIndex, e)}
381
+ fill={fillColor}
382
+ stroke={stroke}
383
+ strokeWidth={padding}
384
+ startAngle={start}
385
+ endAngle={start + arcLength}
386
+ innerRadius={innerR}
387
+ outerRadius={innerR + radius}
388
+ cx={cx}
389
+ cy={cy}
390
+ />
391
+ <Text
392
+ {...textOptions}
393
+ alignmentBaseline="middle"
394
+ textAnchor="middle"
395
+ x={textX + cx}
396
+ y={cy - textY}
397
+ >{d[dataKey]}</Text>
398
+ </g>,
399
+ );
400
+
401
+ const { x: tooltipX, y: tooltipY } = polarToCartesian(cx, cy, innerR + radius / 2, start);
402
+ positions.set(d.name, { x: tooltipX, y: tooltipY });
403
+
404
+ return drawArcs(
405
+ d.children,
406
+ {
407
+ radius,
408
+ innerR: innerR + radius + ringPadding,
409
+ initialAngle: start,
410
+ childColor: fillColor,
411
+ nestedActiveTooltipIndex: currentTooltipIndex,
412
+ },
413
+ depth + 1,
414
+ );
415
+ });
416
+ }
417
+
418
+ drawArcs(data.children, { radius: thickness, innerR: innerRadius, initialAngle: startAngle });
419
+
420
+ const layerClass = clsx('recharts-sunburst', className);
421
+ return <Surface width={width} height={height}>
422
+ <Layer className={layerClass}>{sectors}</Layer>
423
+ <SetSunburstTooltipEntrySettings
424
+ dataKey={dataKey}
425
+ nameKey={nameKey}
426
+ data={data}
427
+ stroke={stroke}
428
+ fill={fill}
429
+ positions={positions}
430
+ id={id}
431
+ />
432
+ {children}
433
+ </Surface>;
434
+ };
435
+
436
+ /**
437
+ * The sunburst is a hierarchical chart, similar to a {@link Treemap}, plotted in polar coordinates.
438
+ * Sunburst charts effectively convey the hierarchical relationships and proportions within each level.
439
+ * It is easy to see all the middle layers in the hierarchy, which might get lost in other visualizations.
440
+ * For some datasets, the radial layout may be more visually appealing and intuitive than a traditional {@link Treemap}.
441
+ *
442
+ * @consumes ResponsiveContainerContext
443
+ * @provides TooltipEntrySettings
444
+ */
445
+ export const SunburstChart = (outsideProps: SunburstChartProps) => {
446
+ const props = resolveDefaultProps(outsideProps, defaultSunburstChartProps);
447
+ const {
448
+ className,
449
+ width,
450
+ height,
451
+ responsive,
452
+ style,
453
+ id: externalId,
454
+ throttleDelay,
455
+ throttledEvents,
456
+ } = props;
457
+ const [tooltipPortal, setTooltipPortal] = useState<HTMLElement | null>(null);
458
+ return <RechartsStoreProvider
459
+ preloadedState={preloadedState}
460
+ reduxStoreName={className ?? 'SunburstChart'}
461
+ >
462
+ <ReportChartSize width={width} height={height} />
463
+ <ReportChartMargin margin={defaultSunburstMargin} />
464
+ <ReportEventSettings throttleDelay={throttleDelay} throttledEvents={throttledEvents} />
465
+ <TooltipPortalContext.Provider value={tooltipPortal}>
466
+ <RechartsWrapper
467
+ className={className}
468
+ width={width}
469
+ height={height}
470
+ responsive={responsive}
471
+ style={style}
472
+ ref={(node: HTMLDivElement) => {
473
+ if (tooltipPortal == null && node != null) {
474
+ setTooltipPortal(node);
475
+ }
476
+ }}
477
+ onMouseEnter={undefined}
478
+ onMouseLeave={undefined}
479
+ onClick={undefined}
480
+ onMouseMove={undefined}
481
+ onMouseDown={undefined}
482
+ onMouseUp={undefined}
483
+ onContextMenu={undefined}
484
+ onDoubleClick={undefined}
485
+ onTouchStart={undefined}
486
+ onTouchMove={undefined}
487
+ onTouchEnd={undefined}
488
+ >
489
+ <RegisterGraphicalItemId id={externalId} type="sunburst">
490
+ {(id) => <SunburstChartImpl {...props} id={id} />}
491
+ </RegisterGraphicalItemId>
492
+ </RechartsWrapper>
493
+ </TooltipPortalContext.Provider>
494
+ </RechartsStoreProvider>;
495
+ };
@@ -0,0 +1,146 @@
1
+ import * as React from 'octane';
2
+ import { CSSProperties } from 'octane';
3
+ import { Props as TextProps } from '../component/Text';
4
+ import { TooltipIndex, TooltipPayloadSearcher } from '../state/tooltipSlice';
5
+ import { DataKey, EventThrottlingProps, Percent } from '../util/types';
6
+ export interface SunburstData {
7
+ [key: string]: any;
8
+ name: string;
9
+ value?: number;
10
+ fill?: string;
11
+ tooltipIndex?: TooltipIndex;
12
+ children?: SunburstData[];
13
+ }
14
+ export interface SunburstChartProps extends EventThrottlingProps {
15
+ className?: string;
16
+ /**
17
+ * The source data. Each element should be an object.
18
+ * The properties of each object represent the values of different data dimensions.
19
+ *
20
+ * Use the `dataKey` prop to specify which properties to use.
21
+ *
22
+ * @example data={[{ name: 'a', value: 12, fill: '#8884d8' }, { name: 'b', value: 5, fill: '#83a6ed' }]}
23
+ */
24
+ data: SunburstData;
25
+ /**
26
+ * The width of chart container.
27
+ * Can be a number or a percent string like "100%".
28
+ *
29
+ * @see {@link https://recharts.github.io/en-US/guide/sizes/ Chart sizing guide}
30
+ */
31
+ width?: number | Percent;
32
+ /**
33
+ * The height of chart container.
34
+ * Can be a number or a percent string like "100%".
35
+ *
36
+ * @see {@link https://recharts.github.io/en-US/guide/sizes/ Chart sizing guide}
37
+ */
38
+ height?: number | Percent;
39
+ /**
40
+ * If true, then it will listen to container size changes and adapt the SVG chart accordingly.
41
+ * If false, then it renders the chart at the specified width and height and will stay that way
42
+ * even if the container size changes.
43
+ *
44
+ * This is similar to ResponsiveContainer but without the need for an extra wrapper component.
45
+ * The `responsive` prop also uses standard CSS sizing rules, instead of custom resolution logic (like ResponsiveContainer does).
46
+ * @default false
47
+ */
48
+ responsive?: boolean;
49
+ /**
50
+ * Distance between sectors.
51
+ *
52
+ * @defaultValue 2
53
+ */
54
+ padding?: number;
55
+ /**
56
+ * Decides how to extract value from the data.
57
+ *
58
+ * @defaultValue value
59
+ */
60
+ dataKey?: string;
61
+ /**
62
+ * Name represents each sector in the tooltip.
63
+ * This allows you to extract the name from the data:
64
+ *
65
+ * - `string`: the name of the field in the data object;
66
+ * - `number`: the index of the field in the data;
67
+ * - `function`: a function that receives the data object and returns the name.
68
+ *
69
+ * @defaultValue name
70
+ */
71
+ nameKey?: DataKey<any>;
72
+ /**
73
+ * Padding between each hierarchical level.
74
+ */
75
+ ringPadding?: number;
76
+ /**
77
+ * The radius of the inner circle at the center of the chart.
78
+ *
79
+ * @defaultValue 50
80
+ */
81
+ innerRadius?: number;
82
+ /**
83
+ * Outermost edge of the chart.
84
+ * Defaults to the max possible radius for a circle inscribed in the chart container
85
+ */
86
+ outerRadius?: number;
87
+ /**
88
+ * The x-coordinate of center in pixels.
89
+ * If undefined, it will be set to half of the chart width.
90
+ */
91
+ cx?: number;
92
+ /**
93
+ * The y-coordinate of center in pixels.
94
+ * If undefined, it will be set to half of the chart height.
95
+ */
96
+ cy?: number;
97
+ /** Angle in degrees from which the chart should start. */
98
+ startAngle?: number;
99
+ /** Angle, in degrees, at which the chart should end. */
100
+ endAngle?: number;
101
+ children?: React.ReactNode;
102
+ fill?: string;
103
+ stroke?: string;
104
+ /**
105
+ * An object with svg text options to control the appearance of the chart labels.
106
+ */
107
+ textOptions?: TextProps;
108
+ onMouseEnter?: (node: SunburstData, e: React.MouseEvent) => void;
109
+ onMouseLeave?: (node: SunburstData, e: React.MouseEvent) => void;
110
+ onClick?: (node: SunburstData) => void;
111
+ style?: CSSProperties;
112
+ id?: string;
113
+ }
114
+ export declare const payloadSearcher: TooltipPayloadSearcher;
115
+ export declare const defaultSunburstChartProps: {
116
+ readonly throttleDelay: number | 'raf';
117
+ readonly throttledEvents: ReadonlyArray<keyof GlobalEventHandlersEventMap> | 'all';
118
+ readonly padding: 2;
119
+ readonly dataKey: 'value';
120
+ readonly nameKey: 'name';
121
+ readonly ringPadding: 2;
122
+ readonly innerRadius: 50;
123
+ readonly fill: '#333';
124
+ readonly stroke: '#FFF';
125
+ readonly textOptions: {
126
+ fontWeight: string;
127
+ paintOrder: string;
128
+ fontSize: string;
129
+ stroke: string;
130
+ fill: string;
131
+ pointerEvents: string;
132
+ };
133
+ readonly startAngle: 0;
134
+ readonly endAngle: 360;
135
+ readonly responsive: false;
136
+ };
137
+ /**
138
+ * The sunburst is a hierarchical chart, similar to a {@link Treemap}, plotted in polar coordinates.
139
+ * Sunburst charts effectively convey the hierarchical relationships and proportions within each level.
140
+ * It is easy to see all the middle layers in the hierarchy, which might get lost in other visualizations.
141
+ * For some datasets, the radial layout may be more visually appealing and intuitive than a traditional {@link Treemap}.
142
+ *
143
+ * @consumes ResponsiveContainerContext
144
+ * @provides TooltipEntrySettings
145
+ */
146
+ export declare const SunburstChart: (outsideProps: SunburstChartProps) => React.JSX.Element;
@@ -0,0 +1,19 @@
1
+ // @ts-nocheck -- compatibility-only upstream type surface is not part of the initial runtime port.
2
+ import type { MouseHandlerDataParam } from '../synchronisation/types';
3
+
4
+ export type TooltipTrigger = 'hover' | 'click';
5
+ export type CategoricalChartFunc<E = Event> = (nextState: MouseHandlerDataParam, event: E) => void;
6
+
7
+ export interface ExternalMouseEvents {
8
+ onClick?: CategoricalChartFunc<MouseEvent>;
9
+ onMouseLeave?: CategoricalChartFunc<MouseEvent>;
10
+ onMouseEnter?: CategoricalChartFunc<MouseEvent>;
11
+ onMouseMove?: CategoricalChartFunc<MouseEvent>;
12
+ onMouseDown?: CategoricalChartFunc<MouseEvent>;
13
+ onMouseUp?: CategoricalChartFunc<MouseEvent>;
14
+ onContextMenu?: CategoricalChartFunc<MouseEvent>;
15
+ onDoubleClick?: CategoricalChartFunc<MouseEvent>;
16
+ onTouchStart?: CategoricalChartFunc<TouchEvent>;
17
+ onTouchMove?: CategoricalChartFunc<TouchEvent>;
18
+ onTouchEnd?: CategoricalChartFunc<TouchEvent>;
19
+ }