@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.
Files changed (306) hide show
  1. package/LICENSE +22 -0
  2. package/NOTICE +19 -0
  3. package/README.md +102 -0
  4. package/dist/dev.js +28564 -0
  5. package/dist/index.d.ts +7859 -0
  6. package/dist/index.js +28546 -0
  7. package/package.json +98 -0
  8. package/src/animation/AnimatedItems.tsx +183 -0
  9. package/src/animation/AnimationController.ts +33 -0
  10. package/src/animation/AnimationControllerImpl.ts +36 -0
  11. package/src/animation/AnimationHandle.ts +307 -0
  12. package/src/animation/CSSTransitionAnimate.tsx +170 -0
  13. package/src/animation/JavascriptAnimate.tsx +119 -0
  14. package/src/animation/easing.ts +221 -0
  15. package/src/animation/matchBy.ts +164 -0
  16. package/src/animation/timeoutController.ts +70 -0
  17. package/src/animation/useAnimationController.tsx +34 -0
  18. package/src/animation/useAnimationStartSnapshot.ts +118 -0
  19. package/src/animation/util.ts +41 -0
  20. package/src/cartesian/Area.tsx +915 -0
  21. package/src/cartesian/AreaRevealShape.tsx +190 -0
  22. package/src/cartesian/Bar.tsx +1369 -0
  23. package/src/cartesian/BarStack.tsx +152 -0
  24. package/src/cartesian/Brush.tsx +951 -0
  25. package/src/cartesian/CartesianAxis.tsx +722 -0
  26. package/src/cartesian/CartesianGrid.tsx +711 -0
  27. package/src/cartesian/ErrorBar.tsx +361 -0
  28. package/src/cartesian/Funnel.tsx +803 -0
  29. package/src/cartesian/GraphicalItemClipPath.tsx +67 -0
  30. package/src/cartesian/Line.tsx +863 -0
  31. package/src/cartesian/LineDrawShape.tsx +89 -0
  32. package/src/cartesian/ReferenceArea.tsx +331 -0
  33. package/src/cartesian/ReferenceDot.tsx +304 -0
  34. package/src/cartesian/ReferenceLine.tsx +474 -0
  35. package/src/cartesian/Scatter.tsx +888 -0
  36. package/src/cartesian/XAxis.tsx +433 -0
  37. package/src/cartesian/YAxis.tsx +443 -0
  38. package/src/cartesian/ZAxis.tsx +155 -0
  39. package/src/cartesian/cartesianPositionToCSSTranslate.tsx +29 -0
  40. package/src/cartesian/cartesianViewBoxToTrapezoid.tsx +21 -0
  41. package/src/cartesian/getCartesianPosition.tsx +267 -0
  42. package/src/cartesian/getEquidistantTicks.ts +144 -0
  43. package/src/cartesian/getTicks.ts +225 -0
  44. package/src/cartesian/isOutsidePosition.ts +15 -0
  45. package/src/cartesian/useAnimatedLineLength.ts +54 -0
  46. package/src/chart/AreaChart.tsx +29 -0
  47. package/src/chart/BarChart.tsx +29 -0
  48. package/src/chart/CartesianChart.tsx +131 -0
  49. package/src/chart/CategoricalChart.tsx +94 -0
  50. package/src/chart/ComposedChart.tsx +29 -0
  51. package/src/chart/FunnelChart.tsx +29 -0
  52. package/src/chart/LineChart.tsx +29 -0
  53. package/src/chart/PieChart.tsx +50 -0
  54. package/src/chart/PolarChart.tsx +164 -0
  55. package/src/chart/RadarChart.tsx +70 -0
  56. package/src/chart/RadialBarChart.tsx +46 -0
  57. package/src/chart/RechartsWrapper.tsx +551 -0
  58. package/src/chart/Sankey.tsx +1534 -0
  59. package/src/chart/ScatterChart.tsx +29 -0
  60. package/src/chart/SunburstChart.tsx +504 -0
  61. package/src/chart/Treemap.tsx +1223 -0
  62. package/src/chart/createInitialRootProps.ts +24 -0
  63. package/src/chart/types.ts +53 -0
  64. package/src/component/ActivePoints.tsx +144 -0
  65. package/src/component/Cell.tsx +37 -0
  66. package/src/component/Cursor.tsx +185 -0
  67. package/src/component/Customized.tsx +50 -0
  68. package/src/component/DefaultLegendContent.tsx +348 -0
  69. package/src/component/DefaultTooltipContent.tsx +224 -0
  70. package/src/component/Dots.tsx +157 -0
  71. package/src/component/Label.tsx +636 -0
  72. package/src/component/LabelList.tsx +375 -0
  73. package/src/component/Legend.tsx +512 -0
  74. package/src/component/ResponsiveContainer.tsx +348 -0
  75. package/src/component/Text.tsx +541 -0
  76. package/src/component/Tooltip.tsx +470 -0
  77. package/src/component/TooltipBoundingBox.tsx +146 -0
  78. package/src/component/responsiveContainerUtils.ts +134 -0
  79. package/src/container/ClipPathProvider.tsx +51 -0
  80. package/src/container/Layer.tsx +38 -0
  81. package/src/container/RootSurface.tsx +120 -0
  82. package/src/container/Surface.tsx +61 -0
  83. package/src/context/CellsContext.tsx +54 -0
  84. package/src/context/ErrorBarContext.tsx +146 -0
  85. package/src/context/GraphicalItemChildrenScope.tsx +18 -0
  86. package/src/context/PanoramaContext.tsx +9 -0
  87. package/src/context/RegisterGraphicalItemId.tsx +30 -0
  88. package/src/context/accessibilityContext.tsx +6 -0
  89. package/src/context/brushUpdateContext.tsx +9 -0
  90. package/src/context/chartDataContext.tsx +97 -0
  91. package/src/context/chartLayoutContext.tsx +201 -0
  92. package/src/context/legendPayloadContext.tsx +20 -0
  93. package/src/context/legendPortalContext.tsx +12 -0
  94. package/src/context/tooltipContext.tsx +89 -0
  95. package/src/context/tooltipPortalContext.tsx +12 -0
  96. package/src/context/useTooltipAxis.ts +22 -0
  97. package/src/hooks.ts +476 -0
  98. package/src/index.ts +280 -0
  99. package/src/polar/Pie.tsx +1360 -0
  100. package/src/polar/PolarAngleAxis.tsx +616 -0
  101. package/src/polar/PolarGrid.tsx +312 -0
  102. package/src/polar/PolarRadiusAxis.tsx +547 -0
  103. package/src/polar/Radar.tsx +734 -0
  104. package/src/polar/RadialBar.tsx +917 -0
  105. package/src/polar/defaultPolarAngleAxisProps.tsx +27 -0
  106. package/src/polar/defaultPolarRadiusAxisProps.tsx +25 -0
  107. package/src/shape/Cross.tsx +89 -0
  108. package/src/shape/Curve.tsx +343 -0
  109. package/src/shape/Dot.tsx +70 -0
  110. package/src/shape/Polygon.tsx +195 -0
  111. package/src/shape/Rectangle.tsx +470 -0
  112. package/src/shape/Sector.tsx +347 -0
  113. package/src/shape/Symbols.tsx +139 -0
  114. package/src/shape/Trapezoid.tsx +280 -0
  115. package/src/state/RechartsStateContext.tsx +12 -0
  116. package/src/state/RechartsStateProvider.tsx +87 -0
  117. package/src/state/RechartsStoreContext.tsx +25 -0
  118. package/src/state/RechartsStoreProvider.tsx +35 -0
  119. package/src/state/ReportChartProps.tsx +40 -0
  120. package/src/state/ReportEventSettings.tsx +30 -0
  121. package/src/state/ReportMainChartProps.tsx +61 -0
  122. package/src/state/ReportPolarOptions.tsx +35 -0
  123. package/src/state/SetGraphicalItem.ts +79 -0
  124. package/src/state/SetLegendPayload.ts +134 -0
  125. package/src/state/SetTooltipEntrySettings.tsx +72 -0
  126. package/src/state/actions.ts +464 -0
  127. package/src/state/brushSlice.ts +13 -0
  128. package/src/state/cartesianAxisSlice.ts +141 -0
  129. package/src/state/chartDataSlice.ts +50 -0
  130. package/src/state/chartState.ts +297 -0
  131. package/src/state/errorBarSlice.ts +29 -0
  132. package/src/state/eventSettingsSlice.ts +8 -0
  133. package/src/state/events.ts +76 -0
  134. package/src/state/externalEventsMiddleware.ts +255 -0
  135. package/src/state/graphicalItemsSlice.ts +74 -0
  136. package/src/state/hooks/useChartSelectors.tsx +45 -0
  137. package/src/state/keyboardEventsMiddleware.ts +228 -0
  138. package/src/state/layoutSlice.ts +21 -0
  139. package/src/state/legendSlice.ts +57 -0
  140. package/src/state/mouseEventsMiddleware.ts +185 -0
  141. package/src/state/optionsSlice.ts +47 -0
  142. package/src/state/polarAxisSlice.ts +10 -0
  143. package/src/state/polarOptionsSlice.ts +12 -0
  144. package/src/state/rawData.ts +26 -0
  145. package/src/state/referenceElementsSlice.ts +40 -0
  146. package/src/state/renderedTicksSlice.ts +15 -0
  147. package/src/state/rootPropsSlice.ts +47 -0
  148. package/src/state/selectors/areaSelectors.ts +240 -0
  149. package/src/state/selectors/arrayEqualityCheck.ts +29 -0
  150. package/src/state/selectors/axisSelectors.ts +2157 -0
  151. package/src/state/selectors/barSelectors.ts +310 -0
  152. package/src/state/selectors/barStackSelectors.ts +77 -0
  153. package/src/state/selectors/brushSelectors.ts +33 -0
  154. package/src/state/selectors/chartSelector.ts +185 -0
  155. package/src/state/selectors/combiners/combineActiveLabel.ts +16 -0
  156. package/src/state/selectors/combiners/combineActiveTooltipIndex.ts +95 -0
  157. package/src/state/selectors/combiners/combineAllBarPositions.ts +122 -0
  158. package/src/state/selectors/combiners/combineAxisRangeWithReverse.ts +16 -0
  159. package/src/state/selectors/combiners/combineBarPosition.ts +23 -0
  160. package/src/state/selectors/combiners/combineBarSizeList.ts +80 -0
  161. package/src/state/selectors/combiners/combineCheckedDomain.ts +48 -0
  162. package/src/state/selectors/combiners/combineConfiguredScale.ts +111 -0
  163. package/src/state/selectors/combiners/combineCoordinateForDefaultIndex.ts +45 -0
  164. package/src/state/selectors/combiners/combineDisplayedStackedData.ts +50 -0
  165. package/src/state/selectors/combiners/combineInverseScaleFunction.ts +16 -0
  166. package/src/state/selectors/combiners/combineRealScaleType.ts +44 -0
  167. package/src/state/selectors/combiners/combineStackedData.ts +27 -0
  168. package/src/state/selectors/combiners/combineTooltipInteractionState.ts +86 -0
  169. package/src/state/selectors/combiners/combineTooltipPayload.ts +205 -0
  170. package/src/state/selectors/combiners/combineTooltipPayloadConfigurations.ts +58 -0
  171. package/src/state/selectors/containerSelectors.ts +12 -0
  172. package/src/state/selectors/dataSelectors.ts +88 -0
  173. package/src/state/selectors/funnelSelectors.ts +75 -0
  174. package/src/state/selectors/graphicalItemSelectors.ts +30 -0
  175. package/src/state/selectors/legendSelectors.ts +29 -0
  176. package/src/state/selectors/lineSelectors.ts +134 -0
  177. package/src/state/selectors/numberDomainEqualityCheck.ts +14 -0
  178. package/src/state/selectors/pickAxisId.ts +5 -0
  179. package/src/state/selectors/pickAxisType.ts +3 -0
  180. package/src/state/selectors/pieSelectors.ts +97 -0
  181. package/src/state/selectors/polarAxisSelectors.ts +201 -0
  182. package/src/state/selectors/polarGridSelectors.ts +28 -0
  183. package/src/state/selectors/polarScaleSelectors.ts +133 -0
  184. package/src/state/selectors/polarSelectors.ts +219 -0
  185. package/src/state/selectors/radarSelectors.ts +191 -0
  186. package/src/state/selectors/radialBarSelectors.ts +435 -0
  187. package/src/state/selectors/rootPropsSelectors.ts +25 -0
  188. package/src/state/selectors/scatterSelectors.ts +96 -0
  189. package/src/state/selectors/selectActivePropsFromChartPointer.ts +26 -0
  190. package/src/state/selectors/selectAllAxes.ts +17 -0
  191. package/src/state/selectors/selectChartOffset.ts +16 -0
  192. package/src/state/selectors/selectChartOffsetInternal.ts +136 -0
  193. package/src/state/selectors/selectLegendArea.ts +20 -0
  194. package/src/state/selectors/selectPlotArea.ts +22 -0
  195. package/src/state/selectors/selectTooltipAxisId.ts +7 -0
  196. package/src/state/selectors/selectTooltipAxisType.ts +32 -0
  197. package/src/state/selectors/selectTooltipEventType.ts +48 -0
  198. package/src/state/selectors/selectTooltipPayloadSearcher.ts +6 -0
  199. package/src/state/selectors/selectTooltipSettings.ts +39 -0
  200. package/src/state/selectors/selectTooltipState.ts +8 -0
  201. package/src/state/selectors/selectors.ts +271 -0
  202. package/src/state/selectors/tooltipSelectors.ts +578 -0
  203. package/src/state/selectors/touchSelectors.ts +31 -0
  204. package/src/state/store.ts +29 -0
  205. package/src/state/storeIdentity.ts +9 -0
  206. package/src/state/teardownWrite.ts +10 -0
  207. package/src/state/tooltipInteraction.ts +23 -0
  208. package/src/state/tooltipSlice.ts +334 -0
  209. package/src/state/touchEventsMiddleware.ts +214 -0
  210. package/src/state/types/AnimationSettings.ts +20 -0
  211. package/src/state/types/AreaSettings.ts +14 -0
  212. package/src/state/types/BarSettings.ts +15 -0
  213. package/src/state/types/LineSettings.ts +9 -0
  214. package/src/state/types/PieSettings.ts +34 -0
  215. package/src/state/types/RadarSettings.ts +5 -0
  216. package/src/state/types/RadialBarSettings.ts +10 -0
  217. package/src/state/types/ScatterSettings.ts +12 -0
  218. package/src/state/types/StackedGraphicalItem.ts +34 -0
  219. package/src/state/useChartState.ts +17 -0
  220. package/src/state/zIndexSlice.ts +39 -0
  221. package/src/synchronisation/syncSelectors.ts +7 -0
  222. package/src/synchronisation/types.ts +44 -0
  223. package/src/synchronisation/useChartSynchronisation.tsx +404 -0
  224. package/src/theme/RechartsTheme.ts +16 -0
  225. package/src/theme/RechartsThemeContext.ts +19 -0
  226. package/src/theme/darkTheme.ts +13 -0
  227. package/src/theme/graphicalItemIdentity.ts +70 -0
  228. package/src/theme/legacyTheme.ts +17 -0
  229. package/src/theme/lightTheme.ts +13 -0
  230. package/src/types.ts +54 -0
  231. package/src/util/ActiveShapeUtils.tsx +162 -0
  232. package/src/util/BarUtils.tsx +62 -0
  233. package/src/util/BarePortal.tsx +50 -0
  234. package/src/util/CamelCaseSVGAttrs.ts +34 -0
  235. package/src/util/CartesianUtils.ts +48 -0
  236. package/src/util/ChartUtils.ts +802 -0
  237. package/src/util/Constants.ts +42 -0
  238. package/src/util/CssPrefixUtils.ts +20 -0
  239. package/src/util/DOMUtils.ts +129 -0
  240. package/src/util/DataUtils.ts +216 -0
  241. package/src/util/Events.ts +16 -0
  242. package/src/util/FunnelUtils.tsx +15 -0
  243. package/src/util/Global.ts +12 -0
  244. package/src/util/IfOverflow.ts +15 -0
  245. package/src/util/LRUCache.ts +41 -0
  246. package/src/util/LogUtils.ts +22 -0
  247. package/src/util/PolarUtils.ts +132 -0
  248. package/src/util/RadialBarUtils.tsx +24 -0
  249. package/src/util/ReactUtils.ts +95 -0
  250. package/src/util/ReduceCSSCalc.ts +187 -0
  251. package/src/util/ScatterUtils.tsx +52 -0
  252. package/src/util/ShapeElementProps.tsx +87 -0
  253. package/src/util/TickUtils.ts +60 -0
  254. package/src/util/XAxisUtils.ts +48 -0
  255. package/src/util/YAxisUtils.ts +48 -0
  256. package/src/util/axisPropsAreEqual.ts +48 -0
  257. package/src/util/createCartesianCharts.tsx +150 -0
  258. package/src/util/createEventProxy.ts +20 -0
  259. package/src/util/createPolarCharts.tsx +112 -0
  260. package/src/util/cursor/getCursorPoints.ts +46 -0
  261. package/src/util/cursor/getCursorRectangle.ts +28 -0
  262. package/src/util/cursor/getRadialCursorPoints.ts +32 -0
  263. package/src/util/excludeEventProps.ts +171 -0
  264. package/src/util/getActiveCoordinate.ts +213 -0
  265. package/src/util/getAxisTypeBasedOnLayout.ts +21 -0
  266. package/src/util/getClassNameFromUnknown.ts +6 -0
  267. package/src/util/getEveryNth.ts +27 -0
  268. package/src/util/getRadiusAndStrokeWidthFromDot.ts +35 -0
  269. package/src/util/getRelativeCoordinate.ts +80 -0
  270. package/src/util/getSliced.ts +13 -0
  271. package/src/util/hoverDedupe.ts +41 -0
  272. package/src/util/isDomainSpecifiedByUser.ts +219 -0
  273. package/src/util/isWellBehavedNumber.ts +7 -0
  274. package/src/util/pathTotalLength.ts +25 -0
  275. package/src/util/payload/getUniqPayload.ts +28 -0
  276. package/src/util/propsAreEqual.ts +121 -0
  277. package/src/util/resolveDefaultProps.ts +161 -0
  278. package/src/util/round.ts +32 -0
  279. package/src/util/scale/CartesianScaleHelper.ts +72 -0
  280. package/src/util/scale/CustomScaleDefinition.ts +81 -0
  281. package/src/util/scale/RechartsScale.ts +130 -0
  282. package/src/util/scale/createCategoricalInverse.ts +72 -0
  283. package/src/util/scale/getNiceTickValues.ts +311 -0
  284. package/src/util/scale/index.ts +2 -0
  285. package/src/util/scale/util/arithmetic.ts +54 -0
  286. package/src/util/solid-1-compat.ts +310 -0
  287. package/src/util/solidJsxCamelAugment.d.ts +84 -0
  288. package/src/util/stacks/getStackSeriesIdentifier.ts +21 -0
  289. package/src/util/stacks/stackTypes.ts +60 -0
  290. package/src/util/structurallyEqual.ts +31 -0
  291. package/src/util/svgPropertiesAndEvents.ts +53 -0
  292. package/src/util/svgPropertiesNoEvents.ts +571 -0
  293. package/src/util/tooltip/translate.ts +171 -0
  294. package/src/util/typedDataKey.ts +48 -0
  295. package/src/util/types.ts +1560 -0
  296. package/src/util/useAnimationId.ts +31 -0
  297. package/src/util/useElementOffset.ts +110 -0
  298. package/src/util/useId.ts +8 -0
  299. package/src/util/usePrefersReducedMotion.ts +48 -0
  300. package/src/util/useReportScale.ts +24 -0
  301. package/src/util/useUniqueId.ts +30 -0
  302. package/src/zIndex/DefaultZIndexes.ts +84 -0
  303. package/src/zIndex/ZIndexLayer.tsx +121 -0
  304. package/src/zIndex/ZIndexPortal.tsx +79 -0
  305. package/src/zIndex/getZIndexFromUnknown.ts +14 -0
  306. package/src/zIndex/zIndexSelectors.ts +48 -0
