-
Couldn't load subscription status.
- Fork 196
Description
sometimes it's better to create a standalone legend (with Plot.legend), not from any pre-existing plot, and use htl.html ... with css to organize better layout,
from https://observablehq.com/@observablehq/plot-legends?collection=@observablehq/plot I'm playing around a bit:
you see the sportsPlot (returned value from Plot.plot) is an HTMLElement with .scale and .legend
HTMLElement {scale: ƒ(e), legend: ƒ(n, r)}
but if I give it a name to wx = Plot.legend({...}) to whatever value returned from Plot.legend, it has nothing other than an empty SVGSVGElement {}
wx = Plot.legend({
color: {
// interpolate: (t) => wavelengthToColor(400 + t * 350),
domain: [400, 750]
},
width: 350,
ticks: 10,
label: "Wavelength (nm) →"
})then what's an easy way to get the scale object? and where to get d3-scale function from it?
I'm expecting it can have a way to return the scale object, something like sportsScale in the example,
> lgd.scale("color")
Object {
type: "ordinal",
domain: Array(4) ["A", "B", "H", "I", "J", ...],
range: Array(10) ["#1f77b4", "#ff7f0e", ...],
label: "...",
apply: ƒ(e),
}
current workaround may be to use fakePlot = Plot.plot(...) create a fake plot first, and get the scale object from ... = fakePlot.scale(...), and then the fakePlot is not needed and wasted

