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,29 +1,29 @@
1
- import { isNumOrStr as e, isWellBehavedNumber as t } from "../../utils/validate.mjs";
2
- import { useIsPanorama as n } from "../../context/PanoramaContextProvider.mjs";
3
- import { selectAxisScale as r } from "../../state/selectors/axisSelectors.mjs";
4
- import { useAppDispatch as i, useAppSelector as a } from "../../state/hooks.mjs";
5
- import { Layer as o } from "../../container/Layer.mjs";
6
- import { Label as s } from "../../components/label/Label.mjs";
7
- import { Rectangle as c } from "../../shape/Rectangle.mjs";
8
- import { addArea as l, removeArea as u } from "../../state/referenceElementsSlice.mjs";
9
- import { useClipPathId as d } from "../../chart/provideClipPathId.mjs";
10
- import { computed as f, createVNode as p, defineComponent as m, mergeProps as h, onMounted as g, onUnmounted as _, reactive as v } from "vue";
1
+ import { isNumOrStr, isWellBehavedNumber } from "../../utils/validate.mjs";
2
+ import { useIsPanorama } from "../../context/PanoramaContextProvider.mjs";
3
+ import { selectAxisScale } from "../../state/selectors/axisSelectors.mjs";
4
+ import { useAppDispatch, useAppSelector } from "../../state/hooks.mjs";
5
+ import { Layer } from "../../container/Layer.mjs";
6
+ import { Label } from "../../components/label/Label.mjs";
7
+ import { Rectangle } from "../../shape/Rectangle.mjs";
8
+ import { addArea, removeArea } from "../../state/referenceElementsSlice.mjs";
9
+ import { useClipPathId } from "../../chart/provideClipPathId.mjs";
10
+ import { computed, createVNode, defineComponent, mergeProps, onMounted, onUnmounted, reactive } from "vue";
11
11
  //#region src/cartesian/reference-area/ReferenceArea.tsx
