vccs 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/README.md +151 -0
  2. package/dist/animation/Animate.d.ts +1 -1
  3. package/dist/cartesian/area/type.d.ts +3 -3
  4. package/dist/cartesian/bar/type.d.ts +1 -13
  5. package/dist/cartesian/brush/components/Slide.d.ts +1 -1
  6. package/dist/cartesian/brush/components/TravellerLayer.d.ts +1 -1
  7. package/dist/cartesian/brush/type.d.ts +2 -1
  8. package/dist/cartesian/cartesian-axis/CartesianAxis.d.ts +2 -1
  9. package/dist/cartesian/funnel/Funnel.d.ts +2 -0
  10. package/dist/cartesian/funnel/index.d.ts +2 -0
  11. package/dist/cartesian/funnel/type.d.ts +74 -6
  12. package/dist/cartesian/index.d.ts +2 -0
  13. package/dist/cartesian/line/Line.d.ts +7 -13
  14. package/dist/cartesian/line/type.d.ts +4 -17
  15. package/dist/cartesian/reference-area/ReferenceArea.d.ts +16 -16
  16. package/dist/cartesian/reference-dot/ReferenceDot.d.ts +143 -0
  17. package/dist/cartesian/reference-dot/index.d.ts +2 -0
  18. package/dist/cartesian/reference-line/ReferenceLine.d.ts +8 -8
  19. package/dist/cartesian/scatter/Scatter.d.ts +1 -1
  20. package/dist/chart/FunnelChart.d.ts +1 -0
  21. package/dist/chart/RechartsWrapper.d.ts +7 -3
  22. package/dist/chart/Surface.d.ts +2 -1
  23. package/dist/chart/Treemap.d.ts +237 -0
  24. package/dist/chart/generateCategoricalChart.d.ts +2 -1
  25. package/dist/chart/index.d.ts +2 -0
  26. package/dist/chart/treemapUtils.d.ts +22 -0
  27. package/dist/components/Customized.d.ts +23 -0
  28. package/dist/components/Text.d.ts +4 -4
  29. package/dist/components/Tooltip.d.ts +1 -1
  30. package/dist/components/index.d.ts +2 -0
  31. package/dist/components/label/Label.d.ts +3 -3
  32. package/dist/components/label/types.d.ts +1 -1
  33. package/dist/container/Surface.d.ts +3 -2
  34. package/dist/es/animation/Animate.mjs +48 -22
  35. package/dist/es/cartesian/GraphicalItemClipPath.mjs +16 -15
  36. package/dist/es/cartesian/area/ActivePoints.mjs +44 -40
  37. package/dist/es/cartesian/area/Area.mjs +42 -31
  38. package/dist/es/cartesian/area/ClipRect.mjs +79 -58
  39. package/dist/es/cartesian/area/RenderArea.mjs +142 -108
  40. package/dist/es/cartesian/area/hooks/useArea.mjs +71 -47
  41. package/dist/es/cartesian/area/type.mjs +13 -15
  42. package/dist/es/cartesian/area/utils.mjs +69 -49
  43. package/dist/es/cartesian/axis/XAxis.mjs +87 -73
  44. package/dist/es/cartesian/axis/YAxis.mjs +67 -56
  45. package/dist/es/cartesian/bar/Bar.mjs +78 -71
  46. package/dist/es/cartesian/bar/components/BarBackground.mjs +22 -19
  47. package/dist/es/cartesian/bar/components/BarRectangles.mjs +117 -80
  48. package/dist/es/cartesian/bar/hooks/useBar.mjs +49 -37
  49. package/dist/es/cartesian/bar/type.mjs +11 -25
  50. package/dist/es/cartesian/bar/utils.mjs +97 -70
  51. package/dist/es/cartesian/cartesian-axis/CartesianAxis.mjs +165 -115
  52. package/dist/es/cartesian/cartesian-grid/Background.mjs +19 -16
  53. package/dist/es/cartesian/cartesian-grid/CartesianGrid.mjs +116 -97
  54. package/dist/es/cartesian/cartesian-grid/HorizontalGridLines.mjs +24 -23
  55. package/dist/es/cartesian/cartesian-grid/HorizontalStripes.mjs +24 -24
  56. package/dist/es/cartesian/cartesian-grid/VerticalGridLines.mjs +23 -22
  57. package/dist/es/cartesian/cartesian-grid/VerticalStripes.mjs +24 -24
  58. package/dist/es/cartesian/cartesian-grid/const.mjs +317 -10
  59. package/dist/es/cartesian/cartesian-grid/utils.mjs +18 -13
  60. package/dist/es/cartesian/error-bar/ErrorBar.mjs +111 -83
  61. package/dist/es/cartesian/error-bar/ErrorBarContext.mjs +13 -12
  62. package/dist/es/cartesian/funnel/Funnel.mjs +162 -0
  63. package/dist/es/cartesian/funnel/type.mjs +78 -0
  64. package/dist/es/cartesian/funnel/utils.mjs +102 -0
  65. package/dist/es/cartesian/line/ActivePoints.mjs +45 -41
  66. package/dist/es/cartesian/line/Line.mjs +41 -37
  67. package/dist/es/cartesian/line/StaticLine.mjs +191 -122
  68. package/dist/es/cartesian/line/hooks/useLine.mjs +60 -44
  69. package/dist/es/cartesian/line/type.mjs +13 -18
  70. package/dist/es/cartesian/line/utils.mjs +27 -26
  71. package/dist/es/cartesian/reference-area/ReferenceArea.mjs +79 -78
  72. package/dist/es/cartesian/reference-dot/ReferenceDot.mjs +134 -0
  73. package/dist/es/cartesian/reference-line/ReferenceLine.mjs +93 -84
  74. package/dist/es/cartesian/scatter/Scatter.mjs +168 -140
  75. package/dist/es/cartesian/scatter/hooks/useScatter.mjs +18 -14
  76. package/dist/es/cartesian/useNeedsClip.mjs +18 -9
  77. package/dist/es/cartesian/utils/get-ticks.mjs +103 -68
  78. package/dist/es/cartesian/z-axis/ZAxis.mjs +30 -28
  79. package/dist/es/chart/AreaChart.mjs +5 -5
  80. package/dist/es/chart/BarChart.mjs +5 -5
  81. package/dist/es/chart/ComposedChart.mjs +5 -5
  82. package/dist/es/chart/FunnelChart.mjs +11 -0
  83. package/dist/es/chart/LegendPortalContext.mjs +3 -3
  84. package/dist/es/chart/LineChart.mjs +5 -5
  85. package/dist/es/chart/PieChart.mjs +5 -5
  86. package/dist/es/chart/RadarChart.mjs +5 -5
  87. package/dist/es/chart/RadialBarChart.mjs +5 -5
  88. package/dist/es/chart/RechartsWrapper.mjs +113 -89
  89. package/dist/es/chart/ScatterChart.mjs +5 -5
  90. package/dist/es/chart/Surface.mjs +3 -3
  91. package/dist/es/chart/Surface.vue_vue_type_script_setup_true_lang.mjs +51 -45
  92. package/dist/es/chart/TooltipPortalContext.mjs +3 -3
  93. package/dist/es/chart/Treemap.mjs +379 -0
  94. package/dist/es/chart/const.mjs +2 -2
  95. package/dist/es/chart/generateCategoricalChart.mjs +99 -89
  96. package/dist/es/chart/provideClipPathId.mjs +12 -7
  97. package/dist/es/chart/treemapUtils.mjs +32 -0
  98. package/dist/es/components/Cell.mjs +16 -4
  99. package/dist/es/components/Customized.mjs +43 -0
  100. package/dist/es/components/Text.mjs +3 -3
  101. package/dist/es/components/Text.vue_vue_type_script_setup_true_lang.mjs +106 -69
  102. package/dist/es/components/Tooltip.mjs +274 -199
  103. package/dist/es/components/label/Label.mjs +30 -26
  104. package/dist/es/components/label/LabelList.mjs +45 -39
  105. package/dist/es/components/label/types.mjs +10 -6
  106. package/dist/es/components/label/utils.mjs +194 -162
  107. package/dist/es/components/legend/Legend.mjs +82 -71
  108. package/dist/es/components/legend/LegendSymbol.mjs +40 -38
  109. package/dist/es/components/legend/hooks/useLegend.mjs +71 -46
  110. package/dist/es/components/legend/hooks/useLegendContent.mjs +52 -31
  111. package/dist/es/components/legend/type.mjs +2 -2
  112. package/dist/es/components/legend/utils.mjs +19 -11
  113. package/dist/es/components/utils.mjs +35 -22
  114. package/dist/es/container/ClipPath.mjs +14 -14
  115. package/dist/es/container/Layer.mjs +9 -7
  116. package/dist/es/container/ResponsiveContainer.mjs +3 -3
  117. package/dist/es/container/ResponsiveContainer.vue_vue_type_script_setup_true_lang.mjs +109 -77
  118. package/dist/es/container/Surface.mjs +25 -23
  119. package/dist/es/container/useSizeContext.mjs +3 -3
  120. package/dist/es/context/ChartDataContextProvider.mjs +19 -13
  121. package/dist/es/context/PanoramaContextProvider.mjs +15 -10
  122. package/dist/es/context/accessibilityContext.mjs +3 -3
  123. package/dist/es/context/cartesianLabelListContext.mjs +3 -3
  124. package/dist/es/context/chartLayoutContext.mjs +33 -30
  125. package/dist/es/context/cursorLayerContext.mjs +3 -3
  126. package/dist/es/context/graphicalLayerContext.mjs +3 -3
  127. package/dist/es/context/labelLayerContext.mjs +3 -3
  128. package/dist/es/context/polarLabelViewBoxContext.mjs +5 -5
  129. package/dist/es/context/useTooltipAxis.mjs +14 -12
  130. package/dist/es/events/useChartSynchronisation.mjs +91 -66
  131. package/dist/es/hooks/publicHooks.mjs +207 -0
  132. package/dist/es/hooks/useIsAnimating.mjs +28 -0
  133. package/dist/es/hooks/useSetupGraphicalItem.mjs +52 -43
  134. package/dist/es/index.mjs +54 -42
  135. package/dist/es/polar/pie/Pie.mjs +131 -115
  136. package/dist/es/polar/pie/type.mjs +8 -10
  137. package/dist/es/polar/radar/PolarAngleAxis.mjs +103 -84
  138. package/dist/es/polar/radar/PolarGrid.mjs +72 -59
  139. package/dist/es/polar/radar/PolarRadiusAxis.mjs +90 -65
  140. package/dist/es/polar/radar/Radar.mjs +181 -145
  141. package/dist/es/polar/radial-bar/RadialBar.mjs +161 -140
  142. package/dist/es/polar/radial-bar/type.mjs +9 -9
  143. package/dist/es/shape/Cross.mjs +11 -10
  144. package/dist/es/shape/Curve.mjs +71 -44
  145. package/dist/es/shape/Dot.mjs +12 -11
  146. package/dist/es/shape/Polygon.mjs +19 -0
  147. package/dist/es/shape/Rectangle.mjs +41 -30
  148. package/dist/es/shape/Sector.mjs +105 -79
  149. package/dist/es/shape/Symbols.mjs +45 -34
  150. package/dist/es/shape/Trapezoid.mjs +50 -0
  151. package/dist/es/state/ReportChartProps.mjs +23 -24
  152. package/dist/es/state/ReportMainChartProps.mjs +26 -21
  153. package/dist/es/state/ReportPolarOptions.mjs +23 -22
  154. package/dist/es/state/SetGraphicalItem.mjs +42 -27
  155. package/dist/es/state/SetLegendPayload.mjs +17 -13
  156. package/dist/es/state/SetTooltipEntrySettings.mjs +14 -12
  157. package/dist/es/state/brushSlice.mjs +12 -8
  158. package/dist/es/state/cartesianAxisSlice.mjs +23 -17
  159. package/dist/es/state/chartDataSlice.mjs +18 -13
  160. package/dist/es/state/externalEventsMiddleware.mjs +25 -15
  161. package/dist/es/state/graphicalItemsSlice.mjs +29 -25
  162. package/dist/es/state/hooks.mjs +24 -3
  163. package/dist/es/state/keyboardEventsMiddleware.mjs +50 -42
  164. package/dist/es/state/layoutSlice.mjs +18 -12
  165. package/dist/es/state/legendSlice.mjs +19 -14
  166. package/dist/es/state/mouseEventsMiddleware.mjs +31 -24
  167. package/dist/es/state/optionsSlice.mjs +14 -11
  168. package/dist/es/state/polarAxisSlice.mjs +15 -13
  169. package/dist/es/state/polarOptionsSlice.mjs +8 -6
  170. package/dist/es/state/reduxDevtoolsJsonStringifyReplacer.mjs +5 -3
  171. package/dist/es/state/referenceElementsSlice.mjs +21 -19
  172. package/dist/es/state/rootPropsSlice.mjs +20 -9
  173. package/dist/es/state/selectors/areaSelectors.mjs +65 -55
  174. package/dist/es/state/selectors/axisSelectors.mjs +784 -569
  175. package/dist/es/state/selectors/barSelectors.mjs +225 -162
  176. package/dist/es/state/selectors/brushSelectors.mjs +15 -14
  177. package/dist/es/state/selectors/combiners/combineActiveLabel.mjs +6 -5
  178. package/dist/es/state/selectors/combiners/combineActiveTooltipIndex.mjs +36 -27
  179. package/dist/es/state/selectors/combiners/combineAxisRangeWithReverse.mjs +5 -3
  180. package/dist/es/state/selectors/combiners/combineCoordinateForDefaultIndex.mjs +13 -11
  181. package/dist/es/state/selectors/combiners/combineTooltipInteractionState.mjs +26 -21
  182. package/dist/es/state/selectors/combiners/combineTooltipPayloadConfigurations.mjs +10 -6
  183. package/dist/es/state/selectors/common.mjs +2 -2
  184. package/dist/es/state/selectors/containerSelectors.mjs +5 -2
  185. package/dist/es/state/selectors/dataSelectors.mjs +28 -9
  186. package/dist/es/state/selectors/funnelSelectors.mjs +38 -0
  187. package/dist/es/state/selectors/legendSelectors.mjs +7 -6
  188. package/dist/es/state/selectors/lineSelectors.mjs +54 -47
  189. package/dist/es/state/selectors/pickAxisId.mjs +2 -2
  190. package/dist/es/state/selectors/pickAxisType.mjs +2 -2
  191. package/dist/es/state/selectors/pieSelectors.mjs +116 -81
  192. package/dist/es/state/selectors/polarAxisSelectors.mjs +113 -94
  193. package/dist/es/state/selectors/polarGridSelectors.mjs +13 -11
  194. package/dist/es/state/selectors/polarScaleSelectors.mjs +49 -46
  195. package/dist/es/state/selectors/polarSelectors.mjs +79 -62
  196. package/dist/es/state/selectors/radarSelectors.mjs +111 -91
  197. package/dist/es/state/selectors/radialBarSelectors.mjs +230 -183
  198. package/dist/es/state/selectors/rootPropsSelectors.mjs +11 -5
  199. package/dist/es/state/selectors/scatterSelectors.mjs +111 -95
  200. package/dist/es/state/selectors/selectActivePropsFromChartPointer.mjs +19 -17
  201. package/dist/es/state/selectors/selectAllAxes.mjs +8 -3
  202. package/dist/es/state/selectors/selectChartOffset.mjs +59 -50
  203. package/dist/es/state/selectors/selectChartOffsetInternal.mjs +55 -44
  204. package/dist/es/state/selectors/selectTooltipEventType.mjs +15 -14
  205. package/dist/es/state/selectors/selectTooltipPayloadSearcher.mjs +3 -3
  206. package/dist/es/state/selectors/selectTooltipSettings.mjs +2 -2
  207. package/dist/es/state/selectors/selectTooltipState.mjs +2 -2
  208. package/dist/es/state/selectors/selectors.mjs +94 -75
  209. package/dist/es/state/selectors/tooltipSelectors.mjs +253 -204
  210. package/dist/es/state/selectors/touchSelectors.mjs +17 -14
  211. package/dist/es/state/store.mjs +46 -46
  212. package/dist/es/state/tooltipSlice.mjs +64 -37
  213. package/dist/es/state/touchEventsMiddleware.mjs +35 -29
  214. package/dist/es/state/utils/useReportScale.mjs +16 -13
  215. package/dist/es/synchronisation/syncSelectors.mjs +3 -3
  216. package/dist/es/synchronisation/useChartSynchronisation.mjs +33 -19
  217. package/dist/es/types/common.mjs +12 -0
  218. package/dist/es/types/event.mjs +164 -2
  219. package/dist/es/utils/ReduceCSSCalc.mjs +81 -49
  220. package/dist/es/utils/VueUtils.mjs +35 -14
  221. package/dist/es/utils/attrs.mjs +43 -26
  222. package/dist/es/utils/cartesian.mjs +47 -15
  223. package/dist/es/utils/cell.mjs +28 -0
  224. package/dist/es/utils/chart.mjs +298 -197
  225. package/dist/es/utils/const.mjs +30 -2
  226. package/dist/es/utils/createCategoricalInverse.mjs +46 -0
  227. package/dist/es/utils/createContext.mjs +28 -9
  228. package/dist/es/utils/data-utils.mjs +9 -8
  229. package/dist/es/utils/data.mjs +35 -21
  230. package/dist/es/utils/events.mjs +5 -3
  231. package/dist/es/utils/getLinearRegression.mjs +28 -11
  232. package/dist/es/utils/grid.mjs +20 -5
  233. package/dist/es/utils/isDomainSpecifiedByUser.mjs +105 -54
  234. package/dist/es/utils/legend.mjs +13 -12
  235. package/dist/es/utils/log.mjs +10 -7
  236. package/dist/es/utils/payload/getUniqPayload.mjs +6 -4
  237. package/dist/es/utils/polar.mjs +37 -30
  238. package/dist/es/utils/props.mjs +16 -10
  239. package/dist/es/utils/resolveDefaultProps.mjs +23 -4
  240. package/dist/es/utils/scale/getNiceTickValues.mjs +127 -49
  241. package/dist/es/utils/scale/utils/arithmetic.mjs +49 -19
  242. package/dist/es/utils/scale/utils/utils.mjs +43 -24
  243. package/dist/es/utils/scale.mjs +46 -0
  244. package/dist/es/utils/style.mjs +24 -13
  245. package/dist/es/utils/tick.mjs +34 -23
  246. package/dist/es/utils/tooltip/translate.mjs +63 -49
  247. package/dist/es/utils/validate.mjs +40 -29
  248. package/dist/hooks/publicHooks.d.ts +143 -0
  249. package/dist/hooks/useIsAnimating.d.ts +14 -0
  250. package/dist/index.d.ts +1 -0
  251. package/dist/polar/pie/type.d.ts +2 -2
  252. package/dist/polar/radar/Radar.d.ts +4 -4
  253. package/dist/shape/Curve.d.ts +2 -1
  254. package/dist/shape/Polygon.d.ts +9 -0
  255. package/dist/shape/Rectangle.d.ts +0 -4
  256. package/dist/shape/Sector.d.ts +2 -2
  257. package/dist/shape/Symbols.d.ts +2 -1
  258. package/dist/shape/Trapezoid.d.ts +30 -0
  259. package/dist/shape/index.d.ts +2 -0
  260. package/dist/shape/types.d.ts +4 -5
  261. package/dist/state/ReportChartProps.d.ts +3 -3
  262. package/dist/state/graphicalItemsSlice.d.ts +1 -1
  263. package/dist/state/rootPropsSlice.d.ts +2 -2
  264. package/dist/state/selectors/axisSelectors.d.ts +5 -0
  265. package/dist/types/axis.d.ts +2 -2
  266. package/dist/types/bar.d.ts +2 -6
  267. package/dist/types/categorical.d.ts +2 -2
  268. package/dist/types/common.d.ts +7 -1
  269. package/dist/types/tooltip.d.ts +2 -2
  270. package/dist/utils/cell.d.ts +11 -0
  271. package/dist/utils/createCategoricalInverse.d.ts +16 -0
  272. package/dist/utils/scale.d.ts +23 -0
  273. package/package.json +2 -1
