Skip to main content

Function: withPatterns()

withPatterns<S, O>(renderSvg, ...sets): (scene, options) => string

Defined in: packages/sdvplot/src/tanstack.ts:346

TanStack's SVG serializer (renderChartSvg from @tanstack/charts/svg, or your own) with the dots' patterns written into the chart's SVG, in a <defs> of their own: pass the result as the chart's renderSvg (vanilla mountChart, React and Svelte <Chart>). Pattern ids are scoped by the chart's idPrefix, as TanStack scopes its gradients, and each dot's url(#...) follows. Build it once per set of dots (a module constant or useMemo).

Type Parameters​

S​

S

O​

O extends object

Parameters​

renderSvg​

(scene, options) => string

sets​

...readonly readonly TanstackImageDot<object, string, string>[][]

Returns​

(scene, options) => string

Example​

import { loadLeague } from "@sportsdataverse/sdvplot";
import { logoDots, withPatterns } from "@sportsdataverse/sdvplot/tanstack";

await loadLeague("nfl");
const logos = logoDots([{ team: "KC", pf: 385, pa: 326 }], { x: "pf", y: "pa", team: "team", league: "nfl" });
// renderChartSvg from "@tanstack/charts/svg"; here a stand-in that returns an empty chart
const renderChartSvg = (_scene: unknown, _o: { idPrefix?: string }) => '<svg class="ts-chart"></svg>';
withPatterns(renderChartSvg, logos)({}, { idPrefix: "epa" });