From 3ac942962db28250ea4a940c3608bce3bad68b53 Mon Sep 17 00:00:00 2001 From: Sean Lynch Date: Mon, 19 Oct 2026 15:53:08 -0400 Subject: [PATCH] Add interactive college sports ranking chart examples --- .../Image/college-football-upsets.svelte | 242 ++++++++++++ .../LineChart/bump-sports-rankings.svelte | 308 +++++++++++++++ .../bump-state-population-ranks.svelte | 4 + docs/src/lib/sports.remote.ts | 372 ++++++++++++++++++ 4 files changed, 926 insertions(+) create mode 100644 docs/src/examples/components/Image/college-football-upsets.svelte create mode 100644 docs/src/examples/components/LineChart/bump-sports-rankings.svelte create mode 100644 docs/src/lib/sports.remote.ts diff --git a/docs/src/examples/components/Image/college-football-upsets.svelte b/docs/src/examples/components/Image/college-football-upsets.svelte new file mode 100644 index 0000000000..5fc6ae6c5f --- /dev/null +++ b/docs/src/examples/components/Image/college-football-upsets.svelte @@ -0,0 +1,242 @@ + + + + + { + if (e.key === 'Shift') hideTooltip = true; + }} + onkeyup={(e) => { + if (e.key === 'Shift') hideTooltip = false; + }} + onblur={() => (hideTooltip = false)} +/> + +
+ data.season, + (v) => { + if (v !== data.season) season = v; + } + } + clearable={false} + toggleIcon={null} + stepper + /> +
+ {#each Object.values(styles) as style (style.label)} + + + {style.label} + + {/each} + {upsetCount} upsets +
+
+ + + {#snippet children({ context })} + {@const highlightId = context.tooltip.data?.game.id} + + + + `#${d}`} /> + + {#each cells as cell (cell.game.id + cell.team.id)} + {@const x = context.xScale(cell.week) ?? 0} + {@const y = context.yScale(cell.rank)} + {@const style = cellStyle(cell)} + + + + + + {/each} + + + {#if !hideTooltip} + + {#snippet children({ data: cell })} + {@const result = cell.team.result} + +
+ + {cell.team.name} (#{cell.rank}) +
+
+ +
+ {#if result} + + {result} + + {cell.team.score}-{cell.opponent.score} + {:else} + {cell.game.status} + {/if} + vs + + {cell.opponent.abbreviation} + {cell.opponent.rank ? `(#${cell.opponent.rank})` : ''} +
+ {#if cell.upset} +
+ Upset +
+ {/if} +
+
+ Hold Shift to hide tooltip +
+ {/snippet} +
+ {/if} + {/snippet} +
diff --git a/docs/src/examples/components/LineChart/bump-sports-rankings.svelte b/docs/src/examples/components/LineChart/bump-sports-rankings.svelte new file mode 100644 index 0000000000..0ff034dd4c --- /dev/null +++ b/docs/src/examples/components/LineChart/bump-sports-rankings.svelte @@ -0,0 +1,308 @@ + + + + + { + if (e.key === 'Shift') hideTooltip = true; + }} + onkeyup={(e) => { + if (e.key === 'Shift') hideTooltip = false; + }} + onblur={() => (hideTooltip = false)} +/> + +
+ sport, + (v) => { + sport = v; + season = undefined; + } + } + clearable={false} + toggleIcon={null} + stepper + /> + data.season, + (v) => { + if (v !== data.season) season = v; + } + } + clearable={false} + toggleIcon={null} + stepper + /> +
+ +
AP Top 25
+ + + {#snippet children({ context })} + {@const highlightId = context.tooltip.data?.teamId} + + + + + + + `#${d}`} /> + finalAbbreviations.get(d) ?? ''} + /> + + {#each teamsInDrawOrder(highlightId) as team (team.id)} + {@const segments = teamSegments(team.id)} + {@const ranks = segments.flat()} + + {#each segments as segment, i (i)} + + {/each} + + + + {/each} + + + {#if !hideTooltip} + + {#snippet children({ data: d })} + {@const team = teamsById.get(d.teamId)} + {@const gameWindow = pollWindow(d.week)} + {@const games = gameWindow + ? getTeamGames({ sport, season: data.season, teamId: d.teamId }) + : undefined} + +
+ + {team?.name} +
+
+ + + + {#if d.record} + + {/if} + + {#if gameWindow && games && !games.error} + + {#if games.current == null} + + {:else} + {#each gamesInWindow(games.current, gameWindow) as game (game.id)} +
+ {#if game.result} + + {game.result} + + {game.score}-{game.opponentScore} + {:else} + {game.status} + {/if} + {game.home || game.neutralSite ? 'vs' : '@'} + + {opponentLabel(game)} +
+ {:else} + + {/each} + {/if} + {/if} +
+
+ Hold Shift to hide tooltip +
+ {/snippet} +
+ {/if} + {/snippet} +
diff --git a/docs/src/examples/components/LineChart/bump-state-population-ranks.svelte b/docs/src/examples/components/LineChart/bump-state-population-ranks.svelte index 1b939639d3..2ce2921369 100644 --- a/docs/src/examples/components/LineChart/bump-state-population-ranks.svelte +++ b/docs/src/examples/components/LineChart/bump-state-population-ranks.svelte @@ -1,3 +1,7 @@ + +