diff --git a/src/components/AxisX.svelte b/src/components/AxisX.svelte index f1ecf61..8cf1d71 100644 --- a/src/components/AxisX.svelte +++ b/src/components/AxisX.svelte @@ -7,29 +7,46 @@ import { innerRadius } from '../stores/dimensions'; export let selectedData = []; + + let labels = []; + + $: { + const grouped = rollups( + selectedData, + (v) => v[0].angle, + (d) => [d.data.year, d.data.volume].join('/') + ); - $: labels = rollups( - selectedData, - (v) => v[0].angle, - (d) => [d.data.year, d.data.volume].join('/') - ); + let yearsDone = new Set(); + labels = grouped.map(([text, angle]) => { + const split = text.split('/') + const year = +split[0]; + if (yearsDone.has(year)) { + text = split[1]; + } else { + text = text.slice(2); + } + yearsDone.add(year); + return { text, angle }; + }); + } - {#each labels as [, angle]} - + {#each labels as label} + {/each} - {#each labels as [text, angle], i} + {#each labels as label, i} {/each}