diff --git a/site/src/components/MmpChart.svelte b/site/src/components/MmpChart.svelte index 6b34def..48d6176 100644 --- a/site/src/components/MmpChart.svelte +++ b/site/src/components/MmpChart.svelte @@ -32,8 +32,18 @@ '#22d3ee', // cyan-400 ]; - function curveColor(key: RangeKey, index: number): string { - return PALETTE[index % PALETTE.length]; + const allRangeKeys = [ + ...Object.keys(PRESET_LABELS), + ...seasons.map(s => s.name), + ]; + + // Stable color per key — based on position in allRangeKeys, not in the active selection + const RANGE_COLOR: Record = Object.fromEntries( + allRangeKeys.map((k, i) => [k, PALETTE[i % PALETTE.length]]) + ); + + function curveColor(key: RangeKey): string { + return RANGE_COLOR[key] ?? PALETTE[0]; } // ── Record-holder lookup ─────────────────────────────────────────────────── @@ -121,7 +131,7 @@ }); }); - $: colorMap = Object.fromEntries(selectedKeys.map((k, i) => [k, curveColor(k, i)])); + $: colorMap = Object.fromEntries(selectedKeys.map(k => [k, curveColor(k)])); function getAxisColor() { return document.documentElement.getAttribute('data-theme') === 'light' ? '#52525b' : '#a1a1aa'; @@ -155,7 +165,7 @@ }, color: { domain: selectedKeys, - range: selectedKeys.map((k, i) => curveColor(k, i)), + range: selectedKeys.map(k => curveColor(k)), legend: selectedKeys.length > 1, }, marks: [ @@ -222,11 +232,6 @@ selectedRanges = next; } - const allRangeKeys = [ - ...Object.keys(PRESET_LABELS), - ...seasons.map(s => s.name), - ]; - // ── Records table ────────────────────────────────────────────────────────── let tableRange: RangeKey = 'all_time'; @@ -254,9 +259,9 @@
- {#each allRangeKeys as key, i} + {#each allRangeKeys as key} {@const active = selectedRanges.has(key)} - {@const color = curveColor(key, i)} + {@const color = curveColor(key)} {/each}