@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,452 @@
1
+ /**
2
+ * @fileOverview Reference Line
3
+ */
4
+ import * as React from 'octane';
5
+ import { ReactElement, SVGProps, useEffect } from 'octane';
6
+ import { clsx } from 'clsx';
7
+ import { Layer } from '../container/Layer';
8
+ import {
9
+ CartesianLabelContextProvider,
10
+ CartesianLabelFromLabelProp,
11
+ ImplicitLabelType,
12
+ } from '../component/Label';
13
+ import type { IfOverflow, Overflowable } from '../util/IfOverflow';
14
+ import { isNumOrStr } from '../util/DataUtils';
15
+ import { rectWithCoords } from '../util/CartesianUtils';
16
+ import { CartesianViewBoxRequired, Coordinate } from '../util/types';
17
+ import { useViewBox } from '../context/chartLayoutContext';
18
+ import { addLine, ReferenceLineSettings, removeLine } from '../state/referenceElementsSlice';
19
+ import { useAppDispatch, useAppSelector } from '../state/hooks';
20
+ import {
21
+ selectAxisScale,
22
+ selectXAxisSettings,
23
+ selectYAxisSettings,
24
+ } from '../state/selectors/axisSelectors';
25
+ import { useIsPanorama } from '../context/PanoramaContext';
26
+
27
+ import { useClipPathId } from '../container/ClipPathProvider';
28
+ import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents';
29
+ import { RequiresDefaultProps, resolveDefaultProps } from '../util/resolveDefaultProps';
30
+ import { ZIndexable, ZIndexLayer } from '../zIndex/ZIndexLayer';
31
+ import { DefaultZIndexes } from '../zIndex/DefaultZIndexes';
32
+ import { isWellBehavedNumber } from '../util/isWellBehavedNumber';
33
+ import { BandPosition, RechartsScale } from '../util/scale/RechartsScale';
34
+ import { CartesianScaleHelper, CartesianScaleHelperImpl } from '../util/scale/CartesianScaleHelper';
35
+
36
+ /**
37
+ * Single point that defines one end of a segment.
38
+ * These coordinates are in data space, meaning that you should provide
39
+ * values that correspond to the data domain of the axes.
40
+ * So you would provide a value of `Page A` to indicate the data value `Page A`
41
+ * and then recharts will convert that to pixels.
42
+ *
43
+ * Likewise for numbers. If your x-axis goes from 0 to 100,
44
+ * and you want the line to end at 50, you would provide `50` here.
45
+ *
46
+ * @inline
47
+ */
48
+ export type ReferenceLineSegment =
49
+ readonly [{
50
+ x?: number | string;
51
+ y?: number | string;
52
+ }, {
53
+ x?: number | string;
54
+ y?: number | string;
55
+ }];
56
+
57
+ type ReferenceCoordinateValue = number | string;
58
+
59
+ interface ReferenceLineProps<
60
+ XValueType extends ReferenceCoordinateValue = any,
61
+ YValueType extends ReferenceCoordinateValue = any,
62
+ > extends Overflowable, ZIndexable {
63
+ /**
64
+ * If defined, renders a horizontal line on this position.
65
+ *
66
+ * This value is using your chart's domain, so you will provide a data value instead of a pixel value.
67
+ * ReferenceLine will internally calculate the correct pixel position.
68
+ *
69
+ * @example <ReferenceLine y="Page D" />
70
+ */
71
+ y?: YValueType;
72
+ /**
73
+ * If defined, renders a vertical line on this position.
74
+ *
75
+ * This value is using your chart's domain, so you will provide a data value instead of a pixel value.
76
+ * ReferenceLine will internally calculate the correct pixel position.
77
+ *
78
+ * @example <ReferenceLine x="Monday" />
79
+ */
80
+ x?: XValueType;
81
+ /**
82
+ * Tuple of coordinates. If defined, renders a diagonal line segment.
83
+ */
84
+ segment?: readonly [{
85
+ x?: XValueType;
86
+ y?: YValueType;
87
+ }, {
88
+ x?: XValueType;
89
+ y?: YValueType;
90
+ }];
91
+ /**
92
+ * The position of the reference line when the axis has bandwidth
93
+ * (e.g., a band scale). This determines where within the band
94
+ * the line is drawn.
95
+ * @defaultValue 'middle'
96
+ */
97
+ position?: BandPosition;
98
+ className?: number | string;
99
+ /**
100
+ * The id of y-axis which is corresponding to the data.
101
+ * Required when there are multiple YAxes.
102
+ * @defaultValue 0
103
+ */
104
+ yAxisId?: number | string;
105
+ /**
106
+ * The id of x-axis which is corresponding to the data.
107
+ * Required when there are multiple XAxes.
108
+ * @defaultValue 0
109
+ */
110
+ xAxisId?: number | string;
111
+ shape?: ReactElement<SVGElement> | ((props: any) => ReactElement<SVGElement>);
112
+ /**
113
+ * Renders a single label.
114
+ *
115
+ * - `false`: no labels are rendered
116
+ * - `string` | `number`: the content of the label
117
+ * - `object`: the props of LabelList component
118
+ * - `ReactElement`: a custom SVG label element, such as `<text>` or `<g>`.
119
+ * HTML elements such as `<div>` are not valid inside the chart SVG and may trigger React DOM warnings.
120
+ * - `function`: a render function of custom label
121
+ *
122
+ * @defaultValue false
123
+ *
124
+ * @see {@link https://recharts.github.io/en-US/examples/LineChartWithReferenceLines/ Reference elements with a label}
125
+ */
126
+ label?: ImplicitLabelType;
127
+ /**
128
+ * Z-Index of this component and its children. The higher the value,
129
+ * the more on top it will be rendered.
130
+ * Components with higher zIndex will appear in front of components with lower zIndex.
131
+ * If undefined or 0, the content is rendered in the default layer without portals.
132
+ *
133
+ * @since 3.4
134
+ * @defaultValue 400
135
+ * @see {@link https://recharts.github.io/en-US/guide/zIndex/ Z-Index and layers guide}
136
+ */
137
+ zIndex?: number;
138
+ /**
139
+ * The width of the stroke
140
+ * @defaultValue 1
141
+ */
142
+ strokeWidth?: number | string;
143
+ }
144
+
145
+ /**
146
+ * This excludes `viewBox` prop from svg for two reasons:
147
+ * 1. The components wants viewBox of object type, and svg wants string
148
+ * - so there's a conflict, and the component will throw if it gets string
149
+ * 2. Internally the component calls `svgPropertiesNoEvents` which filters the viewBox away anyway
150
+ */
151
+ export type Props<
152
+ XValueType extends ReferenceCoordinateValue = any,
153
+ YValueType extends ReferenceCoordinateValue = any,
154
+ > =
155
+ Omit<SVGProps<SVGLineElement>, 'viewBox'> & ReferenceLineProps<XValueType, YValueType>;
156
+
157
+ const renderLine = (option: ReferenceLineProps['shape'], props: SVGProps<SVGLineElement>) => {
158
+ let line;
159
+
160
+ if (React.isValidElement(option)) {
161
+ // @ts-expect-error element cloning is not typed
162
+ line = React.cloneElement(option, props);
163
+ } else if (typeof option === 'function') {
164
+ line = option(props);
165
+ } else {
166
+ if (
167
+ !isWellBehavedNumber(props.x1) || !isWellBehavedNumber(props.y1) ||
168
+ !isWellBehavedNumber(props.x2) ||
169
+ !isWellBehavedNumber(props.y2)
170
+ ) {
171
+ return null;
172
+ }
173
+ line = <line {...props} className="recharts-reference-line-line" />;
174
+ }
175
+
176
+ return line;
177
+ };
178
+
179
+ type EndPointsPropsSubset = Pick<PropsWithDefaults, 'y' | 'x' | 'segment' | 'ifOverflow'>;
180
+
181
+ const getHorizontalLineEndPoints = (
182
+ yCoord: number | string,
183
+ ifOverflow: IfOverflow,
184
+ position: Props['position'],
185
+ yAxisOrientation: Props['orientation'],
186
+ yAxisScale: RechartsScale,
187
+ viewBox: CartesianViewBoxRequired,
188
+ ): ReadonlyArray<Coordinate> | null => {
189
+ const { x, width } = viewBox;
190
+ const coord = yAxisScale.map(yCoord, { position });
191
+ // don't render the line if the scale can't compute a result that makes sense
192
+ if (!isWellBehavedNumber(coord)) {
193
+ return null;
194
+ }
195
+
196
+ if (ifOverflow === 'discard' && !yAxisScale.isInRange(coord)) {
197
+ return null;
198
+ }
199
+
200
+ const points = [
201
+ { x: x + width, y: coord },
202
+ { x, y: coord },
203
+ ];
204
+ return yAxisOrientation === 'left' ? points.reverse() : points;
205
+ };
206
+
207
+ const getVerticalLineEndPoints = (
208
+ xCoord: number | string,
209
+ ifOverflow: IfOverflow,
210
+ position: Props['position'],
211
+ xAxisOrientation: Props['orientation'],
212
+ xAxisScale: RechartsScale,
213
+ viewBox: CartesianViewBoxRequired,
214
+ ): ReadonlyArray<Coordinate> | null => {
215
+ const { y, height } = viewBox;
216
+ const coord = xAxisScale.map(xCoord, { position });
217
+ // don't render the line if the scale can't compute a result that makes sense
218
+ if (!isWellBehavedNumber(coord)) {
219
+ return null;
220
+ }
221
+
222
+ if (ifOverflow === 'discard' && !xAxisScale.isInRange(coord)) {
223
+ return null;
224
+ }
225
+
226
+ const points = [
227
+ { x: coord, y: y + height },
228
+ { x: coord, y },
229
+ ];
230
+ return xAxisOrientation === 'top' ? points.reverse() : points;
231
+ };
232
+
233
+ const getSegmentLineEndPoints = (
234
+ segment: ReferenceLineSegment,
235
+ ifOverflow: IfOverflow,
236
+ position: Props['position'],
237
+ scales: CartesianScaleHelper,
238
+ ): ReadonlyArray<Coordinate> | null => {
239
+ const points: [Coordinate, Coordinate] = [
240
+ scales.mapWithFallback(segment[0], { position, fallback: 'rangeMin' }),
241
+ scales.mapWithFallback(segment[1], { position, fallback: 'rangeMax' }),
242
+ ];
243
+
244
+ if (ifOverflow === 'discard' && points.some((p) => !scales.isInRange(p))) {
245
+ return null;
246
+ }
247
+
248
+ return points;
249
+ };
250
+
251
+ export const getEndPoints = (
252
+ xAxisScale: RechartsScale,
253
+ yAxisScale: RechartsScale,
254
+ viewBox: CartesianViewBoxRequired,
255
+ position: Props['position'],
256
+ xAxisOrientation: Props['orientation'],
257
+ yAxisOrientation: Props['orientation'],
258
+ props: EndPointsPropsSubset,
259
+ ): ReadonlyArray<Coordinate> | null => {
260
+ const { x: xCoord, y: yCoord, segment, ifOverflow } = props;
261
+ const isFixedX = isNumOrStr(xCoord);
262
+ const isFixedY = isNumOrStr(yCoord);
263
+
264
+ if (isFixedY) {
265
+ return getHorizontalLineEndPoints(
266
+ yCoord,
267
+ ifOverflow,
268
+ position,
269
+ yAxisOrientation,
270
+ yAxisScale,
271
+ viewBox,
272
+ );
273
+ }
274
+ if (isFixedX) {
275
+ return getVerticalLineEndPoints(
276
+ xCoord,
277
+ ifOverflow,
278
+ position,
279
+ xAxisOrientation,
280
+ xAxisScale,
281
+ viewBox,
282
+ );
283
+ }
284
+ if (segment != null && segment.length === 2) {
285
+ return getSegmentLineEndPoints(
286
+ segment,
287
+ ifOverflow,
288
+ position,
289
+ new CartesianScaleHelperImpl({ x: xAxisScale, y: yAxisScale }),
290
+ );
291
+ }
292
+
293
+ return null;
294
+ };
295
+
296
+ export function ReportReferenceLine(props: ReferenceLineSettings): null {
297
+ const dispatch = useAppDispatch();
298
+ const { xAxisId, yAxisId, ifOverflow, x, y, segment } = props;
299
+ const segmentStartX = segment?.[0]?.x;
300
+ const segmentStartY = segment?.[0]?.y;
301
+ const segmentEndX = segment?.[1]?.x;
302
+ const segmentEndY = segment?.[1]?.y;
303
+ useEffect(() => {
304
+ const settings: ReferenceLineSettings = {
305
+ xAxisId,
306
+ yAxisId,
307
+ ifOverflow,
308
+ x,
309
+ y,
310
+ segment: segment == null
311
+ ? segment
312
+ : [
313
+ { x: segmentStartX, y: segmentStartY },
314
+ { x: segmentEndX, y: segmentEndY },
315
+ ],
316
+ };
317
+ dispatch(addLine(settings));
318
+ return () => {
319
+ dispatch(removeLine(settings));
320
+ };
321
+ }, [
322
+ dispatch,
323
+ ifOverflow,
324
+ segmentEndX,
325
+ segmentEndY,
326
+ segmentStartX,
327
+ segmentStartY,
328
+ x,
329
+ xAxisId,
330
+ y,
331
+ yAxisId,
332
+ ]);
333
+ return null;
334
+ }
335
+
336
+ function ReferenceLineImpl(props: PropsWithDefaults) {
337
+ const { xAxisId, yAxisId, shape, className, ifOverflow } = props;
338
+
339
+ const isPanorama = useIsPanorama();
340
+ const clipPathId = useClipPathId();
341
+ const xAxis = useAppSelector((state) => selectXAxisSettings(state, xAxisId));
342
+ const yAxis = useAppSelector((state) => selectYAxisSettings(state, yAxisId));
343
+ const xAxisScale = useAppSelector(
344
+ (state) => selectAxisScale(state, 'xAxis', xAxisId, isPanorama),
345
+ );
346
+ const yAxisScale = useAppSelector(
347
+ (state) => selectAxisScale(state, 'yAxis', yAxisId, isPanorama),
348
+ );
349
+
350
+ const viewBox = useViewBox();
351
+
352
+ if (
353
+ !clipPathId || !viewBox || xAxis == null || yAxis == null || xAxisScale == null ||
354
+ yAxisScale == null
355
+ ) {
356
+ return null;
357
+ }
358
+
359
+ const endPoints: ReadonlyArray<Coordinate> | null = getEndPoints(
360
+ xAxisScale,
361
+ yAxisScale,
362
+ viewBox,
363
+ props.position,
364
+ xAxis.orientation,
365
+ yAxis.orientation,
366
+ props,
367
+ );
368
+ if (!endPoints) {
369
+ return null;
370
+ }
371
+
372
+ const point1 = endPoints[0];
373
+ const point2 = endPoints[1];
374
+ if (point1 == null || point2 == null) {
375
+ return null;
376
+ }
377
+ const { x: x1, y: y1 } = point1;
378
+ const { x: x2, y: y2 } = point2;
379
+
380
+ const clipPath =
381
+ ifOverflow === 'hidden' ? `url(#${clipPathId})` : undefined;
382
+
383
+ const lineProps: SVGProps<SVGLineElement> = {
384
+ clipPath,
385
+ ...svgPropertiesAndEvents(props),
386
+ x1,
387
+ y1,
388
+ x2,
389
+ y2,
390
+ };
391
+
392
+ const rect = rectWithCoords({ x1, y1, x2, y2 });
393
+
394
+ return <ZIndexLayer zIndex={props.zIndex}>
395
+ <Layer className={clsx('recharts-reference-line', className)}>
396
+ {renderLine(shape, lineProps)}
397
+ <CartesianLabelContextProvider {...rect} lowerWidth={rect.width} upperWidth={rect.width}>
398
+ <CartesianLabelFromLabelProp label={props.label} />
399
+ {props.children}
400
+ </CartesianLabelContextProvider>
401
+ </Layer>
402
+ </ZIndexLayer>;
403
+ }
404
+
405
+ export const referenceLineDefaultProps = {
406
+ ifOverflow: 'discard',
407
+ xAxisId: 0,
408
+ yAxisId: 0,
409
+ fill: 'none',
410
+ label: false,
411
+ stroke: '#ccc',
412
+ fillOpacity: 1,
413
+ strokeWidth: 1,
414
+ position: 'middle',
415
+ zIndex: DefaultZIndexes.line,
416
+ } as const satisfies Partial<Props>;
417
+
418
+ type PropsWithDefaults = RequiresDefaultProps<Props, typeof referenceLineDefaultProps>;
419
+
420
+ /**
421
+ * Draws a line on the chart connecting two points.
422
+ *
423
+ * This component, unlike {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/line line}, is aware of the cartesian coordinate system,
424
+ * so you specify the dimensions by using data coordinates instead of pixels.
425
+ *
426
+ * ReferenceLine will calculate the pixels based on the provided data coordinates.
427
+ *
428
+ * If you prefer to render using pixels rather than data coordinates,
429
+ * consider using the {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/line line SVG element} instead.
430
+ *
431
+ * @provides CartesianLabelContext
432
+ * @consumes CartesianChartContext
433
+ */
434
+ export function ReferenceLine<
435
+ XValueType extends ReferenceCoordinateValue = any,
436
+ YValueType extends ReferenceCoordinateValue = any,
437
+ >(outsideProps: Props<XValueType, YValueType>) {
438
+ const props: PropsWithDefaults = resolveDefaultProps(outsideProps, referenceLineDefaultProps);
439
+ return <>
440
+ <ReportReferenceLine
441
+ yAxisId={props.yAxisId}
442
+ xAxisId={props.xAxisId}
443
+ ifOverflow={props.ifOverflow}
444
+ x={props.x}
445
+ y={props.y}
446
+ segment={props.segment}
447
+ />
448
+ <ReferenceLineImpl {...props} />
449
+ </>;
450
+ }
451
+
452
+ ReferenceLine.displayName = 'ReferenceLine';
@@ -0,0 +1,178 @@
1
+ /**
2
+ * @fileOverview Reference Line
3
+ */
4
+ import * as React from 'octane';
5
+ import { ReactElement, SVGProps } from 'octane';
6
+ import { ImplicitLabelType } from '../component/Label';
7
+ import { Overflowable } from '../util/IfOverflow';
8
+ import { CartesianViewBoxRequired, Coordinate } from '../util/types';
9
+ import { RequiresDefaultProps } from '../util/resolveDefaultProps';
10
+ import { ZIndexable } from '../zIndex/ZIndexLayer';
11
+ import { BandPosition, RechartsScale } from '../util/scale/RechartsScale';
12
+ /**
13
+ * Single point that defines one end of a segment.
14
+ * These coordinates are in data space, meaning that you should provide
15
+ * values that correspond to the data domain of the axes.
16
+ * So you would provide a value of `Page A` to indicate the data value `Page A`
17
+ * and then recharts will convert that to pixels.
18
+ *
19
+ * Likewise for numbers. If your x-axis goes from 0 to 100,
20
+ * and you want the line to end at 50, you would provide `50` here.
21
+ *
22
+ * @inline
23
+ */
24
+ export type ReferenceLineSegment = readonly [
25
+ {
26
+ x?: number | string;
27
+ y?: number | string;
28
+ },
29
+ {
30
+ x?: number | string;
31
+ y?: number | string;
32
+ },
33
+ ];
34
+ type ReferenceCoordinateValue = number | string;
35
+ interface ReferenceLineProps<
36
+ XValueType extends ReferenceCoordinateValue = any,
37
+ YValueType extends ReferenceCoordinateValue = any,
38
+ >
39
+ extends Overflowable, ZIndexable {
40
+ /**
41
+ * If defined, renders a horizontal line on this position.
42
+ *
43
+ * This value is using your chart's domain, so you will provide a data value instead of a pixel value.
44
+ * ReferenceLine will internally calculate the correct pixel position.
45
+ *
46
+ * @example <ReferenceLine y="Page D" />
47
+ */
48
+ y?: YValueType;
49
+ /**
50
+ * If defined, renders a vertical line on this position.
51
+ *
52
+ * This value is using your chart's domain, so you will provide a data value instead of a pixel value.
53
+ * ReferenceLine will internally calculate the correct pixel position.
54
+ *
55
+ * @example <ReferenceLine x="Monday" />
56
+ */
57
+ x?: XValueType;
58
+ /**
59
+ * Tuple of coordinates. If defined, renders a diagonal line segment.
60
+ */
61
+ segment?: readonly [
62
+ {
63
+ x?: XValueType;
64
+ y?: YValueType;
65
+ },
66
+ {
67
+ x?: XValueType;
68
+ y?: YValueType;
69
+ },
70
+ ];
71
+ /**
72
+ * The position of the reference line when the axis has bandwidth
73
+ * (e.g., a band scale). This determines where within the band
74
+ * the line is drawn.
75
+ * @defaultValue 'middle'
76
+ */
77
+ position?: BandPosition;
78
+ className?: number | string;
79
+ /**
80
+ * The id of y-axis which is corresponding to the data.
81
+ * Required when there are multiple YAxes.
82
+ * @defaultValue 0
83
+ */
84
+ yAxisId?: number | string;
85
+ /**
86
+ * The id of x-axis which is corresponding to the data.
87
+ * Required when there are multiple XAxes.
88
+ * @defaultValue 0
89
+ */
90
+ xAxisId?: number | string;
91
+ shape?: ReactElement<SVGElement> | ((props: any) => ReactElement<SVGElement>);
92
+ /**
93
+ * Renders a single label.
94
+ *
95
+ * - `false`: no labels are rendered
96
+ * - `string` | `number`: the content of the label
97
+ * - `object`: the props of LabelList component
98
+ * - `ReactElement`: a custom SVG label element, such as `<text>` or `<g>`.
99
+ * HTML elements such as `<div>` are not valid inside the chart SVG and may trigger React DOM warnings.
100
+ * - `function`: a render function of custom label
101
+ *
102
+ * @defaultValue false
103
+ *
104
+ * @see {@link https://recharts.github.io/en-US/examples/LineChartWithReferenceLines/ Reference elements with a label}
105
+ */
106
+ label?: ImplicitLabelType;
107
+ /**
108
+ * Z-Index of this component and its children. The higher the value,
109
+ * the more on top it will be rendered.
110
+ * Components with higher zIndex will appear in front of components with lower zIndex.
111
+ * If undefined or 0, the content is rendered in the default layer without portals.
112
+ *
113
+ * @since 3.4
114
+ * @defaultValue 400
115
+ * @see {@link https://recharts.github.io/en-US/guide/zIndex/ Z-Index and layers guide}
116
+ */
117
+ zIndex?: number;
118
+ /**
119
+ * The width of the stroke
120
+ * @defaultValue 1
121
+ */
122
+ strokeWidth?: number | string;
123
+ }
124
+ /**
125
+ * This excludes `viewBox` prop from svg for two reasons:
126
+ * 1. The components wants viewBox of object type, and svg wants string
127
+ * - so there's a conflict, and the component will throw if it gets string
128
+ * 2. Internally the component calls `svgPropertiesNoEvents` which filters the viewBox away anyway
129
+ */
130
+ export type Props<
131
+ XValueType extends ReferenceCoordinateValue = any,
132
+ YValueType extends ReferenceCoordinateValue = any,
133
+ > = Omit<SVGProps<SVGLineElement>, 'viewBox'> & ReferenceLineProps<XValueType, YValueType>;
134
+ type EndPointsPropsSubset = Pick<PropsWithDefaults, 'y' | 'x' | 'segment' | 'ifOverflow'>;
135
+ export declare const getEndPoints: (
136
+ xAxisScale: RechartsScale,
137
+ yAxisScale: RechartsScale,
138
+ viewBox: CartesianViewBoxRequired,
139
+ position: Props['position'],
140
+ xAxisOrientation: Props['orientation'],
141
+ yAxisOrientation: Props['orientation'],
142
+ props: EndPointsPropsSubset,
143
+ ) => ReadonlyArray<Coordinate> | null;
144
+ export declare const referenceLineDefaultProps: {
145
+ readonly ifOverflow: 'discard';
146
+ readonly xAxisId: 0;
147
+ readonly yAxisId: 0;
148
+ readonly fill: 'none';
149
+ readonly label: false;
150
+ readonly stroke: '#ccc';
151
+ readonly fillOpacity: 1;
152
+ readonly strokeWidth: 1;
153
+ readonly position: 'middle';
154
+ readonly zIndex: 400;
155
+ };
156
+ type PropsWithDefaults = RequiresDefaultProps<Props, typeof referenceLineDefaultProps>;
157
+ /**
158
+ * Draws a line on the chart connecting two points.
159
+ *
160
+ * This component, unlike {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/line line}, is aware of the cartesian coordinate system,
161
+ * so you specify the dimensions by using data coordinates instead of pixels.
162
+ *
163
+ * ReferenceLine will calculate the pixels based on the provided data coordinates.
164
+ *
165
+ * If you prefer to render using pixels rather than data coordinates,
166
+ * consider using the {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Reference/Element/line line SVG element} instead.
167
+ *
168
+ * @provides CartesianLabelContext
169
+ * @consumes CartesianChartContext
170
+ */
171
+ export declare function ReferenceLine<
172
+ XValueType extends ReferenceCoordinateValue = any,
173
+ YValueType extends ReferenceCoordinateValue = any,
174
+ >(outsideProps: Props<XValueType, YValueType>): React.JSX.Element;
175
+ export declare namespace ReferenceLine {
176
+ var displayName: string;
177
+ }
178
+ export {};