12
- function y(e, n, r) {
13
- let i = e(n);
14
- if (!t(i)) return;
15
- let a = e.bandwidth?.() ?? 0;
16
- return r === "start" ? i : i + a;
12
+ function scaleValue(scale, value, position) {
13
+ const coord = scale(value);
14
+ if (!isWellBehavedNumber(coord)) return void 0;
15
+ const bandwidth = scale.bandwidth?.() ?? 0;
16
+ return position === "start" ? coord : coord + bandwidth;
17
17
  }
18
- function b(e) {
19
- let t = e.range();
20
- return Math.min(t[0], t[1]);
18
+ function rangeMin(scale) {
19
+ const r = scale.range();
20
+ return Math.min(r[0], r[1]);
21
21
  }
22
- function x(e) {
23
- let t = e.range();
24
- return Math.max(t[0], t[1]);
22
+ function rangeMax(scale) {
23
+ const r = scale.range();
24
+ return Math.max(r[0], r[1]);
25
25
  }
26
- var S = /* @__PURE__ */ m({
26
+ var ReferenceArea = /* @__PURE__ */ defineComponent({
27
27
  name: "ReferenceArea",
28
28
  props: {
29
29
  x1: {
@@ -88,59 +88,76 @@ var S = /* @__PURE__ */ m({
88
88
  default: 0
89
89
  }
90
90
  },
91
- inheritAttrs: !1,
92
- setup(t, { attrs: m }) {
93
- let S = i(), C = n(), w = d(), T = v({
94
- xAxisId: t.xAxisId,
95
- yAxisId: t.yAxisId,
96
- ifOverflow: t.ifOverflow,
97
- x1: t.x1,
98
- x2: t.x2,
99
- y1: t.y1,
100
- y2: t.y2
91
+ inheritAttrs: false,
92
+ setup(props, { attrs }) {
93
+ const dispatch = useAppDispatch();
94
+ const isPanorama = useIsPanorama();
95
+ const clipPathId = useClipPathId();
96
+ const settings = reactive({
97
+ xAxisId: props.xAxisId,
98
+ yAxisId: props.yAxisId,
99
+ ifOverflow: props.ifOverflow,
100
+ x1: props.x1,
101
+ x2: props.x2,
102
+ y1: props.y1,
103
+ y2: props.y2
101
104
  });
102
- g(() => {
103
- S(l(T));
104
- }), _(() => {
105
- S(u(T));
105
+ onMounted(() => {
106
+ dispatch(addArea(settings));
106
107
  });
107
- let E = a((e) => r(e, "xAxis", t.xAxisId, C)), D = a((e) => r(e, "yAxis", t.yAxisId, C)), O = f(() => {
108
- let n = E.value, r = D.value;
109
- if (!n || !r) return null;
110
- let i = e(t.x1), a = e(t.x2), o = e(t.y1), s = e(t.y2);
111
- if (!i && !a && !o && !s) return null;
112
- let c = i ? y(n, t.x1, "start") : b(n), l = a ? y(n, t.x2, "end") : x(n), u = o ? y(r, t.y1, "start") : b(r), d = s ? y(r, t.y2, "end") : x(r);
113
- return c == null || l == null || u == null || d == null ? null : {
114
- x: Math.min(c, l),
115
- y: Math.min(u, d),
116
- width: Math.abs(l - c),
117
- height: Math.abs(d - u)
108
+ onUnmounted(() => {
109
+ dispatch(removeArea(settings));
110
+ });
111
+ const xAxisScale = useAppSelector((state) => selectAxisScale(state, "xAxis", props.xAxisId, isPanorama));
112
+ const yAxisScale = useAppSelector((state) => selectAxisScale(state, "yAxis", props.yAxisId, isPanorama));
113
+ const rect = computed(() => {
114
+ const xScale = xAxisScale.value;
115
+ const yScale = yAxisScale.value;
116
+ if (!xScale || !yScale) return null;
117
+ const hasX1 = isNumOrStr(props.x1);
118
+ const hasX2 = isNumOrStr(props.x2);
119
+ const hasY1 = isNumOrStr(props.y1);
120
+ const hasY2 = isNumOrStr(props.y2);
121
+ if (!hasX1 && !hasX2 && !hasY1 && !hasY2) return null;
122
+ const px1 = hasX1 ? scaleValue(xScale, props.x1, "start") : rangeMin(xScale);
123
+ const px2 = hasX2 ? scaleValue(xScale, props.x2, "end") : rangeMax(xScale);
124
+ const py1 = hasY1 ? scaleValue(yScale, props.y1, "start") : rangeMin(yScale);
125
+ const py2 = hasY2 ? scaleValue(yScale, props.y2, "end") : rangeMax(yScale);
126
+ if (px1 == null || px2 == null || py1 == null || py2 == null) return null;
127
+ return {
128
+ x: Math.min(px1, px2),
129
+ y: Math.min(py1, py2),
130
+ width: Math.abs(px2 - px1),
131
+ height: Math.abs(py2 - py1)
118
132
  };
119
133
  });
120
134
  return () => {
121
- let e = O.value;
122
- if (!e) return null;
123
- let n = t.ifOverflow === "hidden" ? `url(#${w})` : void 0, r = {
124
- ...m,
125
- stroke: t.stroke,
126
- "stroke-width": t.strokeWidth,
127
- fill: t.fill,
128
- "fill-opacity": t.fillOpacity
129
- }, i = t.label, a = typeof i == "object" && i ? i : {};
130
- return p(o, { class: ["v-charts-reference-area", t.className] }, { default: () => [p(c, h(r, {
131
- "clip-path": n,
132
- x: e.x,
133
- y: e.y,
134
- width: e.width,
135
- height: e.height,
136
- radius: t.radius,
137
- class: "v-charts-reference-area-rect"
138
- }), null), i != null && i !== !1 && p(s, h({
139
- viewBox: e,
140
- value: typeof i == "string" || typeof i == "number" ? i : void 0
141
- }, a), null)] });
135
+ const r = rect.value;
136
+ if (!r) return null;
137
+ const clipPath = props.ifOverflow === "hidden" ? `url(#${clipPathId})` : void 0;
138
+ const svgAttrs = {
139
+ ...attrs,
140
+ "stroke": props.stroke,
141
+ "stroke-width": props.strokeWidth,
142
+ "fill": props.fill,
143
+ "fill-opacity": props.fillOpacity
144
+ };
145
+ const labelValue = props.label;
146
+ const labelProps = typeof labelValue === "object" && labelValue !== null ? labelValue : {};
147
+ return createVNode(Layer, { "class": ["v-charts-reference-area", props.className] }, { default: () => [createVNode(Rectangle, mergeProps(svgAttrs, {
148
+ "clip-path": clipPath,
149
+ "x": r.x,
150
+ "y": r.y,
151
+ "width": r.width,
152
+ "height": r.height,
153
+ "radius": props.radius,
154
+ "class": "v-charts-reference-area-rect"
155
+ }), null), labelValue != null && labelValue !== false && createVNode(Label, mergeProps({
156
+ "viewBox": r,
157
+ "value": typeof labelValue === "string" || typeof labelValue === "number" ? labelValue : void 0
158
+ }, labelProps), null)] });
142
159
  };
143
160
  }
144
161
  });
145
162
  //#endregion
146
- export { S as ReferenceArea };
163
+ export { ReferenceArea };
@@ -1,23 +1,26 @@
1
- import { isNumOrStr as e, isWellBehavedNumber as t } from "../../utils/validate.mjs";
2
- import { useIsPanorama as n } from "../../context/PanoramaContextProvider.mjs";
3
- import { selectAxisScale as r, selectXAxisSettings as i, selectYAxisSettings as a } from "../../state/selectors/axisSelectors.mjs";
4
- import { useAppDispatch as o, useAppSelector as s } from "../../state/hooks.mjs";
5
- import { useViewBox as c } from "../../context/chartLayoutContext.mjs";
6
- import { Layer as l } from "../../container/Layer.mjs";
7
- import { Label as u } from "../../components/label/Label.mjs";
8
- import { addLine as d, removeLine as f } from "../../state/referenceElementsSlice.mjs";
9
- import { useClipPathId as p } from "../../chart/provideClipPathId.mjs";
10
- import { computed as m, createVNode as h, defineComponent as g, mergeProps as _, onMounted as v, onUnmounted as y, reactive as b } from "vue";
1
+ import { isNumOrStr, isWellBehavedNumber } from "../../utils/validate.mjs";
2
+ import { useIsPanorama } from "../../context/PanoramaContextProvider.mjs";
3
+ import { selectAxisScale, selectXAxisSettings, selectYAxisSettings } from "../../state/selectors/axisSelectors.mjs";
4
+ import { useAppDispatch, useAppSelector } from "../../state/hooks.mjs";
5
+ import { useViewBox } from "../../context/chartLayoutContext.mjs";
6
+ import { Layer } from "../../container/Layer.mjs";
7
+ import { Label } from "../../components/label/Label.mjs";
8
+ import { addLine, removeLine } from "../../state/referenceElementsSlice.mjs";
9
+ import { useClipPathId } from "../../chart/provideClipPathId.mjs";
10
+ import { computed, createVNode, defineComponent, mergeProps, onMounted, onUnmounted, reactive } from "vue";
11
11
  //#region src/cartesian/reference-line/ReferenceLine.tsx
12
- function x(e, n) {
13
- let r = e(n);
14
- if (t(r)) return r + (e.bandwidth?.() ?? 0) / 2;
12
+ function scaleCoord(scale, value) {
13
+ const coord = scale(value);
14
+ if (!isWellBehavedNumber(coord)) return;
15
+ return coord + (scale.bandwidth?.() ?? 0) / 2;
15
16
  }
16
- function S(e, t) {
17
- let n = e.range(), r = Math.min(n[0], n[1]), i = Math.max(n[0], n[1]);
18
- return t >= r && t <= i;
17
+ function isInRange(scale, coord) {
18
+ const r = scale.range();
19
+ const min = Math.min(r[0], r[1]);
20
+ const max = Math.max(r[0], r[1]);
21
+ return coord >= min && coord <= max;
19
22
  }
20
- var C = /* @__PURE__ */ g({
23
+ var ReferenceLine = /* @__PURE__ */ defineComponent({
21
24
  name: "ReferenceLine",
22
25
  props: {
23
26
  x: {
@@ -66,78 +69,97 @@ var C = /* @__PURE__ */ g({
66
69
  default: void 0
67
70
  }
68
71
  },
69
- inheritAttrs: !1,
70
- setup(g, { attrs: C }) {
71
- let w = o(), T = n(), E = p(), D = c(), O = b({
72
- xAxisId: g.xAxisId,
73
- yAxisId: g.yAxisId,
74
- ifOverflow: g.ifOverflow,
75
- x: g.x,
76
- y: g.y
72
+ inheritAttrs: false,
73
+ setup(props, { attrs }) {
74
+ const dispatch = useAppDispatch();
75
+ const isPanorama = useIsPanorama();
76
+ const clipPathId = useClipPathId();
77
+ const viewBox = useViewBox();
78
+ const settings = reactive({
79
+ xAxisId: props.xAxisId,
80
+ yAxisId: props.yAxisId,
81
+ ifOverflow: props.ifOverflow,
82
+ x: props.x,
83
+ y: props.y
77
84
  });
78
- v(() => {
79
- w(d(O));
80
- }), y(() => {
81
- w(f(O));
85
+ onMounted(() => {
86
+ dispatch(addLine(settings));
82
87
  });
83
- let k = s((e) => i(e, g.xAxisId)), A = s((e) => a(e, g.yAxisId)), j = s((e) => r(e, "xAxis", g.xAxisId, T)), M = s((e) => r(e, "yAxis", g.yAxisId, T)), N = m(() => {
84
- let t = D.value, n = j.value, r = M.value;
85
- if (!t || !n || !r) return null;
86
- if (e(g.y)) {
87
- let e = x(r, g.y);
88
- if (e == null || g.ifOverflow === "discard" && !S(r, e)) return null;
89
- let n = A.value?.orientation, i = [{
90
- x: t.x + t.width,
91
- y: e
88
+ onUnmounted(() => {
89
+ dispatch(removeLine(settings));
90
+ });
91
+ const xAxisSettings = useAppSelector((state) => selectXAxisSettings(state, props.xAxisId));
92
+ const yAxisSettings = useAppSelector((state) => selectYAxisSettings(state, props.yAxisId));
93
+ const xAxisScale = useAppSelector((state) => selectAxisScale(state, "xAxis", props.xAxisId, isPanorama));
94
+ const yAxisScale = useAppSelector((state) => selectAxisScale(state, "yAxis", props.yAxisId, isPanorama));
95
+ const endPoints = computed(() => {
96
+ const vb = viewBox.value;
97
+ const xScale = xAxisScale.value;
98
+ const yScale = yAxisScale.value;
99
+ if (!vb || !xScale || !yScale) return null;
100
+ if (isNumOrStr(props.y)) {
101
+ const coord = scaleCoord(yScale, props.y);
102
+ if (coord == null) return null;
103
+ if (props.ifOverflow === "discard" && !isInRange(yScale, coord)) return null;
104
+ const yOrientation = yAxisSettings.value?.orientation;
105
+ const points = [{
106
+ x: vb.x + vb.width,
107
+ y: coord
92
108
  }, {
93
- x: t.x,
94
- y: e
109
+ x: vb.x,
110
+ y: coord
95
111
  }];
96
- return n === "left" ? i.reverse() : i;
112
+ return yOrientation === "left" ? points.reverse() : points;
97
113
  }
98
- if (e(g.x)) {
99
- let e = x(n, g.x);
100
- if (e == null || g.ifOverflow === "discard" && !S(n, e)) return null;
101
- let r = k.value?.orientation, i = [{
102
- x: e,
103
- y: t.y + t.height
114
+ if (isNumOrStr(props.x)) {
115
+ const coord = scaleCoord(xScale, props.x);
116
+ if (coord == null) return null;
117
+ if (props.ifOverflow === "discard" && !isInRange(xScale, coord)) return null;
118
+ const xOrientation = xAxisSettings.value?.orientation;
119
+ const points = [{
120
+ x: coord,
121
+ y: vb.y + vb.height
104
122
  }, {
105
- x: e,
106
- y: t.y
123
+ x: coord,
124
+ y: vb.y
107
125
  }];
108
- return r === "top" ? i.reverse() : i;
126
+ return xOrientation === "top" ? points.reverse() : points;
109
127
  }
110
128
  return null;
111
129
  });
112
130
  return () => {
113
- let e = N.value;
114
- if (!e || e.length < 2) return null;
115
- let [n, r] = e;
116
- if (!t(n.x) || !t(n.y) || !t(r.x) || !t(r.y)) return null;
117
- let i = g.ifOverflow === "hidden" ? `url(#${E})` : void 0, a = {
118
- ...C,
119
- stroke: g.stroke,
120
- "stroke-width": g.strokeWidth,
121
- fill: g.fill
122
- }, o = {
123
- x: Math.min(n.x, r.x),
124
- y: Math.min(n.y, r.y),
125
- width: Math.abs(r.x - n.x),
126
- height: Math.abs(r.y - n.y)
127
- }, s = g.label, c = typeof s == "object" && s ? s : {};
128
- return h(l, { class: ["v-charts-reference-line", g.className] }, { default: () => [h("line", _(a, {
129
- "clip-path": i,
130
- x1: n.x,
131
- y1: n.y,
132
- x2: r.x,
133
- y2: r.y,
134
- class: "v-charts-reference-line-line"
135
- }), null), s != null && s !== !1 && h(u, _({
136
- viewBox: o,
137
- value: typeof s == "string" || typeof s == "number" ? s : void 0
138
- }, c), null)] });
131
+ const pts = endPoints.value;
132
+ if (!pts || pts.length < 2) return null;
133
+ const [p1, p2] = pts;
134
+ if (!isWellBehavedNumber(p1.x) || !isWellBehavedNumber(p1.y) || !isWellBehavedNumber(p2.x) || !isWellBehavedNumber(p2.y)) return null;
135
+ const clipPath = props.ifOverflow === "hidden" ? `url(#${clipPathId})` : void 0;
136
+ const svgAttrs = {
137
+ ...attrs,
138
+ stroke: props.stroke,
139
+ "stroke-width": props.strokeWidth,
140
+ fill: props.fill
141
+ };
142
+ const labelViewBox = {
143
+ x: Math.min(p1.x, p2.x),
144
+ y: Math.min(p1.y, p2.y),
145
+ width: Math.abs(p2.x - p1.x),
146
+ height: Math.abs(p2.y - p1.y)
147
+ };
148
+ const labelValue = props.label;
149
+ const labelProps = typeof labelValue === "object" && labelValue !== null ? labelValue : {};
150
+ return createVNode(Layer, { "class": ["v-charts-reference-line", props.className] }, { default: () => [createVNode("line", mergeProps(svgAttrs, {
151
+ "clip-path": clipPath,
152
+ "x1": p1.x,
153
+ "y1": p1.y,
154
+ "x2": p2.x,
155
+ "y2": p2.y,
156
+ "class": "v-charts-reference-line-line"
157
+ }), null), labelValue != null && labelValue !== false && createVNode(Label, mergeProps({
158
+ "viewBox": labelViewBox,
159
+ "value": typeof labelValue === "string" || typeof labelValue === "number" ? labelValue : void 0
160
+ }, labelProps), null)] });
139
161
  };
140
162
  }
141
163
  });
142
164
  //#endregion
143
- export { C as ReferenceLine };
165
+ export { ReferenceLine };