iryx-ui 0.15.0 → 0.16.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 +3 -1
- package/dist/component-names.d.ts +1 -1
- package/dist/component-names.js +1 -1
- package/dist/components/BarChart.vue.d.ts +8 -0
- package/dist/components/BarChart.vue_vue_type_script_setup_true_lang.js +169 -151
- package/dist/components/DonutChart.js +5 -0
- package/dist/components/DonutChart.vue.d.ts +96 -0
- package/dist/components/DonutChart.vue_vue_type_script_setup_true_lang.js +234 -0
- package/dist/components/LineChart.vue.d.ts +8 -0
- package/dist/components/LineChart.vue_vue_type_script_setup_true_lang.js +160 -141
- package/dist/components/Sparkline.vue.d.ts +9 -0
- package/dist/components/Sparkline.vue_vue_type_script_setup_true_lang.js +90 -53
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +90 -88
- package/dist/composables/cartesian.d.ts +10 -2
- package/dist/composables/chart-reveal.d.ts +45 -0
- package/dist/composables/chart-reveal.js +93 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +134 -131
- package/dist/theme/donut-chart.d.ts +104 -0
- package/dist/theme/donut-chart.js +17 -0
- package/dist/theme/index.d.ts +1 -0
- package/dist/theme/sparkline.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { useIryxUiConfig as e } from "../config.js";
|
|
2
|
+
import { useElementSize as t } from "../composables/element-size.js";
|
|
3
|
+
import { clampTooltip as n, seriesColor as r, slotOf as i, warnOnSlotOverflow as a } from "../composables/cartesian.js";
|
|
4
|
+
import { useChartAnimation as o, useChartProgress as s } from "../composables/chart-reveal.js";
|
|
5
|
+
import c from "./ChartLegend.js";
|
|
6
|
+
import { donutChartTheme as l } from "../theme/donut-chart.js";
|
|
7
|
+
import { Fragment as u, computed as d, createBlock as f, createCommentVNode as p, createElementBlock as m, createElementVNode as h, defineComponent as g, normalizeClass as _, normalizeStyle as v, openBlock as y, ref as b, renderList as x, renderSlot as ee, toDisplayString as S, unref as C } from "vue";
|
|
8
|
+
//#region src/components/DonutChart.vue?vue&type=script&setup=true&lang.ts
|
|
9
|
+
var te = ["role", "aria-label"], w = [
|
|
10
|
+
"width",
|
|
11
|
+
"height",
|
|
12
|
+
"viewBox"
|
|
13
|
+
], ne = [
|
|
14
|
+
"cx",
|
|
15
|
+
"cy",
|
|
16
|
+
"r",
|
|
17
|
+
"fill",
|
|
18
|
+
"stroke",
|
|
19
|
+
"stroke-width"
|
|
20
|
+
], re = ["d", "onPointerenter"], ie = { scope: "row" }, T = /*@__PURE__*/ g({
|
|
21
|
+
__name: "DonutChart",
|
|
22
|
+
props: {
|
|
23
|
+
data: { default: () => [] },
|
|
24
|
+
size: { default: 240 },
|
|
25
|
+
thickness: {},
|
|
26
|
+
pie: { type: Boolean },
|
|
27
|
+
gap: { default: 2 },
|
|
28
|
+
animate: {
|
|
29
|
+
type: [Boolean, Object],
|
|
30
|
+
default: !0
|
|
31
|
+
},
|
|
32
|
+
legend: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: !0
|
|
35
|
+
},
|
|
36
|
+
locale: {},
|
|
37
|
+
format: {},
|
|
38
|
+
label: {},
|
|
39
|
+
unstyled: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: void 0
|
|
42
|
+
},
|
|
43
|
+
class: {},
|
|
44
|
+
ui: {}
|
|
45
|
+
},
|
|
46
|
+
setup(g) {
|
|
47
|
+
let T = g, ae = e(), E = d(() => T.unstyled ?? ae.unstyled), D = b(), { width: O } = t(D), oe = d(() => new Intl.NumberFormat(T.locale, T.format));
|
|
48
|
+
function k(e) {
|
|
49
|
+
return oe.value.format(e);
|
|
50
|
+
}
|
|
51
|
+
let A = d(() => new Intl.NumberFormat(T.locale, {
|
|
52
|
+
style: "percent",
|
|
53
|
+
maximumFractionDigits: 1
|
|
54
|
+
})), j = !1;
|
|
55
|
+
function M() {
|
|
56
|
+
j || process.env.NODE_ENV === "production" || (j = !0, console.warn("[iryx-ui] IDonutChart dropped a negative value. A share of a whole cannot be negative — plot the magnitudes, or use IBarChart, which has a baseline."));
|
|
57
|
+
}
|
|
58
|
+
let N = d(() => {
|
|
59
|
+
let e = T.data.map((e, t) => ({
|
|
60
|
+
datum: e,
|
|
61
|
+
index: t
|
|
62
|
+
})).filter(({ datum: e }) => {
|
|
63
|
+
let t = e.value;
|
|
64
|
+
return typeof t != "number" || !Number.isFinite(t) || t === 0 ? !1 : t < 0 ? (M(), !1) : !0;
|
|
65
|
+
});
|
|
66
|
+
a(e.length);
|
|
67
|
+
let t = e.reduce((e, { datum: t }) => e + t.value, 0);
|
|
68
|
+
return e.map(({ datum: e, index: n }) => ({
|
|
69
|
+
label: e.label,
|
|
70
|
+
value: e.value,
|
|
71
|
+
share: t ? e.value / t : 0,
|
|
72
|
+
color: r(i(e, n)),
|
|
73
|
+
index: n
|
|
74
|
+
}));
|
|
75
|
+
}), P = d(() => N.value.reduce((e, t) => e + t.value, 0)), F = d(() => N.value.map((e) => ({
|
|
76
|
+
key: `${e.index}-${e.label}`,
|
|
77
|
+
name: e.label,
|
|
78
|
+
slot: T.data[e.index]?.slot ?? e.index
|
|
79
|
+
}))), I = d(() => T.legend && N.value.length > 0), L = d(() => ({
|
|
80
|
+
x: O.value / 2,
|
|
81
|
+
y: T.size / 2
|
|
82
|
+
})), R = d(() => Math.max(Math.min(O.value, T.size) / 2, 0)), z = d(() => {
|
|
83
|
+
if (T.pie) return 0;
|
|
84
|
+
let e = Math.min(T.thickness ?? R.value * .4, R.value);
|
|
85
|
+
return Math.max(R.value - e, 0);
|
|
86
|
+
}), B = -Math.PI / 2, V = d(() => Math.max(T.gap, 0) / 2);
|
|
87
|
+
function H(e) {
|
|
88
|
+
return Math.round(e * 100) / 100;
|
|
89
|
+
}
|
|
90
|
+
function U(e, t) {
|
|
91
|
+
return [H(L.value.x + e * Math.cos(t)), H(L.value.y + e * Math.sin(t))];
|
|
92
|
+
}
|
|
93
|
+
let W = d(() => !!(O.value && R.value && N.value.length)), { progress: G } = s(W, o(d(() => T.animate))), K = d(() => {
|
|
94
|
+
if (!W.value) return [];
|
|
95
|
+
let e = G.value, t = B;
|
|
96
|
+
return N.value.flatMap((n) => {
|
|
97
|
+
let r = n.share * Math.PI * 2, i = t;
|
|
98
|
+
t += r;
|
|
99
|
+
let a = B + (i - B) * e, o = r * e;
|
|
100
|
+
return o <= 0 ? [] : [{
|
|
101
|
+
...n,
|
|
102
|
+
mid: i + r / 2,
|
|
103
|
+
path: se(a, a + o)
|
|
104
|
+
}];
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
function q(e, t) {
|
|
108
|
+
let n = V.value;
|
|
109
|
+
return !n || e <= n ? 0 : Math.min(Math.asin(n / e), t / 3);
|
|
110
|
+
}
|
|
111
|
+
function se(e, t) {
|
|
112
|
+
let n = t - e, r = !z.value, i = N.value.length < 2 ? 0 : q(R.value, n), a = e + i, o = t - i, s = +(o - a > Math.PI), [c, l] = U(R.value, a), [u, d] = U(R.value, o);
|
|
113
|
+
if (r) {
|
|
114
|
+
let [t, r] = U(i ? Math.min(V.value / Math.sin(n / 2), R.value / 2) : 0, e + n / 2);
|
|
115
|
+
return `M${c} ${l} A${H(R.value)} ${H(R.value)} 0 ${s} 1 ${u} ${d} L${t} ${r} Z`;
|
|
116
|
+
}
|
|
117
|
+
let f = i ? q(z.value, n) : 0, p = +(n - f * 2 > Math.PI), [m, h] = U(z.value, t - f), [g, _] = U(z.value, e + f);
|
|
118
|
+
return `M${c} ${l} A${H(R.value)} ${H(R.value)} 0 ${s} 1 ${u} ${d} L${m} ${h} A${H(z.value)} ${H(z.value)} 0 ${p} 0 ${g} ${_} Z`;
|
|
119
|
+
}
|
|
120
|
+
let J = d(() => {
|
|
121
|
+
if (!(K.value.length !== 1 || !R.value || G.value < 1)) return {
|
|
122
|
+
...K.value[0],
|
|
123
|
+
radius: z.value ? (R.value + z.value) / 2 : R.value,
|
|
124
|
+
strokeWidth: R.value - z.value
|
|
125
|
+
};
|
|
126
|
+
}), ce = d(() => J.value ? [] : K.value), Y = b(), X = d(() => {
|
|
127
|
+
if (Y.value == null) return;
|
|
128
|
+
let e = K.value.find((e) => e.index === Y.value);
|
|
129
|
+
if (!e) return;
|
|
130
|
+
let t = k(e.value), r = A.value.format(e.share), [i, a] = U(z.value ? (R.value + z.value) / 2 : R.value / 2, e.mid);
|
|
131
|
+
return {
|
|
132
|
+
label: e.label,
|
|
133
|
+
value: t,
|
|
134
|
+
share: r,
|
|
135
|
+
x: n(i, `${e.label}${t}${r}`, O.value),
|
|
136
|
+
y: a
|
|
137
|
+
};
|
|
138
|
+
}), Z = d(() => l());
|
|
139
|
+
function Q(e, t) {
|
|
140
|
+
let n = T.ui?.[e];
|
|
141
|
+
return E.value ? [n, t] : Z.value[e]({ class: [n, t] });
|
|
142
|
+
}
|
|
143
|
+
function $(e) {
|
|
144
|
+
let t = Y.value != null && Y.value !== e;
|
|
145
|
+
return E.value ? [T.ui?.slice] : Z.value.slice({ class: [T.ui?.slice, t ? Z.value.faded() : void 0] });
|
|
146
|
+
}
|
|
147
|
+
return (e, t) => (y(), m("div", {
|
|
148
|
+
ref_key: "root",
|
|
149
|
+
ref: D,
|
|
150
|
+
role: T.label ? "figure" : void 0,
|
|
151
|
+
"aria-label": T.label,
|
|
152
|
+
class: _(Q("root", T.class))
|
|
153
|
+
}, [
|
|
154
|
+
I.value ? (y(), f(c, {
|
|
155
|
+
key: 0,
|
|
156
|
+
series: F.value,
|
|
157
|
+
active: Y.value == null ? void 0 : N.value.findIndex((e) => e.index === Y.value),
|
|
158
|
+
unstyled: T.unstyled
|
|
159
|
+
}, null, 8, [
|
|
160
|
+
"series",
|
|
161
|
+
"active",
|
|
162
|
+
"unstyled"
|
|
163
|
+
])) : p("", !0),
|
|
164
|
+
h("div", { class: _(E.value ? void 0 : Z.value.plot()) }, [
|
|
165
|
+
(y(), m("svg", {
|
|
166
|
+
width: C(O),
|
|
167
|
+
height: T.size,
|
|
168
|
+
viewBox: `0 0 ${C(O)} ${T.size}`,
|
|
169
|
+
"aria-hidden": "true",
|
|
170
|
+
class: _(Q("svg"))
|
|
171
|
+
}, [J.value ? (y(), m("circle", {
|
|
172
|
+
key: 0,
|
|
173
|
+
cx: L.value.x,
|
|
174
|
+
cy: L.value.y,
|
|
175
|
+
r: J.value.radius,
|
|
176
|
+
fill: z.value ? "none" : J.value.color,
|
|
177
|
+
stroke: z.value ? J.value.color : "none",
|
|
178
|
+
"stroke-width": z.value ? J.value.strokeWidth : 0,
|
|
179
|
+
class: _($(J.value.index)),
|
|
180
|
+
onPointerenter: t[0] ||= (e) => Y.value = J.value.index,
|
|
181
|
+
onPointerleave: t[1] ||= (e) => Y.value = void 0
|
|
182
|
+
}, null, 42, ne)) : p("", !0), (y(!0), m(u, null, x(ce.value, (e) => (y(), m("path", {
|
|
183
|
+
key: `slice-${e.index}`,
|
|
184
|
+
d: e.path,
|
|
185
|
+
style: v({ fill: e.color }),
|
|
186
|
+
class: _($(e.index)),
|
|
187
|
+
onPointerenter: (t) => Y.value = e.index,
|
|
188
|
+
onPointerleave: t[2] ||= (e) => Y.value = void 0
|
|
189
|
+
}, null, 46, re))), 128))], 10, w)),
|
|
190
|
+
e.$slots.center && z.value ? (y(), m("div", {
|
|
191
|
+
key: 0,
|
|
192
|
+
class: _(Q("center")),
|
|
193
|
+
style: v({
|
|
194
|
+
left: `${L.value.x}px`,
|
|
195
|
+
top: `${L.value.y}px`,
|
|
196
|
+
width: `${z.value * 2 * .82}px`,
|
|
197
|
+
transform: "translate(-50%, -50%)"
|
|
198
|
+
})
|
|
199
|
+
}, [ee(e.$slots, "center", {
|
|
200
|
+
total: P.value,
|
|
201
|
+
formatted: k(P.value)
|
|
202
|
+
})], 6)) : p("", !0),
|
|
203
|
+
X.value ? (y(), m("div", {
|
|
204
|
+
key: 1,
|
|
205
|
+
class: _(Q("tooltip")),
|
|
206
|
+
style: v({
|
|
207
|
+
left: `${X.value.x}px`,
|
|
208
|
+
top: `${X.value.y}px`,
|
|
209
|
+
transform: "translate(-50%, -50%)"
|
|
210
|
+
})
|
|
211
|
+
}, [
|
|
212
|
+
h("span", { class: _(Q("tooltipLabel")) }, S(X.value.label), 3),
|
|
213
|
+
h("span", { class: _(Q("tooltipValue")) }, S(X.value.value), 3),
|
|
214
|
+
h("span", { class: _(Q("tooltipShare")) }, S(X.value.share), 3)
|
|
215
|
+
], 6)) : p("", !0)
|
|
216
|
+
], 2),
|
|
217
|
+
h("div", { class: _(Q("table")) }, [h("table", null, [
|
|
218
|
+
h("caption", null, S(T.label), 1),
|
|
219
|
+
t[3] ||= h("thead", null, [h("tr", null, [
|
|
220
|
+
h("th", { scope: "col" }, " Category "),
|
|
221
|
+
h("th", { scope: "col" }, " Value "),
|
|
222
|
+
h("th", { scope: "col" }, " Share ")
|
|
223
|
+
])], -1),
|
|
224
|
+
h("tbody", null, [(y(!0), m(u, null, x(N.value, (e) => (y(), m("tr", { key: `row-${e.index}` }, [
|
|
225
|
+
h("th", ie, S(e.label), 1),
|
|
226
|
+
h("td", null, S(k(e.value)), 1),
|
|
227
|
+
h("td", null, S(A.value.format(e.share)), 1)
|
|
228
|
+
]))), 128))])
|
|
229
|
+
])], 2)
|
|
230
|
+
], 10, te));
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
//#endregion
|
|
234
|
+
export { T as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ChartSeries } from '../composables/cartesian';
|
|
2
|
+
import type { ChartAnimate } from '../composables/chart-reveal';
|
|
2
3
|
import type { SparseValue } from '../composables/scale';
|
|
3
4
|
/**
|
|
4
5
|
* A row. `value` is the single-series shortcut; with `series` set, each entry
|
|
@@ -39,6 +40,12 @@ export interface LineChartProps {
|
|
|
39
40
|
ticks?: number;
|
|
40
41
|
/** Drop the value axis and its gridlines. */
|
|
41
42
|
axis?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Draw the line on across the plot on the first paint. Skipped for a reader
|
|
45
|
+
* who has asked for reduced motion, and played once — not again when the
|
|
46
|
+
* data changes underneath it.
|
|
47
|
+
*/
|
|
48
|
+
animate?: ChartAnimate;
|
|
42
49
|
/** Drop the legend. Only honoured for a single series. */
|
|
43
50
|
legend?: boolean;
|
|
44
51
|
/**
|
|
@@ -101,6 +108,7 @@ declare const __VLS_base: import("vue").DefineComponent<LineChartProps, {}, {},
|
|
|
101
108
|
unstyled: boolean;
|
|
102
109
|
data: readonly LineChartDatum[];
|
|
103
110
|
legend: boolean;
|
|
111
|
+
animate: ChartAnimate;
|
|
104
112
|
flush: boolean;
|
|
105
113
|
height: number;
|
|
106
114
|
ticks: number;
|