@solidports/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 +22 -0
- package/NOTICE +19 -0
- package/README.md +102 -0
- package/dist/dev.js +28564 -0
- package/dist/index.d.ts +7859 -0
- package/dist/index.js +28546 -0
- package/package.json +98 -0
- package/src/animation/AnimatedItems.tsx +183 -0
- package/src/animation/AnimationController.ts +33 -0
- package/src/animation/AnimationControllerImpl.ts +36 -0
- package/src/animation/AnimationHandle.ts +307 -0
- package/src/animation/CSSTransitionAnimate.tsx +170 -0
- package/src/animation/JavascriptAnimate.tsx +119 -0
- package/src/animation/easing.ts +221 -0
- package/src/animation/matchBy.ts +164 -0
- package/src/animation/timeoutController.ts +70 -0
- package/src/animation/useAnimationController.tsx +34 -0
- package/src/animation/useAnimationStartSnapshot.ts +118 -0
- package/src/animation/util.ts +41 -0
- package/src/cartesian/Area.tsx +915 -0
- package/src/cartesian/AreaRevealShape.tsx +190 -0
- package/src/cartesian/Bar.tsx +1369 -0
- package/src/cartesian/BarStack.tsx +152 -0
- package/src/cartesian/Brush.tsx +951 -0
- package/src/cartesian/CartesianAxis.tsx +722 -0
- package/src/cartesian/CartesianGrid.tsx +711 -0
- package/src/cartesian/ErrorBar.tsx +361 -0
- package/src/cartesian/Funnel.tsx +803 -0
- package/src/cartesian/GraphicalItemClipPath.tsx +67 -0
- package/src/cartesian/Line.tsx +863 -0
- package/src/cartesian/LineDrawShape.tsx +89 -0
- package/src/cartesian/ReferenceArea.tsx +331 -0
- package/src/cartesian/ReferenceDot.tsx +304 -0
- package/src/cartesian/ReferenceLine.tsx +474 -0
- package/src/cartesian/Scatter.tsx +888 -0
- package/src/cartesian/XAxis.tsx +433 -0
- package/src/cartesian/YAxis.tsx +443 -0
- package/src/cartesian/ZAxis.tsx +155 -0
- package/src/cartesian/cartesianPositionToCSSTranslate.tsx +29 -0
- package/src/cartesian/cartesianViewBoxToTrapezoid.tsx +21 -0
- package/src/cartesian/getCartesianPosition.tsx +267 -0
- package/src/cartesian/getEquidistantTicks.ts +144 -0
- package/src/cartesian/getTicks.ts +225 -0
- package/src/cartesian/isOutsidePosition.ts +15 -0
- package/src/cartesian/useAnimatedLineLength.ts +54 -0
- package/src/chart/AreaChart.tsx +29 -0
- package/src/chart/BarChart.tsx +29 -0
- package/src/chart/CartesianChart.tsx +131 -0
- package/src/chart/CategoricalChart.tsx +94 -0
- package/src/chart/ComposedChart.tsx +29 -0
- package/src/chart/FunnelChart.tsx +29 -0
- package/src/chart/LineChart.tsx +29 -0
- package/src/chart/PieChart.tsx +50 -0
- package/src/chart/PolarChart.tsx +164 -0
- package/src/chart/RadarChart.tsx +70 -0
- package/src/chart/RadialBarChart.tsx +46 -0
- package/src/chart/RechartsWrapper.tsx +551 -0
- package/src/chart/Sankey.tsx +1534 -0
- package/src/chart/ScatterChart.tsx +29 -0
- package/src/chart/SunburstChart.tsx +504 -0
- package/src/chart/Treemap.tsx +1223 -0
- package/src/chart/createInitialRootProps.ts +24 -0
- package/src/chart/types.ts +53 -0
- package/src/component/ActivePoints.tsx +144 -0
- package/src/component/Cell.tsx +37 -0
- package/src/component/Cursor.tsx +185 -0
- package/src/component/Customized.tsx +50 -0
- package/src/component/DefaultLegendContent.tsx +348 -0
- package/src/component/DefaultTooltipContent.tsx +224 -0
- package/src/component/Dots.tsx +157 -0
- package/src/component/Label.tsx +636 -0
- package/src/component/LabelList.tsx +375 -0
- package/src/component/Legend.tsx +512 -0
- package/src/component/ResponsiveContainer.tsx +348 -0
- package/src/component/Text.tsx +541 -0
- package/src/component/Tooltip.tsx +470 -0
- package/src/component/TooltipBoundingBox.tsx +146 -0
- package/src/component/responsiveContainerUtils.ts +134 -0
- package/src/container/ClipPathProvider.tsx +51 -0
- package/src/container/Layer.tsx +38 -0
- package/src/container/RootSurface.tsx +120 -0
- package/src/container/Surface.tsx +61 -0
- package/src/context/CellsContext.tsx +54 -0
- package/src/context/ErrorBarContext.tsx +146 -0
- package/src/context/GraphicalItemChildrenScope.tsx +18 -0
- package/src/context/PanoramaContext.tsx +9 -0
- package/src/context/RegisterGraphicalItemId.tsx +30 -0
- package/src/context/accessibilityContext.tsx +6 -0
- package/src/context/brushUpdateContext.tsx +9 -0
- package/src/context/chartDataContext.tsx +97 -0
- package/src/context/chartLayoutContext.tsx +201 -0
- package/src/context/legendPayloadContext.tsx +20 -0
- package/src/context/legendPortalContext.tsx +12 -0
- package/src/context/tooltipContext.tsx +89 -0
- package/src/context/tooltipPortalContext.tsx +12 -0
- package/src/context/useTooltipAxis.ts +22 -0
- package/src/hooks.ts +476 -0
- package/src/index.ts +280 -0
- package/src/polar/Pie.tsx +1360 -0
- package/src/polar/PolarAngleAxis.tsx +616 -0
- package/src/polar/PolarGrid.tsx +312 -0
- package/src/polar/PolarRadiusAxis.tsx +547 -0
- package/src/polar/Radar.tsx +734 -0
- package/src/polar/RadialBar.tsx +917 -0
- package/src/polar/defaultPolarAngleAxisProps.tsx +27 -0
- package/src/polar/defaultPolarRadiusAxisProps.tsx +25 -0
- package/src/shape/Cross.tsx +89 -0
- package/src/shape/Curve.tsx +343 -0
- package/src/shape/Dot.tsx +70 -0
- package/src/shape/Polygon.tsx +195 -0
- package/src/shape/Rectangle.tsx +470 -0
- package/src/shape/Sector.tsx +347 -0
- package/src/shape/Symbols.tsx +139 -0
- package/src/shape/Trapezoid.tsx +280 -0
- package/src/state/RechartsStateContext.tsx +12 -0
- package/src/state/RechartsStateProvider.tsx +87 -0
- package/src/state/RechartsStoreContext.tsx +25 -0
- package/src/state/RechartsStoreProvider.tsx +35 -0
- package/src/state/ReportChartProps.tsx +40 -0
- package/src/state/ReportEventSettings.tsx +30 -0
- package/src/state/ReportMainChartProps.tsx +61 -0
- package/src/state/ReportPolarOptions.tsx +35 -0
- package/src/state/SetGraphicalItem.ts +79 -0
- package/src/state/SetLegendPayload.ts +134 -0
- package/src/state/SetTooltipEntrySettings.tsx +72 -0
- package/src/state/actions.ts +464 -0
- package/src/state/brushSlice.ts +13 -0
- package/src/state/cartesianAxisSlice.ts +141 -0
- package/src/state/chartDataSlice.ts +50 -0
- package/src/state/chartState.ts +297 -0
- package/src/state/errorBarSlice.ts +29 -0
- package/src/state/eventSettingsSlice.ts +8 -0
- package/src/state/events.ts +76 -0
- package/src/state/externalEventsMiddleware.ts +255 -0
- package/src/state/graphicalItemsSlice.ts +74 -0
- package/src/state/hooks/useChartSelectors.tsx +45 -0
- package/src/state/keyboardEventsMiddleware.ts +228 -0
- package/src/state/layoutSlice.ts +21 -0
- package/src/state/legendSlice.ts +57 -0
- package/src/state/mouseEventsMiddleware.ts +185 -0
- package/src/state/optionsSlice.ts +47 -0
- package/src/state/polarAxisSlice.ts +10 -0
- package/src/state/polarOptionsSlice.ts +12 -0
- package/src/state/rawData.ts +26 -0
- package/src/state/referenceElementsSlice.ts +40 -0
- package/src/state/renderedTicksSlice.ts +15 -0
- package/src/state/rootPropsSlice.ts +47 -0
- package/src/state/selectors/areaSelectors.ts +240 -0
- package/src/state/selectors/arrayEqualityCheck.ts +29 -0
- package/src/state/selectors/axisSelectors.ts +2157 -0
- package/src/state/selectors/barSelectors.ts +310 -0
- package/src/state/selectors/barStackSelectors.ts +77 -0
- package/src/state/selectors/brushSelectors.ts +33 -0
- package/src/state/selectors/chartSelector.ts +185 -0
- package/src/state/selectors/combiners/combineActiveLabel.ts +16 -0
- package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +95 -0
- package/src/state/selectors/combiners/combineAllBarPositions.ts +122 -0
- package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +16 -0
- package/src/state/selectors/combiners/combineBarPosition.ts +23 -0
- package/src/state/selectors/combiners/combineBarSizeList.ts +80 -0
- package/src/state/selectors/combiners/combineCheckedDomain.ts +48 -0
- package/src/state/selectors/combiners/combineConfiguredScale.ts +111 -0
- package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +45 -0
- package/src/state/selectors/combiners/combineDisplayedStackedData.ts +50 -0
- package/src/state/selectors/combiners/combineInverseScaleFunction.ts +16 -0
- package/src/state/selectors/combiners/combineRealScaleType.ts +44 -0
- package/src/state/selectors/combiners/combineStackedData.ts +27 -0
- package/src/state/selectors/combiners/combineTooltipInteractionState.ts +86 -0
- package/src/state/selectors/combiners/combineTooltipPayload.ts +205 -0
- package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +58 -0
- package/src/state/selectors/containerSelectors.ts +12 -0
- package/src/state/selectors/dataSelectors.ts +88 -0
- package/src/state/selectors/funnelSelectors.ts +75 -0
- package/src/state/selectors/graphicalItemSelectors.ts +30 -0
- package/src/state/selectors/legendSelectors.ts +29 -0
- package/src/state/selectors/lineSelectors.ts +134 -0
- package/src/state/selectors/numberDomainEqualityCheck.ts +14 -0
- package/src/state/selectors/pickAxisId.ts +5 -0
- package/src/state/selectors/pickAxisType.ts +3 -0
- package/src/state/selectors/pieSelectors.ts +97 -0
- package/src/state/selectors/polarAxisSelectors.ts +201 -0
- package/src/state/selectors/polarGridSelectors.ts +28 -0
- package/src/state/selectors/polarScaleSelectors.ts +133 -0
- package/src/state/selectors/polarSelectors.ts +219 -0
- package/src/state/selectors/radarSelectors.ts +191 -0
- package/src/state/selectors/radialBarSelectors.ts +435 -0
- package/src/state/selectors/rootPropsSelectors.ts +25 -0
- package/src/state/selectors/scatterSelectors.ts +96 -0
- package/src/state/selectors/selectActivePropsFromChartPointer.ts +26 -0
- package/src/state/selectors/selectAllAxes.ts +17 -0
- package/src/state/selectors/selectChartOffset.ts +16 -0
- package/src/state/selectors/selectChartOffsetInternal.ts +136 -0
- package/src/state/selectors/selectLegendArea.ts +20 -0
- package/src/state/selectors/selectPlotArea.ts +22 -0
- package/src/state/selectors/selectTooltipAxisId.ts +7 -0
- package/src/state/selectors/selectTooltipAxisType.ts +32 -0
- package/src/state/selectors/selectTooltipEventType.ts +48 -0
- package/src/state/selectors/selectTooltipPayloadSearcher.ts +6 -0
- package/src/state/selectors/selectTooltipSettings.ts +39 -0
- package/src/state/selectors/selectTooltipState.ts +8 -0
- package/src/state/selectors/selectors.ts +271 -0
- package/src/state/selectors/tooltipSelectors.ts +578 -0
- package/src/state/selectors/touchSelectors.ts +31 -0
- package/src/state/store.ts +29 -0
- package/src/state/storeIdentity.ts +9 -0
- package/src/state/teardownWrite.ts +10 -0
- package/src/state/tooltipInteraction.ts +23 -0
- package/src/state/tooltipSlice.ts +334 -0
- package/src/state/touchEventsMiddleware.ts +214 -0
- package/src/state/types/AnimationSettings.ts +20 -0
- package/src/state/types/AreaSettings.ts +14 -0
- package/src/state/types/BarSettings.ts +15 -0
- package/src/state/types/LineSettings.ts +9 -0
- package/src/state/types/PieSettings.ts +34 -0
- package/src/state/types/RadarSettings.ts +5 -0
- package/src/state/types/RadialBarSettings.ts +10 -0
- package/src/state/types/ScatterSettings.ts +12 -0
- package/src/state/types/StackedGraphicalItem.ts +34 -0
- package/src/state/useChartState.ts +17 -0
- package/src/state/zIndexSlice.ts +39 -0
- package/src/synchronisation/syncSelectors.ts +7 -0
- package/src/synchronisation/types.ts +44 -0
- package/src/synchronisation/useChartSynchronisation.tsx +404 -0
- package/src/theme/RechartsTheme.ts +16 -0
- package/src/theme/RechartsThemeContext.ts +19 -0
- package/src/theme/darkTheme.ts +13 -0
- package/src/theme/graphicalItemIdentity.ts +70 -0
- package/src/theme/legacyTheme.ts +17 -0
- package/src/theme/lightTheme.ts +13 -0
- package/src/types.ts +54 -0
- package/src/util/ActiveShapeUtils.tsx +162 -0
- package/src/util/BarUtils.tsx +62 -0
- package/src/util/BarePortal.tsx +50 -0
- package/src/util/CamelCaseSVGAttrs.ts +34 -0
- package/src/util/CartesianUtils.ts +48 -0
- package/src/util/ChartUtils.ts +802 -0
- package/src/util/Constants.ts +42 -0
- package/src/util/CssPrefixUtils.ts +20 -0
- package/src/util/DOMUtils.ts +129 -0
- package/src/util/DataUtils.ts +216 -0
- package/src/util/Events.ts +16 -0
- package/src/util/FunnelUtils.tsx +15 -0
- package/src/util/Global.ts +12 -0
- package/src/util/IfOverflow.ts +15 -0
- package/src/util/LRUCache.ts +41 -0
- package/src/util/LogUtils.ts +22 -0
- package/src/util/PolarUtils.ts +132 -0
- package/src/util/RadialBarUtils.tsx +24 -0
- package/src/util/ReactUtils.ts +95 -0
- package/src/util/ReduceCSSCalc.ts +187 -0
- package/src/util/ScatterUtils.tsx +52 -0
- package/src/util/ShapeElementProps.tsx +87 -0
- package/src/util/TickUtils.ts +60 -0
- package/src/util/XAxisUtils.ts +48 -0
- package/src/util/YAxisUtils.ts +48 -0
- package/src/util/axisPropsAreEqual.ts +48 -0
- package/src/util/createCartesianCharts.tsx +150 -0
- package/src/util/createEventProxy.ts +20 -0
- package/src/util/createPolarCharts.tsx +112 -0
- package/src/util/cursor/getCursorPoints.ts +46 -0
- package/src/util/cursor/getCursorRectangle.ts +28 -0
- package/src/util/cursor/getRadialCursorPoints.ts +32 -0
- package/src/util/excludeEventProps.ts +171 -0
- package/src/util/getActiveCoordinate.ts +213 -0
- package/src/util/getAxisTypeBasedOnLayout.ts +21 -0
- package/src/util/getClassNameFromUnknown.ts +6 -0
- package/src/util/getEveryNth.ts +27 -0
- package/src/util/getRadiusAndStrokeWidthFromDot.ts +35 -0
- package/src/util/getRelativeCoordinate.ts +80 -0
- package/src/util/getSliced.ts +13 -0
- package/src/util/hoverDedupe.ts +41 -0
- package/src/util/isDomainSpecifiedByUser.ts +219 -0
- package/src/util/isWellBehavedNumber.ts +7 -0
- package/src/util/pathTotalLength.ts +25 -0
- package/src/util/payload/getUniqPayload.ts +28 -0
- package/src/util/propsAreEqual.ts +121 -0
- package/src/util/resolveDefaultProps.ts +161 -0
- package/src/util/round.ts +32 -0
- package/src/util/scale/CartesianScaleHelper.ts +72 -0
- package/src/util/scale/CustomScaleDefinition.ts +81 -0
- package/src/util/scale/RechartsScale.ts +130 -0
- package/src/util/scale/createCategoricalInverse.ts +72 -0
- package/src/util/scale/getNiceTickValues.ts +311 -0
- package/src/util/scale/index.ts +2 -0
- package/src/util/scale/util/arithmetic.ts +54 -0
- package/src/util/solid-1-compat.ts +310 -0
- package/src/util/solidJsxCamelAugment.d.ts +84 -0
- package/src/util/stacks/getStackSeriesIdentifier.ts +21 -0
- package/src/util/stacks/stackTypes.ts +60 -0
- package/src/util/structurallyEqual.ts +31 -0
- package/src/util/svgPropertiesAndEvents.ts +53 -0
- package/src/util/svgPropertiesNoEvents.ts +571 -0
- package/src/util/tooltip/translate.ts +171 -0
- package/src/util/typedDataKey.ts +48 -0
- package/src/util/types.ts +1560 -0
- package/src/util/useAnimationId.ts +31 -0
- package/src/util/useElementOffset.ts +110 -0
- package/src/util/useId.ts +8 -0
- package/src/util/usePrefersReducedMotion.ts +48 -0
- package/src/util/useReportScale.ts +24 -0
- package/src/util/useUniqueId.ts +30 -0
- package/src/zIndex/DefaultZIndexes.ts +84 -0
- package/src/zIndex/ZIndexLayer.tsx +121 -0
- package/src/zIndex/ZIndexPortal.tsx +79 -0
- package/src/zIndex/getZIndexFromUnknown.ts +14 -0
- package/src/zIndex/zIndexSelectors.ts +48 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { Props } from "./PolarAngleAxis"
|
|
3
|
+
import { DefaultZIndexes } from "../zIndex/DefaultZIndexes"
|
|
4
|
+
|
|
5
|
+
export const defaultPolarAngleAxisProps = {
|
|
6
|
+
allowDataOverflow: false,
|
|
7
|
+
allowDecimals: false,
|
|
8
|
+
allowDuplicatedCategory: true,
|
|
9
|
+
angle: 0,
|
|
10
|
+
angleAxisId: 0,
|
|
11
|
+
axisLine: true,
|
|
12
|
+
axisLineType: "polygon",
|
|
13
|
+
cx: 0,
|
|
14
|
+
cy: 0,
|
|
15
|
+
hide: false,
|
|
16
|
+
includeHidden: false,
|
|
17
|
+
label: false,
|
|
18
|
+
orientation: "outer",
|
|
19
|
+
reversed: false,
|
|
20
|
+
scale: "auto",
|
|
21
|
+
niceTicks: "auto",
|
|
22
|
+
tick: true,
|
|
23
|
+
tickLine: true,
|
|
24
|
+
tickSize: 8,
|
|
25
|
+
type: "auto",
|
|
26
|
+
zIndex: DefaultZIndexes.axis,
|
|
27
|
+
} as const satisfies Props
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { Props } from "./PolarRadiusAxis"
|
|
3
|
+
import { DefaultZIndexes } from "../zIndex/DefaultZIndexes"
|
|
4
|
+
|
|
5
|
+
export const defaultPolarRadiusAxisProps = {
|
|
6
|
+
allowDataOverflow: false,
|
|
7
|
+
allowDecimals: false,
|
|
8
|
+
allowDuplicatedCategory: true,
|
|
9
|
+
angle: 0,
|
|
10
|
+
axisLine: true,
|
|
11
|
+
hide: false,
|
|
12
|
+
includeHidden: false,
|
|
13
|
+
label: false,
|
|
14
|
+
orientation: "right",
|
|
15
|
+
radiusAxisId: 0,
|
|
16
|
+
reversed: false,
|
|
17
|
+
scale: "auto",
|
|
18
|
+
stroke: "#ccc",
|
|
19
|
+
niceTicks: "auto",
|
|
20
|
+
tick: true,
|
|
21
|
+
tickCount: 5,
|
|
22
|
+
tickLine: true,
|
|
23
|
+
type: "auto",
|
|
24
|
+
zIndex: DefaultZIndexes.axis,
|
|
25
|
+
} as const satisfies Props
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
/**
|
|
3
|
+
* @fileOverview Cross
|
|
4
|
+
*/
|
|
5
|
+
import type { JSX } from '@solidjs/web';
|
|
6
|
+
import { useShapeElementProps } from "../util/ShapeElementProps"
|
|
7
|
+
import type { WithoutRemoveFalse } from "../util/types"
|
|
8
|
+
import { Show } from 'solid-js';
|
|
9
|
+
import { clsx } from "clsx"
|
|
10
|
+
import { isNumber } from "../util/DataUtils"
|
|
11
|
+
import { svgPropertiesAndEvents } from "../util/svgPropertiesAndEvents"
|
|
12
|
+
|
|
13
|
+
interface CrossProps {
|
|
14
|
+
/**
|
|
15
|
+
* The x-coordinate of the vertical line of the cross in pixels.
|
|
16
|
+
*/
|
|
17
|
+
x?: number
|
|
18
|
+
/**
|
|
19
|
+
* The y-coordinate of the horizontal line of the cross in pixels.
|
|
20
|
+
*/
|
|
21
|
+
y?: number
|
|
22
|
+
/**
|
|
23
|
+
* Width of the cross in pixels.
|
|
24
|
+
*/
|
|
25
|
+
width?: number
|
|
26
|
+
/**
|
|
27
|
+
* Height of the cross in pixels.
|
|
28
|
+
*/
|
|
29
|
+
height?: number
|
|
30
|
+
/**
|
|
31
|
+
* The y-coordinate of the top left point in the boundary box of the cross.
|
|
32
|
+
*/
|
|
33
|
+
top?: number
|
|
34
|
+
/**
|
|
35
|
+
* The x-coordinate of the top left point in the boundary box of the cross.
|
|
36
|
+
*/
|
|
37
|
+
left?: number
|
|
38
|
+
class?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type Props = WithoutRemoveFalse<JSX.PathSVGAttributes<SVGPathElement>> & CrossProps
|
|
42
|
+
|
|
43
|
+
const getPath = (
|
|
44
|
+
x: number,
|
|
45
|
+
y: number,
|
|
46
|
+
width: number,
|
|
47
|
+
height: number,
|
|
48
|
+
top: number,
|
|
49
|
+
left: number,
|
|
50
|
+
) => {
|
|
51
|
+
return `M${x},${top}v${height}M${left},${y}h${width}`
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function Cross(ownProps: Props) {
|
|
55
|
+
/* Props injected for a shape passed as an element (see ShapeElementProps). */
|
|
56
|
+
const props = useShapeElementProps(ownProps)
|
|
57
|
+
const x = () => props.x ?? 0
|
|
58
|
+
const y = () => props.y ?? 0
|
|
59
|
+
const top = () => props.top ?? 0
|
|
60
|
+
const left = () => props.left ?? 0
|
|
61
|
+
const width = () => props.width ?? 0
|
|
62
|
+
const height = () => props.height ?? 0
|
|
63
|
+
|
|
64
|
+
const isValid = () =>
|
|
65
|
+
isNumber(x()) &&
|
|
66
|
+
isNumber(y()) &&
|
|
67
|
+
isNumber(width()) &&
|
|
68
|
+
isNumber(height()) &&
|
|
69
|
+
isNumber(top()) &&
|
|
70
|
+
isNumber(left())
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<Show when={isValid()}>
|
|
74
|
+
<path
|
|
75
|
+
{...svgPropertiesAndEvents({
|
|
76
|
+
...props,
|
|
77
|
+
height: height(),
|
|
78
|
+
left: left(),
|
|
79
|
+
top: top(),
|
|
80
|
+
width: width(),
|
|
81
|
+
x: x(),
|
|
82
|
+
y: y(),
|
|
83
|
+
})}
|
|
84
|
+
class={clsx("recharts-cross", props.class)}
|
|
85
|
+
d={getPath(x(), y(), width(), height(), top(), left())}
|
|
86
|
+
/>
|
|
87
|
+
</Show>
|
|
88
|
+
)
|
|
89
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
/**
|
|
3
|
+
* @fileOverview Curve
|
|
4
|
+
*/
|
|
5
|
+
import { Show, createMemo } from 'solid-js';
|
|
6
|
+
import { useShapeElementProps } from "../util/ShapeElementProps"
|
|
7
|
+
import {
|
|
8
|
+
area as shapeArea,
|
|
9
|
+
type Area as D3AreaCurve,
|
|
10
|
+
curveBasis,
|
|
11
|
+
curveBasisClosed,
|
|
12
|
+
curveBasisOpen,
|
|
13
|
+
curveBumpX,
|
|
14
|
+
curveBumpY,
|
|
15
|
+
type CurveFactory,
|
|
16
|
+
curveLinear,
|
|
17
|
+
curveLinearClosed,
|
|
18
|
+
curveMonotoneX,
|
|
19
|
+
curveMonotoneY,
|
|
20
|
+
curveNatural,
|
|
21
|
+
curveStep,
|
|
22
|
+
curveStepAfter,
|
|
23
|
+
curveStepBefore,
|
|
24
|
+
line as shapeLine,
|
|
25
|
+
type Line as D3LineCurve,
|
|
26
|
+
} from "victory-vendor/d3-shape"
|
|
27
|
+
|
|
28
|
+
import { clsx } from "clsx"
|
|
29
|
+
import type {
|
|
30
|
+
RechartsMouseEventHandler,
|
|
31
|
+
Coordinate,
|
|
32
|
+
LayoutType,
|
|
33
|
+
NullableCoordinate,
|
|
34
|
+
PresentationAttributesWithProps,
|
|
35
|
+
} from "../util/types"
|
|
36
|
+
import { adaptEventHandlers } from "../util/types"
|
|
37
|
+
import { isNumber, upperFirst } from "../util/DataUtils"
|
|
38
|
+
import { isWellBehavedNumber } from "../util/isWellBehavedNumber"
|
|
39
|
+
import { svgPropertiesNoEvents } from "../util/svgPropertiesNoEvents"
|
|
40
|
+
import { useChartLayout } from "../context/chartLayoutContext"
|
|
41
|
+
|
|
42
|
+
interface CurveFactories {
|
|
43
|
+
[index: string]: CurveFactory
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const CURVE_FACTORIES: CurveFactories = {
|
|
47
|
+
curveBasis,
|
|
48
|
+
curveBasisClosed,
|
|
49
|
+
curveBasisOpen,
|
|
50
|
+
curveBumpX,
|
|
51
|
+
curveBumpY,
|
|
52
|
+
curveLinear,
|
|
53
|
+
curveLinearClosed,
|
|
54
|
+
curveMonotoneX,
|
|
55
|
+
curveMonotoneY,
|
|
56
|
+
curveNatural,
|
|
57
|
+
curveStep,
|
|
58
|
+
curveStepAfter,
|
|
59
|
+
curveStepBefore,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @inline
|
|
64
|
+
*/
|
|
65
|
+
export type CurveType =
|
|
66
|
+
| "basis"
|
|
67
|
+
| "basisClosed"
|
|
68
|
+
| "basisOpen"
|
|
69
|
+
| "bumpX"
|
|
70
|
+
| "bumpY"
|
|
71
|
+
| "bump"
|
|
72
|
+
| "linear"
|
|
73
|
+
| "linearClosed"
|
|
74
|
+
| "natural"
|
|
75
|
+
| "monotoneX"
|
|
76
|
+
| "monotoneY"
|
|
77
|
+
| "monotone"
|
|
78
|
+
| "step"
|
|
79
|
+
| "stepBefore"
|
|
80
|
+
| "stepAfter"
|
|
81
|
+
| CurveFactory
|
|
82
|
+
|
|
83
|
+
type AreaPoint = Coordinate & { base: Coordinate }
|
|
84
|
+
|
|
85
|
+
type NullableAreaPoint = NullableCoordinate & { base?: NullableCoordinate }
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @inline
|
|
89
|
+
*/
|
|
90
|
+
export type BaseLineType = number | ReadonlyArray<NullableCoordinate>
|
|
91
|
+
|
|
92
|
+
const defined = (p: NullableCoordinate): p is Coordinate =>
|
|
93
|
+
isWellBehavedNumber(p.x) && isWellBehavedNumber(p.y)
|
|
94
|
+
const areaDefined = (d: NullableAreaPoint): d is AreaPoint =>
|
|
95
|
+
d.base != null && defined(d.base) && defined(d)
|
|
96
|
+
const getX = (p: Coordinate) => p.x
|
|
97
|
+
const getY = (p: Coordinate) => p.y
|
|
98
|
+
|
|
99
|
+
const getCurveFactory = (type: CurveType, layout: LayoutType | undefined): CurveFactory => {
|
|
100
|
+
if (typeof type === "function") {
|
|
101
|
+
return type
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const name = `curve${upperFirst(type)}`
|
|
105
|
+
|
|
106
|
+
if ((name === "curveMonotone" || name === "curveBump") && layout) {
|
|
107
|
+
const factory = CURVE_FACTORIES[`${name}${layout === "vertical" ? "Y" : "X"}`]
|
|
108
|
+
if (factory) {
|
|
109
|
+
return factory
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return CURVE_FACTORIES[name] || curveLinear
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface CurveProps {
|
|
116
|
+
class?: string
|
|
117
|
+
/**
|
|
118
|
+
* The interpolation type of curve. Allows custom interpolation function.
|
|
119
|
+
*
|
|
120
|
+
* @defaultValue linear
|
|
121
|
+
* @link https://d3js.org/d3-shape/curve
|
|
122
|
+
* @see {@link https://recharts.github.io/en-US/examples/CardinalAreaChart/ An AreaChart which has two area with different interpolation.}
|
|
123
|
+
*/
|
|
124
|
+
type?: CurveType
|
|
125
|
+
/**
|
|
126
|
+
* This option affects the interpolation algorithm when the `type` prop is set to 'monotone'.
|
|
127
|
+
* It also specifies the type of baseline when the curve is closed.
|
|
128
|
+
*/
|
|
129
|
+
layout?: LayoutType
|
|
130
|
+
/**
|
|
131
|
+
* Baseline of the area:
|
|
132
|
+
* - number: uses the corresponding axis value as a flat baseline;
|
|
133
|
+
* - an array of coordinates: describes a custom baseline path.
|
|
134
|
+
*/
|
|
135
|
+
baseLine?: BaseLineType
|
|
136
|
+
/**
|
|
137
|
+
* The coordinates of all the points in the curve, like an array of objects with x and y coordinates.
|
|
138
|
+
*/
|
|
139
|
+
points?: ReadonlyArray<NullableCoordinate>
|
|
140
|
+
/**
|
|
141
|
+
* Whether to connect the curve across null points.
|
|
142
|
+
*
|
|
143
|
+
* @defaultValue false
|
|
144
|
+
*
|
|
145
|
+
* @see {@link https://recharts.github.io/en-US/examples/LineChartConnectNulls/ LineChart with connectNull true and false}
|
|
146
|
+
* @see {@link https://recharts.github.io/en-US/examples/AreaChartConnectNulls/ AreaChart with connectNull true and false}
|
|
147
|
+
*/
|
|
148
|
+
connectNulls?: boolean
|
|
149
|
+
path?: string
|
|
150
|
+
/* GOTCHA-014-J: ref-object shape for upstream React parity. Tests assert
|
|
151
|
+
`pathRef: { current: <SVGPathElement> }` on the props payload received by
|
|
152
|
+
user event handlers — Solid's natural callback-ref `(el) => ref = el` shape
|
|
153
|
+
diverges. Always use `{ current: el | null }`; Curve's <path ref={...}>
|
|
154
|
+
assigns into the slot via callback. */
|
|
155
|
+
pathRef?: { current: SVGPathElement | null }
|
|
156
|
+
/**
|
|
157
|
+
* The pattern of dashes and gaps used to paint the line.
|
|
158
|
+
*
|
|
159
|
+
* @example strokeDasharray="5 5"
|
|
160
|
+
* @example strokeDasharray={10}
|
|
161
|
+
* @see {@link https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/stroke-dasharray}
|
|
162
|
+
*/
|
|
163
|
+
strokeDasharray?: string | number
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type CurveMouseEventHandler = RechartsMouseEventHandler<Props, SVGPathElement>
|
|
167
|
+
|
|
168
|
+
type CurveMouseEvents = {
|
|
169
|
+
/**
|
|
170
|
+
* The customized event handler of click on the curve
|
|
171
|
+
*/
|
|
172
|
+
onClick?: CurveMouseEventHandler
|
|
173
|
+
/**
|
|
174
|
+
* The customized event handler of mouseenter on the curve
|
|
175
|
+
*/
|
|
176
|
+
onMouseEnter?: CurveMouseEventHandler
|
|
177
|
+
/**
|
|
178
|
+
* The customized event handler of mouseleave on the curve
|
|
179
|
+
*/
|
|
180
|
+
onMouseLeave?: CurveMouseEventHandler
|
|
181
|
+
/**
|
|
182
|
+
* The customized event handler of mousedown on the curve
|
|
183
|
+
*/
|
|
184
|
+
onMouseDown?: CurveMouseEventHandler
|
|
185
|
+
/**
|
|
186
|
+
* The customized event handler of mouseup on the curve
|
|
187
|
+
*/
|
|
188
|
+
onMouseUp?: CurveMouseEventHandler
|
|
189
|
+
/**
|
|
190
|
+
* The customized event handler of mousemove on the curve
|
|
191
|
+
*/
|
|
192
|
+
onMouseMove?: CurveMouseEventHandler
|
|
193
|
+
/**
|
|
194
|
+
* The customized event handler of mouseover on the curve
|
|
195
|
+
*/
|
|
196
|
+
onMouseOver?: CurveMouseEventHandler
|
|
197
|
+
/**
|
|
198
|
+
* The customized event handler of mouseout on the curve
|
|
199
|
+
*/
|
|
200
|
+
onMouseOut?: CurveMouseEventHandler
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type Props = Omit<
|
|
204
|
+
PresentationAttributesWithProps<CurveProps, SVGPathElement>,
|
|
205
|
+
| "type"
|
|
206
|
+
| "points"
|
|
207
|
+
| "onClick"
|
|
208
|
+
| "onMouseEnter"
|
|
209
|
+
| "onMouseLeave"
|
|
210
|
+
| "onMouseDown"
|
|
211
|
+
| "onMouseUp"
|
|
212
|
+
| "onMouseMove"
|
|
213
|
+
| "onMouseOver"
|
|
214
|
+
| "onMouseOut"
|
|
215
|
+
> &
|
|
216
|
+
CurveMouseEvents &
|
|
217
|
+
CurveProps
|
|
218
|
+
|
|
219
|
+
type GetPathProps = Pick<Props, "type" | "points" | "baseLine" | "layout" | "connectNulls">
|
|
220
|
+
|
|
221
|
+
export const defaultCurveProps = {
|
|
222
|
+
connectNulls: false,
|
|
223
|
+
type: "linear",
|
|
224
|
+
} as const satisfies Partial<Props>
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Calculate the path of curve. Returns null if points is an empty array.
|
|
228
|
+
* @return path or null
|
|
229
|
+
*/
|
|
230
|
+
export const getPath = ({
|
|
231
|
+
type = defaultCurveProps.type,
|
|
232
|
+
points = [],
|
|
233
|
+
baseLine,
|
|
234
|
+
layout,
|
|
235
|
+
connectNulls = defaultCurveProps.connectNulls,
|
|
236
|
+
}: GetPathProps): string | null => {
|
|
237
|
+
const curveFactory = getCurveFactory(type, layout)
|
|
238
|
+
const formatPoints: ReadonlyArray<NullableCoordinate> = connectNulls
|
|
239
|
+
? points.filter(defined)
|
|
240
|
+
: points
|
|
241
|
+
|
|
242
|
+
/*
|
|
243
|
+
* When dealing with an area chart (where `baseLine` is an array),
|
|
244
|
+
* we need to pair points with their corresponding `baseLine` points first.
|
|
245
|
+
* This is to ensure that we filter points and their baseline counterparts together,
|
|
246
|
+
* preventing errors from mismatched array lengths and ensuring `defined` checks both.
|
|
247
|
+
*/
|
|
248
|
+
if (Array.isArray(baseLine)) {
|
|
249
|
+
let lineFunction: D3AreaCurve<AreaPoint>
|
|
250
|
+
|
|
251
|
+
const areaPoints: ReadonlyArray<NullableAreaPoint> = points.map((entry, index) => ({
|
|
252
|
+
...entry,
|
|
253
|
+
base: baseLine[index],
|
|
254
|
+
}))
|
|
255
|
+
|
|
256
|
+
if (layout === "vertical") {
|
|
257
|
+
lineFunction = shapeArea<AreaPoint>()
|
|
258
|
+
.y(getY)
|
|
259
|
+
.x1(getX)
|
|
260
|
+
.x0((d) => d.base.x)
|
|
261
|
+
} else {
|
|
262
|
+
lineFunction = shapeArea<AreaPoint>()
|
|
263
|
+
.x(getX)
|
|
264
|
+
.y1(getY)
|
|
265
|
+
.y0((d) => d.base.y)
|
|
266
|
+
}
|
|
267
|
+
/*
|
|
268
|
+
* What happens here is that the `.defined()` call will make it so that this function can accept
|
|
269
|
+
* nullable points, and internally it will filter them out and skip when generating the path.
|
|
270
|
+
* So on the input it accepts NullableCoordinate, but it never calls getX/getY on null points because of the defined() filter.
|
|
271
|
+
*
|
|
272
|
+
* The d3 type definition has only one generic so it doesn't allow to describe this properly.
|
|
273
|
+
* However. d3 types are mutable, but we can pretend that they are not, and we can pretend
|
|
274
|
+
* that calling defined() returns a new function with a different generic type.
|
|
275
|
+
*/
|
|
276
|
+
const withDefined = lineFunction.defined(
|
|
277
|
+
areaDefined as (d: AreaPoint, i: number, data: readonly AreaPoint[]) => boolean,
|
|
278
|
+
)
|
|
279
|
+
const nullableLineFunction: D3AreaCurve<NullableAreaPoint> = withDefined.curve(
|
|
280
|
+
curveFactory,
|
|
281
|
+
) as D3AreaCurve<NullableAreaPoint>
|
|
282
|
+
|
|
283
|
+
const finalPoints: ReadonlyArray<NullableAreaPoint> = connectNulls
|
|
284
|
+
? areaPoints.filter(areaDefined)
|
|
285
|
+
: areaPoints
|
|
286
|
+
|
|
287
|
+
return nullableLineFunction(finalPoints)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
let lineFunction: D3LineCurve<Coordinate> | D3AreaCurve<Coordinate>
|
|
291
|
+
if (layout === "vertical" && isNumber(baseLine)) {
|
|
292
|
+
lineFunction = shapeArea<Coordinate>().y(getY).x1(getX).x0(baseLine)
|
|
293
|
+
} else if (isNumber(baseLine)) {
|
|
294
|
+
lineFunction = shapeArea<Coordinate>().x(getX).y1(getY).y0(baseLine)
|
|
295
|
+
} else {
|
|
296
|
+
lineFunction = shapeLine<Coordinate>().x(getX).y(getY)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const withDefined = (lineFunction as D3LineCurve<Coordinate>).defined(
|
|
300
|
+
defined as (d: Coordinate, i: number, data: readonly Coordinate[]) => boolean,
|
|
301
|
+
)
|
|
302
|
+
const nullableLineFunction: D3LineCurve<NullableCoordinate> = withDefined.curve(
|
|
303
|
+
curveFactory,
|
|
304
|
+
) as D3LineCurve<NullableCoordinate>
|
|
305
|
+
|
|
306
|
+
return nullableLineFunction(formatPoints)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export function Curve(ownProps: Props) {
|
|
310
|
+
/* Props injected for a shape passed as an element (see ShapeElementProps). */
|
|
311
|
+
const props = useShapeElementProps(ownProps)
|
|
312
|
+
const layout = createMemo(() => useChartLayout())
|
|
313
|
+
|
|
314
|
+
const hasData = () => (props.points && props.points.length > 0) || props.path
|
|
315
|
+
|
|
316
|
+
const realPath = (): string | null | undefined => {
|
|
317
|
+
if (props.points && props.points.length > 0) {
|
|
318
|
+
const getPathInput: GetPathProps = {
|
|
319
|
+
baseLine: props.baseLine,
|
|
320
|
+
connectNulls: props.connectNulls,
|
|
321
|
+
layout: props.layout || layout(),
|
|
322
|
+
points: props.points,
|
|
323
|
+
type: props.type,
|
|
324
|
+
}
|
|
325
|
+
return getPath(getPathInput)
|
|
326
|
+
}
|
|
327
|
+
return props.path
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return (
|
|
331
|
+
<Show when={hasData()}>
|
|
332
|
+
<path
|
|
333
|
+
{...svgPropertiesNoEvents(props)}
|
|
334
|
+
{...adaptEventHandlers(props)}
|
|
335
|
+
class={clsx("recharts-curve", props.class)}
|
|
336
|
+
d={realPath() ?? undefined}
|
|
337
|
+
ref={(el: SVGPathElement) => {
|
|
338
|
+
if (props.pathRef) props.pathRef.current = el
|
|
339
|
+
}}
|
|
340
|
+
/>
|
|
341
|
+
</Show>
|
|
342
|
+
)
|
|
343
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/* eslint-disable import/no-cycle */
|
|
2
|
+
import { Show } from 'solid-js';
|
|
3
|
+
import { useShapeElementProps } from "../util/ShapeElementProps"
|
|
4
|
+
import { clsx } from "clsx"
|
|
5
|
+
import type { PresentationAttributesWithProps } from "../util/types"
|
|
6
|
+
import { adaptEventHandlers } from "../util/types"
|
|
7
|
+
import { ownStringKeys, svgPropCanonicalKey } from "../util/svgPropertiesNoEvents"
|
|
8
|
+
import { isEventKey } from "../util/excludeEventProps"
|
|
9
|
+
import { isNumber } from "../util/DataUtils"
|
|
10
|
+
|
|
11
|
+
interface DotProps {
|
|
12
|
+
class?: string
|
|
13
|
+
/**
|
|
14
|
+
* The x-coordinate of center in pixels.
|
|
15
|
+
*/
|
|
16
|
+
cx?: number
|
|
17
|
+
/**
|
|
18
|
+
* The y-coordinate of center in pixels.
|
|
19
|
+
*/
|
|
20
|
+
cy?: number
|
|
21
|
+
/**
|
|
22
|
+
* The radius of dot.
|
|
23
|
+
*/
|
|
24
|
+
r?: number | string
|
|
25
|
+
clipDot?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type Props = PresentationAttributesWithProps<DotProps, SVGCircleElement> & DotProps
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Renders a dot in the chart.
|
|
32
|
+
*
|
|
33
|
+
* This component accepts X and Y coordinates in pixels.
|
|
34
|
+
* If you need to position the rectangle based on your chart's data,
|
|
35
|
+
* consider using the {@link ReferenceDot} component instead.
|
|
36
|
+
*/
|
|
37
|
+
export function Dot(ownProps: Props) {
|
|
38
|
+
/* Props injected for a shape passed as an element (see ShapeElementProps). */
|
|
39
|
+
const props = useShapeElementProps(ownProps)
|
|
40
|
+
/* React-style `className` (e.g. from an activeDot object) merges into `class`. */
|
|
41
|
+
const layerClass = () =>
|
|
42
|
+
clsx("recharts-dot", props.class, (props as { className?: string }).className)
|
|
43
|
+
/* One pass over the props per dot: SVG attributes (minus className, merged into class above),
|
|
44
|
+
then event handlers only when the dot actually has one. Same result as spreading
|
|
45
|
+
svgPropertiesNoEvents(props) and adaptEventHandlers(props). */
|
|
46
|
+
const attributes = () => {
|
|
47
|
+
const source = props as Record<string, unknown>
|
|
48
|
+
const result: Record<string, unknown> = {}
|
|
49
|
+
let hasHandler = false
|
|
50
|
+
for (const key of ownStringKeys(source)) {
|
|
51
|
+
const canonical = key === "className" ? undefined : svgPropCanonicalKey(key)
|
|
52
|
+
if (canonical !== undefined) {
|
|
53
|
+
result[canonical] = source[key]
|
|
54
|
+
} else if (!hasHandler && isEventKey(key) && typeof source[key] === "function") {
|
|
55
|
+
hasHandler = true
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return hasHandler ? Object.assign(result, adaptEventHandlers(props)) : result
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<Show when={isNumber(props.cx) && isNumber(props.cy) && isNumber(props.r)}>
|
|
63
|
+
<circle
|
|
64
|
+
{...attributes()}
|
|
65
|
+
/* cx/cy/r come from the spread in prop order, matching upstream's attribute order */
|
|
66
|
+
class={layerClass()}
|
|
67
|
+
/>
|
|
68
|
+
</Show>
|
|
69
|
+
)
|
|
70
|
+
}
|