@voidable/ui 0.5.4 → 0.6.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.
@@ -0,0 +1,33 @@
1
+ //#region src/components/charts/scale.ts
2
+ var e = class {
3
+ constructor(e, t) {
4
+ this.domain = e, this.range = t;
5
+ }
6
+ scale(e) {
7
+ let [t, n] = this.domain, [r, i] = this.range;
8
+ return n === t ? (r + i) / 2 : r + (e - t) / (n - t) * (i - r);
9
+ }
10
+ ticks(e = 5) {
11
+ let [t, r] = this.domain, i = r - t;
12
+ if (i === 0) return [t];
13
+ let a = n(i / e), o = Math.ceil(t / a) * a, s = [];
14
+ for (let e = o; e <= r + a * 1e-9; e += a) s.push(e);
15
+ return s;
16
+ }
17
+ }, t = class {
18
+ constructor(e, t, n = .2) {
19
+ this.count = e, this.range = t, this.padding = n;
20
+ let r = t[1] - t[0];
21
+ this.step = e > 0 ? r / e : r, this.bandwidth = this.step * (1 - n), this.innerOffset = (this.step - this.bandwidth) / 2;
22
+ }
23
+ scale(e) {
24
+ return this.range[0] + this.step * e + this.innerOffset;
25
+ }
26
+ };
27
+ function n(e) {
28
+ if (e <= 0) return 1;
29
+ let t = 10 ** Math.floor(Math.log10(e)), n = e / t;
30
+ return (n <= 1 ? 1 : n <= 2 ? 2 : n <= 5 ? 5 : 10) * t;
31
+ }
32
+ //#endregion
33
+ export { e as n, t };
@@ -0,0 +1,52 @@
1
+ //#region src/components/charts/shape.ts
2
+ function e(e) {
3
+ return e.length === 0 ? "" : e.map(([e, t], n) => `${n === 0 ? "M" : "L"} ${e.toFixed(2)} ${t.toFixed(2)}`).join(" ");
4
+ }
5
+ function t(e, t) {
6
+ if (e.length === 0) return "";
7
+ let n = e.map(([e, t], n) => `${n === 0 ? "M" : "L"} ${e.toFixed(2)} ${t.toFixed(2)}`).join(" "), r = e[0][0].toFixed(2);
8
+ return `${n} L ${e[e.length - 1][0].toFixed(2)} ${t.toFixed(2)} L ${r} ${t.toFixed(2)} Z`;
9
+ }
10
+ function n(t) {
11
+ if (t.length === 0) return "";
12
+ if (t.length === 1) return `M ${t[0][0].toFixed(2)} ${t[0][1].toFixed(2)}`;
13
+ if (t.length === 2) return e(t);
14
+ let n = t.length, r = [];
15
+ for (let e = 0; e < n - 1; e++) {
16
+ let n = t[e + 1][0] - t[e][0], i = t[e + 1][1] - t[e][1];
17
+ r.push(n === 0 ? 0 : i / n);
18
+ }
19
+ let i = Array(n);
20
+ i[0] = r[0], i[n - 1] = r[n - 2];
21
+ for (let e = 1; e < n - 1; e++) r[e - 1] * r[e] <= 0 ? i[e] = 0 : i[e] = (r[e - 1] + r[e]) / 2;
22
+ for (let e = 0; e < n - 1; e++) {
23
+ if (r[e] === 0) {
24
+ i[e] = 0, i[e + 1] = 0;
25
+ continue;
26
+ }
27
+ let t = i[e] / r[e], n = i[e + 1] / r[e], a = t * t + n * n;
28
+ if (a > 9) {
29
+ let o = 3 / Math.sqrt(a);
30
+ i[e] = o * t * r[e], i[e + 1] = o * n * r[e];
31
+ }
32
+ }
33
+ let a = [`M ${t[0][0].toFixed(2)} ${t[0][1].toFixed(2)}`];
34
+ for (let e = 0; e < n - 1; e++) {
35
+ let [n, r] = t[e], [o, s] = t[e + 1], c = (o - n) / 3, l = n + c, u = r + i[e] * c, d = o - c, f = s - i[e + 1] * c;
36
+ a.push(`C ${l.toFixed(2)} ${u.toFixed(2)} ${d.toFixed(2)} ${f.toFixed(2)} ${o.toFixed(2)} ${s.toFixed(2)}`);
37
+ }
38
+ return a.join(" ");
39
+ }
40
+ function r(e, t) {
41
+ if (e.length === 0) return "";
42
+ let r = n(e), i = e[0][0].toFixed(2);
43
+ return `${r} L ${e[e.length - 1][0].toFixed(2)} ${t.toFixed(2)} L ${i} ${t.toFixed(2)} Z`;
44
+ }
45
+ function i(e, t, n, r, i, a = 0) {
46
+ let o = e + n * Math.cos(r), s = t + n * Math.sin(r), c = e + n * Math.cos(i), l = t + n * Math.sin(i), u = +(i - r > Math.PI);
47
+ if (a <= 0) return `M ${e} ${t} L ${o.toFixed(2)} ${s.toFixed(2)} A ${n} ${n} 0 ${u} 1 ${c.toFixed(2)} ${l.toFixed(2)} Z`;
48
+ let d = e + a * Math.cos(i), f = t + a * Math.sin(i), p = e + a * Math.cos(r), m = t + a * Math.sin(r);
49
+ return `M ${o.toFixed(2)} ${s.toFixed(2)} A ${n} ${n} 0 ${u} 1 ${c.toFixed(2)} ${l.toFixed(2)} L ${d.toFixed(2)} ${f.toFixed(2)} A ${a} ${a} 0 ${u} 0 ${p.toFixed(2)} ${m.toFixed(2)} Z`;
50
+ }
51
+ //#endregion
52
+ export { n as a, r as i, t as n, e as r, i as t };
@@ -0,0 +1,47 @@
1
+ import { LitElement } from 'lit';
2
+ export interface BarChartSeries {
3
+ name: string;
4
+ values: number[];
5
+ /** Series-wide color. Falls back to the rotating palette when omitted. */
6
+ color?: string;
7
+ /** Per-bar color override, index-aligned with `values`. Use a sparse array
8
+ (or `undefined`s) to override only specific bars; the rest fall back to
9
+ `series.color` or the palette. */
10
+ colors?: Array<string | undefined>;
11
+ }
12
+ export interface BarChartData {
13
+ series: BarChartSeries[];
14
+ labels?: string[];
15
+ }
16
+ export declare class VoidBarChart extends LitElement {
17
+ createRenderRoot(): this;
18
+ height: number;
19
+ showValues: boolean;
20
+ variant: 'filled' | 'outline' | 'wireframe';
21
+ ariaLabel: string;
22
+ stagger: boolean | number;
23
+ private _data;
24
+ get data(): BarChartData;
25
+ set data(next: BarChartData);
26
+ private _phase;
27
+ private _display;
28
+ private _targets;
29
+ private _animFrom;
30
+ private _animStart;
31
+ private _animDuration;
32
+ private _staggerMs;
33
+ private _rafHandle;
34
+ private _key;
35
+ private _refreshTargets;
36
+ connectedCallback(): void;
37
+ disconnectedCallback(): void;
38
+ private _startAnimation;
39
+ private _tick;
40
+ render(): import('lit').TemplateResult<1>;
41
+ }
42
+ declare global {
43
+ interface HTMLElementTagNameMap {
44
+ 'void-bar-chart': VoidBarChart;
45
+ }
46
+ }
47
+ //# sourceMappingURL=bar-chart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bar-chart.d.ts","sourceRoot":"","sources":["../../src/components/bar-chart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,MAAM,KAAK,CAAC;AAIrD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;yCAEqC;IACrC,MAAM,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AA2BD,qBAAa,YAAa,SAAQ,UAAU;IAC1C,gBAAgB,IAAI,IAAI;IAEmB,MAAM,SAAO;IACc,UAAU,UAAS;IAC5D,OAAO,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAY;IAC7C,SAAS,SAAM;IAcnD,OAAO,EAAE,OAAO,GAAG,MAAM,CAAQ;IAEpC,OAAO,CAAC,KAAK,CAAgC;IAE7C,IAAI,IAAI,IAAI,YAAY,CAAuB;IAC/C,IAAI,IAAI,CAAC,IAAI,EAAE,YAAY,EAM1B;IAEQ,OAAO,CAAC,MAAM,CAAuC;IAC9D,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,QAAQ,CAA6B;IAC7C,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,IAAI;IAEZ,OAAO,CAAC,eAAe;IAOvB,iBAAiB;IAOjB,oBAAoB;IAKpB,OAAO,CAAC,eAAe;IA4BvB,OAAO,CAAC,KAAK,CA0BX;IAEF,MAAM;CA0FP;AAMD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,gBAAgB,EAAE,YAAY,CAAC;KAChC;CACF"}
@@ -0,0 +1,151 @@
1
+ import { t as e } from "../chunks/decorate-DKuCkHK4.js";
2
+ import { n as t, t as n } from "../chunks/scale-BFZNL3Ss.js";
3
+ import { LitElement as r, html as i, nothing as a, svg as o } from "lit";
4
+ import { property as s, state as c } from "lit/decorators.js";
5
+ //#region src/components/bar-chart.ts
6
+ function l(e) {
7
+ return 1 - (1 - e) ** 3;
8
+ }
9
+ function u(e) {
10
+ return e === 0 ? "0" : Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(e >= 1e4 ? 0 : 1)}k` : Number.isInteger(e) ? String(e) : e.toFixed(1);
11
+ }
12
+ function d(e) {
13
+ return Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(e >= 1e4 ? 0 : 1)}k` : Math.round(e).toString();
14
+ }
15
+ function f(e) {
16
+ if (e <= 0) return 1;
17
+ let t = 10 ** Math.floor(Math.log10(e)), n = e / t;
18
+ return (n <= 1 ? 1 : n <= 2 ? 2 : n <= 5 ? 5 : 10) * t;
19
+ }
20
+ var p = class extends r {
21
+ constructor(...e) {
22
+ super(...e), this.height = 220, this.showValues = !1, this.variant = "filled", this.ariaLabel = "", this.stagger = !0, this._data = { series: [] }, this._phase = "pre", this._display = /* @__PURE__ */ new Map(), this._targets = /* @__PURE__ */ new Map(), this._animFrom = /* @__PURE__ */ new Map(), this._animStart = 0, this._animDuration = 0, this._staggerMs = 0, this._rafHandle = 0, this._tick = (e) => {
23
+ let t = e - this._animStart, n = !1;
24
+ for (let [e, r] of this._targets) {
25
+ let [, i] = e.split("-"), a = Number(i) * this._staggerMs, o = a + this._animDuration, s = this._animFrom.get(e) ?? 0;
26
+ if (t <= a) this._display.set(e, s), n = !0;
27
+ else if (t >= o) this._display.set(e, r);
28
+ else {
29
+ let i = (t - a) / this._animDuration;
30
+ this._display.set(e, s + (r - s) * l(i)), n = !0;
31
+ }
32
+ }
33
+ this.requestUpdate(), n ? this._rafHandle = requestAnimationFrame(this._tick) : this._phase = "idle";
34
+ };
35
+ }
36
+ createRenderRoot() {
37
+ return this;
38
+ }
39
+ get data() {
40
+ return this._data;
41
+ }
42
+ set data(e) {
43
+ let t = new Map(this._display);
44
+ this._data = e, this._refreshTargets(), this.requestUpdate(), this.updateComplete.then(() => this._startAnimation(t));
45
+ }
46
+ _key(e, t) {
47
+ return `${e}-${t}`;
48
+ }
49
+ _refreshTargets() {
50
+ this._targets.clear(), this._data.series.forEach((e, t) => {
51
+ e.values.forEach((e, n) => this._targets.set(this._key(t, n), e));
52
+ });
53
+ }
54
+ connectedCallback() {
55
+ super.connectedCallback(), this.setAttribute("role", "img"), this._refreshTargets(), requestAnimationFrame(() => {
56
+ this._startAnimation(/* @__PURE__ */ new Map());
57
+ });
58
+ }
59
+ disconnectedCallback() {
60
+ super.disconnectedCallback(), cancelAnimationFrame(this._rafHandle);
61
+ }
62
+ _startAnimation(e) {
63
+ cancelAnimationFrame(this._rafHandle);
64
+ let t = getComputedStyle(this), n = t.getPropertyValue("--void-anim-scale").trim(), r = n === "" ? 1 : parseFloat(n), i = parseFloat(t.getPropertyValue("--void-duration-chart-enter")) || 700, a = parseFloat(t.getPropertyValue("--void-stagger-chart-bars")) || 40;
65
+ if (this._animDuration = i * r, this.stagger === !1 ? this._staggerMs = 0 : this.stagger === !0 ? this._staggerMs = a * r : this._staggerMs = this.stagger * r, this._animFrom = e, this._animStart = performance.now(), this._animDuration <= 0) {
66
+ this._display = new Map(this._targets), this._phase = "idle", this.requestUpdate();
67
+ return;
68
+ }
69
+ this._phase = "animating", this._rafHandle = requestAnimationFrame(this._tick);
70
+ }
71
+ render() {
72
+ let { series: e, labels: r = [] } = this._data;
73
+ if (e.length === 0) return i`<svg viewBox="0 0 600 ${this.height}" aria-label=${this.ariaLabel}></svg>`;
74
+ let s = this.height - 16 - 32, c = Math.max(...e.map((e) => e.values.length)), l = e.flatMap((e) => e.values), p = new t([0, f(Math.max(...l, 0) * 1.1) || 1], [16 + s, 16]), m = new n(c, [40, 584], .2), h = p.ticks(5);
75
+ return i`
76
+ <svg
77
+ viewBox="0 0 600 ${this.height}"
78
+ preserveAspectRatio="none"
79
+ role="img"
80
+ aria-label=${this.ariaLabel || "Bar chart"}
81
+ data-phase=${this._phase}
82
+ >
83
+ <g class="void-bar-chart-grid">
84
+ ${h.map((e) => {
85
+ let t = p.scale(e);
86
+ return o`<line x1=${40} x2=${584} y1=${t} y2=${t}></line>`;
87
+ })}
88
+ </g>
89
+
90
+ <g class="void-bar-chart-y-axis">
91
+ ${h.map((e) => o`<text x=${32} y=${p.scale(e)} dy="0.32em" text-anchor="end">${u(e)}</text>`)}
92
+ </g>
93
+
94
+ ${e.map((t, n) => {
95
+ let r = t.color ?? `var(--void-chart-series-${n % 6 + 1})`, i = m.bandwidth / e.length;
96
+ return o`
97
+ <g class="void-bar-chart-series" style="--series-color: ${r}">
98
+ ${t.values.map((e, r) => {
99
+ let c = this._display.get(this._key(n, r)) ?? 0, l = m.scale(r) + i * n, u = p.scale(c), d = Math.max(0, 16 + s - u), f = t.colors?.[r];
100
+ return o`<rect
101
+ class="void-bar-chart-bar"
102
+ x=${l}
103
+ y=${u}
104
+ width=${i - 2}
105
+ height=${d}
106
+ style=${f ? `--series-color: ${f}` : a}
107
+ ></rect>`;
108
+ })}
109
+ </g>
110
+ `;
111
+ })}
112
+
113
+ ${this.showValues ? e.map((t, n) => {
114
+ let r = m.bandwidth / e.length;
115
+ return o`
116
+ <g class="void-bar-chart-values">
117
+ ${t.values.map((e, t) => {
118
+ let i = this._display.get(this._key(n, t)) ?? 0;
119
+ return o`<text x=${m.scale(t) + r * n + (r - 2) / 2} y=${p.scale(i) - 6} text-anchor="middle">${d(i)}</text>`;
120
+ })}
121
+ </g>
122
+ `;
123
+ }) : a}
124
+
125
+ <g class="void-bar-chart-x-axis">
126
+ ${r.slice(0, c).map((e, t) => o`<text x=${m.scale(t) + m.bandwidth / 2} y=${16 + s + 18} text-anchor="middle">${e}</text>`)}
127
+ </g>
128
+ </svg>
129
+ `;
130
+ }
131
+ };
132
+ e([s({
133
+ type: Number,
134
+ reflect: !0
135
+ })], p.prototype, "height", void 0), e([s({
136
+ type: Boolean,
137
+ attribute: "show-values",
138
+ reflect: !0
139
+ })], p.prototype, "showValues", void 0), e([s({ reflect: !0 })], p.prototype, "variant", void 0), e([s({ attribute: "aria-label" })], p.prototype, "ariaLabel", void 0), e([s({ converter: {
140
+ fromAttribute(e) {
141
+ if (e === null || e === "" || e === "true") return !0;
142
+ if (e === "false") return !1;
143
+ let t = Number(e);
144
+ return isNaN(t) ? !0 : t;
145
+ },
146
+ toAttribute(e) {
147
+ return e === !0 ? "" : e === !1 ? "false" : String(e);
148
+ }
149
+ } })], p.prototype, "stagger", void 0), e([c()], p.prototype, "_phase", void 0), customElements.get("void-bar-chart") || customElements.define("void-bar-chart", p);
150
+ //#endregion
151
+ export { p as VoidBarChart };
@@ -0,0 +1,22 @@
1
+ /** Maps a continuous numeric domain to a pixel range. */
2
+ export declare class LinearScale {
3
+ domain: [number, number];
4
+ range: [number, number];
5
+ constructor(domain: [number, number], range: [number, number]);
6
+ scale(value: number): number;
7
+ /** Generate "nice" round tick values that span the domain. */
8
+ ticks(count?: number): number[];
9
+ }
10
+ /** Maps categorical indices to evenly-spaced band positions. */
11
+ export declare class BandScale {
12
+ count: number;
13
+ range: [number, number];
14
+ padding: number;
15
+ bandwidth: number;
16
+ step: number;
17
+ private innerOffset;
18
+ constructor(count: number, range: [number, number], padding?: number);
19
+ /** Left-edge x for the band at index. */
20
+ scale(index: number): number;
21
+ }
22
+ //# sourceMappingURL=scale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale.d.ts","sourceRoot":"","sources":["../../../src/components/charts/scale.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,qBAAa,WAAW;IAEb,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;gBADvB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IAGhC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAO5B,8DAA8D;IAC9D,KAAK,CAAC,KAAK,SAAI,GAAG,MAAM,EAAE;CAU3B;AAED,gEAAgE;AAChE,qBAAa,SAAS;IAMX,KAAK,EAAE,MAAM;IACb,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACvB,OAAO;IAPhB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,WAAW,CAAS;gBAGnB,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACvB,OAAO,SAAM;IAQtB,yCAAyC;IACzC,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAG7B"}
@@ -0,0 +1,13 @@
1
+ /** SVG path for a polyline through points. */
2
+ export declare function linePath(points: Array<[number, number]>): string;
3
+ /** SVG path for the filled area between a polyline and a baseline. */
4
+ export declare function areaPath(points: Array<[number, number]>, baseline: number): string;
5
+ /** SVG path through points using monotone cubic interpolation (Fritsch–Carlson).
6
+ Preserves monotonicity — the curve won't overshoot above local maxima or
7
+ below local minima between data points. Output is a series of cubic Beziers. */
8
+ export declare function smoothLinePath(points: Array<[number, number]>): string;
9
+ /** SVG path for a smooth-curve area between a monotone cubic line and a baseline. */
10
+ export declare function smoothAreaPath(points: Array<[number, number]>, baseline: number): string;
11
+ /** SVG path for a circular arc segment (donut/pie wedge). */
12
+ export declare function arcPath(cx: number, cy: number, outerR: number, startAngle: number, endAngle: number, innerR?: number): string;
13
+ //# sourceMappingURL=shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../../src/components/charts/shape.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,wBAAgB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAKhE;AAED,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQlF;AAED;;mFAEmF;AACnF,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CA4CtE;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMxF;AAED,6DAA6D;AAC7D,wBAAgB,OAAO,CACrB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,MAAM,SAAI,GACT,MAAM,CAgBR"}
@@ -0,0 +1,57 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ export interface DonutChartSegment {
3
+ name: string;
4
+ value: number;
5
+ color?: string;
6
+ }
7
+ export interface DonutChartData {
8
+ segments: DonutChartSegment[];
9
+ }
10
+ export declare class VoidDonutChart extends LitElement {
11
+ createRenderRoot(): this;
12
+ size: number;
13
+ inner: number;
14
+ /** Visible gap between segments. `false`/`0` = seamless (segments touch).
15
+ `true` = 1% of the total arc consumed by gaps (the sensible default
16
+ when you want visible separation). A number = explicit percent of the
17
+ total arc consumed by gaps. Higher % = clearer segmentation but more
18
+ arc sacrificed to whitespace; the precision-vs-clarity tradeoff. */
19
+ gaps: boolean | number;
20
+ variant: 'filled' | 'outline' | 'wireframe';
21
+ showValues: boolean;
22
+ showTotal: boolean;
23
+ ariaLabel: string;
24
+ private _data;
25
+ get data(): DonutChartData;
26
+ set data(next: DonutChartData);
27
+ private _phase;
28
+ private _hoverSegment;
29
+ private _hoverX;
30
+ private _hoverY;
31
+ private _progress;
32
+ private _progressFrom;
33
+ private _displayValues;
34
+ private _targetValues;
35
+ private _animFrom;
36
+ private _displayTotal;
37
+ private _displayTotalFrom;
38
+ private _targetTotal;
39
+ private _animStart;
40
+ private _animDuration;
41
+ private _rafHandle;
42
+ private _refreshTargets;
43
+ connectedCallback(): void;
44
+ disconnectedCallback(): void;
45
+ private _onMouseMove;
46
+ private _onMouseLeave;
47
+ private _startAnimation;
48
+ private _tick;
49
+ render(): TemplateResult<1>;
50
+ private _renderHoverTooltip;
51
+ }
52
+ declare global {
53
+ interface HTMLElementTagNameMap {
54
+ 'void-donut-chart': VoidDonutChart;
55
+ }
56
+ }
57
+ //# sourceMappingURL=donut-chart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"donut-chart.d.ts","sourceRoot":"","sources":["../../src/components/donut-chart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAsB,KAAK,cAAc,EAAE,MAAM,KAAK,CAAC;AAI1E,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,iBAAiB,EAAE,CAAC;CAC/B;AAgBD,qBAAa,cAAe,SAAQ,UAAU;IAC5C,gBAAgB,IAAI,IAAI;IAEmB,IAAI,SAAO;IAC1B,KAAK,SAAO;IACxC;;;;2EAIuE;IAapE,IAAI,EAAE,OAAO,GAAG,MAAM,CAAS;IACL,OAAO,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAY;IACd,UAAU,UAAS;IACpB,SAAS,UAAS;IAChD,SAAS,SAAM;IAEtD,OAAO,CAAC,KAAK,CAAoC;IAEjD,IAAI,IAAI,IAAI,cAAc,CAAuB;IACjD,IAAI,IAAI,CAAC,IAAI,EAAE,cAAc,EAoB5B;IAEQ,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,aAAa,CAAuB;IAC5C,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAa;IACrC,OAAO,CAAC,SAAS,CAAK;IACtB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,cAAc,CAA6B;IACnD,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,SAAS,CAA6B;IAC9C,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,UAAU,CAAK;IAEvB,OAAO,CAAC,eAAe;IASvB,iBAAiB;IASjB,oBAAoB;IAOpB,OAAO,CAAC,YAAY,CAuClB;IAEF,OAAO,CAAC,aAAa,CAEnB;IAEF,OAAO,CAAC,eAAe;IA+BvB,OAAO,CAAC,KAAK,CAoBX;IAEF,MAAM;IA6FN,OAAO,CAAC,mBAAmB;CAgD5B;AAMD,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,kBAAkB,EAAE,cAAc,CAAC;KACpC;CACF"}
@@ -0,0 +1,187 @@
1
+ import { t as e } from "../chunks/decorate-DKuCkHK4.js";
2
+ import { t } from "../chunks/shape-DmgCwYvY.js";
3
+ import { LitElement as n, html as r, nothing as i, svg as a } from "lit";
4
+ import { property as o, state as s } from "lit/decorators.js";
5
+ //#region src/components/donut-chart.ts
6
+ function c(e) {
7
+ return 1 - (1 - e) ** 3;
8
+ }
9
+ function l(e) {
10
+ return Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(e >= 1e4 ? 0 : 1)}k` : Math.round(e).toString();
11
+ }
12
+ function u(e) {
13
+ return Math.abs(e) >= 1e3 ? `${(e / 1e3).toFixed(e >= 1e4 ? 0 : 1)}k` : Math.round(e).toString();
14
+ }
15
+ var d = class extends n {
16
+ constructor(...e) {
17
+ super(...e), this.size = 220, this.inner = .6, this.gaps = !1, this.variant = "filled", this.showValues = !1, this.showTotal = !1, this.ariaLabel = "", this._data = { segments: [] }, this._phase = "pre", this._hoverSegment = null, this._hoverX = 0, this._hoverY = 0, this._progress = 0, this._progressFrom = 0, this._displayValues = /* @__PURE__ */ new Map(), this._targetValues = /* @__PURE__ */ new Map(), this._animFrom = /* @__PURE__ */ new Map(), this._displayTotal = 0, this._displayTotalFrom = 0, this._targetTotal = 0, this._animStart = 0, this._animDuration = 0, this._rafHandle = 0, this._onMouseMove = (e) => {
18
+ let t = this.querySelector("svg");
19
+ if (!t) return;
20
+ let n = this._data.segments;
21
+ if (n.length === 0 || this._displayTotal <= 0) return;
22
+ let r = t.getBoundingClientRect();
23
+ if (r.width === 0) return;
24
+ let i = (e.clientX - r.left) / r.width * this.size, a = (e.clientY - r.top) / r.height * this.size, o = this.size / 2, s = this.size / 2, c = i - o, l = a - s, u = Math.sqrt(c * c + l * l), d = this.size / 2 - 4;
25
+ if (u < d * this.inner || u > d) {
26
+ this._hoverSegment !== null && (this._hoverSegment = null);
27
+ return;
28
+ }
29
+ let f = Math.atan2(l, c) - -Math.PI / 2;
30
+ f < 0 && (f += 2 * Math.PI);
31
+ let p = 2 * Math.PI, m = 0;
32
+ for (let e = 0; e < n.length; e++) {
33
+ let t = n[e].value / this._targetTotal * p;
34
+ if (f >= m && f < m + t) {
35
+ this._hoverSegment !== e && (this._hoverSegment = e), this._hoverX = i, this._hoverY = a;
36
+ return;
37
+ }
38
+ m += t;
39
+ }
40
+ this._hoverSegment !== null && (this._hoverSegment = null);
41
+ }, this._onMouseLeave = () => {
42
+ this._hoverSegment = null;
43
+ }, this._tick = (e) => {
44
+ let t = e - this._animStart, n = Math.min(t / this._animDuration, 1), r = c(n);
45
+ this._progress = this._progressFrom + (1 - this._progressFrom) * r;
46
+ for (let [e, t] of this._targetValues) {
47
+ let n = this._animFrom.get(e) ?? 0;
48
+ this._displayValues.set(e, n + (t - n) * r);
49
+ }
50
+ this._displayTotal = this._displayTotalFrom + (this._targetTotal - this._displayTotalFrom) * r, this.requestUpdate(), n < 1 ? this._rafHandle = requestAnimationFrame(this._tick) : this._phase = "idle";
51
+ };
52
+ }
53
+ createRenderRoot() {
54
+ return this;
55
+ }
56
+ get data() {
57
+ return this._data;
58
+ }
59
+ set data(e) {
60
+ let t = this._data.segments, n = this._progress, r = new Map(this._displayValues), i = this._displayTotal;
61
+ this._data = e, this._refreshTargets(), this.requestUpdate(), this.updateComplete.then(() => {
62
+ let a = /* @__PURE__ */ new Map();
63
+ for (let e = 0; e < t.length; e++) a.set(e, r.get(e) ?? 0);
64
+ for (let t = 0; t < e.segments.length; t++) a.has(t) || a.set(t, 0);
65
+ this._startAnimation(a, i, n >= 1 ? 1 : n, !1);
66
+ });
67
+ }
68
+ _refreshTargets() {
69
+ this._targetValues.clear();
70
+ let e = this._data.segments;
71
+ for (let t = 0; t < e.length; t++) this._targetValues.set(t, e[t].value);
72
+ this._targetTotal = e.reduce((e, t) => e + t.value, 0);
73
+ }
74
+ connectedCallback() {
75
+ super.connectedCallback(), this.setAttribute("role", "img"), this._refreshTargets(), requestAnimationFrame(() => {
76
+ this._startAnimation(/* @__PURE__ */ new Map(), 0, 0, !0);
77
+ }), this.addEventListener("mousemove", this._onMouseMove), this.addEventListener("mouseleave", this._onMouseLeave);
78
+ }
79
+ disconnectedCallback() {
80
+ super.disconnectedCallback(), cancelAnimationFrame(this._rafHandle), this.removeEventListener("mousemove", this._onMouseMove), this.removeEventListener("mouseleave", this._onMouseLeave);
81
+ }
82
+ _startAnimation(e, t, n, r) {
83
+ cancelAnimationFrame(this._rafHandle);
84
+ let i = getComputedStyle(this), a = i.getPropertyValue("--void-anim-scale").trim(), o = a === "" ? 1 : parseFloat(a), s = parseFloat(i.getPropertyValue("--void-duration-chart-enter")) || 700;
85
+ if (this._animDuration = s * o, this._animFrom = e, this._displayTotalFrom = t, this._progressFrom = r ? 0 : n, this._progress = this._progressFrom, this._animStart = performance.now(), this._animDuration <= 0) {
86
+ this._progress = 1, this._displayValues = new Map(this._targetValues), this._displayTotal = this._targetTotal, this._phase = "idle", this.requestUpdate();
87
+ return;
88
+ }
89
+ this._phase = "animating", this._rafHandle = requestAnimationFrame(this._tick);
90
+ }
91
+ render() {
92
+ let { segments: e } = this._data, n = e.reduce((e, t) => e + t.value, 0);
93
+ if (e.length === 0 || n === 0) return r`<svg viewBox="0 0 ${this.size} ${this.size}" role="img" aria-label=${this.ariaLabel || "Donut chart"}></svg>`;
94
+ let o = this.size / 2, s = this.size / 2, c = this.size / 2 - 4, d = c * this.inner, f = Math.max(this._displayTotal, .001), p = 2 * Math.PI, m = -Math.PI / 2 + this._progress * p, h = (this.gaps === !0 ? 1 : this.gaps === !1 ? 0 : this.gaps) / 100 * p, g = (e.length > 0 ? h / e.length : 0) / 2, _ = [], v = -Math.PI / 2;
95
+ for (let n = 0; n < e.length; n++) {
96
+ let r = e[n], i = this._displayValues.get(n) ?? 0, l = v, u = l + i / f * p, h = Math.min(u, m);
97
+ if (h > l + .001) {
98
+ let e = r.color ?? `var(--void-chart-series-${n % 6 + 1})`, i = l + g, u = Math.max(i + .001, h - g);
99
+ _.push(a`
100
+ <path
101
+ class="void-donut-chart-segment"
102
+ d=${t(o, s, c, i, u, d)}
103
+ style="--segment-color: ${e}"
104
+ data-segment-index=${n}
105
+ ></path>
106
+ `);
107
+ }
108
+ v = u;
109
+ }
110
+ return r`
111
+ <svg
112
+ viewBox="0 0 ${this.size} ${this.size}"
113
+ role="img"
114
+ aria-label=${this.ariaLabel || "Donut chart"}
115
+ data-phase=${this._phase}
116
+ >
117
+ ${_}
118
+ ${this.showTotal ? a`
119
+ <g class="void-donut-chart-total">
120
+ <text x=${o} y=${s} text-anchor="middle" dy="0.32em">${l(this._displayTotal)}</text>
121
+ </g>
122
+ ` : i}
123
+ ${this.showValues ? a`
124
+ <g class="void-donut-chart-labels">
125
+ ${e.map((e, t) => {
126
+ let n = this._displayValues.get(t) ?? 0;
127
+ if (n < .001) return i;
128
+ let r = -Math.PI / 2;
129
+ for (let e = 0; e < t; e++) r += (this._displayValues.get(e) ?? 0) / f * p;
130
+ let l = r + n / f * p / 2, m = (c + d) / 2;
131
+ return a`<text x=${o + m * Math.cos(l)} y=${s + m * Math.sin(l)} text-anchor="middle" dy="0.32em">${u(n)}</text>`;
132
+ })}
133
+ </g>
134
+ ` : i}
135
+
136
+ ${this._hoverSegment !== null && this._hoverSegment < e.length ? this._renderHoverTooltip(e, this._hoverSegment) : i}
137
+ </svg>
138
+ `;
139
+ }
140
+ _renderHoverTooltip(e, t) {
141
+ let n = e[t], r = this._displayValues.get(t) ?? n.value, i = [...this._displayValues.values()].reduce((e, t) => e + t, 0) || this._targetTotal || 1, o = Math.round(r / i * 100), s = this.size / 2, c = this._hoverX < s ? this.size - 140 - 8 : 8, l = this._hoverY - 44 / 2;
142
+ return l < 8 && (l = 8), l + 44 > this.size - 8 && (l = this.size - 44 - 8), a`
143
+ <g class="void-donut-chart-hover" pointer-events="none">
144
+ <rect
145
+ class="void-donut-chart-tooltip-bg"
146
+ x=${c} y=${l}
147
+ width=${140} height=${44}
148
+ rx="6" ry="6"
149
+ ></rect>
150
+ <text
151
+ class="void-donut-chart-tooltip-name"
152
+ x=${c + 8}
153
+ y=${l + 8 + 10}
154
+ >${n.name}</text>
155
+ <text
156
+ class="void-donut-chart-tooltip-value"
157
+ x=${c + 8}
158
+ y=${l + 8 + 14 + 10}
159
+ >${u(r)} <tspan class="void-donut-chart-tooltip-pct">(${o}%)</tspan></text>
160
+ </g>
161
+ `;
162
+ }
163
+ };
164
+ e([o({
165
+ type: Number,
166
+ reflect: !0
167
+ })], d.prototype, "size", void 0), e([o({ type: Number })], d.prototype, "inner", void 0), e([o({ converter: {
168
+ fromAttribute(e) {
169
+ if (e === null || e === "" || e === "true") return !0;
170
+ if (e === "false") return !1;
171
+ let t = Number(e);
172
+ return isNaN(t) ? !0 : t;
173
+ },
174
+ toAttribute(e) {
175
+ return e === !0 ? "" : e === !1 ? "false" : String(e);
176
+ }
177
+ } })], d.prototype, "gaps", void 0), e([o({ reflect: !0 })], d.prototype, "variant", void 0), e([o({
178
+ type: Boolean,
179
+ attribute: "show-values",
180
+ reflect: !0
181
+ })], d.prototype, "showValues", void 0), e([o({
182
+ type: Boolean,
183
+ attribute: "show-total",
184
+ reflect: !0
185
+ })], d.prototype, "showTotal", void 0), e([o({ attribute: "aria-label" })], d.prototype, "ariaLabel", void 0), e([s()], d.prototype, "_phase", void 0), e([s()], d.prototype, "_hoverSegment", void 0), e([s()], d.prototype, "_hoverX", void 0), e([s()], d.prototype, "_hoverY", void 0), customElements.get("void-donut-chart") || customElements.define("void-donut-chart", d);
186
+ //#endregion
187
+ export { d as VoidDonutChart };