@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,436 @@
1
+ import * as React from 'octane';
2
+ import { ReactElement, ReactNode, SVGProps } from 'octane';
3
+ import {
4
+ ActiveShape,
5
+ AnimationDuration,
6
+ ChartOffsetInternal,
7
+ Coordinate,
8
+ DataConsumer,
9
+ DataKey,
10
+ DataProvider,
11
+ EasingInput,
12
+ GeometrySector,
13
+ LegendType,
14
+ PolarLayout,
15
+ PresentationAttributesAdaptChildEvent,
16
+ ShapeAnimationProps,
17
+ TooltipType,
18
+ } from '../util/types';
19
+ import { TooltipTriggerInfo } from '../context/tooltipContext';
20
+ import { Formatter } from '../component/DefaultTooltipContent';
21
+ import {
22
+ DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME,
23
+ DATA_ITEM_INDEX_ATTRIBUTE_NAME,
24
+ } from '../util/Constants';
25
+ import { AnimationInterpolateFn } from '../animation/AnimatedItems';
26
+ import { AnimationMatchByProp } from '../animation/matchBy';
27
+ import { PiePresentationProps, PieSettings } from '../state/types/PieSettings';
28
+ import { SVGPropsNoEvents } from '../util/svgPropertiesNoEvents';
29
+ import { Props as LabelListProps } from '../component/LabelList';
30
+ import { GraphicalItemId } from '../state/graphicalItemsSlice';
31
+ import { ZIndexable } from '../zIndex/ZIndexLayer';
32
+ import { ChartData } from '../state/chartDataSlice';
33
+ interface PieDef {
34
+ /**
35
+ * The x-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container width.
36
+ */
37
+ cx?: number | string;
38
+ /**
39
+ * The y-coordinate of center. If set a percentage, the final value is obtained by multiplying the percentage of container height.
40
+ */
41
+ cy?: number | string;
42
+ /**
43
+ * Angle in degrees from which the chart should start.
44
+ */
45
+ startAngle?: number;
46
+ /**
47
+ * Angle, in degrees, at which the chart should end.
48
+ */
49
+ endAngle?: number;
50
+ /**
51
+ * The angle between two sectors.
52
+ *
53
+ * @example <Pie paddingAngle={5} />
54
+ * @example https://recharts.github.io/examples/PieChartWithPaddingAngle
55
+ */
56
+ paddingAngle?: number;
57
+ /**
58
+ * The inner radius of the sectors.
59
+ * If set a percentage, the final value is obtained by multiplying the percentage of maxRadius which is calculated by the width, height, cx, cy.
60
+ */
61
+ innerRadius?: number | string;
62
+ /**
63
+ * The outer radius of the sectors.
64
+ * If set a percentage, the final value is obtained by multiplying the percentage of maxRadius which is calculated by the width, height, cx, cy.
65
+ * Function should return a string percentage or number.
66
+ */
67
+ outerRadius?: number | string | ((dataPoint: any) => number | string);
68
+ cornerRadius?: number | string;
69
+ }
70
+ type PieLabelLine =
71
+ | ReactElement<SVGElement>
72
+ | ((props: any) => ReactElement<SVGElement>)
73
+ | SVGProps<SVGPathElement>
74
+ | boolean;
75
+ interface PieLabelExtraProps {
76
+ stroke: string;
77
+ index: number;
78
+ textAnchor: string;
79
+ }
80
+ export type PieLabelRenderProps = Omit<SVGPropsNoEvents<PieSvgAttributes>, 'offset'> &
81
+ Omit<PieSectorDataItem, 'offset'> &
82
+ PieLabelExtraProps &
83
+ Coordinate;
84
+ export type LabelListPropsWithPosition = LabelListProps & {
85
+ position: LabelListProps['position'];
86
+ };
87
+ /**
88
+ * The `label` prop in Pie accepts a variety of alternatives.
89
+ */
90
+ export type PieLabel =
91
+ | boolean
92
+ | LabelListPropsWithPosition
93
+ | Partial<PieLabelRenderProps>
94
+ | ((props: PieLabelRenderProps) => ReactNode | ReactElement<SVGElement>)
95
+ | ReactElement<SVGElement>;
96
+ export type PieSectorData = GeometrySector &
97
+ TooltipTriggerInfo & {
98
+ dataKey?: DataKey<any>;
99
+ midAngle?: number;
100
+ middleRadius?: number;
101
+ name?: string | number;
102
+ paddingAngle?: number;
103
+ payload?: any;
104
+ percent?: number;
105
+ value: number;
106
+ };
107
+ /**
108
+ * We spread the data object into the sector data item,
109
+ * so we can't really know what is going to be inside.
110
+ *
111
+ * This type represents our best effort, but it all depends on the input data
112
+ * and what is inside of it.
113
+ *
114
+ * https://github.com/recharts/recharts/issues/6380
115
+ * https://github.com/recharts/recharts/discussions/6375
116
+ */
117
+ export type PieSectorDataItem = PiePresentationProps &
118
+ PieCoordinate &
119
+ PieSectorData & {
120
+ cornerRadius: number | undefined;
121
+ };
122
+ export type PieSectorShapeProps = PieSectorDataItem &
123
+ ShapeAnimationProps & {
124
+ [DATA_ITEM_INDEX_ATTRIBUTE_NAME]: number;
125
+ [DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME]: GraphicalItemId;
126
+ isActive: boolean;
127
+ index: number;
128
+ } & SVGProps<SVGPathElement>;
129
+ export type PieShape = ActiveShape<PieSectorShapeProps, SVGPathElement>;
130
+ interface PieEvents {
131
+ /**
132
+ * The customized event handler of click on the sectors in this group.
133
+ */
134
+ onClick?: (
135
+ data: PieSectorDataItem,
136
+ index: number,
137
+ e: React.MouseEvent<SVGGraphicsElement>,
138
+ ) => void;
139
+ /**
140
+ * The customized event handler of mousedown on the sectors in this group.
141
+ */
142
+ onMouseDown?: (
143
+ data: PieSectorDataItem,
144
+ index: number,
145
+ e: React.MouseEvent<SVGGraphicsElement>,
146
+ ) => void;
147
+ /**
148
+ * The customized event handler of mouseup on the sectors in this group.
149
+ */
150
+ onMouseUp?: (
151
+ data: PieSectorDataItem,
152
+ index: number,
153
+ e: React.MouseEvent<SVGGraphicsElement>,
154
+ ) => void;
155
+ /**
156
+ * The customized event handler of mousemove on the sectors in this group.
157
+ */
158
+ onMouseMove?: (
159
+ data: PieSectorDataItem,
160
+ index: number,
161
+ e: React.MouseEvent<SVGGraphicsElement>,
162
+ ) => void;
163
+ /**
164
+ * The customized event handler of mouseover on the sectors in this group.
165
+ */
166
+ onMouseOver?: (
167
+ data: PieSectorDataItem,
168
+ index: number,
169
+ e: React.MouseEvent<SVGGraphicsElement>,
170
+ ) => void;
171
+ /**
172
+ * The customized event handler of mouseout on the sectors in this group.
173
+ */
174
+ onMouseOut?: (
175
+ data: PieSectorDataItem,
176
+ index: number,
177
+ e: React.MouseEvent<SVGGraphicsElement>,
178
+ ) => void;
179
+ /**
180
+ * The customized event handler of mouseenter on the sectors in this group.
181
+ */
182
+ onMouseEnter?: (
183
+ data: PieSectorDataItem,
184
+ index: number,
185
+ e: React.MouseEvent<SVGGraphicsElement>,
186
+ ) => void;
187
+ /**
188
+ * The customized event handler of mouseleave on the sectors in this group.
189
+ */
190
+ onMouseLeave?: (
191
+ data: PieSectorDataItem,
192
+ index: number,
193
+ e: React.MouseEvent<SVGGraphicsElement>,
194
+ ) => void;
195
+ onTouchStart?: (
196
+ data: PieSectorDataItem,
197
+ index: number,
198
+ e: React.TouchEvent<SVGGraphicsElement>,
199
+ ) => void;
200
+ onTouchMove?: (
201
+ data: PieSectorDataItem,
202
+ index: number,
203
+ e: React.TouchEvent<SVGGraphicsElement>,
204
+ ) => void;
205
+ onTouchEnd?: (
206
+ data: PieSectorDataItem,
207
+ index: number,
208
+ e: React.TouchEvent<SVGGraphicsElement>,
209
+ ) => void;
210
+ }
211
+ interface PieProps<DataPointType = any, DataValueType = any>
212
+ extends
213
+ DataProvider<DataPointType>,
214
+ DataConsumer<DataPointType, DataValueType>,
215
+ PieDef,
216
+ PieEvents,
217
+ ZIndexable {
218
+ /**
219
+ * This component is rendered when this graphical item is activated
220
+ * (could be by mouse hover, touch, keyboard, programmatically).
221
+ *
222
+ * @deprecated Use the `shape` prop to create each sector. `isActive` designates the "active" shape.
223
+ * @example <Pie activeShape={<CustomActiveShape />} />
224
+ * @example https://recharts.github.io/examples/CustomActiveShapePieChart
225
+ */
226
+ activeShape?: ActiveShape<PieSectorDataItem>;
227
+ /**
228
+ * Specifies when the animation should begin, the unit of this option is ms.
229
+ * @defaultValue 400
230
+ */
231
+ animationBegin?: number;
232
+ /**
233
+ * Specifies the duration of animation, the unit of this option is ms.
234
+ * @defaultValue 1500
235
+ */
236
+ animationDuration?: AnimationDuration;
237
+ /**
238
+ * The type of easing function.
239
+ * @defaultValue ease
240
+ */
241
+ animationEasing?: EasingInput;
242
+ /**
243
+ * Custom animation function for interpolating data items.
244
+ * When provided, this replaces the default animation interpolation.
245
+ *
246
+ * @param prevItems The items from the previous animation frame, or null on first render
247
+ * @param nextItems The target items to animate towards
248
+ * @param animationElapsedTime A normalized time value (0 = start, 1 = end)
249
+ * @returns The interpolated items at time animationElapsedTime
250
+ *
251
+ * @since 3.9
252
+ * @see {@link https://recharts.github.io/en-US/guide/animations/ Animations guide}
253
+ */
254
+ animationInterpolateFn?: AnimationInterpolateFn<PieSectorDataItem, PolarLayout>;
255
+ /**
256
+ * Strategy for matching previous items to next items during animation.
257
+ * Determines how Recharts pairs old data points with new data points
258
+ * to create smooth transitions.
259
+ *
260
+ * - `matchAppend` (default): match sequentially by index and treat newly appended items as new
261
+ * - `matchByIndex`: match by array position with proportional stretching
262
+ * - `matchByDataKey('someKey')`: match by a data key from the payload
263
+ * - Custom function `(item, index) => key`: match by the returned key
264
+ *
265
+ * @defaultValue append
266
+ * @see matchByIndex
267
+ * @see matchByDataKey
268
+ * @see matchAppend
269
+ *
270
+ * @since 3.9
271
+ * @see {@link https://recharts.github.io/en-US/guide/animations/ Animations guide}
272
+ */
273
+ animationMatchBy?: AnimationMatchByProp<PieSectorDataItem>;
274
+ className?: string;
275
+ /**
276
+ * Hides the whole graphical element when true.
277
+ *
278
+ * Hiding an element is different from removing it from the chart:
279
+ * Hidden graphical elements are still visible in Legend,
280
+ * and can be included in axis domain calculations,
281
+ * depending on `includeHidden` props of your XAxis/YAxis.
282
+ *
283
+ * @defaultValue false
284
+ */
285
+ hide?: boolean;
286
+ id?: string;
287
+ /**
288
+ * The shape of inactive sector.
289
+ * @deprecated Use the `shape` prop to modify each sector.
290
+ */
291
+ inactiveShape?: ActiveShape<PieSectorDataItem>;
292
+ /**
293
+ * If set false, animation will be disabled.
294
+ * If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
295
+ * @defaultValue auto
296
+ */
297
+ isAnimationActive?: boolean | 'auto';
298
+ /**
299
+ * Renders one label for each pie sector. Options:
300
+ * - `true`: renders default labels;
301
+ * - `false`: no labels are rendered;
302
+ * - `object` that has `position` prop: the props of LabelList component;
303
+ * - `object` that does not have `position` prop: the props of a custom Pie label (similar to Label with position "outside"); this variant supports `labelLine`
304
+ * - `ReactElement`: a custom SVG label element, such as `<text>` or `<g>`.
305
+ * HTML elements such as `<div>` are not valid inside the chart SVG and may trigger React DOM warnings.
306
+ * - `function`: a render function of custom label.
307
+ *
308
+ * Also see the `labelLine` prop that draws a line connecting each label to the corresponding sector.
309
+ *
310
+ * @defaultValue false
311
+ * @example <Pie label={<CustomizedLabel />} />
312
+ * @example https://recharts.github.io/examples/PieChartWithCustomizedLabel
313
+ */
314
+ label?: PieLabel;
315
+ /**
316
+ * If false set, label lines will not be drawn. If true set, label lines will be drawn which have the props calculated internally.
317
+ * If object set, label lines will be drawn which have the props merged by the internal calculated props and the option.
318
+ * If ReactElement set, the option can be the custom label line element.
319
+ * If set a function, the function will be called to render customized label line.
320
+ * @defaultValue true
321
+ * @example <Pie labelLine={<CustomizedLabelLine />} />
322
+ * @example https://recharts.github.io/examples/PieChartWithCustomizedLabel
323
+ */
324
+ labelLine?: PieLabelLine;
325
+ /**
326
+ * The type of icon in legend. If set to 'none', no legend item will be rendered.
327
+ * @defaultValue rect
328
+ */
329
+ legendType?: LegendType;
330
+ /** the max radius of pie */
331
+ maxRadius?: number;
332
+ /**
333
+ * The minimum angle of each unzero data.
334
+ * @defaultValue 0
335
+ */
336
+ minAngle?: number;
337
+ /**
338
+ * Name represents each sector in the tooltip, and legend.
339
+ * This allows you to extract the name from the data:
340
+ *
341
+ * - `string`: the name of the field in the data object;
342
+ * - `number`: the index of the field in the data;
343
+ * - `function`: a function that receives the data object and returns the name.
344
+ *
345
+ * @defaultValue name
346
+ */
347
+ nameKey?: DataKey<DataPointType, DataValueType>;
348
+ /**
349
+ * The customized event handler of animation end.
350
+ */
351
+ onAnimationEnd?: () => void;
352
+ /**
353
+ * The customized event handler of animation start.
354
+ */
355
+ onAnimationStart?: () => void;
356
+ /**
357
+ * The tabindex of wrapper surrounding the cells.
358
+ * @defaultValue 0
359
+ */
360
+ rootTabIndex?: number;
361
+ /**
362
+ * The custom shape of a Pie Sector.
363
+ * Can also be used to render active sector by checking isActive.
364
+ * During animations, the function shape also receives `animationElapsedTime`, `isAnimating`, and `isEntrance`.
365
+ * If undefined, renders {@link Sector} shape.
366
+ */
367
+ shape?: PieShape;
368
+ tooltipType?: TooltipType;
369
+ /**
370
+ * Formats the value displayed in the tooltip for this Pie.
371
+ * When set, takes precedence over the `formatter` prop on the Tooltip component.
372
+ */
373
+ formatter?: Formatter;
374
+ /**
375
+ * @defaultValue 100
376
+ */
377
+ zIndex?: number;
378
+ }
379
+ type PieSvgAttributes = Omit<
380
+ PresentationAttributesAdaptChildEvent<any, SVGElement>,
381
+ 'ref' | keyof PieEvents
382
+ >;
383
+ export type Props<DataPointType = any, DataValueType = any> = PieSvgAttributes &
384
+ PieProps<DataPointType, DataValueType>;
385
+ export type PieCoordinate = {
386
+ cx: number;
387
+ cy: number;
388
+ innerRadius: number;
389
+ outerRadius: number;
390
+ maxRadius: number;
391
+ };
392
+ export declare function computePieSectors({
393
+ pieSettings,
394
+ displayedData,
395
+ cells,
396
+ offset,
397
+ }: {
398
+ pieSettings: PieSettings;
399
+ displayedData: ChartData;
400
+ cells: ReadonlyArray<ReactElement> | undefined;
401
+ offset: ChartOffsetInternal;
402
+ }): ReadonlyArray<PieSectorDataItem> | undefined;
403
+ export declare const defaultPieProps: {
404
+ readonly animationBegin: 400;
405
+ readonly animationDuration: 1500;
406
+ readonly animationEasing: 'ease';
407
+ readonly animationInterpolateFn: AnimationInterpolateFn<PieSectorDataItem, PolarLayout>;
408
+ readonly animationMatchBy: 'append';
409
+ readonly cx: '50%';
410
+ readonly cy: '50%';
411
+ readonly dataKey: 'value';
412
+ readonly endAngle: 360;
413
+ readonly fill: '#808080';
414
+ readonly hide: false;
415
+ readonly innerRadius: 0;
416
+ readonly isAnimationActive: 'auto';
417
+ readonly label: false;
418
+ readonly labelLine: true;
419
+ readonly legendType: 'rect';
420
+ readonly minAngle: 0;
421
+ readonly nameKey: 'name';
422
+ readonly outerRadius: '80%';
423
+ readonly paddingAngle: 0;
424
+ readonly rootTabIndex: 0;
425
+ readonly shape: React.FC<import('..').SectorProps>;
426
+ readonly startAngle: 0;
427
+ readonly stroke: '#fff';
428
+ readonly zIndex: 100;
429
+ };
430
+ export declare const Pie: {
431
+ <DataPointType = any, DataValueType = any>(
432
+ outsideProps: Props<DataPointType, DataValueType>,
433
+ ): ReactElement;
434
+ (outsideProps: Props<any, any>): ReactElement;
435
+ };
436
+ export {};