@solidports/recharts 0.1.0 → 0.1.1

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 (304) hide show
  1. package/dist/index.d.ts +40 -2
  2. package/dist/index.js +14238 -7174
  3. package/dist/{dev.js → index.jsx} +18367 -15900
  4. package/dist/server.js +48178 -0
  5. package/package.json +36 -19
  6. package/src/animation/AnimatedItems.tsx +0 -183
  7. package/src/animation/AnimationController.ts +0 -33
  8. package/src/animation/AnimationControllerImpl.ts +0 -36
  9. package/src/animation/AnimationHandle.ts +0 -307
  10. package/src/animation/CSSTransitionAnimate.tsx +0 -170
  11. package/src/animation/JavascriptAnimate.tsx +0 -119
  12. package/src/animation/easing.ts +0 -221
  13. package/src/animation/matchBy.ts +0 -164
  14. package/src/animation/timeoutController.ts +0 -70
  15. package/src/animation/useAnimationController.tsx +0 -34
  16. package/src/animation/useAnimationStartSnapshot.ts +0 -118
  17. package/src/animation/util.ts +0 -41
  18. package/src/cartesian/Area.tsx +0 -915
  19. package/src/cartesian/AreaRevealShape.tsx +0 -190
  20. package/src/cartesian/Bar.tsx +0 -1369
  21. package/src/cartesian/BarStack.tsx +0 -152
  22. package/src/cartesian/Brush.tsx +0 -951
  23. package/src/cartesian/CartesianAxis.tsx +0 -722
  24. package/src/cartesian/CartesianGrid.tsx +0 -711
  25. package/src/cartesian/ErrorBar.tsx +0 -361
  26. package/src/cartesian/Funnel.tsx +0 -803
  27. package/src/cartesian/GraphicalItemClipPath.tsx +0 -67
  28. package/src/cartesian/Line.tsx +0 -863
  29. package/src/cartesian/LineDrawShape.tsx +0 -89
  30. package/src/cartesian/ReferenceArea.tsx +0 -331
  31. package/src/cartesian/ReferenceDot.tsx +0 -304
  32. package/src/cartesian/ReferenceLine.tsx +0 -474
  33. package/src/cartesian/Scatter.tsx +0 -888
  34. package/src/cartesian/XAxis.tsx +0 -433
  35. package/src/cartesian/YAxis.tsx +0 -443
  36. package/src/cartesian/ZAxis.tsx +0 -155
  37. package/src/cartesian/cartesianPositionToCSSTranslate.tsx +0 -29
  38. package/src/cartesian/cartesianViewBoxToTrapezoid.tsx +0 -21
  39. package/src/cartesian/getCartesianPosition.tsx +0 -267
  40. package/src/cartesian/getEquidistantTicks.ts +0 -144
  41. package/src/cartesian/getTicks.ts +0 -225
  42. package/src/cartesian/isOutsidePosition.ts +0 -15
  43. package/src/cartesian/useAnimatedLineLength.ts +0 -54
  44. package/src/chart/AreaChart.tsx +0 -29
  45. package/src/chart/BarChart.tsx +0 -29
  46. package/src/chart/CartesianChart.tsx +0 -131
  47. package/src/chart/CategoricalChart.tsx +0 -94
  48. package/src/chart/ComposedChart.tsx +0 -29
  49. package/src/chart/FunnelChart.tsx +0 -29
  50. package/src/chart/LineChart.tsx +0 -29
  51. package/src/chart/PieChart.tsx +0 -50
  52. package/src/chart/PolarChart.tsx +0 -164
  53. package/src/chart/RadarChart.tsx +0 -70
  54. package/src/chart/RadialBarChart.tsx +0 -46
  55. package/src/chart/RechartsWrapper.tsx +0 -551
  56. package/src/chart/Sankey.tsx +0 -1534
  57. package/src/chart/ScatterChart.tsx +0 -29
  58. package/src/chart/SunburstChart.tsx +0 -504
  59. package/src/chart/Treemap.tsx +0 -1223
  60. package/src/chart/createInitialRootProps.ts +0 -24
  61. package/src/chart/types.ts +0 -53
  62. package/src/component/ActivePoints.tsx +0 -144
  63. package/src/component/Cell.tsx +0 -37
  64. package/src/component/Cursor.tsx +0 -185
  65. package/src/component/Customized.tsx +0 -50
  66. package/src/component/DefaultLegendContent.tsx +0 -348
  67. package/src/component/DefaultTooltipContent.tsx +0 -224
  68. package/src/component/Dots.tsx +0 -157
  69. package/src/component/Label.tsx +0 -636
  70. package/src/component/LabelList.tsx +0 -375
  71. package/src/component/Legend.tsx +0 -512
  72. package/src/component/ResponsiveContainer.tsx +0 -348
  73. package/src/component/Text.tsx +0 -541
  74. package/src/component/Tooltip.tsx +0 -470
  75. package/src/component/TooltipBoundingBox.tsx +0 -146
  76. package/src/component/responsiveContainerUtils.ts +0 -134
  77. package/src/container/ClipPathProvider.tsx +0 -51
  78. package/src/container/Layer.tsx +0 -38
  79. package/src/container/RootSurface.tsx +0 -120
  80. package/src/container/Surface.tsx +0 -61
  81. package/src/context/CellsContext.tsx +0 -54
  82. package/src/context/ErrorBarContext.tsx +0 -146
  83. package/src/context/GraphicalItemChildrenScope.tsx +0 -18
  84. package/src/context/PanoramaContext.tsx +0 -9
  85. package/src/context/RegisterGraphicalItemId.tsx +0 -30
  86. package/src/context/accessibilityContext.tsx +0 -6
  87. package/src/context/brushUpdateContext.tsx +0 -9
  88. package/src/context/chartDataContext.tsx +0 -97
  89. package/src/context/chartLayoutContext.tsx +0 -201
  90. package/src/context/legendPayloadContext.tsx +0 -20
  91. package/src/context/legendPortalContext.tsx +0 -12
  92. package/src/context/tooltipContext.tsx +0 -89
  93. package/src/context/tooltipPortalContext.tsx +0 -12
  94. package/src/context/useTooltipAxis.ts +0 -22
  95. package/src/hooks.ts +0 -476
  96. package/src/index.ts +0 -280
  97. package/src/polar/Pie.tsx +0 -1360
  98. package/src/polar/PolarAngleAxis.tsx +0 -616
  99. package/src/polar/PolarGrid.tsx +0 -312
  100. package/src/polar/PolarRadiusAxis.tsx +0 -547
  101. package/src/polar/Radar.tsx +0 -734
  102. package/src/polar/RadialBar.tsx +0 -917
  103. package/src/polar/defaultPolarAngleAxisProps.tsx +0 -27
  104. package/src/polar/defaultPolarRadiusAxisProps.tsx +0 -25
  105. package/src/shape/Cross.tsx +0 -89
  106. package/src/shape/Curve.tsx +0 -343
  107. package/src/shape/Dot.tsx +0 -70
  108. package/src/shape/Polygon.tsx +0 -195
  109. package/src/shape/Rectangle.tsx +0 -470
  110. package/src/shape/Sector.tsx +0 -347
  111. package/src/shape/Symbols.tsx +0 -139
  112. package/src/shape/Trapezoid.tsx +0 -280
  113. package/src/state/RechartsStateContext.tsx +0 -12
  114. package/src/state/RechartsStateProvider.tsx +0 -87
  115. package/src/state/RechartsStoreContext.tsx +0 -25
  116. package/src/state/RechartsStoreProvider.tsx +0 -35
  117. package/src/state/ReportChartProps.tsx +0 -40
  118. package/src/state/ReportEventSettings.tsx +0 -30
  119. package/src/state/ReportMainChartProps.tsx +0 -61
  120. package/src/state/ReportPolarOptions.tsx +0 -35
  121. package/src/state/SetGraphicalItem.ts +0 -79
  122. package/src/state/SetLegendPayload.ts +0 -134
  123. package/src/state/SetTooltipEntrySettings.tsx +0 -72
  124. package/src/state/actions.ts +0 -464
  125. package/src/state/brushSlice.ts +0 -13
  126. package/src/state/cartesianAxisSlice.ts +0 -141
  127. package/src/state/chartDataSlice.ts +0 -50
  128. package/src/state/chartState.ts +0 -297
  129. package/src/state/errorBarSlice.ts +0 -29
  130. package/src/state/eventSettingsSlice.ts +0 -8
  131. package/src/state/events.ts +0 -76
  132. package/src/state/externalEventsMiddleware.ts +0 -255
  133. package/src/state/graphicalItemsSlice.ts +0 -74
  134. package/src/state/hooks/useChartSelectors.tsx +0 -45
  135. package/src/state/keyboardEventsMiddleware.ts +0 -228
  136. package/src/state/layoutSlice.ts +0 -21
  137. package/src/state/legendSlice.ts +0 -57
  138. package/src/state/mouseEventsMiddleware.ts +0 -185
  139. package/src/state/optionsSlice.ts +0 -47
  140. package/src/state/polarAxisSlice.ts +0 -10
  141. package/src/state/polarOptionsSlice.ts +0 -12
  142. package/src/state/rawData.ts +0 -26
  143. package/src/state/referenceElementsSlice.ts +0 -40
  144. package/src/state/renderedTicksSlice.ts +0 -15
  145. package/src/state/rootPropsSlice.ts +0 -47
  146. package/src/state/selectors/areaSelectors.ts +0 -240
  147. package/src/state/selectors/arrayEqualityCheck.ts +0 -29
  148. package/src/state/selectors/axisSelectors.ts +0 -2157
  149. package/src/state/selectors/barSelectors.ts +0 -310
  150. package/src/state/selectors/barStackSelectors.ts +0 -77
  151. package/src/state/selectors/brushSelectors.ts +0 -33
  152. package/src/state/selectors/chartSelector.ts +0 -185
  153. package/src/state/selectors/combiners/combineActiveLabel.ts +0 -16
  154. package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +0 -95
  155. package/src/state/selectors/combiners/combineAllBarPositions.ts +0 -122
  156. package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +0 -16
  157. package/src/state/selectors/combiners/combineBarPosition.ts +0 -23
  158. package/src/state/selectors/combiners/combineBarSizeList.ts +0 -80
  159. package/src/state/selectors/combiners/combineCheckedDomain.ts +0 -48
  160. package/src/state/selectors/combiners/combineConfiguredScale.ts +0 -111
  161. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +0 -45
  162. package/src/state/selectors/combiners/combineDisplayedStackedData.ts +0 -50
  163. package/src/state/selectors/combiners/combineInverseScaleFunction.ts +0 -16
  164. package/src/state/selectors/combiners/combineRealScaleType.ts +0 -44
  165. package/src/state/selectors/combiners/combineStackedData.ts +0 -27
  166. package/src/state/selectors/combiners/combineTooltipInteractionState.ts +0 -86
  167. package/src/state/selectors/combiners/combineTooltipPayload.ts +0 -205
  168. package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +0 -58
  169. package/src/state/selectors/containerSelectors.ts +0 -12
  170. package/src/state/selectors/dataSelectors.ts +0 -88
  171. package/src/state/selectors/funnelSelectors.ts +0 -75
  172. package/src/state/selectors/graphicalItemSelectors.ts +0 -30
  173. package/src/state/selectors/legendSelectors.ts +0 -29
  174. package/src/state/selectors/lineSelectors.ts +0 -134
  175. package/src/state/selectors/numberDomainEqualityCheck.ts +0 -14
  176. package/src/state/selectors/pickAxisId.ts +0 -5
  177. package/src/state/selectors/pickAxisType.ts +0 -3
  178. package/src/state/selectors/pieSelectors.ts +0 -97
  179. package/src/state/selectors/polarAxisSelectors.ts +0 -201
  180. package/src/state/selectors/polarGridSelectors.ts +0 -28
  181. package/src/state/selectors/polarScaleSelectors.ts +0 -133
  182. package/src/state/selectors/polarSelectors.ts +0 -219
  183. package/src/state/selectors/radarSelectors.ts +0 -191
  184. package/src/state/selectors/radialBarSelectors.ts +0 -435
  185. package/src/state/selectors/rootPropsSelectors.ts +0 -25
  186. package/src/state/selectors/scatterSelectors.ts +0 -96
  187. package/src/state/selectors/selectActivePropsFromChartPointer.ts +0 -26
  188. package/src/state/selectors/selectAllAxes.ts +0 -17
  189. package/src/state/selectors/selectChartOffset.ts +0 -16
  190. package/src/state/selectors/selectChartOffsetInternal.ts +0 -136
  191. package/src/state/selectors/selectLegendArea.ts +0 -20
  192. package/src/state/selectors/selectPlotArea.ts +0 -22
  193. package/src/state/selectors/selectTooltipAxisId.ts +0 -7
  194. package/src/state/selectors/selectTooltipAxisType.ts +0 -32
  195. package/src/state/selectors/selectTooltipEventType.ts +0 -48
  196. package/src/state/selectors/selectTooltipPayloadSearcher.ts +0 -6
  197. package/src/state/selectors/selectTooltipSettings.ts +0 -39
  198. package/src/state/selectors/selectTooltipState.ts +0 -8
  199. package/src/state/selectors/selectors.ts +0 -271
  200. package/src/state/selectors/tooltipSelectors.ts +0 -578
  201. package/src/state/selectors/touchSelectors.ts +0 -31
  202. package/src/state/store.ts +0 -29
  203. package/src/state/storeIdentity.ts +0 -9
  204. package/src/state/teardownWrite.ts +0 -10
  205. package/src/state/tooltipInteraction.ts +0 -23
  206. package/src/state/tooltipSlice.ts +0 -334
  207. package/src/state/touchEventsMiddleware.ts +0 -214
  208. package/src/state/types/AnimationSettings.ts +0 -20
  209. package/src/state/types/AreaSettings.ts +0 -14
  210. package/src/state/types/BarSettings.ts +0 -15
  211. package/src/state/types/LineSettings.ts +0 -9
  212. package/src/state/types/PieSettings.ts +0 -34
  213. package/src/state/types/RadarSettings.ts +0 -5
  214. package/src/state/types/RadialBarSettings.ts +0 -10
  215. package/src/state/types/ScatterSettings.ts +0 -12
  216. package/src/state/types/StackedGraphicalItem.ts +0 -34
  217. package/src/state/useChartState.ts +0 -17
  218. package/src/state/zIndexSlice.ts +0 -39
  219. package/src/synchronisation/syncSelectors.ts +0 -7
  220. package/src/synchronisation/types.ts +0 -44
  221. package/src/synchronisation/useChartSynchronisation.tsx +0 -404
  222. package/src/theme/RechartsTheme.ts +0 -16
  223. package/src/theme/RechartsThemeContext.ts +0 -19
  224. package/src/theme/darkTheme.ts +0 -13
  225. package/src/theme/graphicalItemIdentity.ts +0 -70
  226. package/src/theme/legacyTheme.ts +0 -17
  227. package/src/theme/lightTheme.ts +0 -13
  228. package/src/types.ts +0 -54
  229. package/src/util/ActiveShapeUtils.tsx +0 -162
  230. package/src/util/BarUtils.tsx +0 -62
  231. package/src/util/BarePortal.tsx +0 -50
  232. package/src/util/CamelCaseSVGAttrs.ts +0 -34
  233. package/src/util/CartesianUtils.ts +0 -48
  234. package/src/util/ChartUtils.ts +0 -802
  235. package/src/util/Constants.ts +0 -42
  236. package/src/util/CssPrefixUtils.ts +0 -20
  237. package/src/util/DOMUtils.ts +0 -129
  238. package/src/util/DataUtils.ts +0 -216
  239. package/src/util/Events.ts +0 -16
  240. package/src/util/FunnelUtils.tsx +0 -15
  241. package/src/util/Global.ts +0 -12
  242. package/src/util/IfOverflow.ts +0 -15
  243. package/src/util/LRUCache.ts +0 -41
  244. package/src/util/LogUtils.ts +0 -22
  245. package/src/util/PolarUtils.ts +0 -132
  246. package/src/util/RadialBarUtils.tsx +0 -24
  247. package/src/util/ReactUtils.ts +0 -95
  248. package/src/util/ReduceCSSCalc.ts +0 -187
  249. package/src/util/ScatterUtils.tsx +0 -52
  250. package/src/util/ShapeElementProps.tsx +0 -87
  251. package/src/util/TickUtils.ts +0 -60
  252. package/src/util/XAxisUtils.ts +0 -48
  253. package/src/util/YAxisUtils.ts +0 -48
  254. package/src/util/axisPropsAreEqual.ts +0 -48
  255. package/src/util/createCartesianCharts.tsx +0 -150
  256. package/src/util/createEventProxy.ts +0 -20
  257. package/src/util/createPolarCharts.tsx +0 -112
  258. package/src/util/cursor/getCursorPoints.ts +0 -46
  259. package/src/util/cursor/getCursorRectangle.ts +0 -28
  260. package/src/util/cursor/getRadialCursorPoints.ts +0 -32
  261. package/src/util/excludeEventProps.ts +0 -171
  262. package/src/util/getActiveCoordinate.ts +0 -213
  263. package/src/util/getAxisTypeBasedOnLayout.ts +0 -21
  264. package/src/util/getClassNameFromUnknown.ts +0 -6
  265. package/src/util/getEveryNth.ts +0 -27
  266. package/src/util/getRadiusAndStrokeWidthFromDot.ts +0 -35
  267. package/src/util/getRelativeCoordinate.ts +0 -80
  268. package/src/util/getSliced.ts +0 -13
  269. package/src/util/hoverDedupe.ts +0 -41
  270. package/src/util/isDomainSpecifiedByUser.ts +0 -219
  271. package/src/util/isWellBehavedNumber.ts +0 -7
  272. package/src/util/pathTotalLength.ts +0 -25
  273. package/src/util/payload/getUniqPayload.ts +0 -28
  274. package/src/util/propsAreEqual.ts +0 -121
  275. package/src/util/resolveDefaultProps.ts +0 -161
  276. package/src/util/round.ts +0 -32
  277. package/src/util/scale/CartesianScaleHelper.ts +0 -72
  278. package/src/util/scale/CustomScaleDefinition.ts +0 -81
  279. package/src/util/scale/RechartsScale.ts +0 -130
  280. package/src/util/scale/createCategoricalInverse.ts +0 -72
  281. package/src/util/scale/getNiceTickValues.ts +0 -311
  282. package/src/util/scale/index.ts +0 -2
  283. package/src/util/scale/util/arithmetic.ts +0 -54
  284. package/src/util/solid-1-compat.ts +0 -310
  285. package/src/util/solidJsxCamelAugment.d.ts +0 -84
  286. package/src/util/stacks/getStackSeriesIdentifier.ts +0 -21
  287. package/src/util/stacks/stackTypes.ts +0 -60
  288. package/src/util/structurallyEqual.ts +0 -31
  289. package/src/util/svgPropertiesAndEvents.ts +0 -53
  290. package/src/util/svgPropertiesNoEvents.ts +0 -571
  291. package/src/util/tooltip/translate.ts +0 -171
  292. package/src/util/typedDataKey.ts +0 -48
  293. package/src/util/types.ts +0 -1560
  294. package/src/util/useAnimationId.ts +0 -31
  295. package/src/util/useElementOffset.ts +0 -110
  296. package/src/util/useId.ts +0 -8
  297. package/src/util/usePrefersReducedMotion.ts +0 -48
  298. package/src/util/useReportScale.ts +0 -24
  299. package/src/util/useUniqueId.ts +0 -30
  300. package/src/zIndex/DefaultZIndexes.ts +0 -84
  301. package/src/zIndex/ZIndexLayer.tsx +0 -121
  302. package/src/zIndex/ZIndexPortal.tsx +0 -79
  303. package/src/zIndex/getZIndexFromUnknown.ts +0 -14
  304. package/src/zIndex/zIndexSelectors.ts +0 -48
@@ -1,27 +0,0 @@
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
@@ -1,25 +0,0 @@
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
@@ -1,89 +0,0 @@
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
- }
@@ -1,343 +0,0 @@
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
- }
package/src/shape/Dot.tsx DELETED
@@ -1,70 +0,0 @@
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
- }