top-level legend option, and better types #2249
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This introduces a new top-level legend option which is inherited by scales that support legends (color, symbol, and opacity). This makes it slightly more concise to enable legends, and takes us a step closer to enabling them automatically if desired. For example:
Note above that Plot is smart enough to realize that the symbol legend subsumes the color legend, and hence the color legend does not need to be displayed separately. Plot now suppresses the color legend automatically when the symbol legend also encodes color. You can force separate legends by using the stroke symbol legend option:
I considered the alternative below, which we could have display a colorless symbol legend and no color legend, but it would require more finagling to allow the symbol legend to read the color legend options; let me know if you prefer it:
I also wasn’t sure if we wanted a way to force the display of separate symbol and color legends, as this currently displays only a joint legend (which I think makes sense, since it’s equivalent to inheriting the top-level option):
Lastly, this fixes a types bug where legend options were not allowed on scale options. For example, setting the stroke symbol legend option previously errored with
Object literal may only specify known properties, and 'stroke' does not exist in type 'ScaleOptions'.
This also introduces more specific types for legend options for additional safety.