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.
Files changed (56) hide show
  1. package/README.md +4 -0
  2. package/dist/cartesian/axis/YAxis.d.ts +5 -5
  3. package/dist/cartesian/cartesian-axis/CartesianAxis.d.ts +11 -0
  4. package/dist/chart/{RechartsWrapper.d.ts → ChartsWrapper.d.ts} +19 -4
  5. package/dist/chart/Sankey.d.ts +327 -0
  6. package/dist/chart/SunburstChart.d.ts +249 -0
  7. package/dist/chart/Surface.d.ts +2 -2
  8. package/dist/chart/generateCategoricalChart.d.ts +6 -2
  9. package/dist/chart/index.d.ts +2 -0
  10. package/dist/chart/sankeyUtils.d.ts +36 -0
  11. package/dist/chart/sunburstUtils.d.ts +34 -0
  12. package/dist/container/Surface.d.ts +3 -3
  13. package/dist/es/cartesian/axis/YAxis.mjs +52 -5
  14. package/dist/es/cartesian/cartesian-axis/CartesianAxis.mjs +6 -1
  15. package/dist/es/cartesian/utils/get-ticks.mjs +3 -2
  16. package/dist/es/chart/{RechartsWrapper.mjs → ChartsWrapper.mjs} +37 -10
  17. package/dist/es/chart/Sankey.mjs +332 -0
  18. package/dist/es/chart/SunburstChart.mjs +229 -0
  19. package/dist/es/chart/Surface.vue_vue_type_script_setup_true_lang.mjs +7 -1
  20. package/dist/es/chart/Treemap.mjs +2 -2
  21. package/dist/es/chart/generateCategoricalChart.mjs +72 -43
  22. package/dist/es/chart/sankeyUtils.mjs +28 -0
  23. package/dist/es/chart/sunburstUtils.mjs +67 -0
  24. package/dist/es/components/Tooltip.mjs +15 -6
  25. package/dist/es/container/ResponsiveContainer.vue_vue_type_script_setup_true_lang.mjs +15 -2
  26. package/dist/es/container/Surface.mjs +5 -1
  27. package/dist/es/index.mjs +5 -2
  28. package/dist/es/polar/pie/Pie.mjs +1 -1
  29. package/dist/es/polar/pie/type.mjs +7 -0
  30. package/dist/es/polar/radar/Radar.mjs +9 -1
  31. package/dist/es/polar/radial-bar/RadialBar.mjs +1 -0
  32. package/dist/es/polar/radial-bar/type.mjs +7 -0
  33. package/dist/es/state/cartesianAxisSlice.mjs +13 -2
  34. package/dist/es/state/selectors/axisSelectors.mjs +2 -2
  35. package/dist/es/state/selectors/selectChartOffset.mjs +7 -4
  36. package/dist/es/state/touchEventsMiddleware.mjs +1 -1
  37. package/dist/es/utils/Global.mjs +18 -0
  38. package/dist/es/utils/YAxisUtils.mjs +29 -0
  39. package/dist/es/utils/attrs.mjs +2 -2
  40. package/dist/es/utils/validate.mjs +1 -2
  41. package/dist/hooks/publicHooks.d.ts +1 -1
  42. package/dist/index.d.ts +2 -0
  43. package/dist/polar/pie/type.d.ts +8 -0
  44. package/dist/polar/radar/Radar.d.ts +16 -0
  45. package/dist/polar/radial-bar/type.d.ts +8 -0
  46. package/dist/state/cartesianAxisSlice.d.ts +11 -3
  47. package/dist/state/selectors/combiners/combineActiveLabel.d.ts +1 -1
  48. package/dist/state/selectors/selectors.d.ts +1 -1
  49. package/dist/state/selectors/tooltipSelectors.d.ts +1 -1
  50. package/dist/types/axis.d.ts +11 -1
  51. package/dist/types/common.d.ts +1 -1
  52. package/dist/utils/Global.d.ts +9 -0
  53. package/dist/utils/YAxisUtils.d.ts +20 -0
  54. package/dist/utils/index.d.ts +1 -0
  55. package/dist/utils/validate.d.ts +0 -1
  56. package/package.json +3 -1
@@ -1,4 +1,4 @@
1
- import { CSSProperties } from 'vue';
1
+ import { StyleValue } from 'vue';
2
2
  import { VueClassValue } from '../types';
