Milestone

Completed

Visualisations

Understanding the weekly music dashboard

Now we get to the fun part. The Weekly Top Artists page turns all the music I’ve listened to each week into a simple interactive visual story, updated week by week, showing which artists I played the most and how my listening habits change over time.


1. Quick Terms to Know

A quick recap of terminology:

  • Scrobble: A single play of a song. If you listen to 5 tracks by an artist in a week, that counts as 5 scrobbles.
  • Week: A 7-day period (Monday through Sunday) capturing all one’s listening activity.

2. Key Features

šŸ“ˆ The All-Weeks Timeline (Top Chart)

The mountain-like line graph at the top gives you a birds-eye view of your total listening activity across your entire history:

  • Peaks & Valleys: Higher peaks represent weeks where you listened to a lot of music; lower valleys represent quieter weeks.
  • Year Labels: Timeline ticks along the bottom help you pinpoint exactly when different listening periods took place.

šŸŽÆ Interactive Scrubber & Playhead

  • Click or Drag: You can click or drag your mouse across the timeline chart to instantly jump to any point in time.
  • Playhead Line: A subtle vertical marker and dot track your cursor, highlighting the exact week currently displayed below.

šŸ† Weekly Leaderboard (Bottom Section)

Below the timeline, you’ll find the breakdown for the selected week:

  • Date & Total Scrobbles: Displays the exact calendar range (e.g., Jan 12 – Jan 18) and the total number of track plays logged that week.
  • Ranked Artist Rows: Shows each artist ranked by play count.
  • Visual Progress Bars: Coloured horizontal bars give you a quick visual comparison of how dominant your top artists were relative to each other.
  • Colour Coding: Your top #1 artist gets the brightest highlight colour. As you move down the ranks, the bar colours shift to softer tones, making it easy to identify your top favorites at a glance.

3. How to Navigate

You can explore your listening history in whichever way feels most natural to you:

  1. On-Screen Navigation Buttons:

    • ā® Jump to the very first week recorded.
    • ‹ Prev Move back one week.
    • Next › Advance forward one week.
    • ā­ Jump directly to the latest week.
  2. Keyboard Controls:

    • Left Arrow (←): Go back one week.
    • Right Arrow (→): Go forward one week.
    • Home Key: Jump to your earliest week.
    • End Key: Jump to your most recent week.
  3. Hover Popups (Tooltips):

    • Hover your mouse (or tap on mobile) over any artist’s bar row to see an instant pop-up window showing their exact rank and total scrobbles for that week.

4. Helpful Details

  • Remembers Where You Left Off: When you revisit the page later, it automatically remembers the last week you were looking at.
  • Fast & Reliable: The dashboard is built to load instantly, displaying your latest week immediately even on slow internet connections.
  • Works Without a Mouse: The timeline is a proper focusable control, not just a decorative chart, so tabbing to it and using the arrow keys works the same as clicking around with a mouse.

The dashboard uses a hybrid rendering architecture—combining static server-side HTML generation with light, framework-free client-side JavaScript.

Architectural Layers

  • Build-Time Processing (Astro Frontmatter): When the site builds, Node.js reads raw CSV data (weekly-top-artists.csv), parses artist rankings per week, calculates relative play counts, and pre-computes geometry for the overview sparkline graph.

  • Zero-JS Static Base (SSR): The component outputs pure HTML and CSS for the most recent week by default. A visitor gets a fully formatted chart instantly on initial page load, even if JavaScript is disabled or fails to execute.

  • Inline Data Injection: Full historical week-by-week data is serialized directly into a

Core Data Visualisation Techniques

FeatureTech ImplementationKey Details
Sparkline ChartInline SVG & Math UtilitiesBuilt using native SVG elements (, , ). Linear coordinate scaling functions (xForIdx and yForVal) transform raw scrobble counts into pixel-precise vector path commands (d=ā€œM … L … Zā€).
Colour PaletteOKLab Color SpaceRanks 1 through 5 use a single-hue ordinal scale defined via CSS custom properties (—lfm-rank-1..5). The ramp uses OKLab spacing to maintain uniform visual contrast across light and dark modes. Ranks past #5 reuse shade 5 to prevent contrast degradation.
Bar LeaderboardRelative Percentage WidthsEach artist’s play count is normalized against that week’s top artist ((count / max) * 100). The fill width scales via CSS transitions for smooth visual updates.

