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,104 +1,125 @@
1
- import { isNumber as e, isWellBehavedNumber as t } from "../../utils/validate.mjs";
2
- import { useAreaContext as n } from "./hooks/useArea.mjs";
3
- import { Animate as r } from "../../animation/Animate.mjs";
4
- import { createVNode as i, defineComponent as a, ref as o, watch as s } from "vue";
1
+ import { isNumber, isWellBehavedNumber } from "../../utils/validate.mjs";
2
+ import { useAreaContext } from "./hooks/useArea.mjs";
3
+ import { Animate } from "../../animation/Animate.mjs";
4
+ import { createVNode, defineComponent, ref, watch } from "vue";
5
5
  //#region src/cartesian/area/ClipRect.tsx
6
- var c = /* @__PURE__ */ a({
6
+ var HorizontalRect = /* @__PURE__ */ defineComponent({
7
7
  name: "HorizontalRect",
8
8
  props: {
9
9
  alpha: {
10
10
  type: Number,
11
- required: !0
11
+ required: true
12
12
  },
13
13
  points: {
14
14
  type: Array,
15
- required: !0
15
+ required: true
16
16
  },
17
17
  baseLine: {
18
18
  type: [Number, Array],
19
- required: !0
19
+ required: true
20
20
  },
21
21
  strokeWidth: {
22
22
  type: Number,
23
- required: !0
23
+ required: true
24
24
  }
25
25
  },
26
- setup(t) {
27
- let { points: n } = t;
26
+ setup(props) {
27
+ const { points } = props;
28
28
  return () => {
29
- let { alpha: r, baseLine: a, strokeWidth: o } = t, s = n[0].x, c = n[n.length - 1].x, l = r * Math.abs(s - c), u = Math.max(...n.map((e) => e.y || 0));
30
- return e(a) ? u = Math.max(a, u) : a && Array.isArray(a) && a.length && (u = Math.max(...a.map((e) => e.y || 0), u)), e(u) ? i("rect", {
31
- x: s < c ? s : s - l,
32
- y: 0,
33
- width: l,
34
- height: Math.floor(u + (o ? parseInt(`${o}`, 10) : 1))
35
- }, null) : null;
29
+ const { alpha, baseLine, strokeWidth } = props;
30
+ const startX = points[0].x;
31
+ const endX = points[points.length - 1].x;
32
+ const width = alpha * Math.abs(startX - endX);
33
+ let maxY = Math.max(...points.map((entry) => entry.y || 0));
34
+ if (isNumber(baseLine)) maxY = Math.max(baseLine, maxY);
35
+ else if (baseLine && Array.isArray(baseLine) && baseLine.length) maxY = Math.max(...baseLine.map((entry) => entry.y || 0), maxY);
36
+ if (isNumber(maxY)) return createVNode("rect", {
37
+ "x": startX < endX ? startX : startX - width,
38
+ "y": 0,
39
+ "width": width,
40
+ "height": Math.floor(maxY + (strokeWidth ? parseInt(`${strokeWidth}`, 10) : 1))
41
+ }, null);
42
+ return null;
36
43
  };
37
44
  }
38
- }), l = /* @__PURE__ */ a({
45
+ });
46
+ var VerticalRect = /* @__PURE__ */ defineComponent({
39
47
  name: "VerticalRect",
40
48
  props: {
41
49
  alpha: {
42
50
  type: Number,
43
- required: !0
51
+ required: true
44
52
  },
45
53
  points: {
46
54
  type: Array,
47
- required: !0
55
+ required: true
48
56
  },
49
57
  baseLine: {
50
58
  type: [Number, Array],
51
- required: !0
59
+ required: true
52
60
  },
53
61
  strokeWidth: {
54
62
  type: Number,
55
- required: !0
63
+ required: true
56
64
  }
57
65
  },
58
- setup(n) {
59
- let { points: r } = n;
66
+ setup(props) {
67
+ const { points } = props;
60
68
  return () => {
61
- let { alpha: a, baseLine: o, strokeWidth: s } = n, c = r[0].y, l = r[r.length - 1].y;
62
- if (!t(c) || !t(l)) return null;
63
- let u = a * Math.abs(c - l), d = Math.max(...r.map((e) => e.x || 0));
64
- return e(o) ? d = Math.max(o, d) : o && Array.isArray(o) && o.length && (d = Math.max(...o.map((e) => e.x || 0), d)), i("rect", {
65
- x: 0,
66
- y: c < l ? c : c - u,
67
- width: d + (s ? parseInt(`${s}`, 10) : 1),
68
- height: Math.floor(u)
69
+ const { alpha, baseLine, strokeWidth } = props;
70
+ const startY = points[0].y;
71
+ const endY = points[points.length - 1].y;
72
+ if (!isWellBehavedNumber(startY) || !isWellBehavedNumber(endY)) return null;
73
+ const height = alpha * Math.abs(startY - endY);
74
+ let maxX = Math.max(...points.map((entry) => entry.x || 0));
75
+ if (isNumber(baseLine)) maxX = Math.max(baseLine, maxX);
76
+ else if (baseLine && Array.isArray(baseLine) && baseLine.length) maxX = Math.max(...baseLine.map((entry) => entry.x || 0), maxX);
77
+ return createVNode("rect", {
78
+ "x": 0,
79
+ "y": startY < endY ? startY : startY - height,
80
+ "width": maxX + (strokeWidth ? parseInt(`${strokeWidth}`, 10) : 1),
81
+ "height": Math.floor(height)
69
82
  }, null);
70
83
  };
71
84
  }
72
- }), u = /* @__PURE__ */ a({
85
+ });
86
+ var ClipRect = /* @__PURE__ */ defineComponent({
73
87
  name: "ClipRect",
74
88
  setup() {
75
- let { points: e, props: t, areaData: a, layout: u, isClipRectAnimating: d } = n(), f = o(!1);
76
- s(e, (e) => {
77
- e && e.length > 0 && !f.value && (f.value = !0);
78
- }, { immediate: !0 });
79
- let p = () => {
80
- f.value = !1, d.value = !1, t.onAnimationEnd?.();
89
+ const { points, props, areaData, layout, isClipRectAnimating } = useAreaContext();
90
+ const isAnimationActive = ref(false);
91
+ watch(points, (newPoints) => {
92
+ if (newPoints && newPoints.length > 0 && !isAnimationActive.value) isAnimationActive.value = true;
93
+ }, { immediate: true });
94
+ const handleAnimationEnd = () => {
95
+ isAnimationActive.value = false;
96
+ isClipRectAnimating.value = false;
97
+ props.onAnimationEnd?.();
81
98
  };
82
99
  return () => {
83
- let n = a.value?.baseLine;
84
- return !e.value || e.value.length === 0 ? null : i(r, {
85
- isActive: f.value,
86
- transition: t.transition,
87
- onAnimationStart: t.onAnimationStart,
88
- onAnimationEnd: p
89
- }, { default: (r) => u.value === "horizontal" ? i(c, {
90
- alpha: r,
91
- points: e.value,
92
- baseLine: n,
93
- strokeWidth: t.strokeWidth || 2
94
- }, null) : i(l, {
95
- alpha: r,
96
- points: e.value,
97
- baseLine: n,
98
- strokeWidth: t.strokeWidth || 2
99
- }, null) });
100
+ const baseLine = areaData.value?.baseLine;
101
+ if (!points.value || points.value.length === 0) return null;
102
+ return createVNode(Animate, {
103
+ "isActive": isAnimationActive.value,
104
+ "transition": props.transition,
105
+ "onAnimationStart": props.onAnimationStart,
106
+ "onAnimationEnd": handleAnimationEnd
107
+ }, { default: (t) => {
108
+ if (layout.value === "horizontal") return createVNode(HorizontalRect, {
109
+ "alpha": t,
110
+ "points": points.value,
111
+ "baseLine": baseLine,
112
+ "strokeWidth": props.strokeWidth || 2
113
+ }, null);
114
+ return createVNode(VerticalRect, {
115
+ "alpha": t,
116
+ "points": points.value,
117
+ "baseLine": baseLine,
118
+ "strokeWidth": props.strokeWidth || 2
119
+ }, null);
120
+ } });
100
121
  };
101
122
  }
102
123
  });
103
124
  //#endregion
104
- export { u as ClipRect };
125
+ export { ClipRect };
@@ -1,151 +1,185 @@
1
- import { isNan as e, isNullish as t, isNumber as n } from "../../utils/validate.mjs";
2
- import { interpolate as r } from "../../utils/data-utils.mjs";
3
- import { Curve as i } from "../../shape/Curve.mjs";
4
- import { isClipDot as a } from "../../utils/chart.mjs";
5
- import { useOffset as o } from "../../context/chartLayoutContext.mjs";
6
- import { useAreaContext as s } from "./hooks/useArea.mjs";
7
- import { Layer as c } from "../../container/Layer.mjs";
8
- import { Dot as l } from "../../shape/Dot.mjs";
9
- import { LabelList as u } from "../../components/label/LabelList.mjs";
10
- import { Fragment as d, createVNode as f, defineComponent as p, mergeProps as m, ref as h, watch as g } from "vue";
11
- import { animate as _ } from "motion-v";
1
+ import { isNan, isNullish, isNumber } from "../../utils/validate.mjs";
2
+ import { interpolate } from "../../utils/data-utils.mjs";
3
+ import { Curve } from "../../shape/Curve.mjs";
4
+ import { isClipDot } from "../../utils/chart.mjs";
5
+ import { useOffset } from "../../context/chartLayoutContext.mjs";
6
+ import { useAreaContext } from "./hooks/useArea.mjs";
7
+ import { Layer } from "../../container/Layer.mjs";
8
+ import { Dot } from "../../shape/Dot.mjs";
9
+ import { LabelList } from "../../components/label/LabelList.mjs";
10
+ import { Fragment, createVNode, defineComponent, mergeProps, ref, watch } from "vue";
11
+ import { animate } from "motion-v";
12
12
  //#region src/cartesian/area/RenderArea.tsx
13
- var v = /* @__PURE__ */ p({
13
+ var Dots = /* @__PURE__ */ defineComponent({
14
14
  name: "Dots",
15
15
  props: { points: {
16
16
  type: Array,
17
17
  default: () => []
18
18
  } },
19
- setup(e) {
20
- let { clipPathId: t, props: n, attrs: r, dotSlot: i } = s();
19
+ setup(_props) {
20
+ const { clipPathId, props, attrs, dotSlot } = useAreaContext();
21
21
  return () => {
22
- let { points: o } = e;
23
- if (!b(o, n.dot)) return null;
24
- let s = a(n.dot), u = {
25
- fill: n.fill,
26
- "fill-opacity": n.fillOpacity,
27
- "stroke-width": n.strokeWidth,
28
- stroke: n.stroke
22
+ const { points } = _props;
23
+ if (!shouldRenderDots(points, props.dot)) return null;
24
+ const clipDot = isClipDot(props.dot);
25
+ const dotsProps = {
26
+ "fill": props.fill,
27
+ "fill-opacity": props.fillOpacity,
28
+ "stroke-width": props.strokeWidth,
29
+ "stroke": props.stroke
29
30
  };
30
- return f(c, {
31
- class: "v-charts-area-dots",
32
- "clip-path": n.needClip ? `url(#clipPath-${s ? "" : "dots-"}${t.value})` : void 0
33
- }, { default: () => [o?.map((e) => {
34
- let t = {
35
- ...u,
36
- ...r,
31
+ return createVNode(Layer, {
32
+ "class": "v-charts-area-dots",
33
+ "clip-path": props.needClip ? `url(#clipPath-${clipDot ? "" : "dots-"}${clipPathId.value})` : void 0
34
+ }, { default: () => [points?.map((point) => {
35
+ const dotProps = {
36
+ ...dotsProps,
37
+ ...attrs,
37
38
  r: 3,
38
- cx: e.x,
39
- cy: e.y,
39
+ cx: point.x,
40
+ cy: point.y,
40
41
  class: "v-charts-area-dot",
41
- clipDot: s
42
+ clipDot
42
43
  };
43
- return i ? i(t) : f(l, t, null);
44
+ if (dotSlot) return dotSlot(dotProps);
45
+ return createVNode(Dot, dotProps, null);
44
46
  })] });
45
47
  };
46
48
  }
47
- }), y = /* @__PURE__ */ p({
49
+ });
50
+ var StaticArea = /* @__PURE__ */ defineComponent({
48
51
  name: "StaticArea",
49
52
  setup() {
50
- let { points: a, clipPathId: l, layout: p, attrs: y, areaData: b, props: x, isAnimating: S, isClipRectAnimating: C } = s(), w = o(), T = h(a.value || []), E = h(b.value?.baseLine || []), D = T.value || [], O = b.value?.baseLine || [], k = !1;
51
- return g(a, (i, a, o) => {
52
- if (C.value) {
53
- T.value = i, E.value = b.value?.baseLine || [];
53
+ const { points, clipPathId, layout, attrs, areaData, props, isAnimating, isClipRectAnimating } = useAreaContext();
54
+ const offset = useOffset();
55
+ const currentPoints = ref(points.value || []);
56
+ const currentBaseLine = ref(areaData.value?.baseLine || []);
57
+ let prevPoints = currentPoints.value || [];
58
+ let prevBaseLine = areaData.value?.baseLine || [];
59
+ let animationStopped = false;
60
+ watch(points, (newPoints, _, onCleanup) => {
61
+ if (isClipRectAnimating.value) {
62
+ currentPoints.value = newPoints;
63
+ currentBaseLine.value = areaData.value?.baseLine || [];
54
64
  return;
55
65
  }
56
- if (i && i.length > 0) {
57
- k = !1, S.value = !0;
58
- let a = _(0, 1, {
59
- ...x.transition,
60
- onUpdate(a) {
61
- if (!k && D.length) {
62
- let o = D.length / i.length, s = a === 1 ? i : i.map((e, t) => {
63
- let n = Math.floor(t * o);
64
- if (D[n]) {
65
- let t = D[n];
66
+ if (newPoints && newPoints.length > 0) {
67
+ animationStopped = false;
68
+ isAnimating.value = true;
69
+ const animation = animate(0, 1, {
70
+ ...props.transition,
71
+ onUpdate(t) {
72
+ if (animationStopped) return;
73
+ if (prevPoints.length) {
74
+ const prevPointsDiffFactor = prevPoints.length / newPoints.length;
75
+ const stepPoints = t === 1 ? newPoints : newPoints.map((entry, index) => {
76
+ const prevPointIndex = Math.floor(index * prevPointsDiffFactor);
77
+ if (prevPoints[prevPointIndex]) {
78
+ const prev = prevPoints[prevPointIndex];
66
79
  return {
67
- ...e,
68
- x: r(t.x, e.x, a),
69
- y: r(t.y, e.y, a)
80
+ ...entry,
81
+ x: interpolate(prev.x, entry.x, t),
82
+ y: interpolate(prev.y, entry.y, t)
70
83
  };
71
84
  }
72
- return e;
73
- }), c;
74
- c = n(b.value?.baseLine) ? r(O, b.value?.baseLine, a) : t(b.value?.baseLine) || e(b.value?.baseLine) ? r(O, 0, a) : b?.value.baseLine.map((e, t) => {
75
- let n = Math.floor(t * o);
76
- if (Array.isArray(O) && O[n]) {
77
- let t = O[n];
85
+ return entry;
86
+ });
87
+ let stepBaseLine;
88
+ if (isNumber(areaData.value?.baseLine)) stepBaseLine = interpolate(prevBaseLine, areaData.value?.baseLine, t);
89
+ else if (isNullish(areaData.value?.baseLine) || isNan(areaData.value?.baseLine)) stepBaseLine = interpolate(prevBaseLine, 0, t);
90
+ else stepBaseLine = areaData?.value.baseLine.map((entry, index) => {
91
+ const prevPointIndex = Math.floor(index * prevPointsDiffFactor);
92
+ if (Array.isArray(prevBaseLine) && prevBaseLine[prevPointIndex]) {
93
+ const prev = prevBaseLine[prevPointIndex];
78
94
  return {
79
- ...e,
80
- x: r(t.x, e.x, a),
81
- y: r(t.y, e.y, a)
95
+ ...entry,
96
+ x: interpolate(prev.x, entry.x, t),
97
+ y: interpolate(prev.y, entry.y, t)
82
98
  };
83
99
  }
84
- return e;
85
- }), T.value = s, E.value = c;
100
+ return entry;
101
+ });
102
+ currentPoints.value = stepPoints;
103
+ currentBaseLine.value = stepBaseLine;
86
104
  }
87
105
  },
88
106
  onPlay() {
89
- x.onAnimationStart?.();
107
+ props.onAnimationStart?.();
90
108
  },
91
109
  onComplete() {
92
- S.value = !1, x.onAnimationEnd?.();
110
+ isAnimating.value = false;
111
+ props.onAnimationEnd?.();
93
112
  }
94
113
  });
95
- o(() => {
96
- k = !0, a.stop(), D = T.value, O = E.value;
114
+ onCleanup(() => {
115
+ animationStopped = true;
116
+ animation.stop();
117
+ prevPoints = currentPoints.value;
118
+ prevBaseLine = currentBaseLine.value;
97
119
  });
98
- } else S.value = !1, T.value = i || [], E.value = b.value?.baseLine || [], D = T.value, O = E.value;
99
- }, { immediate: !0 }), () => {
100
- let e = {
101
- ...y,
102
- fill: x.fill,
103
- "fill-opacity": x.fillOpacity,
104
- height: w.value.height,
105
- width: w.value.width,
106
- "stroke-width": x.strokeWidth
107
- }, t = b.value?.isRange, n = !S.value && x.label, r = typeof x.label == "object" ? x.label : {};
108
- return f(d, null, [
109
- T.value && T.value.length > 1 && f(c, { "clip-path": x.needClip ? `url(#clipPath-${l.value})` : void 0 }, { default: () => [
110
- f(i, m(e, {
111
- points: T.value,
112
- connectNulls: x.connectNulls,
113
- type: x.type,
114
- layout: p.value,
115
- baseLine: E.value,
116
- stroke: "none",
117
- class: "v-charts-area-area"
120
+ } else {
121
+ isAnimating.value = false;
122
+ currentPoints.value = newPoints || [];
123
+ currentBaseLine.value = areaData.value?.baseLine || [];
124
+ prevPoints = currentPoints.value;
125
+ prevBaseLine = currentBaseLine.value;
126
+ }
127
+ }, { immediate: true });
128
+ return () => {
129
+ const curveAttrs = {
130
+ ...attrs,
131
+ "fill": props.fill,
132
+ "fill-opacity": props.fillOpacity,
133
+ "height": offset.value.height,
134
+ "width": offset.value.width,
135
+ "stroke-width": props.strokeWidth
136
+ };
137
+ const isRange = areaData.value?.isRange;
138
+ const showLabels = !isAnimating.value && props.label;
139
+ const labelProps = typeof props.label === "object" ? props.label : {};
140
+ return createVNode(Fragment, null, [
141
+ currentPoints.value && currentPoints.value.length > 1 && createVNode(Layer, { "clip-path": props.needClip ? `url(#clipPath-${clipPathId.value})` : void 0 }, { default: () => [
142
+ createVNode(Curve, mergeProps(curveAttrs, {
143
+ "points": currentPoints.value,
144
+ "connectNulls": props.connectNulls,
145
+ "type": props.type,
146
+ "layout": layout.value,
147
+ "baseLine": currentBaseLine.value,
148
+ "stroke": "none",
149
+ "class": "v-charts-area-area"
118
150
  }), null),
119
- y.stroke !== "none" && f(i, m(e, {
120
- layout: p.value,
121
- type: x.type,
122
- connectNulls: x.connectNulls,
123
- fill: "none",
124
- points: T.value,
125
- stroke: x.stroke,
126
- class: "v-charts-area-curve"
151
+ attrs.stroke !== "none" && createVNode(Curve, mergeProps(curveAttrs, {
152
+ "layout": layout.value,
153
+ "type": props.type,
154
+ "connectNulls": props.connectNulls,
155
+ "fill": "none",
156
+ "points": currentPoints.value,
157
+ "stroke": props.stroke,
158
+ "class": "v-charts-area-curve"
127
159
  }), null),
128
- y.stroke !== "none" && t && f(i, m(e, {
129
- class: "v-charts-area-curve",
130
- layout: p.value,
131
- type: x.type,
132
- connectNulls: x.connectNulls,
133
- fill: "none",
134
- points: E.value,
135
- stroke: x.stroke
160
+ attrs.stroke !== "none" && isRange && createVNode(Curve, mergeProps(curveAttrs, {
161
+ "class": "v-charts-area-curve",
162
+ "layout": layout.value,
163
+ "type": props.type,
164
+ "connectNulls": props.connectNulls,
165
+ "fill": "none",
166
+ "points": currentBaseLine.value,
167
+ "stroke": props.stroke
136
168
  }), null)
137
169
  ] }),
138
- f(v, { points: T.value }, null),
139
- n && f(u, m(r, {
140
- data: b.value?.points ?? [],
141
- dataKey: x.dataKey
170
+ createVNode(Dots, { "points": currentPoints.value }, null),
171
+ showLabels && createVNode(LabelList, mergeProps(labelProps, {
172
+ "data": areaData.value?.points ?? [],
173
+ "dataKey": props.dataKey
142
174
  }), null)
143
175
  ]);
144
176
  };
145
177
  }
146
178
  });
147
- function b(e, t) {
148
- return e == null || !e.length ? !1 : t ? !0 : e.length === 1;
179
+ function shouldRenderDots(points, dot) {
180
+ if (points == null || !points.length) return false;
181
+ if (dot) return true;
182
+ return points.length === 1;
149
183
  }
150
184
  //#endregion
151
- export { y as StaticArea };
185
+ export { StaticArea };
@@ -1,57 +1,81 @@
1
- import { uniqueId as e } from "../../../utils/data-utils.mjs";
2
- import { useIsPanorama as t } from "../../../context/PanoramaContextProvider.mjs";
3
- import { isClipDot as n } from "../../../utils/chart.mjs";
4
- import { useAppSelector as r } from "../../../state/hooks.mjs";
5
- import { useChartLayout as i } from "../../../context/chartLayoutContext.mjs";
6
- import { useChartName as a } from "../../../state/selectors/selectors.mjs";
7
- import { selectArea as o } from "../../../state/selectors/areaSelectors.mjs";
8
- import { filterProps as s } from "../../../utils/VueUtils.mjs";
9
- import { computed as c, inject as l, provide as u, ref as d, watch as f } from "vue";
1
+ import { uniqueId } from "../../../utils/data-utils.mjs";
2
+ import { useIsPanorama } from "../../../context/PanoramaContextProvider.mjs";
3
+ import { isClipDot } from "../../../utils/chart.mjs";
4
+ import { useAppSelector } from "../../../state/hooks.mjs";
5
+ import { useChartLayout } from "../../../context/chartLayoutContext.mjs";
6
+ import { useChartName } from "../../../state/selectors/selectors.mjs";
7
+ import { selectArea } from "../../../state/selectors/areaSelectors.mjs";
8
+ import { useIsAnimating } from "../../../hooks/useIsAnimating.mjs";
9
+ import { filterProps } from "../../../utils/VueUtils.mjs";
10
+ import { computed, inject, provide, ref, watch } from "vue";
10
11
  //#region src/cartesian/area/hooks/useArea.ts
11
- var p = Symbol("AreaContext");
12
- function m(e) {
13
- u(p, e);
12
+ var AreaContextKey = Symbol("AreaContext");
13
+ function provideAreaContext(context) {
14
+ provide(AreaContextKey, context);
14
15
  }
15
- function h() {
16
- let e = l(p);
17
- if (!e) throw Error("useAreaContext must be used within Area component");
18
- return e;
16
+ function useAreaContext() {
17
+ const context = inject(AreaContextKey);
18
+ if (!context) throw new Error("useAreaContext must be used within Area component");
19
+ return context;
19
20
  }
20
- function g(l, u = {}, p) {
21
- let h = i(), g = a(), _ = e("v-charts-area-"), v = c(() => l.id || _), y = t(), b = d(l.isAnimationActive), x = c(() => (h.value === "horizontal" || h.value === "vertical") && (g.value === "AreaChart" || g.value === "ComposedChart") && !l.hide), S = c(() => ({
22
- baseValue: l.baseValue,
23
- stackId: l.stackId,
24
- connectNulls: l.connectNulls,
25
- data: l.data,
26
- dataKey: l.dataKey
27
- })), C = r((e) => o(e, l.xAxisId, l.yAxisId, y, S.value)), w = d(!0);
28
- f(() => l.hide, (e) => {
29
- e || (w.value = !0);
21
+ function useArea(props, attrs = {}, dotSlot) {
22
+ const layout = useChartLayout();
23
+ const chartName = useChartName();
24
+ const localId = uniqueId("v-charts-area-");
25
+ const clipPathId = computed(() => props.id || localId);
26
+ const isPanorama = useIsPanorama();
27
+ /**
28
+ * is Area animating
29
+ */
30
+ const isAnimating = useIsAnimating(() => props.isAnimationActive);
31
+ /**
32
+ * render only when layout is horizontal or vertical and chartName is AreaChart or ComposedChart
33
+ */
34
+ const shouldRender = computed(() => (layout.value === "horizontal" || layout.value === "vertical") && (chartName.value === "AreaChart" || chartName.value === "ComposedChart") && !props.hide);
35
+ const areaSettings = computed(() => ({
36
+ baseValue: props.baseValue,
37
+ stackId: props.stackId,
38
+ connectNulls: props.connectNulls,
39
+ data: props.data,
40
+ dataKey: props.dataKey
41
+ }));
42
+ const areaData = useAppSelector((state) => selectArea(state, props.xAxisId, props.yAxisId, isPanorama, areaSettings.value));
43
+ const isClipRectAnimating = ref(true);
44
+ watch(() => props.hide, (v) => {
45
+ if (!v) isClipRectAnimating.value = true;
30
46
  });
31
- let T = c(() => l.isAnimationActive && C.value?.points?.length && w.value), E = l.dot, D = n(E), { r: O = 3, strokeWidth: k = 2 } = s(E, !1) ?? {
47
+ const shouldShowAnimation = computed(() => {
48
+ return props.isAnimationActive && areaData.value?.points?.length && isClipRectAnimating.value;
49
+ });
50
+ const dot = props.dot;
51
+ const clipDot = isClipDot(dot);
52
+ const { r = 3, strokeWidth = 2 } = filterProps(dot, false) ?? {
32
53
  r: 3,
33
54
  strokeWidth: 2
34
- }, A = O * 2 + k, j = {
35
- clipPathId: v,
36
- layout: h,
37
- points: c(() => C.value?.points),
38
- props: l,
39
- attrs: u,
40
- dot: E,
41
- clipDot: D,
42
- dotSize: A,
43
- dotSlot: p,
44
- areaData: C,
45
- isAnimating: b,
46
- isClipRectAnimating: w
47
55
  };
48
- return m(j), {
49
- shouldRender: x,
50
- areaData: C,
51
- points: j.points,
52
- clipPathId: v,
53
- shouldShowAnimation: T
56
+ const dotSize = r * 2 + strokeWidth;
57
+ const areaContext = {
58
+ clipPathId,
59
+ layout,
60
+ points: computed(() => areaData.value?.points),
61
+ props,
62
+ attrs,
63
+ dot,
64
+ clipDot,
65
+ dotSize,
66
+ dotSlot,
67
+ areaData,
68
+ isAnimating,
69
+ isClipRectAnimating
70
+ };
71
+ provideAreaContext(areaContext);
72
+ return {
73
+ shouldRender,
74
+ areaData,
75
+ points: areaContext.points,
76
+ clipPathId,
77
+ shouldShowAnimation
54
78
  };
55
79
  }
56
80
  //#endregion
57
- export { g as useArea, h as useAreaContext };
81
+ export { useArea, useAreaContext };