x-next 1.7.0 → 1.8.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 (88) hide show
  1. package/AI_USAGE.md +129 -4
  2. package/CHANGELOG.md +38 -0
  3. package/dist/_hooks/use-chart-size.d.ts +25 -0
  4. package/dist/_utils/chart/index.d.ts +6 -0
  5. package/dist/_utils/chart/padding.d.ts +15 -0
  6. package/dist/_utils/chart/path.d.ts +34 -0
  7. package/dist/_utils/chart/scale.d.ts +55 -0
  8. package/dist/components/_components/chart/ChartAxis.d.ts +85 -0
  9. package/dist/components/_components/chart/ChartLegend.d.ts +26 -0
  10. package/dist/components/_components/chart/ChartTooltip.d.ts +76 -0
  11. package/dist/components/_components/chart/colors.d.ts +10 -0
  12. package/dist/components/_components/chart/interface.d.ts +38 -0
  13. package/dist/components/bar-chart/BarChart.d.ts +278 -0
  14. package/dist/components/bar-chart/helpers/layout.d.ts +55 -0
  15. package/dist/components/bar-chart/index.d.ts +600 -0
  16. package/dist/components/bar-chart/interface.d.ts +74 -0
  17. package/dist/components/bar-chart/props.d.ts +145 -0
  18. package/dist/components/heatmap/Heatmap.d.ts +10 -0
  19. package/dist/components/heatmap/index.d.ts +30 -0
  20. package/dist/components/index.d.ts +3 -0
  21. package/dist/components/line-chart/LineChart.d.ts +295 -0
  22. package/dist/components/line-chart/helpers/layout.d.ts +74 -0
  23. package/dist/components/line-chart/index.d.ts +614 -0
  24. package/dist/components/line-chart/interface.d.ts +76 -0
  25. package/dist/components/line-chart/props.d.ts +173 -0
  26. package/dist/components/pie-chart/PieChart.d.ts +219 -0
  27. package/dist/components/pie-chart/index.d.ts +470 -0
  28. package/dist/components/pie-chart/interface.d.ts +58 -0
  29. package/dist/components/pie-chart/props.d.ts +107 -0
  30. package/dist/components/trend-chart/components/TrendChart.d.ts +19 -96
  31. package/dist/components/trend-chart/index.d.ts +33 -187
  32. package/dist/components/trend-chart/props.d.ts +9 -78
  33. package/dist/components/trend-chart/themes.d.ts +0 -1
  34. package/dist/es/_hooks/use-chart-size.js +25 -0
  35. package/dist/es/_styles/palette-aliases.js +5 -0
  36. package/dist/es/_utils/chart/padding.js +22 -0
  37. package/dist/es/_utils/chart/path.js +69 -0
  38. package/dist/es/_utils/chart/scale.js +77 -0
  39. package/dist/es/components/_components/chart/ChartAxis.js +79 -0
  40. package/dist/es/components/_components/chart/ChartLegend.js +53 -0
  41. package/dist/es/components/_components/chart/ChartTooltip.js +64 -0
  42. package/dist/es/components/_components/chart/colors.js +12 -0
  43. package/dist/es/components/bar-chart/BarChart.js +470 -0
  44. package/dist/es/components/bar-chart/helpers/layout.js +53 -0
  45. package/dist/es/components/bar-chart/index.js +8 -0
  46. package/dist/es/components/bar-chart/props.js +148 -0
  47. package/dist/es/components/heatmap/Heatmap.js +244 -169
  48. package/dist/es/components/index.js +132 -126
  49. package/dist/es/components/line-chart/LineChart.js +532 -0
  50. package/dist/es/components/line-chart/helpers/layout.js +80 -0
  51. package/dist/es/components/line-chart/index.js +8 -0
  52. package/dist/es/components/line-chart/props.js +178 -0
  53. package/dist/es/components/pie-chart/PieChart.js +397 -0
  54. package/dist/es/components/pie-chart/index.js +8 -0
  55. package/dist/es/components/pie-chart/props.js +104 -0
  56. package/dist/es/components/trend-chart/components/TrendChart.js +143 -183
  57. package/dist/es/components/trend-chart/components/trend-chart-curve.js +85 -81
  58. package/dist/es/components/trend-chart/props.js +28 -74
  59. package/dist/es/components/trend-chart/themes.js +30 -31
  60. package/dist/es/index.js +193 -187
  61. package/dist/es/locale/en-US.js +8 -1
  62. package/dist/es/locale/zh-CN.js +8 -1
  63. package/dist/es/style.css +1 -1
  64. package/dist/index.cjs +4 -4
  65. package/dist/index.umd.js +4 -4
  66. package/dist/locale/interface.d.ts +13 -0
  67. package/dist/style/bar-chart.css +1 -0
  68. package/dist/style/bar-chart.js +2 -0
  69. package/dist/style/base.css +1 -1
  70. package/dist/style/heatmap.css +1 -1
  71. package/dist/style/line-chart.css +1 -0
  72. package/dist/style/line-chart.js +2 -0
  73. package/dist/style/pie-chart.css +1 -0
  74. package/dist/style/pie-chart.js +2 -0
  75. package/dist/style.css +1 -1
  76. package/dist/types.d.ts +3 -0
  77. package/package.json +1 -1
  78. package/volar.d.ts +3 -0
  79. package/dist/components/trend-chart/components/trend-chart-grid.d.ts +0 -55
  80. package/dist/components/trend-chart/components/trend-chart-labels.d.ts +0 -26
  81. package/dist/components/trend-chart/helpers/genPath.d.ts +0 -8
  82. package/dist/components/trend-chart/helpers/getPadding.d.ts +0 -8
  83. package/dist/components/trend-chart/helpers/validatePadding.d.ts +0 -2
  84. package/dist/es/components/trend-chart/components/trend-chart-grid.js +0 -62
  85. package/dist/es/components/trend-chart/components/trend-chart-labels.js +0 -75
  86. package/dist/es/components/trend-chart/helpers/genPath.js +0 -22
  87. package/dist/es/components/trend-chart/helpers/getPadding.js +0 -21
  88. package/dist/es/components/trend-chart/helpers/validatePadding.js +0 -7
