@leavepulse/ui 0.24.1 → 0.26.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/dist/assets/LpNumberFlow-rZkwQwlU.css +116 -0
- package/dist/assets/LpRollingText-CR1mb0Vt.css +74 -0
- package/dist/assets/LpSkeleton-D7xU8IPV.css +29 -0
- package/dist/assets/LpSparkline-0mKTq7pb.css +51 -0
- package/dist/assets/LpTooltip-B61SYd4K.css +17 -0
- package/dist/assets/LpUptimeBar-B98o9krI.css +18 -0
- package/dist/chunks/LpChart-tNXs1ttr.js +671 -0
- package/dist/chunks/{LpConfirmDialog-CObRah9c.js → LpConfirmDialog-CjOGcj1e.js} +32 -4
- package/dist/chunks/{LpFileTree-H7Ho8uoq.js → LpFileTree-BaV7f0O7.js} +1 -1
- package/dist/chunks/{LpFileTreeNode-BEZIvxHi.js → LpFileTreeNode-BzpBa7R7.js} +5 -7
- package/dist/chunks/{LpLogViewer-B1aLUVdz.js → LpLogViewer-CcQ3s3Fp.js} +2 -1
- package/dist/chunks/{LpMapPicker-DFKrd1Ne.js → LpMapPicker-CXvoTrAe.js} +2 -4
- package/dist/chunks/{LpNotificationBell-X1M30e0X.js → LpNotificationBell-Dvu-b6Vn.js} +56 -27
- package/dist/chunks/LpNumberFlow-amWYaeuA.js +221 -0
- package/dist/chunks/LpPie-BkjWlfSw.js +525 -0
- package/dist/chunks/LpProgress-DoIP4jQR.js +198 -0
- package/dist/chunks/LpRollingText-CM5gkSeF.js +50 -0
- package/dist/chunks/LpSkeleton-t5mMYl3a.js +29 -0
- package/dist/chunks/LpSparkline-C6xQ2dwv.js +175 -0
- package/dist/chunks/{LpStat-CdbEFOvn.js → LpStat-CDanpzU0.js} +43 -5
- package/dist/chunks/{LpThemeSwitcher-BgpJgrnP.js → LpThemeSwitcher-7mAK6bI7.js} +2 -4
- package/dist/chunks/LpTooltip-hCLPAqMG.js +131 -0
- package/dist/chunks/LpUptimeBar-DcQ8HikG.js +152 -0
- package/dist/component-names.d.ts +1 -1
- package/dist/components/LpChart.vue.d.ts +88 -0
- package/dist/components/LpChart.vue.js +4 -0
- package/dist/components/LpConfirmDialog.vue.d.ts +18 -2
- package/dist/components/LpConfirmDialog.vue.js +1 -1
- package/dist/components/LpFileTree.vue.d.ts +1 -1
- package/dist/components/LpFileTree.vue.js +1 -1
- package/dist/components/LpFileTreeNode.vue.js +1 -1
- package/dist/components/LpLightbox.vue.d.ts +1 -1
- package/dist/components/LpLogViewer.vue.d.ts +1 -1
- package/dist/components/LpLogViewer.vue.js +1 -1
- package/dist/components/LpMapPicker.vue.js +1 -1
- package/dist/components/LpNotificationBell.vue.d.ts +12 -0
- package/dist/components/LpNotificationBell.vue.js +1 -1
- package/dist/components/LpNumberFlow.vue.d.ts +35 -0
- package/dist/components/LpNumberFlow.vue.js +4 -0
- package/dist/components/LpPie.vue.d.ts +134 -0
- package/dist/components/LpPie.vue.js +4 -0
- package/dist/components/LpProgress.vue.d.ts +56 -2
- package/dist/components/LpProgress.vue.js +1 -1
- package/dist/components/LpRollingText.vue.d.ts +33 -0
- package/dist/components/LpRollingText.vue.js +4 -0
- package/dist/components/LpSkeleton.vue.d.ts +11 -1
- package/dist/components/LpSkeleton.vue.js +1 -1
- package/dist/components/LpSparkline.vue.d.ts +48 -0
- package/dist/components/LpSparkline.vue.js +4 -0
- package/dist/components/LpStat.vue.d.ts +25 -2
- package/dist/components/LpStat.vue.js +1 -1
- package/dist/components/LpThemeSwitcher.vue.js +1 -1
- package/dist/components/LpTooltip.vue.d.ts +24 -3
- package/dist/components/LpTooltip.vue.js +1 -1
- package/dist/components/LpUptimeBar.vue.js +1 -1
- package/dist/components/chart.d.ts +180 -0
- package/dist/components/chart.js +353 -0
- package/dist/composables/easing.d.ts +46 -0
- package/dist/composables/easing.js +23 -0
- package/dist/composables/usePillTransition.d.ts +13 -1
- package/dist/composables/usePillTransition.js +22 -2
- package/dist/composables/useReveal.d.ts +26 -0
- package/dist/composables/useReveal.js +45 -0
- package/dist/composables/useSettled.js +2 -2
- package/dist/composables/useShift.js +2 -4
- package/dist/index.d.ts +14 -0
- package/dist/index.js +125 -102
- package/package.json +2 -1
- package/src/component-names.ts +5 -0
- package/src/components/LpChart.vue +846 -0
- package/src/components/LpConfirmDialog.vue +49 -0
- package/src/components/LpFileTreeNode.vue +5 -9
- package/src/components/LpLogViewer.vue +2 -3
- package/src/components/LpMapPicker.vue +2 -5
- package/src/components/LpNotificationBell.vue +76 -15
- package/src/components/LpNumberFlow.vue +524 -0
- package/src/components/LpPie.vue +778 -0
- package/src/components/LpProgress.vue +283 -6
- package/src/components/LpRollingText.vue +157 -0
- package/src/components/LpSkeleton.vue +81 -8
- package/src/components/LpSparkline.vue +312 -0
- package/src/components/LpStat.vue +52 -4
- package/src/components/LpTooltip.vue +185 -3
- package/src/components/LpUptimeBar.vue +150 -53
- package/src/components/chart.ts +686 -0
- package/src/composables/easing.ts +88 -0
- package/src/composables/usePillTransition.ts +71 -6
- package/src/composables/useReveal.ts +113 -0
- package/src/composables/useSettled.ts +2 -4
- package/src/composables/useShift.ts +2 -8
- package/src/index.ts +19 -0
- package/src/theme/useTheme.ts +2 -8
- package/src/tokens/tokens.css +36 -0
- package/dist/chunks/LpProgress-BhI0IbjC.js +0 -37
- package/dist/chunks/LpSkeleton-eSFIo4kD.js +0 -22
- package/dist/chunks/LpTooltip-D1hbjQWG.js +0 -63
- package/dist/chunks/LpUptimeBar-CB366k0O.js +0 -127
|
@@ -0,0 +1,671 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, onMounted, onBeforeUnmount, shallowRef, watch, openBlock, createElementBlock, createElementVNode, toDisplayString, createCommentVNode, renderSlot, Fragment, renderList, normalizeClass, normalizeStyle, createVNode, withCtx, unref, withDirectives, vShow, createBlock, createTextVNode } from "vue";
|
|
2
|
+
import { Motion } from "motion-v";
|
|
3
|
+
import { usePillTransition } from "../composables/usePillTransition.js";
|
|
4
|
+
import { useReveal } from "../composables/useReveal.js";
|
|
5
|
+
import { normalise, pointCount, resolveLabels, extent, axisTicks, niceScale, yAt, plotWidth, xAt, areaPath, linePath, barPath, plotHeight, nearestIndex, formatTick } from "../components/chart.js";
|
|
6
|
+
import { _ as _sfc_main$1 } from "./LpContextMenu-D0mzXqA7.js";
|
|
7
|
+
import { _ as _sfc_main$2 } from "./LpIcon-CCnX5_2j.js";
|
|
8
|
+
import { _ as _sfc_main$3 } from "./LpShift-DXNsauQZ.js";
|
|
9
|
+
const _hoisted_1 = {
|
|
10
|
+
key: 0,
|
|
11
|
+
class: "flex items-start justify-between gap-3"
|
|
12
|
+
};
|
|
13
|
+
const _hoisted_2 = { class: "flex flex-col gap-0.5" };
|
|
14
|
+
const _hoisted_3 = {
|
|
15
|
+
key: 0,
|
|
16
|
+
class: "text-sm font-medium text-ink"
|
|
17
|
+
};
|
|
18
|
+
const _hoisted_4 = {
|
|
19
|
+
key: 1,
|
|
20
|
+
class: "text-xs text-muted"
|
|
21
|
+
};
|
|
22
|
+
const _hoisted_5 = {
|
|
23
|
+
key: 1,
|
|
24
|
+
class: "flex flex-wrap items-center gap-x-4 gap-y-1.5"
|
|
25
|
+
};
|
|
26
|
+
const _hoisted_6 = ["onClick"];
|
|
27
|
+
const _hoisted_7 = { class: "text-muted-strong group-hover:text-ink" };
|
|
28
|
+
const _hoisted_8 = {
|
|
29
|
+
key: 0,
|
|
30
|
+
class: "text-[10px] text-muted",
|
|
31
|
+
title: "Measured on the right axis"
|
|
32
|
+
};
|
|
33
|
+
const _hoisted_9 = {
|
|
34
|
+
key: 0,
|
|
35
|
+
class: "flex size-full flex-col items-center justify-center gap-2 rounded-control border border-dashed border-line text-muted"
|
|
36
|
+
};
|
|
37
|
+
const _hoisted_10 = { class: "text-xs" };
|
|
38
|
+
const _hoisted_11 = ["width", "height"];
|
|
39
|
+
const _hoisted_12 = ["id"];
|
|
40
|
+
const _hoisted_13 = ["stop-color"];
|
|
41
|
+
const _hoisted_14 = ["stop-color"];
|
|
42
|
+
const _hoisted_15 = ["id"];
|
|
43
|
+
const _hoisted_16 = ["x", "height", "width"];
|
|
44
|
+
const _hoisted_17 = ["to"];
|
|
45
|
+
const _hoisted_18 = { key: 0 };
|
|
46
|
+
const _hoisted_19 = ["x1", "x2", "y1", "y2"];
|
|
47
|
+
const _hoisted_20 = ["x", "y"];
|
|
48
|
+
const _hoisted_21 = ["x", "y"];
|
|
49
|
+
const _hoisted_22 = ["x1", "x2", "y1", "y2"];
|
|
50
|
+
const _hoisted_23 = ["x", "y", "width", "height"];
|
|
51
|
+
const _hoisted_24 = ["clip-path"];
|
|
52
|
+
const _hoisted_25 = ["d", "fill", "opacity"];
|
|
53
|
+
const _hoisted_26 = ["d", "fill"];
|
|
54
|
+
const _hoisted_27 = ["d", "stroke", "stroke-dasharray"];
|
|
55
|
+
const _hoisted_28 = ["cx", "cy", "fill"];
|
|
56
|
+
const _hoisted_29 = { key: 3 };
|
|
57
|
+
const _hoisted_30 = ["x1", "x2", "y1", "y2"];
|
|
58
|
+
const _hoisted_31 = ["cx", "cy", "fill"];
|
|
59
|
+
const _hoisted_32 = ["x", "y"];
|
|
60
|
+
const _hoisted_33 = { class: "mb-1 text-[11px] font-medium text-muted-strong" };
|
|
61
|
+
const _hoisted_34 = { class: "flex flex-col gap-1" };
|
|
62
|
+
const _hoisted_35 = { class: "flex items-center gap-1.5 text-muted" };
|
|
63
|
+
const _hoisted_36 = { class: "font-mono tabular-nums text-ink" };
|
|
64
|
+
const CARD_W = 150;
|
|
65
|
+
const CARD_GAP = 14;
|
|
66
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
67
|
+
__name: "LpChart",
|
|
68
|
+
props: {
|
|
69
|
+
series: {},
|
|
70
|
+
labels: {},
|
|
71
|
+
type: { default: "line" },
|
|
72
|
+
height: { default: 240 },
|
|
73
|
+
title: {},
|
|
74
|
+
subtitle: {},
|
|
75
|
+
smooth: { default: 0.9 },
|
|
76
|
+
showPoints: { type: Boolean },
|
|
77
|
+
showGrid: { type: Boolean, default: true },
|
|
78
|
+
showXAxis: { type: Boolean, default: true },
|
|
79
|
+
showYAxis: { type: Boolean, default: true },
|
|
80
|
+
showLegend: { type: Boolean, default: true },
|
|
81
|
+
yTicks: { default: 4 },
|
|
82
|
+
includeZero: { type: Boolean },
|
|
83
|
+
unit: {},
|
|
84
|
+
rightUnit: {},
|
|
85
|
+
formatValue: {},
|
|
86
|
+
formatRightValue: {},
|
|
87
|
+
stacked: { type: Boolean },
|
|
88
|
+
animate: { type: Boolean, default: true },
|
|
89
|
+
emptyLabel: { default: "No data" },
|
|
90
|
+
menuItems: {}
|
|
91
|
+
},
|
|
92
|
+
emits: ["pointClick", "pointContextMenu"],
|
|
93
|
+
setup(__props, { emit: __emit }) {
|
|
94
|
+
const props = __props;
|
|
95
|
+
const emit = __emit;
|
|
96
|
+
const root = ref(null);
|
|
97
|
+
const width = ref(0);
|
|
98
|
+
let ro = null;
|
|
99
|
+
const { el: revealAnchor, revealed } = useReveal({ immediate: () => !props.animate });
|
|
100
|
+
const drawing = computed(() => props.animate && revealed.value);
|
|
101
|
+
onMounted(() => {
|
|
102
|
+
revealAnchor.value = root.value;
|
|
103
|
+
if (!root.value || typeof ResizeObserver === "undefined") return;
|
|
104
|
+
ro = new ResizeObserver(([entry]) => {
|
|
105
|
+
width.value = entry.contentRect.width;
|
|
106
|
+
});
|
|
107
|
+
ro.observe(root.value);
|
|
108
|
+
width.value = root.value.clientWidth;
|
|
109
|
+
});
|
|
110
|
+
onBeforeUnmount(() => {
|
|
111
|
+
ro?.disconnect();
|
|
112
|
+
ro = null;
|
|
113
|
+
});
|
|
114
|
+
const hidden = ref(/* @__PURE__ */ new Set());
|
|
115
|
+
const toggleSeries = (name) => {
|
|
116
|
+
const next = new Set(hidden.value);
|
|
117
|
+
if (next.has(name)) next.delete(name);
|
|
118
|
+
else next.add(name);
|
|
119
|
+
if (next.size < props.series.length) hidden.value = next;
|
|
120
|
+
};
|
|
121
|
+
const allSeries = computed(() => normalise(props.series));
|
|
122
|
+
const visible = computed(() => allSeries.value.filter((s) => !hidden.value.has(s.name)));
|
|
123
|
+
const count = computed(() => pointCount(allSeries.value));
|
|
124
|
+
const labels = computed(() => resolveLabels(props.series, props.labels, count.value));
|
|
125
|
+
const banded = computed(() => props.type === "bar");
|
|
126
|
+
const hasData = computed(
|
|
127
|
+
() => allSeries.value.some((s) => s.values.some((v) => v != null))
|
|
128
|
+
);
|
|
129
|
+
const zeroBased = computed(() => props.includeZero || props.type === "bar");
|
|
130
|
+
const stackTotals = computed(() => {
|
|
131
|
+
if (!(props.type === "bar" && props.stacked)) return null;
|
|
132
|
+
const pos = [];
|
|
133
|
+
const neg = [];
|
|
134
|
+
for (let i = 0; i < count.value; i++) {
|
|
135
|
+
let p = 0;
|
|
136
|
+
let n = 0;
|
|
137
|
+
for (const s of visible.value) {
|
|
138
|
+
const v = s.values[i];
|
|
139
|
+
if (v == null) continue;
|
|
140
|
+
if (v >= 0) p += v;
|
|
141
|
+
else n += v;
|
|
142
|
+
}
|
|
143
|
+
pos.push(p);
|
|
144
|
+
neg.push(n);
|
|
145
|
+
}
|
|
146
|
+
return { pos, neg };
|
|
147
|
+
});
|
|
148
|
+
const onRight = computed(() => visible.value.filter((s) => s.axis === "right"));
|
|
149
|
+
const onLeft = computed(() => {
|
|
150
|
+
const left = visible.value.filter((s) => s.axis === "left");
|
|
151
|
+
return left.length || !onRight.value.length ? left : visible.value;
|
|
152
|
+
});
|
|
153
|
+
const hasRightAxis = computed(() => onRight.value.length > 0 && onLeft.value !== visible.value);
|
|
154
|
+
const scaleFor = (members) => {
|
|
155
|
+
const totals = stackTotals.value;
|
|
156
|
+
const raw = totals ? { min: Math.min(0, ...totals.neg), max: Math.max(0, ...totals.pos) } : extent(members, zeroBased.value);
|
|
157
|
+
return niceScale(raw.min, raw.max, props.yTicks);
|
|
158
|
+
};
|
|
159
|
+
const scale = computed(() => scaleFor(onLeft.value));
|
|
160
|
+
const rightScale = computed(() => {
|
|
161
|
+
if (!hasRightAxis.value) return null;
|
|
162
|
+
const raw = extent(onRight.value, zeroBased.value);
|
|
163
|
+
const steps = Math.max(1, axisTicks(scale.value.min, scale.value.max, scale.value.step).length - 1);
|
|
164
|
+
const nice = niceScale(raw.min, raw.max, steps);
|
|
165
|
+
return { min: nice.min, max: nice.min + nice.step * steps, step: nice.step };
|
|
166
|
+
});
|
|
167
|
+
const fmtWith = (v, unit, f) => `${f ? f(v) : formatTick(v)}${unit ?? ""}`;
|
|
168
|
+
const fmt = (v) => fmtWith(v, props.unit, props.formatValue);
|
|
169
|
+
const fmtRight = (v) => fmtWith(v, props.rightUnit ?? props.unit, props.formatRightValue ?? props.formatValue);
|
|
170
|
+
const fmtSeries = (s, v) => s.axis === "right" && hasRightAxis.value ? fmtRight(v) : fmt(v);
|
|
171
|
+
const scaleOf = (s) => s.axis === "right" && rightScale.value ? rightScale.value : scale.value;
|
|
172
|
+
const yLabels = computed(
|
|
173
|
+
() => axisTicks(scale.value.min, scale.value.max, scale.value.step).map(fmt)
|
|
174
|
+
);
|
|
175
|
+
const rightLabels = computed(
|
|
176
|
+
() => rightScale.value ? axisTicks(rightScale.value.min, rightScale.value.max, rightScale.value.step).map(fmtRight) : []
|
|
177
|
+
);
|
|
178
|
+
const gutter = (labels2) => 12 + Math.max(...labels2.map((l) => l.length), 1) * 7;
|
|
179
|
+
const box = computed(() => ({
|
|
180
|
+
width: width.value,
|
|
181
|
+
height: props.height,
|
|
182
|
+
left: props.showYAxis ? gutter(yLabels.value) : 8,
|
|
183
|
+
right: props.showYAxis && rightLabels.value.length ? gutter(rightLabels.value) : 12,
|
|
184
|
+
top: 10,
|
|
185
|
+
bottom: props.showXAxis ? 26 : 8
|
|
186
|
+
}));
|
|
187
|
+
const geo = computed(() => ({
|
|
188
|
+
min: scale.value.min,
|
|
189
|
+
max: scale.value.max,
|
|
190
|
+
box: box.value,
|
|
191
|
+
count: count.value,
|
|
192
|
+
banded: banded.value
|
|
193
|
+
}));
|
|
194
|
+
const geoOf = (s) => ({ ...geo.value, ...scaleOf(s) });
|
|
195
|
+
const gridLines = computed(() => {
|
|
196
|
+
const left = axisTicks(scale.value.min, scale.value.max, scale.value.step);
|
|
197
|
+
const right = rightScale.value ? axisTicks(rightScale.value.min, rightScale.value.max, rightScale.value.step) : [];
|
|
198
|
+
return left.map((v, i) => ({
|
|
199
|
+
v,
|
|
200
|
+
y: yAt(v, scale.value.min, scale.value.max, box.value),
|
|
201
|
+
label: fmt(v),
|
|
202
|
+
rightLabel: right[i] != null ? fmtRight(right[i]) : ""
|
|
203
|
+
}));
|
|
204
|
+
});
|
|
205
|
+
const xLabelStride = computed(() => {
|
|
206
|
+
const w = plotWidth(box.value);
|
|
207
|
+
if (w <= 0 || count.value === 0) return 1;
|
|
208
|
+
const longest = Math.max(...labels.value.map((l) => l.length), 1);
|
|
209
|
+
return Math.max(1, Math.ceil(count.value * (longest * 6.5 + 16) / w));
|
|
210
|
+
});
|
|
211
|
+
const xLabels = computed(
|
|
212
|
+
() => labels.value.map((label, i) => ({ label, i, x: xAt(i, count.value, box.value, banded.value) })).filter(({ i }) => i % xLabelStride.value === 0 || i === count.value - 1)
|
|
213
|
+
);
|
|
214
|
+
const baseY = computed(
|
|
215
|
+
() => yAt(
|
|
216
|
+
Math.max(scale.value.min, Math.min(scale.value.max, 0)),
|
|
217
|
+
scale.value.min,
|
|
218
|
+
scale.value.max,
|
|
219
|
+
box.value
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
const lines = computed(
|
|
223
|
+
() => visible.value.map((s) => {
|
|
224
|
+
const g = geoOf(s);
|
|
225
|
+
return {
|
|
226
|
+
...s,
|
|
227
|
+
d: linePath(s.values, g, props.smooth),
|
|
228
|
+
fill: props.type === "area" ? areaPath(s.values, g, props.smooth) : "",
|
|
229
|
+
/* A dashed series is a reference level (a budget, a target), not a
|
|
230
|
+
measurement — dotting it implies readings that aren't there. */
|
|
231
|
+
points: props.showPoints && !s.dashed,
|
|
232
|
+
scale: scaleOf(s)
|
|
233
|
+
};
|
|
234
|
+
})
|
|
235
|
+
);
|
|
236
|
+
const bars = computed(() => {
|
|
237
|
+
if (props.type !== "bar" || count.value === 0 || plotWidth(box.value) <= 0) return [];
|
|
238
|
+
const band = plotWidth(box.value) / count.value;
|
|
239
|
+
const inner = Math.min(band * 0.6, props.stacked ? 46 : 30 * (visible.value.length || 1));
|
|
240
|
+
const n = visible.value.length || 1;
|
|
241
|
+
const slot = props.stacked ? inner : inner / n;
|
|
242
|
+
const out = [];
|
|
243
|
+
const posTop = new Array(count.value).fill(0);
|
|
244
|
+
const negTop = new Array(count.value).fill(0);
|
|
245
|
+
visible.value.forEach((s, si) => {
|
|
246
|
+
for (let i = 0; i < count.value; i++) {
|
|
247
|
+
const v = s.values[i];
|
|
248
|
+
if (v == null) continue;
|
|
249
|
+
const centre = xAt(i, count.value, box.value, true);
|
|
250
|
+
const x = props.stacked ? centre - inner / 2 : centre - inner / 2 + si * slot;
|
|
251
|
+
let y;
|
|
252
|
+
let h;
|
|
253
|
+
if (props.stacked) {
|
|
254
|
+
const prev = v >= 0 ? posTop[i] : negTop[i];
|
|
255
|
+
const from = yAt(prev, scale.value.min, scale.value.max, box.value);
|
|
256
|
+
const to = yAt(prev + v, scale.value.min, scale.value.max, box.value);
|
|
257
|
+
y = Math.min(from, to);
|
|
258
|
+
h = Math.abs(to - from);
|
|
259
|
+
if (v >= 0) posTop[i] += v;
|
|
260
|
+
else negTop[i] += v;
|
|
261
|
+
} else {
|
|
262
|
+
const sc = scaleOf(s);
|
|
263
|
+
const top = yAt(v, sc.min, sc.max, box.value);
|
|
264
|
+
const base = yAt(Math.max(sc.min, Math.min(sc.max, 0)), sc.min, sc.max, box.value);
|
|
265
|
+
y = Math.min(top, base);
|
|
266
|
+
h = Math.abs(top - base);
|
|
267
|
+
}
|
|
268
|
+
out.push({
|
|
269
|
+
key: `${s.name}-${i}`,
|
|
270
|
+
x,
|
|
271
|
+
y,
|
|
272
|
+
w: Math.max(1, slot - (props.stacked ? 0 : 2)),
|
|
273
|
+
h: Math.max(v === 0 ? 0 : 1, h),
|
|
274
|
+
color: s.color,
|
|
275
|
+
index: i,
|
|
276
|
+
/* A standalone bar rounds only the end it grows toward: a negative one
|
|
277
|
+
hangs off the baseline, so its square end is the top. */
|
|
278
|
+
roundTop: props.stacked || v >= 0,
|
|
279
|
+
roundBottom: props.stacked || v < 0,
|
|
280
|
+
d: ""
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
if (props.stacked) {
|
|
285
|
+
const columns = /* @__PURE__ */ new Map();
|
|
286
|
+
for (const b of out) {
|
|
287
|
+
const col = columns.get(b.index) ?? [];
|
|
288
|
+
col.push(b);
|
|
289
|
+
columns.set(b.index, col);
|
|
290
|
+
}
|
|
291
|
+
for (const col of columns.values()) {
|
|
292
|
+
const top = Math.min(...col.map((b) => b.y));
|
|
293
|
+
const bottom = Math.max(...col.map((b) => b.y + b.h));
|
|
294
|
+
for (const b of col) {
|
|
295
|
+
b.roundTop = b.y === top;
|
|
296
|
+
b.roundBottom = b.y + b.h === bottom;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
for (const b of out) {
|
|
301
|
+
b.d = barPath(b.x, b.y, b.w, b.h, 4, { top: b.roundTop, bottom: b.roundBottom });
|
|
302
|
+
}
|
|
303
|
+
return out;
|
|
304
|
+
});
|
|
305
|
+
const active = ref(-1);
|
|
306
|
+
const pointer = ref({ x: 0, y: 0 });
|
|
307
|
+
const onMove = (e) => {
|
|
308
|
+
const el = e.currentTarget;
|
|
309
|
+
const rect = el.getBoundingClientRect();
|
|
310
|
+
const x = e.clientX - rect.left;
|
|
311
|
+
pointer.value = { x, y: e.clientY - rect.top };
|
|
312
|
+
active.value = nearestIndex(x, geo.value);
|
|
313
|
+
};
|
|
314
|
+
const onLeave = () => {
|
|
315
|
+
active.value = -1;
|
|
316
|
+
};
|
|
317
|
+
const pointEvent = (originalEvent) => ({
|
|
318
|
+
index: active.value,
|
|
319
|
+
label: labels.value[active.value] ?? "",
|
|
320
|
+
values: allSeries.value.map((s) => s.values[active.value] ?? null),
|
|
321
|
+
originalEvent
|
|
322
|
+
});
|
|
323
|
+
const onClick = (e) => {
|
|
324
|
+
if (active.value < 0) return;
|
|
325
|
+
emit("pointClick", pointEvent(e));
|
|
326
|
+
};
|
|
327
|
+
const menuPoint = ref(null);
|
|
328
|
+
const menuEntries = computed(
|
|
329
|
+
() => props.menuItems && menuPoint.value ? props.menuItems(menuPoint.value) : []
|
|
330
|
+
);
|
|
331
|
+
const onContextMenu = (e) => {
|
|
332
|
+
const rect = e.currentTarget.getBoundingClientRect();
|
|
333
|
+
active.value = nearestIndex(e.clientX - rect.left, geo.value);
|
|
334
|
+
if (active.value < 0) return;
|
|
335
|
+
menuPoint.value = pointEvent(e);
|
|
336
|
+
emit("pointContextMenu", menuPoint.value);
|
|
337
|
+
};
|
|
338
|
+
const activeX = computed(
|
|
339
|
+
() => active.value < 0 ? 0 : xAt(active.value, count.value, box.value, banded.value)
|
|
340
|
+
);
|
|
341
|
+
const activePoints = computed(() => {
|
|
342
|
+
if (active.value < 0) return [];
|
|
343
|
+
return visible.value.map((s) => ({ s, v: s.values[active.value] })).filter((r) => r.v != null).map(({ s, v }) => {
|
|
344
|
+
const sc = scaleOf(s);
|
|
345
|
+
return {
|
|
346
|
+
color: s.color,
|
|
347
|
+
name: s.name,
|
|
348
|
+
value: v,
|
|
349
|
+
y: yAt(v, sc.min, sc.max, box.value)
|
|
350
|
+
};
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
const tooltipRows = computed(
|
|
354
|
+
() => active.value < 0 ? [] : visible.value.map((s) => ({
|
|
355
|
+
name: s.name,
|
|
356
|
+
color: s.color,
|
|
357
|
+
text: s.values[active.value] == null ? "—" : fmtSeries(s, s.values[active.value])
|
|
358
|
+
}))
|
|
359
|
+
);
|
|
360
|
+
const tooltipTarget = computed(() => {
|
|
361
|
+
const flip = activeX.value > box.value.width - CARD_W;
|
|
362
|
+
const y = Math.min(
|
|
363
|
+
Math.max(pointer.value.y, box.value.top + 8),
|
|
364
|
+
box.value.top + plotHeight(box.value) - 8
|
|
365
|
+
);
|
|
366
|
+
return {
|
|
367
|
+
x: flip ? activeX.value - CARD_GAP : activeX.value + CARD_GAP,
|
|
368
|
+
y,
|
|
369
|
+
flip
|
|
370
|
+
};
|
|
371
|
+
});
|
|
372
|
+
const floatTransition = usePillTransition("float");
|
|
373
|
+
const revealKey = shallowRef(0);
|
|
374
|
+
watch(
|
|
375
|
+
() => [props.series, props.type],
|
|
376
|
+
() => {
|
|
377
|
+
revealKey.value++;
|
|
378
|
+
},
|
|
379
|
+
{ deep: true }
|
|
380
|
+
);
|
|
381
|
+
const clipId = `lp-chart-${Math.random().toString(36).slice(2, 9)}`;
|
|
382
|
+
return (_ctx, _cache) => {
|
|
383
|
+
return openBlock(), createElementBlock("div", {
|
|
384
|
+
ref_key: "root",
|
|
385
|
+
ref: root,
|
|
386
|
+
class: "flex w-full flex-col gap-3"
|
|
387
|
+
}, [
|
|
388
|
+
__props.title || __props.subtitle || _ctx.$slots.actions ? (openBlock(), createElementBlock("div", _hoisted_1, [
|
|
389
|
+
createElementVNode("div", _hoisted_2, [
|
|
390
|
+
__props.title ? (openBlock(), createElementBlock("span", _hoisted_3, toDisplayString(__props.title), 1)) : createCommentVNode("", true),
|
|
391
|
+
__props.subtitle ? (openBlock(), createElementBlock("span", _hoisted_4, toDisplayString(__props.subtitle), 1)) : createCommentVNode("", true)
|
|
392
|
+
]),
|
|
393
|
+
renderSlot(_ctx.$slots, "actions")
|
|
394
|
+
])) : createCommentVNode("", true),
|
|
395
|
+
__props.showLegend && allSeries.value.length > 1 ? (openBlock(), createElementBlock("div", _hoisted_5, [
|
|
396
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(allSeries.value, (s) => {
|
|
397
|
+
return openBlock(), createElementBlock("button", {
|
|
398
|
+
key: s.name,
|
|
399
|
+
type: "button",
|
|
400
|
+
class: normalizeClass(["group flex cursor-pointer items-center gap-1.5 rounded-md text-xs outline-none transition-opacity duration-fast focus-visible:ring-2 focus-visible:ring-ring", hidden.value.has(s.name) ? "opacity-40" : ""]),
|
|
401
|
+
onClick: ($event) => toggleSeries(s.name)
|
|
402
|
+
}, [
|
|
403
|
+
createElementVNode("span", {
|
|
404
|
+
class: "size-2 shrink-0 rounded-full transition-transform duration-fast group-hover:scale-125",
|
|
405
|
+
style: normalizeStyle({ backgroundColor: s.color })
|
|
406
|
+
}, null, 4),
|
|
407
|
+
createElementVNode("span", _hoisted_7, toDisplayString(s.name), 1),
|
|
408
|
+
hasRightAxis.value && s.axis === "right" ? (openBlock(), createElementBlock("span", _hoisted_8, " ↗ ")) : createCommentVNode("", true)
|
|
409
|
+
], 10, _hoisted_6);
|
|
410
|
+
}), 128))
|
|
411
|
+
])) : createCommentVNode("", true),
|
|
412
|
+
createVNode(_sfc_main$1, {
|
|
413
|
+
items: menuEntries.value,
|
|
414
|
+
always: !!__props.menuItems
|
|
415
|
+
}, {
|
|
416
|
+
default: withCtx(() => [
|
|
417
|
+
createElementVNode("div", {
|
|
418
|
+
class: "group/plot relative",
|
|
419
|
+
style: normalizeStyle({ height: `${__props.height}px` })
|
|
420
|
+
}, [
|
|
421
|
+
!hasData.value ? (openBlock(), createElementBlock("div", _hoisted_9, [
|
|
422
|
+
createVNode(_sfc_main$2, {
|
|
423
|
+
name: "lucide:chart-no-axes-column",
|
|
424
|
+
size: 18
|
|
425
|
+
}),
|
|
426
|
+
createElementVNode("span", _hoisted_10, toDisplayString(__props.emptyLabel), 1)
|
|
427
|
+
])) : width.value > 0 ? (openBlock(), createElementBlock("svg", {
|
|
428
|
+
key: 1,
|
|
429
|
+
width: width.value,
|
|
430
|
+
height: __props.height,
|
|
431
|
+
class: "overflow-visible touch-none select-none",
|
|
432
|
+
onPointermove: onMove,
|
|
433
|
+
onPointerleave: onLeave,
|
|
434
|
+
onClick,
|
|
435
|
+
onContextmenu: onContextMenu
|
|
436
|
+
}, [
|
|
437
|
+
createElementVNode("defs", null, [
|
|
438
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(lines.value, (s) => {
|
|
439
|
+
return openBlock(), createElementBlock("linearGradient", {
|
|
440
|
+
id: `${clipId}-g-${s.name}`,
|
|
441
|
+
key: s.name,
|
|
442
|
+
x1: "0",
|
|
443
|
+
y1: "0",
|
|
444
|
+
x2: "0",
|
|
445
|
+
y2: "1"
|
|
446
|
+
}, [
|
|
447
|
+
createElementVNode("stop", {
|
|
448
|
+
offset: "0%",
|
|
449
|
+
"stop-color": s.color,
|
|
450
|
+
"stop-opacity": "0.28"
|
|
451
|
+
}, null, 8, _hoisted_13),
|
|
452
|
+
createElementVNode("stop", {
|
|
453
|
+
offset: "100%",
|
|
454
|
+
"stop-color": s.color,
|
|
455
|
+
"stop-opacity": "0.02"
|
|
456
|
+
}, null, 8, _hoisted_14)
|
|
457
|
+
], 8, _hoisted_12);
|
|
458
|
+
}), 128)),
|
|
459
|
+
createElementVNode("clipPath", {
|
|
460
|
+
id: `${clipId}-reveal`
|
|
461
|
+
}, [
|
|
462
|
+
(openBlock(), createElementBlock("rect", {
|
|
463
|
+
key: revealKey.value,
|
|
464
|
+
x: box.value.left,
|
|
465
|
+
y: 0,
|
|
466
|
+
height: __props.height,
|
|
467
|
+
width: __props.animate ? 0 : unref(plotWidth)(box.value)
|
|
468
|
+
}, [
|
|
469
|
+
drawing.value ? (openBlock(), createElementBlock("animate", {
|
|
470
|
+
key: 0,
|
|
471
|
+
attributeName: "width",
|
|
472
|
+
from: 0,
|
|
473
|
+
to: unref(plotWidth)(box.value),
|
|
474
|
+
dur: "0.95s",
|
|
475
|
+
fill: "freeze",
|
|
476
|
+
calcMode: "spline",
|
|
477
|
+
keySplines: "0.2 0.25 0.5 0.85",
|
|
478
|
+
keyTimes: "0;1"
|
|
479
|
+
}, null, 8, _hoisted_17)) : createCommentVNode("", true)
|
|
480
|
+
], 8, _hoisted_16))
|
|
481
|
+
], 8, _hoisted_15)
|
|
482
|
+
]),
|
|
483
|
+
__props.showGrid || __props.showYAxis ? (openBlock(), createElementBlock("g", _hoisted_18, [
|
|
484
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(gridLines.value, (g) => {
|
|
485
|
+
return openBlock(), createElementBlock(Fragment, {
|
|
486
|
+
key: g.v
|
|
487
|
+
}, [
|
|
488
|
+
__props.showGrid ? (openBlock(), createElementBlock("line", {
|
|
489
|
+
key: 0,
|
|
490
|
+
x1: box.value.left,
|
|
491
|
+
x2: box.value.width - box.value.right,
|
|
492
|
+
y1: g.y,
|
|
493
|
+
y2: g.y,
|
|
494
|
+
stroke: "var(--color-line)",
|
|
495
|
+
"stroke-width": "1"
|
|
496
|
+
}, null, 8, _hoisted_19)) : createCommentVNode("", true),
|
|
497
|
+
__props.showYAxis ? (openBlock(), createElementBlock("text", {
|
|
498
|
+
key: 1,
|
|
499
|
+
x: box.value.left - 8,
|
|
500
|
+
y: g.y,
|
|
501
|
+
"text-anchor": "end",
|
|
502
|
+
"dominant-baseline": "middle",
|
|
503
|
+
class: "fill-[var(--color-muted)] text-[10px] tabular-nums"
|
|
504
|
+
}, toDisplayString(g.label), 9, _hoisted_20)) : createCommentVNode("", true),
|
|
505
|
+
__props.showYAxis && g.rightLabel ? (openBlock(), createElementBlock("text", {
|
|
506
|
+
key: 2,
|
|
507
|
+
x: box.value.width - box.value.right + 8,
|
|
508
|
+
y: g.y,
|
|
509
|
+
"text-anchor": "start",
|
|
510
|
+
"dominant-baseline": "middle",
|
|
511
|
+
class: "fill-[var(--color-muted)] text-[10px] tabular-nums"
|
|
512
|
+
}, toDisplayString(g.rightLabel), 9, _hoisted_21)) : createCommentVNode("", true)
|
|
513
|
+
], 64);
|
|
514
|
+
}), 128))
|
|
515
|
+
])) : createCommentVNode("", true),
|
|
516
|
+
scale.value.min < 0 && scale.value.max > 0 ? (openBlock(), createElementBlock("line", {
|
|
517
|
+
key: 1,
|
|
518
|
+
x1: box.value.left,
|
|
519
|
+
x2: box.value.width - box.value.right,
|
|
520
|
+
y1: baseY.value,
|
|
521
|
+
y2: baseY.value,
|
|
522
|
+
stroke: "var(--color-line-strong)",
|
|
523
|
+
"stroke-width": "1"
|
|
524
|
+
}, null, 8, _hoisted_22)) : createCommentVNode("", true),
|
|
525
|
+
active.value >= 0 && banded.value ? (openBlock(), createElementBlock("rect", {
|
|
526
|
+
key: 2,
|
|
527
|
+
x: activeX.value - unref(plotWidth)(box.value) / count.value / 2,
|
|
528
|
+
y: box.value.top,
|
|
529
|
+
width: unref(plotWidth)(box.value) / count.value,
|
|
530
|
+
height: unref(plotHeight)(box.value),
|
|
531
|
+
fill: "var(--color-surface-soft)",
|
|
532
|
+
opacity: "0.5"
|
|
533
|
+
}, null, 8, _hoisted_23)) : createCommentVNode("", true),
|
|
534
|
+
createElementVNode("g", {
|
|
535
|
+
"clip-path": `url(#${clipId}-reveal)`
|
|
536
|
+
}, [
|
|
537
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(bars.value, (b) => {
|
|
538
|
+
return openBlock(), createElementBlock("path", {
|
|
539
|
+
key: b.key,
|
|
540
|
+
d: b.d,
|
|
541
|
+
fill: b.color,
|
|
542
|
+
class: "transition-opacity duration-fast",
|
|
543
|
+
opacity: active.value < 0 || active.value === b.index ? 1 : 0.45
|
|
544
|
+
}, null, 8, _hoisted_25);
|
|
545
|
+
}), 128)),
|
|
546
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(lines.value, (s) => {
|
|
547
|
+
return withDirectives((openBlock(), createElementBlock("path", {
|
|
548
|
+
key: `f-${s.name}`,
|
|
549
|
+
d: s.fill,
|
|
550
|
+
fill: `url(#${clipId}-g-${s.name})`
|
|
551
|
+
}, null, 8, _hoisted_26)), [
|
|
552
|
+
[vShow, __props.type === "area"]
|
|
553
|
+
]);
|
|
554
|
+
}), 128)),
|
|
555
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(lines.value, (s) => {
|
|
556
|
+
return withDirectives((openBlock(), createElementBlock("path", {
|
|
557
|
+
key: `l-${s.name}`,
|
|
558
|
+
d: s.d,
|
|
559
|
+
fill: "none",
|
|
560
|
+
stroke: s.color,
|
|
561
|
+
"stroke-width": "2",
|
|
562
|
+
"stroke-linecap": "round",
|
|
563
|
+
"stroke-linejoin": "round",
|
|
564
|
+
"stroke-dasharray": s.dashed ? "5 4" : void 0
|
|
565
|
+
}, null, 8, _hoisted_27)), [
|
|
566
|
+
[vShow, __props.type !== "bar"]
|
|
567
|
+
]);
|
|
568
|
+
}), 128)),
|
|
569
|
+
__props.type !== "bar" ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(lines.value, (s) => {
|
|
570
|
+
return openBlock(), createElementBlock(Fragment, {
|
|
571
|
+
key: `p-${s.name}`
|
|
572
|
+
}, [
|
|
573
|
+
s.points ? (openBlock(true), createElementBlock(Fragment, { key: 0 }, renderList(s.values, (v, i) => {
|
|
574
|
+
return withDirectives((openBlock(), createElementBlock("circle", {
|
|
575
|
+
key: i,
|
|
576
|
+
cx: unref(xAt)(i, count.value, box.value, banded.value),
|
|
577
|
+
cy: v == null ? 0 : unref(yAt)(v, s.scale.min, s.scale.max, box.value),
|
|
578
|
+
r: "2.5",
|
|
579
|
+
fill: s.color
|
|
580
|
+
}, null, 8, _hoisted_28)), [
|
|
581
|
+
[vShow, v != null]
|
|
582
|
+
]);
|
|
583
|
+
}), 128)) : createCommentVNode("", true)
|
|
584
|
+
], 64);
|
|
585
|
+
}), 128)) : createCommentVNode("", true)
|
|
586
|
+
], 8, _hoisted_24),
|
|
587
|
+
active.value >= 0 && __props.type !== "bar" ? (openBlock(), createElementBlock("g", _hoisted_29, [
|
|
588
|
+
createElementVNode("line", {
|
|
589
|
+
x1: activeX.value,
|
|
590
|
+
x2: activeX.value,
|
|
591
|
+
y1: box.value.top,
|
|
592
|
+
y2: box.value.top + unref(plotHeight)(box.value),
|
|
593
|
+
stroke: "var(--color-line-strong)",
|
|
594
|
+
"stroke-width": "1",
|
|
595
|
+
"stroke-dasharray": "3 3"
|
|
596
|
+
}, null, 8, _hoisted_30),
|
|
597
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(activePoints.value, (p) => {
|
|
598
|
+
return openBlock(), createElementBlock("circle", {
|
|
599
|
+
key: p.name,
|
|
600
|
+
cx: activeX.value,
|
|
601
|
+
cy: p.y,
|
|
602
|
+
r: "4",
|
|
603
|
+
fill: p.color,
|
|
604
|
+
stroke: "var(--color-surface)",
|
|
605
|
+
"stroke-width": "2"
|
|
606
|
+
}, null, 8, _hoisted_31);
|
|
607
|
+
}), 128))
|
|
608
|
+
])) : createCommentVNode("", true),
|
|
609
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(xLabels.value, (l) => {
|
|
610
|
+
return withDirectives((openBlock(), createElementBlock("text", {
|
|
611
|
+
key: l.i,
|
|
612
|
+
x: l.x,
|
|
613
|
+
y: __props.height - 8,
|
|
614
|
+
"text-anchor": "middle",
|
|
615
|
+
class: normalizeClass(["fill-[var(--color-muted)] text-[10px]", active.value === l.i ? "fill-[var(--color-ink)]" : ""])
|
|
616
|
+
}, toDisplayString(l.label), 11, _hoisted_32)), [
|
|
617
|
+
[vShow, __props.showXAxis]
|
|
618
|
+
]);
|
|
619
|
+
}), 128))
|
|
620
|
+
], 40, _hoisted_11)) : createCommentVNode("", true),
|
|
621
|
+
active.value >= 0 && hasData.value ? (openBlock(), createBlock(unref(Motion), {
|
|
622
|
+
key: 2,
|
|
623
|
+
as: "div",
|
|
624
|
+
class: "pointer-events-none absolute left-0 top-0 z-(--z-tooltip) min-w-32 rounded-control border border-line bg-surface-overlay px-2.5 py-2 shadow-panel backdrop-blur group-data-[state=open]/plot:hidden",
|
|
625
|
+
initial: { opacity: 0, scale: 0.96 },
|
|
626
|
+
animate: {
|
|
627
|
+
opacity: 1,
|
|
628
|
+
scale: 1,
|
|
629
|
+
x: tooltipTarget.value.flip ? `calc(${tooltipTarget.value.x}px - 100%)` : `${tooltipTarget.value.x}px`,
|
|
630
|
+
y: `calc(${tooltipTarget.value.y}px - 50%)`
|
|
631
|
+
},
|
|
632
|
+
transition: unref(floatTransition)
|
|
633
|
+
}, {
|
|
634
|
+
default: withCtx(() => [
|
|
635
|
+
createVNode(_sfc_main$3, { axis: "both" }, {
|
|
636
|
+
default: withCtx(() => [
|
|
637
|
+
createElementVNode("div", _hoisted_33, toDisplayString(labels.value[active.value]), 1),
|
|
638
|
+
createElementVNode("div", _hoisted_34, [
|
|
639
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(tooltipRows.value, (r) => {
|
|
640
|
+
return openBlock(), createElementBlock("div", {
|
|
641
|
+
key: r.name,
|
|
642
|
+
class: "flex items-center justify-between gap-3 text-xs"
|
|
643
|
+
}, [
|
|
644
|
+
createElementVNode("span", _hoisted_35, [
|
|
645
|
+
createElementVNode("span", {
|
|
646
|
+
class: "size-1.5 shrink-0 rounded-full",
|
|
647
|
+
style: normalizeStyle({ backgroundColor: r.color })
|
|
648
|
+
}, null, 4),
|
|
649
|
+
createTextVNode(" " + toDisplayString(r.name), 1)
|
|
650
|
+
]),
|
|
651
|
+
createElementVNode("span", _hoisted_36, toDisplayString(r.text), 1)
|
|
652
|
+
]);
|
|
653
|
+
}), 128))
|
|
654
|
+
])
|
|
655
|
+
]),
|
|
656
|
+
_: 1
|
|
657
|
+
})
|
|
658
|
+
]),
|
|
659
|
+
_: 1
|
|
660
|
+
}, 8, ["animate", "transition"])) : createCommentVNode("", true)
|
|
661
|
+
], 4)
|
|
662
|
+
]),
|
|
663
|
+
_: 1
|
|
664
|
+
}, 8, ["items", "always"])
|
|
665
|
+
], 512);
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
export {
|
|
670
|
+
_sfc_main as _
|
|
671
|
+
};
|