Dynamic DOM Updating: When swapping weeks, the client script re-renders bar rows using plain JavaScript (document.createElement). Global CSS rules (.lfm- prefix) ensure dynamically added DOM elements inherit styles without needing Astro’s scoped stylesheet compiler.

Unified Input Handling: Navigation listens to button clicks, keypresses (ArrowLeft, ArrowRight, Home, End), and pointer events (pointerdown, pointermove). Pointer capture locks dragging across the SVG sparkline for a smooth scrubbing interface.

Local Persistence: Page selections save to localStorage (lastfm-weekly-idx), restoring the last viewed week automatically on subsequent visits.


Why no charting library?

There’s no chart library anywhere in WeeklyTopArtists.astro, no D3, no Chart.js, nothing pulled in for this. Both visuals are built from primitives: the per-week leaderboard is a list of <div>s with a percentage-width fill, and the ā€œall weeksā€ overview is a single hand-built SVG <path>. For a bar list and a sparkline-style line chart, a library would mostly be paying for chart types this page doesn’t use.

The CSV is parsed once at build time using a ~100-line dependency-free parser in weeklyTopArtists.ts. Last.fm artist names contain commas often enough that a naive split(',') breaks, so it’s a proper quoted-field parser, just not a whole library for it. The result ships as plain HTML plus a small inline script.

The overview sparkline is a static SVG <path> computed at build time too, so the whole page renders correctly with JavaScript disabled. The script only adds the playhead, drag-to-scrub, and keyboard paging on top of markup that already works.

The bar count follows the CSV exactly, there’s no separate ā€œtop Nā€ setting in the component, just whatever --top-n the pull was run with. The rank colour shading doesn’t stretch as far, though: it’s a single-hue ramp validated against this site’s light/dark surfaces, and that validation stops holding up past about 5 steps (the accent colour and the contrast floor just don’t leave enough room for more distinguishable, accessible shades). Past rank 5 the bars fall back to the 5th shade; rank and value are still fully carried by position, the numbered badge, and the bar itself, so colour stays a bonus cue rather than the only one.


Built at build time, not in the browser

The overview chart’s geometry — the M/L path commands for the line, the matching filled area, the year tick positions — is all computed once in the component’s frontmatter, from the parsed CSV, at build time. Astro renders that straight to static SVG markup. The per-week bar list works the same way for whichever week is shown first: server-rendered <div> rows with pct widths baked in, no client JS required to see them.

A small inline <script> then hydrates the page on top of that markup — Prev/Next buttons, dragging the overview chart to scrub between weeks, arrow-key paging, and the tooltip. It reads the same week data (embedded as a JSON blob) and re-renders the bar list with document.createElement when the selected week changes. If JavaScript never runs, the page still shows a fully correct, fully readable chart for the latest week — the script only adds interactivity on top, never supplies content that wasn’t already there.


Colour as a bonus cue, not the only one

The bar-rank shading uses a 5-step single-hue colour ramp (--lfm-rank-1 through --lfm-rank-5, with separate light/dark values), spaced in OKLab rather than sRGB so the perceived lightness steps are actually even. It only defines 5 shades because that’s roughly where the usable range runs out — between this site’s accent colour and a legible contrast floor on both light and dark backgrounds, there isn’t room to fit more steps that stay both distinct from each other and accessible. Ranks past 5 reuse the 5th, most recessive shade rather than inventing a colour that wasn’t validated. That’s fine because colour was never the only way rank is shown, position in the list, the numbered badge, and the bar’s own length all carry it too.

Further reading on why OKLab rather than sRGB or HSL for this kind of ramp: Bjƶrn Ottosson’s A perceptual color space for image processing, which is where the OKLab colour space this ramp is built in comes from.