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,84 +1,111 @@
1
- import { isNullish as e, isNumber as t } from "../../utils/validate.mjs";
2
- import { mathSign as n } from "../../utils/data.mjs";
3
- import { getBaseValueOfBar as r, getCateCoordinateOfBar as i, getValueByDataKey as a, truncateByDomain as o } from "../../utils/chart.mjs";
4
- import { toRaw as s } from "vue";
5
- import { isNaN as c } from "es-toolkit/compat";
6
- import { invariant as l } from "es-toolkit";
1
+ import { isNullish, isNumber } from "../../utils/validate.mjs";
2
+ import { mathSign } from "../../utils/data.mjs";
3
+ import { getBaseValueOfBar, getCateCoordinateOfBar, getValueByDataKey, truncateByDomain } from "../../utils/chart.mjs";
4
+ import { toRaw } from "vue";
5
+ import { isNaN } from "es-toolkit/compat";
6
+ import { invariant } from "es-toolkit";
7
7
  //#region src/cartesian/bar/utils.ts
8
- function u(n, r = 0) {
9
- return (i, a) => {
10
- if (t(n)) return n;
11
- let o = t(i) || e(i);
12
- return o ? n(i, a) : (l(o, `minPointSize callback function received a value with type of ${typeof i}. Currently only numbers or null/undefined are supported.`), r);
8
+ /**
9
+ * Safely gets minPointSize from the minPointSize prop if it is a function
10
+ * @param minPointSize minPointSize as passed to the Bar component
11
+ * @param defaultValue default minPointSize
12
+ * @returns minPointSize
13
+ */
14
+ function minPointSizeCallback(minPointSize, defaultValue = 0) {
15
+ return (value, index) => {
16
+ if (isNumber(minPointSize)) return minPointSize;
17
+ const isValueNumberOrNil = isNumber(value) || isNullish(value);
18
+ if (isValueNumberOrNil) return minPointSize(value, index);
19
+ invariant(isValueNumberOrNil, `minPointSize callback function received a value with type of ${typeof value}. Currently only numbers or null/undefined are supported.`);
20
+ return defaultValue;
13
21
  };
14
22
  }
15
- var d = 0;
16
- function f({ layout: e, barSettings: { dataKey: t, minPointSize: l }, pos: f, bandSize: p, xAxis: m, yAxis: h, xAxisTicks: g, yAxisTicks: _, stackedData: v, displayedData: y, offset: b }) {
17
- let x = {
18
- x: b.left,
19
- y: b.top,
20
- width: b.width,
21
- height: b.height
22
- }, S = e === "horizontal" ? h : m, C = v ? S.scale.domain() : null, w = r({ numericAxis: S }), T = S.scale(w);
23
- return y.map((r, y) => {
24
- let S = s(r), E, D, O, k, A, j;
25
- v ? E = o(v[y], C) : (E = a(S, t), Array.isArray(E) || (E = [w, E]));
26
- let M = u(l, d)(E[1], y);
27
- if (e === "horizontal") {
28
- let [e, t] = [h.scale(E[0]), h.scale(E[1])];
29
- D = i({
30
- axis: m,
31
- ticks: g,
32
- bandSize: p,
33
- offset: f.offset,
34
- entry: S,
35
- index: y
36
- }), O = t ?? e ?? void 0, k = f.size;
37
- let r = e - t;
38
- if (A = c(r) ? 0 : r, j = {
39
- x: D,
40
- y: b.top,
41
- width: k,
42
- height: b.height
43
- }, Math.abs(M) > 0 && Math.abs(A) < Math.abs(M)) {
44
- let e = n(A || M) * (Math.abs(M) - Math.abs(A));
45
- O -= e, A += e;
23
+ var defaultMinPointSize = 0;
24
+ function computeBarRectangles({ layout, barSettings: { dataKey, minPointSize: minPointSizeProp }, pos, bandSize, xAxis, yAxis, xAxisTicks, yAxisTicks, stackedData, displayedData, offset }) {
25
+ const parentViewBox = {
26
+ x: offset.left,
27
+ y: offset.top,
28
+ width: offset.width,
29
+ height: offset.height
30
+ };
31
+ const numericAxis = layout === "horizontal" ? yAxis : xAxis;
32
+ const stackedDomain = stackedData ? numericAxis.scale.domain() : null;
33
+ const baseValue = getBaseValueOfBar({ numericAxis });
34
+ const stackedBarStart = numericAxis.scale(baseValue);
35
+ return displayedData.map((rawEntry, index) => {
36
+ const entry = toRaw(rawEntry);
37
+ let value, x, y, width, height, background;
38
+ if (stackedData) value = truncateByDomain(stackedData[index], stackedDomain);
39
+ else {
40
+ value = getValueByDataKey(entry, dataKey);
41
+ if (!Array.isArray(value)) value = [baseValue, value];
42
+ }
43
+ const minPointSize = minPointSizeCallback(minPointSizeProp, defaultMinPointSize)(value[1], index);
44
+ if (layout === "horizontal") {
45
+ const [baseValueScale, currentValueScale] = [yAxis.scale(value[0]), yAxis.scale(value[1])];
46
+ x = getCateCoordinateOfBar({
47
+ axis: xAxis,
48
+ ticks: xAxisTicks,
49
+ bandSize,
50
+ offset: pos.offset,
51
+ entry,
52
+ index
53
+ });
54
+ y = currentValueScale ?? baseValueScale ?? void 0;
55
+ width = pos.size;
56
+ const computedHeight = baseValueScale - currentValueScale;
57
+ height = isNaN(computedHeight) ? 0 : computedHeight;
58
+ background = {
59
+ x,
60
+ y: offset.top,
61
+ width,
62
+ height: offset.height
63
+ };
64
+ if (Math.abs(minPointSize) > 0 && Math.abs(height) < Math.abs(minPointSize)) {
65
+ const delta = mathSign(height || minPointSize) * (Math.abs(minPointSize) - Math.abs(height));
66
+ y -= delta;
67
+ height += delta;
46
68
  }
47
69
  } else {
48
- let [e, t] = [m.scale(E[0]), m.scale(E[1])];
49
- if (D = e, O = i({
50
- axis: h,
51
- ticks: _,
52
- bandSize: p,
53
- offset: f.offset,
54
- entry: S,
55
- index: y
56
- }), k = t - e, A = f.size, j = {
57
- x: b.left,
58
- y: O,
59
- width: b.width,
60
- height: A
61
- }, Math.abs(M) > 0 && Math.abs(k) < Math.abs(M)) {
62
- let e = n(k || M) * (Math.abs(M) - Math.abs(k));
63
- k += e;
70
+ const [baseValueScale, currentValueScale] = [xAxis.scale(value[0]), xAxis.scale(value[1])];
71
+ x = baseValueScale;
72
+ y = getCateCoordinateOfBar({
73
+ axis: yAxis,
74
+ ticks: yAxisTicks,
75
+ bandSize,
76
+ offset: pos.offset,
77
+ entry,
78
+ index
79
+ });
80
+ width = currentValueScale - baseValueScale;
81
+ height = pos.size;
82
+ background = {
83
+ x: offset.left,
84
+ y,
85
+ width: offset.width,
86
+ height
87
+ };
88
+ if (Math.abs(minPointSize) > 0 && Math.abs(width) < Math.abs(minPointSize)) {
89
+ const delta = mathSign(width || minPointSize) * (Math.abs(minPointSize) - Math.abs(width));
90
+ width += delta;
64
91
  }
65
92
  }
66
93
  return {
67
- x: D,
68
- y: O,
69
- width: k,
70
- height: A,
71
- stackedBarStart: T ?? 0,
72
- value: v ? E : E[1],
73
- payload: S,
74
- background: j,
94
+ x,
95
+ y,
96
+ width,
97
+ height,
98
+ stackedBarStart: stackedBarStart ?? 0,
99
+ value: stackedData ? value : value[1],
100
+ payload: entry,
101
+ background,
75
102
  tooltipPosition: {
76
- x: D + k / 2,
77
- y: O + A / 2
103
+ x: x + width / 2,
104
+ y: y + height / 2
78
105
  },
79
- parentViewBox: x
106
+ parentViewBox
80
107
  };
81
108
  });
82
109
  }
83
110
  //#endregion
84
- export { f as computeBarRectangles };
111
+ export { computeBarRectangles };
@@ -1,13 +1,19 @@
1
- import { isNumber as e } from "../../utils/validate.mjs";
2
- import { filterProps as t } from "../../utils/VueUtils.mjs";
3
- import { Layer as n } from "../../container/Layer.mjs";
4
- import r from "../../components/Text.mjs";
5
- import { Label as i } from "../../components/label/Label.mjs";
6
- import { getTicks as a } from "../utils/get-ticks.mjs";
7
- import { createVNode as o, defineComponent as s, mergeProps as c, reactive as l } from "vue";
8
- import { get as u } from "es-toolkit/compat";
1
+ import { isNumber } from "../../utils/validate.mjs";
2
+ import { filterProps } from "../../utils/VueUtils.mjs";
3
+ import { Layer } from "../../container/Layer.mjs";
4
+ import Text_default from "../../components/Text.mjs";
5
+ import { Label } from "../../components/label/Label.mjs";
6
+ import { getTicks } from "../utils/get-ticks.mjs";
7
+ import { createVNode, defineComponent, mergeProps, reactive } from "vue";
8
+ import { get } from "es-toolkit/compat";
9
9
  //#region src/cartesian/cartesian-axis/CartesianAxis.tsx
10
- var d = /* @__PURE__ */ s({
10
+ /**
11
+ * @fileOverview Cartesian Axis
12
+ */
13
+ /** The orientation of the axis in correspondence to the chart */
14
+ /** A unit to be appended to a value */
15
+ /** The formatter function of tick */
16
+ var CartesianAxis = /* @__PURE__ */ defineComponent({
11
17
  name: "CartesianAxis",
12
18
  props: {
13
19
  x: {
@@ -42,19 +48,19 @@ var d = /* @__PURE__ */ s({
42
48
  },
43
49
  tick: {
44
50
  type: Boolean,
45
- default: !0
51
+ default: true
46
52
  },
47
53
  axisLine: {
48
54
  type: [Boolean, Object],
49
- default: () => !0
55
+ default: () => true
50
56
  },
51
57
  tickLine: {
52
58
  type: [Boolean, Object],
53
- default: () => !0
59
+ default: () => true
54
60
  },
55
61
  mirror: {
56
62
  type: Boolean,
57
- default: !1
63
+ default: false
58
64
  },
59
65
  tickMargin: {
60
66
  type: Number,
@@ -86,161 +92,205 @@ var d = /* @__PURE__ */ s({
86
92
  default: "#666"
87
93
  }
88
94
  },
89
- inheritAttrs: !1,
90
- setup(s, { attrs: d, slots: f }) {
91
- let p = l({
95
+ inheritAttrs: false,
96
+ setup(props, { attrs, slots }) {
97
+ const state = reactive({
92
98
  fontSize: "",
93
99
  letterSpacing: ""
94
- }), m = (t) => {
95
- let { x: n, y: r, width: i, height: a, orientation: o, tickSize: c, mirror: l, tickMargin: u } = s, d, f, p, m, h, g, _ = l ? -1 : 1, v = t.tickSize || c, y = e(t.tickCoord) ? t.tickCoord : t.coordinate;
96
- switch (o) {
100
+ });
101
+ const getTickLineCoord = (data) => {
102
+ const { x, y, width, height, orientation, tickSize, mirror, tickMargin } = props;
103
+ let x1, x2, y1, y2, tx, ty;
104
+ const sign = mirror ? -1 : 1;
105
+ const finalTickSize = data.tickSize || tickSize;
106
+ const tickCoord = isNumber(data.tickCoord) ? data.tickCoord : data.coordinate;
107
+ switch (orientation) {
97
108
  case "top":
98
- d = f = t.coordinate, m = r + +!l * a, p = m - _ * v, g = p - _ * u, h = y;
109
+ x1 = x2 = data.coordinate;
110
+ y2 = y + +!mirror * height;
111
+ y1 = y2 - sign * finalTickSize;
112
+ ty = y1 - sign * tickMargin;
113
+ tx = tickCoord;
99
114
  break;
100
115
  case "left":
101
- p = m = t.coordinate, f = n + +!l * i, d = f - _ * v, h = d - _ * u, g = y;
116
+ y1 = y2 = data.coordinate;
117
+ x2 = x + +!mirror * width;
118
+ x1 = x2 - sign * finalTickSize;
119
+ tx = x1 - sign * tickMargin;
120
+ ty = tickCoord;
102
121
  break;
103
122
  case "right":
104
- p = m = t.coordinate, f = n + +l * i, d = f + _ * v, h = d + _ * u, g = y;
123
+ y1 = y2 = data.coordinate;
124
+ x2 = x + +mirror * width;
125
+ x1 = x2 + sign * finalTickSize;
126
+ tx = x1 + sign * tickMargin;
127
+ ty = tickCoord;
105
128
  break;
106
129
  default:
107
- d = f = t.coordinate, m = r + +l * a, p = m + _ * v, g = p + _ * u, h = y;
130
+ x1 = x2 = data.coordinate;
131
+ y2 = y + +mirror * height;
132
+ y1 = y2 + sign * finalTickSize;
133
+ ty = y1 + sign * tickMargin;
134
+ tx = tickCoord;
108
135
  break;
109
136
  }
110
137
  return {
111
138
  line: {
112
- x1: d,
113
- y1: p,
114
- x2: f,
115
- y2: m
139
+ x1,
140
+ y1,
141
+ x2,
142
+ y2
116
143
  },
117
144
  tick: {
118
- x: h,
119
- y: g
145
+ x: tx,
146
+ y: ty
120
147
  }
121
148
  };
122
- }, h = () => {
123
- let { orientation: e, mirror: t } = s, n;
124
- switch (e) {
149
+ };
150
+ const getTickTextAnchor = () => {
151
+ const { orientation, mirror } = props;
152
+ let textAnchor;
153
+ switch (orientation) {
125
154
  case "left":
126
- n = t ? "start" : "end";
155
+ textAnchor = mirror ? "start" : "end";
127
156
  break;
128
157
  case "right":
129
- n = t ? "end" : "start";
158
+ textAnchor = mirror ? "end" : "start";
130
159
  break;
131
160
  default:
132
- n = "middle";
161
+ textAnchor = "middle";
133
162
  break;
134
163
  }
135
- return n;
136
- }, g = () => {
137
- let { orientation: e, mirror: t } = s;
138
- switch (e) {
164
+ return textAnchor;
165
+ };
166
+ const getTickVerticalAnchor = () => {
167
+ const { orientation, mirror } = props;
168
+ switch (orientation) {
139
169
  case "left":
140
170
  case "right": return "middle";
141
- case "top": return t ? "start" : "end";
142
- default: return t ? "end" : "start";
171
+ case "top": return mirror ? "start" : "end";
172
+ default: return mirror ? "end" : "start";
143
173
  }
144
- }, _ = () => {
145
- let { x: e, y: n, width: r, height: i, orientation: a, mirror: l, axisLine: d } = s, f = {
146
- ...t(s, !1),
147
- ...t(d, !1),
174
+ };
175
+ const renderAxisLine = () => {
176
+ const { x, y, width, height, orientation, mirror, axisLine } = props;
177
+ let lineProps = {
178
+ ...filterProps(props, false),
179
+ ...filterProps(axisLine, false),
148
180
  fill: "none",
149
181
  x1: 0,
150
182
  y1: 0,
151
183
  x2: 0,
152
184
  y2: 0
153
185
  };
154
- if (a === "top" || a === "bottom") {
155
- let t = +(a === "top" && !l || a === "bottom" && l);
156
- f = {
157
- ...f,
158
- x1: e,
159
- y1: n + t * i,
160
- x2: e + r,
161
- y2: n + t * i
186
+ if (orientation === "top" || orientation === "bottom") {
187
+ const needHeight = +(orientation === "top" && !mirror || orientation === "bottom" && mirror);
188
+ lineProps = {
189
+ ...lineProps,
190
+ x1: x,
191
+ y1: y + needHeight * height,
192
+ x2: x + width,
193
+ y2: y + needHeight * height
162
194
  };
163
195
  } else {
164
- let t = +(a === "left" && !l || a === "right" && l);
165
- f = {
166
- ...f,
167
- x1: e + t * r,
168
- y1: n,
169
- x2: e + t * r,
170
- y2: n + i
196
+ const needWidth = +(orientation === "left" && !mirror || orientation === "right" && mirror);
197
+ lineProps = {
198
+ ...lineProps,
199
+ x1: x + needWidth * width,
200
+ y1: y,
201
+ x2: x + needWidth * width,
202
+ y2: y + height
171
203
  };
172
204
  }
173
- return o("line", c(f, { class: ["v-charts-cartesian-axis-line", u(d, "class")] }), null);
205
+ return createVNode("line", mergeProps(lineProps, { "class": ["v-charts-cartesian-axis-line", get(axisLine, "class")] }), null);
174
206
  };
175
- function v(e, t) {
176
- return o(r, c(e, {
177
- class: ["v-charts-cartesian-axis-tick-value", e.class],
178
- value: t
207
+ function renderTickItem(props, value) {
208
+ const className = ["v-charts-cartesian-axis-tick-value", props.class];
209
+ return createVNode(Text_default, mergeProps(props, {
210
+ "class": className,
211
+ "value": value
179
212
  }), null);
180
213
  }
181
- let y = (e, r, i) => {
182
- let { tickLine: s, stroke: l, tick: d, tickFormatter: p, unit: _ } = e, y = a(e, r, i), b = h(), x = g(), S = t(e, !1), C = t(d, !1), w = {
183
- ...S,
214
+ const renderTicks = (props, fontSize, letterSpacing) => {
215
+ const { tickLine, stroke, tick, tickFormatter, unit } = props;
216
+ const finalTicks = getTicks(props, fontSize, letterSpacing);
217
+ const textAnchor = getTickTextAnchor();
218
+ const verticalAnchor = getTickVerticalAnchor();
219
+ const axisProps = filterProps(props, false);
220
+ const customTickProps = filterProps(tick, false);
221
+ const tickLineProps = {
222
+ ...axisProps,
184
223
  fill: "none",
185
- ...t(s, !1)
186
- }, T = y.map((e, t) => {
187
- let { line: r, tick: i } = m(e), a = {
188
- textAnchor: b,
189
- verticalAnchor: x,
190
- ...S,
224
+ ...filterProps(tickLine, false)
225
+ };
226
+ const items = finalTicks.map((entry, i) => {
227
+ const { line: lineCoord, tick: tickCoord } = getTickLineCoord(entry);
228
+ const tickProps = {
229
+ textAnchor,
230
+ verticalAnchor,
231
+ ...axisProps,
191
232
  stroke: "none",
192
- fill: l,
193
- ...C,
194
- ...i,
195
- index: t,
196
- payload: e,
197
- visibleTicksCount: y.length,
198
- tickFormatter: p
233
+ fill: stroke,
234
+ ...customTickProps,
235
+ ...tickCoord,
236
+ index: i,
237
+ payload: entry,
238
+ visibleTicksCount: finalTicks.length,
239
+ tickFormatter
199
240
  };
200
- return o(n, {
201
- class: "v-charts-cartesian-axis-tick",
202
- key: `tick-${e.value}-${e.coordinate}-${e.tickCoord}`
203
- }, { default: () => [s && o("line", c(w, r, { class: ["v-charts-cartesian-axis-tick-line", u(s, "class")] }), null), d && (f.tick ? f.tick({
204
- ...a,
205
- value: e.value
206
- }) : v(a, `${typeof p == "function" ? p(e.value, t) : e.value}${_ || ""}`))] });
241
+ return createVNode(Layer, {
242
+ "class": "v-charts-cartesian-axis-tick",
243
+ "key": `tick-${entry.value}-${entry.coordinate}-${entry.tickCoord}`
244
+ }, { default: () => [tickLine && createVNode("line", mergeProps(tickLineProps, lineCoord, { "class": ["v-charts-cartesian-axis-tick-line", get(tickLine, "class")] }), null), tick && (slots.tick ? slots.tick({
245
+ ...tickProps,
246
+ value: entry.value
247
+ }) : renderTickItem(tickProps, `${typeof tickFormatter === "function" ? tickFormatter(entry.value, i) : entry.value}${unit || ""}`))] });
207
248
  });
208
- return T.length > 0 ? o("g", { class: "v-charts-cartesian-axis-ticks" }, [T]) : null;
209
- }, b = () => {
210
- let { label: e, x: t, y: n, width: r, height: a } = s;
211
- if (!e) return null;
212
- let l = {
213
- x: t,
214
- y: n,
215
- width: r,
216
- height: a
249
+ return items.length > 0 ? createVNode("g", { "class": "v-charts-cartesian-axis-ticks" }, [items]) : null;
250
+ };
251
+ const renderLabel = () => {
252
+ const { label, x, y, width, height } = props;
253
+ if (!label) return null;
254
+ const axisViewBox = {
255
+ x,
256
+ y,
257
+ width,
258
+ height
217
259
  };
218
- return typeof e == "string" || typeof e == "number" ? o(i, {
219
- value: e,
220
- viewBox: l
221
- }, null) : typeof e == "object" ? o(i, c(e, { viewBox: l }), null) : null;
260
+ if (typeof label === "string" || typeof label === "number") return createVNode(Label, {
261
+ "value": label,
262
+ "viewBox": axisViewBox
263
+ }, null);
264
+ if (typeof label === "object") return createVNode(Label, mergeProps(label, { "viewBox": axisViewBox }), null);
265
+ return null;
222
266
  };
223
267
  return () => {
224
- let { axisLine: e, width: t, height: r, hide: i } = s;
225
- return i || t != null && t <= 0 || r != null && r <= 0 ? null : o(n, {
226
- class: ["v-charts-cartesian-axis", d.class],
227
- ref: (e) => {
228
- let t = e?.$el;
229
- if (t) {
230
- let e = t?.getElementsByClassName("v-charts-cartesian-axis-tick-value")[0];
231
- if (e) {
232
- let t = window.getComputedStyle(e).fontSize, n = window.getComputedStyle(e).letterSpacing;
233
- (t !== p.fontSize || n !== p.letterSpacing) && (p.fontSize = window.getComputedStyle(e).fontSize, p.letterSpacing = window.getComputedStyle(e).letterSpacing);
268
+ const { axisLine, width, height, hide } = props;
269
+ if (hide) return null;
270
+ if (width != null && width <= 0 || height != null && height <= 0) return null;
271
+ return createVNode(Layer, {
272
+ "class": ["v-charts-cartesian-axis", attrs.class],
273
+ "ref": (ref) => {
274
+ const elm = ref?.$el;
275
+ if (elm) {
276
+ const tick = elm?.getElementsByClassName("v-charts-cartesian-axis-tick-value")[0];
277
+ if (tick) {
278
+ const calculatedFontSize = window.getComputedStyle(tick).fontSize;
279
+ const calculatedLetterSpacing = window.getComputedStyle(tick).letterSpacing;
280
+ if (calculatedFontSize !== state.fontSize || calculatedLetterSpacing !== state.letterSpacing) {
281
+ state.fontSize = window.getComputedStyle(tick).fontSize;
282
+ state.letterSpacing = window.getComputedStyle(tick).letterSpacing;
283
+ }
234
284
  }
235
285
  }
236
286
  }
237
287
  }, { default: () => [
238
- e && _(),
239
- y(s, p.fontSize, p.letterSpacing),
240
- b()
288
+ axisLine && renderAxisLine(),
289
+ renderTicks(props, state.fontSize, state.letterSpacing),
290
+ renderLabel()
241
291
  ] });
242
292
  };
243
293
  }
244
294
  });
245
295
  //#endregion
246
- export { d as CartesianAxis };
296
+ export { CartesianAxis };
@@ -1,8 +1,8 @@
1
- import { createVNode as e, defineComponent as t } from "vue";
1
+ import { createVNode, defineComponent } from "vue";
2
2
  //#region src/cartesian/cartesian-grid/Background.tsx
3
- var n = /* @__PURE__ */ t({
3
+ var Background = /* @__PURE__ */ defineComponent({
4
4
  name: "Background",
5
- inheritAttrs: !1,
5
+ inheritAttrs: false,
6
6
  props: {
7
7
  fill: String,
8
8
  fillOpacity: Number,
@@ -12,19 +12,22 @@ var n = /* @__PURE__ */ t({
12
12
  height: Number,
13
13
  ry: Number
14
14
  },
15
- setup(t) {
16
- return () => !t.fill || t.fill === "none" ? null : e("rect", {
17
- x: t.x,
18
- y: t.y,
19
- ry: t.ry,
20
- width: t.width,
21
- height: t.height,
22
- stroke: "none",
23
- fill: t.fill,
24
- "fill-opacity": t.fillOpacity,
25
- class: "v-charts-cartesian-grid-bg"
26
- }, null);
15
+ setup(props) {
16
+ return () => {
17
+ if (!props.fill || props.fill === "none") return null;
18
+ return createVNode("rect", {
19
+ "x": props.x,
20
+ "y": props.y,
21
+ "ry": props.ry,
22
+ "width": props.width,
23
+ "height": props.height,
24
+ "stroke": "none",
25
+ "fill": props.fill,
26
+ "fill-opacity": props.fillOpacity,
27
+ "class": "v-charts-cartesian-grid-bg"
28
+ }, null);
29
+ };
27
30
  }
28
31
  });
29
32
  //#endregion
30
- export { n as default };
33
+ export { Background as default };