Function: logoPlugin()
logoPlugin(
rows,o):UPlotPlugin
Defined in: packages/sdvplot/src/uplot.ts:82
Team logos on a uPlot chart: a plugin whose draw hook paints each row's logo centred on its x / y (data units,
placed with uPlot's own valToPos), height of the plot area tall (a fraction, as in the spec adapters), over the
series. The images start loading when the chart starts (uPlot's init hook, before its first draw), and the
chart redraws as each one lands; building the plugin fetches nothing. A team with no logo draws nothing and warns
once, as sdvplot/echarts does; an image that fails to load is never drawn and warns once; a point outside the plot
area (after a zoom) is not drawn over the axes.
rows can also be a function of the chart, read at every draw: give it u.data and the logos follow live data
(u.setData(...)), such as a logo at each line's newest point.
Parameters
rows
readonly Row[] | ((u) => readonly Row[])
o
Returns
Example
import { loadLeague } from "@sportsdataverse/sdvplot";
import { logoPlugin } from "@sportsdataverse/sdvplot/uplot";
await loadLeague("nfl");
// the 2024 Chiefs and Bills: points for (x) against points against (y)
const rows = [
{ team: "KC", pf: 385, pa: 326 },
{ team: "BUF", pf: 525, pa: 368 },
];
const plugin = logoPlugin(rows, { x: "pf", y: "pa", team: "team", league: "nfl", height: 0.15 });
// in the browser: new uPlot({ width: 640, height: 320, series, plugins: [plugin] }, data, element)
Object.keys(plugin.hooks);