@@ -1,36 +1,40 @@
1
- import { isNullish as e } from "../../utils/validate.mjs";
2
- import { useViewBox as t } from "../../context/chartLayoutContext.mjs";
3
- import { LabelVueProps as n } from "./types.mjs";
4
- import { usePolarLabelViewBox as r } from "../../context/polarLabelViewBoxContext.mjs";
5
- import { getAttrsOfCartesianLabel as i, getAttrsOfPolarLabel as a, isPolar as o, renderRadialLabel as s } from "./utils.mjs";
6
- import c from "../Text.mjs";
7
- import { createVNode as l, defineComponent as u, mergeProps as d } from "vue";
1
+ import { isNullish } from "../../utils/validate.mjs";
2
+ import { useViewBox } from "../../context/chartLayoutContext.mjs";
3
+ import { LabelVueProps } from "./types.mjs";
4
+ import { usePolarLabelViewBox } from "../../context/polarLabelViewBoxContext.mjs";
5
+ import { getAttrsOfCartesianLabel, getAttrsOfPolarLabel, isPolar, renderRadialLabel } from "./utils.mjs";
6
+ import Text_default from "../Text.mjs";
7
+ import { createVNode, defineComponent, mergeProps } from "vue";
8
8
  //#region src/components/label/Label.tsx
