@svadmin/ui 0.118.0 → 0.120.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/app.css +201 -52
- package/dist/app.theme.css +201 -52
- package/dist/components/AboutSettings.svelte +1 -1
- package/dist/components/AuditLogDrawer.svelte +165 -55
- package/dist/components/AuditLogDrawer.svelte.d.ts +4 -2
- package/dist/components/Authenticated.svelte +2 -2
- package/dist/components/AutoSaveIndicator.svelte +2 -2
- package/dist/components/AutoTable.svelte +1 -1
- package/dist/components/Barcode.svelte +219 -0
- package/dist/components/Barcode.svelte.d.ts +15 -0
- package/dist/components/Breadcrumbs.svelte +1 -1
- package/dist/components/Breadcrumbs.svelte.d.ts +1 -1
- package/dist/components/CanAccess.svelte +2 -2
- package/dist/components/CancelTaskButton.svelte +2 -2
- package/dist/components/Cascader.svelte +19 -19
- package/dist/components/Cascader.svelte.d.ts +19 -19
- package/dist/components/ColorPicker.svelte +9 -9
- package/dist/components/ColorPicker.svelte.d.ts +9 -9
- package/dist/components/ComboboxField.svelte +15 -15
- package/dist/components/ComboboxField.svelte.d.ts +15 -15
- package/dist/components/ConcurrentConflictModal.svelte +292 -0
- package/dist/components/ConcurrentConflictModal.svelte.d.ts +24 -0
- package/dist/components/ConfigErrorScreen.svelte +2 -2
- package/dist/components/ConfirmDialog.svelte +6 -4
- package/dist/components/ConfirmDialog.svelte.d.ts +2 -2
- package/dist/components/CronExpressionBuilder.svelte +389 -0
- package/dist/components/CronExpressionBuilder.svelte.d.ts +20 -0
- package/dist/components/DateRangeInput.svelte +22 -22
- package/dist/components/DateRangeInput.svelte.d.ts +22 -22
- package/dist/components/DateTimeInput.svelte +2 -2
- package/dist/components/DateTimeInput.svelte.d.ts +2 -2
- package/dist/components/EmptyState.svelte +2 -2
- package/dist/components/ErrorComponent.svelte +2 -2
- package/dist/components/ErrorSummary.svelte +2 -2
- package/dist/components/FieldRenderer.svelte +3 -3
- package/dist/components/FileUpload.svelte +16 -16
- package/dist/components/FileUpload.svelte.d.ts +16 -16
- package/dist/components/FileUploadField.svelte +7 -7
- package/dist/components/FileUploadField.svelte.d.ts +7 -7
- package/dist/components/FilterDropdown.svelte.d.ts +1 -1
- package/dist/components/ForgotPasswordPage.svelte +2 -2
- package/dist/components/Header.svelte +2 -2
- package/dist/components/LiveIndicator.svelte +2 -2
- package/dist/components/LoginPage.svelte +2 -2
- package/dist/components/MetricGrid.svelte +163 -0
- package/dist/components/MetricGrid.svelte.d.ts +39 -0
- package/dist/components/MicroAppFrame.svelte +290 -0
- package/dist/components/MicroAppFrame.svelte.d.ts +36 -0
- package/dist/components/MoneyInput.svelte +15 -15
- package/dist/components/MoneyInput.svelte.d.ts +15 -15
- package/dist/components/NotificationCenter.svelte +16 -16
- package/dist/components/NotificationCenter.svelte.d.ts +16 -16
- package/dist/components/NumberInput.svelte +13 -13
- package/dist/components/NumberInput.svelte.d.ts +13 -13
- package/dist/components/NumberRoll.svelte +149 -0
- package/dist/components/NumberRoll.svelte.d.ts +17 -0
- package/dist/components/NumericInput.svelte +16 -16
- package/dist/components/NumericInput.svelte.d.ts +16 -16
- package/dist/components/OfflineGuard.svelte +65 -0
- package/dist/components/OfflineGuard.svelte.d.ts +15 -0
- package/dist/components/OrgChart.svelte +171 -0
- package/dist/components/OrgChart.svelte.d.ts +26 -0
- package/dist/components/PageSkeleton.svelte +2 -2
- package/dist/components/PercentInput.svelte +14 -14
- package/dist/components/PercentInput.svelte.d.ts +14 -14
- package/dist/components/PresenceAvatarGroup.svelte +78 -29
- package/dist/components/PresenceAvatarGroup.svelte.d.ts +14 -8
- package/dist/components/Rate.svelte +9 -9
- package/dist/components/Rate.svelte.d.ts +9 -9
- package/dist/components/RegisterPage.svelte +2 -2
- package/dist/components/ResizeBox.svelte.d.ts +1 -1
- package/dist/components/RetryTaskButton.svelte +2 -2
- package/dist/components/SafeDeleteConfirm.svelte +301 -0
- package/dist/components/SafeDeleteConfirm.svelte.d.ts +24 -0
- package/dist/components/SignaturePad.svelte +19 -3
- package/dist/components/SignaturePad.svelte.d.ts +3 -0
- package/dist/components/SliderCaptcha.svelte +448 -0
- package/dist/components/SliderCaptcha.svelte.d.ts +26 -0
- package/dist/components/TagsInput.svelte +10 -10
- package/dist/components/TagsInput.svelte.d.ts +10 -10
- package/dist/components/TaskCenter.svelte +450 -0
- package/dist/components/TaskCenter.svelte.d.ts +37 -0
- package/dist/components/TaskDetails.svelte +2 -2
- package/dist/components/TaskList.svelte +2 -2
- package/dist/components/TaskProgressBar.svelte +2 -2
- package/dist/components/TaskStatusBadge.svelte +2 -2
- package/dist/components/ThemedTitle.svelte +2 -2
- package/dist/components/Tour.svelte +9 -1
- package/dist/components/Tour.svelte.d.ts +2 -1
- package/dist/components/Transfer.svelte +11 -11
- package/dist/components/Transfer.svelte.d.ts +11 -11
- package/dist/components/TreeSelect.svelte +17 -17
- package/dist/components/TreeSelect.svelte.d.ts +17 -17
- package/dist/components/TreeTable.svelte.d.ts +1 -1
- package/dist/components/TrendIndicator.svelte +177 -0
- package/dist/components/TrendIndicator.svelte.d.ts +27 -0
- package/dist/components/UndoableNotification.svelte +2 -2
- package/dist/components/UpdatePasswordPage.svelte +2 -2
- package/dist/components/VirtualList.svelte +165 -0
- package/dist/components/VirtualList.svelte.d.ts +43 -0
- package/dist/components/VirtualTreeSelect.svelte +431 -0
- package/dist/components/VirtualTreeSelect.svelte.d.ts +34 -0
- package/dist/components/buttons/CreateButton.svelte +2 -2
- package/dist/components/buttons/ExportButton.svelte +2 -2
- package/dist/components/buttons/ListButton.svelte +2 -2
- package/dist/components/buttons/RefreshButton.svelte +2 -2
- package/dist/components/buttons/SaveButton.svelte +2 -2
- package/dist/components/charts/GaugeChart.svelte +452 -57
- package/dist/components/charts/GaugeChart.svelte.d.ts +61 -10
- package/dist/components/content/AuditTimeline.svelte +125 -28
- package/dist/components/content/AuditTimeline.svelte.d.ts +30 -16
- package/dist/components/fields/JsonField.svelte +2 -2
- package/dist/components/fields/MultiSelectField.svelte +2 -2
- package/dist/components/fields/RelationField.svelte +2 -2
- package/dist/components/fields/RichTextField.svelte +2 -2
- package/dist/components/fields/SelectField.svelte +2 -2
- package/dist/components/list-state.svelte.d.ts +1 -1
- package/dist/components/ui/checkbox/checkbox.svelte.d.ts +1 -1
- package/dist/components/ui/command/command-dialog.svelte.d.ts +1 -1
- package/dist/components/ui/command/index.d.ts +1 -1
- package/dist/components/ui/input/input.svelte.d.ts +1 -1
- package/dist/components/ui/switch/switch.svelte.d.ts +1 -1
- package/dist/components/useNetworkStatus.d.svelte.ts +1 -0
- package/dist/components/useNetworkStatus.svelte.d.ts +30 -0
- package/dist/components/useNetworkStatus.svelte.js +74 -0
- package/dist/design-system.d.ts +4 -4
- package/dist/index.d.ts +26 -5
- package/dist/index.js +27 -3
- package/dist/recipes.d.ts +91 -619
- package/package.json +30 -30
|
@@ -1,74 +1,469 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
2
|
+
import { cn } from '../../utils.js';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
|
|
5
|
+
export type GaugeTone = 'primary' | 'success' | 'warning' | 'destructive' | 'info' | 'muted';
|
|
6
|
+
export type GaugeType = 'half' | 'arc' | 'circle';
|
|
7
|
+
export type GaugeMode = 'progress' | 'needle' | 'both';
|
|
8
|
+
|
|
9
|
+
export interface GaugeThreshold {
|
|
10
|
+
/** Upper bound value of this segment/threshold zone */
|
|
11
|
+
value: number;
|
|
12
|
+
/** Semantic tone (success, warning, destructive, primary, info, muted) */
|
|
13
|
+
tone?: GaugeTone | undefined;
|
|
14
|
+
/** Optional custom CSS color token or variable expression (e.g. 'var(--chart-1)') */
|
|
15
|
+
color?: string | undefined;
|
|
16
|
+
/** Human-readable label for this threshold zone (e.g. 'Normal', 'Warning', 'Critical') */
|
|
17
|
+
label?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface GaugeChartProps {
|
|
21
|
+
/** Current numeric metric value */
|
|
3
22
|
value: number;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
/** Minimum gauge value (default: 0) */
|
|
24
|
+
min?: number | undefined;
|
|
25
|
+
/** Maximum gauge value (default: 100) */
|
|
26
|
+
max?: number | undefined;
|
|
27
|
+
/** Unit suffix (e.g. '%', 'MB/s', 'req/s', 'ms', '°C') */
|
|
28
|
+
unit?: string | undefined;
|
|
29
|
+
/** Metric title / label */
|
|
30
|
+
label?: string | undefined;
|
|
31
|
+
/** Subtitle or contextual note (e.g. 'Target: < 80%', 'Peak: 95%') */
|
|
32
|
+
subtext?: string | undefined;
|
|
33
|
+
/** Gauge arc span type: 'half' (180° semi-circle), 'arc' (240° speedometer), 'circle' (270° wide arc) */
|
|
34
|
+
type?: GaugeType | undefined;
|
|
35
|
+
/** Display mode: 'progress' (filled progress arc), 'needle' (classic indicator needle), 'both' */
|
|
36
|
+
mode?: GaugeMode | undefined;
|
|
37
|
+
/** Custom threshold intervals. Defaults to [0..60 success, 60..85 warning, 85..100 destructive] */
|
|
38
|
+
thresholds?: GaugeThreshold[] | undefined;
|
|
39
|
+
/** Benchmark target line value (e.g. SLA target 80) */
|
|
40
|
+
target?: number | undefined;
|
|
41
|
+
/** Target label (default: 'Target') */
|
|
42
|
+
targetLabel?: string | undefined;
|
|
43
|
+
/** Number of tick marks or custom tick values */
|
|
44
|
+
ticks?: number | number[] | undefined;
|
|
45
|
+
/** Whether to show tick marks (default: true) */
|
|
46
|
+
showTicks?: boolean | undefined;
|
|
47
|
+
/** Whether to show min/max tick labels (default: true) */
|
|
48
|
+
showTickLabels?: boolean | undefined;
|
|
49
|
+
/** Gauge size preset ('sm' | 'md' | 'lg') or numeric width (default: 'md' / 220) */
|
|
50
|
+
size?: 'sm' | 'md' | 'lg' | number | undefined;
|
|
51
|
+
/** Stroke thickness for the gauge arc track (default: 14) */
|
|
52
|
+
thickness?: number | undefined;
|
|
53
|
+
/** Custom stroke width for the gauge arc track (alias for thickness) */
|
|
54
|
+
strokeWidth?: number | undefined;
|
|
55
|
+
/** Custom value formatter (legacy alias for formatter) */
|
|
56
|
+
format?: ((val: number) => string) | undefined;
|
|
57
|
+
/** Custom value formatter */
|
|
58
|
+
formatter?: ((val: number) => string) | undefined;
|
|
59
|
+
/** Explicit stroke color override */
|
|
60
|
+
color?: string | undefined;
|
|
61
|
+
/** Whether to display current status badge below value (default: true) */
|
|
62
|
+
showBadge?: boolean | undefined;
|
|
63
|
+
/** Additional CSS classes for the outer container */
|
|
64
|
+
class?: string | undefined;
|
|
65
|
+
/** Optional bottom actions or extra details slot */
|
|
66
|
+
footer?: Snippet | undefined;
|
|
12
67
|
}
|
|
13
68
|
|
|
14
69
|
let {
|
|
15
70
|
value,
|
|
16
71
|
min = 0,
|
|
17
72
|
max = 100,
|
|
18
|
-
|
|
19
|
-
thickness = 14,
|
|
73
|
+
unit = '',
|
|
20
74
|
label,
|
|
21
|
-
|
|
22
|
-
|
|
75
|
+
subtext,
|
|
76
|
+
type = 'half',
|
|
77
|
+
mode = 'progress',
|
|
78
|
+
thresholds = [
|
|
79
|
+
{ value: 60, tone: 'success', label: 'Normal' },
|
|
80
|
+
{ value: 85, tone: 'warning', label: 'Warning' },
|
|
81
|
+
{ value: 100, tone: 'destructive', label: 'Critical' },
|
|
82
|
+
],
|
|
83
|
+
target,
|
|
84
|
+
targetLabel = 'Target',
|
|
85
|
+
ticks = 5,
|
|
86
|
+
showTicks = true,
|
|
87
|
+
showTickLabels = true,
|
|
88
|
+
size = 'md',
|
|
89
|
+
thickness = 14,
|
|
90
|
+
strokeWidth,
|
|
91
|
+
format,
|
|
92
|
+
formatter,
|
|
93
|
+
color,
|
|
94
|
+
showBadge = true,
|
|
23
95
|
class: className = '',
|
|
24
|
-
|
|
96
|
+
footer,
|
|
97
|
+
}: GaugeChartProps = $props();
|
|
98
|
+
|
|
99
|
+
const effectiveThickness = $derived(strokeWidth ?? thickness ?? 14);
|
|
25
100
|
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
101
|
+
// Helper mappings for semantic design tokens without bare hex or bare palette utilities
|
|
102
|
+
const TONE_MAP: Record<
|
|
103
|
+
GaugeTone,
|
|
104
|
+
{ stroke: string; text: string; bg: string; badge: string }
|
|
105
|
+
> = {
|
|
106
|
+
primary: {
|
|
107
|
+
stroke: 'var(--primary)',
|
|
108
|
+
text: 'text-primary',
|
|
109
|
+
bg: 'bg-primary',
|
|
110
|
+
badge: 'bg-primary/10 text-primary border-primary/20',
|
|
111
|
+
},
|
|
112
|
+
success: {
|
|
113
|
+
stroke: 'var(--success, var(--primary))',
|
|
114
|
+
text: 'text-success',
|
|
115
|
+
bg: 'bg-success',
|
|
116
|
+
badge: 'bg-success/15 text-success border-success/20',
|
|
117
|
+
},
|
|
118
|
+
warning: {
|
|
119
|
+
stroke: 'var(--warning, var(--primary))',
|
|
120
|
+
text: 'text-warning',
|
|
121
|
+
bg: 'bg-warning',
|
|
122
|
+
badge: 'bg-warning/15 text-warning border-warning/20',
|
|
123
|
+
},
|
|
124
|
+
destructive: {
|
|
125
|
+
stroke: 'var(--destructive)',
|
|
126
|
+
text: 'text-destructive',
|
|
127
|
+
bg: 'bg-destructive',
|
|
128
|
+
badge: 'bg-destructive/15 text-destructive border-destructive/20',
|
|
129
|
+
},
|
|
130
|
+
info: {
|
|
131
|
+
stroke: 'var(--info, var(--primary))',
|
|
132
|
+
text: 'text-info',
|
|
133
|
+
bg: 'bg-info',
|
|
134
|
+
badge: 'bg-info/15 text-info border-info/20',
|
|
135
|
+
},
|
|
136
|
+
muted: {
|
|
137
|
+
stroke: 'var(--muted-foreground)',
|
|
138
|
+
text: 'text-muted-foreground',
|
|
139
|
+
bg: 'bg-muted',
|
|
140
|
+
badge: 'bg-muted text-muted-foreground border-border',
|
|
141
|
+
},
|
|
142
|
+
};
|
|
31
143
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
144
|
+
// Dimensions & geometry
|
|
145
|
+
const widthPx = $derived.by(() => {
|
|
146
|
+
if (typeof size === 'number') return size;
|
|
147
|
+
switch (size) {
|
|
148
|
+
case 'sm':
|
|
149
|
+
return 180;
|
|
150
|
+
case 'lg':
|
|
151
|
+
return 300;
|
|
152
|
+
case 'md':
|
|
153
|
+
default:
|
|
154
|
+
return 220;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const cx = $derived(widthPx / 2);
|
|
159
|
+
const radius = $derived(widthPx / 2 - effectiveThickness / 2 - 8);
|
|
160
|
+
|
|
161
|
+
const geometry = $derived.by(() => {
|
|
162
|
+
switch (type) {
|
|
163
|
+
case 'arc':
|
|
164
|
+
return {
|
|
165
|
+
startAngle: 150,
|
|
166
|
+
endAngle: 390,
|
|
167
|
+
spanAngle: 240,
|
|
168
|
+
cy: widthPx / 2 - 4,
|
|
169
|
+
viewBox: `0 0 ${widthPx} ${Math.round(widthPx * 0.88)}`,
|
|
170
|
+
};
|
|
171
|
+
case 'circle':
|
|
172
|
+
return {
|
|
173
|
+
startAngle: 135,
|
|
174
|
+
endAngle: 405,
|
|
175
|
+
spanAngle: 270,
|
|
176
|
+
cy: widthPx / 2 - 4,
|
|
177
|
+
viewBox: `0 0 ${widthPx} ${Math.round(widthPx * 0.92)}`,
|
|
178
|
+
};
|
|
179
|
+
case 'half':
|
|
180
|
+
default:
|
|
181
|
+
return {
|
|
182
|
+
startAngle: 180,
|
|
183
|
+
endAngle: 360,
|
|
184
|
+
spanAngle: 180,
|
|
185
|
+
cy: radius + effectiveThickness / 2 + 10,
|
|
186
|
+
viewBox: `0 0 ${widthPx} ${Math.round(radius + effectiveThickness + 24)}`,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const range = $derived(max > min ? max - min : 1);
|
|
192
|
+
const clampedValue = $derived(Math.min(max, Math.max(min, value)));
|
|
193
|
+
const ratio = $derived((clampedValue - min) / range);
|
|
194
|
+
const percent100 = $derived(Math.round(ratio * 100));
|
|
195
|
+
const currentAngle = $derived(geometry.startAngle + ratio * geometry.spanAngle);
|
|
196
|
+
|
|
197
|
+
// Active tone determined by threshold matching
|
|
198
|
+
const activeThreshold = $derived.by(() => {
|
|
199
|
+
const sorted = [...thresholds].sort((a, b) => a.value - b.value);
|
|
200
|
+
for (const t of sorted) {
|
|
201
|
+
if (clampedValue <= t.value) {
|
|
202
|
+
return t;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return sorted[sorted.length - 1] ?? { value: max, tone: 'primary' as GaugeTone };
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const activeTone = $derived<GaugeTone>(activeThreshold.tone ?? 'primary');
|
|
209
|
+
const activeTokenInfo = $derived(TONE_MAP[activeTone] ?? TONE_MAP.primary);
|
|
210
|
+
const activeColor = $derived(color ?? activeThreshold.color ?? activeTokenInfo.stroke);
|
|
211
|
+
|
|
212
|
+
// SVG trigonometry helpers
|
|
213
|
+
function polarToCartesian(centerX: number, centerY: number, r: number, angleDegrees: number) {
|
|
214
|
+
const rad = (angleDegrees * Math.PI) / 180.0;
|
|
215
|
+
return {
|
|
216
|
+
x: centerX + r * Math.cos(rad),
|
|
217
|
+
y: centerY + r * Math.sin(rad),
|
|
218
|
+
};
|
|
35
219
|
}
|
|
36
220
|
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
221
|
+
function describeArc(
|
|
222
|
+
centerX: number,
|
|
223
|
+
centerY: number,
|
|
224
|
+
r: number,
|
|
225
|
+
startDeg: number,
|
|
226
|
+
endDeg: number,
|
|
227
|
+
) {
|
|
228
|
+
if (Math.abs(endDeg - startDeg) < 0.1) return '';
|
|
229
|
+
const start = polarToCartesian(centerX, centerY, r, startDeg);
|
|
230
|
+
const end = polarToCartesian(centerX, centerY, r, endDeg);
|
|
231
|
+
const diff = endDeg - startDeg;
|
|
232
|
+
const largeArcFlag = diff > 180 ? 1 : 0;
|
|
233
|
+
return `M ${start.x.toFixed(2)} ${start.y.toFixed(2)} A ${r} ${r} 0 ${largeArcFlag} 1 ${end.x.toFixed(2)} ${end.y.toFixed(2)}`;
|
|
42
234
|
}
|
|
235
|
+
|
|
236
|
+
// Track arc path from startAngle to endAngle
|
|
237
|
+
const fullTrackPath = $derived(
|
|
238
|
+
describeArc(cx, geometry.cy, radius, geometry.startAngle, geometry.endAngle),
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
// Format resolver
|
|
242
|
+
const displayFormatter = $derived.by(() => {
|
|
243
|
+
if (format) return format;
|
|
244
|
+
if (formatter) return formatter;
|
|
245
|
+
return (val: number) => (Number.isInteger(val) ? `${val}` : val.toFixed(1));
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Ticks list
|
|
249
|
+
const computedTicks = $derived.by(() => {
|
|
250
|
+
if (!showTicks) return [];
|
|
251
|
+
if (Array.isArray(ticks)) {
|
|
252
|
+
return ticks.map((val) => {
|
|
253
|
+
const valRatio = (Math.max(min, Math.min(max, val)) - min) / range;
|
|
254
|
+
const deg = geometry.startAngle + valRatio * geometry.spanAngle;
|
|
255
|
+
const p1 = polarToCartesian(cx, geometry.cy, radius - effectiveThickness / 2 - 2, deg);
|
|
256
|
+
const p2 = polarToCartesian(cx, geometry.cy, radius - effectiveThickness / 2 - 6, deg);
|
|
257
|
+
return { val, deg, p1, p2 };
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const count = Math.max(2, ticks);
|
|
262
|
+
const result: Array<{
|
|
263
|
+
val: number;
|
|
264
|
+
deg: number;
|
|
265
|
+
p1: { x: number; y: number };
|
|
266
|
+
p2: { x: number; y: number };
|
|
267
|
+
}> = [];
|
|
268
|
+
for (let i = 0; i <= count; i++) {
|
|
269
|
+
const valRatio = i / count;
|
|
270
|
+
const deg = geometry.startAngle + valRatio * geometry.spanAngle;
|
|
271
|
+
const val = Math.round(min + valRatio * range);
|
|
272
|
+
const isMajor = i === 0 || i === count || i === Math.floor(count / 2);
|
|
273
|
+
const tickLen = isMajor ? 7 : 4;
|
|
274
|
+
const p1 = polarToCartesian(cx, geometry.cy, radius - effectiveThickness / 2 - 2, deg);
|
|
275
|
+
const p2 = polarToCartesian(cx, geometry.cy, radius - effectiveThickness / 2 - 2 - tickLen, deg);
|
|
276
|
+
result.push({ val, deg, p1, p2 });
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// Target benchmark line
|
|
282
|
+
const targetMark = $derived.by(() => {
|
|
283
|
+
if (target === undefined || target < min || target > max) return null;
|
|
284
|
+
const targetRatio = (target - min) / range;
|
|
285
|
+
const deg = geometry.startAngle + targetRatio * geometry.spanAngle;
|
|
286
|
+
const p1 = polarToCartesian(cx, geometry.cy, radius - effectiveThickness / 2 - 3, deg);
|
|
287
|
+
const p2 = polarToCartesian(cx, geometry.cy, radius + effectiveThickness / 2 + 3, deg);
|
|
288
|
+
return { target, deg, p1, p2 };
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
// Min / Max point coordinates for labels
|
|
292
|
+
const minPos = $derived(polarToCartesian(cx, geometry.cy, radius - 16, geometry.startAngle + 8));
|
|
293
|
+
const maxPos = $derived(polarToCartesian(cx, geometry.cy, radius - 16, geometry.endAngle - 8));
|
|
43
294
|
</script>
|
|
44
295
|
|
|
45
|
-
<div
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
296
|
+
<div
|
|
297
|
+
role="meter"
|
|
298
|
+
aria-valuenow={value}
|
|
299
|
+
aria-valuemin={min}
|
|
300
|
+
aria-valuemax={max}
|
|
301
|
+
aria-label={label ?? `${displayFormatter(value)}${unit}`}
|
|
302
|
+
data-svadmin-component="GaugeChart"
|
|
303
|
+
data-tone={activeTone}
|
|
304
|
+
data-gauge-type={type}
|
|
305
|
+
class={cn(
|
|
306
|
+
'relative flex flex-col items-center justify-between rounded-xl border border-border bg-card p-4 text-card-foreground shadow-sm transition-all',
|
|
307
|
+
className,
|
|
308
|
+
)}
|
|
309
|
+
style="width: {widthPx}px;"
|
|
310
|
+
>
|
|
311
|
+
{#if label || target !== undefined}
|
|
312
|
+
<div class="mb-2 w-full flex items-center justify-between px-1">
|
|
313
|
+
<span class="text-sm font-semibold tracking-tight text-foreground truncate">
|
|
314
|
+
{label ?? ''}
|
|
315
|
+
</span>
|
|
316
|
+
{#if target !== undefined}
|
|
317
|
+
<span class="text-[11px] font-medium text-muted-foreground font-mono">
|
|
318
|
+
{targetLabel}: {target}{unit}
|
|
319
|
+
</span>
|
|
320
|
+
{/if}
|
|
321
|
+
</div>
|
|
322
|
+
{/if}
|
|
323
|
+
|
|
324
|
+
<div class="relative flex w-full items-center justify-center overflow-hidden">
|
|
325
|
+
<svg
|
|
326
|
+
role="img"
|
|
327
|
+
aria-label={label ?? `${displayFormatter(value)}`}
|
|
328
|
+
viewBox={geometry.viewBox}
|
|
329
|
+
class="w-full h-auto max-w-full select-none"
|
|
330
|
+
>
|
|
331
|
+
<!-- Base track arc -->
|
|
332
|
+
<path
|
|
333
|
+
d={fullTrackPath}
|
|
334
|
+
fill="none"
|
|
335
|
+
stroke="var(--muted)"
|
|
336
|
+
stroke-width={effectiveThickness}
|
|
337
|
+
stroke-linecap="round"
|
|
338
|
+
pathLength="100"
|
|
339
|
+
/>
|
|
340
|
+
|
|
341
|
+
<!-- Active progress arc -->
|
|
342
|
+
<path
|
|
343
|
+
d={fullTrackPath}
|
|
344
|
+
fill="none"
|
|
345
|
+
stroke={activeColor}
|
|
346
|
+
stroke-width={effectiveThickness}
|
|
347
|
+
stroke-linecap="round"
|
|
348
|
+
pathLength="100"
|
|
349
|
+
stroke-dasharray="{percent100} 100"
|
|
350
|
+
class="transition-all duration-500"
|
|
351
|
+
/>
|
|
352
|
+
|
|
353
|
+
<!-- Tick marks -->
|
|
354
|
+
{#if showTicks}
|
|
355
|
+
{#each computedTicks as tick, i (i)}
|
|
356
|
+
<line
|
|
357
|
+
x1={tick.p1.x}
|
|
358
|
+
y1={tick.p1.y}
|
|
359
|
+
x2={tick.p2.x}
|
|
360
|
+
y2={tick.p2.y}
|
|
361
|
+
stroke="currentColor"
|
|
362
|
+
class="text-muted-foreground/40"
|
|
363
|
+
stroke-width="1.5"
|
|
364
|
+
stroke-linecap="round"
|
|
365
|
+
/>
|
|
366
|
+
{/each}
|
|
367
|
+
{/if}
|
|
368
|
+
|
|
369
|
+
<!-- Target benchmark line -->
|
|
370
|
+
{#if targetMark}
|
|
371
|
+
<line
|
|
372
|
+
x1={targetMark.p1.x}
|
|
373
|
+
y1={targetMark.p1.y}
|
|
374
|
+
x2={targetMark.p2.x}
|
|
375
|
+
y2={targetMark.p2.y}
|
|
376
|
+
stroke="currentColor"
|
|
377
|
+
class="text-foreground"
|
|
378
|
+
stroke-width="2.5"
|
|
379
|
+
stroke-dasharray="2 2"
|
|
380
|
+
/>
|
|
381
|
+
{/if}
|
|
382
|
+
|
|
383
|
+
<!-- Needle pointer indicator -->
|
|
384
|
+
{#if mode === 'needle' || mode === 'both'}
|
|
385
|
+
<g
|
|
386
|
+
transform="rotate({currentAngle}, {cx}, {geometry.cy})"
|
|
387
|
+
class="transition-transform duration-500 ease-out origin-[{cx}px_{geometry.cy}px]"
|
|
388
|
+
>
|
|
389
|
+
<polygon
|
|
390
|
+
points="{cx - 8},{geometry.cy - 3} {cx + radius - 12},{geometry.cy} {cx - 8},{geometry.cy + 3}"
|
|
391
|
+
fill={activeColor}
|
|
392
|
+
class="drop-shadow-sm"
|
|
393
|
+
/>
|
|
394
|
+
<circle
|
|
395
|
+
cx={cx}
|
|
396
|
+
cy={geometry.cy}
|
|
397
|
+
r="5.5"
|
|
398
|
+
fill="currentColor"
|
|
399
|
+
class="text-background"
|
|
400
|
+
stroke={activeColor}
|
|
401
|
+
stroke-width="2"
|
|
402
|
+
/>
|
|
403
|
+
</g>
|
|
404
|
+
{/if}
|
|
405
|
+
|
|
406
|
+
<!-- Min and Max scale labels -->
|
|
407
|
+
{#if showTickLabels}
|
|
408
|
+
<text
|
|
409
|
+
x={minPos.x}
|
|
410
|
+
y={minPos.y}
|
|
411
|
+
text-anchor="middle"
|
|
412
|
+
class="fill-muted-foreground text-[10px] font-mono select-none"
|
|
413
|
+
>
|
|
414
|
+
{min}
|
|
415
|
+
</text>
|
|
416
|
+
<text
|
|
417
|
+
x={maxPos.x}
|
|
418
|
+
y={maxPos.y}
|
|
419
|
+
text-anchor="middle"
|
|
420
|
+
class="fill-muted-foreground text-[10px] font-mono select-none"
|
|
421
|
+
>
|
|
422
|
+
{max}
|
|
423
|
+
</text>
|
|
424
|
+
{/if}
|
|
425
|
+
</svg>
|
|
426
|
+
|
|
427
|
+
<!-- Center reading readout -->
|
|
428
|
+
<div
|
|
429
|
+
class={cn(
|
|
430
|
+
'pointer-events-none absolute flex flex-col items-center justify-center text-center',
|
|
431
|
+
type === 'half' ? 'bottom-2' : 'bottom-5',
|
|
432
|
+
)}
|
|
433
|
+
>
|
|
434
|
+
<div class="flex items-baseline gap-1">
|
|
435
|
+
<span class="font-mono text-2xl font-bold tracking-tight text-foreground md:text-3xl">
|
|
436
|
+
{displayFormatter(clampedValue)}
|
|
437
|
+
</span>
|
|
438
|
+
{#if unit}
|
|
439
|
+
<span class="text-xs font-medium text-muted-foreground">{unit}</span>
|
|
440
|
+
{/if}
|
|
441
|
+
</div>
|
|
442
|
+
|
|
443
|
+
{#if showBadge && activeThreshold.label}
|
|
444
|
+
<span
|
|
445
|
+
data-slot="badge"
|
|
446
|
+
data-tone={activeTone}
|
|
447
|
+
class={cn(
|
|
448
|
+
'mt-1 inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] font-medium leading-none transition-colors',
|
|
449
|
+
activeTokenInfo.badge,
|
|
450
|
+
)}
|
|
451
|
+
>
|
|
452
|
+
{activeThreshold.label}
|
|
453
|
+
</span>
|
|
454
|
+
{/if}
|
|
455
|
+
</div>
|
|
456
|
+
</div>
|
|
457
|
+
|
|
458
|
+
{#if subtext}
|
|
459
|
+
<p class="mt-2 text-center text-xs text-muted-foreground">
|
|
460
|
+
{subtext}
|
|
461
|
+
</p>
|
|
462
|
+
{/if}
|
|
463
|
+
|
|
464
|
+
{#if footer}
|
|
465
|
+
<div class="mt-3 w-full border-t border-border pt-2 text-xs">
|
|
466
|
+
{@render footer()}
|
|
467
|
+
</div>
|
|
468
|
+
{/if}
|
|
469
|
+
</div>
|
|
@@ -1,14 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
export type GaugeTone = 'primary' | 'success' | 'warning' | 'destructive' | 'info' | 'muted';
|
|
3
|
+
export type GaugeType = 'half' | 'arc' | 'circle';
|
|
4
|
+
export type GaugeMode = 'progress' | 'needle' | 'both';
|
|
5
|
+
export interface GaugeThreshold {
|
|
6
|
+
/** Upper bound value of this segment/threshold zone */
|
|
2
7
|
value: number;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
label
|
|
8
|
-
|
|
9
|
-
color?: string;
|
|
10
|
-
class?: string;
|
|
8
|
+
/** Semantic tone (success, warning, destructive, primary, info, muted) */
|
|
9
|
+
tone?: GaugeTone | undefined;
|
|
10
|
+
/** Optional custom CSS color token or variable expression (e.g. 'var(--chart-1)') */
|
|
11
|
+
color?: string | undefined;
|
|
12
|
+
/** Human-readable label for this threshold zone (e.g. 'Normal', 'Warning', 'Critical') */
|
|
13
|
+
label?: string | undefined;
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
export interface GaugeChartProps {
|
|
16
|
+
/** Current numeric metric value */
|
|
17
|
+
value: number;
|
|
18
|
+
/** Minimum gauge value (default: 0) */
|
|
19
|
+
min?: number | undefined;
|
|
20
|
+
/** Maximum gauge value (default: 100) */
|
|
21
|
+
max?: number | undefined;
|
|
22
|
+
/** Unit suffix (e.g. '%', 'MB/s', 'req/s', 'ms', '°C') */
|
|
23
|
+
unit?: string | undefined;
|
|
24
|
+
/** Metric title / label */
|
|
25
|
+
label?: string | undefined;
|
|
26
|
+
/** Subtitle or contextual note (e.g. 'Target: < 80%', 'Peak: 95%') */
|
|
27
|
+
subtext?: string | undefined;
|
|
28
|
+
/** Gauge arc span type: 'half' (180° semi-circle), 'arc' (240° speedometer), 'circle' (270° wide arc) */
|
|
29
|
+
type?: GaugeType | undefined;
|
|
30
|
+
/** Display mode: 'progress' (filled progress arc), 'needle' (classic indicator needle), 'both' */
|
|
31
|
+
mode?: GaugeMode | undefined;
|
|
32
|
+
/** Custom threshold intervals. Defaults to [0..60 success, 60..85 warning, 85..100 destructive] */
|
|
33
|
+
thresholds?: GaugeThreshold[] | undefined;
|
|
34
|
+
/** Benchmark target line value (e.g. SLA target 80) */
|
|
35
|
+
target?: number | undefined;
|
|
36
|
+
/** Target label (default: 'Target') */
|
|
37
|
+
targetLabel?: string | undefined;
|
|
38
|
+
/** Number of tick marks or custom tick values */
|
|
39
|
+
ticks?: number | number[] | undefined;
|
|
40
|
+
/** Whether to show tick marks (default: true) */
|
|
41
|
+
showTicks?: boolean | undefined;
|
|
42
|
+
/** Whether to show min/max tick labels (default: true) */
|
|
43
|
+
showTickLabels?: boolean | undefined;
|
|
44
|
+
/** Gauge size preset ('sm' | 'md' | 'lg') or numeric width (default: 'md' / 220) */
|
|
45
|
+
size?: 'sm' | 'md' | 'lg' | number | undefined;
|
|
46
|
+
/** Stroke thickness for the gauge arc track (default: 14) */
|
|
47
|
+
thickness?: number | undefined;
|
|
48
|
+
/** Custom stroke width for the gauge arc track (alias for thickness) */
|
|
49
|
+
strokeWidth?: number | undefined;
|
|
50
|
+
/** Custom value formatter (legacy alias for formatter) */
|
|
51
|
+
format?: ((val: number) => string) | undefined;
|
|
52
|
+
/** Custom value formatter */
|
|
53
|
+
formatter?: ((val: number) => string) | undefined;
|
|
54
|
+
/** Explicit stroke color override */
|
|
55
|
+
color?: string | undefined;
|
|
56
|
+
/** Whether to display current status badge below value (default: true) */
|
|
57
|
+
showBadge?: boolean | undefined;
|
|
58
|
+
/** Additional CSS classes for the outer container */
|
|
59
|
+
class?: string | undefined;
|
|
60
|
+
/** Optional bottom actions or extra details slot */
|
|
61
|
+
footer?: Snippet | undefined;
|
|
62
|
+
}
|
|
63
|
+
declare const GaugeChart: import("svelte").Component<GaugeChartProps, {}, "">;
|
|
13
64
|
type GaugeChart = ReturnType<typeof GaugeChart>;
|
|
14
65
|
export default GaugeChart;
|