Player trend explorer
The question: is a player trending up or down, and what did they do over a stretch you pick? Season averages hide form. A game-by-game line with a rolling average shows the streaks, and brushing a stretch of dates gives that window's averages, the numbers a fantasy manager or a beat writer wants.
The workflow: sportsdataverse-js reads ESPN's game log (sdv.nba.espnNbaPlayerGamelog({ athlete_id, season, parsed: true }) in Node; the same parser on the same JSON here). The parser gives one row per game: the season block (season_type_name), the event id and fourteen stats as stat_0 to stat_13. The rest is in the same response beside the rows: names says which stat is which (stat_13 is points), and events holds each game's date, opponent and result. The page joins the two on the event id, draws the chosen stat with sdvplot (the player's team colour and ESPN headshot), and links a 1-D brushFilter on the dates to an sdvtables table of the games.
The snapshot is LeBron James's 2023-24 game log (ESPN athlete 1966, season=2024): one capture shared with sdv-js's player form tutorial, byte for byte. Tick Fetch live from ESPN to load any NBA or WNBA player by ESPN athlete id (the number in an espn.com player URL); leave Season blank for ESPN's current one.
Drag across the chart to brush a stretch of games: the table keeps those games and the line under the table gives their averages. Click outside the brush to clear it.
What to take from it
- The rows are half the answer. sdv-js's game-log parser returns the stats as positional columns, because ESPN does:
namesbeside them says what each position means, andeventsholds the dates and opponents. Look a column up by name (stat_${names.indexOf("points")}), never by a hard-coded position. - "Regular Season" is ESPN's filing, not the league's. ESPN puts the All-Star Game and the in-season cup finals under "Regular Season". Dropping them turns the snapshot's 73 logged games into the 71 that count, 1,822 points (25.7 a game), LeBron James's official 2023-24 line.
- Brush, then summarise. A 1-D
brushFilteron the dates writes a row test to the store; the table applies it as it is, and the summary line reads the same test, so the window's averages always match the rows on screen.
Script it in Node: sdv-js's player form tutorial draws the same season as a static chart with meanLines and headshots. The Linked interactivity notebook covers brushFilter in depth.