Skip to main content

Getting started

sdvplot-js draws team logos, headshots, team colours, playing surfaces (courts, rinks, fields) and styled tables for Observable Plot, D3 and React, with adapters for 20+ chart, map, grid and 3D libraries, from Chart.js, Plotly, Vega-Lite and ECharts to Recharts, MUI X, nivo, Svelte, deck.gl, MapLibre and Three.js. It is made of three packages.

Install​

pnpm add @sportsdataverse/sdvplot @sportsdataverse/sporty @sportsdataverse/sdvtables @observablehq/plot

Each adapter's library is an optional peer: install the one you draw with. Many adapters (Plotly, Vega-Lite, ECharts, uPlot, G2, MapLibre and others) import nothing from their library, and build options or specs for the copy you already load. The README's install table lists what each entry point needs. Keep @sportsdataverse/sporty in the install even if you draw no surface: sdvplot/plot, /d3, /shots, /chartjs/surface, /deckgl and /three import it when they load.

Entry points​

@sportsdataverse/sdvplot (logo, headshot and colour data per league)

  • @sportsdataverse/sdvplot: loadLeague, team lookup, colours, marks, tiers.
  • @sportsdataverse/sdvplot/plot: Observable Plot marks: logos, surface, teamColor, axisLogos, teamTiers.
  • @sportsdataverse/sdvplot/d3: D3 helpers.
  • @sportsdataverse/sdvplot/react: React components and hooks.
  • @sportsdataverse/sdvplot/bins: hexagon and square binning (hexbin, squarebin, binner) in the points' own units.
  • @sportsdataverse/sdvplot/shots: shot-chart numbers, bins and FG% against a league (binShots, cellsVsLeague, fgPctByDistance, signaturePoints) and the diffScale colours; it imports no Plot or d3.
  • @sportsdataverse/sdvplot/plotly, /vega, /echarts: spec adapters for Plotly, Vega-Lite and ECharts.
  • @sportsdataverse/sdvplot/chartjs and /chartjs/surface: Chart.js colours, image plugins and surfaces (in React, through react-chartjs-2).
  • @sportsdataverse/sdvplot/g2: G2 5 spec pieces (a team colour scale, logos as image marks, logos on a band axis), for G2 and for Ant Design Charts configs (see G2 and Ant Design Charts).
  • @sportsdataverse/sdvplot/recharts and /shadcn: Recharts render props (logos as ticks and points, team colours), and teamChartConfig, shadcn/ui's chart config for teams (see shadcn/ui charts).
  • @sportsdataverse/sdvplot/mui: MUI X Charts team colours (teamColors follows MUI's light and dark mode) and logo slots for a scatter's points, a line's marks and an axis' ticks (see MUI X Charts).
  • @sportsdataverse/sdvplot/tanstack: TanStack Charts team colours (the chart's color option) and logos as dots filled with SVG patterns, for its React, Svelte and DOM charts (see TanStack Charts).
  • @sportsdataverse/sdvplot/maplibre: MapLibre GL JS sources and layers, team logos at their venues and team-coloured travel lines, and a keyless OpenFreeMap basemap (see MapLibre GL JS).
  • @sportsdataverse/sdvplot/svelte: Svelte 5 components for LayerChart charts (LogoMark, HeadshotMark, SurfaceBackdrop) and teamColorPalette (see Svelte and LayerChart).
  • @sportsdataverse/sdvplot/nivo: nivo team colours, logoLayer (logos over a Bump, SwarmPlot or Chord) and logoNode (logos as nodes) (see nivo).
  • @sportsdataverse/sdvplot/victory: teamTheme and teamColorPalette for Victory charts; sdvplot/react's <LogoPoint> and <LogoTick> draw the logos (see Victory).
  • @sportsdataverse/sdvplot/uplot: withTeamSeries (series in team colours) and logoPlugin (logos painted on the canvas at data points) (see uPlot).
  • @sportsdataverse/sdvplot/lightweight-charts: teamSeriesOptions, logoMarkers, and TradingView's attribution through withAttribution and attributionNotice (see Lightweight Charts).
  • @sportsdataverse/sdvplot/deckgl: deck.gl layer props: logoIconLayer, passArcLayer in team colours and surfaceLayer, a sporty surface (see deck.gl).
  • @sportsdataverse/sdvplot/cytoscape: passNetwork, a passing network as Cytoscape elements and stylesheet, and teamStylesheet (see Cytoscape.js).
  • @sportsdataverse/sdvplot/three: mesh buffers for Three.js (surfaceMesh, trajectoryTube, statcastPitchPath); sdvplot/react's <Surface3D> and <Trajectory> draw them, on React 19 (see Three.js).
  • @sportsdataverse/sdvplot/unovis: Unovis accessor helpers: team colours for nodes, links and flows, and logos and headshots as a Graph's node icons, for @unovis/ts and @unovis/react (see Unovis).
  • @sportsdataverse/sdvplot/perspective: a Perspective viewer config with team colours in the Datagrid and in split charts and number formats, and a logo column, the same config sdvplot for Python builds (see Perspective).
  • @sportsdataverse/sdvplot/interact: linked figures and tables over one selection store (brushFilter, linkSelection, linkCursor, nearestHover, tooltip, highlight); see Linked figures and tables.
  • @sportsdataverse/sdvplot/export: Node only: toPNG (an SVG to a PNG, with @resvg/resvg-js) and socialCard (see Export to PNG).
  • @sportsdataverse/sdvplot/testing: the adapter contract suite.

@sportsdataverse/sporty (playing-surface geometry and data frames)

  • @sportsdataverse/sporty: surface, toSurfaceFrame, court/rink/field specs.
  • @sportsdataverse/sporty/svg: SVG output.
  • @sportsdataverse/sporty/specs: raw surface specifications.
  • @sportsdataverse/sporty/plot: Plot marks and scales for a surface.
  • @sportsdataverse/sporty/d3: D3 drawing helpers.
  • @sportsdataverse/sporty/canvas: drawing on a 2D canvas context.

@sportsdataverse/sdvtables (tables from a plain-data spec)

  • @sportsdataverse/sdvtables: defineTable, the column kinds, decorations and themes.
  • @sportsdataverse/sdvtables/html: renderHTML, renderHTMLAsync, prepare, toElement.
  • @sportsdataverse/sdvtables/react: <SdvTable> and useTable, a spec as a React table, static or interactive (see HTML, SSR and the host page).
  • @sportsdataverse/sdvtables/export: Node only: tableToPNG, htmlToPNG and page layouts (stackTables, gridTables, composePage, socialCrop) through Playwright (see Export to PNG).
  • @sportsdataverse/sdvtables/mui: dataGridProps, a spec as MUI X Data Grid props: formats, logo and headshot cells, team-coloured rows and the theme (see MUI X Data Grid).
  • @sportsdataverse/sdvtables/aggrid: gridOptions, a spec as AG Grid Community options: formats, sorting, logo and headshot cells, team-coloured rows and the theme (see AG Grid).
  • @sportsdataverse/sdvtables/tanstack-table: tanstackTable, a spec as TanStack Table v9 options for React, Svelte and the other adapters: labels, number text, sorting, row ids, and logo and headshot cells as data (see TanStack Table).

Node and SSR​

Everything also runs in Node. Plot needs a DOM document (from jsdom or linkedom); read the figure's SVG string:

310320330340350360370380390400410420430↑ pa300350400450500pf →
import * as Plot from "@observablehq/plot";
import { STANDINGS } from "@sportsdataverse/examples/data";
import { loadLeague } from "@sportsdataverse/sdvplot";
import { logos } from "@sportsdataverse/sdvplot/plot";
import { JSDOM } from "jsdom";

await loadLeague("nfl");
const { document } = new JSDOM("").window;
const svg: string = Plot.plot({
document,
marks: [logos(STANDINGS, { league: "nfl", x: "pf", y: "pa", team: "team", height: 0.1 })],
}).outerHTML;

svg;

Where next​