@@ -32,52 +32,80 @@ const unallocatedPercent = computed(() => {
3232 return Math .max (0 , partitionPercent (diskSize - usedSpace .value , diskSize ))
3333})
3434
35+ const knownLabelColors = {
36+ efi: ' bg-yellow-500' ,
37+ boot: ' bg-orange-500' ,
38+ state: ' bg-purple-500' ,
39+ ephemeral: ' bg-blue-500' ,
40+ }
41+
42+ const unknownLabelColors = computed (
43+ () =>
44+ new Map (
45+ volumes
46+ .filter ((v ) => {
47+ const label = v .spec .partition_label ?.toLowerCase ()
48+
49+ return ! label || ! (label in knownLabelColors )
50+ })
51+ .map ((v , i ) => {
52+ const hue = ((i + 1 ) * 137.508 ) % 360
53+
54+ return [v .metadata .id ! , ` hsl(${hue .toFixed (1 )}deg 55% 30%) ` ] as const
55+ }),
56+ ),
57+ )
58+
3559const getVolumeClass = (volume : Resource <DiscoveredVolumeSpec >) => {
36- const fsType = volume .spec .name ?.toLowerCase ()
37- const label = volume .spec .partition_label ?.toLowerCase ()
38-
39- if (label ?.includes (' efi' )) return ' bg-yellow-500'
40- if (label ?.includes (' boot' )) return ' bg-orange-500'
41- if (label ?.includes (' state' )) return ' bg-purple-500'
42- if (label ?.includes (' ephemeral' )) return ' bg-blue-500'
43- if (fsType ?.includes (' luks' )) return ' bg-indigo-500'
44- if (fsType ?.includes (' xfs' ) || fsType ?.includes (' ext' )) return ' bg-green-600'
45- if (fsType ?.includes (' vfat' ) || fsType ?.includes (' fat' )) return ' bg-yellow-600'
46- if (fsType ?.includes (' swap' )) return ' bg-red-500'
47- return ' bg-naturals-n9'
60+ const label = volume .spec .partition_label ?.toLowerCase () as keyof typeof knownLabelColors
61+
62+ return label ? knownLabelColors [label ] : undefined
63+ }
64+
65+ const getVolumeStyle = (volume : Resource <DiscoveredVolumeSpec >) => {
66+ const color = unknownLabelColors .value .get (volume .metadata .id ! )
67+
68+ return color ? { backgroundColor: color } : undefined
4869}
4970 </script >
5071
5172<template >
5273 <div >
53- <div class =" flex h-8 w-full overflow-hidden rounded bg-naturals-n5" >
74+ <div class =" flex h-8 w-full overflow-hidden rounded bg-naturals-n5 text-xs " >
5475 <div
5576 v-for =" volume in volumes"
5677 :key =" volume.metadata.id"
5778 :title =" `${volume.spec.partition_label || volume.spec.label || volume.spec.dev_path} — ${prettyBytes(volume.spec.size ?? 0)}`"
5879 :class =" getVolumeClass(volume)"
5980 :style =" {
6081 width: `${partitionPercent(volume.spec.size, disk.spec.size)}%`,
82+ ...getVolumeStyle(volume),
6183 }"
62- class =" flex min-w-0 items-center justify-center overflow-hidden text-xs text- naturals-n14 last:border-r-0"
84+ class =" flex min-w-0 items-center justify-center overflow-hidden text-naturals-n14 last:border-r-0"
6385 >
6486 <span
6587 v-if =" partitionPercent(volume.spec.size, disk.spec.size) > 10"
66- class =" truncate px-1.5 text-xs font-medium drop-shadow-xs drop-shadow-black"
88+ class =" truncate px-1.5 font-medium drop-shadow-xs drop-shadow-black"
6789 >
6890 {{ volume.spec.partition_label || volume.spec.label || '' }}
6991 <span class =" opacity-80" >
7092 {{ prettyBytes(volume.spec.size ?? 0) }}
7193 </span >
7294 </span >
7395 </div >
96+
7497 <div
7598 v-if =" unallocatedPercent > 0"
7699 :style =" { width: `${unallocatedPercent}%` }"
77100 title =" Unallocated"
78- class =" flex min-w-0 items-center justify-center overflow-hidden text-xs text-naturals-n12"
101+ class =" flex min-w-0 items-center justify-center overflow-hidden bg-[repeating-linear-gradient(-45deg,var(--stripe-color),var(--stripe-color)_var(--stripe-size),transparent_var(--stripe-size),transparent_calc(var(--stripe-size)*2))] text-naturals-n12 [--stripe-color:var(--color-naturals-n7)] [--stripe-size:12px] "
79102 >
80- <span v-if =" unallocatedPercent > 10" class =" truncate px-1.5" >Unallocated</span >
103+ <span
104+ v-if =" unallocatedPercent > 10"
105+ class =" truncate px-1.5 font-medium drop-shadow-xs drop-shadow-black"
106+ >
107+ Unallocated
108+ </span >
81109 </div >
82110 </div >
83111
@@ -87,7 +115,11 @@ const getVolumeClass = (volume: Resource<DiscoveredVolumeSpec>) => {
87115 :key =" 'legend-' + volume.metadata.id"
88116 class =" flex items-center gap-1.5"
89117 >
90- <span class =" inline-block size-2.5 rounded-sm" :class =" getVolumeClass(volume)" />
118+ <span
119+ class =" inline-block size-2.5 rounded-sm"
120+ :class =" getVolumeClass(volume)"
121+ :style =" getVolumeStyle(volume)"
122+ />
91123 <span class =" font-medium text-naturals-n12" >
92124 {{ volume.spec.partition_label || volume.spec.label || volume.spec.dev_path }}
93125 </span >
0 commit comments