include LegendOptions (e.g., className, fontSize, r…) in the type for scales#2175
include LegendOptions (e.g., className, fontSize, r…) in the type for scales#2175
Conversation
mbostock
left a comment
There was a problem hiding this comment.
This seems right, but it also seems a little dangerous to mix the legend options into the scale options. Maybe we could do it more like the tip mark option, where instead of legend: true you could pass legend: options?
Plot.plot({
color: {
type: "ordinal",
scheme: "rainbow",
legend: {
className: "legend",
style: {fontSize: "16px"}
}
},
style: {fontSize: "7px"},
marks: [Plot.cell("ABCDEFGHIJ", {x: Plot.identity, fill: Plot.identity})]
})We would then change ScaleDefaults from:
legend?: LegendOptions["legend"] | boolean | null;to:
legend?: LegendOptions | LegendOptions["legend"] | boolean | null;It’d probably be safe to just make this change, but we could also be conservative and continue supporting the undocumented way of mixing legend options into scale options if desired.
There was a problem hiding this comment.
This was also superseded by #2249, which included type declarations for legend options within scale options. Note that we only want legend options for scales that can have legends, which is currently the color, opacity, and symbol scales; if other scales support legends in the future (such as r #236) then we can add those types as appropriate then.
There does seem to be a bug in the current implementation in that ColorLegendOptions only includes the options that are specific to color legends and does not include the generic LegendOptions. That’s because LegendOptions extends ColorLegendOptions rather than the other way around.
Generic legend options (`label`, `tickFormat`, `fontVariant`, `style`, `className`) were only declared on LegendOptions, which extends ColorLegendOptions. This meant passing `style` or `className` inside scale options was a type error. Instead we introduce `BaseLegendOptions` and have each specific legend type extend it. Fixes #2175
|
superseded by #2421 |
No description provided.