vccs 0.4.0 → 0.5.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.
- package/README.md +4 -0
- package/dist/cartesian/axis/YAxis.d.ts +5 -5
- package/dist/cartesian/cartesian-axis/CartesianAxis.d.ts +11 -0
- package/dist/chart/{RechartsWrapper.d.ts → ChartsWrapper.d.ts} +19 -4
- package/dist/chart/Sankey.d.ts +327 -0
- package/dist/chart/SunburstChart.d.ts +249 -0
- package/dist/chart/Surface.d.ts +2 -2
- package/dist/chart/generateCategoricalChart.d.ts +6 -2
- package/dist/chart/index.d.ts +2 -0
- package/dist/chart/sankeyUtils.d.ts +36 -0
- package/dist/chart/sunburstUtils.d.ts +34 -0
- package/dist/container/Surface.d.ts +3 -3
- package/dist/es/cartesian/axis/YAxis.mjs +52 -5
- package/dist/es/cartesian/cartesian-axis/CartesianAxis.mjs +6 -1
- package/dist/es/cartesian/utils/get-ticks.mjs +3 -2
- package/dist/es/chart/{RechartsWrapper.mjs → ChartsWrapper.mjs} +37 -10
- package/dist/es/chart/Sankey.mjs +332 -0
- package/dist/es/chart/SunburstChart.mjs +229 -0
- package/dist/es/chart/Surface.vue_vue_type_script_setup_true_lang.mjs +7 -1
- package/dist/es/chart/Treemap.mjs +2 -2
- package/dist/es/chart/generateCategoricalChart.mjs +72 -43
- package/dist/es/chart/sankeyUtils.mjs +28 -0
- package/dist/es/chart/sunburstUtils.mjs +67 -0
- package/dist/es/components/Tooltip.mjs +15 -6
- package/dist/es/container/ResponsiveContainer.vue_vue_type_script_setup_true_lang.mjs +15 -2
- package/dist/es/container/Surface.mjs +5 -1
- package/dist/es/index.mjs +5 -2
- package/dist/es/polar/pie/Pie.mjs +1 -1
- package/dist/es/polar/pie/type.mjs +7 -0
- package/dist/es/polar/radar/Radar.mjs +9 -1
- package/dist/es/polar/radial-bar/RadialBar.mjs +1 -0
- package/dist/es/polar/radial-bar/type.mjs +7 -0
- package/dist/es/state/cartesianAxisSlice.mjs +13 -2
- package/dist/es/state/selectors/axisSelectors.mjs +2 -2
- package/dist/es/state/selectors/selectChartOffset.mjs +7 -4
- package/dist/es/state/touchEventsMiddleware.mjs +1 -1
- package/dist/es/utils/Global.mjs +18 -0
- package/dist/es/utils/YAxisUtils.mjs +29 -0
- package/dist/es/utils/attrs.mjs +2 -2
- package/dist/es/utils/validate.mjs +1 -2
- package/dist/hooks/publicHooks.d.ts +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/polar/pie/type.d.ts +8 -0
- package/dist/polar/radar/Radar.d.ts +16 -0
- package/dist/polar/radial-bar/type.d.ts +8 -0
- package/dist/state/cartesianAxisSlice.d.ts +11 -3
- package/dist/state/selectors/combiners/combineActiveLabel.d.ts +1 -1
- package/dist/state/selectors/selectors.d.ts +1 -1
- package/dist/state/selectors/tooltipSelectors.d.ts +1 -1
- package/dist/types/axis.d.ts +11 -1
- package/dist/types/common.d.ts +1 -1
- package/dist/utils/Global.d.ts +9 -0
- package/dist/utils/YAxisUtils.d.ts +20 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/validate.d.ts +0 -1
- package/package.json +3 -1
|
@@ -5,13 +5,13 @@ import { createRechartsStore } from "../state/store.mjs";
|
|
|
5
5
|
import Surface_default from "./Surface.mjs";
|
|
6
6
|
import { ChartDataContextProvider } from "../context/ChartDataContextProvider.mjs";
|
|
7
7
|
import ClipPath_default from "../container/ClipPath.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { ChartsWrapper } from "./ChartsWrapper.mjs";
|
|
9
9
|
import { FULL_WIDTH_AND_HEIGHT } from "./const.mjs";
|
|
10
10
|
import { ReportMainChartProps } from "../state/ReportMainChartProps.mjs";
|
|
11
11
|
import ReportChartProps_default from "../state/ReportChartProps.mjs";
|
|
12
12
|
import { applyDefaultProps } from "../utils/props.mjs";
|
|
13
13
|
import { ReportPolarOptions } from "../state/ReportPolarOptions.mjs";
|
|
14
|
-
import { Fragment, createVNode, defineComponent, mergeProps } from "vue";
|
|
14
|
+
import { Fragment, createVNode, defineComponent, mergeProps, ref } from "vue";
|
|
15
15
|
import { provideStore } from "@reduxjs/vue-redux";
|
|
16
16
|
//#region src/chart/generateCategoricalChart.tsx
|
|
17
17
|
var defaultLayout = "horizontal";
|
|
@@ -63,6 +63,10 @@ var CategoricalProps = {
|
|
|
63
63
|
},
|
|
64
64
|
maxBarSize: { type: Number },
|
|
65
65
|
outerRadius: { type: [Number, String] },
|
|
66
|
+
responsive: {
|
|
67
|
+
type: Boolean,
|
|
68
|
+
default: false
|
|
69
|
+
},
|
|
66
70
|
reverseStackOrder: {
|
|
67
71
|
type: Boolean,
|
|
68
72
|
default: false
|
|
@@ -73,7 +77,11 @@ var CategoricalProps = {
|
|
|
73
77
|
default: "none"
|
|
74
78
|
},
|
|
75
79
|
startAngle: { type: Number },
|
|
76
|
-
style: { type:
|
|
80
|
+
style: { type: [
|
|
81
|
+
String,
|
|
82
|
+
Object,
|
|
83
|
+
Array
|
|
84
|
+
] },
|
|
77
85
|
syncId: { type: [Number, String] },
|
|
78
86
|
syncMethod: {
|
|
79
87
|
type: [String, Function],
|
|
@@ -98,38 +106,57 @@ function generateCategoricalChart({ chartName, defaultProps = {}, defaultTooltip
|
|
|
98
106
|
eventEmitter: void 0
|
|
99
107
|
} }, props.id ?? chartName) });
|
|
100
108
|
const clipPathId = provideClipPathId(props);
|
|
109
|
+
const responsiveSize = ref({
|
|
110
|
+
width: 0,
|
|
111
|
+
height: 0
|
|
112
|
+
});
|
|
113
|
+
function handleResize(width, height) {
|
|
114
|
+
const roundedWidth = Math.round(width);
|
|
115
|
+
const roundedHeight = Math.round(height);
|
|
116
|
+
if (responsiveSize.value.width === roundedWidth && responsiveSize.value.height === roundedHeight) return;
|
|
117
|
+
responsiveSize.value = {
|
|
118
|
+
width: roundedWidth,
|
|
119
|
+
height: roundedHeight
|
|
120
|
+
};
|
|
121
|
+
}
|
|
101
122
|
return () => {
|
|
102
|
-
const { compact, width, height, title, desc, ...rest } = props;
|
|
123
|
+
const { compact, width, height, title, desc, responsive, ...rest } = props;
|
|
103
124
|
const attributes = { ...attrs };
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
125
|
+
const effectiveWidth = responsive ? responsiveSize.value.width : width;
|
|
126
|
+
const effectiveHeight = responsive ? responsiveSize.value.height : height;
|
|
127
|
+
const hasValidSize = validateWidthHeight({
|
|
128
|
+
width: effectiveWidth,
|
|
129
|
+
height: effectiveHeight
|
|
130
|
+
});
|
|
108
131
|
const layout = props.layout ?? defaultProps.layout ?? defaultLayout;
|
|
109
132
|
const isPolarChart = layout === "centric" || layout === "radial";
|
|
110
|
-
if (compact)
|
|
111
|
-
|
|
112
|
-
createVNode(
|
|
113
|
-
"
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
if (compact) {
|
|
134
|
+
if (!hasValidSize) return null;
|
|
135
|
+
return createVNode(Fragment, null, [
|
|
136
|
+
createVNode(ChartDataContextProvider, { "chartData": props.data }, null),
|
|
137
|
+
createVNode(ReportMainChartProps, {
|
|
138
|
+
"width": effectiveWidth,
|
|
139
|
+
"height": effectiveHeight,
|
|
140
|
+
"layout": layout,
|
|
141
|
+
"margin": props.margin ?? defaultMargin
|
|
142
|
+
}, null),
|
|
143
|
+
isPolarChart && createVNode(ReportPolarOptions, {
|
|
144
|
+
"cx": props.cx ?? "50%",
|
|
145
|
+
"cy": props.cy ?? "50%",
|
|
146
|
+
"startAngle": props.startAngle ?? defaultProps.startAngle ?? 90,
|
|
147
|
+
"endAngle": props.endAngle ?? defaultProps.endAngle ?? -270,
|
|
148
|
+
"innerRadius": props.innerRadius ?? 0,
|
|
149
|
+
"outerRadius": props.outerRadius ?? "80%"
|
|
150
|
+
}, null),
|
|
151
|
+
createVNode(Surface_default, mergeProps(attrs, rest, {
|
|
152
|
+
"width": effectiveWidth,
|
|
153
|
+
"height": effectiveHeight,
|
|
154
|
+
"title": title,
|
|
155
|
+
"desc": desc
|
|
156
|
+
}), { default: () => [createVNode(ClipPath_default, { "clipPathId": clipPathId }, null), slots.default?.()] })
|
|
157
|
+
]);
|
|
158
|
+
}
|
|
159
|
+
if (!responsive && !hasValidSize) return null;
|
|
133
160
|
if (props.accessibilityLayer) {
|
|
134
161
|
attributes.tabindex = props.tabIndex ?? 0;
|
|
135
162
|
attributes.role = props.role ?? "application";
|
|
@@ -139,14 +166,14 @@ function generateCategoricalChart({ chartName, defaultProps = {}, defaultTooltip
|
|
|
139
166
|
for (const [key, value] of Object.entries(attributes)) if (key.startsWith("on") && typeof value === "function") eventHandlerAttrs[key] = value;
|
|
140
167
|
else svgAttributes[key] = value;
|
|
141
168
|
return createVNode(Fragment, null, [
|
|
142
|
-
createVNode(ChartDataContextProvider, { "chartData": props.data }, null),
|
|
143
|
-
createVNode(ReportMainChartProps, {
|
|
144
|
-
"width":
|
|
145
|
-
"height":
|
|
169
|
+
hasValidSize && createVNode(ChartDataContextProvider, { "chartData": props.data }, null),
|
|
170
|
+
hasValidSize && createVNode(ReportMainChartProps, {
|
|
171
|
+
"width": effectiveWidth,
|
|
172
|
+
"height": effectiveHeight,
|
|
146
173
|
"layout": layout,
|
|
147
174
|
"margin": props.margin ?? defaultMargin
|
|
148
175
|
}, null),
|
|
149
|
-
isPolarChart && createVNode(ReportPolarOptions, {
|
|
176
|
+
hasValidSize && isPolarChart && createVNode(ReportPolarOptions, {
|
|
150
177
|
"cx": props.cx ?? "50%",
|
|
151
178
|
"cy": props.cy ?? "50%",
|
|
152
179
|
"startAngle": props.startAngle ?? defaultProps.startAngle ?? 90,
|
|
@@ -154,19 +181,21 @@ function generateCategoricalChart({ chartName, defaultProps = {}, defaultTooltip
|
|
|
154
181
|
"innerRadius": props.innerRadius ?? 0,
|
|
155
182
|
"outerRadius": props.outerRadius ?? "80%"
|
|
156
183
|
}, null),
|
|
157
|
-
createVNode(
|
|
184
|
+
createVNode(ChartsWrapper, mergeProps({
|
|
185
|
+
"responsive": responsive,
|
|
186
|
+
"onResize": handleResize,
|
|
158
187
|
"style": props.style,
|
|
159
188
|
"class": props.class,
|
|
160
|
-
"width":
|
|
161
|
-
"height":
|
|
162
|
-
}, eventHandlerAttrs), { default: () => [createVNode(Surface_default, mergeProps(svgAttributes, {
|
|
163
|
-
"width":
|
|
164
|
-
"height":
|
|
189
|
+
"width": effectiveWidth,
|
|
190
|
+
"height": effectiveHeight
|
|
191
|
+
}, eventHandlerAttrs), { default: () => [hasValidSize && createVNode(Surface_default, mergeProps(svgAttributes, {
|
|
192
|
+
"width": effectiveWidth,
|
|
193
|
+
"height": effectiveHeight,
|
|
165
194
|
"title": title,
|
|
166
195
|
"desc": desc,
|
|
167
196
|
"style": FULL_WIDTH_AND_HEIGHT
|
|
168
197
|
}), { default: () => [createVNode(ClipPath_default, { "clipPathId": clipPathId }, null), slots.default?.()] }), slots.tooltip?.()] }),
|
|
169
|
-
createVNode(ReportChartProps_default, props, null)
|
|
198
|
+
hasValidSize && createVNode(ReportChartProps_default, props, null)
|
|
170
199
|
]);
|
|
171
200
|
};
|
|
172
201
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { toRaw } from "vue";
|
|
2
|
+
import { sankey, sankeyLinkHorizontal } from "d3-sankey";
|
|
3
|
+
//#region src/chart/sankeyUtils.ts
|
|
4
|
+
function computeSankeyLayout(args) {
|
|
5
|
+
const { data, width, height, nodePadding, nodeWidth, iterations, margin } = args;
|
|
6
|
+
const cloned = {
|
|
7
|
+
nodes: data.nodes.map((n) => ({ ...toRaw(n) })),
|
|
8
|
+
links: data.links.map((l) => ({ ...toRaw(l) }))
|
|
9
|
+
};
|
|
10
|
+
const result = sankey().nodeWidth(nodeWidth).nodePadding(nodePadding).extent([[margin.left, margin.top], [Math.max(margin.left + 1, width - margin.right), Math.max(margin.top + 1, height - margin.bottom)]]).iterations(iterations)(cloned);
|
|
11
|
+
const x0Min = margin.left;
|
|
12
|
+
const x1Max = Math.max(margin.left + 1, width - margin.right);
|
|
13
|
+
const y0Min = margin.top;
|
|
14
|
+
const y1Max = Math.max(margin.top + 1, height - margin.bottom);
|
|
15
|
+
for (const n of result.nodes) {
|
|
16
|
+
if (n.x0 != null && n.x0 < x0Min) n.x0 = x0Min;
|
|
17
|
+
if (n.x1 != null && n.x1 > x1Max) n.x1 = x1Max;
|
|
18
|
+
if (n.y0 != null && n.y0 < y0Min) n.y0 = y0Min;
|
|
19
|
+
if (n.y1 != null && n.y1 > y1Max) n.y1 = y1Max;
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
nodes: result.nodes,
|
|
23
|
+
links: result.links
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var linkPathGenerator = sankeyLinkHorizontal();
|
|
27
|
+
//#endregion
|
|
28
|
+
export { computeSankeyLayout, linkPathGenerator };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { hierarchy, partition } from "d3-hierarchy";
|
|
2
|
+
//#region src/chart/sunburstUtils.ts
|
|
3
|
+
/**
|
|
4
|
+
* Record each node's original child index before sorting mutates the order.
|
|
5
|
+
* This ensures tooltipIndex paths point into the original data.children order.
|
|
6
|
+
*/
|
|
7
|
+
function recordOriginalIndices(node) {
|
|
8
|
+
if (node.children) node.children.forEach((child, i) => {
|
|
9
|
+
child._originalIndex = i;
|
|
10
|
+
recordOriginalIndices(child);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Build a hierarchical tooltip index path string for a d3 hierarchy node.
|
|
15
|
+
* Uses _originalIndex (pre-sort) so the path matches the original data structure.
|
|
16
|
+
* E.g. 'children[0].children[1]'
|
|
17
|
+
*/
|
|
18
|
+
function buildTooltipIndex(node) {
|
|
19
|
+
const parts = [];
|
|
20
|
+
let current = node;
|
|
21
|
+
while (current.parent) {
|
|
22
|
+
const idx = current._originalIndex ?? current.parent.children.indexOf(current);
|
|
23
|
+
parts.unshift(`children[${idx}]`);
|
|
24
|
+
current = current.parent;
|
|
25
|
+
}
|
|
26
|
+
return parts.join(".");
|
|
27
|
+
}
|
|
28
|
+
function computeSunburstLayout(options) {
|
|
29
|
+
const { data, cx, cy, innerRadius, outerRadius, startAngle, endAngle, dataKey, ringPadding = 0, padding = 0 } = options;
|
|
30
|
+
if (!data.children || data.children.length === 0) return [];
|
|
31
|
+
const root = hierarchy(data).sum((d) => {
|
|
32
|
+
if (d.children && d.children.length > 0) return 0;
|
|
33
|
+
const val = d[dataKey];
|
|
34
|
+
return typeof val === "number" && val > 0 ? val : 0;
|
|
35
|
+
});
|
|
36
|
+
recordOriginalIndices(root);
|
|
37
|
+
root.sort((a, b) => (b.value ?? 0) - (a.value ?? 0));
|
|
38
|
+
partition().size([1, 1])(root);
|
|
39
|
+
const angleRange = endAngle - startAngle;
|
|
40
|
+
const radiusRange = outerRadius - innerRadius;
|
|
41
|
+
const nodes = [];
|
|
42
|
+
root.descendants().forEach((d) => {
|
|
43
|
+
if (d.depth === 0) return;
|
|
44
|
+
const nodeStartAngle = startAngle + d.x0 * angleRange + padding / 2;
|
|
45
|
+
const nodeEndAngle = startAngle + d.x1 * angleRange - padding / 2;
|
|
46
|
+
const nodeInnerRadius = innerRadius + d.y0 * radiusRange + ringPadding / 2;
|
|
47
|
+
const nodeOuterRadius = innerRadius + d.y1 * radiusRange - ringPadding / 2;
|
|
48
|
+
if (nodeEndAngle <= nodeStartAngle || nodeOuterRadius <= nodeInnerRadius) return;
|
|
49
|
+
nodes.push({
|
|
50
|
+
cx,
|
|
51
|
+
cy,
|
|
52
|
+
innerRadius: nodeInnerRadius,
|
|
53
|
+
outerRadius: nodeOuterRadius,
|
|
54
|
+
startAngle: nodeStartAngle,
|
|
55
|
+
endAngle: nodeEndAngle,
|
|
56
|
+
depth: d.depth,
|
|
57
|
+
name: d.data.name,
|
|
58
|
+
value: d.value ?? 0,
|
|
59
|
+
fill: d.data.fill,
|
|
60
|
+
payload: d.data,
|
|
61
|
+
tooltipIndex: buildTooltipIndex(d)
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
return nodes;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { computeSunburstLayout };
|
|
@@ -8,17 +8,17 @@ import { selectActiveCoordinate, selectActiveLabel, selectIsTooltipActive, selec
|
|
|
8
8
|
import { Rectangle } from "../shape/Rectangle.mjs";
|
|
9
9
|
import { useCursorLayerRef } from "../context/cursorLayerContext.mjs";
|
|
10
10
|
import { usePortal } from "../chart/TooltipPortalContext.mjs";
|
|
11
|
+
import { Sector } from "../shape/Sector.mjs";
|
|
11
12
|
import { useAccessibilityLayer } from "../context/accessibilityContext.mjs";
|
|
12
13
|
import { getTooltipTranslate } from "../utils/tooltip/translate.mjs";
|
|
13
14
|
import { Cross } from "../shape/Cross.mjs";
|
|
14
|
-
import { Sector } from "../shape/Sector.mjs";
|
|
15
15
|
import { getCursorPoints } from "./utils.mjs";
|
|
16
16
|
import { useTooltipAxisBandSize } from "../context/useTooltipAxis.mjs";
|
|
17
17
|
import { useTooltipChartSynchronisation } from "../synchronisation/useChartSynchronisation.mjs";
|
|
18
18
|
import { Fragment, Teleport, computed, createVNode, defineComponent, isVNode, reactive, ref, watch, watchEffect, watchPostEffect } from "vue";
|
|
19
19
|
import { sortBy, uniqBy } from "es-toolkit/compat";
|
|
20
20
|
import { animate } from "motion-v";
|
|
21
|
-
import {
|
|
21
|
+
import { useMagicKeys, usePreferredReducedMotion } from "@vueuse/core";
|
|
22
22
|
//#region src/components/Tooltip.tsx
|
|
23
23
|
function _isSlot(s) {
|
|
24
24
|
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
@@ -148,7 +148,10 @@ var TooltipBoundingBox = /* @__PURE__ */ defineComponent({
|
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
150
|
const el = ref();
|
|
151
|
-
const
|
|
151
|
+
const tooltipSize = ref({
|
|
152
|
+
width: 0,
|
|
153
|
+
height: 0
|
|
154
|
+
});
|
|
152
155
|
let preTransform;
|
|
153
156
|
let animationControls;
|
|
154
157
|
const reducedMotion = usePreferredReducedMotion();
|
|
@@ -161,13 +164,13 @@ var TooltipBoundingBox = /* @__PURE__ */ defineComponent({
|
|
|
161
164
|
position,
|
|
162
165
|
reverseDirection,
|
|
163
166
|
tooltipBox: {
|
|
164
|
-
height:
|
|
165
|
-
width:
|
|
167
|
+
height: tooltipSize.value.height,
|
|
168
|
+
width: tooltipSize.value.width
|
|
166
169
|
},
|
|
167
170
|
useTranslate3d: false,
|
|
168
171
|
viewBox
|
|
169
172
|
});
|
|
170
|
-
transform = !
|
|
173
|
+
transform = !tooltipSize.value.height && preTransform ? preTransform : transform;
|
|
171
174
|
preTransform = transform || preTransform;
|
|
172
175
|
return {
|
|
173
176
|
cssClasses,
|
|
@@ -181,6 +184,12 @@ var TooltipBoundingBox = /* @__PURE__ */ defineComponent({
|
|
|
181
184
|
if (!element || !transform?.transform) return;
|
|
182
185
|
if (props.isAnimationActive && reducedMotion.value !== "reduce") animationControls = animate(element, { transform: transform.transform }, props.transition);
|
|
183
186
|
else element.style.transform = transform.transform;
|
|
187
|
+
const width = element.offsetWidth;
|
|
188
|
+
const height = element.offsetHeight;
|
|
189
|
+
if (height > 0 && (width !== tooltipSize.value.width || height !== tooltipSize.value.height)) tooltipSize.value = {
|
|
190
|
+
width,
|
|
191
|
+
height
|
|
192
|
+
};
|
|
184
193
|
onCleanup(() => {
|
|
185
194
|
animationControls?.stop();
|
|
186
195
|
animationControls = void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isPercent } from "../utils/validate.mjs";
|
|
2
2
|
import { normalizeStyle as normalizeStyle$1 } from "../utils/style.mjs";
|
|
3
3
|
import { provideSizeContext } from "./useSizeContext.mjs";
|
|
4
|
-
import { Fragment, cloneVNode, computed,
|
|
4
|
+
import { Fragment, cloneVNode, computed, createElementBlock, createVNode, defineComponent, normalizeClass, normalizeStyle, onMounted, onUnmounted, openBlock, ref, toRef, useSlots } from "vue";
|
|
5
5
|
import { useThrottleFn } from "@vueuse/core";
|
|
6
6
|
//#region src/container/ResponsiveContainer.vue?vue&type=script&setup=true&lang.ts
|
|
7
7
|
var _hoisted_1 = ["id"];
|
|
@@ -119,6 +119,19 @@ var ResponsiveContainer_vue_vue_type_script_setup_true_lang_default = /* @__PURE
|
|
|
119
119
|
});
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Rendering the children through `<component :is="() => renderChildren()" />` would
|
|
124
|
+
* create a new component type on every render, so Vue unmounts and remounts the whole
|
|
125
|
+
* chart subtree each time. Charts that dispatch on `mouseenter` (radial bar, radar) then
|
|
126
|
+
* loop forever: the remount recreates the element under the cursor, which fires
|
|
127
|
+
* `mouseenter` again. This renderer keeps a stable type, so the subtree is patched.
|
|
128
|
+
*/
|
|
129
|
+
const ChildrenRenderer = (rendererProps) => rendererProps.nodes;
|
|
130
|
+
ChildrenRenderer.props = { nodes: {
|
|
131
|
+
type: Array,
|
|
132
|
+
required: true
|
|
133
|
+
} };
|
|
134
|
+
ChildrenRenderer.inheritAttrs = false;
|
|
122
135
|
const containerStyle = computed(() => ({
|
|
123
136
|
...props.style,
|
|
124
137
|
...normalizeStyle$1({
|
|
@@ -136,7 +149,7 @@ var ResponsiveContainer_vue_vue_type_script_setup_true_lang_default = /* @__PURE
|
|
|
136
149
|
ref: containerRef,
|
|
137
150
|
class: normalizeClass(["vcharts-responsive-container", [props.class]]),
|
|
138
151
|
style: normalizeStyle(containerStyle.value)
|
|
139
|
-
}, [(
|
|
152
|
+
}, [createVNode(ChildrenRenderer, { nodes: renderChildren() ?? [] }, null, 8, ["nodes"])], 14, _hoisted_1);
|
|
140
153
|
};
|
|
141
154
|
}
|
|
142
155
|
});
|
package/dist/es/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Global } from "./utils/Global.mjs";
|
|
1
2
|
import { Curve, CurveVueProps, getPath } from "./shape/Curve.mjs";
|
|
2
3
|
import { useActiveTooltipDataPoints } from "./state/hooks.mjs";
|
|
3
4
|
import { useChartHeight, useChartWidth, useMargin, useOffset } from "./context/chartLayoutContext.mjs";
|
|
@@ -36,11 +37,13 @@ import { ScatterChart } from "./chart/ScatterChart.mjs";
|
|
|
36
37
|
import { RadialBarChart } from "./chart/RadialBarChart.mjs";
|
|
37
38
|
import { FunnelChart } from "./chart/FunnelChart.mjs";
|
|
38
39
|
import { Treemap, TreemapVueProps, treemapPayloadSearcher } from "./chart/Treemap.mjs";
|
|
40
|
+
import { Sankey, SankeyVueProps, sankeyPayloadSearcher } from "./chart/Sankey.mjs";
|
|
41
|
+
import { Sector } from "./shape/Sector.mjs";
|
|
42
|
+
import { SunburstChart, SunburstChartVueProps, sunburstPayloadSearcher } from "./chart/SunburstChart.mjs";
|
|
39
43
|
import ResponsiveContainer_default from "./container/ResponsiveContainer.mjs";
|
|
40
44
|
import { Customized } from "./components/Customized.mjs";
|
|
41
45
|
import Legend_default from "./components/legend/Legend.mjs";
|
|
42
46
|
import { Cross } from "./shape/Cross.mjs";
|
|
43
|
-
import { Sector } from "./shape/Sector.mjs";
|
|
44
47
|
import Tooltip, { getUniqPayload } from "./components/Tooltip.mjs";
|
|
45
48
|
import { PieVueProps } from "./polar/pie/type.mjs";
|
|
46
49
|
import { Pie } from "./polar/pie/Pie.mjs";
|
|
@@ -51,4 +54,4 @@ import { PolarRadiusAxis } from "./polar/radar/PolarRadiusAxis.mjs";
|
|
|
51
54
|
import { RadialBar } from "./polar/radial-bar/RadialBar.mjs";
|
|
52
55
|
import { Polygon } from "./shape/Polygon.mjs";
|
|
53
56
|
import { useActiveTooltipCoordinate, useActiveTooltipLabel, useCartesianScale, useIsTooltipActive, usePlotArea, useXAxisDomain, useXAxisInverseDataSnapScale, useXAxisInverseScale, useXAxisInverseTickSnapScale, useXAxisScale, useXAxisTicks, useYAxisDomain, useYAxisInverseDataSnapScale, useYAxisInverseScale, useYAxisInverseTickSnapScale, useYAxisScale, useYAxisTicks } from "./hooks/publicHooks.mjs";
|
|
54
|
-
export { Area, AreaChart, Bar, BarChart, CartesianAxis, CartesianGrid, Cell, ComposedChart, Cross, Curve, CurveVueProps, Customized, Dot, ErrorBar, ErrorBarVueProps, Funnel, FunnelChart, FunnelVueProps, Label, LabelList, Legend_default as Legend, Line, LineChart, LineContextKey, Pie, PieChart, PieVueProps, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Polygon, Radar, RadarChart, RadialBar, RadialBarChart, Rectangle, ReferenceArea, ReferenceDot, ReferenceLine, ResponsiveContainer_default as ResponsiveContainer, Scatter, ScatterChart, Sector, Symbols, Text_default as Text, Tooltip, Trapezoid, Treemap, TreemapVueProps, XAxis, YAxis, ZAxis, createErrorBarRegistry, getPath, getUniqPayload, provideErrorBarContext, provideErrorBarRegistry, provideLineContext, treemapPayloadSearcher, useActiveTooltipCoordinate, useActiveTooltipDataPoints, useActiveTooltipLabel, useCartesianScale, useChartHeight, useChartWidth, useErrorBarContext, useErrorBarRegistry, useIsTooltipActive, useLine, useLineContext, useMargin, useOffset, usePlotArea, useXAxisDomain, useXAxisInverseDataSnapScale, useXAxisInverseScale, useXAxisInverseTickSnapScale, useXAxisScale, useXAxisTicks, useYAxisDomain, useYAxisInverseDataSnapScale, useYAxisInverseScale, useYAxisInverseTickSnapScale, useYAxisScale, useYAxisTicks };
|
|
57
|
+
export { Area, AreaChart, Bar, BarChart, CartesianAxis, CartesianGrid, Cell, ComposedChart, Cross, Curve, CurveVueProps, Customized, Dot, ErrorBar, ErrorBarVueProps, Funnel, FunnelChart, FunnelVueProps, Global, Label, LabelList, Legend_default as Legend, Line, LineChart, LineContextKey, Pie, PieChart, PieVueProps, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Polygon, Radar, RadarChart, RadialBar, RadialBarChart, Rectangle, ReferenceArea, ReferenceDot, ReferenceLine, ResponsiveContainer_default as ResponsiveContainer, Sankey, SankeyVueProps, Scatter, ScatterChart, Sector, SunburstChart, SunburstChartVueProps, Symbols, Text_default as Text, Tooltip, Trapezoid, Treemap, TreemapVueProps, XAxis, YAxis, ZAxis, createErrorBarRegistry, getPath, getUniqPayload, provideErrorBarContext, provideErrorBarRegistry, provideLineContext, sankeyPayloadSearcher, sunburstPayloadSearcher, treemapPayloadSearcher, useActiveTooltipCoordinate, useActiveTooltipDataPoints, useActiveTooltipLabel, useCartesianScale, useChartHeight, useChartWidth, useErrorBarContext, useErrorBarRegistry, useIsTooltipActive, useLine, useLineContext, useMargin, useOffset, usePlotArea, useXAxisDomain, useXAxisInverseDataSnapScale, useXAxisInverseScale, useXAxisInverseTickSnapScale, useXAxisScale, useXAxisTicks, useYAxisDomain, useYAxisInverseDataSnapScale, useYAxisInverseScale, useYAxisInverseTickSnapScale, useYAxisScale, useYAxisTicks };
|
|
@@ -120,7 +120,7 @@ var Pie = /* @__PURE__ */ defineComponent({
|
|
|
120
120
|
"isActive": props.isAnimationActive,
|
|
121
121
|
"from": 0,
|
|
122
122
|
"to": 1,
|
|
123
|
-
"transition":
|
|
123
|
+
"transition": props.transition
|
|
124
124
|
}, { default: (progress) => {
|
|
125
125
|
let curAngle = sectorList[0]?.startAngle ?? 0;
|
|
126
126
|
const sectorNodes = sectorList.map((sector, i) => {
|
|
@@ -115,6 +115,13 @@ var Radar = /* @__PURE__ */ defineComponent({
|
|
|
115
115
|
type: Boolean,
|
|
116
116
|
default: true
|
|
117
117
|
},
|
|
118
|
+
transition: {
|
|
119
|
+
type: Object,
|
|
120
|
+
default: () => ({
|
|
121
|
+
duration: .8,
|
|
122
|
+
ease: "easeOut"
|
|
123
|
+
})
|
|
124
|
+
},
|
|
118
125
|
activeDot: {
|
|
119
126
|
type: [Object, Boolean],
|
|
120
127
|
default: true
|
|
@@ -175,7 +182,7 @@ var Radar = /* @__PURE__ */ defineComponent({
|
|
|
175
182
|
let prevPoints = null;
|
|
176
183
|
let prevBaseLinePoints = null;
|
|
177
184
|
let animationId = 0;
|
|
178
|
-
let lastData
|
|
185
|
+
let lastData;
|
|
179
186
|
const renderPolygon = (points, baseLinePoints, isRange) => {
|
|
180
187
|
const stroke = props.stroke ?? props.fill;
|
|
181
188
|
const hasStroke = stroke && stroke !== "none";
|
|
@@ -259,6 +266,7 @@ var Radar = /* @__PURE__ */ defineComponent({
|
|
|
259
266
|
createVNode(Animate, {
|
|
260
267
|
"key": animationId,
|
|
261
268
|
"isActive": true,
|
|
269
|
+
"transition": props.transition,
|
|
262
270
|
"onAnimationStart": () => {
|
|
263
271
|
isAnimating.value = true;
|
|
264
272
|
},
|
|
@@ -25,6 +25,17 @@ var cartesianAxisSlice = createSlice({
|
|
|
25
25
|
removeYAxis(state, action) {
|
|
26
26
|
delete state.yAxis[action.payload.id];
|
|
27
27
|
},
|
|
28
|
+
updateYAxisWidth(state, action) {
|
|
29
|
+
const { id, width } = action.payload;
|
|
30
|
+
const axis = state.yAxis[id];
|
|
31
|
+
if (axis) {
|
|
32
|
+
const history = axis.widthHistory || [];
|
|
33
|
+
if (history.length === 3 && history[0] === history[2] && width === history[1] && width !== axis.width && Math.abs(width - (history[0] ?? 0)) <= 1) return;
|
|
34
|
+
const newHistory = [...history, width].slice(-3);
|
|
35
|
+
axis.width = width;
|
|
36
|
+
axis.widthHistory = newHistory;
|
|
37
|
+
}
|
|
38
|
+
},
|
|
28
39
|
addZAxis(state, action) {
|
|
29
40
|
state.zAxis[action.payload.id] = castDraft(action.payload);
|
|
30
41
|
},
|
|
@@ -33,7 +44,7 @@ var cartesianAxisSlice = createSlice({
|
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
});
|
|
36
|
-
var { addXAxis, removeXAxis, addYAxis, removeYAxis, addZAxis, removeZAxis } = cartesianAxisSlice.actions;
|
|
47
|
+
var { addXAxis, removeXAxis, addYAxis, removeYAxis, addZAxis, removeZAxis, updateYAxisWidth } = cartesianAxisSlice.actions;
|
|
37
48
|
var cartesianAxisReducer = cartesianAxisSlice.reducer;
|
|
38
49
|
//#endregion
|
|
39
|
-
export { addXAxis, addYAxis, addZAxis, cartesianAxisReducer, removeXAxis, removeYAxis, removeZAxis };
|
|
50
|
+
export { addXAxis, addYAxis, addZAxis, cartesianAxisReducer, removeXAxis, removeYAxis, removeZAxis, updateYAxisWidth };
|
|
@@ -639,7 +639,7 @@ function getXAxisSize(offset, axisSettings) {
|
|
|
639
639
|
}
|
|
640
640
|
function getYAxisSize(offset, axisSettings) {
|
|
641
641
|
return {
|
|
642
|
-
width: axisSettings.width,
|
|
642
|
+
width: typeof axisSettings.width === "number" ? axisSettings.width : 60,
|
|
643
643
|
height: offset.height
|
|
644
644
|
};
|
|
645
645
|
}
|
|
@@ -712,7 +712,7 @@ function selectYAxisPosition(state, axisId) {
|
|
|
712
712
|
}
|
|
713
713
|
var selectYAxisSize = createSelector(selectChartOffset, selectYAxisSettings, (offset, axisSettings) => {
|
|
714
714
|
return {
|
|
715
|
-
width: axisSettings.width,
|
|
715
|
+
width: typeof axisSettings.width === "number" ? axisSettings.width : 60,
|
|
716
716
|
height: offset.height
|
|
717
717
|
};
|
|
718
718
|
});
|
|
@@ -18,10 +18,13 @@ var selectChartOffset = createSelector([
|
|
|
18
18
|
], (chartWidth, chartHeight, margin, brushHeight, xAxes, yAxes, legendSettings, legendSize) => {
|
|
19
19
|
const offsetH = yAxes.reduce((result, entry) => {
|
|
20
20
|
const { orientation } = entry;
|
|
21
|
-
if (!entry.mirror && !entry.hide)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if (!entry.mirror && !entry.hide) {
|
|
22
|
+
const width = typeof entry.width === "number" ? entry.width : 60;
|
|
23
|
+
return {
|
|
24
|
+
...result,
|
|
25
|
+
[orientation]: result[orientation] + width
|
|
26
|
+
};
|
|
27
|
+
}
|
|
25
28
|
return result;
|
|
26
29
|
}, {
|
|
27
30
|
left: margin.left || 0,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { DATA_ITEM_DATAKEY_ATTRIBUTE_NAME, DATA_ITEM_INDEX_ATTRIBUTE_NAME } from "../utils/const.mjs";
|
|
1
2
|
import { getChartPointer } from "../utils/chart.mjs";
|
|
2
3
|
import { selectTooltipEventType } from "./selectors/selectTooltipEventType.mjs";
|
|
3
4
|
import { setActiveMouseOverItemIndex, setMouseOverAxisIndex } from "./tooltipSlice.mjs";
|
|
4
|
-
import { DATA_ITEM_DATAKEY_ATTRIBUTE_NAME, DATA_ITEM_INDEX_ATTRIBUTE_NAME } from "../utils/const.mjs";
|
|
5
5
|
import { selectActivePropsFromChartPointer } from "./selectors/selectActivePropsFromChartPointer.mjs";
|
|
6
6
|
import { selectTooltipCoordinate } from "./selectors/touchSelectors.mjs";
|
|
7
7
|
import { createAction, createListenerMiddleware } from "@reduxjs/toolkit";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/utils/Global.ts
|
|
2
|
+
function parseIsSsrByDefault() {
|
|
3
|
+
return typeof window === "undefined";
|
|
4
|
+
}
|
|
5
|
+
var Global = {
|
|
6
|
+
isSsr: parseIsSsrByDefault(),
|
|
7
|
+
get(key) {
|
|
8
|
+
return Global[key];
|
|
9
|
+
},
|
|
10
|
+
set(key, value) {
|
|
11
|
+
if (typeof key === "string") Global[key] = value;
|
|
12
|
+
else Object.keys(key).forEach((k) => {
|
|
13
|
+
Global[k] = key[k];
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { Global };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/utils/YAxisUtils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the width of the Y-axis based on the tick labels and the axis label.
|
|
4
|
+
* @param params - The parameters object.
|
|
5
|
+
* @param [params.ticks] - An array-like object of tick elements, each with a `getBoundingClientRect` method.
|
|
6
|
+
* @param [params.label] - The axis label element, with a `getBoundingClientRect` method.
|
|
7
|
+
* @param [params.labelGapWithTick] - The gap between the label and the tick.
|
|
8
|
+
* @param [params.tickSize] - The length of the tick line.
|
|
9
|
+
* @param [params.tickMargin] - The margin between the tick line and the tick text.
|
|
10
|
+
* @returns The calculated width of the Y-axis.
|
|
11
|
+
*/
|
|
12
|
+
function getCalculatedYAxisWidth({ ticks, label, labelGapWithTick = 5, tickSize = 0, tickMargin = 0 }) {
|
|
13
|
+
let maxTickWidth = 0;
|
|
14
|
+
if (ticks) {
|
|
15
|
+
Array.from(ticks).forEach((tickNode) => {
|
|
16
|
+
if (tickNode) {
|
|
17
|
+
const bbox = tickNode.getBoundingClientRect();
|
|
18
|
+
if (bbox.width > maxTickWidth) maxTickWidth = bbox.width;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const labelWidth = label ? label.getBoundingClientRect().width : 0;
|
|
22
|
+
const tickWidth = (tickSize ?? 0) + (tickMargin ?? 0);
|
|
23
|
+
const updatedYAxisWidth = maxTickWidth + tickWidth + labelWidth + (label ? labelGapWithTick : 0);
|
|
24
|
+
return Math.round(updatedYAxisWidth);
|
|
25
|
+
}
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { getCalculatedYAxisWidth };
|
package/dist/es/utils/attrs.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Global } from "./Global.mjs";
|
|
2
2
|
//#region src/utils/attrs.ts
|
|
3
3
|
var stringCache = {
|
|
4
4
|
widthCache: {},
|
|
@@ -23,7 +23,7 @@ function removeInvalidKeys(obj) {
|
|
|
23
23
|
return copyObj;
|
|
24
24
|
}
|
|
25
25
|
function getStringSize(text, style = {}) {
|
|
26
|
-
if (text === void 0 || text === null || isSsr) return {
|
|
26
|
+
if (text === void 0 || text === null || Global.isSsr) return {
|
|
27
27
|
width: 0,
|
|
28
28
|
height: 0
|
|
29
29
|
};
|
|
@@ -28,7 +28,6 @@ function isVisible(sign, tickPosition, getSize, start, end) {
|
|
|
28
28
|
const size = getSize();
|
|
29
29
|
return sign * (tickPosition - sign * size / 2 - start) >= 0 && sign * (tickPosition + sign * size / 2 - end) <= 0;
|
|
30
30
|
}
|
|
31
|
-
var isSsr = typeof window === "undefined";
|
|
32
31
|
/**
|
|
33
32
|
* Checks if the value is null or undefined
|
|
34
33
|
* @param {any} value The value to check
|
|
@@ -39,4 +38,4 @@ function isNullish(value) {
|
|
|
39
38
|
}
|
|
40
39
|
var isNumOrStr = (value) => isNumber(value) || typeof value === "string";
|
|
41
40
|
//#endregion
|
|
42
|
-
export { isCategoricalAxis, isNan, isNullish, isNumOrStr, isNumber, isPercent,
|
|
41
|
+
export { isCategoricalAxis, isNan, isNullish, isNumOrStr, isNumber, isPercent, isVisible, isWellBehavedNumber, validateWidthHeight };
|