3
3
  interface SurfaceProps {
4
4
  width: number;
@@ -10,7 +10,7 @@ interface SurfaceProps {
10
10
  height?: number;
11
11
  };
12
12
  class?: VueClassValue;
13
- style?: CSSProperties;
13
+ style?: StyleValue;
14
14
  title?: string;
15
15
  desc?: string;
16
16
  }
@@ -1,5 +1,5 @@
1
1
  import { DataKey, LayoutType, Margin, StackOffsetType, SyncMethod, VuePropsToType, WithSVGProps } from '../types';
2
- import { PropType } from 'vue';
2
+ import { PropType, StyleValue } from 'vue';
3
3
  import { TooltipEventType } from '../types/tooltip';
4
4
  import { ChartData } from '../state/chartDataSlice';
5
5
  export declare const CategoricalProps: {
@@ -67,6 +67,10 @@ export declare const CategoricalProps: {
67
67
  outerRadius: {
68
68
  type: (NumberConstructor | StringConstructor)[];
69
69
  };
70
+ responsive: {
71
+ type: BooleanConstructor;
72
+ default: boolean;
73
+ };
70
74
  reverseStackOrder: {
71
75
  type: BooleanConstructor;
72
76
  default: boolean;
@@ -82,7 +86,7 @@ export declare const CategoricalProps: {
82
86
  type: NumberConstructor;
83
87
  };
84
88
  style: {
85
- type: ObjectConstructor;
89
+ type: PropType<StyleValue>;
86
90
  };
87
91
  syncId: {
88
92
  type: (NumberConstructor | StringConstructor)[];
@@ -8,3 +8,5 @@ export * from './ScatterChart';
8
8
  export * from './RadialBarChart';
9
9
  export * from './FunnelChart';
10
10
  export * from './Treemap';
11
+ export * from './Sankey';
12
+ export * from './SunburstChart';
@@ -0,0 +1,36 @@
1
+ import { SankeyLink, SankeyNode } from 'd3-sankey';
2
+ export interface SankeyInputNode {
3
+ name?: string;
4
+ [key: string]: any;
5
+ }
6
+ export interface SankeyInputLink {
7
+ source: number | string;
8
+ target: number | string;
9
+ value: number;
10
+ [key: string]: any;
11
+ }
12
+ export type SankeyLayoutNode = SankeyNode<SankeyInputNode, SankeyInputLink>;
13
+ export type SankeyLayoutLink = SankeyLink<SankeyInputNode, SankeyInputLink>;
14
+ export interface ComputeSankeyLayoutArgs {
15
+ data: {
16
+ nodes: SankeyInputNode[];
17
+ links: SankeyInputLink[];
18
+ };
19
+ width: number;
20
+ height: number;
21
+ nodePadding: number;
22
+ nodeWidth: number;
23
+ iterations: number;
24
+ margin: {
25
+ top: number;
26
+ right: number;
27
+ bottom: number;
28
+ left: number;
29
+ };
30
+ }
31
+ export interface ComputeSankeyLayoutResult {
32
+ nodes: SankeyLayoutNode[];
33
+ links: SankeyLayoutLink[];
34
+ }
35
+ export declare function computeSankeyLayout(args: ComputeSankeyLayoutArgs): ComputeSankeyLayoutResult;
36
+ export declare const linkPathGenerator: (link: SankeyLayoutLink) => string | null;
@@ -0,0 +1,34 @@
1
+ export interface SunburstData {
2
+ [key: string]: any;
3
+ name: string;
4
+ value?: number;
5
+ fill?: string;
6
+ children?: SunburstData[];
7
+ }
8
+ export interface SunburstLayoutNode {
9
+ cx: number;
10
+ cy: number;
11
+ innerRadius: number;
12
+ outerRadius: number;
13
+ startAngle: number;
14
+ endAngle: number;
15
+ depth: number;
16
+ name: string;
17
+ value: number;
18
+ fill?: string;
19
+ payload: SunburstData;
20
+ tooltipIndex: string;
21
+ }
22
+ export interface SunburstLayoutOptions {
23
+ data: SunburstData;
24
+ cx: number;
25
+ cy: number;
26
+ innerRadius: number;
27
+ outerRadius: number;
28
+ startAngle: number;
29
+ endAngle: number;
30
+ dataKey: string;
31
+ ringPadding?: number;
32
+ padding?: number;
33
+ }
34
+ export declare function computeSunburstLayout(options: SunburstLayoutOptions): SunburstLayoutNode[];
@@ -1,4 +1,4 @@
1
- import { CSSProperties, SVGAttributes } from 'vue';
1
+ import { SVGAttributes, StyleValue } from 'vue';
2
2
  import { VueClassValue } from '../types';
3
3
  interface ViewBox {
4
4
  x?: number;
@@ -11,7 +11,7 @@ declare const Surface: import('vue').DefineComponent<Omit<SVGAttributes, "viewBo
11
11
  height: number;
12
12
  viewBox?: ViewBox;
13
13
  class?: VueClassValue;
14
- style?: CSSProperties;
14
+ style?: StyleValue;
15
15
  title?: string;
16
16
  desc?: string;
17
17
  }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<Omit<SVGAttributes, "viewBox"> & {
@@ -19,7 +19,7 @@ declare const Surface: import('vue').DefineComponent<Omit<SVGAttributes, "viewBo
19
19
  height: number;
20
20
  viewBox?: ViewBox;
21
21
  class?: VueClassValue;
22
- style?: CSSProperties;
22
+ style?: StyleValue;
23
23
  title?: string;
24
24
  desc?: string;
25
25
  }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
@@ -2,9 +2,10 @@ import { useIsPanorama } from "../../context/PanoramaContextProvider.mjs";
2
2
  import { selectAxisViewBox } from "../../state/selectors/selectChartOffset.mjs";
3
3
  import { implicitYAxis, selectAxisScale, selectTicksOfAxis, selectYAxisPosition, selectYAxisSize } from "../../state/selectors/axisSelectors.mjs";
4
4
  import { useAppDispatch, useAppSelector } from "../../state/hooks.mjs";
5
- import { addYAxis, removeYAxis } from "../../state/cartesianAxisSlice.mjs";
5
+ import { addYAxis, removeYAxis, updateYAxisWidth } from "../../state/cartesianAxisSlice.mjs";
6
6
  import { CartesianAxis } from "../cartesian-axis/CartesianAxis.mjs";
7
- import { createVNode, defineComponent, mergeProps, watchEffect } from "vue";
7
+ import { getCalculatedYAxisWidth } from "../../utils/YAxisUtils.mjs";
8
+ import { createVNode, defineComponent, isVNode, mergeProps, nextTick, ref, watch, watchEffect } from "vue";
8
9
  //#region src/cartesian/axis/YAxis.tsx
9
10
  var YAxisImpl = /* @__PURE__ */ defineComponent({
10
11
  props: { yAxisId: {
@@ -15,11 +16,55 @@ var YAxisImpl = /* @__PURE__ */ defineComponent({
15
16
  setup(props, { attrs }) {
16
17
  const isPanorama = useIsPanorama();
17
18
  const axisType = "yAxis";
19
+ const dispatch = useAppDispatch();
18
20
  const scale = useAppSelector((state) => selectAxisScale(state, axisType, props.yAxisId, isPanorama));
19
21
  const axisSize = useAppSelector((state) => selectYAxisSize(state, props.yAxisId));
20
22
  const position = useAppSelector((state) => selectYAxisPosition(state, props.yAxisId));
21
23
  const cartesianTickItems = useAppSelector((state) => selectTicksOfAxis(state, axisType, props.yAxisId, isPanorama));
22
24
  const viewBox = useAppSelector(selectAxisViewBox);
25
+ const chartDataLengthEmpty = useAppSelector((state) => !state.chartData.chartData?.length);
26
+ const cartesianAxisRef = ref(null);
27
+ const isAutoWidth = () => attrs.width === "auto";
28
+ const measureAxisWidth = () => {
29
+ const el = cartesianAxisRef.value?.$el;
30
+ if (!el) return;
31
+ const ticks = el.getElementsByClassName("v-charts-cartesian-axis-tick-value");
32
+ const label = el.getElementsByClassName("v-charts-label")[0];
33
+ return getCalculatedYAxisWidth({
34
+ ticks,
35
+ label,
36
+ labelGapWithTick: 5,
37
+ tickSize: typeof attrs.tickSize === "number" ? attrs.tickSize : 6,
38
+ tickMargin: typeof attrs.tickMargin === "number" ? attrs.tickMargin : 2
39
+ });
40
+ };
41
+ watch(chartDataLengthEmpty, (empty) => {
42
+ if (empty === false && isAutoWidth()) dispatch(updateYAxisWidth({
43
+ id: props.yAxisId,
44
+ width: 60
45
+ }));
46
+ });
47
+ const updateAutoWidth = () => {
48
+ if (!isAutoWidth() || axisSize.value == null) return;
49
+ const label = attrs.label;
50
+ if (typeof label === "function" || isVNode(label)) return;
51
+ const updatedYAxisWidth = measureAxisWidth();
52
+ if (updatedYAxisWidth == null) return;
53
+ if (Math.round(axisSize.value.width) !== Math.round(updatedYAxisWidth)) dispatch(updateYAxisWidth({
54
+ id: props.yAxisId,
55
+ width: updatedYAxisWidth
56
+ }));
57
+ };
58
+ watch([
59
+ axisSize,
60
+ cartesianTickItems,
61
+ () => attrs.label
62
+ ], () => {
63
+ nextTick(updateAutoWidth);
64
+ }, {
65
+ flush: "post",
66
+ immediate: true
67
+ });
23
68
  return () => {
24
69
  const { ...allOtherProps } = props;
25
70
  if (axisSize.value == null || position.value == null) return null;
@@ -31,7 +76,9 @@ var YAxisImpl = /* @__PURE__ */ defineComponent({
31
76
  "width": axisSize.value?.width,
32
77
  "height": axisSize.value?.height,
33
78
  "ticks": cartesianTickItems.value,
34
- "class": ["v-charts-yAxis yAxis"]
79
+ "tickTextProps": isAutoWidth() ? { width: void 0 } : { width: axisSize.value?.width },
80
+ "class": ["v-charts-yAxis yAxis"],
81
+ "ref": cartesianAxisRef
35
82
  }), null);
36
83
  };
37
84
  }
@@ -53,7 +100,7 @@ var YAxisSettingsDispatcher = /* @__PURE__ */ defineComponent({
53
100
  includeHidden: Boolean,
54
101
  reversed: Boolean,
55
102
  ticks: Array,
56
- width: Number,
103
+ width: [Number, String],
57
104
  orientation: String,
58
105
  mirror: Boolean,
59
106
  hide: Boolean,
@@ -113,7 +160,7 @@ var YAxis = /* @__PURE__ */ defineComponent({
113
160
  default: implicitYAxis.allowDuplicatedCategory
114
161
  },
115
162
  width: {
116
- type: Number,
163
+ type: [Number, String],
117
164
  default: implicitYAxis.width
118
165
  },
119
166
  hide: {
@@ -90,6 +90,10 @@ var CartesianAxis = /* @__PURE__ */ defineComponent({
90
90
  stroke: {
91
91
  type: String,
92
92
  default: "#666"
93
+ },
94
+ tickTextProps: {
95
+ type: Object,
96
+ default: void 0
93
97
  }
94
98
  },
95
99
  setup(props, { slots }) {
@@ -235,7 +239,8 @@ var CartesianAxis = /* @__PURE__ */ defineComponent({
235
239
  index: i,
236
240
  payload: entry,
237
241
  visibleTicksCount: finalTicks.length,
238
- tickFormatter
242
+ tickFormatter,
243
+ ...props.tickTextProps
239
244
  };
240
245
  return createVNode(Layer, {
241
246
  "class": "v-charts-cartesian-axis-tick",
@@ -1,4 +1,5 @@
1
- import { isNumber, isSsr, isVisible } from "../../utils/validate.mjs";
1
+ import { isNumber, isVisible } from "../../utils/validate.mjs";
2
+ import { Global } from "../../utils/Global.mjs";
2
3
  import { mathSign } from "../../utils/data.mjs";
3
4
  import { getStringSize } from "../../utils/attrs.mjs";
4
5
  import { getAngledTickWidth, getNumberIntervalTicks, getTickBoundaries } from "../../utils/tick.mjs";
@@ -87,7 +88,7 @@ function getTicksStart(sign, boundaries, getTickSize, ticks, minTickGap, preserv
87
88
  function getTicks(props, fontSize, letterSpacing) {
88
89
  const { tick, ticks, viewBox, minTickGap, orientation, interval, tickFormatter, unit, angle } = props;
89
90
  if (!ticks || !ticks.length || !tick) return [];
90
- if (isNumber(interval) || isSsr) return getNumberIntervalTicks(ticks, isNumber(interval) ? interval : 0) ?? [];
91
+ if (isNumber(interval) || Global.isSsr) return getNumberIntervalTicks(ticks, isNumber(interval) ? interval : 0) ?? [];
91
92
  let candidates = [];
92
93
  const sizeKey = orientation === "top" || orientation === "bottom" ? "width" : "height";
93
94
  const unitSize = unit && sizeKey === "width" ? getStringSize(unit, {
@@ -10,10 +10,11 @@ import { useSynchronisedEventsFromOtherCharts } from "../events/useChartSynchron
10
10
  import { useReportScale } from "../state/utils/useReportScale.mjs";
11
11
  import { providePortalRaw } from "./TooltipPortalContext.mjs";
12
12
  import { provideLegendPortalRaw } from "./LegendPortalContext.mjs";
13
- import { createVNode, defineComponent, ref } from "vue";
14
- //#region src/chart/RechartsWrapper.tsx
15
- var RechartsWrapper = /* @__PURE__ */ defineComponent({
16
- name: "RechartsWrapper",
13
+ import { createVNode, defineComponent, onMounted, ref } from "vue";
14
+ import { useResizeObserver } from "@vueuse/core";
15
+ //#region src/chart/ChartsWrapper.tsx
16
+ var ChartsWrapper = /* @__PURE__ */ defineComponent({
17
+ name: "ChartsWrapper",
17
18
  props: {
18
19
  class: classProp,
19
20
  height: {
@@ -28,10 +29,19 @@ var RechartsWrapper = /* @__PURE__ */ defineComponent({
28
29
  onMouseLeave: { type: Function },
29
30
  onMouseMove: { type: Function },
30
31
  onMouseUp: { type: Function },
32
+ onResize: { type: Function },
31
33
  onTouchEnd: { type: Function },
32
34
  onTouchMove: { type: Function },
33
35
  onTouchStart: { type: Function },
34
- style: { type: Object },
36
+ responsive: {
37
+ type: Boolean,
38
+ default: false
39
+ },
40
+ style: { type: [
41
+ String,
42
+ Object,
43
+ Array
44
+ ] },
35
45
  width: {
36
46
  type: Number,
37
47
  required: true
@@ -45,11 +55,24 @@ var RechartsWrapper = /* @__PURE__ */ defineComponent({
45
55
  const legendPortal = ref(null);
46
56
  providePortalRaw(tooltipPortal);
47
57
  provideLegendPortalRaw(legendPortal);
58
+ const wrapperEl = ref(null);
48
59
  const innerRef = (node) => {
49
60
  scaleRef.value = node;
50
61
  tooltipPortal.value = node;
51
62
  legendPortal.value = node;
63
+ wrapperEl.value = node;
52
64
  };
65
+ if (props.responsive) {
66
+ useResizeObserver(wrapperEl, (entries) => {
67
+ const { width, height } = entries[0].contentRect;
68
+ props.onResize?.(width, height);
69
+ });
70
+ onMounted(() => {
71
+ if (!wrapperEl.value) return;
72
+ const { width, height } = wrapperEl.value.getBoundingClientRect();
73
+ props.onResize?.(width, height);
74
+ });
75
+ }
53
76
  const myOnClick = (e) => {
54
77
  const chartPointer = getChartPointer(e);
55
78
  if (chartPointer) dispatch(mouseClickAction(chartPointer));
@@ -132,13 +155,17 @@ var RechartsWrapper = /* @__PURE__ */ defineComponent({
132
155
  };
133
156
  return () => createVNode("div", {
134
157
  "class": ["v-charts-wrapper", props.class],
135
- "style": {
158
+ "style": [props.responsive ? {
159
+ position: "relative",
160
+ cursor: "default",
161
+ width: "100%",
162
+ height: "100%"
163
+ } : {
136
164
  position: "relative",
137
165
  cursor: "default",
138
166
  width: `${props.width}px`,
139
- height: `${props.height}px`,
140
- ...props.style
141
- },
167
+ height: `${props.height}px`
168
+ }, props.style],
142
169
  "role": "application",
143
170
  "onClick": myOnClick,
144
171
  "onContextmenu": myOnContextMenu,
@@ -158,4 +185,4 @@ var RechartsWrapper = /* @__PURE__ */ defineComponent({
158
185
  }
159
186
  });
160
187
  //#endregion
161
- export { RechartsWrapper };
188
+ export { ChartsWrapper };