@octanejs/recharts 0.1.0
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.
- package/LICENSE +21 -0
- package/package.json +53 -0
- package/src/animation/AnimatedItems.tsrx +82 -0
- package/src/animation/AnimationControllerImpl.js +33 -0
- package/src/animation/AnimationHandle.js +291 -0
- package/src/animation/JavascriptAnimate.tsrx +81 -0
- package/src/animation/easing.js +193 -0
- package/src/animation/matchBy.js +279 -0
- package/src/animation/timeoutController.js +49 -0
- package/src/animation/useAnimationController.ts +22 -0
- package/src/animation/useAnimationStartSnapshot.ts +43 -0
- package/src/animation/util.js +11 -0
- package/src/cartesian/Bar.ts +4 -0
- package/src/cartesian/Bar.tsrx +716 -0
- package/src/cartesian/Bar.tsrx.d.ts +4 -0
- package/src/cartesian/BarStack.tsrx +97 -0
- package/src/cartesian/BarStack.tsrx.d.ts +6 -0
- package/src/cartesian/CartesianAxis.tsrx +413 -0
- package/src/cartesian/CartesianAxis.tsrx.d.ts +3 -0
- package/src/cartesian/GraphicalItemClipPath.tsrx +44 -0
- package/src/cartesian/Line.ts +4 -0
- package/src/cartesian/Line.tsrx +544 -0
- package/src/cartesian/Line.tsrx.d.ts +4 -0
- package/src/cartesian/LineDrawShape.tsrx +106 -0
- package/src/cartesian/LineDrawShape.tsrx.d.ts +2 -0
- package/src/cartesian/XAxis.tsrx +156 -0
- package/src/cartesian/XAxis.tsrx.d.ts +3 -0
- package/src/cartesian/YAxis.tsrx +183 -0
- package/src/cartesian/YAxis.tsrx.d.ts +3 -0
- package/src/cartesian/getCartesianPosition.js +277 -0
- package/src/cartesian/getEquidistantTicks.js +133 -0
- package/src/cartesian/getTicks.js +280 -0
- package/src/cartesian/useAnimatedLineLength.ts +33 -0
- package/src/chart/BarChart.tsrx +22 -0
- package/src/chart/BarChart.tsrx.d.ts +2 -0
- package/src/chart/CartesianChart.tsrx +76 -0
- package/src/chart/CartesianChart.tsrx.d.ts +10 -0
- package/src/chart/CategoricalChart.tsrx +54 -0
- package/src/chart/LineChart.tsrx +22 -0
- package/src/chart/LineChart.tsrx.d.ts +2 -0
- package/src/chart/RechartsWrapper.tsrx +294 -0
- package/src/component/ActivePoints.tsrx +76 -0
- package/src/component/Cell.ts +37 -0
- package/src/component/Dots.tsrx +74 -0
- package/src/component/Label.tsrx +309 -0
- package/src/component/Label.tsrx.d.ts +12 -0
- package/src/component/LabelList.tsrx +83 -0
- package/src/component/LabelList.tsrx.d.ts +8 -0
- package/src/component/ResponsiveContainer.ts +22 -0
- package/src/component/Text.tsrx +281 -0
- package/src/component/Text.tsrx.d.ts +9 -0
- package/src/component/responsiveContainerUtils.js +111 -0
- package/src/container/ClipPathProvider.tsrx +29 -0
- package/src/container/Layer.tsrx +9 -0
- package/src/container/Layer.tsrx.d.ts +6 -0
- package/src/container/RootSurface.tsrx +76 -0
- package/src/container/Surface.tsrx +23 -0
- package/src/container/Surface.tsrx.d.ts +12 -0
- package/src/context/CellsContext.ts +80 -0
- package/src/context/ErrorBarContext.tsrx +53 -0
- package/src/context/PanoramaContext.ts +10 -0
- package/src/context/RegisterGraphicalItemId.tsrx +19 -0
- package/src/context/accessibilityContext.js +10 -0
- package/src/context/chartDataContext.ts +57 -0
- package/src/context/chartLayoutContext.ts +171 -0
- package/src/context/legendPortalContext.ts +5 -0
- package/src/context/tooltipContext.js +55 -0
- package/src/context/tooltipPortalContext.ts +5 -0
- package/src/hooks.js +509 -0
- package/src/index.ts +64 -0
- package/src/internal.ts +37 -0
- package/src/polar/defaultPolarAngleAxisProps.js +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.js +24 -0
- package/src/shape/Cross.tsrx +25 -0
- package/src/shape/Cross.tsrx.d.ts +12 -0
- package/src/shape/Curve.tsrx +132 -0
- package/src/shape/Curve.tsrx.d.ts +42 -0
- package/src/shape/Dot.tsrx +21 -0
- package/src/shape/Dot.tsrx.d.ts +9 -0
- package/src/shape/Polygon.tsrx +95 -0
- package/src/shape/Polygon.tsrx.d.ts +13 -0
- package/src/shape/Rectangle.tsrx +162 -0
- package/src/shape/Rectangle.tsrx.d.ts +31 -0
- package/src/shape/Sector.tsrx +219 -0
- package/src/shape/Sector.tsrx.d.ts +29 -0
- package/src/shape/Symbols.tsrx +95 -0
- package/src/shape/Symbols.tsrx.d.ts +15 -0
- package/src/shape/Trapezoid.tsrx +56 -0
- package/src/shape/Trapezoid.tsrx.d.ts +29 -0
- package/src/state/RechartsReduxContext.ts +7 -0
- package/src/state/RechartsStoreProvider.tsrx +24 -0
- package/src/state/ReportChartProps.ts +13 -0
- package/src/state/ReportEventSettings.ts +15 -0
- package/src/state/ReportMainChartProps.ts +22 -0
- package/src/state/SetGraphicalItem.ts +61 -0
- package/src/state/SetLegendPayload.ts +61 -0
- package/src/state/SetTooltipEntrySettings.ts +40 -0
- package/src/state/brushSlice.js +36 -0
- package/src/state/cartesianAxisSlice.js +256 -0
- package/src/state/chartDataSlice.js +67 -0
- package/src/state/errorBarSlice.js +53 -0
- package/src/state/eventSettingsSlice.js +25 -0
- package/src/state/externalEventsMiddleware.js +127 -0
- package/src/state/graphicalItemsSlice.js +91 -0
- package/src/state/hooks.ts +46 -0
- package/src/state/keyboardEventsMiddleware.js +226 -0
- package/src/state/layoutSlice.js +57 -0
- package/src/state/legendSlice.js +83 -0
- package/src/state/mouseEventsMiddleware.js +130 -0
- package/src/state/optionsSlice.js +45 -0
- package/src/state/polarAxisSlice.js +33 -0
- package/src/state/polarOptionsSlice.js +26 -0
- package/src/state/reduxDevtoolsJsonStringifyReplacer.js +14 -0
- package/src/state/referenceElementsSlice.js +51 -0
- package/src/state/renderedTicksSlice.js +41 -0
- package/src/state/rootPropsSlice.js +48 -0
- package/src/state/selectors/arrayEqualityCheck.js +32 -0
- package/src/state/selectors/axisSelectors.js +2113 -0
- package/src/state/selectors/barSelectors.js +263 -0
- package/src/state/selectors/barStackSelectors.js +65 -0
- package/src/state/selectors/brushSelectors.js +21 -0
- package/src/state/selectors/combiners/combineActiveLabel.js +18 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.js +75 -0
- package/src/state/selectors/combiners/combineAllBarPositions.js +169 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.js +11 -0
- package/src/state/selectors/combiners/combineBarPosition.js +17 -0
- package/src/state/selectors/combiners/combineBarSizeList.js +115 -0
- package/src/state/selectors/combiners/combineCheckedDomain.js +44 -0
- package/src/state/selectors/combiners/combineConfiguredScale.js +46 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.js +48 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.js +54 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.js +12 -0
- package/src/state/selectors/combiners/combineRealScaleType.js +36 -0
- package/src/state/selectors/combiners/combineStackedData.js +22 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.js +121 -0
- package/src/state/selectors/combiners/combineTooltipPayload.js +248 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.js +59 -0
- package/src/state/selectors/containerSelectors.js +6 -0
- package/src/state/selectors/dataSelectors.js +97 -0
- package/src/state/selectors/graphicalItemSelectors.js +25 -0
- package/src/state/selectors/legendSelectors.js +18 -0
- package/src/state/selectors/lineSelectors.js +106 -0
- package/src/state/selectors/numberDomainEqualityCheck.js +11 -0
- package/src/state/selectors/pickAxisId.js +3 -0
- package/src/state/selectors/pickAxisType.js +3 -0
- package/src/state/selectors/polarAxisSelectors.js +237 -0
- package/src/state/selectors/rootPropsSelectors.js +13 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.js +23 -0
- package/src/state/selectors/selectAllAxes.js +15 -0
- package/src/state/selectors/selectChartOffset.js +12 -0
- package/src/state/selectors/selectChartOffsetInternal.js +174 -0
- package/src/state/selectors/selectPlotArea.js +19 -0
- package/src/state/selectors/selectTooltipAxisId.js +3 -0
- package/src/state/selectors/selectTooltipAxisType.js +25 -0
- package/src/state/selectors/selectTooltipEventType.js +27 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.js +3 -0
- package/src/state/selectors/selectTooltipSettings.js +3 -0
- package/src/state/selectors/selectTooltipState.js +3 -0
- package/src/state/selectors/selectors.js +222 -0
- package/src/state/selectors/tooltipSelectors.js +471 -0
- package/src/state/selectors/touchSelectors.js +31 -0
- package/src/state/store.js +101 -0
- package/src/state/tooltipSlice.js +237 -0
- package/src/state/touchEventsMiddleware.js +140 -0
- package/src/state/types/StackedGraphicalItem.js +18 -0
- package/src/state/zIndexSlice.js +167 -0
- package/src/synchronisation/syncSelectors.js +5 -0
- package/src/synchronisation/useChartSynchronisation.tsrx +285 -0
- package/src/util/ActiveShapeUtils.tsrx +62 -0
- package/src/util/BarUtils.tsrx +35 -0
- package/src/util/CartesianUtils.js +66 -0
- package/src/util/ChartUtils.js +630 -0
- package/src/util/Constants.js +42 -0
- package/src/util/DOMUtils.js +180 -0
- package/src/util/DataUtils.js +199 -0
- package/src/util/Events.js +7 -0
- package/src/util/Global.js +13 -0
- package/src/util/LRUCache.js +58 -0
- package/src/util/LogUtils.js +29 -0
- package/src/util/PolarUtils.js +190 -0
- package/src/util/ReactUtils.ts +94 -0
- package/src/util/ReduceCSSCalc.js +260 -0
- package/src/util/TickUtils.js +43 -0
- package/src/util/YAxisUtils.js +43 -0
- package/src/util/axisPropsAreEqual.js +63 -0
- package/src/util/createEventProxy.js +18 -0
- package/src/util/excludeEventProps.js +172 -0
- package/src/util/getActiveCoordinate.js +253 -0
- package/src/util/getAxisTypeBasedOnLayout.js +17 -0
- package/src/util/getClassNameFromUnknown.js +8 -0
- package/src/util/getEveryNth.js +29 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.js +28 -0
- package/src/util/getRelativeCoordinate.js +96 -0
- package/src/util/getSliced.js +11 -0
- package/src/util/isDomainSpecifiedByUser.js +255 -0
- package/src/util/isWellBehavedNumber.js +8 -0
- package/src/util/propsAreEqual.js +96 -0
- package/src/util/resolveDefaultProps.js +131 -0
- package/src/util/round.js +39 -0
- package/src/util/scale/RechartsScale.js +68 -0
- package/src/util/scale/createCategoricalInverse.js +77 -0
- package/src/util/scale/getNiceTickValues.js +354 -0
- package/src/util/scale/index.js +3 -0
- package/src/util/scale/util/arithmetic.js +51 -0
- package/src/util/stacks/getStackSeriesIdentifier.js +10 -0
- package/src/util/svgPropertiesAndEvents.ts +29 -0
- package/src/util/svgPropertiesNoEvents.js +383 -0
- package/src/util/types.ts +59 -0
- package/src/util/useAnimationId.ts +14 -0
- package/src/util/useId.ts +13 -0
- package/src/util/usePrefersReducedMotion.ts +30 -0
- package/src/util/useReportScale.ts +26 -0
- package/src/util/useUniqueId.js +34 -0
- package/src/zIndex/DefaultZIndexes.js +75 -0
- package/src/zIndex/ZIndexLayer.tsrx +80 -0
- package/src/zIndex/ZIndexLayer.tsrx.d.ts +2 -0
- package/src/zIndex/ZIndexPortal.tsrx +43 -0
- package/src/zIndex/getZIndexFromUnknown.js +15 -0
- package/src/zIndex/zIndexSelectors.js +45 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Type declaration for the .tsrx component (resolved by relative path).
|
|
2
|
+
export interface CrossProps {
|
|
3
|
+
x?: number;
|
|
4
|
+
y?: number;
|
|
5
|
+
top?: number;
|
|
6
|
+
left?: number;
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
className?: unknown;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
}
|
|
12
|
+
export declare const Cross: (props: CrossProps) => unknown;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Port of shape/Curve.tsx — the line/area path. The `d` string comes straight
|
|
2
|
+
// from victory-vendor's d3-shape line/area generators (same dependency, same
|
|
3
|
+
// version as upstream), so output is byte-identical by construction.
|
|
4
|
+
import {
|
|
5
|
+
area as shapeArea,
|
|
6
|
+
curveBasis,
|
|
7
|
+
curveBasisClosed,
|
|
8
|
+
curveBasisOpen,
|
|
9
|
+
curveBumpX,
|
|
10
|
+
curveBumpY,
|
|
11
|
+
curveLinear,
|
|
12
|
+
curveLinearClosed,
|
|
13
|
+
curveMonotoneX,
|
|
14
|
+
curveMonotoneY,
|
|
15
|
+
curveNatural,
|
|
16
|
+
curveStep,
|
|
17
|
+
curveStepAfter,
|
|
18
|
+
curveStepBefore,
|
|
19
|
+
line as shapeLine,
|
|
20
|
+
} from 'victory-vendor/d3-shape';
|
|
21
|
+
import { clsx } from 'clsx';
|
|
22
|
+
import { adaptEventHandlers } from '../util/types.ts';
|
|
23
|
+
import { isNumber, upperFirst } from '../util/DataUtils';
|
|
24
|
+
import { isWellBehavedNumber } from '../util/isWellBehavedNumber';
|
|
25
|
+
import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
|
|
26
|
+
import { useChartLayout } from '../context/chartLayoutContext.ts';
|
|
27
|
+
|
|
28
|
+
const CURVE_FACTORIES = {
|
|
29
|
+
curveBasisClosed,
|
|
30
|
+
curveBasisOpen,
|
|
31
|
+
curveBasis,
|
|
32
|
+
curveBumpX,
|
|
33
|
+
curveBumpY,
|
|
34
|
+
curveLinearClosed,
|
|
35
|
+
curveLinear,
|
|
36
|
+
curveMonotoneX,
|
|
37
|
+
curveMonotoneY,
|
|
38
|
+
curveNatural,
|
|
39
|
+
curveStep,
|
|
40
|
+
curveStepAfter,
|
|
41
|
+
curveStepBefore,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const defined = (p) => isWellBehavedNumber(p.x) && isWellBehavedNumber(p.y);
|
|
45
|
+
const areaDefined = (d) => d.base != null && defined(d.base) && defined(d);
|
|
46
|
+
const getX = (p) => p.x;
|
|
47
|
+
const getY = (p) => p.y;
|
|
48
|
+
|
|
49
|
+
const getCurveFactory = (type, layout) => {
|
|
50
|
+
if (typeof type === 'function') {
|
|
51
|
+
return type;
|
|
52
|
+
}
|
|
53
|
+
const name = 'curve' + upperFirst(type);
|
|
54
|
+
if ((name === 'curveMonotone' || name === 'curveBump') && layout) {
|
|
55
|
+
const factory = CURVE_FACTORIES[name + (layout === 'vertical' ? 'Y' : 'X')];
|
|
56
|
+
if (factory) {
|
|
57
|
+
return factory;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return CURVE_FACTORIES[name] || curveLinear;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const defaultCurveProps = {
|
|
64
|
+
connectNulls: false,
|
|
65
|
+
type: 'linear',
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Calculate the path of curve. Returns null if points is an empty array.
|
|
70
|
+
* @return path or null
|
|
71
|
+
*/
|
|
72
|
+
export const getPath = ({
|
|
73
|
+
type = defaultCurveProps.type,
|
|
74
|
+
points = [],
|
|
75
|
+
baseLine,
|
|
76
|
+
layout,
|
|
77
|
+
connectNulls = defaultCurveProps.connectNulls,
|
|
78
|
+
}) => {
|
|
79
|
+
const curveFactory = getCurveFactory(type, layout);
|
|
80
|
+
const formatPoints =
|
|
81
|
+
connectNulls ? points.filter(defined) : points;
|
|
82
|
+
|
|
83
|
+
// An area chart's array `baseLine` pairs each point with its baseline
|
|
84
|
+
// counterpart FIRST, so the `defined` filter drops both sides together.
|
|
85
|
+
if (Array.isArray(baseLine)) {
|
|
86
|
+
const areaPoints = points.map((entry, index) => ({ ...entry, base: baseLine[index] }));
|
|
87
|
+
let lineFunction;
|
|
88
|
+
if (layout === 'vertical') {
|
|
89
|
+
lineFunction = shapeArea().y(getY).x1(getX).x0((d) => d.base.x);
|
|
90
|
+
} else {
|
|
91
|
+
lineFunction = shapeArea().x(getX).y1(getY).y0((d) => d.base.y);
|
|
92
|
+
}
|
|
93
|
+
const nullableLineFunction = lineFunction.defined(areaDefined).curve(curveFactory);
|
|
94
|
+
const finalPoints =
|
|
95
|
+
connectNulls ? areaPoints.filter(areaDefined) : areaPoints;
|
|
96
|
+
return nullableLineFunction(finalPoints);
|
|
97
|
+
}
|
|
98
|
+
let lineFunction;
|
|
99
|
+
if (layout === 'vertical' && isNumber(baseLine)) {
|
|
100
|
+
lineFunction = shapeArea().y(getY).x1(getX).x0(baseLine);
|
|
101
|
+
} else if (isNumber(baseLine)) {
|
|
102
|
+
lineFunction = shapeArea().x(getX).y1(getY).y0(baseLine);
|
|
103
|
+
} else {
|
|
104
|
+
lineFunction = shapeLine().x(getX).y(getY);
|
|
105
|
+
}
|
|
106
|
+
const nullableLineFunction = lineFunction.defined(defined).curve(curveFactory);
|
|
107
|
+
return nullableLineFunction(formatPoints);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export function Curve(props) {
|
|
111
|
+
const { className, points, path, pathRef } = props;
|
|
112
|
+
const layout = useChartLayout();
|
|
113
|
+
if ((!points || !points.length) && !path) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const getPathInput = {
|
|
117
|
+
type: props.type,
|
|
118
|
+
points: props.points,
|
|
119
|
+
baseLine: props.baseLine,
|
|
120
|
+
layout: props.layout || layout,
|
|
121
|
+
connectNulls: props.connectNulls,
|
|
122
|
+
};
|
|
123
|
+
const realPath =
|
|
124
|
+
points && points.length ? getPath(getPathInput) : path;
|
|
125
|
+
return <path
|
|
126
|
+
{...svgPropertiesNoEvents(props)}
|
|
127
|
+
{...adaptEventHandlers(props)}
|
|
128
|
+
className={clsx('recharts-curve', className)}
|
|
129
|
+
d={realPath === null ? undefined : realPath}
|
|
130
|
+
ref={pathRef}
|
|
131
|
+
/>;
|
|
132
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Type declaration for the .tsrx component (resolved by relative path).
|
|
2
|
+
export interface CurvePoint {
|
|
3
|
+
x: number | null;
|
|
4
|
+
y: number | null;
|
|
5
|
+
}
|
|
6
|
+
export type CurveType =
|
|
7
|
+
| 'basis'
|
|
8
|
+
| 'basisClosed'
|
|
9
|
+
| 'basisOpen'
|
|
10
|
+
| 'bump'
|
|
11
|
+
| 'bumpX'
|
|
12
|
+
| 'bumpY'
|
|
13
|
+
| 'linear'
|
|
14
|
+
| 'linearClosed'
|
|
15
|
+
| 'monotone'
|
|
16
|
+
| 'monotoneX'
|
|
17
|
+
| 'monotoneY'
|
|
18
|
+
| 'natural'
|
|
19
|
+
| 'step'
|
|
20
|
+
| 'stepAfter'
|
|
21
|
+
| 'stepBefore'
|
|
22
|
+
| ((...args: unknown[]) => unknown);
|
|
23
|
+
export interface CurveProps {
|
|
24
|
+
type?: CurveType;
|
|
25
|
+
points?: ReadonlyArray<CurvePoint>;
|
|
26
|
+
baseLine?: number | ReadonlyArray<CurvePoint>;
|
|
27
|
+
layout?: 'horizontal' | 'vertical';
|
|
28
|
+
connectNulls?: boolean;
|
|
29
|
+
path?: string;
|
|
30
|
+
pathRef?: unknown;
|
|
31
|
+
className?: unknown;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
export declare const defaultCurveProps: { connectNulls: boolean; type: 'linear' };
|
|
35
|
+
export declare const getPath: (input: {
|
|
36
|
+
type?: CurveType;
|
|
37
|
+
points?: ReadonlyArray<CurvePoint>;
|
|
38
|
+
baseLine?: number | ReadonlyArray<CurvePoint>;
|
|
39
|
+
layout?: 'horizontal' | 'vertical';
|
|
40
|
+
connectNulls?: boolean;
|
|
41
|
+
}) => string | null;
|
|
42
|
+
export declare const Curve: (props: CurveProps) => unknown;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Port of shape/Dot.tsx — a circle marker.
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { adaptEventHandlers } from '../util/types.ts';
|
|
4
|
+
import { svgPropertiesNoEvents } from '../util/svgPropertiesNoEvents';
|
|
5
|
+
import { isNumber } from '../util/DataUtils';
|
|
6
|
+
|
|
7
|
+
export function Dot(props) {
|
|
8
|
+
const { cx, cy, r, className } = props;
|
|
9
|
+
const layerClass = clsx('recharts-dot', className);
|
|
10
|
+
if (isNumber(cx) && isNumber(cy) && isNumber(r)) {
|
|
11
|
+
return <circle
|
|
12
|
+
{...svgPropertiesNoEvents(props)}
|
|
13
|
+
{...adaptEventHandlers(props)}
|
|
14
|
+
className={layerClass}
|
|
15
|
+
cx={cx}
|
|
16
|
+
cy={cy}
|
|
17
|
+
r={r}
|
|
18
|
+
/>;
|
|
19
|
+
}
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// Port of shape/Polygon.tsx — closed/segmented polygon paths (Radar,
|
|
2
|
+
// PolarGrid). Path strings mirror upstream's roundTemplateLiteral output.
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents.ts';
|
|
5
|
+
import { round } from '../util/round';
|
|
6
|
+
|
|
7
|
+
function isValidatePoint(point) {
|
|
8
|
+
return point != null && point.x === +point.x && point.y === +point.y;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function getParsedPoints(points = []) {
|
|
12
|
+
let segmentPoints = [[]];
|
|
13
|
+
points.forEach((entry) => {
|
|
14
|
+
const lastLink = segmentPoints[segmentPoints.length - 1];
|
|
15
|
+
if (isValidatePoint(entry)) {
|
|
16
|
+
if (lastLink) {
|
|
17
|
+
lastLink.push(entry);
|
|
18
|
+
}
|
|
19
|
+
} else if (lastLink && lastLink.length > 0) {
|
|
20
|
+
segmentPoints.push([]);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const firstPoint = points[0];
|
|
24
|
+
const lastLink = segmentPoints[segmentPoints.length - 1];
|
|
25
|
+
if (isValidatePoint(firstPoint) && lastLink) {
|
|
26
|
+
lastLink.push(firstPoint);
|
|
27
|
+
}
|
|
28
|
+
const finalLink = segmentPoints[segmentPoints.length - 1];
|
|
29
|
+
if (finalLink && finalLink.length <= 0) {
|
|
30
|
+
segmentPoints = segmentPoints.slice(0, -1);
|
|
31
|
+
}
|
|
32
|
+
return segmentPoints;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getSinglePolygonPath(points, connectNulls) {
|
|
36
|
+
let segmentPoints = getParsedPoints(points);
|
|
37
|
+
if (connectNulls) {
|
|
38
|
+
segmentPoints = [segmentPoints.reduce((res, segPoints) => [...res, ...segPoints], [])];
|
|
39
|
+
}
|
|
40
|
+
const polygonPath = segmentPoints.map(
|
|
41
|
+
(segPoints) => segPoints.reduce(
|
|
42
|
+
(path, point, index) => path + (index === 0 ? 'M' : 'L') + round(point.x) + ',' +
|
|
43
|
+
round(point.y),
|
|
44
|
+
'',
|
|
45
|
+
),
|
|
46
|
+
).join('');
|
|
47
|
+
return segmentPoints.length === 1 ? polygonPath + 'Z' : polygonPath;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getRanglePath(points, baseLinePoints, connectNulls) {
|
|
51
|
+
const outerPath = getSinglePolygonPath(points, connectNulls);
|
|
52
|
+
return (outerPath.slice(-1) === 'Z' ? outerPath.slice(0, -1) : outerPath) + 'L' +
|
|
53
|
+
getSinglePolygonPath(Array.from(baseLinePoints).reverse(), connectNulls).slice(1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function Polygon(props) {
|
|
57
|
+
const { points, className, baseLinePoints, connectNulls, ...others } = props;
|
|
58
|
+
if (!points || !points.length) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
const layerClass = clsx('recharts-polygon', className);
|
|
62
|
+
if (baseLinePoints && baseLinePoints.length) {
|
|
63
|
+
const hasStroke = others.stroke && others.stroke !== 'none';
|
|
64
|
+
const rangePath = getRanglePath(points, baseLinePoints, connectNulls);
|
|
65
|
+
return <g className={layerClass}>
|
|
66
|
+
<path
|
|
67
|
+
{...svgPropertiesAndEvents(others)}
|
|
68
|
+
fill={rangePath.slice(-1) === 'Z' ? others.fill : 'none'}
|
|
69
|
+
stroke="none"
|
|
70
|
+
d={rangePath}
|
|
71
|
+
/>
|
|
72
|
+
{hasStroke
|
|
73
|
+
? <path
|
|
74
|
+
{...svgPropertiesAndEvents(others)}
|
|
75
|
+
fill="none"
|
|
76
|
+
d={getSinglePolygonPath(points, connectNulls)}
|
|
77
|
+
/>
|
|
78
|
+
: null}
|
|
79
|
+
{hasStroke
|
|
80
|
+
? <path
|
|
81
|
+
{...svgPropertiesAndEvents(others)}
|
|
82
|
+
fill="none"
|
|
83
|
+
d={getSinglePolygonPath(baseLinePoints, connectNulls)}
|
|
84
|
+
/>
|
|
85
|
+
: null}
|
|
86
|
+
</g>;
|
|
87
|
+
}
|
|
88
|
+
const singlePath = getSinglePolygonPath(points, connectNulls);
|
|
89
|
+
return <path
|
|
90
|
+
{...svgPropertiesAndEvents(others)}
|
|
91
|
+
fill={singlePath.slice(-1) === 'Z' ? others.fill : 'none'}
|
|
92
|
+
className={layerClass}
|
|
93
|
+
d={singlePath}
|
|
94
|
+
/>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Type declaration for the .tsrx component (resolved by relative path).
|
|
2
|
+
export interface PolygonPoint {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
export interface PolygonProps {
|
|
7
|
+
points?: ReadonlyArray<PolygonPoint>;
|
|
8
|
+
baseLinePoints?: ReadonlyArray<PolygonPoint>;
|
|
9
|
+
connectNulls?: boolean;
|
|
10
|
+
className?: unknown;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare const Polygon: (props: PolygonProps) => unknown;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Port of shape/Rectangle.tsx — a rectangle path with per-corner rounding.
|
|
2
|
+
// Phase 0 ports the STATIC path (isUpdateAnimationActive defaults false, and
|
|
3
|
+
// standalone Rectangles never animate); the width/height update animation and
|
|
4
|
+
// the getTotalLength entrance dash arrive with the Phase 5 animation port.
|
|
5
|
+
// Path strings must be BYTE-IDENTICAL to upstream: recharts builds them via
|
|
6
|
+
// roundTemplateLiteral (every interpolated number rounded to 4dp, template
|
|
7
|
+
// whitespace/newlines preserved verbatim) — mirrored exactly here.
|
|
8
|
+
import { clsx } from 'clsx';
|
|
9
|
+
import { resolveDefaultProps } from '../util/resolveDefaultProps';
|
|
10
|
+
import { round } from '../util/round';
|
|
11
|
+
import { svgPropertiesAndEvents } from '../util/svgPropertiesAndEvents.ts';
|
|
12
|
+
|
|
13
|
+
function getRectanglePath(x, y, width, height, radius) {
|
|
14
|
+
const roundedWidth = round(width);
|
|
15
|
+
const roundedHeight = round(height);
|
|
16
|
+
const maxRadius = Math.min(Math.abs(roundedWidth) / 2, Math.abs(roundedHeight) / 2);
|
|
17
|
+
const ySign =
|
|
18
|
+
roundedHeight >= 0 ? 1 : -1;
|
|
19
|
+
const xSign =
|
|
20
|
+
roundedWidth >= 0 ? 1 : -1;
|
|
21
|
+
const clockWise =
|
|
22
|
+
roundedHeight >= 0 && roundedWidth >= 0 || roundedHeight < 0 && roundedWidth < 0 ? 1 : 0;
|
|
23
|
+
let path;
|
|
24
|
+
|
|
25
|
+
if (maxRadius > 0 && Array.isArray(radius)) {
|
|
26
|
+
const newRadius = [0, 0, 0, 0];
|
|
27
|
+
for (let i = 0; i < 4; i++) {
|
|
28
|
+
const r = radius[i] ?? 0;
|
|
29
|
+
newRadius[i] = r > maxRadius ? maxRadius : r;
|
|
30
|
+
}
|
|
31
|
+
// roundTemplateLiteral`M${…},${…}` etc. — values rounded, whitespace verbatim.
|
|
32
|
+
path = 'M' + round(x) + ',' + round(y + ySign * newRadius[0]);
|
|
33
|
+
if (newRadius[0] > 0) {
|
|
34
|
+
path += 'A ' + round(newRadius[0]) + ',' + round(newRadius[0]) + ',0,0,' + round(clockWise) +
|
|
35
|
+
',' +
|
|
36
|
+
round(x + xSign * newRadius[0]) +
|
|
37
|
+
',' +
|
|
38
|
+
round(y);
|
|
39
|
+
}
|
|
40
|
+
path += 'L ' + round(x + width - xSign * newRadius[1]) + ',' + round(y);
|
|
41
|
+
if (newRadius[1] > 0) {
|
|
42
|
+
path += 'A ' + round(newRadius[1]) + ',' + round(newRadius[1]) + ',0,0,' + round(clockWise) +
|
|
43
|
+
',\n ' +
|
|
44
|
+
round(x + width) +
|
|
45
|
+
',' +
|
|
46
|
+
round(y + ySign * newRadius[1]);
|
|
47
|
+
}
|
|
48
|
+
path += 'L ' + round(x + width) + ',' + round(y + height - ySign * newRadius[2]);
|
|
49
|
+
if (newRadius[2] > 0) {
|
|
50
|
+
path += 'A ' + round(newRadius[2]) + ',' + round(newRadius[2]) + ',0,0,' + round(clockWise) +
|
|
51
|
+
',\n ' +
|
|
52
|
+
round(x + width - xSign * newRadius[2]) +
|
|
53
|
+
',' +
|
|
54
|
+
round(y + height);
|
|
55
|
+
}
|
|
56
|
+
path += 'L ' + round(x + xSign * newRadius[3]) + ',' + round(y + height);
|
|
57
|
+
if (newRadius[3] > 0) {
|
|
58
|
+
path += 'A ' + round(newRadius[3]) + ',' + round(newRadius[3]) + ',0,0,' + round(clockWise) +
|
|
59
|
+
',\n ' +
|
|
60
|
+
round(x) +
|
|
61
|
+
',' +
|
|
62
|
+
round(y + height - ySign * newRadius[3]);
|
|
63
|
+
}
|
|
64
|
+
path += 'Z';
|
|
65
|
+
} else if (maxRadius > 0 && radius === +radius && radius > 0) {
|
|
66
|
+
const r = Math.min(maxRadius, radius);
|
|
67
|
+
path = 'M ' + round(x) + ',' + round(y + ySign * r) + '\n A ' + round(r) + ',' +
|
|
68
|
+
round(r) +
|
|
69
|
+
',0,0,' +
|
|
70
|
+
round(clockWise) +
|
|
71
|
+
',' +
|
|
72
|
+
round(x + xSign * r) +
|
|
73
|
+
',' +
|
|
74
|
+
round(y) +
|
|
75
|
+
'\n L ' +
|
|
76
|
+
round(x + width - xSign * r) +
|
|
77
|
+
',' +
|
|
78
|
+
round(y) +
|
|
79
|
+
'\n A ' +
|
|
80
|
+
round(r) +
|
|
81
|
+
',' +
|
|
82
|
+
round(r) +
|
|
83
|
+
',0,0,' +
|
|
84
|
+
round(clockWise) +
|
|
85
|
+
',' +
|
|
86
|
+
round(x + width) +
|
|
87
|
+
',' +
|
|
88
|
+
round(y + ySign * r) +
|
|
89
|
+
'\n L ' +
|
|
90
|
+
round(x + width) +
|
|
91
|
+
',' +
|
|
92
|
+
round(y + height - ySign * r) +
|
|
93
|
+
'\n A ' +
|
|
94
|
+
round(r) +
|
|
95
|
+
',' +
|
|
96
|
+
round(r) +
|
|
97
|
+
',0,0,' +
|
|
98
|
+
round(clockWise) +
|
|
99
|
+
',' +
|
|
100
|
+
round(x + width - xSign * r) +
|
|
101
|
+
',' +
|
|
102
|
+
round(y + height) +
|
|
103
|
+
'\n L ' +
|
|
104
|
+
round(x + xSign * r) +
|
|
105
|
+
',' +
|
|
106
|
+
round(y + height) +
|
|
107
|
+
'\n A ' +
|
|
108
|
+
round(r) +
|
|
109
|
+
',' +
|
|
110
|
+
round(r) +
|
|
111
|
+
',0,0,' +
|
|
112
|
+
round(clockWise) +
|
|
113
|
+
',' +
|
|
114
|
+
round(x) +
|
|
115
|
+
',' +
|
|
116
|
+
round(y + height - ySign * r) +
|
|
117
|
+
' Z';
|
|
118
|
+
} else {
|
|
119
|
+
path = 'M ' + round(x) + ',' + round(y) + ' h ' + round(width) + ' v ' + round(height) + ' h ' +
|
|
120
|
+
round(-width) +
|
|
121
|
+
' Z';
|
|
122
|
+
}
|
|
123
|
+
return path;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export const defaultRectangleProps = {
|
|
127
|
+
x: 0,
|
|
128
|
+
y: 0,
|
|
129
|
+
width: 0,
|
|
130
|
+
height: 0,
|
|
131
|
+
radius: 0,
|
|
132
|
+
isAnimationActive: false,
|
|
133
|
+
isUpdateAnimationActive: false,
|
|
134
|
+
animationBegin: 0,
|
|
135
|
+
animationDuration: 1500,
|
|
136
|
+
animationEasing: 'ease',
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
export function Rectangle(rectangleProps) {
|
|
140
|
+
const props = resolveDefaultProps(rectangleProps, defaultRectangleProps);
|
|
141
|
+
const { x, y, width, height, radius, className } = props;
|
|
142
|
+
|
|
143
|
+
if (
|
|
144
|
+
x !== +x || y !== +y || width !== +width || height !== +height || width === 0 || height === 0
|
|
145
|
+
) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const layerClass = clsx('recharts-rectangle', className);
|
|
149
|
+
|
|
150
|
+
// Static path — the update-animation branch is a Phase 5 port.
|
|
151
|
+
const { radius: _radius, ...otherPathProps } = svgPropertiesAndEvents(props);
|
|
152
|
+
return <path
|
|
153
|
+
{...otherPathProps}
|
|
154
|
+
x={round(x)}
|
|
155
|
+
y={round(y)}
|
|
156
|
+
width={round(width)}
|
|
157
|
+
height={round(height)}
|
|
158
|
+
radius={typeof radius === 'number' ? radius : undefined}
|
|
159
|
+
className={layerClass}
|
|
160
|
+
d={getRectanglePath(x, y, width, height, radius)}
|
|
161
|
+
/>;
|
|
162
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Type declaration for the .tsrx component (resolved by relative path).
|
|
2
|
+
export interface RectangleProps {
|
|
3
|
+
x?: number;
|
|
4
|
+
y?: number;
|
|
5
|
+
width?: number;
|
|
6
|
+
height?: number;
|
|
7
|
+
radius?: number | [number, number, number, number];
|
|
8
|
+
className?: unknown;
|
|
9
|
+
isAnimationActive?: boolean;
|
|
10
|
+
isUpdateAnimationActive?: boolean;
|
|
11
|
+
animationBegin?: number;
|
|
12
|
+
animationDuration?: number;
|
|
13
|
+
animationEasing?: string;
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
export declare const defaultRectangleProps: Required<
|
|
17
|
+
Pick<
|
|
18
|
+
RectangleProps,
|
|
19
|
+
| 'x'
|
|
20
|
+
| 'y'
|
|
21
|
+
| 'width'
|
|
22
|
+
| 'height'
|
|
23
|
+
| 'radius'
|
|
24
|
+
| 'isAnimationActive'
|
|
25
|
+
| 'isUpdateAnimationActive'
|
|
26
|
+
| 'animationBegin'
|
|
27
|
+
| 'animationDuration'
|
|
28
|
+
| 'animationEasing'
|
|
29
|
+
>
|
|
30
|
+
>;
|
|
31
|
+
export declare const Rectangle: (props: RectangleProps) => unknown;
|