9
- var f = /* @__PURE__ */ u({
9
+ var Label = /* @__PURE__ */ defineComponent({
10
10
  name: "Label",
11
- props: n,
11
+ props: LabelVueProps,
12
12
  slots: Object,
13
- setup(n, { slots: u, attrs: f }) {
14
- let p = t(), m = r();
13
+ setup(props, { slots, attrs }) {
14
+ const viewBoxFromContext = useViewBox();
15
+ const polarLabelViewBox = usePolarLabelViewBox();
15
16
  return () => {
16
- let { viewBox: t, value: r, position: h, textBreakAll: g, formatter: _ } = n, v = t || m.value || p.value;
17
- if (!v || e(r) && !u.content) return null;
18
- let y = o(v);
19
- if (u.content) return u.content({
20
- ...n,
21
- viewBox: v
17
+ const { viewBox: viewBoxFromProps, value, position, textBreakAll, formatter } = props;
18
+ const viewBox = viewBoxFromProps || polarLabelViewBox.value || viewBoxFromContext.value;
19
+ if (!viewBox || isNullish(value) && !slots.content) return null;
20
+ const isPolarLabel = isPolar(viewBox);
21
+ if (slots.content) return slots.content({
22
+ ...props,
23
+ viewBox
22
24
  });
23
- let b = r;
24
- if (typeof _ == "function" && (b = _(b)), y && (h === "insideStart" || h === "insideEnd" || h === "end")) return s(n, h, b, f, v);
25
- let x = y ? a(n, v) : i(n, v), S = f.textAnchor != null && (f.textAnchor === "start" || f.textAnchor === "middle" || f.textAnchor === "end") ? f.textAnchor : x.textAnchor;
26
- return l(c, d({ class: ["v-charts-label", n.class] }, f, x, {
27
- textAnchor: S,
28
- angle: n.angle,
29
- breakAll: g,
30
- value: b
25
+ let label = value;
26
+ if (typeof formatter === "function") label = formatter(label);
27
+ if (isPolarLabel && (position === "insideStart" || position === "insideEnd" || position === "end")) return renderRadialLabel(props, position, label, attrs, viewBox);
28
+ const positionAttrs = isPolarLabel ? getAttrsOfPolarLabel(props, viewBox) : getAttrsOfCartesianLabel(props, viewBox);
29
+ const textAnchor = attrs.textAnchor != null && (attrs.textAnchor === "start" || attrs.textAnchor === "middle" || attrs.textAnchor === "end") ? attrs.textAnchor : positionAttrs.textAnchor;
30
+ return createVNode(Text_default, mergeProps({ "class": ["v-charts-label", props.class] }, attrs, positionAttrs, {
31
+ "textAnchor": textAnchor,
32
+ "angle": props.angle,
33
+ "breakAll": textBreakAll,
34
+ "value": label
31
35
  }), null);
32
36
  };
33
37
  }
34
38
  });
35
39
  //#endregion
36
- export { f as Label };
40
+ export { Label };
@@ -1,49 +1,55 @@
1
- import { isNullish as e } from "../../utils/validate.mjs";
2
- import { getValueByDataKey as t } from "../../utils/chart.mjs";
3
- import { Layer as n } from "../../container/Layer.mjs";
4
- import { LabelListVueProps as r } from "./types.mjs";
5
- import { parseViewBox as i } from "./utils.mjs";
6
- import { Label as a } from "./Label.mjs";
7
- import { useLabelLayerRef as o } from "../../context/labelLayerContext.mjs";
8
- import { useCartesianLabelListData as s } from "../../context/cartesianLabelListContext.mjs";
9
- import { Teleport as c, createVNode as l, defineComponent as u, isVNode as d, mergeProps as f } from "vue";
1
+ import { isNullish } from "../../utils/validate.mjs";
2
+ import { getValueByDataKey } from "../../utils/chart.mjs";
3
+ import { Layer } from "../../container/Layer.mjs";
4
+ import { LabelListVueProps } from "./types.mjs";
5
+ import { parseViewBox } from "./utils.mjs";
6
+ import { Label } from "./Label.mjs";
7
+ import { useLabelLayerRef } from "../../context/labelLayerContext.mjs";
8
+ import { useCartesianLabelListData } from "../../context/cartesianLabelListContext.mjs";
9
+ import { Teleport, createVNode, defineComponent, isVNode, mergeProps } from "vue";
10
10
  //#region src/components/label/LabelList.tsx
11
- function p(e) {
12
- return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !d(e);
11
+ function _isSlot(s) {
12
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
13
13
  }
14
- var m = /* @__PURE__ */ u({
15
- props: r,
16
- setup(r, { attrs: u, slots: d }) {
17
- let m = o(null), h = s(null);
14
+ var LabelList = /* @__PURE__ */ defineComponent({
15
+ props: LabelListVueProps,
16
+ setup(props, { attrs, slots }) {
17
+ const labelLayerRef = useLabelLayerRef(null);
18
+ const contextData = useCartesianLabelListData(null);
18
19
  return () => {
19
- let o, { dataKey: s, valueAccessor: g, clockWise: _, id: v, ...y } = r, b = r.data ?? h?.value;
20
- if (!b || !b.length) return null;
21
- let x = l(n, { class: "v-charts-label-list" }, p(o = b.map((n, r) => {
22
- let o = e(s) ? g(n, r) : t(n && n.payload, s), c = e(v) ? void 0 : `${v}-${r}`, p = i(e(_) ? n : {
23
- ...n,
24
- clockWise: _
20
+ let _slot;
21
+ const { dataKey, valueAccessor, clockWise, id, ...others } = props;
22
+ const data = props.data ?? contextData?.value;
23
+ if (!data || !data.length) return null;
24
+ const content = createVNode(Layer, { "class": "v-charts-label-list" }, _isSlot(_slot = data.map((entry, index) => {
25
+ const value = isNullish(dataKey) ? valueAccessor(entry, index) : getValueByDataKey(entry && entry.payload, dataKey);
26
+ const idProps = isNullish(id) ? void 0 : `${id}-${index}`;
27
+ const viewBox = parseViewBox(isNullish(clockWise) ? entry : {
28
+ ...entry,
29
+ clockWise
25
30
  });
26
- if (d.label) return d.label({
27
- ...y,
28
- ...u,
29
- ...p,
30
- value: o,
31
- index: r,
32
- key: `label-${r}`
31
+ if (slots.label) return slots.label({
32
+ ...others,
33
+ ...attrs,
34
+ ...viewBox,
35
+ value,
36
+ index,
37
+ key: `label-${index}`
33
38
  });
34
- let m = n.fill != null && !("fill" in y) && !("fill" in u) ? n.fill : void 0;
35
- return l(a, f(y, u, m == null ? {} : { fill: m }, {
36
- id: c,
37
- parentViewBox: n.parentViewBox,
38
- value: o,
39
- viewBox: p,
40
- key: `label-${r}`,
41
- index: r
39
+ const entryFill = entry.fill != null && !("fill" in others) && !("fill" in attrs) ? entry.fill : void 0;
40
+ return createVNode(Label, mergeProps(others, attrs, entryFill != null ? { fill: entryFill } : {}, {
41
+ "id": idProps,
42
+ "parentViewBox": entry.parentViewBox,
43
+ "value": value,
44
+ "viewBox": viewBox,
45
+ "key": `label-${index}`,
46
+ "index": index
42
47
  }), null);
43
- })) ? o : { default: () => [o] });
44
- return m?.value ? l(c, { to: m.value }, p(x) ? x : { default: () => [x] }) : x;
48
+ })) ? _slot : { default: () => [_slot] });
49
+ if (labelLayerRef?.value) return createVNode(Teleport, { "to": labelLayerRef.value }, _isSlot(content) ? content : { default: () => [content] });
50
+ return content;
45
51
  };
46
52
  }
47
53
  });
48
54
  //#endregion
49
- export { m as LabelList };
55
+ export { LabelList };
@@ -1,10 +1,13 @@
1
- import { last as e } from "es-toolkit/compat";
2
- var t = {
1
+ import { classProp } from "../../types/common.mjs";
2
+ import { last } from "es-toolkit/compat";
3
+ //#region src/components/label/types.ts
4
+ var defaultAccessor = (entry) => Array.isArray(entry.value) ? last(entry.value) : entry.value;
5
+ var LabelListVueProps = {
3
6
  id: { type: String },
4
7
  data: { type: Array },
5
8
  valueAccessor: {
6
9
  type: Function,
7
- default: (t) => Array.isArray(t.value) ? e(t.value) : t.value
10
+ default: defaultAccessor
8
11
  },
9
12
  clockWise: { type: Boolean },
10
13
  dataKey: { type: [String, Function] },
@@ -12,10 +15,11 @@ var t = {
12
15
  position: { type: String },
13
16
  offset: { type: Number },
14
17
  angle: { type: Number }
15
- }, n = {
18
+ };
19
+ var LabelVueProps = {
16
20
  id: { type: String },
17
21
  class: {
18
- type: String,
22
+ ...classProp,
19
23
  default: ""
20
24
  },
21
25
  viewBox: { type: Object },
@@ -32,4 +36,4 @@ var t = {
32
36
  index: { type: Number }
33
37
  };
34
38
  //#endregion
35
- export { t as LabelListVueProps, n as LabelVueProps };
39
+ export { LabelListVueProps, LabelVueProps };
@@ -1,233 +1,265 @@
1
- import { isNumber as e, isPercent as t } from "../../utils/validate.mjs";
2
- import { uniqueId as n } from "../../utils/data-utils.mjs";
3
- import { getPercentValue as r, mathSign as i } from "../../utils/data.mjs";
4
- import { createVNode as a, mergeProps as o } from "vue";
1
+ import { isNumber, isPercent } from "../../utils/validate.mjs";
2
+ import { uniqueId } from "../../utils/data-utils.mjs";
3
+ import { getPercentValue, mathSign } from "../../utils/data.mjs";
4
+ import { createVNode, mergeProps } from "vue";
5
5
  //#region src/components/label/utils.tsx
6
- function s(t) {
7
- let { cx: n, cy: r, angle: i, startAngle: a, endAngle: o, r: s, radius: c, innerRadius: l, outerRadius: u, x: d, y: f, top: p, left: m, width: h, height: g, clockWise: _, labelViewBox: v } = t;
8
- if (v) return v;
9
- if (e(h) && e(g)) {
10
- if (e(d) && e(f)) return {
11
- x: d,
12
- y: f,
13
- width: h,
14
- height: g
6
+ function parseViewBox(props) {
7
+ const { cx, cy, angle, startAngle, endAngle, r, radius, innerRadius, outerRadius, x, y, top, left, width, height, clockWise, labelViewBox } = props;
8
+ if (labelViewBox) return labelViewBox;
9
+ if (isNumber(width) && isNumber(height)) {
10
+ if (isNumber(x) && isNumber(y)) return {
11
+ x,
12
+ y,
13
+ width,
14
+ height
15
15
  };
16
- if (e(p) && e(m)) return {
17
- x: p,
18
- y: m,
19
- width: h,
20
- height: g
16
+ if (isNumber(top) && isNumber(left)) return {
17
+ x: top,
18
+ y: left,
19
+ width,
20
+ height
21
21
  };
22
22
  }
23
- if (e(d) && e(f)) return {
24
- x: d,
25
- y: f,
23
+ if (isNumber(x) && isNumber(y)) return {
24
+ x,
25
+ y,
26
26
  width: 0,
27
27
  height: 0
28
28
  };
29
- if (e(n) && e(r)) return {
30
- cx: n,
31
- cy: r,
32
- startAngle: a || i || 0,
33
- endAngle: o || i || 0,
34
- innerRadius: l || 0,
35
- outerRadius: u || c || s || 0,
36
- clockWise: _
29
+ if (isNumber(cx) && isNumber(cy)) return {
30
+ cx,
31
+ cy,
32
+ startAngle: startAngle || angle || 0,
33
+ endAngle: endAngle || angle || 0,
34
+ innerRadius: innerRadius || 0,
35
+ outerRadius: outerRadius || radius || r || 0,
36
+ clockWise
37
37
  };
38
- if (t.viewBox) return t.viewBox;
38
+ if (props.viewBox) return props.viewBox;
39
39
  }
40
- function c(t) {
41
- return "cx" in t && e(t.cx);
40
+ function isPolar(viewBox) {
41
+ return "cx" in viewBox && isNumber(viewBox.cx);
42
42
  }
43
- var l = Math.PI / 180;
44
- function u(e, t, n, r) {
43
+ var RADIAN = Math.PI / 180;
44
+ function polarToCartesian(cx, cy, radius, angle) {
45
45
  return {
46
- x: e + Math.cos(-l * r) * n,
47
- y: t + Math.sin(-l * r) * n
46
+ x: cx + Math.cos(-RADIAN * angle) * radius,
47
+ y: cy + Math.sin(-RADIAN * angle) * radius
48
48
  };
49
49
  }
50
- function d(e, t) {
51
- return i(t - e) * Math.min(Math.abs(t - e), 360);
50
+ function getDeltaAngle(startAngle, endAngle) {
51
+ return mathSign(endAngle - startAngle) * Math.min(Math.abs(endAngle - startAngle), 360);
52
52
  }
53
- function f(e, t, r, i, s) {
54
- let { offset: c = 5, class: l, id: f } = e, { cx: p, cy: m, innerRadius: h, outerRadius: g, startAngle: _, endAngle: v, clockWise: y } = s, b = (h + g) / 2, x = d(_, v), S = x >= 0 ? 1 : -1, C, w;
55
- switch (t) {
53
+ function renderRadialLabel(labelProps, position, label, attrs, viewBox) {
54
+ const { offset = 5, class: className, id: labelId } = labelProps;
55
+ const { cx, cy, innerRadius, outerRadius, startAngle, endAngle, clockWise } = viewBox;
56
+ const radius = (innerRadius + outerRadius) / 2;
57
+ const deltaAngle = getDeltaAngle(startAngle, endAngle);
58
+ const sign = deltaAngle >= 0 ? 1 : -1;
59
+ let labelAngle;
60
+ let direction;
61
+ switch (position) {
56
62
  case "insideStart":
57
- C = _ + S * c, w = y;
63
+ labelAngle = startAngle + sign * offset;
64
+ direction = clockWise;
58
65
  break;
59
66
  case "insideEnd":
60
- C = v - S * c, w = !y;
67
+ labelAngle = endAngle - sign * offset;
68
+ direction = !clockWise;
61
69
  break;
62
70
  case "end":
63
- C = v + S * c, w = y;
71
+ labelAngle = endAngle + sign * offset;
72
+ direction = clockWise;
64
73
  break;
65
- default: throw Error(`Unsupported position ${t}`);
74
+ default: throw new Error(`Unsupported position ${position}`);
66
75
  }
67
- w = x <= 0 ? w : !w;
68
- let T = u(p, m, b, C), E = u(p, m, b, C + (w ? 1 : -1) * 359), D = `M${T.x},${T.y} A${b},${b},0,1,${w ? 0 : 1},${E.x},${E.y}`, O = f ?? n("v-charts-radial-line-");
69
- return a("text", o(i, {
76
+ direction = deltaAngle <= 0 ? direction : !direction;
77
+ const startPoint = polarToCartesian(cx, cy, radius, labelAngle);
78
+ const endPoint = polarToCartesian(cx, cy, radius, labelAngle + (direction ? 1 : -1) * 359);
79
+ const path = `M${startPoint.x},${startPoint.y} A${radius},${radius},0,1,${direction ? 0 : 1},${endPoint.x},${endPoint.y}`;
80
+ const id = labelId == null ? uniqueId("v-charts-radial-line-") : labelId;
81
+ return createVNode("text", mergeProps(attrs, {
70
82
  "dominant-baseline": "central",
71
- class: ["v-charts-radial-bar-label", l]
72
- }), [a("defs", null, [a("path", {
73
- id: O,
74
- d: D
75
- }, null)]), a("textPath", { "xlink:href": `#${O}` }, [r])]);
83
+ "class": ["v-charts-radial-bar-label", className]
84
+ }), [createVNode("defs", null, [createVNode("path", {
85
+ "id": id,
86
+ "d": path
87
+ }, null)]), createVNode("textPath", { "xlink:href": `#${id}` }, [label])]);
76
88
  }
77
- function p(e, t) {
78
- let { offset: n, position: r } = e, { cx: i, cy: a, innerRadius: o, outerRadius: s, startAngle: c, endAngle: l } = t ?? e.viewBox, d = (c + l) / 2;
79
- if (r === "outside") {
80
- let { x: e, y: t } = u(i, a, s + n, d);
89
+ function getAttrsOfPolarLabel(props, viewBox) {
90
+ const { offset, position } = props;
91
+ const { cx, cy, innerRadius, outerRadius, startAngle, endAngle } = viewBox ?? props.viewBox;
92
+ const midAngle = (startAngle + endAngle) / 2;
93
+ if (position === "outside") {
94
+ const { x, y } = polarToCartesian(cx, cy, outerRadius + offset, midAngle);
81
95
  return {
82
- x: e,
83
- y: t,
84
- textAnchor: e >= i ? "start" : "end",
96
+ x,
97
+ y,
98
+ textAnchor: x >= cx ? "start" : "end",
85
99
  verticalAnchor: "middle"
86
100
  };
87
101
  }
88
- if (r === "center") return {
89
- x: i,
90
- y: a,
102
+ if (position === "center") return {
103
+ x: cx,
104
+ y: cy,
91
105
  textAnchor: "middle",
92
106
  verticalAnchor: "middle"
93
107
  };
94
- if (r === "centerTop") return {
95
- x: i,
96
- y: a,
108
+ if (position === "centerTop") return {
109
+ x: cx,
110
+ y: cy,
97
111
  textAnchor: "middle",
98
112
  verticalAnchor: "start"
99
113
  };
100
- if (r === "centerBottom") return {
101
- x: i,
102
- y: a,
114
+ if (position === "centerBottom") return {
115
+ x: cx,
116
+ y: cy,
103
117
  textAnchor: "middle",
104
118
  verticalAnchor: "end"
105
119
  };
106
- let { x: f, y: p } = u(i, a, (o + s) / 2, d);
120
+ const { x, y } = polarToCartesian(cx, cy, (innerRadius + outerRadius) / 2, midAngle);
107
121
  return {
108
- x: f,
109
- y: p,
122
+ x,
123
+ y,
110
124
  textAnchor: "middle",
111
125
  verticalAnchor: "middle"
112
126
  };
113
127
  }
114
- function m(n, i) {
115
- let { parentViewBox: a, offset: o, position: s } = n, { x: c, y: l, width: u, height: d } = i, f = d >= 0 ? 1 : -1, p = f * o, m = f > 0 ? "end" : "start", h = f > 0 ? "start" : "end", g = u >= 0 ? 1 : -1, _ = g * o, v = g > 0 ? "end" : "start", y = g > 0 ? "start" : "end";
116
- if (s === "top") return {
117
- x: c + u / 2,
118
- y: l - f * o,
128
+ function getAttrsOfCartesianLabel(props, viewBox) {
129
+ const { parentViewBox, offset, position } = props;
130
+ const { x, y, width, height } = viewBox;
131
+ const verticalSign = height >= 0 ? 1 : -1;
132
+ const verticalOffset = verticalSign * offset;
133
+ const verticalEnd = verticalSign > 0 ? "end" : "start";
134
+ const verticalStart = verticalSign > 0 ? "start" : "end";
135
+ const horizontalSign = width >= 0 ? 1 : -1;
136
+ const horizontalOffset = horizontalSign * offset;
137
+ const horizontalEnd = horizontalSign > 0 ? "end" : "start";
138
+ const horizontalStart = horizontalSign > 0 ? "start" : "end";
139
+ if (position === "top") return {
140
+ x: x + width / 2,
141
+ y: y - verticalSign * offset,
119
142
  textAnchor: "middle",
120
- verticalAnchor: m,
121
- ...a ? {
122
- height: Math.max(l - a.y, 0),
123
- width: u
143
+ verticalAnchor: verticalEnd,
144
+ ...parentViewBox ? {
145
+ height: Math.max(y - parentViewBox.y, 0),
146
+ width
124
147
  } : {}
125
148
  };
126
- if (s === "bottom") return {
127
- x: c + u / 2,
128
- y: l + d + p,
149
+ if (position === "bottom") return {
150
+ x: x + width / 2,
151
+ y: y + height + verticalOffset,
129
152
  textAnchor: "middle",
130
- verticalAnchor: h,
131
- ...a ? {
132
- height: Math.max(a.y + a.height - (l + d), 0),
133
- width: u
153
+ verticalAnchor: verticalStart,
154
+ ...parentViewBox ? {
155
+ height: Math.max(parentViewBox.y + parentViewBox.height - (y + height), 0),
156
+ width
134
157
  } : {}
135
158
  };
136
- if (s === "left") {
137
- let e = {
138
- x: c - _,
139
- y: l + d / 2,
140
- textAnchor: v,
159
+ if (position === "left") {
160
+ const attrs = {
161
+ x: x - horizontalOffset,
162
+ y: y + height / 2,
163
+ textAnchor: horizontalEnd,
141
164
  verticalAnchor: "middle"
142
165
  };
143
166
  return {
144
- ...e,
145
- ...a ? {
146
- width: Math.max(e.x - a.x, 0),
147
- height: d
167
+ ...attrs,
168
+ ...parentViewBox ? {
169
+ width: Math.max(attrs.x - parentViewBox.x, 0),
170
+ height
148
171
  } : {}
149
172
  };
150
173
  }
151
- if (s === "right") {
152
- let e = {
153
- x: c + u + _,
154
- y: l + d / 2,
155
- textAnchor: y,
174
+ if (position === "right") {
175
+ const attrs = {
176
+ x: x + width + horizontalOffset,
177
+ y: y + height / 2,
178
+ textAnchor: horizontalStart,
156
179
  verticalAnchor: "middle"
157
180
  };
158
181
  return {
159
- ...e,
160
- ...a ? {
161
- width: Math.max(a.x + a.width - e.x, 0),
162
- height: d
182
+ ...attrs,
183
+ ...parentViewBox ? {
184
+ width: Math.max(parentViewBox.x + parentViewBox.width - attrs.x, 0),
185
+ height
163
186
  } : {}
164
187
  };
165
188
  }
166
- let b = a ? {
167
- width: u,
168
- height: d
189
+ const sizeAttrs = parentViewBox ? {
190
+ width,
191
+ height
169
192
  } : {};
170
- return s === "insideLeft" ? {
171
- x: c + _,
172
- y: l + d / 2,
173
- textAnchor: y,
193
+ if (position === "insideLeft") return {
194
+ x: x + horizontalOffset,
195
+ y: y + height / 2,
196
+ textAnchor: horizontalStart,
174
197
  verticalAnchor: "middle",
175
- ...b
176
- } : s === "insideRight" ? {
177
- x: c + u - _,
178
- y: l + d / 2,
179
- textAnchor: v,
198
+ ...sizeAttrs
199
+ };
200
+ if (position === "insideRight") return {
201
+ x: x + width - horizontalOffset,
202
+ y: y + height / 2,
203
+ textAnchor: horizontalEnd,
180
204
  verticalAnchor: "middle",
181
- ...b
182
- } : s === "insideTop" ? {
183
- x: c + u / 2,
184
- y: l + p,
205
+ ...sizeAttrs
206
+ };
207
+ if (position === "insideTop") return {
208
+ x: x + width / 2,
209
+ y: y + verticalOffset,
185
210
  textAnchor: "middle",
186
- verticalAnchor: h,
187
- ...b
188
- } : s === "insideBottom" ? {
189
- x: c + u / 2,
190
- y: l + d - p,
211
+ verticalAnchor: verticalStart,
212
+ ...sizeAttrs
213
+ };
214
+ if (position === "insideBottom") return {
215
+ x: x + width / 2,
216
+ y: y + height - verticalOffset,
191
217
  textAnchor: "middle",
192
- verticalAnchor: m,
193
- ...b
194
- } : s === "insideTopLeft" ? {
195
- x: c + _,
196
- y: l + p,
197
- textAnchor: y,
198
- verticalAnchor: h,
199
- ...b
200
- } : s === "insideTopRight" ? {
201
- x: c + u - _,
202
- y: l + p,
203
- textAnchor: v,
204
- verticalAnchor: h,
205
- ...b
206
- } : s === "insideBottomLeft" ? {
207
- x: c + _,
208
- y: l + d - p,
209
- textAnchor: y,
210
- verticalAnchor: m,
211
- ...b
212
- } : s === "insideBottomRight" ? {
213
- x: c + u - _,
214
- y: l + d - p,
215
- textAnchor: v,
216
- verticalAnchor: m,
217
- ...b
218
- } : s && typeof s == "object" && (e(s.x) || t(s.x)) && (e(s.y) || t(s.y)) ? {
219
- x: c + r(s.x, u),
220
- y: l + r(s.y, d),
218
+ verticalAnchor: verticalEnd,
219
+ ...sizeAttrs
220
+ };
221
+ if (position === "insideTopLeft") return {
222
+ x: x + horizontalOffset,
223
+ y: y + verticalOffset,
224
+ textAnchor: horizontalStart,
225
+ verticalAnchor: verticalStart,
226
+ ...sizeAttrs
227
+ };
228
+ if (position === "insideTopRight") return {
229
+ x: x + width - horizontalOffset,
230
+ y: y + verticalOffset,
231
+ textAnchor: horizontalEnd,
232
+ verticalAnchor: verticalStart,
233
+ ...sizeAttrs
234
+ };
235
+ if (position === "insideBottomLeft") return {
236
+ x: x + horizontalOffset,
237
+ y: y + height - verticalOffset,
238
+ textAnchor: horizontalStart,
239
+ verticalAnchor: verticalEnd,
240
+ ...sizeAttrs
241
+ };
242
+ if (position === "insideBottomRight") return {
243
+ x: x + width - horizontalOffset,
244
+ y: y + height - verticalOffset,
245
+ textAnchor: horizontalEnd,
246
+ verticalAnchor: verticalEnd,
247
+ ...sizeAttrs
248
+ };
249
+ if (!!position && typeof position === "object" && (isNumber(position.x) || isPercent(position.x)) && (isNumber(position.y) || isPercent(position.y))) return {
250
+ x: x + getPercentValue(position.x, width),
251
+ y: y + getPercentValue(position.y, height),
221
252
  textAnchor: "end",
222
253
  verticalAnchor: "end",
223
- ...b
224
- } : {
225
- x: c + u / 2,
226
- y: l + d / 2,
254
+ ...sizeAttrs
255
+ };
256
+ return {
257
+ x: x + width / 2,
258
+ y: y + height / 2,
227
259
  textAnchor: "middle",
228
260
  verticalAnchor: "middle",
229
- ...b
261
+ ...sizeAttrs
230
262
  };
231
263
  }
232
264
  //#endregion
233
- export { m as getAttrsOfCartesianLabel, p as getAttrsOfPolarLabel, c as isPolar, s as parseViewBox, f as renderRadialLabel };
265
+ export { getAttrsOfCartesianLabel, getAttrsOfPolarLabel, isPolar, parseViewBox, renderRadialLabel };