@@ -0,0 +1,69 @@
1
+ const $ = (n) => Math.round(n * 100) / 100, i = (n, e, r, t, u) => {
2
+ if (r <= 0 || t <= 0) return "";
3
+ const o = Math.min(Math.max(u, 0), r / 2, t);
4
+ return o <= 0 ? `M${$(n)},${$(e)}h${$(r)}v${$(t)}h${$(-r)}Z` : [
5
+ `M${$(n)},${$(e + t)}`,
6
+ `L${$(n)},${$(e + o)}`,
7
+ `Q${$(n)},${$(e)} ${$(n + o)},${$(e)}`,
8
+ `L${$(n + r - o)},${$(e)}`,
9
+ `Q${$(n + r)},${$(e)} ${$(n + r)},${$(e + o)}`,
10
+ `L${$(n + r)},${$(e + t)}`,
11
+ "Z"
12
+ ].join("");
13
+ }, x = (n, e = !1) => {
14
+ if (!n.length) return "";
15
+ if (n.length === 1)
16
+ return `M${$(n[0].x)},${$(n[0].y)}`;
17
+ if (!e)
18
+ return n.map((t, u) => `${u === 0 ? "M" : "L"}${$(t.x)},${$(t.y)}`).join("");
19
+ let r = `M${$(n[0].x)},${$(n[0].y)}`;
20
+ for (let t = 1; t < n.length; t += 1) {
21
+ const u = n[t - 1], o = n[t], c = (u.x + o.x) / 2;
22
+ r += `C${$(c)},${$(u.y)} ${$(c)},${$(o.y)} ${$(
23
+ o.x
24
+ )},${$(o.y)}`;
25
+ }
26
+ return r;
27
+ }, A = (n, e, r = !1) => {
28
+ const t = x(n, r);
29
+ if (!t) return "";
30
+ const u = n[0], o = n[n.length - 1];
31
+ return `${t}L${$(o.x)},${$(e)}L${$(u.x)},${$(
32
+ e
33
+ )}Z`;
34
+ }, a = (n, e, r, t) => {
35
+ const u = t * Math.PI / 180;
36
+ return { x: n + r * Math.cos(u), y: e + r * Math.sin(u) };
37
+ }, L = (n) => {
38
+ const { cx: e, cy: r, startAngle: t } = n, u = Math.max(0, Math.min(n.innerRadius, n.outerRadius - 0.5)), o = Math.min(n.endAngle, t + 359.99), c = o - t;
39
+ if (c <= 0) return "";
40
+ const l = c > 180 ? 1 : 0, s = a(e, r, n.outerRadius, t), M = a(e, r, n.outerRadius, o);
41
+ if (u <= 0)
42
+ return [
43
+ `M${$(e)},${$(r)}`,
44
+ `L${$(s.x)},${$(s.y)}`,
45
+ `A${$(n.outerRadius)},${$(n.outerRadius)} 0 ${l} 1 ${$(
46
+ M.x
47
+ )},${$(M.y)}`,
48
+ "Z"
49
+ ].join("");
50
+ const d = a(e, r, u, o), f = a(e, r, u, t);
51
+ return [
52
+ `M${$(s.x)},${$(s.y)}`,
53
+ `A${$(n.outerRadius)},${$(n.outerRadius)} 0 ${l} 1 ${$(
54
+ M.x
55
+ )},${$(M.y)}`,
56
+ `L${$(d.x)},${$(d.y)}`,
57
+ `A${$(u)},${$(u)} 0 ${l} 0 ${$(f.x)},${$(
58
+ f.y
59
+ )}`,
60
+ "Z"
61
+ ].join("");
62
+ };
63
+ export {
64
+ L as describeArcSegment,
65
+ A as genAreaPath,
66
+ x as genLinePath,
67
+ a as polarPoint,
68
+ i as roundedTopRectPath
69
+ };
@@ -0,0 +1,77 @@
1
+ const h = (t) => Number(t.toPrecision(12)), g = (t) => Number(t.toFixed(4)), f = (t) => Math.max(2, Math.floor(t)), p = (t) => {
2
+ if (!Number.isFinite(t) || t <= 0) return 0;
3
+ const e = 10 ** Math.floor(Math.log10(t)), i = t / e;
4
+ return e * (i <= 1 ? 1 : i <= 2 ? 2 : i <= 5 ? 5 : 10);
5
+ }, x = (t, e = 4) => {
6
+ if (!Number.isFinite(t) || t <= 0)
7
+ return { max: 0, ticks: [0] };
8
+ const i = f(e) - 1, s = p(t / i), r = h(Math.ceil(t / s) * s), n = Math.round(r / s);
9
+ return {
10
+ max: r,
11
+ ticks: Array.from({ length: n + 1 }, (o, c) => h(s * c))
12
+ };
13
+ }, M = (t, e = 4, i) => {
14
+ const s = f(e);
15
+ if (Number.isFinite(i) && i > 0) {
16
+ const r = i, n = s - 1;
17
+ return {
18
+ max: r,
19
+ ticks: Array.from(
20
+ { length: n + 1 },
21
+ (o, c) => g(r / n * c)
22
+ )
23
+ };
24
+ }
25
+ return x(t, s);
26
+ }, d = (t, e, i = 4) => {
27
+ const s = Number.isFinite(t) ? t : 0, r = Number.isFinite(e) ? e : 0, n = Math.min(0, s), o = Math.max(0, r);
28
+ if (n === 0 && o === 0)
29
+ return { min: 0, max: 0, ticks: [0] };
30
+ const c = f(i) - 1, u = p((o - n) / c), l = h(Math.floor(n / u) * u), m = h(Math.ceil(o / u) * u), a = Math.round((m - l) / u);
31
+ return {
32
+ min: l,
33
+ max: m,
34
+ ticks: Array.from({ length: a + 1 }, (N, b) => h(l + u * b))
35
+ };
36
+ }, A = (t, e, i = 4, s, r) => {
37
+ const n = f(i), o = Number.isFinite(s), c = Number.isFinite(r);
38
+ if (!o && !c)
39
+ return d(t, e, n);
40
+ const u = Math.min(0, Number.isFinite(t) ? t : 0), l = Math.max(0, Number.isFinite(e) ? e : 0);
41
+ let m = o ? s : u, a = c ? r : l;
42
+ m > a && ([m, a] = [a, m]);
43
+ const N = n - 1;
44
+ return {
45
+ min: m,
46
+ max: a,
47
+ ticks: Array.from(
48
+ { length: N + 1 },
49
+ (b, F) => g(m + (a - m) / N * F)
50
+ )
51
+ };
52
+ }, k = (t) => {
53
+ if (!Number.isFinite(t)) return "";
54
+ const e = Number(Number(t.toPrecision(12)).toFixed(4)), [i, s] = String(Math.abs(e)).split("."), r = i.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
55
+ return `${e < 0 ? "-" : ""}${r}${s ? `.${s}` : ""}`;
56
+ }, y = (t, e) => {
57
+ let i = 0;
58
+ for (const s of t)
59
+ i += s.charCodeAt(0) > 255 ? 1 : 0.6;
60
+ return i * e;
61
+ }, S = (t, e, i, s = 8) => {
62
+ if (t <= 0) return [];
63
+ const r = Math.max(1, Math.ceil((i + s) / Math.max(e, 1))), n = [];
64
+ for (let c = 0; c < t; c += r)
65
+ n.push(c);
66
+ const o = t - 1;
67
+ return n[n.length - 1] !== o && (n.length > 1 && o - n[n.length - 1] < r * 0.6 && n.pop(), n.push(o)), n;
68
+ };
69
+ export {
70
+ k as defaultValueFormatter,
71
+ y as estimateTextWidth,
72
+ A as getDomain,
73
+ d as getNiceDomain,
74
+ x as getNiceScale,
75
+ M as getScale,
76
+ S as pickLabelIndices
77
+ };
@@ -0,0 +1,79 @@
1
+ import { defineComponent as s, createVNode as a } from "vue";
2
+ import { getClassNameMixin as i } from "../../../_utils/config.js";
3
+ const y = 6, x = 8, c = /* @__PURE__ */ s({
4
+ name: "ChartAxis",
5
+ props: {
6
+ plot: {
7
+ type: Object,
8
+ required: !0
9
+ },
10
+ ticks: {
11
+ type: Array,
12
+ default: () => []
13
+ },
14
+ xLabels: {
15
+ type: Array,
16
+ default: () => []
17
+ },
18
+ fontSize: {
19
+ type: Number,
20
+ default: 12
21
+ },
22
+ color: {
23
+ type: String,
24
+ default: "var(--x-chart-color-axis-text)"
25
+ },
26
+ showX: {
27
+ type: Boolean,
28
+ default: !0
29
+ },
30
+ showY: {
31
+ type: Boolean,
32
+ default: !0
33
+ },
34
+ showHorizontalLines: {
35
+ type: Boolean,
36
+ default: !0
37
+ }
38
+ },
39
+ setup(e) {
40
+ const l = i("chart"), o = () => ({
41
+ fontSize: `${e.fontSize}px`,
42
+ fill: e.color
43
+ });
44
+ return () => a("g", null, [e.showHorizontalLines && a("g", {
45
+ class: l.element("grid")
46
+ }, [e.ticks.map((t, n) => a("line", {
47
+ key: n,
48
+ class: [l.element("grid-line"), {
49
+ [l.is("baseline")]: t.isBaseline
50
+ }],
51
+ x1: e.plot.left,
52
+ x2: e.plot.left + e.plot.width,
53
+ y1: t.y,
54
+ y2: t.y
55
+ }, null))]), e.showY && a("g", {
56
+ class: l.element("y-labels")
57
+ }, [e.ticks.map((t, n) => a("text", {
58
+ key: n,
59
+ class: l.element("axis-label"),
60
+ x: e.plot.left - y,
61
+ y: t.y,
62
+ "text-anchor": "end",
63
+ "dominant-baseline": "middle",
64
+ style: o()
65
+ }, [t.label]))]), e.showX && a("g", {
66
+ class: l.element("x-labels")
67
+ }, [e.xLabels.map((t, n) => a("text", {
68
+ key: n,
69
+ class: l.element("axis-label"),
70
+ x: t.x,
71
+ y: e.plot.bottom + x + e.fontSize * 0.9,
72
+ "text-anchor": "middle",
73
+ style: o()
74
+ }, [t.text]))])]);
75
+ }
76
+ });
77
+ export {
78
+ c as default
79
+ };
@@ -0,0 +1,53 @@
1
+ import { defineComponent as o, createVNode as l } from "vue";
2
+ import { getClassNameMixin as m } from "../../../_utils/config.js";
3
+ import { useLocale as u } from "../../../locale/index.js";
4
+ const f = /* @__PURE__ */ o({
5
+ name: "ChartLegend",
6
+ props: {
7
+ items: {
8
+ type: Array,
9
+ default: () => []
10
+ }
11
+ },
12
+ emits: {
13
+ toggle: (a) => !0
14
+ },
15
+ setup(a, {
16
+ emit: s,
17
+ slots: t
18
+ }) {
19
+ const n = m("chart"), {
20
+ t: d
21
+ } = u();
22
+ return () => a.items.length ? t.default ? l("div", {
23
+ class: n.element("legend")
24
+ }, [t.default({
25
+ items: a.items
26
+ })]) : l("div", {
27
+ class: n.element("legend")
28
+ }, [a.items.map((e, r) => l("button", {
29
+ key: e.key,
30
+ type: "button",
31
+ class: [n.element("legend-item"), {
32
+ [n.is("hidden")]: e.hidden
33
+ }],
34
+ "aria-pressed": !e.hidden,
35
+ "aria-label": d("chart.legendToggle", {
36
+ name: e.name
37
+ }),
38
+ onClick: () => s("toggle", r)
39
+ }, [l("span", {
40
+ class: n.element("legend-swatch"),
41
+ style: {
42
+ backgroundColor: e.color
43
+ }
44
+ }, null), l("span", {
45
+ class: n.element("legend-name")
46
+ }, [e.name]), e.value !== void 0 && l("span", {
47
+ class: n.element("legend-value")
48
+ }, [e.value])]))]) : null;
49
+ }
50
+ });
51
+ export {
52
+ f as default
53
+ };
@@ -0,0 +1,64 @@
1
+ import { defineComponent as i, createVNode as e, Fragment as n } from "vue";
2
+ import { getClassNameMixin as s } from "../../../_utils/config.js";
3
+ const c = /* @__PURE__ */ i({
4
+ name: "ChartTooltip",
5
+ props: {
6
+ visible: {
7
+ type: Boolean,
8
+ default: !1
9
+ },
10
+ title: {
11
+ type: String
12
+ },
13
+ entries: {
14
+ type: Array,
15
+ default: () => []
16
+ },
17
+ /** 合计行;entries 只有一个时可传 null 隐藏 */
18
+ total: {
19
+ type: Object,
20
+ default: null
21
+ },
22
+ /** 位置样式,由各图换算(锚点或指针坐标) */
23
+ position: {
24
+ type: Object,
25
+ default: () => ({})
26
+ },
27
+ /** 需要测量提示宽度做贴边收敛时,通过该回调取到 DOM 节点 */
28
+ onElement: {
29
+ type: Function
30
+ }
31
+ },
32
+ setup(t, {
33
+ slots: o
34
+ }) {
35
+ const l = s("chart");
36
+ return () => t.visible ? e("div", {
37
+ ref: t.onElement,
38
+ class: [l.element("tooltip"), l.is("visible")],
39
+ style: t.position,
40
+ role: "tooltip"
41
+ }, [o.default ? o.default() : e(n, null, [t.title !== void 0 && e("div", {
42
+ class: l.element("tooltip-title")
43
+ }, [t.title]), e("div", {
44
+ class: l.element("tooltip-list")
45
+ }, [t.entries.map((a) => e("div", {
46
+ key: a.key,
47
+ class: l.element("tooltip-item")
48
+ }, [a.color !== void 0 && e("span", {
49
+ class: l.element("tooltip-swatch"),
50
+ style: {
51
+ backgroundColor: a.color
52
+ }
53
+ }, null), e("span", {
54
+ class: l.element("tooltip-name")
55
+ }, [a.name]), e("span", {
56
+ class: l.element("tooltip-value")
57
+ }, [a.value])]))]), t.total && e("div", {
58
+ class: l.element("tooltip-total")
59
+ }, [e("span", null, [t.total.label]), e("span", null, [t.total.value])])])]) : null;
60
+ }
61
+ });
62
+ export {
63
+ c as default
64
+ };
@@ -0,0 +1,12 @@
1
+ const r = [
2
+ "var(--x-chart-color-series-1)",
3
+ "var(--x-chart-color-series-2)",
4
+ "var(--x-chart-color-series-3)",
5
+ "var(--x-chart-color-series-4)",
6
+ "var(--x-chart-color-series-5)",
7
+ "var(--x-chart-color-series-6)"
8
+ ], o = (e) => r[(e % r.length + r.length) % r.length];
9
+ export {
10
+ r as ChartSeriesColors,
11
+ o as getSeriesColor
12
+ };