vccs 0.1.0 → 0.3.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 (273) hide show
  1. package/README.md +151 -0
  2. package/dist/animation/Animate.d.ts +1 -1
  3. package/dist/cartesian/area/type.d.ts +3 -3
  4. package/dist/cartesian/bar/type.d.ts +1 -13
  5. package/dist/cartesian/brush/components/Slide.d.ts +1 -1
  6. package/dist/cartesian/brush/components/TravellerLayer.d.ts +1 -1
  7. package/dist/cartesian/brush/type.d.ts +2 -1
  8. package/dist/cartesian/cartesian-axis/CartesianAxis.d.ts +2 -1
  9. package/dist/cartesian/funnel/Funnel.d.ts +2 -0
  10. package/dist/cartesian/funnel/index.d.ts +2 -0
  11. package/dist/cartesian/funnel/type.d.ts +74 -6
  12. package/dist/cartesian/index.d.ts +2 -0
  13. package/dist/cartesian/line/Line.d.ts +7 -13
  14. package/dist/cartesian/line/type.d.ts +4 -17
  15. package/dist/cartesian/reference-area/ReferenceArea.d.ts +16 -16
  16. package/dist/cartesian/reference-dot/ReferenceDot.d.ts +143 -0
  17. package/dist/cartesian/reference-dot/index.d.ts +2 -0
  18. package/dist/cartesian/reference-line/ReferenceLine.d.ts +8 -8
  19. package/dist/cartesian/scatter/Scatter.d.ts +1 -1
  20. package/dist/chart/FunnelChart.d.ts +1 -0
  21. package/dist/chart/RechartsWrapper.d.ts +7 -3
  22. package/dist/chart/Surface.d.ts +2 -1
  23. package/dist/chart/Treemap.d.ts +237 -0
  24. package/dist/chart/generateCategoricalChart.d.ts +2 -1
  25. package/dist/chart/index.d.ts +2 -0
  26. package/dist/chart/treemapUtils.d.ts +22 -0
  27. package/dist/components/Customized.d.ts +23 -0
  28. package/dist/components/Text.d.ts +4 -4
  29. package/dist/components/Tooltip.d.ts +1 -1
  30. package/dist/components/index.d.ts +2 -0
  31. package/dist/components/label/Label.d.ts +3 -3
  32. package/dist/components/label/types.d.ts +1 -1
  33. package/dist/container/Surface.d.ts +3 -2
  34. package/dist/es/animation/Animate.mjs +48 -22
  35. package/dist/es/cartesian/GraphicalItemClipPath.mjs +16 -15
  36. package/dist/es/cartesian/area/ActivePoints.mjs +44 -40
  37. package/dist/es/cartesian/area/Area.mjs +42 -31
  38. package/dist/es/cartesian/area/ClipRect.mjs +79 -58
  39. package/dist/es/cartesian/area/RenderArea.mjs +142 -108
  40. package/dist/es/cartesian/area/hooks/useArea.mjs +71 -47
  41. package/dist/es/cartesian/area/type.mjs +13 -15
  42. package/dist/es/cartesian/area/utils.mjs +69 -49
  43. package/dist/es/cartesian/axis/XAxis.mjs +87 -73
  44. package/dist/es/cartesian/axis/YAxis.mjs +67 -56
  45. package/dist/es/cartesian/bar/Bar.mjs +78 -71
  46. package/dist/es/cartesian/bar/components/BarBackground.mjs +22 -19
  47. package/dist/es/cartesian/bar/components/BarRectangles.mjs +117 -80
  48. package/dist/es/cartesian/bar/hooks/useBar.mjs +49 -37
  49. package/dist/es/cartesian/bar/type.mjs +11 -25
  50. package/dist/es/cartesian/bar/utils.mjs +97 -70
  51. package/dist/es/cartesian/cartesian-axis/CartesianAxis.mjs +165 -115
  52. package/dist/es/cartesian/cartesian-grid/Background.mjs +19 -16
  53. package/dist/es/cartesian/cartesian-grid/CartesianGrid.mjs +116 -97
  54. package/dist/es/cartesian/cartesian-grid/HorizontalGridLines.mjs +24 -23
  55. package/dist/es/cartesian/cartesian-grid/HorizontalStripes.mjs +24 -24
  56. package/dist/es/cartesian/cartesian-grid/VerticalGridLines.mjs +23 -22
  57. package/dist/es/cartesian/cartesian-grid/VerticalStripes.mjs +24 -24
  58. package/dist/es/cartesian/cartesian-grid/const.mjs +317 -10
  59. package/dist/es/cartesian/cartesian-grid/utils.mjs +18 -13
  60. package/dist/es/cartesian/error-bar/ErrorBar.mjs +111 -83
  61. package/dist/es/cartesian/error-bar/ErrorBarContext.mjs +13 -12
  62. package/dist/es/cartesian/funnel/Funnel.mjs +162 -0
  63. package/dist/es/cartesian/funnel/type.mjs +78 -0
  64. package/dist/es/cartesian/funnel/utils.mjs +102 -0
  65. package/dist/es/cartesian/line/ActivePoints.mjs +45 -41
  66. package/dist/es/cartesian/line/Line.mjs +41 -37
  67. package/dist/es/cartesian/line/StaticLine.mjs +191 -122
  68. package/dist/es/cartesian/line/hooks/useLine.mjs +60 -44
  69. package/dist/es/cartesian/line/type.mjs +13 -18
  70. package/dist/es/cartesian/line/utils.mjs +27 -26
  71. package/dist/es/cartesian/reference-area/ReferenceArea.mjs +79 -78
  72. package/dist/es/cartesian/reference-dot/ReferenceDot.mjs +134 -0
  73. package/dist/es/cartesian/reference-line/ReferenceLine.mjs +93 -84
  74. package/dist/es/cartesian/scatter/Scatter.mjs +168 -140
  75. package/dist/es/cartesian/scatter/hooks/useScatter.mjs +18 -14
  76. package/dist/es/cartesian/useNeedsClip.mjs +18 -9
  77. package/dist/es/cartesian/utils/get-ticks.mjs +103 -68
  78. package/dist/es/cartesian/z-axis/ZAxis.mjs +30 -28
  79. package/dist/es/chart/AreaChart.mjs +5 -5
  80. package/dist/es/chart/BarChart.mjs +5 -5
  81. package/dist/es/chart/ComposedChart.mjs +5 -5
  82. package/dist/es/chart/FunnelChart.mjs +11 -0
  83. package/dist/es/chart/LegendPortalContext.mjs +3 -3
  84. package/dist/es/chart/LineChart.mjs +5 -5
  85. package/dist/es/chart/PieChart.mjs +5 -5
  86. package/dist/es/chart/RadarChart.mjs +5 -5
  87. package/dist/es/chart/RadialBarChart.mjs +5 -5
  88. package/dist/es/chart/RechartsWrapper.mjs +113 -89
  89. package/dist/es/chart/ScatterChart.mjs +5 -5
  90. package/dist/es/chart/Surface.mjs +3 -3
  91. package/dist/es/chart/Surface.vue_vue_type_script_setup_true_lang.mjs +51 -45
  92. package/dist/es/chart/TooltipPortalContext.mjs +3 -3
  93. package/dist/es/chart/Treemap.mjs +379 -0
  94. package/dist/es/chart/const.mjs +2 -2
  95. package/dist/es/chart/generateCategoricalChart.mjs +99 -89
  96. package/dist/es/chart/provideClipPathId.mjs +12 -7
  97. package/dist/es/chart/treemapUtils.mjs +32 -0
  98. package/dist/es/components/Cell.mjs +16 -4
  99. package/dist/es/components/Customized.mjs +43 -0
  100. package/dist/es/components/Text.mjs +3 -3
  101. package/dist/es/components/Text.vue_vue_type_script_setup_true_lang.mjs +106 -69
  102. package/dist/es/components/Tooltip.mjs +274 -199
  103. package/dist/es/components/label/Label.mjs +30 -26
  104. package/dist/es/components/label/LabelList.mjs +45 -39
  105. package/dist/es/components/label/types.mjs +10 -6
  106. package/dist/es/components/label/utils.mjs +194 -162
  107. package/dist/es/components/legend/Legend.mjs +82 -71
  108. package/dist/es/components/legend/LegendSymbol.mjs +40 -38
  109. package/dist/es/components/legend/hooks/useLegend.mjs +71 -46
  110. package/dist/es/components/legend/hooks/useLegendContent.mjs +52 -31
  111. package/dist/es/components/legend/type.mjs +2 -2
  112. package/dist/es/components/legend/utils.mjs +19 -11
  113. package/dist/es/components/utils.mjs +35 -22
  114. package/dist/es/container/ClipPath.mjs +14 -14
  115. package/dist/es/container/Layer.mjs +9 -7
  116. package/dist/es/container/ResponsiveContainer.mjs +3 -3
  117. package/dist/es/container/ResponsiveContainer.vue_vue_type_script_setup_true_lang.mjs +109 -77
  118. package/dist/es/container/Surface.mjs +25 -23
  119. package/dist/es/container/useSizeContext.mjs +3 -3
  120. package/dist/es/context/ChartDataContextProvider.mjs +19 -13
  121. package/dist/es/context/PanoramaContextProvider.mjs +15 -10
  122. package/dist/es/context/accessibilityContext.mjs +3 -3
  123. package/dist/es/context/cartesianLabelListContext.mjs +3 -3
  124. package/dist/es/context/chartLayoutContext.mjs +33 -30
  125. package/dist/es/context/cursorLayerContext.mjs +3 -3
  126. package/dist/es/context/graphicalLayerContext.mjs +3 -3
  127. package/dist/es/context/labelLayerContext.mjs +3 -3
  128. package/dist/es/context/polarLabelViewBoxContext.mjs +5 -5
  129. package/dist/es/context/useTooltipAxis.mjs +14 -12
  130. package/dist/es/events/useChartSynchronisation.mjs +91 -66
  131. package/dist/es/hooks/publicHooks.mjs +207 -0
  132. package/dist/es/hooks/useIsAnimating.mjs +28 -0
  133. package/dist/es/hooks/useSetupGraphicalItem.mjs +52 -43
  134. package/dist/es/index.mjs +54 -42
  135. package/dist/es/polar/pie/Pie.mjs +131 -115
  136. package/dist/es/polar/pie/type.mjs +8 -10
  137. package/dist/es/polar/radar/PolarAngleAxis.mjs +103 -84
  138. package/dist/es/polar/radar/PolarGrid.mjs +72 -59
  139. package/dist/es/polar/radar/PolarRadiusAxis.mjs +90 -65
  140. package/dist/es/polar/radar/Radar.mjs +181 -145
  141. package/dist/es/polar/radial-bar/RadialBar.mjs +161 -140
  142. package/dist/es/polar/radial-bar/type.mjs +9 -9
  143. package/dist/es/shape/Cross.mjs +11 -10
  144. package/dist/es/shape/Curve.mjs +71 -44
  145. package/dist/es/shape/Dot.mjs +12 -11
  146. package/dist/es/shape/Polygon.mjs +19 -0
  147. package/dist/es/shape/Rectangle.mjs +41 -30
  148. package/dist/es/shape/Sector.mjs +105 -79
  149. package/dist/es/shape/Symbols.mjs +45 -34
  150. package/dist/es/shape/Trapezoid.mjs +50 -0
  151. package/dist/es/state/ReportChartProps.mjs +23 -24
  152. package/dist/es/state/ReportMainChartProps.mjs +26 -21
  153. package/dist/es/state/ReportPolarOptions.mjs +23 -22
  154. package/dist/es/state/SetGraphicalItem.mjs +42 -27
  155. package/dist/es/state/SetLegendPayload.mjs +17 -13
  156. package/dist/es/state/SetTooltipEntrySettings.mjs +14 -12
  157. package/dist/es/state/brushSlice.mjs +12 -8
  158. package/dist/es/state/cartesianAxisSlice.mjs +23 -17
  159. package/dist/es/state/chartDataSlice.mjs +18 -13
  160. package/dist/es/state/externalEventsMiddleware.mjs +25 -15
  161. package/dist/es/state/graphicalItemsSlice.mjs +29 -25
  162. package/dist/es/state/hooks.mjs +24 -3
  163. package/dist/es/state/keyboardEventsMiddleware.mjs +50 -42
  164. package/dist/es/state/layoutSlice.mjs +18 -12
  165. package/dist/es/state/legendSlice.mjs +19 -14
  166. package/dist/es/state/mouseEventsMiddleware.mjs +31 -24
  167. package/dist/es/state/optionsSlice.mjs +14 -11
  168. package/dist/es/state/polarAxisSlice.mjs +15 -13
  169. package/dist/es/state/polarOptionsSlice.mjs +8 -6
  170. package/dist/es/state/reduxDevtoolsJsonStringifyReplacer.mjs +5 -3
  171. package/dist/es/state/referenceElementsSlice.mjs +21 -19
  172. package/dist/es/state/rootPropsSlice.mjs +20 -9
  173. package/dist/es/state/selectors/areaSelectors.mjs +65 -55
  174. package/dist/es/state/selectors/axisSelectors.mjs +784 -569
  175. package/dist/es/state/selectors/barSelectors.mjs +225 -162
  176. package/dist/es/state/selectors/brushSelectors.mjs +15 -14
  177. package/dist/es/state/selectors/combiners/combineActiveLabel.mjs +6 -5
  178. package/dist/es/state/selectors/combiners/combineActiveTooltipIndex.mjs +36 -27
  179. package/dist/es/state/selectors/combiners/combineAxisRangeWithReverse.mjs +5 -3
  180. package/dist/es/state/selectors/combiners/combineCoordinateForDefaultIndex.mjs +13 -11
  181. package/dist/es/state/selectors/combiners/combineTooltipInteractionState.mjs +26 -21
  182. package/dist/es/state/selectors/combiners/combineTooltipPayloadConfigurations.mjs +10 -6
  183. package/dist/es/state/selectors/common.mjs +2 -2
  184. package/dist/es/state/selectors/containerSelectors.mjs +5 -2
  185. package/dist/es/state/selectors/dataSelectors.mjs +28 -9
  186. package/dist/es/state/selectors/funnelSelectors.mjs +38 -0
  187. package/dist/es/state/selectors/legendSelectors.mjs +7 -6
  188. package/dist/es/state/selectors/lineSelectors.mjs +54 -47
  189. package/dist/es/state/selectors/pickAxisId.mjs +2 -2
  190. package/dist/es/state/selectors/pickAxisType.mjs +2 -2
  191. package/dist/es/state/selectors/pieSelectors.mjs +116 -81
  192. package/dist/es/state/selectors/polarAxisSelectors.mjs +113 -94
  193. package/dist/es/state/selectors/polarGridSelectors.mjs +13 -11
  194. package/dist/es/state/selectors/polarScaleSelectors.mjs +49 -46
  195. package/dist/es/state/selectors/polarSelectors.mjs +79 -62
  196. package/dist/es/state/selectors/radarSelectors.mjs +111 -91
  197. package/dist/es/state/selectors/radialBarSelectors.mjs +230 -183
  198. package/dist/es/state/selectors/rootPropsSelectors.mjs +11 -5
  199. package/dist/es/state/selectors/scatterSelectors.mjs +111 -95
  200. package/dist/es/state/selectors/selectActivePropsFromChartPointer.mjs +19 -17
  201. package/dist/es/state/selectors/selectAllAxes.mjs +8 -3
  202. package/dist/es/state/selectors/selectChartOffset.mjs +59 -50
  203. package/dist/es/state/selectors/selectChartOffsetInternal.mjs +55 -44
  204. package/dist/es/state/selectors/selectTooltipEventType.mjs +15 -14
  205. package/dist/es/state/selectors/selectTooltipPayloadSearcher.mjs +3 -3
  206. package/dist/es/state/selectors/selectTooltipSettings.mjs +2 -2
  207. package/dist/es/state/selectors/selectTooltipState.mjs +2 -2
  208. package/dist/es/state/selectors/selectors.mjs +94 -75
  209. package/dist/es/state/selectors/tooltipSelectors.mjs +253 -204
  210. package/dist/es/state/selectors/touchSelectors.mjs +17 -14
  211. package/dist/es/state/store.mjs +46 -46
  212. package/dist/es/state/tooltipSlice.mjs +64 -37
  213. package/dist/es/state/touchEventsMiddleware.mjs +35 -29
  214. package/dist/es/state/utils/useReportScale.mjs +16 -13
  215. package/dist/es/synchronisation/syncSelectors.mjs +3 -3
  216. package/dist/es/synchronisation/useChartSynchronisation.mjs +33 -19
  217. package/dist/es/types/common.mjs +12 -0
  218. package/dist/es/types/event.mjs +164 -2
  219. package/dist/es/utils/ReduceCSSCalc.mjs +81 -49
  220. package/dist/es/utils/VueUtils.mjs +35 -14
  221. package/dist/es/utils/attrs.mjs +43 -26
  222. package/dist/es/utils/cartesian.mjs +47 -15
  223. package/dist/es/utils/cell.mjs +28 -0
  224. package/dist/es/utils/chart.mjs +298 -197
  225. package/dist/es/utils/const.mjs +30 -2
  226. package/dist/es/utils/createCategoricalInverse.mjs +46 -0
  227. package/dist/es/utils/createContext.mjs +28 -9
  228. package/dist/es/utils/data-utils.mjs +9 -8
  229. package/dist/es/utils/data.mjs +35 -21
  230. package/dist/es/utils/events.mjs +5 -3
  231. package/dist/es/utils/getLinearRegression.mjs +28 -11
  232. package/dist/es/utils/grid.mjs +20 -5
  233. package/dist/es/utils/isDomainSpecifiedByUser.mjs +105 -54
  234. package/dist/es/utils/legend.mjs +13 -12
  235. package/dist/es/utils/log.mjs +10 -7
  236. package/dist/es/utils/payload/getUniqPayload.mjs +6 -4
  237. package/dist/es/utils/polar.mjs +37 -30
  238. package/dist/es/utils/props.mjs +16 -10
  239. package/dist/es/utils/resolveDefaultProps.mjs +23 -4
  240. package/dist/es/utils/scale/getNiceTickValues.mjs +127 -49
  241. package/dist/es/utils/scale/utils/arithmetic.mjs +49 -19
  242. package/dist/es/utils/scale/utils/utils.mjs +43 -24
  243. package/dist/es/utils/scale.mjs +46 -0
  244. package/dist/es/utils/style.mjs +24 -13
  245. package/dist/es/utils/tick.mjs +34 -23
  246. package/dist/es/utils/tooltip/translate.mjs +63 -49
  247. package/dist/es/utils/validate.mjs +40 -29
  248. package/dist/hooks/publicHooks.d.ts +143 -0
  249. package/dist/hooks/useIsAnimating.d.ts +14 -0
  250. package/dist/index.d.ts +1 -0
  251. package/dist/polar/pie/type.d.ts +2 -2
  252. package/dist/polar/radar/Radar.d.ts +4 -4
  253. package/dist/shape/Curve.d.ts +2 -1
  254. package/dist/shape/Polygon.d.ts +9 -0
  255. package/dist/shape/Rectangle.d.ts +0 -4
  256. package/dist/shape/Sector.d.ts +2 -2
  257. package/dist/shape/Symbols.d.ts +2 -1
  258. package/dist/shape/Trapezoid.d.ts +30 -0
  259. package/dist/shape/index.d.ts +2 -0
  260. package/dist/shape/types.d.ts +4 -5
  261. package/dist/state/ReportChartProps.d.ts +3 -3
  262. package/dist/state/graphicalItemsSlice.d.ts +1 -1
  263. package/dist/state/rootPropsSlice.d.ts +2 -2
  264. package/dist/state/selectors/axisSelectors.d.ts +5 -0
  265. package/dist/types/axis.d.ts +2 -2
  266. package/dist/types/bar.d.ts +2 -6
  267. package/dist/types/categorical.d.ts +2 -2
  268. package/dist/types/common.d.ts +7 -1
  269. package/dist/types/tooltip.d.ts +2 -2
  270. package/dist/utils/cell.d.ts +11 -0
  271. package/dist/utils/createCategoricalInverse.d.ts +16 -0
  272. package/dist/utils/scale.d.ts +23 -0
  273. package/package.json +2 -1
