vccs 0.1.0 → 0.2.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 (215) hide show
  1. package/dist/cartesian/funnel/Funnel.d.ts +2 -0
  2. package/dist/cartesian/funnel/index.d.ts +2 -0
  3. package/dist/cartesian/funnel/type.d.ts +74 -5
  4. package/dist/cartesian/index.d.ts +1 -0
  5. package/dist/chart/FunnelChart.d.ts +1 -0
  6. package/dist/chart/index.d.ts +1 -0
  7. package/dist/es/animation/Animate.mjs +48 -22
  8. package/dist/es/cartesian/GraphicalItemClipPath.mjs +16 -15
  9. package/dist/es/cartesian/area/ActivePoints.mjs +44 -40
  10. package/dist/es/cartesian/area/Area.mjs +42 -31
  11. package/dist/es/cartesian/area/ClipRect.mjs +79 -58
  12. package/dist/es/cartesian/area/RenderArea.mjs +142 -108
  13. package/dist/es/cartesian/area/hooks/useArea.mjs +71 -47
  14. package/dist/es/cartesian/area/type.mjs +11 -11
  15. package/dist/es/cartesian/area/utils.mjs +69 -49
  16. package/dist/es/cartesian/axis/XAxis.mjs +87 -73
  17. package/dist/es/cartesian/axis/YAxis.mjs +67 -56
  18. package/dist/es/cartesian/bar/Bar.mjs +93 -71
  19. package/dist/es/cartesian/bar/components/BarBackground.mjs +22 -19
  20. package/dist/es/cartesian/bar/components/BarRectangles.mjs +117 -80
  21. package/dist/es/cartesian/bar/hooks/useBar.mjs +49 -37
  22. package/dist/es/cartesian/bar/type.mjs +9 -9
  23. package/dist/es/cartesian/bar/utils.mjs +97 -70
  24. package/dist/es/cartesian/cartesian-axis/CartesianAxis.mjs +165 -115
  25. package/dist/es/cartesian/cartesian-grid/Background.mjs +19 -16
  26. package/dist/es/cartesian/cartesian-grid/CartesianGrid.mjs +116 -97
  27. package/dist/es/cartesian/cartesian-grid/HorizontalGridLines.mjs +24 -23
  28. package/dist/es/cartesian/cartesian-grid/HorizontalStripes.mjs +24 -24
  29. package/dist/es/cartesian/cartesian-grid/VerticalGridLines.mjs +23 -22
  30. package/dist/es/cartesian/cartesian-grid/VerticalStripes.mjs +24 -24
  31. package/dist/es/cartesian/cartesian-grid/const.mjs +317 -10
  32. package/dist/es/cartesian/cartesian-grid/utils.mjs +18 -13
  33. package/dist/es/cartesian/error-bar/ErrorBar.mjs +111 -83
  34. package/dist/es/cartesian/error-bar/ErrorBarContext.mjs +13 -12
  35. package/dist/es/cartesian/funnel/Funnel.mjs +177 -0
  36. package/dist/es/cartesian/funnel/type.mjs +80 -0
  37. package/dist/es/cartesian/funnel/utils.mjs +102 -0
  38. package/dist/es/cartesian/line/ActivePoints.mjs +45 -41
  39. package/dist/es/cartesian/line/Line.mjs +41 -37
  40. package/dist/es/cartesian/line/StaticLine.mjs +191 -122
  41. package/dist/es/cartesian/line/hooks/useLine.mjs +60 -44
  42. package/dist/es/cartesian/line/type.mjs +11 -11
  43. package/dist/es/cartesian/line/utils.mjs +27 -26
  44. package/dist/es/cartesian/reference-area/ReferenceArea.mjs +86 -69
  45. package/dist/es/cartesian/reference-line/ReferenceLine.mjs +99 -77
  46. package/dist/es/cartesian/scatter/Scatter.mjs +168 -140
  47. package/dist/es/cartesian/scatter/hooks/useScatter.mjs +18 -14
  48. package/dist/es/cartesian/useNeedsClip.mjs +18 -9
  49. package/dist/es/cartesian/utils/get-ticks.mjs +103 -68
  50. package/dist/es/cartesian/z-axis/ZAxis.mjs +30 -28
  51. package/dist/es/chart/AreaChart.mjs +5 -5
  52. package/dist/es/chart/BarChart.mjs +5 -5
  53. package/dist/es/chart/ComposedChart.mjs +5 -5
  54. package/dist/es/chart/FunnelChart.mjs +11 -0
  55. package/dist/es/chart/LegendPortalContext.mjs +3 -3
  56. package/dist/es/chart/LineChart.mjs +5 -5
  57. package/dist/es/chart/PieChart.mjs +5 -5
  58. package/dist/es/chart/RadarChart.mjs +5 -5
  59. package/dist/es/chart/RadialBarChart.mjs +5 -5
  60. package/dist/es/chart/RechartsWrapper.mjs +111 -88
  61. package/dist/es/chart/ScatterChart.mjs +5 -5
  62. package/dist/es/chart/Surface.mjs +3 -3
  63. package/dist/es/chart/Surface.vue_vue_type_script_setup_true_lang.mjs +51 -45
  64. package/dist/es/chart/TooltipPortalContext.mjs +3 -3
  65. package/dist/es/chart/const.mjs +2 -2
  66. package/dist/es/chart/generateCategoricalChart.mjs +97 -88
  67. package/dist/es/chart/provideClipPathId.mjs +12 -7
  68. package/dist/es/components/Cell.mjs +16 -4
  69. package/dist/es/components/Text.mjs +3 -3
  70. package/dist/es/components/Text.vue_vue_type_script_setup_true_lang.mjs +106 -69
  71. package/dist/es/components/Tooltip.mjs +274 -199
  72. package/dist/es/components/label/Label.mjs +30 -26
  73. package/dist/es/components/label/LabelList.mjs +45 -39
  74. package/dist/es/components/label/types.mjs +8 -5
  75. package/dist/es/components/label/utils.mjs +194 -162
  76. package/dist/es/components/legend/Legend.mjs +82 -71
  77. package/dist/es/components/legend/LegendSymbol.mjs +40 -38
  78. package/dist/es/components/legend/hooks/useLegend.mjs +66 -46
  79. package/dist/es/components/legend/hooks/useLegendContent.mjs +52 -31
  80. package/dist/es/components/legend/type.mjs +2 -2
  81. package/dist/es/components/legend/utils.mjs +19 -11
  82. package/dist/es/components/utils.mjs +35 -22
  83. package/dist/es/container/ClipPath.mjs +14 -14
  84. package/dist/es/container/Layer.mjs +9 -7
  85. package/dist/es/container/ResponsiveContainer.mjs +3 -3
  86. package/dist/es/container/ResponsiveContainer.vue_vue_type_script_setup_true_lang.mjs +109 -77
  87. package/dist/es/container/Surface.mjs +23 -19
  88. package/dist/es/container/useSizeContext.mjs +3 -3
  89. package/dist/es/context/ChartDataContextProvider.mjs +19 -13
  90. package/dist/es/context/PanoramaContextProvider.mjs +15 -10
  91. package/dist/es/context/accessibilityContext.mjs +3 -3
  92. package/dist/es/context/cartesianLabelListContext.mjs +3 -3
  93. package/dist/es/context/chartLayoutContext.mjs +33 -30
  94. package/dist/es/context/cursorLayerContext.mjs +3 -3
  95. package/dist/es/context/graphicalLayerContext.mjs +3 -3
  96. package/dist/es/context/labelLayerContext.mjs +3 -3
  97. package/dist/es/context/polarLabelViewBoxContext.mjs +5 -5
  98. package/dist/es/context/useTooltipAxis.mjs +14 -12
  99. package/dist/es/events/useChartSynchronisation.mjs +91 -66
  100. package/dist/es/hooks/useIsAnimating.mjs +28 -0
  101. package/dist/es/hooks/useSetupGraphicalItem.mjs +52 -43
  102. package/dist/es/index.mjs +46 -42
  103. package/dist/es/polar/pie/Pie.mjs +131 -115
  104. package/dist/es/polar/pie/type.mjs +6 -6
  105. package/dist/es/polar/radar/PolarAngleAxis.mjs +103 -84
  106. package/dist/es/polar/radar/PolarGrid.mjs +72 -59
  107. package/dist/es/polar/radar/PolarRadiusAxis.mjs +90 -65
  108. package/dist/es/polar/radar/Radar.mjs +181 -145
  109. package/dist/es/polar/radial-bar/RadialBar.mjs +161 -140
  110. package/dist/es/polar/radial-bar/type.mjs +9 -9
  111. package/dist/es/shape/Cross.mjs +11 -10
  112. package/dist/es/shape/Curve.mjs +69 -43
  113. package/dist/es/shape/Dot.mjs +12 -11
  114. package/dist/es/shape/Rectangle.mjs +41 -26
  115. package/dist/es/shape/Sector.mjs +103 -75
  116. package/dist/es/shape/Symbols.mjs +45 -34
  117. package/dist/es/shape/Trapezoid.mjs +52 -0
  118. package/dist/es/state/ReportChartProps.mjs +21 -20
  119. package/dist/es/state/ReportMainChartProps.mjs +26 -21
  120. package/dist/es/state/ReportPolarOptions.mjs +23 -22
  121. package/dist/es/state/SetGraphicalItem.mjs +42 -27
  122. package/dist/es/state/SetLegendPayload.mjs +17 -13
  123. package/dist/es/state/SetTooltipEntrySettings.mjs +14 -12
  124. package/dist/es/state/brushSlice.mjs +12 -8
  125. package/dist/es/state/cartesianAxisSlice.mjs +23 -17
  126. package/dist/es/state/chartDataSlice.mjs +18 -13
  127. package/dist/es/state/externalEventsMiddleware.mjs +25 -15
  128. package/dist/es/state/graphicalItemsSlice.mjs +29 -25
  129. package/dist/es/state/hooks.mjs +4 -3
  130. package/dist/es/state/keyboardEventsMiddleware.mjs +50 -42
  131. package/dist/es/state/layoutSlice.mjs +18 -12
  132. package/dist/es/state/legendSlice.mjs +19 -14
  133. package/dist/es/state/mouseEventsMiddleware.mjs +31 -24
  134. package/dist/es/state/optionsSlice.mjs +14 -11
  135. package/dist/es/state/polarAxisSlice.mjs +15 -13
  136. package/dist/es/state/polarOptionsSlice.mjs +8 -6
  137. package/dist/es/state/reduxDevtoolsJsonStringifyReplacer.mjs +5 -3
  138. package/dist/es/state/referenceElementsSlice.mjs +21 -19
  139. package/dist/es/state/rootPropsSlice.mjs +20 -9
  140. package/dist/es/state/selectors/areaSelectors.mjs +65 -55
  141. package/dist/es/state/selectors/axisSelectors.mjs +755 -569
  142. package/dist/es/state/selectors/barSelectors.mjs +225 -162
  143. package/dist/es/state/selectors/brushSelectors.mjs +15 -14
  144. package/dist/es/state/selectors/combiners/combineActiveLabel.mjs +6 -5
  145. package/dist/es/state/selectors/combiners/combineActiveTooltipIndex.mjs +36 -27
  146. package/dist/es/state/selectors/combiners/combineAxisRangeWithReverse.mjs +5 -3
  147. package/dist/es/state/selectors/combiners/combineCoordinateForDefaultIndex.mjs +13 -11
  148. package/dist/es/state/selectors/combiners/combineTooltipInteractionState.mjs +26 -21
  149. package/dist/es/state/selectors/combiners/combineTooltipPayloadConfigurations.mjs +10 -6
  150. package/dist/es/state/selectors/common.mjs +2 -2
  151. package/dist/es/state/selectors/containerSelectors.mjs +5 -2
  152. package/dist/es/state/selectors/dataSelectors.mjs +28 -9
  153. package/dist/es/state/selectors/funnelSelectors.mjs +38 -0
  154. package/dist/es/state/selectors/legendSelectors.mjs +7 -6
  155. package/dist/es/state/selectors/lineSelectors.mjs +54 -47
  156. package/dist/es/state/selectors/pickAxisId.mjs +2 -2
  157. package/dist/es/state/selectors/pickAxisType.mjs +2 -2
  158. package/dist/es/state/selectors/pieSelectors.mjs +116 -81
  159. package/dist/es/state/selectors/polarAxisSelectors.mjs +113 -94
  160. package/dist/es/state/selectors/polarGridSelectors.mjs +13 -11
  161. package/dist/es/state/selectors/polarScaleSelectors.mjs +49 -46
  162. package/dist/es/state/selectors/polarSelectors.mjs +79 -62
  163. package/dist/es/state/selectors/radarSelectors.mjs +111 -91
  164. package/dist/es/state/selectors/radialBarSelectors.mjs +230 -183
  165. package/dist/es/state/selectors/rootPropsSelectors.mjs +11 -5
  166. package/dist/es/state/selectors/scatterSelectors.mjs +111 -95
  167. package/dist/es/state/selectors/selectActivePropsFromChartPointer.mjs +19 -17
  168. package/dist/es/state/selectors/selectAllAxes.mjs +8 -3
  169. package/dist/es/state/selectors/selectChartOffset.mjs +59 -50
  170. package/dist/es/state/selectors/selectChartOffsetInternal.mjs +55 -44
  171. package/dist/es/state/selectors/selectTooltipEventType.mjs +15 -14
  172. package/dist/es/state/selectors/selectTooltipPayloadSearcher.mjs +3 -3
  173. package/dist/es/state/selectors/selectTooltipSettings.mjs +2 -2
  174. package/dist/es/state/selectors/selectTooltipState.mjs +2 -2
  175. package/dist/es/state/selectors/selectors.mjs +94 -75
  176. package/dist/es/state/selectors/tooltipSelectors.mjs +253 -204
  177. package/dist/es/state/selectors/touchSelectors.mjs +17 -14
  178. package/dist/es/state/store.mjs +46 -46
  179. package/dist/es/state/tooltipSlice.mjs +64 -37
  180. package/dist/es/state/touchEventsMiddleware.mjs +35 -29
  181. package/dist/es/state/utils/useReportScale.mjs +16 -13
  182. package/dist/es/synchronisation/syncSelectors.mjs +3 -3
  183. package/dist/es/synchronisation/useChartSynchronisation.mjs +33 -19
  184. package/dist/es/types/event.mjs +164 -2
  185. package/dist/es/utils/ReduceCSSCalc.mjs +81 -49
  186. package/dist/es/utils/VueUtils.mjs +35 -14
  187. package/dist/es/utils/attrs.mjs +43 -26
  188. package/dist/es/utils/cartesian.mjs +47 -15
  189. package/dist/es/utils/chart.mjs +298 -197
  190. package/dist/es/utils/const.mjs +30 -2
  191. package/dist/es/utils/createContext.mjs +28 -9
  192. package/dist/es/utils/data-utils.mjs +9 -8
  193. package/dist/es/utils/data.mjs +35 -21
  194. package/dist/es/utils/events.mjs +5 -3
  195. package/dist/es/utils/getLinearRegression.mjs +28 -11
  196. package/dist/es/utils/grid.mjs +20 -5
  197. package/dist/es/utils/isDomainSpecifiedByUser.mjs +105 -54
  198. package/dist/es/utils/legend.mjs +13 -12
  199. package/dist/es/utils/log.mjs +10 -7
  200. package/dist/es/utils/payload/getUniqPayload.mjs +6 -4
  201. package/dist/es/utils/polar.mjs +37 -30
  202. package/dist/es/utils/props.mjs +16 -10
  203. package/dist/es/utils/resolveDefaultProps.mjs +23 -4
  204. package/dist/es/utils/scale/getNiceTickValues.mjs +127 -49
  205. package/dist/es/utils/scale/utils/arithmetic.mjs +49 -19
  206. package/dist/es/utils/scale/utils/utils.mjs +43 -24
  207. package/dist/es/utils/style.mjs +24 -13
  208. package/dist/es/utils/tick.mjs +34 -23
  209. package/dist/es/utils/tooltip/translate.mjs +63 -49
  210. package/dist/es/utils/validate.mjs +40 -29
  211. package/dist/hooks/useIsAnimating.d.ts +14 -0
  212. package/dist/shape/Trapezoid.d.ts +31 -0
  213. package/dist/shape/index.d.ts +1 -0
  214. package/dist/state/graphicalItemsSlice.d.ts +1 -1
  215. package/package.json +1 -1
