Skip to main content

Function: appendLegend()

appendLegend<D>(g, scale?, o?): number

Defined in: packages/sdvplot/src/d3/shots.ts:85

A diff-colour legend for d3 charts: gradient bar, ticks, caption, notes and an optional cell size key (blazing-the-nets main lib/charts/theme.ts:109-143, lib/charts/hexShotChart.ts:196-213). It replaces master's static PNG ramp (ShootingSignature/Legend.js:45-50, rgy5.png) with a gradient generated from the scale, whose id is a hash of its stops. Nothing is measured (text wraps at an estimated 6.2 px per character), so it renders the same in jsdom and SSR. Returns the height used. Plot users: Plot.legend({ color: scale.plot }).

Type Parameters​

D​

D

Parameters​

g​

G<D>

scale?​

DiffScale = ...

o?​

AppendLegendOptions = {}

Returns​

number

Example​

import { create } from "d3";
import { appendLegend } from "@sportsdataverse/sdvplot/d3";
import { diffScale } from "@sportsdataverse/sdvplot/shots";

const svg = create("svg").attr("viewBox", "0 0 300 80");
appendLegend(svg.append("g"), diffScale(), { width: 280 });
svg.node();