@@ -1,7 +1,26 @@
1
1
  //#region src/utils/resolveDefaultProps.ts
2
- function e(e, t) {
3
- let n = { ...e }, r = t;
4
- return Object.keys(t).reduce((e, t) => (e[t] === void 0 && r[t] !== void 0 && (e[t] = r[t]), e), n);
2
+ /**
3
+ * This function mimics the behavior of the `defaultProps` static property in React.
4
+ * Functional components do not have a defaultProps property, so this function is useful to resolve default props.
5
+ *
6
+ * The common recommendation is to use ES6 destructuring with default values in the function signature,
7
+ * but you need to be careful there and make sure you destructure all the individual properties
8
+ * and not the whole object. See the test file for example.
9
+ *
10
+ * And because destructuring all properties one by one is a faff, and it's easy to miss one property,
11
+ * this function exists.
12
+ *
13
+ * @param realProps - the props object passed to the component by the user
14
+ * @param defaultProps - the default props object defined in the component by Recharts
15
+ * @returns - the props object with all the default props resolved. All `undefined` values are replaced with the default value.
16
+ */
17
+ function resolveDefaultProps(realProps, defaultProps) {
18
+ const resolvedProps = { ...realProps };
19
+ const dp = defaultProps;
20
+ return Object.keys(defaultProps).reduce((acc, key) => {
21
+ if (acc[key] === void 0 && dp[key] !== void 0) acc[key] = dp[key];
22
+ return acc;
23
+ }, resolvedProps);
5
24
  }
6
25
  //#endregion
7
- export { e as resolveDefaultProps };
26
+ export { resolveDefaultProps };
@@ -1,59 +1,137 @@
1
- import { compose as e, map as t, memoize as n, range as r, reverse as i } from "./utils/utils.mjs";
2
- import { getDigitCount as a, rangeStep as o } from "./utils/arithmetic.mjs";
3
- import s from "decimal.js-light";
1
+ import { compose, map, memoize, range, reverse } from "./utils/utils.mjs";
2
+ import { getDigitCount, rangeStep } from "./utils/arithmetic.mjs";
3
+ import Decimal from "decimal.js-light";
4
4
  //#region src/utils/scale/getNiceTickValues.ts
5
- function c([e, t]) {
6
- let [n, r] = [e, t];
7
- return e > t && ([n, r] = [t, e]), [n, r];
5
+ /**
6
+ * Calculate a interval of a minimum value and a maximum value
7
+ *
8
+ * @param {number} min The minimum value
9
+ * @param {number} max The maximum value
10
+ * @return {Array} An interval
11
+ */
12
+ function getValidInterval([min, max]) {
13
+ let [validMin, validMax] = [min, max];
14
+ if (min > max) [validMin, validMax] = [max, min];
15
+ return [validMin, validMax];
8
16
  }
9
- function l(e, t, n) {
10
- if (e.lte(0)) return new s(0);
11
- let r = a(e.toNumber()), i = new s(10).pow(r), o = e.div(i), c = r === 1 ? .1 : .05, l = new s(Math.ceil(o.div(c).toNumber())).add(n).mul(c).mul(i);
12
- return t ? new s(l.toNumber()) : new s(Math.ceil(l.toNumber()));
17
+ /**
18
+ * Calculate the step which is easy to understand between ticks, like 10, 20, 25
19
+ *
20
+ * @param {Decimal} roughStep The rough step calculated by dividing the
21
+ * difference by the tickCount
22
+ * @param {boolean} allowDecimals Allow the ticks to be decimals or not
23
+ * @param {Integer} correctionFactor A correction factor
24
+ * @return {Decimal} The step which is easy to understand between two ticks
25
+ */
26
+ function getFormatStep(roughStep, allowDecimals, correctionFactor) {
27
+ if (roughStep.lte(0)) return new Decimal(0);
28
+ const digitCount = getDigitCount(roughStep.toNumber());
29
+ const digitCountValue = new Decimal(10).pow(digitCount);
30
+ const stepRatio = roughStep.div(digitCountValue);
31
+ const stepRatioScale = digitCount !== 1 ? .05 : .1;
32
+ const formatStep = new Decimal(Math.ceil(stepRatio.div(stepRatioScale).toNumber())).add(correctionFactor).mul(stepRatioScale).mul(digitCountValue);
33
+ return allowDecimals ? new Decimal(formatStep.toNumber()) : new Decimal(Math.ceil(formatStep.toNumber()));
13
34
  }
14
- function u(n, i, o) {
15
- let c = new s(1), l = new s(n);
16
- if (!l.isint() && o) {
17
- let e = Math.abs(n);
18
- e < 1 ? (c = new s(10).pow(a(n) - 1), l = new s(Math.floor(l.div(c).toNumber())).mul(c)) : e > 1 && (l = new s(Math.floor(n)));
19
- } else n === 0 ? l = new s(Math.floor((i - 1) / 2)) : o || (l = new s(Math.floor(n)));
20
- let u = Math.floor((i - 1) / 2);
21
- return e(t((e) => l.add(new s(e - u).mul(c)).toNumber()), r)(0, i);
35
+ /**
36
+ * calculate the ticks when the minimum value equals to the maximum value
37
+ *
38
+ * @param value The minimum value which is also the maximum value
39
+ * @param tickCount The count of ticks
40
+ * @param allowDecimals Allow the ticks to be decimals or not
41
+ * @return array of ticks
42
+ */
43
+ function getTickOfSingleValue(value, tickCount, allowDecimals) {
44
+ let step = new Decimal(1);
45
+ let middle = new Decimal(value);
46
+ if (!middle.isint() && allowDecimals) {
47
+ const absVal = Math.abs(value);
48
+ if (absVal < 1) {
49
+ step = new Decimal(10).pow(getDigitCount(value) - 1);
50
+ middle = new Decimal(Math.floor(middle.div(step).toNumber())).mul(step);
51
+ } else if (absVal > 1) middle = new Decimal(Math.floor(value));
52
+ } else if (value === 0) middle = new Decimal(Math.floor((tickCount - 1) / 2));
53
+ else if (!allowDecimals) middle = new Decimal(Math.floor(value));
54
+ const middleIndex = Math.floor((tickCount - 1) / 2);
55
+ return compose(map((n) => middle.add(new Decimal(n - middleIndex).mul(step)).toNumber()), range)(0, tickCount);
22
56
  }
23
- function d(e, t, n, r, i = 0) {
24
- if (!Number.isFinite((t - e) / (n - 1))) return {
25
- step: new s(0),
26
- tickMin: new s(0),
27
- tickMax: new s(0)
57
+ /**
58
+ * Calculate the step
59
+ *
60
+ * @param {number} min The minimum value of an interval
61
+ * @param {number} max The maximum value of an interval
62
+ * @param {Integer} tickCount The count of ticks
63
+ * @param {boolean} allowDecimals Allow the ticks to be decimals or not
64
+ * @param {number} correctionFactor A correction factor
65
+ * @return {object} The step, minimum value of ticks, maximum value of ticks
66
+ */
67
+ function calculateStep(min, max, tickCount, allowDecimals, correctionFactor = 0) {
68
+ if (!Number.isFinite((max - min) / (tickCount - 1))) return {
69
+ step: new Decimal(0),
70
+ tickMin: new Decimal(0),
71
+ tickMax: new Decimal(0)
72
+ };
73
+ const step = getFormatStep(new Decimal(max).sub(min).div(tickCount - 1), allowDecimals, correctionFactor);
74
+ let middle;
75
+ if (min <= 0 && max >= 0) middle = new Decimal(0);
76
+ else {
77
+ middle = new Decimal(min).add(max).div(2);
78
+ middle = middle.sub(new Decimal(middle).mod(step));
79
+ }
80
+ let belowCount = Math.ceil(middle.sub(min).div(step).toNumber());
81
+ let upCount = Math.ceil(new Decimal(max).sub(middle).div(step).toNumber());
82
+ const scaleCount = belowCount + upCount + 1;
83
+ if (scaleCount > tickCount) return calculateStep(min, max, tickCount, allowDecimals, correctionFactor + 1);
84
+ if (scaleCount < tickCount) {
85
+ upCount = max > 0 ? upCount + (tickCount - scaleCount) : upCount;
86
+ belowCount = max > 0 ? belowCount : belowCount + (tickCount - scaleCount);
87
+ }
88
+ return {
89
+ step,
90
+ tickMin: middle.sub(new Decimal(belowCount).mul(step)),
91
+ tickMax: middle.add(new Decimal(upCount).mul(step))
28
92
  };
29
- let a = l(new s(t).sub(e).div(n - 1), r, i), o;
30
- e <= 0 && t >= 0 ? o = new s(0) : (o = new s(e).add(t).div(2), o = o.sub(new s(o).mod(a)));
31
- let c = Math.ceil(o.sub(e).div(a).toNumber()), u = Math.ceil(new s(t).sub(o).div(a).toNumber()), f = c + u + 1;
32
- return f > n ? d(e, t, n, r, i + 1) : (f < n && (u = t > 0 ? u + (n - f) : u, c = t > 0 ? c : c + (n - f)), {
33
- step: a,
34
- tickMin: o.sub(new s(c).mul(a)),
35
- tickMax: o.add(new s(u).mul(a))
36
- });
37
93
  }
38
- function f([e, t], n = 6, a = !0) {
39
- if (!Number.isFinite(e) || !Number.isFinite(t)) return [];
40
- let l = Math.max(n, 2), [f, p] = c([e, t]);
41
- if (f === -Infinity || p === Infinity) {
42
- let a = p === Infinity ? [f, ...r(0, n - 1).map(() => Infinity)] : [...r(0, n - 1).map(() => -Infinity), p];
43
- return e > t ? i(a) : a;
94
+ /**
95
+ * Calculate the ticks of an interval, the count of ticks will be guaranteed
96
+ *
97
+ * @param {number} min, max min: The minimum value, max: The maximum value
98
+ * @param {Integer} tickCount The count of ticks
99
+ * @param {boolean} allowDecimals Allow the ticks to be decimals or not
100
+ * @return {Array} ticks
101
+ */
102
+ function getNiceTickValuesFn([min, max], tickCount = 6, allowDecimals = true) {
103
+ if (!Number.isFinite(min) || !Number.isFinite(max)) return [];
104
+ const count = Math.max(tickCount, 2);
105
+ const [cormin, cormax] = getValidInterval([min, max]);
106
+ if (cormin === -Infinity || cormax === Infinity) {
107
+ const values = cormax === Infinity ? [cormin, ...range(0, tickCount - 1).map(() => Infinity)] : [...range(0, tickCount - 1).map(() => -Infinity), cormax];
108
+ return min > max ? reverse(values) : values;
44
109
  }
45
- if (f === p) return u(f, n, a);
46
- let { step: m, tickMin: h, tickMax: g } = d(f, p, l, a, 0), _ = o(h, g.add(new s(.1).mul(m)), m);
47
- return e > t ? i(_) : _;
110
+ if (cormin === cormax) return getTickOfSingleValue(cormin, tickCount, allowDecimals);
111
+ const { step, tickMin, tickMax } = calculateStep(cormin, cormax, count, allowDecimals, 0);
112
+ const values = rangeStep(tickMin, tickMax.add(new Decimal(.1).mul(step)), step);
113
+ return min > max ? reverse(values) : values;
48
114
  }
49
- function p([e, t], n, r = !0) {
50
- if (!Number.isFinite(e) || !Number.isFinite(t)) return [];
51
- let [a, u] = c([e, t]);
52
- if (a === -Infinity || u === Infinity) return [e, t];
53
- if (a === u) return [a];
54
- let d = Math.max(n, 2), f = l(new s(u).sub(a).div(d - 1), r, 0), p = [...o(new s(a), new s(u).sub(new s(.99).mul(f)), f), u];
55
- return e > t ? i(p) : p;
115
+ /**
116
+ * Calculate the ticks of an interval, the count of ticks won't be guraranteed,
117
+ * but the domain will be guaranteed
118
+ *
119
+ * @param {number} min, max min: The minimum value, max: The maximum value
120
+ * @param {Integer} tickCount The count of ticks
121
+ * @param {boolean} allowDecimals Allow the ticks to be decimals or not
122
+ * @return {Array} ticks
123
+ */
124
+ function getTickValuesFixedDomainFn([min, max], tickCount, allowDecimals = true) {
125
+ if (!Number.isFinite(min) || !Number.isFinite(max)) return [];
126
+ const [cormin, cormax] = getValidInterval([min, max]);
127
+ if (cormin === -Infinity || cormax === Infinity) return [min, max];
128
+ if (cormin === cormax) return [cormin];
129
+ const count = Math.max(tickCount, 2);
130
+ const step = getFormatStep(new Decimal(cormax).sub(cormin).div(count - 1), allowDecimals, 0);
131
+ const values = [...rangeStep(new Decimal(cormin), new Decimal(cormax).sub(new Decimal(.99).mul(step)), step), cormax];
132
+ return min > max ? reverse(values) : values;
56
133
  }
57
- var m = n(f), h = n(p);
134
+ var getNiceTickValues = memoize(getNiceTickValuesFn);
135
+ var getTickValuesFixedDomain = memoize(getTickValuesFixedDomainFn);
58
136
  //#endregion
59
- export { m as getNiceTickValues, h as getTickValuesFixedDomain };
137
+ export { getNiceTickValues, getTickValuesFixedDomain };
@@ -1,24 +1,54 @@
1
- import { curry as e } from "./utils.mjs";
2
- import t from "decimal.js-light";
1
+ import { curry } from "./utils.mjs";
2
+ import Decimal from "decimal.js-light";
3
3
  //#region src/utils/scale/utils/arithmetic.ts
4
- function n(e) {
5
- let n;
6
- return n = e === 0 ? 1 : Math.floor(new t(e).abs().log(10).toNumber()) + 1, n;
4
+ /**
5
+ * 获取数值的位数
6
+ * 其中绝对值属于区间[0.1, 1), 得到的值为0
7
+ * 绝对值属于区间[0.01, 0.1),得到的位数为 -1
8
+ * 绝对值属于区间[0.001, 0.01),得到的位数为 -2
9
+ *
10
+ * @param {number} value 数值
11
+ * @return {Integer} 位数
12
+ */
13
+ function getDigitCount(value) {
14
+ let result;
15
+ if (value === 0) result = 1;
16
+ else result = Math.floor(new Decimal(value).abs().log(10).toNumber()) + 1;
17
+ return result;
7
18
  }
8
- function r(e, n, r) {
9
- let i = new t(e), a = 0, o = [];
10
- for (; i.lt(n) && a < 1e5;) o.push(i.toNumber()), i = i.add(r), a++;
11
- return o;
19
+ /**
20
+ * 按照固定的步长获取[start, end)这个区间的数据
21
+ * 并且需要处理js计算精度的问题
22
+ *
23
+ * @param {Decimal} start 起点
24
+ * @param {Decimal} end 终点,不包含该值
25
+ * @param {Decimal} step 步长
26
+ * @return {Array} 若干数值
27
+ */
28
+ function rangeStep(start, end, step) {
29
+ let num = new Decimal(start);
30
+ let i = 0;
31
+ const result = [];
32
+ while (num.lt(end) && i < 1e5) {
33
+ result.push(num.toNumber());
34
+ num = num.add(step);
35
+ i++;
36
+ }
37
+ return result;
12
38
  }
13
- e((e, t, n) => {
14
- let r = +e;
15
- return r + n * (+t - r);
16
- }), e((e, t, n) => {
17
- let r = t - +e;
18
- return r ||= Infinity, (n - e) / r;
19
- }), e((e, t, n) => {
20
- let r = t - +e;
21
- return r ||= Infinity, Math.max(0, Math.min(1, (n - e) / r));
39
+ curry((a, b, t) => {
40
+ const newA = +a;
41
+ return newA + t * (+b - newA);
42
+ });
43
+ curry((a, b, x) => {
44
+ let diff = b - +a;
45
+ diff = diff || Infinity;
46
+ return (x - a) / diff;
47
+ });
48
+ curry((a, b, x) => {
49
+ let diff = b - +a;
50
+ diff = diff || Infinity;
51
+ return Math.max(0, Math.min(1, (x - a) / diff));
22
52
  });
23
53
  //#endregion
24
- export { n as getDigitCount, r as rangeStep };
54
+ export { getDigitCount, rangeStep };
@@ -1,34 +1,53 @@
1
1
  //#region src/utils/scale/utils/utils.ts
2
- var e = (e) => e, t = { "@@functional/placeholder": !0 }, n = (e) => e === t;
3
- function r(e) {
4
- return function t(...r) {
5
- return r.length === 0 || r.length === 1 && n(r[0]) ? t : e(...r);
2
+ var identity = (i) => i;
3
+ var PLACE_HOLDER = { "@@functional/placeholder": true };
4
+ var isPlaceHolder = (val) => val === PLACE_HOLDER;
5
+ function curry0(fn) {
6
+ return function _curried(...args) {
7
+ if (args.length === 0 || args.length === 1 && isPlaceHolder(args[0])) return _curried;
8
+ return fn(...args);
6
9
  };
7
10
  }
8
- function i(e, a) {
9
- return e === 1 ? a : r((...o) => {
10
- let s = o.filter((e) => e !== t).length;
11
- return s >= e ? a(...o) : i(e - s, r((...e) => a(...o.map((t) => n(t) ? e.shift() : t), ...e)));
11
+ function curryN(n, fn) {
12
+ if (n === 1) return fn;
13
+ return curry0((...args) => {
14
+ const argsLength = args.filter((arg) => arg !== PLACE_HOLDER).length;
15
+ if (argsLength >= n) return fn(...args);
16
+ return curryN(n - argsLength, curry0((...restArgs) => {
17
+ return fn(...args.map((arg) => isPlaceHolder(arg) ? restArgs.shift() : arg), ...restArgs);
18
+ }));
12
19
  });
13
20
  }
14
- var a = (e) => i(e.length, e);
15
- function o(e, t) {
16
- let n = [];
17
- for (let r = e; r < t; ++r) n[r - e] = r;
18
- return n;
21
+ var curry = (fn) => curryN(fn.length, fn);
22
+ function range(begin, end) {
23
+ const arr = [];
24
+ for (let i = begin; i < end; ++i) arr[i - begin] = i;
25
+ return arr;
19
26
  }
20
- var s = a((e, t) => Array.isArray(t) ? t.map(e) : Object.keys(t).map((e) => t[e]).map(e));
21
- function c(...t) {
22
- if (!t.length) return e;
23
- let n = t.reverse(), r = n[0], i = n.slice(1);
24
- return (...e) => i.reduce((e, t) => t(e), r(...e));
27
+ var map = curry((fn, arr) => {
28
+ if (Array.isArray(arr)) return arr.map(fn);
29
+ return Object.keys(arr).map((key) => arr[key]).map(fn);
30
+ });
31
+ function compose(...args) {
32
+ if (!args.length) return identity;
33
+ const fns = args.reverse();
34
+ const firstFn = fns[0];
35
+ const tailsFn = fns.slice(1);
36
+ return (...composeArgs) => tailsFn.reduce((res, fn) => fn(res), firstFn(...composeArgs));
25
37
  }
26
- function l(e) {
27
- return Array.isArray(e) ? e.reverse() : e.split("").reverse().join("");
38
+ function reverse(arr) {
39
+ if (Array.isArray(arr)) return arr.reverse();
40
+ return arr.split("").reverse().join("");
28
41
  }
29
- function u(e) {
30
- let t = null, n = null;
31
- return ((...r) => t && r.every((e, n) => e === t?.[n]) ? n : (t = r, n = e(...r), n));
42
+ function memoize(fn) {
43
+ let lastArgs = null;
44
+ let lastResult = null;
45
+ return ((...args) => {
46
+ if (lastArgs && args.every((val, i) => val === lastArgs?.[i])) return lastResult;
47
+ lastArgs = args;
48
+ lastResult = fn(...args);
49
+ return lastResult;
50
+ });
32
51
  }
33
52
  //#endregion
34
- export { c as compose, a as curry, s as map, u as memoize, o as range, l as reverse };
53
+ export { compose, curry, map, memoize, range, reverse };
@@ -0,0 +1,46 @@
1
+ import { isWellBehavedNumber } from "./validate.mjs";
2
+ //#region src/utils/scale.ts
3
+ /**
4
+ * Convert a data value to pixel coordinate using a D3 scale.
5
+ * Automatically centers on band-scale categories by adding half the bandwidth.
6
+ */
7
+ function scaleCoord(scale, value) {
8
+ const coord = scale(value);
9
+ if (!isWellBehavedNumber(coord)) return void 0;
10
+ return coord + (scale.bandwidth?.() ?? 0) / 2;
11
+ }
12
+ /**
13
+ * Convert a data value to pixel coordinate for range boundaries.
14
+ * `start` returns the left/top edge; `end` returns the right/bottom edge (adding full bandwidth).
15
+ */
16
+ function scaleValue(scale, value, position) {
17
+ const coord = scale(value);
18
+ if (!isWellBehavedNumber(coord)) return void 0;
19
+ const bandwidth = scale.bandwidth?.() ?? 0;
20
+ return position === "start" ? coord : coord + bandwidth;
21
+ }
22
+ /**
23
+ * Check whether a pixel coordinate falls within the scale's output range.
24
+ */
25
+ function isInRange(scale, coord) {
26
+ const r = scale.range();
27
+ const min = Math.min(r[0], r[1]);
28
+ const max = Math.max(r[0], r[1]);
29
+ return coord >= min && coord <= max;
30
+ }
31
+ /**
32
+ * Get the minimum value of a scale's range.
33
+ */
34
+ function rangeMin(scale) {
35
+ const r = scale.range();
36
+ return Math.min(r[0], r[1]);
37
+ }
38
+ /**
39
+ * Get the maximum value of a scale's range.
40
+ */
41
+ function rangeMax(scale) {
42
+ const r = scale.range();
43
+ return Math.max(r[0], r[1]);
44
+ }
45
+ //#endregion
46
+ export { isInRange, rangeMax, rangeMin, scaleCoord, scaleValue };
@@ -1,19 +1,30 @@
1
- import { isNumber as e } from "./validate.mjs";
1
+ import { isNumber } from "./validate.mjs";
2
2
  //#region src/utils/style.ts
3
- function t(t) {
4
- if (t !== void 0) return e(t) ? `${t}px` : t;
3
+ /**
4
+ * Converts a style value to a string with 'px' if it's a number
5
+ * @param value The style value to convert
6
+ * @returns The converted style value
7
+ */
8
+ function toPx(value) {
9
+ if (value === void 0) return void 0;
10
+ return isNumber(value) ? `${value}px` : value;
5
11
  }
6
- function n(e = {}) {
7
- let { height: n, width: r, minHeight: i, maxHeight: a, minWidth: o, maxWidth: s, ...c } = e;
12
+ /**
13
+ * Converts style object values to use 'px' for numeric height/width values
14
+ * @param style The style object to convert
15
+ * @returns A new style object with converted values
16
+ */
17
+ function normalizeStyle(style = {}) {
18
+ const { height, width, minHeight, maxHeight, minWidth, maxWidth, ...rest } = style;
8
19
  return {
9
- height: t(n),
10
- width: t(r),
11
- minHeight: t(i),
12
- maxHeight: t(a),
13
- minWidth: t(o),
14
- maxWidth: t(s),
15
- ...c
20
+ height: toPx(height),
21
+ width: toPx(width),
22
+ minHeight: toPx(minHeight),
23
+ maxHeight: toPx(maxHeight),
24
+ minWidth: toPx(minWidth),
25
+ maxWidth: toPx(maxWidth),
26
+ ...rest
16
27
  };
17
28
  }
18
29
  //#endregion
19
- export { n as normalizeStyle };
30
+ export { normalizeStyle };
@@ -1,31 +1,42 @@
1
- import { getAngledRectangleWidth as e } from "./cartesian.mjs";
1
+ import { getAngledRectangleWidth } from "./cartesian.mjs";
2
2
  //#region src/utils/tick.ts
3
- function t(e, t) {
4
- return n(e, t + 1);
3
+ function getNumberIntervalTicks(ticks, interval) {
4
+ return getEveryNthWithCondition(ticks, interval + 1);
5
5
  }
6
- function n(e, t, n) {
7
- if (t < 1) return [];
8
- if (t === 1 && n === void 0) return e;
9
- let r = [];
10
- for (let i = 0; i < e.length; i += t) if (n === void 0 || n(e[i]) === !0) r.push(e[i]);
6
+ /**
7
+ * Given an array and a number N, return a new array which contains every nTh
8
+ * element of the input array. For n below 1, an empty array is returned.
9
+ * If isValid is provided, all candidates must suffice the condition, else undefined is returned.
10
+ * @param {T[]} array An input array.
11
+ * @param {integer} n A number
12
+ * @param {Function} isValid A function to evaluate a candidate form the array
13
+ * @returns {T[]} The result array of the same type as the input array.
14
+ */
15
+ function getEveryNthWithCondition(array, n, isValid) {
16
+ if (n < 1) return [];
17
+ if (n === 1 && isValid === void 0) return array;
18
+ const result = [];
19
+ for (let i = 0; i < array.length; i += n) if (isValid === void 0 || isValid(array[i]) === true) result.push(array[i]);
11
20
  else return;
12
- return r;
21
+ return result;
13
22
  }
14
- function r(t, n, r) {
15
- return e({
16
- width: t.width + n.width,
17
- height: t.height + n.height
18
- }, r);
23
+ function getAngledTickWidth(contentSize, unitSize, angle) {
24
+ return getAngledRectangleWidth({
25
+ width: contentSize.width + unitSize.width,
26
+ height: contentSize.height + unitSize.height
27
+ }, angle);
19
28
  }
20
- function i(e, t, n) {
21
- let r = n === "width", { x: i, y: a, width: o, height: s } = e;
22
- return t === 1 ? {
23
- start: r ? i : a,
24
- end: r ? i + o : a + s
25
- } : {
26
- start: r ? i + o : a + s,
27
- end: r ? i : a
29
+ function getTickBoundaries(viewBox, sign, sizeKey) {
30
+ const isWidth = sizeKey === "width";
31
+ const { x, y, width, height } = viewBox;
32
+ if (sign === 1) return {
33
+ start: isWidth ? x : y,
34
+ end: isWidth ? x + width : y + height
35
+ };
36
+ return {
37
+ start: isWidth ? x + width : y + height,
38
+ end: isWidth ? x : y
28
39
  };
29
40
  }
30
41
  //#endregion
31
- export { r as getAngledTickWidth, n as getEveryNthWithCondition, t as getNumberIntervalTicks, i as getTickBoundaries };
42
+ export { getAngledTickWidth, getEveryNthWithCondition, getNumberIntervalTicks, getTickBoundaries };