@@ -0,0 +1,42 @@
1
+ export const COLOR_PANEL = [
2
+ "#1890FF",
3
+ "#66B5FF",
4
+ "#41D9C7",
5
+ "#2FC25B",
6
+ "#6EDB8F",
7
+ "#9AE65C",
8
+ "#FACC14",
9
+ "#E6965C",
10
+ "#57AD71",
11
+ "#223273",
12
+ "#738AE6",
13
+ "#7564CC",
14
+ "#8543E0",
15
+ "#A877ED",
16
+ "#5C8EE6",
17
+ "#13C2C2",
18
+ "#70E0E0",
19
+ "#5CA3E6",
20
+ "#3436C7",
21
+ "#8082FF",
22
+ "#DD81E6",
23
+ "#F04864",
24
+ "#FA7D92",
25
+ "#D598D9",
26
+ ]
27
+
28
+ /**
29
+ * We use this attribute to identify which element is the one that the user is touching.
30
+ * The index is the position of the element in the data array.
31
+ * This can be either a number (for array-based charts) or a string (for the charts that have a matrix-shaped data).
32
+ */
33
+ export const DATA_ITEM_INDEX_ATTRIBUTE_NAME = "data-recharts-item-index"
34
+
35
+ /**
36
+ * We use this attribute to identify which element is the one that the user is touching.
37
+ * Unlike dataKey, or name, it is always unique.
38
+ */
39
+ export const DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME = "data-recharts-item-id"
40
+
41
+ export const DEFAULT_Y_AXIS_WIDTH = 60
42
+ export const DEFAULT_X_AXIS_HEIGHT = 30
@@ -0,0 +1,20 @@
1
+ const PREFIX_LIST = ["Webkit", "Moz", "O", "ms"]
2
+
3
+ export const generatePrefixStyle = (name: string, value: string) => {
4
+ if (!name) {
5
+ return undefined
6
+ }
7
+
8
+ const camelName = name.replace(/(\w)/, (v) => v.toUpperCase())
9
+ const result: Record<string, string> = PREFIX_LIST.reduce(
10
+ (res: Record<string, string>, entry) => {
11
+ res[entry + camelName] = value
12
+ return res
13
+ },
14
+ {},
15
+ )
16
+
17
+ result[name] = value
18
+
19
+ return result
20
+ }
@@ -0,0 +1,129 @@
1
+ /* eslint-disable import/no-cycle */
2
+ import type { JSX } from '@solidjs/web';
3
+ import { Global } from "./Global"
4
+ import { Size } from "./types"
5
+ import { LRUCache } from "./LRUCache"
6
+
7
+ export interface TextMeasurementConfig {
8
+ /** Maximum number of items to cache */
9
+ cacheSize: number
10
+ /** Whether to enable caching */
11
+ enableCache: boolean
12
+ }
13
+
14
+ const defaultConfig: TextMeasurementConfig = {
15
+ cacheSize: 2000,
16
+ enableCache: true,
17
+ }
18
+
19
+ let currentConfig = { ...defaultConfig }
20
+
21
+ let stringCache = new LRUCache<string, Size>(currentConfig.cacheSize)
22
+ const SPAN_STYLE = {
23
+ border: "none",
24
+ left: 0,
25
+ margin: 0,
26
+ padding: 0,
27
+ position: "absolute",
28
+ top: "-20000px",
29
+ whiteSpace: "pre",
30
+ }
31
+ const MEASUREMENT_SPAN_ID = "recharts_measurement_span"
32
+
33
+ function createCacheKey(text: string | number, style: JSX.CSSProperties): string {
34
+ const fontSize = style["font-size"] || ""
35
+ const fontFamily = style["font-family"] || ""
36
+ const fontWeight = style["font-weight"] || ""
37
+ const fontStyle = style["font-style"] || ""
38
+ const letterSpacing = style["letter-spacing"] || ""
39
+ const textTransform = style["text-transform"] || ""
40
+
41
+ return `${text}|${fontSize}|${fontFamily}|${fontWeight}|${fontStyle}|${letterSpacing}|${textTransform}`
42
+ }
43
+
44
+ /**
45
+ * Measure text using DOM (accurate but slower)
46
+ * @param text - The text to measure
47
+ * @param style - CSS style properties to apply
48
+ * @returns The size of the text
49
+ */
50
+ const measureTextWithDOM = (text: string | number, style: JSX.CSSProperties): Size => {
51
+ try {
52
+ let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID)
53
+ if (!measurementSpan) {
54
+ measurementSpan = document.createElement("span")
55
+ measurementSpan.setAttribute("id", MEASUREMENT_SPAN_ID)
56
+ measurementSpan.setAttribute("aria-hidden", "true")
57
+ document.body.appendChild(measurementSpan)
58
+ }
59
+
60
+ Object.assign(measurementSpan.style, SPAN_STYLE, style)
61
+ measurementSpan.textContent = `${text}`
62
+
63
+ const rect = measurementSpan.getBoundingClientRect()
64
+ return { height: rect.height, width: rect.width }
65
+ } catch {
66
+ return { height: 0, width: 0 }
67
+ }
68
+ }
69
+
70
+ export const getStringSize = (text: string | number, style: JSX.CSSProperties = {}): Size => {
71
+ if (text === undefined || text === null || Global.isSsr) {
72
+ return { height: 0, width: 0 }
73
+ }
74
+
75
+ if (!currentConfig.enableCache) {
76
+ return measureTextWithDOM(text, style)
77
+ }
78
+
79
+ const cacheKey = createCacheKey(text, style)
80
+ const cachedResult = stringCache.get(cacheKey)
81
+
82
+ if (cachedResult) {
83
+ return cachedResult
84
+ }
85
+
86
+ const result = measureTextWithDOM(text, style)
87
+
88
+ stringCache.set(cacheKey, result)
89
+
90
+ return result
91
+ }
92
+
93
+ /**
94
+ * Configure text measurement behavior
95
+ * @param config - Partial configuration to apply
96
+ * @returns void
97
+ */
98
+ export const configureTextMeasurement = (config: Partial<TextMeasurementConfig>): void => {
99
+ const newConfig = { ...currentConfig, ...config }
100
+
101
+ if (newConfig.cacheSize !== currentConfig.cacheSize) {
102
+ stringCache = new LRUCache<string, Size>(newConfig.cacheSize)
103
+ }
104
+
105
+ currentConfig = newConfig
106
+ }
107
+
108
+ /**
109
+ * Get current text measurement configuration
110
+ * @returns Current configuration
111
+ */
112
+ export const getTextMeasurementConfig = (): TextMeasurementConfig => ({ ...currentConfig })
113
+
114
+ /**
115
+ * Clear the string size cache. Useful for testing or memory management.
116
+ * @returns void
117
+ */
118
+ export const clearStringCache = (): void => {
119
+ stringCache.clear()
120
+ }
121
+
122
+ /**
123
+ * Get cache statistics for debugging purposes.
124
+ * @returns Cache statistics including size and max size
125
+ */
126
+ export const getStringCacheStats = () => ({
127
+ maxSize: currentConfig.cacheSize,
128
+ size: stringCache.size(),
129
+ })
@@ -0,0 +1,216 @@
1
+ /* eslint-disable import/no-cycle */
2
+ import get from "es-toolkit/compat/get"
3
+ import { NonEmptyArray, Percent } from "./types"
4
+ import { round } from "./round"
5
+
6
+ export const mathSign = (value: number) => {
7
+ if (value === 0) {
8
+ return 0
9
+ }
10
+ if (value > 0) {
11
+ return 1
12
+ }
13
+
14
+ return -1
15
+ }
16
+
17
+ export const isNan = (value: unknown): value is number => {
18
+ return typeof value === "number" && value !== +value
19
+ }
20
+
21
+ export const isPercent = (value: string | number | undefined): value is Percent =>
22
+ typeof value === "string" && value.indexOf("%") === value.length - 1
23
+
24
+ export const isNumber = (value: unknown): value is number =>
25
+ (typeof value === "number" || (typeof value === "object" && value !== null && Object.prototype.toString.call(value) === "[object Number]")) && !isNan(value)
26
+
27
+ export const isNumOrStr = (value: unknown): value is number | string =>
28
+ isNumber(value) || typeof value === "string"
29
+
30
+ let idCounter = 0
31
+ export const uniqueId = (prefix?: string) => {
32
+ const id = ++idCounter
33
+
34
+ return `${prefix || ""}${id}`
35
+ }
36
+
37
+ /**
38
+ * Calculates the numeric value represented by a percent string or number, based on a total value.
39
+ *
40
+ * - If `percent` is not a number or string, returns `defaultValue`.
41
+ * - If `percent` is a percent string but `totalValue` is null/undefined, returns `defaultValue`.
42
+ * - If the result is NaN, returns `defaultValue`.
43
+ * - If `validate` is true and the result exceeds `totalValue`, returns `totalValue`.
44
+ *
45
+ * @param percent - The percent value to convert. Can be a number (e.g. 25) or a string ending with '%' (e.g. '25%').
46
+ * If a string, it must end with '%' to be treated as a percent; otherwise, it is parsed as a number.
47
+ * @param totalValue - The total value to calculate the percent of. Required if `percent` is a percent string.
48
+ * @param defaultValue - The value returned if `percent` is undefined, invalid, or cannot be converted to a number.
49
+ * @param validate - If true, ensures the result does not exceed `totalValue` (when provided).
50
+ * @returns The calculated value, or `defaultValue` for invalid input.
51
+ */
52
+ export const getPercentValue = (
53
+ percent: number | string | undefined,
54
+ totalValue: number | undefined,
55
+ defaultValue = 0,
56
+ validate = false,
57
+ ) => {
58
+ if (!isNumber(percent) && typeof percent !== "string") {
59
+ return defaultValue
60
+ }
61
+
62
+ let value: number
63
+
64
+ if (isPercent(percent)) {
65
+ if (totalValue == null) {
66
+ return defaultValue
67
+ }
68
+ const index = percent.indexOf("%")
69
+ value = (totalValue * parseFloat((percent as string).slice(0, index))) / 100
70
+ } else {
71
+ value = +percent
72
+ }
73
+
74
+ if (isNan(value)) {
75
+ value = defaultValue
76
+ }
77
+
78
+ if (validate && totalValue != null && value > totalValue) {
79
+ value = totalValue
80
+ }
81
+
82
+ return value
83
+ }
84
+
85
+ export const hasDuplicate = (ary: ReadonlyArray<unknown>): boolean => {
86
+ if (!Array.isArray(ary)) {
87
+ return false
88
+ }
89
+
90
+ const len = ary.length
91
+ const cache: Record<string, boolean> = {}
92
+
93
+ for (let i = 0; i < len; i++) {
94
+ if (!cache[String(ary[i])]) {
95
+ cache[String(ary[i])] = true
96
+ } else {
97
+ return true
98
+ }
99
+ }
100
+
101
+ return false
102
+ }
103
+
104
+ export function interpolate(start: unknown, end: number, t: number): number
105
+ export function interpolate(start: unknown, end: null, t: number): null
106
+ export function interpolate(start: unknown, end: number | null, t: number): number | null
107
+ export function interpolate(start: unknown, end: number | null, t: number): number | null {
108
+ if (isNumber(start) && isNumber(end)) {
109
+ return round(start + t * (end - start))
110
+ }
111
+ return end
112
+ }
113
+
114
+ export function findEntryInArray<T>(
115
+ ary: ReadonlyArray<T>,
116
+ specifiedKey: number | string | ((entry: T) => unknown),
117
+ specifiedValue: unknown,
118
+ ): T | undefined {
119
+ if (!ary || !ary.length) {
120
+ return undefined
121
+ }
122
+
123
+ return ary.find(
124
+ (entry) =>
125
+ entry &&
126
+ (typeof specifiedKey === "function" ? specifiedKey(entry) : get(entry, specifiedKey)) ===
127
+ specifiedValue,
128
+ )
129
+ }
130
+
131
+ type LinearRegressionResult = {
132
+ xmin: number
133
+ xmax: number
134
+ a: number
135
+ b: number
136
+ }
137
+
138
+ /**
139
+ * The least square linear regression
140
+ * @param {Array} data The array of points
141
+ * @returns {Object} The domain of x, and the parameter of linear function
142
+ */
143
+ export const getLinearRegression = (
144
+ data: NonEmptyArray<{ cx?: number; cy?: number }>,
145
+ ): LinearRegressionResult => {
146
+ const len = data.length
147
+ let xsum = 0
148
+ let ysum = 0
149
+ let xysum = 0
150
+ let xxsum = 0
151
+ let xmin = Infinity
152
+ let xmax = -Infinity
153
+ let xcurrent = 0
154
+ let ycurrent = 0
155
+
156
+ for (let i = 0; i < len; i++) {
157
+ xcurrent = data[i]?.cx || 0
158
+ ycurrent = data[i]?.cy || 0
159
+
160
+ xsum += xcurrent
161
+ ysum += ycurrent
162
+ xysum += xcurrent * ycurrent
163
+ xxsum += xcurrent * xcurrent
164
+ xmin = Math.min(xmin, xcurrent)
165
+ xmax = Math.max(xmax, xcurrent)
166
+ }
167
+
168
+ const a =
169
+ len * xxsum !== xsum * xsum ? (len * xysum - xsum * ysum) / (len * xxsum - xsum * xsum) : 0
170
+
171
+ return {
172
+ a,
173
+ b: (ysum - a * xsum) / len,
174
+ xmax,
175
+ xmin,
176
+ }
177
+ }
178
+
179
+ type Nullish = null | undefined
180
+
181
+ /**
182
+ * Checks if the value is null or undefined
183
+ * @param value The value to check
184
+ * @returns true if the value is null or undefined
185
+ */
186
+ export const isNullish = (value: unknown): value is Nullish => {
187
+ return value === null || typeof value === "undefined"
188
+ }
189
+
190
+ /**
191
+ * Uppercase the first letter of a string
192
+ * @param {string} value The string to uppercase
193
+ * @returns {string} The uppercased string
194
+ */
195
+ export const upperFirst = (value: string): string => {
196
+ if (isNullish(value)) {
197
+ return value
198
+ }
199
+
200
+ return `${value.charAt(0).toUpperCase()}${value.slice(1)}`
201
+ }
202
+
203
+ /**
204
+ * Checks if the value is not null nor undefined.
205
+ * @param value The value to check
206
+ * @returns true if the value is not null nor undefined
207
+ */
208
+ export function isNotNil<T>(value: T): value is NonNullable<T> {
209
+ return value != null
210
+ }
211
+
212
+ /**
213
+ * No-operation function that does nothing.
214
+ * Useful as a placeholder or default callback function.
215
+ */
216
+ export function noop(): undefined {}
@@ -0,0 +1,16 @@
1
+ import EventEmitter from "eventemitter3"
2
+ import type { BrushStartEndIndex } from "../context/brushUpdateContext"
3
+ import type { TooltipSyncState } from "../state/tooltipSlice"
4
+
5
+ const eventCenter: EventEmitter<EventTypes> = new EventEmitter()
6
+
7
+ export { eventCenter }
8
+
9
+ export const TOOLTIP_SYNC_EVENT = "recharts.syncEvent.tooltip"
10
+
11
+ export const BRUSH_SYNC_EVENT = "recharts.syncEvent.brush"
12
+
13
+ interface EventTypes {
14
+ [TOOLTIP_SYNC_EVENT](syncId: number | string, data: TooltipSyncState, emitter: symbol): void
15
+ [BRUSH_SYNC_EVENT](syncId: number | string, data: BrushStartEndIndex, emitter: symbol): void
16
+ }
@@ -0,0 +1,15 @@
1
+ /* eslint-disable import/no-cycle */
2
+ import type { JSX } from '@solidjs/web';
3
+ import { Props as FunnelProps, FunnelTrapezoidItem } from "../cartesian/Funnel"
4
+ import { Shape } from "./ActiveShapeUtils"
5
+ import type { ShapeAnimationProps } from "./types"
6
+
7
+ export type FunnelTrapezoidProps = {
8
+ option: FunnelProps["activeShape"]
9
+ isActive: boolean
10
+ } & ShapeAnimationProps &
11
+ FunnelTrapezoidItem
12
+
13
+ export function FunnelTrapezoid(props: FunnelTrapezoidProps): JSX.Element {
14
+ return <Shape shapeType="trapezoid" {...props} />
15
+ }
@@ -0,0 +1,12 @@
1
+ const parseIsSsrByDefault = (): boolean =>
2
+ !(
3
+ typeof window !== "undefined" &&
4
+ window.document &&
5
+ Boolean(window.document.createElement) &&
6
+ window.setTimeout
7
+ )
8
+
9
+ export const Global = {
10
+ devToolsEnabled: process.env.NODE_ENV !== "production",
11
+ isSsr: parseIsSsrByDefault(),
12
+ }
@@ -0,0 +1,15 @@
1
+ export type IfOverflow = "hidden" | "visible" | "discard" | "extendDomain"
2
+
3
+ export interface Overflowable {
4
+ /**
5
+ * Defines how to draw this component if it falls partly outside the canvas:
6
+ *
7
+ * - `discard`: the whole component will not be drawn at all
8
+ * - `hidden`: the component will be clipped to the chart plot area
9
+ * - `visible`: the component will be drawn completely
10
+ * - `extendDomain`: the domain of the overflown axis will be extended such that the whole component fits into the plot area
11
+ *
12
+ * @defaultValue discard
13
+ */
14
+ ifOverflow?: IfOverflow
15
+ }
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Simple LRU (Least Recently Used) cache implementation
3
+ */
4
+ export class LRUCache<K, V> {
5
+ private cache = new Map<K, V>()
6
+
7
+ private maxSize: number
8
+
9
+ constructor(maxSize: number) {
10
+ this.maxSize = maxSize
11
+ }
12
+
13
+ get(key: K): V | undefined {
14
+ const value = this.cache.get(key)
15
+ if (value !== undefined) {
16
+ this.cache.delete(key)
17
+ this.cache.set(key, value)
18
+ }
19
+ return value
20
+ }
21
+
22
+ set(key: K, value: V): void {
23
+ if (this.cache.has(key)) {
24
+ this.cache.delete(key)
25
+ } else if (this.cache.size >= this.maxSize) {
26
+ const firstKey = this.cache.keys().next().value
27
+ if (firstKey != null) {
28
+ this.cache.delete(firstKey)
29
+ }
30
+ }
31
+ this.cache.set(key, value)
32
+ }
33
+
34
+ clear(): void {
35
+ this.cache.clear()
36
+ }
37
+
38
+ size(): number {
39
+ return this.cache.size
40
+ }
41
+ }
@@ -0,0 +1,22 @@
1
+ const isDev = process.env.NODE_ENV !== "production"
2
+
3
+ export const warn = (condition: boolean, format: string, ...args: Array<unknown>) => {
4
+ if (isDev && typeof console !== "undefined" && console.warn) {
5
+ if (format === undefined) {
6
+ console.warn("LogUtils requires an error message argument")
7
+ }
8
+
9
+ if (!condition) {
10
+ if (format === undefined) {
11
+ console.warn(
12
+ "Minified exception occurred; use the non-minified dev environment " +
13
+ "for the full error message and additional helpful warnings.",
14
+ )
15
+ } else {
16
+ let argIndex = 0
17
+
18
+ console.warn(format.replace(/%s/g, () => String(args[argIndex++])))
19
+ }
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,132 @@
1
+ /* eslint-disable import/no-cycle */
2
+ import {
3
+ ChartOffsetInternal,
4
+ RelativePointer,
5
+ Coordinate,
6
+ PolarViewBoxRequired,
7
+ RangeObj,
8
+ } from "./types"
9
+
10
+ export const RADIAN = Math.PI / 180
11
+
12
+ export const degreeToRadian = (angle: number) => (angle * Math.PI) / 180
13
+
14
+ export const radianToDegree = (angleInRadian: number) => (angleInRadian * 180) / Math.PI
15
+
16
+ export const polarToCartesian = (
17
+ cx: number,
18
+ cy: number,
19
+ radius: number,
20
+ angle: number,
21
+ ): Coordinate => ({
22
+ x: cx + Math.cos(-RADIAN * angle) * radius,
23
+ y: cy + Math.sin(-RADIAN * angle) * radius,
24
+ })
25
+
26
+ export const getMaxRadius = (
27
+ width: number,
28
+ height: number,
29
+ offset: ChartOffsetInternal = {
30
+ bottom: 0,
31
+ brushBottom: 0,
32
+ height: 0,
33
+ left: 0,
34
+ right: 0,
35
+ top: 0,
36
+ width: 0,
37
+ },
38
+ ) =>
39
+ Math.min(
40
+ Math.abs(width - (offset.left || 0) - (offset.right || 0)),
41
+ Math.abs(height - (offset.top || 0) - (offset.bottom || 0)),
42
+ ) / 2
43
+
44
+ const distanceBetweenPoints = (point: Coordinate, anotherPoint: Coordinate) => {
45
+ const { x: x1, y: y1 } = point
46
+ const { x: x2, y: y2 } = anotherPoint
47
+
48
+ return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
49
+ }
50
+
51
+ const getAngleOfPoint = ({ x, y }: Coordinate, { cx, cy }: PolarViewBoxRequired) => {
52
+ const radius = distanceBetweenPoints({ x, y }, { x: cx, y: cy })
53
+
54
+ if (radius <= 0) {
55
+ return { angle: 0, radius }
56
+ }
57
+
58
+ const cos = (x - cx) / radius
59
+ let angleInRadian = Math.acos(cos)
60
+
61
+ if (y > cy) {
62
+ angleInRadian = 2 * Math.PI - angleInRadian
63
+ }
64
+
65
+ return { angle: radianToDegree(angleInRadian), angleInRadian, radius }
66
+ }
67
+
68
+ const formatAngleOfSector = ({ startAngle, endAngle }: PolarViewBoxRequired) => {
69
+ const startCnt = Math.floor(startAngle / 360)
70
+ const endCnt = Math.floor(endAngle / 360)
71
+ const min = Math.min(startCnt, endCnt)
72
+
73
+ return {
74
+ endAngle: endAngle - min * 360,
75
+ startAngle: startAngle - min * 360,
76
+ }
77
+ }
78
+
79
+ const reverseFormatAngleOfSector = (
80
+ angle: number,
81
+ { startAngle, endAngle }: PolarViewBoxRequired,
82
+ ): number => {
83
+ const startCnt = Math.floor(startAngle / 360)
84
+ const endCnt = Math.floor(endAngle / 360)
85
+ const min = Math.min(startCnt, endCnt)
86
+
87
+ return angle + min * 360
88
+ }
89
+
90
+ export const inRangeOfSector = (
91
+ { relativeX: x, relativeY: y }: RelativePointer,
92
+ viewBox: PolarViewBoxRequired,
93
+ ): RangeObj | null => {
94
+ const { radius, angle } = getAngleOfPoint({ x, y }, viewBox)
95
+ const { innerRadius, outerRadius } = viewBox
96
+
97
+ if (radius < innerRadius || radius > outerRadius) {
98
+ return null
99
+ }
100
+
101
+ if (radius === 0) {
102
+ return null
103
+ }
104
+
105
+ const { startAngle, endAngle } = formatAngleOfSector(viewBox)
106
+ let formatAngle = angle
107
+ let inRange
108
+
109
+ if (startAngle <= endAngle) {
110
+ while (formatAngle > endAngle) {
111
+ formatAngle -= 360
112
+ }
113
+ while (formatAngle < startAngle) {
114
+ formatAngle += 360
115
+ }
116
+ inRange = formatAngle >= startAngle && formatAngle <= endAngle
117
+ } else {
118
+ while (formatAngle > startAngle) {
119
+ formatAngle -= 360
120
+ }
121
+ while (formatAngle < endAngle) {
122
+ formatAngle += 360
123
+ }
124
+ inRange = formatAngle >= endAngle && formatAngle <= startAngle
125
+ }
126
+
127
+ if (inRange) {
128
+ return { ...viewBox, angle: reverseFormatAngleOfSector(formatAngle, viewBox), radius }
129
+ }
130
+
131
+ return null
132
+ }
@@ -0,0 +1,24 @@
1
+ /* eslint-disable import/no-cycle */
2
+ import type { JSX } from '@solidjs/web';
3
+ import { RadialBarDataItem, RadialBarProps } from "../polar/RadialBar"
4
+ import { Shape } from "./ActiveShapeUtils"
5
+ import type { ShapeAnimationProps } from "./types"
6
+
7
+ export function parseCornerRadius(cornerRadius: string | number | undefined): number | undefined {
8
+ if (typeof cornerRadius === "string") {
9
+ return parseInt(cornerRadius, 10)
10
+ }
11
+
12
+ return cornerRadius
13
+ }
14
+
15
+ export interface RadialBarSectorProps extends RadialBarDataItem, ShapeAnimationProps {
16
+ index: number
17
+ option: RadialBarProps["activeShape"]
18
+ isActive: boolean
19
+ className?: string
20
+ }
21
+
22
+ export function RadialBarSector(props: RadialBarSectorProps): JSX.Element {
23
+ return <Shape shapeType="sector" {...props} />
24
+ }