Skip to content

Throw when color and symbol legend domains don't match - #2463

Open
RitiGrover wants to merge 1 commit into
observablehq:mainfrom
RitiGrover:fix-legend-symbol-color-domain-mismatch
Open

RitiGrover wants to merge 1 commit into
observablehq:mainfrom
RitiGrover:fix-legend-symbol-color-domain-mismatch

Conversation

@RitiGrover

Copy link
Copy Markdown

Summary

Closes #2384.

When Plot.legend builds a symbol legend with a stroke: "color" hint (i.e. both color and symbol scale options are passed), and the color scale's domain doesn't cover a value in the symbol domain, the stroke lookup silently resolves to undefined and the symbol renders with no stroke, with no indication of why.

This adds a check in legendSymbols (src/legends/swatches.js) that validates every value in the symbol domain resolves in the color scale before rendering, and throws the color and symbol scale domains must match if not, so the mismatch is caught immediately instead of producing an unstyled swatch.

Test plan

  • Added tests in test/legend-test.js:
    • mismatched domains throw the new error
    • matching domains still render the correct stroke colors
    • a color domain that's a superset of the symbol domain still works
    • a symbol legend with no color scale is unaffected
  • Confirmed the new test fails on main (no throw) and passes with the fix.
  • Ran vitest run test/legend-test.js and a broader --testNamePattern legend run; no other tests affected.
  • eslint and prettier --check pass on the changed files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plot.legend with different domains for color and symbol

1 participant