feat: computer stats redesign

- also fix bug where all time uptime doesn't show when computer is
offline
- another bug was fixed related to that because of how it is calculated
This commit is contained in:
trafficlunar 2025-11-29 14:57:11 +00:00
parent 85e5bc31ec
commit 00e2406008
4 changed files with 213 additions and 130 deletions

View file

@ -13,6 +13,7 @@
"@tailwindcss/vite": "^4.1.17", "@tailwindcss/vite": "^4.1.17",
"astro": "^5.15.7", "astro": "^5.15.7",
"d3-scale": "^4.0.2", "d3-scale": "^4.0.2",
"d3-shape": "^3.2.0",
"layerchart": "2.0.0-next.43", "layerchart": "2.0.0-next.43",
"svelte": "^5.43.6", "svelte": "^5.43.6",
"tailwindcss": "^4.1.17", "tailwindcss": "^4.1.17",
@ -20,6 +21,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/d3-scale": "^4.0.9", "@types/d3-scale": "^4.0.9",
"@types/d3-shape": "^3.1.7",
"vite": "^7.2.2", "vite": "^7.2.2",
}, },
}, },
@ -535,8 +537,12 @@
"@trysound/sax": ["@trysound/sax@0.2.0", "", {}, "sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA=="], "@trysound/sax": ["@trysound/sax@0.2.0", "", {}, "sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA=="],
"@types/d3-path": ["@types/d3-path@3.1.1", "", {}, "sha512-VMZBYyQvbGmWyWVea0EHs/BwLgxc+MKi1zLDCONksozI4YJMcTt8ZEuIR4Sb1MMTE8MMW49v0IwI5+b7RmfWlg=="],
"@types/d3-scale": ["@types/d3-scale@4.0.9", "", { "dependencies": { "@types/d3-time": "*" } }, "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw=="], "@types/d3-scale": ["@types/d3-scale@4.0.9", "", { "dependencies": { "@types/d3-time": "*" } }, "sha512-dLmtwB8zkAeO/juAMfnV+sItKjlsw2lKdZVVy6LRr0cBmegxSABiLEpGVmSJJ8O08i4+sGR6qQtb6WtuwJdvVw=="],
"@types/d3-shape": ["@types/d3-shape@3.1.7", "", { "dependencies": { "@types/d3-path": "*" } }, "sha512-VLvUQ33C+3J+8p+Daf+nYSOsjB4GXp19/S/aGo60m9h1v6XaxjiT82lKVWJCfzhtuZ3yD7i/TPeC/fuKLLOSmg=="],
"@types/d3-time": ["@types/d3-time@3.0.4", "", {}, "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g=="], "@types/d3-time": ["@types/d3-time@3.0.4", "", {}, "sha512-yuzZug1nkAAaBlBBikKZTgzCeA+k1uy4ZFwWANOfKw5z5LRhV0gNA7gNkKm7HoK+HRN0wX3EkxGk0fpbWhmB7g=="],
"@types/debug": ["@types/debug@4.1.12", "", { "dependencies": { "@types/ms": "*" } }, "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ=="], "@types/debug": ["@types/debug@4.1.12", "", { "dependencies": { "@types/ms": "*" } }, "sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ=="],

View file

@ -18,6 +18,7 @@
"@tailwindcss/vite": "^4.1.17", "@tailwindcss/vite": "^4.1.17",
"astro": "^5.15.7", "astro": "^5.15.7",
"d3-scale": "^4.0.2", "d3-scale": "^4.0.2",
"d3-shape": "^3.2.0",
"layerchart": "2.0.0-next.43", "layerchart": "2.0.0-next.43",
"svelte": "^5.43.6", "svelte": "^5.43.6",
"tailwindcss": "^4.1.17", "tailwindcss": "^4.1.17",
@ -25,6 +26,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/d3-scale": "^4.0.9", "@types/d3-scale": "^4.0.9",
"@types/d3-shape": "^3.1.7",
"vite": "^7.2.2" "vite": "^7.2.2"
} }
} }

View file

