@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.
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
@@ -94,8 +94,9 @@ import { CellsContext, useCellRegistry } from '../context/CellsContext';
94
94
 
95
95
  const STABLE_EMPTY_ARRAY: readonly RadialBarDataItem[] = [];
96
96
 
97
- export type RadialBarDataItem =
98
- SectorProps & GeometrySector & TooltipTriggerInfo & {
97
+ export type RadialBarDataItem = SectorProps &
98
+ GeometrySector &
99
+ TooltipTriggerInfo & {
99
100
  value?: any;
100
101
  payload?: any;
101
102
  background?: SectorProps;
@@ -103,12 +104,11 @@ export type RadialBarDataItem =
103
104
 
104
105
  type RadialBarBackground = boolean | (ActiveShape<SectorProps> & ZIndexable);
105
106
 
106
- type RadialBarSectorsProps =
107
- ShapeAnimationProps & {
108
- sectors: ReadonlyArray<RadialBarDataItem>;
109
- allOtherRadialBarProps: InternalProps;
110
- showLabels: boolean;
111
- };
107
+ type RadialBarSectorsProps = ShapeAnimationProps & {
108
+ sectors: ReadonlyArray<RadialBarDataItem>;
109
+ allOtherRadialBarProps: InternalProps;
110
+ showLabels: boolean;
111
+ };
112
112
 
113
113
  function RadialBarLabelListProvider({
114
114
  showLabels,
@@ -138,9 +138,11 @@ function RadialBarLabelListProvider({
138
138
  }),
139
139
  );
140
140
 
141
- return <PolarLabelListContextProvider
142
- value={showLabels ? labelListEntries : undefined}
143
- >{children}</PolarLabelListContextProvider>;
141
+ return (
142
+ <PolarLabelListContextProvider value={showLabels ? labelListEntries : undefined}>
143
+ {children}
144
+ </PolarLabelListContextProvider>
145
+ );
144
146
  }
145
147
 
146
148
  function RadialBarSectors({
@@ -178,49 +180,55 @@ function RadialBarSectors({
178
180
  return null;
179
181
  }
180
182
 
181
- return <RadialBarLabelListProvider showLabels={showLabels} sectors={sectors}>
182
- {sectors.map((entry: RadialBarDataItem, i: number) => {
183
- const isActive: boolean = Boolean(activeShape && activeIndex === String(i));
184
- const onMouseEnter = onMouseEnterFromContext(entry, i);
185
- const onMouseLeave = onMouseLeaveFromContext(entry, i);
186
- const onClick = onClickFromContext(entry, i);
187
-
188
- const radialBarSectorProps: ComponentProps<typeof RadialBarSector> = {
189
- ...baseProps,
190
- cornerRadius: parseCornerRadius(cornerRadius),
191
- ...entry,
192
- ...adaptEventsOfChild(restOfAllOtherProps, entry, i),
193
- onMouseEnter,
194
- onMouseLeave,
195
- onClick,
196
- className: `recharts-radial-bar-sector ${entry.className}`,
197
- forceCornerRadius: others.forceCornerRadius,
198
- cornerIsExternal: others.cornerIsExternal,
199
- animationElapsedTime,
200
- isAnimating,
201
- isEntrance,
202
- isActive,
203
- option: isActive && activeShape != null ? activeShape : shape,
204
- index: i,
205
- };
206
-
207
- if (isActive) {
208
- return <ZIndexLayer
209
- zIndex={DefaultZIndexes.activeBar}
210
- key={`sector-${entry.cx}-${entry.cy}-${entry.innerRadius}-${entry.outerRadius}-${entry.startAngle}-${entry.endAngle}-${i}`}
211
- >
212
- <RadialBarSector {...radialBarSectorProps} />
213
- </ZIndexLayer>;
214
- }
183
+ return (
184
+ <RadialBarLabelListProvider showLabels={showLabels} sectors={sectors}>
185
+ {sectors.map((entry: RadialBarDataItem, i: number) => {
186
+ const isActive: boolean = Boolean(activeShape && activeIndex === String(i));
187
+ const onMouseEnter = onMouseEnterFromContext(entry, i);
188
+ const onMouseLeave = onMouseLeaveFromContext(entry, i);
189
+ const onClick = onClickFromContext(entry, i);
190
+
191
+ const radialBarSectorProps: ComponentProps<typeof RadialBarSector> = {
192
+ ...baseProps,
193
+ cornerRadius: parseCornerRadius(cornerRadius),
194
+ ...entry,
195
+ ...adaptEventsOfChild(restOfAllOtherProps, entry, i),
196
+ onMouseEnter,
197
+ onMouseLeave,
198
+ onClick,
199
+ className: `recharts-radial-bar-sector ${entry.className}`,
200
+ forceCornerRadius: others.forceCornerRadius,
201
+ cornerIsExternal: others.cornerIsExternal,
202
+ animationElapsedTime,
203
+ isAnimating,
204
+ isEntrance,
205
+ isActive,
206
+ option: isActive && activeShape != null ? activeShape : shape,
207
+ index: i,
208
+ };
209
+
210
+ if (isActive) {
211
+ return (
212
+ <ZIndexLayer
213
+ zIndex={DefaultZIndexes.activeBar}
214
+ key={`sector-${entry.cx}-${entry.cy}-${entry.innerRadius}-${entry.outerRadius}-${entry.startAngle}-${entry.endAngle}-${i}`}
215
+ >
216
+ <RadialBarSector {...radialBarSectorProps} />
217
+ </ZIndexLayer>
218
+ );
219
+ }
215
220
 
216
- return <RadialBarSector
217
- key={`sector-${entry.cx}-${entry.cy}-${entry.innerRadius}-${entry.outerRadius}-${entry.startAngle}-${entry.endAngle}-${i}`}
218
- {...radialBarSectorProps}
219
- />;
220
- })}
221
- <LabelListFromLabelProp label={allOtherRadialBarProps.label} />
222
- {allOtherRadialBarProps.children}
223
- </RadialBarLabelListProvider>;
221
+ return (
222
+ <RadialBarSector
223
+ key={`sector-${entry.cx}-${entry.cy}-${entry.innerRadius}-${entry.outerRadius}-${entry.startAngle}-${entry.endAngle}-${i}`}
224
+ {...radialBarSectorProps}
225
+ />
226
+ );
227
+ })}
228
+ <LabelListFromLabelProp label={allOtherRadialBarProps.label} />
229
+ {allOtherRadialBarProps.children}
230
+ </RadialBarLabelListProvider>
231
+ );
224
232
  }
225
233
 
226
234
  const defaultRadialBarAnimateItems: AnimationInterpolateFn<RadialBarDataItem, PolarLayout> = (
@@ -269,16 +277,14 @@ function SectorsWithAnimation({
269
277
  onAnimationEnd,
270
278
  } = props;
271
279
  const animationInput = JSON.stringify(
272
- sectors.map(
273
- ({ cx, cy, innerRadius, outerRadius, startAngle, endAngle }) => [
274
- cx,
275
- cy,
276
- innerRadius,
277
- outerRadius,
278
- startAngle,
279
- endAngle,
280
- ],
281
- ),
280
+ sectors.map(({ cx, cy, innerRadius, outerRadius, startAngle, endAngle }) => [
281
+ cx,
282
+ cy,
283
+ innerRadius,
284
+ outerRadius,
285
+ startAngle,
286
+ endAngle,
287
+ ]),
282
288
  );
283
289
 
284
290
  const { isAnimating, handleAnimationStart, handleAnimationEnd } = useAnimationCallbacks(
@@ -290,31 +296,34 @@ function SectorsWithAnimation({
290
296
 
291
297
  if (layout == null) return null;
292
298
 
293
- return <AnimatedItems
294
- animationInput={animationInput}
295
- animationIdPrefix="recharts-radialbar-"
296
- items={sectors}
297
- previousItemsRef={previousSectorsRef}
298
- isAnimationActive={isAnimationActive}
299
- animationBegin={animationBegin}
300
- animationDuration={animationDuration}
301
- animationEasing={animationEasing}
302
- onAnimationStart={handleAnimationStart}
303
- onAnimationEnd={handleAnimationEnd}
304
- animationInterpolateFn={props.animationInterpolateFn}
305
- animationMatchBy={props.animationMatchBy}
306
- layout={layout}
307
- >
308
- {(stepData, animationElapsedTime, isEntrance) =>
309
- <RadialBarSectors
310
- sectors={stepData}
311
- allOtherRadialBarProps={props}
312
- showLabels={!isAnimating}
313
- animationElapsedTime={animationElapsedTime}
314
- isAnimating={isAnimating || animationElapsedTime < 1}
315
- isEntrance={isEntrance}
316
- />}
317
- </AnimatedItems>;
299
+ return (
300
+ <AnimatedItems
301
+ animationInput={animationInput}
302
+ animationIdPrefix="recharts-radialbar-"
303
+ items={sectors}
304
+ previousItemsRef={previousSectorsRef}
305
+ isAnimationActive={isAnimationActive}
306
+ animationBegin={animationBegin}
307
+ animationDuration={animationDuration}
308
+ animationEasing={animationEasing}
309
+ onAnimationStart={handleAnimationStart}
310
+ onAnimationEnd={handleAnimationEnd}
311
+ animationInterpolateFn={props.animationInterpolateFn}
312
+ animationMatchBy={props.animationMatchBy}
313
+ layout={layout}
314
+ >
315
+ {(stepData, animationElapsedTime, isEntrance) => (
316
+ <RadialBarSectors
317
+ sectors={stepData}
318
+ allOtherRadialBarProps={props}
319
+ showLabels={!isAnimating}
320
+ animationElapsedTime={animationElapsedTime}
321
+ isAnimating={isAnimating || animationElapsedTime < 1}
322
+ isEntrance={isEntrance}
323
+ />
324
+ )}
325
+ </AnimatedItems>
326
+ );
318
327
  }
319
328
 
320
329
  function RenderSectors(props: InternalProps) {
@@ -323,271 +332,293 @@ function RenderSectors(props: InternalProps) {
323
332
  return <SectorsWithAnimation props={props} previousSectorsRef={previousSectorsRef} />;
324
333
  }
325
334
 
326
- interface InternalRadialBarProps<DataPointType = any, DataValueType = any> extends DataConsumer<
327
- DataPointType,
328
- DataValueType
329
- >, ZIndexable {
335
+ interface InternalRadialBarProps<DataPointType = any, DataValueType = any>
336
+ extends DataConsumer<DataPointType, DataValueType>, ZIndexable {
330
337
  activeShape?: ActiveShape<RadialBarSectorProps, SVGPathElement>;
331
338
  /**
332
- * @defaultValue 0
333
- */
339
+ * @defaultValue 0
340
+ */
334
341
  angleAxisId?: AxisId;
335
342
  /**
336
- * Specifies when the animation should begin, the unit of this option is ms.
337
- * @defaultValue 0
338
- */
343
+ * Specifies when the animation should begin, the unit of this option is ms.
344
+ * @defaultValue 0
345
+ */
339
346
  animationBegin?: number;
340
347
  /**
341
- * Specifies the duration of animation, the unit of this option is ms.
342
- * @defaultValue 1500
343
- */
348
+ * Specifies the duration of animation, the unit of this option is ms.
349
+ * @defaultValue 1500
350
+ */
344
351
  animationDuration?: AnimationDuration;
345
352
  /**
346
- * The type of easing function.
347
- * @defaultValue ease
348
- */
353
+ * The type of easing function.
354
+ * @defaultValue ease
355
+ */
349
356
  animationEasing?: EasingInput;
350
357
  /**
351
- * Custom animation function for interpolating data items.
352
- * When provided, this replaces the default animation interpolation.
353
- *
354
- * @param prevItems The items from the previous animation frame, or null on first render
355
- * @param nextItems The target items to animate towards
356
- * @param animationElapsedTime A normalized time value (0 = start, 1 = end)
357
- * @returns The interpolated items at time animationElapsedTime
358
- *
359
- * @since 3.9
360
- * @see {@link https://recharts.github.io/en-US/guide/animations/ Animations guide}
361
- */
358
+ * Custom animation function for interpolating data items.
359
+ * When provided, this replaces the default animation interpolation.
360
+ *
361
+ * @param prevItems The items from the previous animation frame, or null on first render
362
+ * @param nextItems The target items to animate towards
363
+ * @param animationElapsedTime A normalized time value (0 = start, 1 = end)
364
+ * @returns The interpolated items at time animationElapsedTime
365
+ *
366
+ * @since 3.9
367
+ * @see {@link https://recharts.github.io/en-US/guide/animations/ Animations guide}
368
+ */
362
369
  animationInterpolateFn?: AnimationInterpolateFn<RadialBarDataItem, PolarLayout>;
363
370
  /**
364
- * Strategy for matching previous items to next items during animation.
365
- * Determines how Recharts pairs old data points with new data points
366
- * to create smooth transitions.
367
- *
368
- * - `matchAppend` (default): match sequentially by index and treat newly appended items as new
369
- * - `matchByIndex`: match by array position with proportional stretching
370
- * - `matchByDataKey('someKey')`: match by a data key from the payload
371
- * - Custom function `(item, index) => key`: match by the returned key
372
- *
373
- * @defaultValue append
374
- * @see matchByIndex
375
- * @see matchByDataKey
376
- * @see matchAppend
377
- */
371
+ * Strategy for matching previous items to next items during animation.
372
+ * Determines how Recharts pairs old data points with new data points
373
+ * to create smooth transitions.
374
+ *
375
+ * - `matchAppend` (default): match sequentially by index and treat newly appended items as new
376
+ * - `matchByIndex`: match by array position with proportional stretching
377
+ * - `matchByDataKey('someKey')`: match by a data key from the payload
378
+ * - Custom function `(item, index) => key`: match by the returned key
379
+ *
380
+ * @defaultValue append
381
+ * @see matchByIndex
382
+ * @see matchByDataKey
383
+ * @see matchAppend
384
+ */
378
385
  animationMatchBy?: AnimationMatchByProp<RadialBarDataItem>;
379
386
  /**
380
- * Renders a background for each bar. Options:
381
- * - `false`: no background;
382
- * - `true`: renders default background;
383
- * - `object`: the props of background rectangle;
384
- * - `OctaneElement`: a custom background element;
385
- * - `function`: a render function of custom background.
386
- *
387
- * @defaultValue false
388
- */
387
+ * Renders a background for each bar. Options:
388
+ * - `false`: no background;
389
+ * - `true`: renders default background;
390
+ * - `object`: the props of background rectangle;
391
+ * - `OctaneElement`: a custom background element;
392
+ * - `function`: a render function of custom background.
393
+ *
394
+ * @defaultValue false
395
+ */
389
396
  background?: RadialBarBackground;
390
397
  /**
391
- * The width or height of each bar. If the barSize is not specified, the size of the bar will be calculated by the barCategoryGap, barGap and the quantity of bar groups.
392
- */
398
+ * The width or height of each bar. If the barSize is not specified, the size of the bar will be calculated by the barCategoryGap, barGap and the quantity of bar groups.
399
+ */
393
400
  barSize?: number;
394
401
  className?: string;
395
402
  /**
396
- * @defaultValue false
397
- */
403
+ * @defaultValue false
404
+ */
398
405
  cornerIsExternal?: boolean;
399
406
  /**
400
- * @defaultValue 0
401
- */
407
+ * @defaultValue 0
408
+ */
402
409
  cornerRadius?: string | number;
403
410
  /**
404
- * Calculated radial bar sectors
405
- */
411
+ * Calculated radial bar sectors
412
+ */
406
413
  sectors: ReadonlyArray<RadialBarDataItem>;
407
414
  /**
408
- * @defaultValue false
409
- */
415
+ * @defaultValue false
416
+ */
410
417
  forceCornerRadius?: boolean;
411
418
  /**
412
- * @defaultValue false
413
- */
419
+ * @defaultValue false
420
+ */
414
421
  hide?: boolean;
415
422
  /**
416
- * If set false, animation of radial bars will be disabled.
417
- * If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
418
- * @defaultValue auto
419
- */
423
+ * If set false, animation of radial bars will be disabled.
424
+ * If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
425
+ * @defaultValue auto
426
+ */
420
427
  isAnimationActive?: boolean | 'auto';
421
428
  /**
422
- * Renders one label for each data point. Options:
423
- * - `true`: renders default labels;
424
- * - `false`: no labels are rendered;
425
- * - `object`: the props of LabelList component;
426
- * - `OctaneElement`: a custom SVG label element, such as `<text>` or `<g>`.
427
- * HTML elements such as `<div>` are not valid inside the chart SVG and may trigger React DOM warnings.
428
- * - `function`: a render function of custom label.
429
- *
430
- * @defaultValue false
431
- */
429
+ * Renders one label for each data point. Options:
430
+ * - `true`: renders default labels;
431
+ * - `false`: no labels are rendered;
432
+ * - `object`: the props of LabelList component;
433
+ * - `OctaneElement`: a custom SVG label element, such as `<text>` or `<g>`.
434
+ * HTML elements such as `<div>` are not valid inside the chart SVG and may trigger React DOM warnings.
435
+ * - `function`: a render function of custom label.
436
+ *
437
+ * @defaultValue false
438
+ */
432
439
  label?: ImplicitLabelListType;
433
440
  /**
434
- * The type of icon in legend. If set to 'none', no legend item will be rendered.
435
- * @defaultValue rect
436
- */
441
+ * The type of icon in legend. If set to 'none', no legend item will be rendered.
442
+ * @defaultValue rect
443
+ */
437
444
  legendType?: LegendType;
438
445
  maxBarSize?: number;
439
446
  /**
440
- * @defaultValue 0
441
- */
447
+ * @defaultValue 0
448
+ */
442
449
  minPointSize?: number;
443
450
  /**
444
- * The customized event handler of animation end
445
- */
451
+ * The customized event handler of animation end
452
+ */
446
453
  onAnimationEnd?: () => void;
447
454
  /**
448
- * The customized event handler of animation start
449
- */
455
+ * The customized event handler of animation start
456
+ */
450
457
  onAnimationStart?: () => void;
451
458
  /**
452
- * The customized event handler of click in this chart.
453
- */
454
- onClick?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
455
- SVGGraphicsElement
456
- >) => void;
459
+ * The customized event handler of click in this chart.
460
+ */
461
+ onClick?: (
462
+ data: RadialBarDataItem,
463
+ index: number,
464
+ e: NativeMouseEvent<SVGGraphicsElement>,
465
+ ) => void;
457
466
  /**
458
- * The customized event handler of mousedown in this chart.
459
- */
460
- onMouseDown?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
461
- SVGGraphicsElement
462
- >) => void;
467
+ * The customized event handler of mousedown in this chart.
468
+ */
469
+ onMouseDown?: (
470
+ data: RadialBarDataItem,
471
+ index: number,
472
+ e: NativeMouseEvent<SVGGraphicsElement>,
473
+ ) => void;
463
474
  /**
464
- * The customized event handler of mouseup in this chart.
465
- */
466
- onMouseUp?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
467
- SVGGraphicsElement
468
- >) => void;
475
+ * The customized event handler of mouseup in this chart.
476
+ */
477
+ onMouseUp?: (
478
+ data: RadialBarDataItem,
479
+ index: number,
480
+ e: NativeMouseEvent<SVGGraphicsElement>,
481
+ ) => void;
469
482
  /**
470
- * The customized event handler of mousemove in this chart.
471
- */
472
- onMouseMove?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
473
- SVGGraphicsElement
474
- >) => void;
483
+ * The customized event handler of mousemove in this chart.
484
+ */
485
+ onMouseMove?: (
486
+ data: RadialBarDataItem,
487
+ index: number,
488
+ e: NativeMouseEvent<SVGGraphicsElement>,
489
+ ) => void;
475
490
  /**
476
- * The customized event handler of mouseover in this chart.
477
- */
478
- onMouseOver?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
479
- SVGGraphicsElement
480
- >) => void;
491
+ * The customized event handler of mouseover in this chart.
492
+ */
493
+ onMouseOver?: (
494
+ data: RadialBarDataItem,
495
+ index: number,
496
+ e: NativeMouseEvent<SVGGraphicsElement>,
497
+ ) => void;
481
498
  /**
482
- * The customized event handler of mouseout in this chart.
483
- */
484
- onMouseOut?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
485
- SVGGraphicsElement
486
- >) => void;
499
+ * The customized event handler of mouseout in this chart.
500
+ */
501
+ onMouseOut?: (
502
+ data: RadialBarDataItem,
503
+ index: number,
504
+ e: NativeMouseEvent<SVGGraphicsElement>,
505
+ ) => void;
487
506
  /**
488
- * The customized event handler of mouseenter in this chart.
489
- */
490
- onMouseEnter?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
491
- SVGGraphicsElement
492
- >) => void;
507
+ * The customized event handler of mouseenter in this chart.
508
+ */
509
+ onMouseEnter?: (
510
+ data: RadialBarDataItem,
511
+ index: number,
512
+ e: NativeMouseEvent<SVGGraphicsElement>,
513
+ ) => void;
493
514
  /**
494
- * The customized event handler of mouseleave in this chart.
495
- */
496
- onMouseLeave?: (data: RadialBarDataItem, index: number, e: NativeMouseEvent<
497
- SVGGraphicsElement
498
- >) => void;
499
- onTouchStart?: (data: RadialBarDataItem, index: number, e: NativeTouchEvent<
500
- SVGGraphicsElement
501
- >) => void;
502
- onTouchMove?: (data: RadialBarDataItem, index: number, e: NativeTouchEvent<
503
- SVGGraphicsElement
504
- >) => void;
505
- onTouchEnd?: (data: RadialBarDataItem, index: number, e: NativeTouchEvent<
506
- SVGGraphicsElement
507
- >) => void;
515
+ * The customized event handler of mouseleave in this chart.
516
+ */
517
+ onMouseLeave?: (
518
+ data: RadialBarDataItem,
519
+ index: number,
520
+ e: NativeMouseEvent<SVGGraphicsElement>,
521
+ ) => void;
522
+ onTouchStart?: (
523
+ data: RadialBarDataItem,
524
+ index: number,
525
+ e: NativeTouchEvent<SVGGraphicsElement>,
526
+ ) => void;
527
+ onTouchMove?: (
528
+ data: RadialBarDataItem,
529
+ index: number,
530
+ e: NativeTouchEvent<SVGGraphicsElement>,
531
+ ) => void;
532
+ onTouchEnd?: (
533
+ data: RadialBarDataItem,
534
+ index: number,
535
+ e: NativeTouchEvent<SVGGraphicsElement>,
536
+ ) => void;
508
537
  /**
509
- * @defaultValue 0
510
- */
538
+ * @defaultValue 0
539
+ */
511
540
  radiusAxisId?: AxisId;
512
541
  /**
513
- * If set a OctaneElement, the shape of radial bar sectors can be customized.
514
- * If set a function, the function will be called to render customized shape.
515
- * During animations, the function shape also receives `animationElapsedTime`, `isAnimating`, and `isEntrance`.
516
- * By default, renders a sector.
517
- */
542
+ * If set a OctaneElement, the shape of radial bar sectors can be customized.
543
+ * If set a function, the function will be called to render customized shape.
544
+ * During animations, the function shape also receives `animationElapsedTime`, `isAnimating`, and `isEntrance`.
545
+ * By default, renders a sector.
546
+ */
518
547
  shape?: ActiveShape<RadialBarSectorProps, SVGPathElement>;
519
548
  stackId?: string | number;
520
549
  tooltipType?: TooltipType;
521
550
  /**
522
- * Formats the value displayed in the tooltip for this RadialBar.
523
- * When set, takes precedence over the `formatter` prop on the Tooltip component.
524
- */
551
+ * Formats the value displayed in the tooltip for this RadialBar.
552
+ * When set, takes precedence over the `formatter` prop on the Tooltip component.
553
+ */
525
554
  formatter?: Formatter;
526
555
  /**
527
- * @defaultValue 300
528
- */
556
+ * @defaultValue 300
557
+ */
529
558
  zIndex?: number;
530
559
  }
531
560
 
532
- export type RadialBarProps<DataPointType = any, DataValueType = any> =
533
- Omit<
534
- PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement>,
535
- 'ref' | keyof InternalRadialBarProps<DataPointType, DataValueType>
536
- > & Omit<InternalRadialBarProps<DataPointType, DataValueType>, 'sectors'>;
561
+ export type RadialBarProps<DataPointType = any, DataValueType = any> = Omit<
562
+ PresentationAttributesAdaptChildEvent<RadialBarDataItem, SVGElement>,
563
+ 'ref' | keyof InternalRadialBarProps<DataPointType, DataValueType>
564
+ > &
565
+ Omit<InternalRadialBarProps<DataPointType, DataValueType>, 'sectors'>;
537
566
 
538
567
  type InternalProps = WithIdRequired<PropsWithDefaults> & Pick<InternalRadialBarProps, 'sectors'>;
539
568
 
540
569
  function SetRadialBarPayloadLegend(props: RadialBarProps) {
541
- const legendPayload = useAppSelector(
542
- (state) => selectRadialBarLegendPayload(state, props.legendType),
570
+ const legendPayload = useAppSelector((state) =>
571
+ selectRadialBarLegendPayload(state, props.legendType),
543
572
  );
544
573
  return <SetPolarLegendPayload legendPayload={legendPayload ?? []} />;
545
574
  }
546
575
 
547
- const SetRadialBarTooltipEntrySettings = React.memo(({
548
- dataKey,
549
- sectors,
550
- stroke,
551
- strokeWidth,
552
- name,
553
- hide,
554
- fill,
555
- tooltipType,
556
- formatter,
557
- id,
558
- }: Pick<
559
- InternalProps,
560
- | 'dataKey'
561
- | 'sectors'
562
- | 'stroke'
563
- | 'strokeWidth'
564
- | 'name'
565
- | 'hide'
566
- | 'fill'
567
- | 'tooltipType'
568
- | 'formatter'
569
- | 'id'
570
- >) => {
571
- const tooltipEntrySettings: TooltipPayloadConfiguration = {
572
- dataDefinedOnItem: sectors,
573
- getPosition: noop,
574
- settings: {
575
- graphicalItemId: id,
576
- stroke,
577
- strokeWidth,
578
- fill,
579
- nameKey: undefined, // RadialBar does not have nameKey, why?
580
- dataKey,
581
- name: getTooltipNameProp(name, dataKey),
582
- hide,
583
- type: tooltipType,
584
- color: fill,
585
- unit: '', // Why does RadialBar not support unit?
586
- formatter,
587
- },
588
- };
589
- return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings} />;
590
- });
576
+ const SetRadialBarTooltipEntrySettings = React.memo(
577
+ ({
578
+ dataKey,
579
+ sectors,
580
+ stroke,
581
+ strokeWidth,
582
+ name,
583
+ hide,
584
+ fill,
585
+ tooltipType,
586
+ formatter,
587
+ id,
588
+ }: Pick<
589
+ InternalProps,
590
+ | 'dataKey'
591
+ | 'sectors'
592
+ | 'stroke'
593
+ | 'strokeWidth'
594
+ | 'name'
595
+ | 'hide'
596
+ | 'fill'
597
+ | 'tooltipType'
598
+ | 'formatter'
599
+ | 'id'
600
+ >) => {
601
+ const tooltipEntrySettings: TooltipPayloadConfiguration = {
602
+ dataDefinedOnItem: sectors,
603
+ getPosition: noop,
604
+ settings: {
605
+ graphicalItemId: id,
606
+ stroke,
607
+ strokeWidth,
608
+ fill,
609
+ nameKey: undefined, // RadialBar does not have nameKey, why?
610
+ dataKey,
611
+ name: getTooltipNameProp(name, dataKey),
612
+ hide,
613
+ type: tooltipType,
614
+ color: fill,
615
+ unit: '', // Why does RadialBar not support unit?
616
+ formatter,
617
+ },
618
+ };
619
+ return <SetTooltipEntrySettings tooltipEntrySettings={tooltipEntrySettings} />;
620
+ },
621
+ );
591
622
 
592
623
  function renderBackground(props: InternalProps, sectors?: ReadonlyArray<RadialBarDataItem>) {
593
624
  if (sectors == null) {
@@ -595,33 +626,40 @@ function renderBackground(props: InternalProps, sectors?: ReadonlyArray<RadialBa
595
626
  }
596
627
  const { cornerRadius } = props;
597
628
  const backgroundProps = svgPropertiesNoEventsFromUnknown(props.background);
598
- return <ZIndexLayer
599
- zIndex={getZIndexFromUnknown(props.background, DefaultZIndexes.barBackground)}
600
- >{sectors.map((entry, i) => {
601
- const { value, background, ...rest } = entry;
629
+ return (
630
+ <ZIndexLayer zIndex={getZIndexFromUnknown(props.background, DefaultZIndexes.barBackground)}>
631
+ {sectors.map((entry, i) => {
632
+ const { value, background, ...rest } = entry;
602
633
 
603
- if (!background) {
604
- return null;
605
- }
634
+ if (!background) {
635
+ return null;
636
+ }
606
637
 
607
- const sectorProps: ComponentProps<typeof RadialBarSector> = {
608
- cornerRadius: parseCornerRadius(cornerRadius),
609
- ...rest,
610
- fill: '#eee',
611
- ...background,
612
- ...backgroundProps,
613
- ...adaptEventsOfChild(props, entry, i),
614
- index: i,
615
- className: clsx('recharts-radial-bar-background-sector', String(backgroundProps?.className)),
616
- option: background,
617
- isActive: false,
618
- };
638
+ const sectorProps: ComponentProps<typeof RadialBarSector> = {
639
+ cornerRadius: parseCornerRadius(cornerRadius),
640
+ ...rest,
641
+ fill: '#eee',
642
+ ...background,
643
+ ...backgroundProps,
644
+ ...adaptEventsOfChild(props, entry, i),
645
+ index: i,
646
+ className: clsx(
647
+ 'recharts-radial-bar-background-sector',
648
+ String(backgroundProps?.className),
649
+ ),
650
+ option: background,
651
+ isActive: false,
652
+ };
619
653
 
620
- return <RadialBarSector
621
- key={`background-${rest.cx}-${rest.cy}-${rest.innerRadius}-${rest.outerRadius}-${rest.startAngle}-${rest.endAngle}-${i}`}
622
- {...sectorProps}
623
- />;
624
- })}</ZIndexLayer>;
654
+ return (
655
+ <RadialBarSector
656
+ key={`background-${rest.cx}-${rest.cy}-${rest.innerRadius}-${rest.outerRadius}-${rest.startAngle}-${rest.endAngle}-${i}`}
657
+ {...sectorProps}
658
+ />
659
+ );
660
+ })}
661
+ </ZIndexLayer>
662
+ );
625
663
  }
626
664
 
627
665
  function RadialBarWithState(props: InternalProps) {
@@ -633,18 +671,20 @@ function RadialBarWithState(props: InternalProps) {
633
671
 
634
672
  const layerClass = clsx('recharts-area', className);
635
673
 
636
- return <ZIndexLayer zIndex={props.zIndex}>
637
- <Layer className={layerClass}>
638
- {background &&
639
- <Layer className="recharts-radial-bar-background">{renderBackground(
640
- props,
641
- sectors,
642
- )}</Layer>}
643
- <Layer className="recharts-radial-bar-sectors">
644
- <RenderSectors {...props} />
674
+ return (
675
+ <ZIndexLayer zIndex={props.zIndex}>
676
+ <Layer className={layerClass}>
677
+ {background && (
678
+ <Layer className="recharts-radial-bar-background">
679
+ {renderBackground(props, sectors)}
680
+ </Layer>
681
+ )}
682
+ <Layer className="recharts-radial-bar-sectors">
683
+ <RenderSectors {...props} />
684
+ </Layer>
645
685
  </Layer>
646
- </Layer>
647
- </ZIndexLayer>;
686
+ </ZIndexLayer>
687
+ );
648
688
  }
649
689
 
650
690
  function RadialBarImpl(props: WithIdRequired<PropsWithDefaults>) {
@@ -676,31 +716,32 @@ function RadialBarImpl(props: WithIdRequired<PropsWithDefaults>) {
676
716
  ],
677
717
  );
678
718
  const sectors: ReadonlyArray<RadialBarDataItem> =
679
- useAppSelector(
680
- (state) => selectRadialBarSectors(
719
+ useAppSelector((state) =>
720
+ selectRadialBarSectors(
681
721
  state,
682
722
  props.radiusAxisId,
683
723
  props.angleAxisId,
684
724
  radialBarSettings,
685
725
  cells,
686
726
  ),
687
- ) ??
688
- STABLE_EMPTY_ARRAY;
689
- return <CellsContext value={cellRegistry}>
690
- <SetRadialBarTooltipEntrySettings
691
- dataKey={props.dataKey}
692
- sectors={sectors}
693
- stroke={props.stroke}
694
- strokeWidth={props.strokeWidth}
695
- name={props.name}
696
- hide={props.hide}
697
- fill={props.fill}
698
- tooltipType={props.tooltipType}
699
- formatter={props.formatter}
700
- id={props.id}
701
- />
702
- <RadialBarWithState {...props} sectors={sectors} />
703
- </CellsContext>;
727
+ ) ?? STABLE_EMPTY_ARRAY;
728
+ return (
729
+ <CellsContext value={cellRegistry}>
730
+ <SetRadialBarTooltipEntrySettings
731
+ dataKey={props.dataKey}
732
+ sectors={sectors}
733
+ stroke={props.stroke}
734
+ strokeWidth={props.strokeWidth}
735
+ name={props.name}
736
+ hide={props.hide}
737
+ fill={props.fill}
738
+ tooltipType={props.tooltipType}
739
+ formatter={props.formatter}
740
+ id={props.id}
741
+ />
742
+ <RadialBarWithState {...props} sectors={sectors} />
743
+ </CellsContext>
744
+ );
704
745
  }
705
746
 
706
747
  export const defaultRadialBarProps = {
@@ -724,8 +765,10 @@ export const defaultRadialBarProps = {
724
765
  zIndex: DefaultZIndexes.bar,
725
766
  } as const satisfies Partial<RadialBarProps>;
726
767
 
727
- type PropsWithDefaults<DataPointType = any, DataValueType = any> =
728
- RequiresDefaultProps<RadialBarProps<DataPointType, DataValueType>, typeof defaultRadialBarProps>;
768
+ type PropsWithDefaults<DataPointType = any, DataValueType = any> = RequiresDefaultProps<
769
+ RadialBarProps<DataPointType, DataValueType>,
770
+ typeof defaultRadialBarProps
771
+ >;
729
772
 
730
773
  export function computeRadialBarDataItems({
731
774
  displayedData,
@@ -852,7 +895,7 @@ export function computeRadialBarDataItems({
852
895
  // Sector. Keep the row so custom shapes, Cell overrides, and tooltip
853
896
  // indices still refer to the original datum.
854
897
  return {
855
- ...entry as Record<string, unknown>,
898
+ ...(entry as Record<string, unknown>),
856
899
  ...backgroundSector,
857
900
  payload: entry,
858
901
  value: stackedData ? value : value[1],
@@ -862,7 +905,7 @@ export function computeRadialBarDataItems({
862
905
  outerRadius: outerRadius ?? defaultSectorProps.outerRadius,
863
906
  startAngle: startAngle ?? defaultSectorProps.startAngle,
864
907
  endAngle: endAngle ?? defaultSectorProps.endAngle,
865
- ...cells && cells[index] && cells[index].props as CellPropsFor<SVGPathElement>,
908
+ ...(cells && cells[index] && (cells[index].props as CellPropsFor<SVGPathElement>)),
866
909
  } satisfies RadialBarDataItem;
867
910
  });
868
911
  }
@@ -879,25 +922,29 @@ export function RadialBar<DataPointType = any, DataValueType = any>(
879
922
  outsideProps,
880
923
  defaultRadialBarProps,
881
924
  );
882
- return <RegisterGraphicalItemId id={props.id} type="radialBar">
883
- {(id) => <>
884
- <SetPolarGraphicalItem
885
- type="radialBar"
886
- id={id}
887
- data={undefined}
888
- dataKey={props.dataKey}
889
- hide={props.hide ?? defaultRadialBarProps.hide}
890
- angleAxisId={props.angleAxisId ?? defaultRadialBarProps.angleAxisId}
891
- radiusAxisId={props.radiusAxisId ?? defaultRadialBarProps.radiusAxisId}
892
- stackId={getNormalizedStackId(props.stackId)}
893
- barSize={props.barSize}
894
- minPointSize={props.minPointSize}
895
- maxBarSize={props.maxBarSize}
896
- />
897
- <SetRadialBarPayloadLegend {...props} />
898
- <RadialBarImpl {...props} id={id} />
899
- </>}
900
- </RegisterGraphicalItemId>;
925
+ return (
926
+ <RegisterGraphicalItemId id={props.id} type="radialBar">
927
+ {(id) => (
928
+ <>
929
+ <SetPolarGraphicalItem
930
+ type="radialBar"
931
+ id={id}
932
+ data={undefined}
933
+ dataKey={props.dataKey}
934
+ hide={props.hide ?? defaultRadialBarProps.hide}
935
+ angleAxisId={props.angleAxisId ?? defaultRadialBarProps.angleAxisId}
936
+ radiusAxisId={props.radiusAxisId ?? defaultRadialBarProps.radiusAxisId}
937
+ stackId={getNormalizedStackId(props.stackId)}
938
+ barSize={props.barSize}
939
+ minPointSize={props.minPointSize}
940
+ maxBarSize={props.maxBarSize}
941
+ />
942
+ <SetRadialBarPayloadLegend {...props} />
943
+ <RadialBarImpl {...props} id={id} />
944
+ </>
945
+ )}
946
+ </RegisterGraphicalItemId>
947
+ );
901
948
  }
902
949
 
903
950
  RadialBar.displayName = 'RadialBar';