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,12 +1,31 @@
1
- import { inject as e, provide as t } from "vue";
1
+ import { inject, provide } from "vue";
2
2
  //#region src/utils/createContext.ts
3
- function n(n) {
4
- let r = n, i = Symbol(r);
5
- return [(t) => {
6
- let r = e(i, t);
7
- if (r === void 0) throw Error(`Injection \`${i.toString()}\` not found. Component must be used within ${`\`${n}\``}`);
8
- return r;
9
- }, (e) => (t(i, e), e)];
3
+ /**
4
+ * @param providerComponentName - The name(s) of the component(s) providing the context.
5
+ *
6
+ * There are situations where context can come from multiple components. In such cases, you might need to give an array of component names to provide your context, instead of just a single string.
7
+ *
8
+ * @param contextName The description for injection key symbol.
9
+ */
10
+ function createContext(contextName) {
11
+ const symbolDescription = contextName;
12
+ const injectionKey = Symbol(symbolDescription);
13
+ /**
14
+ * @param fallback The context value to return if the injection fails.
15
+ *
16
+ * @throws When context injection failed and no fallback is specified.
17
+ * This happens when the component injecting the context is not a child of the root component providing the context.
18
+ */
19
+ const injectContext = (fallback) => {
20
+ const context = inject(injectionKey, fallback);
21
+ if (context === void 0) throw new Error(`Injection \`${injectionKey.toString()}\` not found. Component must be used within ${`\`${contextName}\``}`);
22
+ return context;
23
+ };
24
+ const provideContext = (contextValue) => {
25
+ provide(injectionKey, contextValue);
26
+ return contextValue;
27
+ };
28
+ return [injectContext, provideContext];
10
29
  }
11
30
  //#endregion
12
- export { n as createContext };
31
+ export { createContext };
@@ -1,12 +1,13 @@
1
- import { isNumber as e } from "./validate.mjs";
1
+ import { isNumber } from "./validate.mjs";
2
2
  //#region src/utils/data-utils.ts
3
- var t = 0;
4
- function n(e) {
5
- let n = ++t;
6
- return `${e || ""}${n}`;
3
+ var idCounter = 0;
4
+ function uniqueId(prefix) {
5
+ const id = ++idCounter;
6
+ return `${prefix || ""}${id}`;
7
7
  }
8
- function r(t, n, r) {
9
- return e(t) && e(n) ? t + r * (n - t) : n;
8
+ function interpolate(start, end, t) {
9
+ if (isNumber(start) && isNumber(end)) return start + t * (end - start);
10
+ return end;
10
11
  }
11
12
  //#endregion
12
- export { r as interpolate, n as uniqueId };
13
+ export { interpolate, uniqueId };
@@ -1,27 +1,41 @@
1
- import { isNan as e, isNumber as t, isPercent as n } from "./validate.mjs";
2
- import { get as r } from "lodash-es";
1
+ import { isNan, isNumber, isPercent } from "./validate.mjs";
2
+ import { get } from "lodash-es";
3
3
  //#region src/utils/data.ts
4
- function i(e) {
5
- return e === 0 ? 0 : e > 0 ? 1 : -1;
4
+ function mathSign(value) {
5
+ if (value === 0) return 0;
6
+ if (value > 0) return 1;
7
+ return -1;
6
8
  }
7
- function a(e) {
8
- if (!Array.isArray(e)) return !1;
9
- let t = e.length, n = {};
10
- for (let r = 0; r < t; r++) if (!n[e[r]]) n[e[r]] = !0;
11
- else return !0;
12
- return !1;
9
+ function hasDuplicate(ary) {
10
+ if (!Array.isArray(ary)) return false;
11
+ const len = ary.length;
12
+ const cache = {};
13
+ for (let i = 0; i < len; i++) if (!cache[ary[i]]) cache[ary[i]] = true;
14
+ else return true;
15
+ return false;
13
16
  }
14
- function o(r, i, a = 0, o = !1) {
15
- if (!t(r) && typeof r != "string") return a;
16
- let s;
17
- if (n(r)) {
18
- let e = r.indexOf("%");
19
- s = i * parseFloat(r.slice(0, e)) / 100;
20
- } else s = +r;
21
- return e(s) && (s = a), o && s > i && (s = i), s;
17
+ /**
18
+ * Get percent value of a total value
19
+ * @param {number|string} percent A percent
20
+ * @param {number} totalValue Total value
21
+ * @param {number} defaultValue The value returned when percent is undefined or invalid
22
+ * @param {boolean} validate If set to be true, the result will be validated
23
+ * @return {number} value
24
+ */
25
+ function getPercentValue(percent, totalValue, defaultValue = 0, validate = false) {
26
+ if (!isNumber(percent) && typeof percent !== "string") return defaultValue;
27
+ let value;
28
+ if (isPercent(percent)) {
29
+ const index = percent.indexOf("%");
30
+ value = totalValue * parseFloat(percent.slice(0, index)) / 100;
31
+ } else value = +percent;
32
+ if (isNan(value)) value = defaultValue;
33
+ if (validate && value > totalValue) value = totalValue;
34
+ return value;
22
35
  }
23
- function s(e, t, n) {
24
- return !e || !e.length ? null : e.find((e) => e && (typeof t == "function" ? t(e) : r(e, t)) === n);
36
+ function findEntryInArray(ary, specifiedKey, specifiedValue) {
37
+ if (!ary || !ary.length) return null;
38
+ return ary.find((entry) => entry && (typeof specifiedKey === "function" ? specifiedKey(entry) : get(entry, specifiedKey)) === specifiedValue);
25
39
  }
26
40
  //#endregion
27
- export { s as findEntryInArray, o as getPercentValue, a as hasDuplicate, i as mathSign };
41
+ export { findEntryInArray, getPercentValue, hasDuplicate, mathSign };
@@ -1,5 +1,7 @@
1
- import e from "eventemitter3";
1
+ import EventEmitter from "eventemitter3";
2
2
  //#region src/utils/events.ts
3
- var t = new e(), n = "recharts.syncEvent.tooltip", r = "recharts.syncEvent.brush";
3
+ var eventCenter = new EventEmitter();
4
+ var TOOLTIP_SYNC_EVENT = "recharts.syncEvent.tooltip";
5
+ var BRUSH_SYNC_EVENT = "recharts.syncEvent.brush";
4
6
  //#endregion
5
- export { r as BRUSH_SYNC_EVENT, n as TOOLTIP_SYNC_EVENT, t as eventCenter };
7
+ export { BRUSH_SYNC_EVENT, TOOLTIP_SYNC_EVENT, eventCenter };
@@ -1,17 +1,34 @@
1
1
  //#region src/utils/getLinearRegression.ts
2
- function e(e) {
3
- let t = e.length, n = 0, r = 0, i = 0, a = 0, o = Infinity, s = -Infinity;
4
- for (let c = 0; c < t; c++) {
5
- let t = e[c]?.cx || 0, l = e[c]?.cy || 0;
6
- n += t, r += l, i += t * l, a += t * t, o = Math.min(o, t), s = Math.max(s, t);
2
+ /**
3
+ * The least square linear regression
4
+ * @param data The array of points
5
+ * @returns The domain of x, and the parameter of linear function y = ax + b
6
+ */
7
+ function getLinearRegression(data) {
8
+ const len = data.length;
9
+ let xsum = 0;
10
+ let ysum = 0;
11
+ let xysum = 0;
12
+ let xxsum = 0;
13
+ let xmin = Infinity;
14
+ let xmax = -Infinity;
15
+ for (let i = 0; i < len; i++) {
16
+ const xcurrent = data[i]?.cx || 0;
17
+ const ycurrent = data[i]?.cy || 0;
18
+ xsum += xcurrent;
19
+ ysum += ycurrent;
20
+ xysum += xcurrent * ycurrent;
21
+ xxsum += xcurrent * xcurrent;
22
+ xmin = Math.min(xmin, xcurrent);
23
+ xmax = Math.max(xmax, xcurrent);
7
24
  }
8
- let c = t * a === n * n ? 0 : (t * i - n * r) / (t * a - n * n);
25
+ const a = len * xxsum !== xsum * xsum ? (len * xysum - xsum * ysum) / (len * xxsum - xsum * xsum) : 0;
9
26
  return {
10
- xmin: o,
11
- xmax: s,
12
- a: c,
13
- b: (r - c * n) / t
27
+ xmin,
28
+ xmax,
29
+ a,
30
+ b: (ysum - a * xsum) / len
14
31
  };
15
32
  }
16
33
  //#endregion
17
- export { e as getLinearRegression };
34
+ export { getLinearRegression };
@@ -1,8 +1,23 @@
1
1
  //#region src/utils/grid.ts
2
- function e(e, t, n, r) {
3
- if (r) return e.map((e) => e.coordinate);
4
- let i, a, o = e.map((e) => (e.coordinate === t && (i = !0), e.coordinate === n && (a = !0), e.coordinate));
5
- return i || o.push(t), a || o.push(n), o;
2
+ /**
3
+ * Calculate the Coordinates of grid
4
+ * @param {Array} ticks The ticks in axis
5
+ * @param {number} minValue The minimum value of axis
6
+ * @param {number} maxValue The maximum value of axis
7
+ * @param {boolean} syncWithTicks Synchronize grid lines with ticks or not
8
+ * @return {Array} Coordinates
9
+ */
10
+ function getCoordinatesOfGrid(ticks, minValue, maxValue, syncWithTicks) {
11
+ if (syncWithTicks) return ticks.map((entry) => entry.coordinate);
12
+ let hasMin, hasMax;
13
+ const values = ticks.map((entry) => {
14
+ if (entry.coordinate === minValue) hasMin = true;
15
+ if (entry.coordinate === maxValue) hasMax = true;
16
+ return entry.coordinate;
17
+ });
18
+ if (!hasMin) values.push(minValue);
19
+ if (!hasMax) values.push(maxValue);
20
+ return values;
6
21
  }
7
22
  //#endregion
8
- export { e as getCoordinatesOfGrid };
23
+ export { getCoordinatesOfGrid };
@@ -1,65 +1,116 @@
1
- import { isNumber as e, isWellBehavedNumber as t } from "./validate.mjs";
2
- import { MAX_VALUE_REG as n, MIN_VALUE_REG as r } from "./chart.mjs";
1
+ import { isNumber, isWellBehavedNumber } from "./validate.mjs";
2
+ import { MAX_VALUE_REG, MIN_VALUE_REG } from "./chart.mjs";
3
3
  //#region src/utils/isDomainSpecifiedByUser.ts
4
- function i(e) {
5
- if (Array.isArray(e) && e.length === 2) {
6
- let [n, r] = e;
7
- if (t(n) && t(r)) return !0;
4
+ function isWellFormedNumberDomain(v) {
5
+ if (Array.isArray(v) && v.length === 2) {
6
+ const [min, max] = v;
7
+ if (isWellBehavedNumber(min) && isWellBehavedNumber(max)) return true;
8
8
  }
9
- return !1;
9
+ return false;
10
10
  }
11
- function a(e, t, n) {
12
- return n ? e : [Math.min(e[0], t[0]), Math.max(e[1], t[1])];
11
+ function extendDomain(providedDomain, boundaryDomain, allowDataOverflow) {
12
+ if (allowDataOverflow) return providedDomain;
13
+ return [Math.min(providedDomain[0], boundaryDomain[0]), Math.max(providedDomain[1], boundaryDomain[1])];
13
14
  }
14
- function o(e, n) {
15
- if (n && typeof e != "function" && Array.isArray(e) && e.length === 2) {
16
- let [n, r] = e, a, o;
17
- if (t(n)) a = n;
18
- else if (typeof n == "function") return;
19
- if (t(r)) o = r;
20
- else if (typeof r == "function") return;
21
- let s = [a, o];
22
- if (i(s)) return s;
15
+ /**
16
+ * So Recharts allows users to provide their own domains,
17
+ * but it also places some expectations on what the domain is.
18
+ * We can improve on the typescript typing, but we also need a runtime test
19
+ to observe that the user-provided domain is well-formed,
20
+ * that is: an array with exactly two numbers.
21
+ *
22
+ * This function does not accept data as an argument.
23
+ * This is to enable a performance optimization - if the domain is there,
24
+ * and we know what it is without traversing all the data,
25
+ * then we don't have to traverse all the data!
26
+ *
27
+ * If the user-provided domain is not well-formed,
28
+ * this function will return undefined - in which case we should traverse the data to calculate the real domain.
29
+ *
30
+ * This function is for parsing the numerical domain only.
31
+ *
32
+ * @param userDomain external prop, user provided, before validation. Can have various shapes: array, function, special magical strings inside too.
33
+ * @param allowDataOverflow boolean, provided by users. If true then the data domain wins
34
+ *
35
+ * @return [min, max] domain if it's well-formed; undefined if the domain is invalid
36
+ */
37
+ function numericalDomainSpecifiedWithoutRequiringData(userDomain, allowDataOverflow) {
38
+ if (!allowDataOverflow) return;
39
+ if (typeof userDomain === "function") return;
40
+ if (Array.isArray(userDomain) && userDomain.length === 2) {
41
+ const [providedMin, providedMax] = userDomain;
42
+ let finalMin, finalMax;
43
+ if (isWellBehavedNumber(providedMin)) finalMin = providedMin;
44
+ else if (typeof providedMin === "function") return;
45
+ if (isWellBehavedNumber(providedMax)) finalMax = providedMax;
46
+ else if (typeof providedMax === "function") return;
47
+ const candidate = [finalMin, finalMax];
48
+ if (isWellFormedNumberDomain(candidate)) return candidate;
23
49
  }
24
50
  }
25
- function s(t, o, s) {
26
- if (!(!s && o == null)) {
27
- if (typeof t == "function" && o != null) try {
28
- let e = t(o, s);
29
- if (i(e)) return a(e, o, s);
51
+ /**
52
+ * So Recharts allows users to provide their own domains,
53
+ * but it also places some expectations on what the domain is.
54
+ * We can improve on the typescript typing, but we also need a runtime test
55
+ * to observe that the user-provided domain is well-formed,
56
+ * that is: an array with exactly two numbers.
57
+ * If the user-provided domain is not well-formed,
58
+ * this function will return undefined - in which case we should traverse the data to calculate the real domain.
59
+ *
60
+ * This function is for parsing the numerical domain only.
61
+ *
62
+ * You are probably thinking, why does domain need tick count?
63
+ * Well it adjusts the domain based on where the "nice ticks" land, and nice ticks depend on the tick count.
64
+ *
65
+ * @param userDomain external prop, user provided, before validation. Can have various shapes: array, function, special magical strings inside too.
66
+ * @param dataDomain calculated from data. Can be undefined, as an option for performance optimization
67
+ * @param allowDataOverflow provided by users. If true then the data domain wins
68
+ *
69
+ * @return [min, max] domain if it's well-formed; undefined if the domain is invalid
70
+ */
71
+ function parseNumericalUserDomain(userDomain, dataDomain, allowDataOverflow) {
72
+ if (!allowDataOverflow && dataDomain == null) return;
73
+ if (typeof userDomain === "function" && dataDomain != null) try {
74
+ const result = userDomain(dataDomain, allowDataOverflow);
75
+ if (isWellFormedNumberDomain(result)) return extendDomain(result, dataDomain, allowDataOverflow);
76
+ } catch {}
77
+ if (Array.isArray(userDomain) && userDomain.length === 2) {
78
+ const [providedMin, providedMax] = userDomain;
79
+ let finalMin, finalMax;
80
+ if (providedMin === "auto") {
81
+ if (dataDomain != null) finalMin = Math.min(...dataDomain);
82
+ } else if (isNumber(providedMin)) finalMin = providedMin;
83
+ else if (typeof providedMin === "function") try {
84
+ if (dataDomain != null) finalMin = providedMin(dataDomain?.[0]);
30
85
  } catch {}
31
- if (Array.isArray(t) && t.length === 2) {
32
- let [c, l] = t, u, d;
33
- if (c === "auto") o != null && (u = Math.min(...o));
34
- else if (e(c)) u = c;
35
- else if (typeof c == "function") try {
36
- o != null && (u = c(o?.[0]));
37
- } catch {}
38
- else if (typeof c == "string" && r.test(c)) {
39
- let e = r.exec(c);
40
- if (e == null || o == null) u = void 0;
41
- else {
42
- let t = +e[1];
43
- u = o[0] - t;
44
- }
45
- } else u = o?.[0];
46
- if (l === "auto") o != null && (d = Math.max(...o));
47
- else if (e(l)) d = l;
48
- else if (typeof l == "function") try {
49
- o != null && (d = l(o?.[1]));
50
- } catch {}
51
- else if (typeof l == "string" && n.test(l)) {
52
- let e = n.exec(l);
53
- if (e == null || o == null) d = void 0;
54
- else {
55
- let t = +e[1];
56
- d = o[1] + t;
57
- }
58
- } else d = o?.[1];
59
- let f = [u, d];
60
- if (i(f)) return o == null ? f : a(f, o, s);
86
+ else if (typeof providedMin === "string" && MIN_VALUE_REG.test(providedMin)) {
87
+ const match = MIN_VALUE_REG.exec(providedMin);
88
+ if (match == null || dataDomain == null) finalMin = void 0;
89
+ else {
90
+ const value = +match[1];
91
+ finalMin = dataDomain[0] - value;
92
+ }
93
+ } else finalMin = dataDomain?.[0];
94
+ if (providedMax === "auto") {
95
+ if (dataDomain != null) finalMax = Math.max(...dataDomain);
96
+ } else if (isNumber(providedMax)) finalMax = providedMax;
97
+ else if (typeof providedMax === "function") try {
98
+ if (dataDomain != null) finalMax = providedMax(dataDomain?.[1]);
99
+ } catch {}
100
+ else if (typeof providedMax === "string" && MAX_VALUE_REG.test(providedMax)) {
101
+ const match = MAX_VALUE_REG.exec(providedMax);
102
+ if (match == null || dataDomain == null) finalMax = void 0;
103
+ else {
104
+ const value = +match[1];
105
+ finalMax = dataDomain[1] + value;
106
+ }
107
+ } else finalMax = dataDomain?.[1];
108
+ const candidate = [finalMin, finalMax];
109
+ if (isWellFormedNumberDomain(candidate)) {
110
+ if (dataDomain == null) return candidate;
111
+ return extendDomain(candidate, dataDomain, allowDataOverflow);
61
112
  }
62
113
  }
63
114
  }
64
115
  //#endregion
65
- export { i as isWellFormedNumberDomain, o as numericalDomainSpecifiedWithoutRequiringData, s as parseNumericalUserDomain };
116
+ export { isWellFormedNumberDomain, numericalDomainSpecifiedWithoutRequiringData, parseNumericalUserDomain };
@@ -1,18 +1,19 @@
1
- import { isNumber as e } from "./validate.mjs";
1
+ import { isNumber } from "./validate.mjs";
2
2
  //#region src/utils/legend.ts
3
- function t(t, n, r) {
4
- if (n && r) {
5
- let { width: i, height: a } = r, { align: o, verticalAlign: s, layout: c } = n;
6
- if ((c === "vertical" || c === "horizontal" && s === "middle") && o !== "center" && e(t[o])) return {
7
- ...t,
8
- [o]: t[o] + (i || 0)
3
+ function appendOffsetOfLegend(offset, legendSettings, legendSize) {
4
+ if (legendSettings && legendSize) {
5
+ const { width: boxWidth, height: boxHeight } = legendSize;
6
+ const { align, verticalAlign, layout } = legendSettings;
7
+ if ((layout === "vertical" || layout === "horizontal" && verticalAlign === "middle") && align !== "center" && isNumber(offset[align])) return {
8
+ ...offset,
9
+ [align]: offset[align] + (boxWidth || 0)
9
10
  };
10
- if ((c === "horizontal" || c === "vertical" && o === "center") && s !== "middle" && e(t[s])) return {
11
- ...t,
12
- [s]: t[s] + (a || 0)
11
+ if ((layout === "horizontal" || layout === "vertical" && align === "center") && verticalAlign !== "middle" && isNumber(offset[verticalAlign])) return {
12
+ ...offset,
13
+ [verticalAlign]: offset[verticalAlign] + (boxHeight || 0)
13
14
  };
14
15
  }
15
- return t;
16
+ return offset;
16
17
  }
17
18
  //#endregion
18
- export { t as appendOffsetOfLegend };
19
+ export { appendOffsetOfLegend };
@@ -1,11 +1,14 @@
1
1
  //#region src/utils/log.ts
2
- var e = process.env.NODE_ENV !== "production";
3
- function t(t, n, ...r) {
4
- if (e && typeof console < "u" && console.warn && (n === void 0 && console.warn("LogUtils requires an error message argument"), !t)) if (n === void 0) console.warn("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");
5
- else {
6
- let e = 0;
7
- console.warn(n.replace(/%s/g, () => r[e++]));
2
+ var isDev = process.env.NODE_ENV !== "production";
3
+ function warn(condition, format, ...args) {
4
+ if (isDev && typeof console !== "undefined" && console.warn) {
5
+ if (format === void 0) console.warn("LogUtils requires an error message argument");
6
+ if (!condition) if (format === void 0) console.warn("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");
7
+ else {
8
+ let argIndex = 0;
9
+ console.warn(format.replace(/%s/g, () => args[argIndex++]));
10
+ }
8
11
  }
9
12
  }
10
13
  //#endregion
11
- export { t as warn };
14
+ export { warn };
@@ -1,7 +1,9 @@
1
- import { uniqBy as e } from "es-toolkit/compat";
1
+ import { uniqBy } from "es-toolkit/compat";
2
2
  //#region src/utils/payload/getUniqPayload.ts
3
- function t(t, n, r) {
4
- return n === !0 ? e(t, r) : typeof n == "function" ? e(t, n) : t;
3
+ function getUniqPayload(payload, option, defaultUniqBy) {
4
+ if (option === true) return uniqBy(payload, defaultUniqBy);
5
+ if (typeof option === "function") return uniqBy(payload, option);
6
+ return payload;
5
7
  }
6
8
  //#endregion
7
- export { t as getUniqPayload };
9
+ export { getUniqPayload };
@@ -1,52 +1,59 @@
1
1
  //#region src/utils/polar.ts
2
- var e = Math.PI / 180, t = (e) => e * 180 / Math.PI;
3
- function n(e, t) {
4
- let { x: n, y: r } = e, { x: i, y: a } = t;
5
- return Math.sqrt((n - i) ** 2 + (r - a) ** 2);
2
+ var RADIAN = Math.PI / 180;
3
+ var radianToDegree = (angleInRadian) => angleInRadian * 180 / Math.PI;
4
+ function distanceBetweenPoints(point, anotherPoint) {
5
+ const { x: x1, y: y1 } = point;
6
+ const { x: x2, y: y2 } = anotherPoint;
7
+ return Math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2);
6
8
  }
7
- function r({ startAngle: e, endAngle: t }) {
8
- let n = Math.floor(e / 360), r = Math.floor(t / 360), i = Math.min(n, r);
9
+ function formatAngleOfSector({ startAngle, endAngle }) {
10
+ const startCnt = Math.floor(startAngle / 360);
11
+ const endCnt = Math.floor(endAngle / 360);
12
+ const min = Math.min(startCnt, endCnt);
9
13
  return {
10
- startAngle: e - i * 360,
11
- endAngle: t - i * 360
14
+ startAngle: startAngle - min * 360,
15
+ endAngle: endAngle - min * 360
12
16
  };
13
17
  }
14
- function i({ x: e, y: r }, { cx: i, cy: a }) {
15
- let o = n({
16
- x: e,
17
- y: r
18
+ function getAngleOfPoint({ x, y }, { cx, cy }) {
19
+ const radius = distanceBetweenPoints({
20
+ x,
21
+ y
18
22
  }, {
19
- x: i,
20
- y: a
23
+ x: cx,
24
+ y: cy
21
25
  });
22
- if (o <= 0) return {
23
- radius: o,
26
+ if (radius <= 0) return {
27
+ radius,
24
28
  angle: 0
25
29
  };
26
- let s = (e - i) / o, c = Math.acos(s);
27
- return r > a && (c = 2 * Math.PI - c), {
28
- radius: o,
29
- angle: t(c),
30
- angleInRadian: c
30
+ const cos = (x - cx) / radius;
31
+ let angleInRadian = Math.acos(cos);
32
+ if (y > cy) angleInRadian = 2 * Math.PI - angleInRadian;
33
+ return {
34
+ radius,
35
+ angle: radianToDegree(angleInRadian),
36
+ angleInRadian
31
37
  };
32
38
  }
33
- function a(e, { startAngle: t, endAngle: n }) {
34
- let r = Math.floor(t / 360), i = Math.floor(n / 360);
35
- return e + Math.min(r, i) * 360;
39
+ function reverseFormatAngleOfSector(angle, { startAngle, endAngle }) {
40
+ const startCnt = Math.floor(startAngle / 360);
41
+ const endCnt = Math.floor(endAngle / 360);
42
+ return angle + Math.min(startCnt, endCnt) * 360;
36
43
  }
37
- function o(t, n, r, i) {
44
+ function polarToCartesian(cx, cy, radius, angle) {
38
45
  return {
39
- x: t + Math.cos(-e * i) * r,
40
- y: n + Math.sin(-e * i) * r
46
+ x: cx + Math.cos(-RADIAN * angle) * radius,
47
+ y: cy + Math.sin(-RADIAN * angle) * radius
41
48
  };
42
49
  }
43
- function s(e, t, n = {
50
+ function getMaxRadius(width, height, offset = {
44
51
  top: 0,
45
52
  right: 0,
46
53
  bottom: 0,
47
54
  left: 0
48
55
  }) {
49
- return Math.min(Math.abs(e - (n.left || 0) - (n.right || 0)), Math.abs(t - (n.top || 0) - (n.bottom || 0))) / 2;
56
+ return Math.min(Math.abs(width - (offset.left || 0) - (offset.right || 0)), Math.abs(height - (offset.top || 0) - (offset.bottom || 0))) / 2;
50
57
  }
51
58
  //#endregion
52
- export { e as RADIAN, r as formatAngleOfSector, i as getAngleOfPoint, s as getMaxRadius, o as polarToCartesian, a as reverseFormatAngleOfSector };
59
+ export { RADIAN, formatAngleOfSector, getAngleOfPoint, getMaxRadius, polarToCartesian, reverseFormatAngleOfSector };
@@ -1,14 +1,20 @@
1
1
  //#region src/utils/props.ts
2
- function e(e, t) {
3
- let n = { ...e };
4
- for (let [e, r] of Object.entries(t)) if (e in n) {
5
- let t = n[e];
6
- typeof t == "object" && t && "type" in t && (n[e] = {
7
- ...t,
8
- default: r
9
- });
2
+ /**
3
+ * 将 defaultProps 的属性值作为 props 的 default 属性
4
+ * @param props - Vue 组件的 props 定义对象
5
+ * @param defaultProps - 默认值对象
6
+ * @returns 新的 Vue 组件 props 对象
7
+ */
8
+ function applyDefaultProps(props, defaultProps) {
9
+ const newProps = { ...props };
10
+ for (const [key, defaultValue] of Object.entries(defaultProps)) if (key in newProps) {
11
+ const propDef = newProps[key];
12
+ if (typeof propDef === "object" && propDef !== null && "type" in propDef) newProps[key] = {
13
+ ...propDef,
14
+ default: defaultValue
15
+ };
10
16
  }
11
- return n;
17
+ return newProps;
12
18
  }
13
19
  //#endregion
14
- export { e as applyDefaultProps };
20
+ export { applyDefaultProps };
@@ -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 };