@@ -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 };
@@ -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 };
@@ -1,59 +1,73 @@
1
- import { isNumber as e } from "../validate.mjs";
1
+ import { isNumber } from "../validate.mjs";
2
2
  //#region src/utils/tooltip/translate.ts
3
- var t = "v-charts-tooltip-wrapper", n = { visibility: "hidden" };
4
- function r({ coordinate: n, translateX: r, translateY: i }) {
5
- return [t, {
6
- [`${t}-right`]: e(r) && n && e(n.x) && r >= n.x,
7
- [`${t}-left`]: e(r) && n && e(n.x) && r < n.x,
8
- [`${t}-bottom`]: e(i) && n && e(n.y) && i >= n.y,
9
- [`${t}-top`]: e(i) && n && e(n.y) && i < n.y
3
+ var CSS_CLASS_PREFIX = "v-charts-tooltip-wrapper";
4
+ var TOOLTIP_HIDDEN = { visibility: "hidden" };
5
+ function getTooltipCSSClassName({ coordinate, translateX, translateY }) {
6
+ return [CSS_CLASS_PREFIX, {
7
+ [`${CSS_CLASS_PREFIX}-right`]: isNumber(translateX) && coordinate && isNumber(coordinate.x) && translateX >= coordinate.x,
8
+ [`${CSS_CLASS_PREFIX}-left`]: isNumber(translateX) && coordinate && isNumber(coordinate.x) && translateX < coordinate.x,
9
+ [`${CSS_CLASS_PREFIX}-bottom`]: isNumber(translateY) && coordinate && isNumber(coordinate.y) && translateY >= coordinate.y,
10
+ [`${CSS_CLASS_PREFIX}-top`]: isNumber(translateY) && coordinate && isNumber(coordinate.y) && translateY < coordinate.y
10
11
  }];
11
12
  }
12
- function i({ allowEscapeViewBox: t, coordinate: n, key: r, offsetTopLeft: i, position: a, reverseDirection: o, tooltipDimension: s, viewBox: c, viewBoxDimension: l }) {
13
- if (a && e(a[r])) return a[r];
14
- let u = n[r] - s - (i > 0 ? i : 0), d = n[r] + i;
15
- if (t[r]) return o[r] ? u : d;
16
- let f = c[r];
17
- return f == null ? 0 : o[r] ? u < f ? Math.max(d, f) : Math.max(u, f) : l == null ? 0 : d + s > f + l ? Math.max(u, f) : Math.max(d, f);
13
+ function getTooltipTranslateXY({ allowEscapeViewBox, coordinate, key, offsetTopLeft, position, reverseDirection, tooltipDimension, viewBox, viewBoxDimension }) {
14
+ if (position && isNumber(position[key])) return position[key];
15
+ const negative = coordinate[key] - tooltipDimension - (offsetTopLeft > 0 ? offsetTopLeft : 0);
16
+ const positive = coordinate[key] + offsetTopLeft;
17
+ if (allowEscapeViewBox[key]) return reverseDirection[key] ? negative : positive;
18
+ const viewBoxKey = viewBox[key];
19
+ if (viewBoxKey == null) return 0;
20
+ if (reverseDirection[key]) {
21
+ if (negative < viewBoxKey) return Math.max(positive, viewBoxKey);
22
+ return Math.max(negative, viewBoxKey);
23
+ }
24
+ if (viewBoxDimension == null) return 0;
25
+ if (positive + tooltipDimension > viewBoxKey + viewBoxDimension) return Math.max(negative, viewBoxKey);
26
+ return Math.max(positive, viewBoxKey);
18
27
  }
19
- function a({ translateX: e, translateY: t, useTranslate3d: n }) {
20
- return { transform: n ? `translate3d(${e}px, ${t}px, 0)` : `translate(${e}px, ${t}px)` };
28
+ function getTransformStyle({ translateX, translateY, useTranslate3d }) {
29
+ return { transform: useTranslate3d ? `translate3d(${translateX}px, ${translateY}px, 0)` : `translate(${translateX}px, ${translateY}px)` };
21
30
  }
22
- function o({ allowEscapeViewBox: e, coordinate: t, offsetTopLeft: o, position: s, reverseDirection: c, tooltipBox: l, useTranslate3d: u, viewBox: d }) {
23
- let f, p, m;
24
- return l.height > 0 && l.width > 0 && t ? (p = i({
25
- allowEscapeViewBox: e,
26
- coordinate: t,
27
- key: "x",
28
- offsetTopLeft: o,
29
- position: s,
30
- reverseDirection: c,
31
- tooltipDimension: l.width,
32
- viewBox: d,
33
- viewBoxDimension: d.width
34
- }), m = i({
35
- allowEscapeViewBox: e,
36
- coordinate: t,
37
- key: "y",
38
- offsetTopLeft: o,
39
- position: s,
40
- reverseDirection: c,
41
- tooltipDimension: l.height,
42
- viewBox: d,
43
- viewBoxDimension: d.height
44
- }), f = {}) : f = n, {
45
- cssProperties: f,
46
- cssClasses: r({
47
- translateX: p,
48
- translateY: m,
49
- coordinate: t
31
+ function getTooltipTranslate({ allowEscapeViewBox, coordinate, offsetTopLeft, position, reverseDirection, tooltipBox, useTranslate3d, viewBox }) {
32
+ let cssProperties, translateX, translateY;
33
+ if (tooltipBox.height > 0 && tooltipBox.width > 0 && coordinate) {
34
+ translateX = getTooltipTranslateXY({
35
+ allowEscapeViewBox,
36
+ coordinate,
37
+ key: "x",
38
+ offsetTopLeft,
39
+ position,
40
+ reverseDirection,
41
+ tooltipDimension: tooltipBox.width,
42
+ viewBox,
43
+ viewBoxDimension: viewBox.width
44
+ });
45
+ translateY = getTooltipTranslateXY({
46
+ allowEscapeViewBox,
47
+ coordinate,
48
+ key: "y",
49
+ offsetTopLeft,
50
+ position,
51
+ reverseDirection,
52
+ tooltipDimension: tooltipBox.height,
53
+ viewBox,
54
+ viewBoxDimension: viewBox.height
55
+ });
56
+ cssProperties = {};
57
+ } else cssProperties = TOOLTIP_HIDDEN;
58
+ return {
59
+ cssProperties,
60
+ cssClasses: getTooltipCSSClassName({
61
+ translateX,
62
+ translateY,
63
+ coordinate
50
64
  }),
51
- transform: a({
52
- translateX: p ?? 0,
53
- translateY: m ?? 0,
54
- useTranslate3d: u
65
+ transform: getTransformStyle({
66
+ translateX: translateX ?? 0,
67
+ translateY: translateY ?? 0,
68
+ useTranslate3d
55
69
  })
56
70
  };
57
71
  }
58
72
  //#endregion
59
- export { o as getTooltipTranslate };
73
+ export { getTooltipTranslate };