@octanejs/recharts 0.1.15 → 0.1.17

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 +5 -5
  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,219 @@
1
+ import * as React from 'octane';
2
+ import { ReactElement, SVGProps } from 'octane';
3
+ import { ChartOffsetInternal } from '../util/types';
4
+ import { AxisPropsNeededForTicksGenerator } from '../util/ChartUtils';
5
+ import { GetTicksInput } from './getTicks';
6
+ import { AxisId } from '../state/cartesianAxisSlice';
7
+ import { ZIndexable } from '../zIndex/ZIndexLayer';
8
+ /**
9
+ * The <CartesianGrid horizontal
10
+ */
11
+ export type GridLineTypeFunctionProps = Omit<LineItemProps, 'key'> & {
12
+ key: LineItemProps['key'] | undefined;
13
+ offset: ChartOffsetInternal;
14
+ };
15
+ export type AxisPropsForCartesianGridTicksGeneration = AxisPropsNeededForTicksGenerator &
16
+ Omit<GetTicksInput, 'ticks' | 'viewBox'>;
17
+ type GridLineType =
18
+ | SVGProps<SVGLineElement>
19
+ | ReactElement<SVGElement>
20
+ | ((props: GridLineTypeFunctionProps) => ReactElement<SVGElement>)
21
+ | boolean;
22
+ export type HorizontalCoordinatesGenerator = (
23
+ props: {
24
+ yAxis: AxisPropsForCartesianGridTicksGeneration | undefined;
25
+ width: number;
26
+ height: number;
27
+ offset: ChartOffsetInternal;
28
+ },
29
+ syncWithTicks: boolean,
30
+ ) => number[];
31
+ export type VerticalCoordinatesGenerator = (
32
+ props: {
33
+ xAxis: AxisPropsForCartesianGridTicksGeneration | undefined;
34
+ width: number;
35
+ height: number;
36
+ offset: ChartOffsetInternal;
37
+ },
38
+ syncWithTicks: boolean,
39
+ ) => number[];
40
+ interface CartesianGridProps extends ZIndexable {
41
+ /**
42
+ * The width of grid. If undefined, covers the full width of the chart plot area.
43
+ */
44
+ width?: number;
45
+ /**
46
+ * The height of grid. If undefined, covers the full height of the chart plot area.
47
+ */
48
+ height?: number;
49
+ /**
50
+ * A function that generates the y-coordinates of all horizontal lines.
51
+ *
52
+ * @see {@link https://codesandbox.io/p/sandbox/cartesian-grid-with-coordinate-generators-my38cg?file=%2Fsrc%2FApp.tsx Cartesian grid with coordinate generators}
53
+ */
54
+ horizontalCoordinatesGenerator?: HorizontalCoordinatesGenerator;
55
+ /**
56
+ * A function that generates the x-coordinates of all vertical lines.
57
+ *
58
+ * @see {@link https://codesandbox.io/p/sandbox/cartesian-grid-with-coordinate-generators-my38cg?file=%2Fsrc%2FApp.tsx Cartesian grid with coordinate generators}
59
+ */
60
+ verticalCoordinatesGenerator?: VerticalCoordinatesGenerator;
61
+ /**
62
+ * The x-coordinate of grid.
63
+ * If left undefined, it will be computed from the chart's offset and margins.
64
+ */
65
+ x?: number;
66
+ /**
67
+ * The y-coordinate of grid.
68
+ * If left undefined, it will be computed from the chart's offset and margins.
69
+ */
70
+ y?: number;
71
+ /**
72
+ * If set false, no horizontal grid lines will be drawn.
73
+ *
74
+ * @defaultValue true
75
+ */
76
+ horizontal?: GridLineType;
77
+ /**
78
+ * If set false, no vertical grid lines will be drawn.
79
+ *
80
+ * @defaultValue true
81
+ */
82
+ vertical?: GridLineType;
83
+ /**
84
+ * Array of coordinates in pixels where to draw horizontal grid lines.
85
+ * Has priority over syncWithTicks and horizontalValues.
86
+ *
87
+ * @defaultValue []
88
+ */
89
+ horizontalPoints?: number[];
90
+ /**
91
+ * Array of coordinates in pixels where to draw vertical grid lines.
92
+ * Has priority over syncWithTicks and verticalValues.
93
+ *
94
+ * @defaultValue []
95
+ */
96
+ verticalPoints?: number[];
97
+ /**
98
+ * The background color used to fill the space between grid lines
99
+ *
100
+ * @defaultValue none
101
+ * @example <CartesianGrid fill="red" />
102
+ * @example <CartesianGrid fill="#ccc" />
103
+ */
104
+ fill?: string;
105
+ /**
106
+ * The opacity of the background used to fill the space between grid lines
107
+ *
108
+ * @example <CartesianGrid fill="red" fillOpacity={0.6} />
109
+ */
110
+ fillOpacity?: number | string;
111
+ /**
112
+ * Defines background color of stripes.
113
+ *
114
+ * The values from this array will be passed in as the `fill` property in a `rect` SVG element.
115
+ * For possible values see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#rect
116
+ *
117
+ * In case there are more stripes than colors, the colors will start from beginning.
118
+ * So for example: verticalFill['yellow', 'black'] produces a pattern of yellow|black|yellow|black
119
+ *
120
+ * If this is undefined, or an empty array, then there is no background fill.
121
+ * Note: Grid lines will be rendered above these background stripes.
122
+ *
123
+ * @defaultValue []
124
+ */
125
+ verticalFill?: string[];
126
+ /**
127
+ * Defines background color of stripes.
128
+ *
129
+ * The values from this array will be passed in as the `fill` property in a `rect` SVG element.
130
+ * For possible values see: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/fill#rect
131
+ *
132
+ * In case there are more stripes than colors, the colors will start from beginning.
133
+ * So for example: horizontalFill['yellow', 'black'] produces a pattern of yellow|black|yellow|black
134
+ *
135
+ * If this is undefined, or an empty array, then there is no background fill.
136
+ * Note: Grid lines will be rendered above these background stripes.
137
+ *
138
+ * @defaultValue []
139
+ */
140
+ horizontalFill?: string[];
141
+ /**
142
+ * If true, only the lines that correspond to the axes ticks values will be drawn.
143
+ * If false, extra lines could be added for each axis (at min and max coordinates), if there will not such ticks.
144
+ * horizontalPoints, verticalPoints, horizontalValues, verticalValues have priority over syncWithTicks.
145
+ *
146
+ * @defaultValue false
147
+ */
148
+ syncWithTicks?: boolean;
149
+ /**
150
+ * Array of values, where horizontal lines will be drawn. Numbers or strings, in dependence on axis type.
151
+ * Has priority over syncWithTicks but not over horizontalPoints.
152
+ */
153
+ horizontalValues?: number[] | string[];
154
+ /**
155
+ * Array of values, where vertical lines will be drawn. Numbers or strings, in dependence on axis type.
156
+ * Has priority over syncWithTicks but not over verticalPoints.
157
+ */
158
+ verticalValues?: number[] | string[];
159
+ /**
160
+ * The pattern of dashes and gaps used to paint the lines of the grid
161
+ *
162
+ * @example <CartesianGrid strokeDasharray="3 3" />
163
+ * @example <CartesianGrid strokeDasharray={[5, 5, 1, 5]} />
164
+ * @example <CartesianGrid strokeDasharray="5 5 1 5" />
165
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray stroke-dasharray on MDN}
166
+ */
167
+ strokeDasharray?: string | number[];
168
+ /**
169
+ * The id of XAxis which is corresponding to the data. Required when there are multiple XAxes.
170
+ * @defaultValue 0
171
+ */
172
+ xAxisId?: AxisId;
173
+ /**
174
+ * The id of YAxis which is corresponding to the data. Required when there are multiple YAxes.
175
+ * @defaultValue 0
176
+ */
177
+ yAxisId?: AxisId;
178
+ /**
179
+ * @defaultValue -100
180
+ */
181
+ zIndex?: number;
182
+ }
183
+ type AcceptedSvgProps = Omit<SVGProps<SVGLineElement>, 'offset'>;
184
+ export type Props = AcceptedSvgProps & CartesianGridProps;
185
+ type LineItemProps = Props & {
186
+ offset: ChartOffsetInternal;
187
+ xAxis: undefined | AxisPropsForCartesianGridTicksGeneration;
188
+ yAxis: undefined | AxisPropsForCartesianGridTicksGeneration;
189
+ x1: number;
190
+ y1: number;
191
+ x2: number;
192
+ y2: number;
193
+ key: string;
194
+ index: number;
195
+ };
196
+ export declare const defaultCartesianGridProps: {
197
+ readonly horizontal: true;
198
+ readonly vertical: true;
199
+ readonly horizontalPoints: [];
200
+ readonly verticalPoints: [];
201
+ readonly stroke: '#ccc';
202
+ readonly fill: 'none';
203
+ readonly verticalFill: [];
204
+ readonly horizontalFill: [];
205
+ readonly xAxisId: 0;
206
+ readonly yAxisId: 0;
207
+ readonly syncWithTicks: false;
208
+ readonly zIndex: -100;
209
+ };
210
+ /**
211
+ * Renders background grid with lines and fill colors in a Cartesian chart.
212
+ *
213
+ * @consumes CartesianChartContext
214
+ */
215
+ export declare function CartesianGrid(props: Props): React.JSX.Element | null;
216
+ export declare namespace CartesianGrid {
217
+ var displayName: string;
218
+ }
219
+ export {};
@@ -0,0 +1,322 @@
1
+ /**
2
+ * @fileOverview Render a group of error bar
3
+ */
4
+ import * as React from 'octane';
5
+ import { SVGProps } from 'octane';
6
+ import { Layer } from '../container/Layer';
7
+ import { EasingInput, DataKey, RectangleCoordinate } from '../util/types';
8
+ import { BarRectangleItem } from './Bar';
9
+ import { LinePointItem } from './Line';
10
+ import { ScatterPointItem } from './Scatter';
11
+ import { ReportErrorBarSettings, useErrorBarContext } from '../context/ErrorBarContext';
12
+ import { useXAxis, useYAxis } from '../hooks';
13
+ import { resolveDefaultProps } from '../util/resolveDefaultProps';
14
+ import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
15
+ import { useChartLayout } from '../context/chartLayoutContext';
16
+ import { CSSTransitionAnimate, extractCssEasing } from '../animation/CSSTransitionAnimate';
17
+ import { ZIndexable, ZIndexLayer } from '../zIndex/ZIndexLayer';
18
+ import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
19
+
20
+ export interface ErrorBarDataItem {
21
+ x: number | undefined;
22
+ y: number | undefined;
23
+ value: number;
24
+ errorVal?: number[] | number;
25
+ }
26
+
27
+ /**
28
+ * So usually the direction is decided by the chart layout.
29
+ * Horizontal layout means error bars are vertical means direction=y
30
+ * Vertical layout means error bars are horizontal means direction=x
31
+ *
32
+ * Except! In Scatter chart, error bars can go both ways.
33
+ *
34
+ * So this property is only ever used in Scatter chart, and ignored elsewhere.
35
+ */
36
+ export type ErrorBarDirection = 'x' | 'y';
37
+
38
+ export type ErrorBarDataPointFormatter<
39
+ T extends BarRectangleItem | LinePointItem | ScatterPointItem,
40
+ > =
41
+ (entry: T, dataKey: DataKey<
42
+ T,
43
+ number[] | number
44
+ >, direction: ErrorBarDirection) => ErrorBarDataItem;
45
+
46
+ /**
47
+ * External ErrorBar props, visible for users of the library
48
+ */
49
+ interface ErrorBarProps<DataPointType = any, DataValueType = any> extends ZIndexable {
50
+ /**
51
+ * Decides how to extract the value of this ErrorBar from the data:
52
+ * - `string`: the name of the field in the data object;
53
+ * - `number`: the index of the field in the data;
54
+ * - `function`: a function that receives the data object and returns the value of this ErrorBar.
55
+ *
56
+ * The error values can be a single value for symmetric error bars;
57
+ * or an array of a lower and upper error value for asymmetric error bars.
58
+ */
59
+ dataKey: DataKey<DataPointType, DataValueType>;
60
+ /**
61
+ * Width of the error bar ends (the serifs) in pixels.
62
+ * This is not the total width of the error bar, but just the width of the little lines at the ends.
63
+ *
64
+ * The total width of the error bar is determined by the data value plus/minus the error value.
65
+ *
66
+ * @defaultValue 5
67
+ */
68
+ width?: number;
69
+ /**
70
+ * Direction of the error bar. Usually determined by chart layout, except in Scatter chart.
71
+ * In Scatter chart, "x" means horizontal error bars, "y" means vertical error bars.
72
+ */
73
+ direction?: ErrorBarDirection;
74
+ /**
75
+ * @defaultValue true
76
+ */
77
+ isAnimationActive?: boolean;
78
+ /**
79
+ * @defaultValue 0
80
+ */
81
+ animationBegin?: number;
82
+ /**
83
+ * @defaultValue 400
84
+ */
85
+ animationDuration?: number;
86
+ /**
87
+ * @defaultValue ease-in-out
88
+ */
89
+ animationEasing?: EasingInput;
90
+ /**
91
+ * The width of the stroke
92
+ */
93
+ strokeWidth?: number | string;
94
+ /**
95
+ * The stroke color. If "none", no line will be drawn.
96
+ *
97
+ * @defaultValue black
98
+ */
99
+ stroke?: string;
100
+ /**
101
+ * @defaultValue 400
102
+ */
103
+ zIndex?: number;
104
+ }
105
+
106
+ export type Props = SVGProps<SVGLineElement> & ErrorBarProps;
107
+
108
+ /**
109
+ * Props after defaults, and required props have been applied.
110
+ */
111
+ type ErrorBarInternalProps =
112
+ SVGProps<SVGLineElement> & {
113
+ dataKey: DataKey<any>;
114
+ /** the width of the error bar ends */
115
+ width: number;
116
+ /**
117
+ * Only used for ScatterChart with error bars in two directions.
118
+ * Only accepts a value of "x" or "y" and makes the error bars lie in that direction.
119
+ */
120
+ direction: ErrorBarDirection;
121
+ isAnimationActive: boolean;
122
+ animationBegin: number;
123
+ animationDuration: number;
124
+ animationEasing: EasingInput;
125
+ };
126
+
127
+ function ErrorBarImpl(props: ErrorBarInternalProps) {
128
+ const {
129
+ direction,
130
+ width,
131
+ dataKey,
132
+ isAnimationActive,
133
+ animationBegin,
134
+ animationDuration,
135
+ animationEasing,
136
+ ...others
137
+ } = props;
138
+ const svgProps = svgPropertiesNoEvents(others);
139
+
140
+ const { data, dataPointFormatter, xAxisId, yAxisId, errorBarOffset: offset } =
141
+ useErrorBarContext();
142
+
143
+ const xAxis = useXAxis(xAxisId);
144
+ const yAxis = useYAxis(yAxisId);
145
+
146
+ if (xAxis?.scale == null || yAxis?.scale == null || data == null) {
147
+ return null;
148
+ }
149
+
150
+ // ErrorBar requires type number XAxis, why?
151
+ if (direction === 'x' && xAxis.type !== 'number') {
152
+ return null;
153
+ }
154
+
155
+ const errorBars = data.map((entry: any, dataIndex: number) => {
156
+ const { x, y, value, errorVal } = dataPointFormatter(entry, dataKey, direction);
157
+
158
+ if (errorVal == null || x == null || y == null) {
159
+ return null;
160
+ }
161
+
162
+ const lineCoordinates: Array<RectangleCoordinate> = [];
163
+ let lowBound: number, highBound: number;
164
+
165
+ if (Array.isArray(errorVal)) {
166
+ const [low, high] = errorVal;
167
+ if (low == null || high == null) {
168
+ return null;
169
+ }
170
+ lowBound = low;
171
+ highBound = high;
172
+ } else {
173
+ lowBound = highBound = errorVal;
174
+ }
175
+
176
+ if (direction === 'x') {
177
+ // error bar for horizontal charts, the y is fixed, x is a range value
178
+ const { scale } = xAxis;
179
+
180
+ const yMid = y + offset;
181
+ const yMin = yMid + width;
182
+ const yMax = yMid - width;
183
+
184
+ const xMin = scale.map(value - lowBound);
185
+ const xMax = scale.map(value + highBound);
186
+
187
+ if (xMin != null && xMax != null) {
188
+ // the right line of |--|
189
+ lineCoordinates.push({ x1: xMax, y1: yMin, x2: xMax, y2: yMax });
190
+ // the middle line of |--|
191
+ lineCoordinates.push({ x1: xMin, y1: yMid, x2: xMax, y2: yMid });
192
+ // the left line of |--|
193
+ lineCoordinates.push({ x1: xMin, y1: yMin, x2: xMin, y2: yMax });
194
+ }
195
+ } else if (direction === 'y') {
196
+ // error bar for horizontal charts, the x is fixed, y is a range value
197
+ const { scale } = yAxis;
198
+
199
+ const xMid = x + offset;
200
+ const xMin = xMid - width;
201
+ const xMax = xMid + width;
202
+
203
+ const yMin = scale.map(value - lowBound);
204
+ const yMax = scale.map(value + highBound);
205
+
206
+ if (yMin != null && yMax != null) {
207
+ // the top line
208
+ lineCoordinates.push({ x1: xMin, y1: yMax, x2: xMax, y2: yMax });
209
+ // the middle line
210
+ lineCoordinates.push({ x1: xMid, y1: yMin, x2: xMid, y2: yMax });
211
+ // the bottom line
212
+ lineCoordinates.push({ x1: xMin, y1: yMin, x2: xMax, y2: yMin });
213
+ }
214
+ }
215
+
216
+ const scaleDirection: string =
217
+ direction === 'x' ? 'scaleX' : 'scaleY';
218
+
219
+ const transformOrigin =
220
+ direction === 'x' ? `${x}px ${y + offset}px` : `${x + offset}px ${y}px`;
221
+
222
+ return <Layer
223
+ className="recharts-errorBar"
224
+ key={`bar-${x}-${y}-${value}-${dataIndex}`}
225
+ {...svgProps}
226
+ >{lineCoordinates.map((c, lineIndex) => {
227
+ const lineStyle = isAnimationActive ? { transformOrigin } : undefined;
228
+ return <CSSTransitionAnimate
229
+ animationId={`error-bar-${direction}_${c.x1}-${c.x2}-${c.y1}-${c.y2}`}
230
+ from={`${scaleDirection}(0)`}
231
+ to={`${scaleDirection}(1)`}
232
+ attributeName="transform"
233
+ begin={animationBegin}
234
+ easing={extractCssEasing(animationEasing)}
235
+ isActive={isAnimationActive}
236
+ duration={animationDuration}
237
+ key={`errorbar-${dataIndex}-${c.x1}-${c.y1}-${c.x2}-${c.y2}-${lineIndex}`}
238
+ >
239
+ {(style) => <line {...c} style={{ ...lineStyle, ...style }} />}
240
+ </CSSTransitionAnimate>;
241
+ })}</Layer>;
242
+ });
243
+
244
+ return <Layer className="recharts-errorBars">{errorBars}</Layer>;
245
+ }
246
+
247
+ function useErrorBarDirection(
248
+ directionFromProps: ErrorBarDirection | undefined,
249
+ ): ErrorBarDirection {
250
+ const layout = useChartLayout();
251
+ if (directionFromProps != null) {
252
+ return directionFromProps;
253
+ }
254
+ if (layout != null) {
255
+ return layout === 'horizontal' ? 'y' : 'x';
256
+ }
257
+ return 'x';
258
+ }
259
+
260
+ export const errorBarDefaultProps = {
261
+ stroke: 'black',
262
+ strokeWidth: 1.5,
263
+ width: 5,
264
+ offset: 0,
265
+ isAnimationActive: true,
266
+ animationBegin: 0,
267
+ animationDuration: 400,
268
+ animationEasing: 'ease-in-out',
269
+ zIndex: DefaultZIndexes.line,
270
+ } as const satisfies Partial<Props>;
271
+
272
+ /**
273
+ * ErrorBar renders whiskers to represent error margins on a chart.
274
+ *
275
+ * It must be a child of a graphical element.
276
+ *
277
+ * ErrorBar expects data in one of the following forms:
278
+ * - Symmetric error bars: a single error value representing both lower and upper bounds.
279
+ * - Asymmetric error bars: an array of two values representing lower and upper bounds separately. First value is the lower bound, second value is the upper bound.
280
+ *
281
+ * The values provided are relative to the main data value.
282
+ * For example, if the main data value is 10 and the error value is 2,
283
+ * the error bar will extend from 8 to 12 for symmetric error bars.
284
+ *
285
+ * In other words, what ErrorBar will render is:
286
+ * - For symmetric error bars: [value - errorVal, value + errorVal]
287
+ * - For asymmetric error bars: [value - errorVal[0], value + errorVal[1]]
288
+ *
289
+ * In stacked or ranged Bar charts, ErrorBar will use the higher data value
290
+ * as the reference point for calculating the error bar positions.
291
+ *
292
+ * @consumes ErrorBarContext
293
+ */
294
+ export function ErrorBar(outsideProps: Props) {
295
+ const realDirection: ErrorBarDirection = useErrorBarDirection(outsideProps.direction);
296
+ const props = resolveDefaultProps(outsideProps, errorBarDefaultProps);
297
+ const {
298
+ width,
299
+ isAnimationActive,
300
+ animationBegin,
301
+ animationDuration,
302
+ animationEasing,
303
+ zIndex,
304
+ } = props;
305
+
306
+ return <>
307
+ <ReportErrorBarSettings dataKey={props.dataKey} direction={realDirection} />
308
+ <ZIndexLayer zIndex={zIndex}>
309
+ <ErrorBarImpl
310
+ {...props}
311
+ direction={realDirection}
312
+ width={width}
313
+ isAnimationActive={isAnimationActive}
314
+ animationBegin={animationBegin}
315
+ animationDuration={animationDuration}
316
+ animationEasing={animationEasing}
317
+ />
318
+ </ZIndexLayer>
319
+ </>;
320
+ }
321
+
322
+ ErrorBar.displayName = 'ErrorBar';
@@ -0,0 +1,131 @@
1
+ /**
2
+ * @fileOverview Render a group of error bar
3
+ */
4
+ import * as React from 'octane';
5
+ import { SVGProps } from 'octane';
6
+ import { EasingInput, DataKey } from '../util/types';
7
+ import { BarRectangleItem } from './Bar';
8
+ import { LinePointItem } from './Line';
9
+ import { ScatterPointItem } from './Scatter';
10
+ import { ZIndexable } from '../zIndex/ZIndexLayer';
11
+ export interface ErrorBarDataItem {
12
+ x: number | undefined;
13
+ y: number | undefined;
14
+ value: number;
15
+ errorVal?: number[] | number;
16
+ }
17
+ /**
18
+ * So usually the direction is decided by the chart layout.
19
+ * Horizontal layout means error bars are vertical means direction=y
20
+ * Vertical layout means error bars are horizontal means direction=x
21
+ *
22
+ * Except! In Scatter chart, error bars can go both ways.
23
+ *
24
+ * So this property is only ever used in Scatter chart, and ignored elsewhere.
25
+ */
26
+ export type ErrorBarDirection = 'x' | 'y';
27
+ export type ErrorBarDataPointFormatter<
28
+ T extends BarRectangleItem | LinePointItem | ScatterPointItem,
29
+ > = (
30
+ entry: T,
31
+ dataKey: DataKey<T, number[] | number>,
32
+ direction: ErrorBarDirection,
33
+ ) => ErrorBarDataItem;
34
+ /**
35
+ * External ErrorBar props, visible for users of the library
36
+ */
37
+ interface ErrorBarProps<DataPointType = any, DataValueType = any> extends ZIndexable {
38
+ /**
39
+ * Decides how to extract the value of this ErrorBar from the data:
40
+ * - `string`: the name of the field in the data object;
41
+ * - `number`: the index of the field in the data;
42
+ * - `function`: a function that receives the data object and returns the value of this ErrorBar.
43
+ *
44
+ * The error values can be a single value for symmetric error bars;
45
+ * or an array of a lower and upper error value for asymmetric error bars.
46
+ */
47
+ dataKey: DataKey<DataPointType, DataValueType>;
48
+ /**
49
+ * Width of the error bar ends (the serifs) in pixels.
50
+ * This is not the total width of the error bar, but just the width of the little lines at the ends.
51
+ *
52
+ * The total width of the error bar is determined by the data value plus/minus the error value.
53
+ *
54
+ * @defaultValue 5
55
+ */
56
+ width?: number;
57
+ /**
58
+ * Direction of the error bar. Usually determined by chart layout, except in Scatter chart.
59
+ * In Scatter chart, "x" means horizontal error bars, "y" means vertical error bars.
60
+ */
61
+ direction?: ErrorBarDirection;
62
+ /**
63
+ * @defaultValue true
64
+ */
65
+ isAnimationActive?: boolean;
66
+ /**
67
+ * @defaultValue 0
68
+ */
69
+ animationBegin?: number;
70
+ /**
71
+ * @defaultValue 400
72
+ */
73
+ animationDuration?: number;
74
+ /**
75
+ * @defaultValue ease-in-out
76
+ */
77
+ animationEasing?: EasingInput;
78
+ /**
79
+ * The width of the stroke
80
+ */
81
+ strokeWidth?: number | string;
82
+ /**
83
+ * The stroke color. If "none", no line will be drawn.
84
+ *
85
+ * @defaultValue black
86
+ */
87
+ stroke?: string;
88
+ /**
89
+ * @defaultValue 400
90
+ */
91
+ zIndex?: number;
92
+ }
93
+ export type Props = SVGProps<SVGLineElement> & ErrorBarProps;
94
+ export declare const errorBarDefaultProps: {
95
+ readonly stroke: 'black';
96
+ readonly strokeWidth: 1.5;
97
+ readonly width: 5;
98
+ readonly offset: 0;
99
+ readonly isAnimationActive: true;
100
+ readonly animationBegin: 0;
101
+ readonly animationDuration: 400;
102
+ readonly animationEasing: 'ease-in-out';
103
+ readonly zIndex: 400;
104
+ };
105
+ /**
106
+ * ErrorBar renders whiskers to represent error margins on a chart.
107
+ *
108
+ * It must be a child of a graphical element.
109
+ *
110
+ * ErrorBar expects data in one of the following forms:
111
+ * - Symmetric error bars: a single error value representing both lower and upper bounds.
112
+ * - Asymmetric error bars: an array of two values representing lower and upper bounds separately. First value is the lower bound, second value is the upper bound.
113
+ *
114
+ * The values provided are relative to the main data value.
115
+ * For example, if the main data value is 10 and the error value is 2,
116
+ * the error bar will extend from 8 to 12 for symmetric error bars.
117
+ *
118
+ * In other words, what ErrorBar will render is:
119
+ * - For symmetric error bars: [value - errorVal, value + errorVal]
120
+ * - For asymmetric error bars: [value - errorVal[0], value + errorVal[1]]
121
+ *
122
+ * In stacked or ranged Bar charts, ErrorBar will use the higher data value
123
+ * as the reference point for calculating the error bar positions.
124
+ *
125
+ * @consumes ErrorBarContext
126
+ */
127
+ export declare function ErrorBar(outsideProps: Props): React.JSX.Element;
128
+ export declare namespace ErrorBar {
129
+ var displayName: string;
130
+ }
131
+ export {};