Files
archie/ui/src/base/Gauge.vue
T
sam 3d20dde9cb feat(webui): port the shared primitives (Phase 2)
The Preact tree's ui/src/base/ was deleted with the dashboard. This rebuilds
what depended on it, on the shadcn layer rather than as new bespoke markup.

Badge and Card come from the shadcn-vue CLI, so they match the already-vendored
components, and the composed pieces sit on top of them:

- Badge gains the five status variants the pills used, over the palette's status
  tokens. The pill's dot did not come across: the Badge's own shape is the
  affordance, and the same variant now covers a trend indicator, where a dot
  reads as noise.
- base/StatTile.vue uses full Card composition instead of dumping everything
  into one content slot, with base/Sparkline.vue and the goodDirection logic
  that says whether "up" is good news.
- base/Gauge.vue and base/SegmentBar.vue, both of them: the original exported
  two components from one file and budget composition uses the second.
- base/LogRow.vue over lib/log.ts, which holds the LOG_LEVELS wire contract
  (the server matches that CSV server-side, so it is not a display choice).
- lib/status.ts, so status colour has one home: a task state, a gate result, a
  log level and a trend all draw from the same five kinds.

Two deliberate departures:

The icon module is not ported. Its name-to-glyph string lookup is the pattern
shadcn-vue's rules call out as wrong, and nothing consumes the five bespoke
glyphs anyway: the navigation is text with tooltips. Icons come from @lucide/vue
at the call site, and the five become components if a page draws them.

The gauge's aria-label announces the rounded percentage. It announced the raw
one, so a screen reader read 71.38461538461539% where the screen showed 71%
(bead 86au).

Also lands the four modules the checklist marks copy-verbatim, which encode
bugs fixed just before the delete: dashboard/activity-detail, chat/
command-scroll, workflows/workflow-rows and logs/logs-empty.
2026-09-20 19:38:17 +10:00

76 lines
2.5 KiB
Vue

<script setup lang="ts">
import { computed } from "vue";
/**
* Arc gauge for a single headline percentage.
*
* A percentage that decides whether you need to act deserves more than a line
* of text: the arc is readable at a glance from across a room, which a number
* is not. Colour follows the value, so "is this bad" is answered before the
* digits are read.
*/
const props = withDefaults(defineProps<{ value: number | string; label: string; size?: number }>(), {
size: 168,
});
const pct = computed(() => Math.max(0, Math.min(100, Number(props.value) || 0)));
const rounded = computed(() => Math.round(pct.value));
const stroke = computed(() => (pct.value >= 90 ? "var(--ok)" : pct.value >= 70 ? "var(--warn)" : "var(--danger)"));
// 240-degree arc, opening downward, so the value reads left-to-right.
const R = 62;
const SWEEP = 240;
const START = 150;
const circumference = 2 * Math.PI * R * (SWEEP / 360);
function arc(from: number, deg: number): string {
const cx = props.size / 2;
const cy = props.size / 2;
const a0 = (from * Math.PI) / 180;
const a1 = ((from + deg) * Math.PI) / 180;
const large = deg > 180 ? 1 : 0;
return [
`M ${cx + R * Math.cos(a0)} ${cy + R * Math.sin(a0)}`,
`A ${R} ${R} 0 ${large} 1 ${cx + R * Math.cos(a1)} ${cy + R * Math.sin(a1)}`,
].join(" ");
}
</script>
<template>
<div class="relative grid place-items-center">
<!--
The label announces the rounded value. It used to announce the raw one, so
a screen reader read "71.38461538461539%" before the same figure was
shown rounded.
-->
<svg
class="block w-full max-w-[200px]"
:viewBox="`0 0 ${props.size} ${props.size * 0.78}`"
role="img"
:aria-label="`${props.label}: ${rounded}%`"
>
<path
:d="arc(START, SWEEP)"
fill="none"
stroke="var(--border)"
stroke-width="12"
stroke-linecap="round"
/>
<path
:d="arc(START, SWEEP)"
fill="none"
:stroke="stroke"
stroke-width="12"
stroke-linecap="round"
:stroke-dasharray="circumference"
:stroke-dashoffset="circumference * (1 - pct / 100)"
class="transition-[stroke-dashoffset] duration-[600ms] ease-[cubic-bezier(0.4,0,0.2,1)]"
/>
</svg>
<div class="absolute top-[52%] -translate-y-1/2 text-center">
<div class="text-2xl font-semibold tracking-[-0.03em]">{{ rounded }}%</div>
<div class="text-xs text-fg-muted">{{ props.label }}</div>
</div>
</div>
</template>