@ -1,7 +1,8 @@
<script lang="ts"> <script lang="ts">
import { onMount } from "svelte";
import { Area, Axis, Chart, Highlight, LinearGradient, Svg, Tooltip } from "layerchart"; import { Area, Axis, Chart, Highlight, LinearGradient, Svg, Tooltip } from "layerchart";
import { scaleTime } from "d3-scale"; import { scaleTime } from "d3-scale";
import { onMount } from "svelte"; import { curveBasis } from "d3-shape";
import { computerData } from "../states.svelte"; import { computerData } from "../states.svelte";
type GraphData = { type GraphData = {
@ -16,6 +17,9 @@
let currentCPU = $state(0); let currentCPU = $state(0);
let currentRAM = $state(0); let currentRAM = $state(0);
let stopwatchDeg = $state(0);
let clicksPerMinute = $state(0); let clicksPerMinute = $state(0);
let keysPerMinute = $state(0); let keysPerMinute = $state(0);
@ -73,15 +77,19 @@
keysPerMinute = totalKeys / 60; keysPerMinute = totalKeys / 60;
// Uptime // Uptime
const diff = data.online ? Math.floor((Date.now() - data.uptimeStart * 1000) / 1000) : 0;
const allTime = diff + data.totals.uptime;
allTimeUptime = formatTime(allTime);
if (!data.online) { if (!data.online) {
uptime = "Offline"; uptime = "Offline";
return; return;
} }
const diff = Math.floor((Date.now() - data.uptimeStart * 1000) / 1000);
const allTime = diff + data.totals.uptime;
uptime = formatTime(diff); uptime = formatTime(diff);
allTimeUptime = formatTime(allTime); // there is a bug where the arrow spins around when it reaches ~354 degrees but it looks cool so i'm not fixing it
stopwatchDeg = (diff % 60) * 6;
}; };
get(); get();
@ -90,45 +98,97 @@
}); });
</script> </script>
<div class="grid grid-cols-1 md:grid-cols-2 gap-0.5 font-mono text-sm p-4"> <div class="relative transition-all duration-300 delay-200 starting:opacity-0 starting:translate-y-4">
<div class="grid grid-cols-2 grid-rows-4 gap-0.5">
<span class="font-black">CPU:</span>
<span>{currentCPU}%</span>
<span class="font-black">RAM:</span>
<span>{currentRAM}%</span>
<span class="font-black">Clicks:</span>
<span>{clicksPerMinute.toFixed(2)}/min</span>
<span class="font-black">Keys:</span>
<span>{keysPerMinute.toFixed(2)}/min</span>
</div>
<div class="grid grid-cols-2 grid-rows-4 gap-0.5">
<span class="font-black">Uptime:</span>
<span>{uptime}</span>
<span class="font-black">All Time Uptime:</span>
<span>{allTimeUptime}</span>
<span class="font-black">All Time Clicks:</span>
<span>{allTimeClicks}</span>
<span class="font-black">All Time Keys:</span>
<span>{allTimeKeys}</span>
</div>
</div>
<div class="relative h-96">
<div class="absolute inset-0 size-full rounded-md bg-mantle border border-surface0 z-10"></div>
<div class="flex justify-center items-center absolute -top-2 right-2 z-0"> <div class="flex justify-center items-center absolute -top-2 right-2 z-0">
<div class="w-4 h-4 rounded-full {online ? 'bg-green' : 'bg-red'}"></div> <div class="w-4 h-4 rounded-full {online ? 'bg-green' : 'bg-red'}"></div>
<div class="w-4 h-4 rounded-full absolute animate-duration-2s animate-delay-2s {online ? 'bg-green animate-ping' : 'bg-red'}"></div> <div class="w-4 h-4 rounded-full absolute animate-duration-2s animate-delay-2s {online ? 'bg-green animate-ping' : 'bg-red'}"></div>
</div> </div>
<div class="absolute inset-0 size-full z-20 p-2"> <section class="mb-0!">
<legend>computer</legend>
<div class="font-mono text-sm mb-4 space-y-4">
<!-- System Stats Row -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<div class="flex items-center justify-between mb-1">
<span class="text-xs font-black text-overlay2">CPU</span>
<span class="text-xs font-bold text-peach">{currentCPU}%</span>
</div>
<div class="h-1.5 w-full rounded-full overflow-hidden bg-surface0/50">
<div class="h-full rounded-full bg-peach transition-all duration-300" style="width: {Math.min(100, currentCPU)}%;"></div>
</div>
</div>
<div>
<div class="flex items-center justify-between mb-1">
<span class="text-xs font-black text-overlay2">RAM</span>
<span class="text-xs font-bold text-yellow">{currentRAM}%</span>
</div>
<div class="h-1.5 w-full rounded-full overflow-hidden bg-surface0/50">
<div class="h-full rounded-full bg-yellow transition-all duration-300" style="width: {Math.min(100, currentRAM)}%;"></div>
</div>
</div>
</div>
<!-- Stats Grid -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<!-- Uptime Card -->
<div class="bg-surface0/30 rounded-lg p-3 border border-surface0 shadow-sm">
<div class="flex mb-1">
<div class="relative">
<svg width="20" height="20" viewBox="0 0 20 20" fill-rule="evenodd" class="absolute -bottom-0.5 fill-overlay1">
<path d="M10 5.5a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11M2.5 11a7.5 7.5 0 1 1 15 0 7.5 7.5 0 0 1-15 0" />
<path
d="M2.793 3.793a1 1 0 0 1 1.414 0l1.5 1.5c.91.943-.471 2.324-1.414 1.414l-1.5-1.5a1 1 0 0 1 0-1.414m11.5 2.914a1 1 0 0 0 1.414 0l1.5-1.5c.91-.943-.471-2.324-1.414-1.414l-1.5 1.5a1 1 0 0 0 0 1.414M9 4V2h2v2z"
/>
<path d="M7.5 2a1 1 0 0 1 1-1h3a1 1 0 1 1 0 2h-3a1 1 0 0 1-1-1" />
<!-- Hand -->
<path
d="m 13.28,8.375 c 0.345578,0.4310223 0.276171,1.0606079 -0.155,1.406 l -2.5,2 C 9.583667,12.614333 8.333667,11.052333 9.375,10.219 l 2.5,-2 c 0.431286,-0.3453463 1.060907,-0.2754879 1.406,0.156"
style="transform: rotate({stopwatchDeg - 52}deg); transform-origin: 10px 11px; transition: transform 1s linear;"
/>
</svg>
</div>
<span class="font-black text-xs text-overlay1 ml-6">UPTIME</span>
</div>
<div class="text-lg font-bold text-text">{uptime}</div>
<div class="text-xs text-overlay1 mt-1">Total: {allTimeUptime}</div>
</div>
<!-- Activity Card -->
<div class="bg-surface0/30 rounded-lg p-3 border border-surface0 shadow-sm">
<div class="font-black text-xs text-overlay1 mb-2">ACTIVITY / MIN</div>
<div class="space-y-1.5">
<div class="flex justify-between items-center">
<span class="text-xs text-overlay1">Clicks</span>
<span class="font-bold text-teal">{clicksPerMinute.toFixed(1)}</span>
</div>
<div class="flex justify-between items-center">
<span class="text-xs text-overlay1">Keys</span>
<span class="font-bold text-green">{keysPerMinute.toFixed(1)}</span>
</div>
</div>
</div>
<!-- All Time Card -->
<div class="bg-surface0/30 rounded-lg p-3 border border-surface0 shadow-sm">
<div class="font-black text-xs text-overlay1 mb-2">ALL TIME</div>
<div class="space-y-1.5">
<div class="flex justify-between items-center">
<span class="text-xs text-overlay1">Clicks</span>
<span class="font-bold text-teal">{allTimeClicks}</span>
</div>
<div class="flex justify-between items-center">
<span class="text-xs text-overlay1">Keys</span>
<span class="font-bold text-green">{allTimeKeys}</span>
</div>
</div>
</div>
</div>
</div>
<div class="relative h-96 rounded-md bg-mantle border border-surface0 p-2 shadow-sm">
<Chart <Chart
data={chartData} data={chartData}
x="timestamp" x="timestamp"
@ -140,20 +200,30 @@
tooltip={{ mode: "bisect-x" }} tooltip={{ mode: "bisect-x" }}
> >
<Svg> <Svg>
<Axis placement="left" grid rule classes={{ tickLabel: "fill-overlay1 font-medium stroke-none" }} format="percentRound" /> <Axis
<Axis placement="bottom" rule classes={{ tickLabel: "fill-overlay1 font-medium stroke-none" }} /> placement="left"
grid
rule
classes={{ tickLabel: "fill-overlay1 font-medium stroke-none", rule: "stroke-surface0/50", tick: "stroke-surface0/50" }}
format="percentRound"
/>
<Axis
placement="bottom"
rule
classes={{ tickLabel: "fill-overlay1 font-medium stroke-none", rule: "stroke-surface0/50", tick: "stroke-surface0/50" }}
/>
<!-- RAM --> <!-- RAM -->
<LinearGradient class="from-peach/50 to-peach/1" vertical> <LinearGradient class="from-peach/50 to-peach/1" vertical>
{#snippet children({ gradient })} {#snippet children({ gradient })}
<Area y1={(d) => d.ram} fill={gradient} line={{ class: "stroke-2 stroke-peach" }} /> <Area y1={(d) => d.ram} fill={gradient} line={{ class: "stroke-2 stroke-peach" }} curve={curveBasis} />
{/snippet} {/snippet}
</LinearGradient> </LinearGradient>
<!-- CPU --> <!-- CPU -->
<LinearGradient class="from-yellow/50 to-yellow/1" vertical> <LinearGradient class="from-yellow/50 to-yellow/1" vertical>
{#snippet children({ gradient })} {#snippet children({ gradient })}
<Area y1={(d) => d.cpu} fill={gradient} line={{ class: "stroke-2 stroke-yellow" }} /> <Area y1={(d) => d.cpu} fill={gradient} line={{ class: "stroke-2 stroke-yellow" }} curve={curveBasis} />
{/snippet} {/snippet}
</LinearGradient> </LinearGradient>
@ -166,16 +236,15 @@
{#snippet children({ data })} {#snippet children({ data })}
<Tooltip.Header value={data.timestamp} format="time" classes={{ root: "border-peach" }} /> <Tooltip.Header value={data.timestamp} format="time" classes={{ root: "border-peach" }} />
<Tooltip.List> <Tooltip.List>
<Tooltip.Item label="RAM (%)" value={data.ram} format="percentRound" classes={{ value: "font-mono font-black" }} /> <Tooltip.Item label="RAM (%)" value={data.ram} format="percentRound" classes={{ value: "font-mono font-black text-peach" }} />
<Tooltip.Item label="CPU (%)" value={data.cpu} format="percentRound" classes={{ value: "font-mono font-black" }} /> <Tooltip.Item label="CPU (%)" value={data.cpu} format="percentRound" classes={{ value: "font-mono font-black text-yellow" }} />
</Tooltip.List> </Tooltip.List>
{/snippet} {/snippet}
</Tooltip.Root> </Tooltip.Root>
</Chart> </Chart>
</div> </div>
</div>
<div class="relative h-48 rounded-md bg-mantle border border-surface0 p-2 mt-2"> <div class="relative h-48 rounded-md bg-mantle border border-surface0 p-2 mt-2 shadow-sm">
<Chart <Chart
data={chartData} data={chartData}
x="timestamp" x="timestamp"
@ -187,20 +256,29 @@
tooltip={{ mode: "bisect-x" }} tooltip={{ mode: "bisect-x" }}
> >
<Svg> <Svg>
<Axis placement="left" rule classes={{ tickLabel: "fill-overlay1 font-medium stroke-none" }} /> <Axis
<Axis placement="bottom" rule classes={{ tickLabel: "fill-overlay1 font-medium stroke-none" }} /> placement="left"
rule
classes={{ tickLabel: "fill-overlay1 font-medium stroke-none", rule: "stroke-surface0/50", tick: "stroke-surface0/50" }}
/>
<Axis
placement="bottom"
grid
rule
classes={{ tickLabel: "fill-overlay1 font-medium stroke-none", rule: "stroke-surface0/50", tick: "stroke-surface0/50" }}
/>
<!-- Keys --> <!-- Keys -->
<LinearGradient class="from-green/50 to-green/1" vertical> <LinearGradient class="from-green/50 to-green/1" vertical>
{#snippet children({ gradient })} {#snippet children({ gradient })}
<Area y1={(d) => d.keys} fill={gradient} line={{ class: "stroke-2 stroke-green" }} /> <Area y1={(d) => d.keys} fill={gradient} line={{ class: "stroke-2 stroke-green" }} curve={curveBasis} />
{/snippet} {/snippet}
</LinearGradient> </LinearGradient>
<!-- Clicks --> <!-- Clicks -->
<LinearGradient class="from-teal/50 to-teal/1" vertical> <LinearGradient class="from-teal/50 to-teal/1" vertical>
{#snippet children({ gradient })} {#snippet children({ gradient })}
<Area y1={(d) => d.clicks} fill={gradient} line={{ class: "stroke-2 stroke-teal" }} /> <Area y1={(d) => d.clicks} fill={gradient} line={{ class: "stroke-2 stroke-teal" }} curve={curveBasis} />
{/snippet} {/snippet}
</LinearGradient> </LinearGradient>
@ -213,10 +291,12 @@
{#snippet children({ data })} {#snippet children({ data })}
<Tooltip.Header value={data.timestamp} format="time" classes={{ root: "border-peach" }} /> <Tooltip.Header value={data.timestamp} format="time" classes={{ root: "border-peach" }} />
<Tooltip.List> <Tooltip.List>
<Tooltip.Item label="Keys" value={data.keys} classes={{ value: "font-mono font-black" }} /> <Tooltip.Item label="Keys" value={data.keys} classes={{ value: "font-mono font-black text-green" }} />
<Tooltip.Item label="Clicks" value={data.clicks} classes={{ value: "font-mono font-black" }} /> <Tooltip.Item label="Clicks" value={data.clicks} classes={{ value: "font-mono font-black text-teal" }} />
</Tooltip.List> </Tooltip.List>
{/snippet} {/snippet}
</Tooltip.Root> </Tooltip.Root>
</Chart> </Chart>
</div>
</section>
</div> </div>

View file

@ -7,10 +7,5 @@ import Computer from "../components/Computer.svelte";
<Layout> <Layout>
<Music client:load /> <Music client:load />
<section class="pt-0! transition-all duration-300 delay-200 starting:opacity-0 starting:translate-y-4">
<legend>computer</legend>
<Computer client:load /> <Computer client:load />
</section>
</Layout> </Layout>