Skip to content

fix(color): ensure createLinearScale always returns a color for null/NaN input#38631

Draft
rebenitez1802 wants to merge 1 commit intomasterfrom
rebenitez1802/fix/sequential-scale-always-return-color
Draft

fix(color): ensure createLinearScale always returns a color for null/NaN input#38631
rebenitez1802 wants to merge 1 commit intomasterfrom
rebenitez1802/fix/sequential-scale-always-return-color

Conversation

@rebenitez1802
Copy link
Contributor

SUMMARY

SequentialScheme.createLinearScale() returns a d3 scaleLinear that returns undefined for null, undefined, and NaN inputs. This causes missing fill colors in charts when metric values are nullable.

This fix uses d3's built-in .unknown() method to set a fallback color (this.colors[0]) so the scale always returns a valid color string. This fixes the issue upstream rather than requiring every caller to add ?? fallback guards.

Affected plugins (7 callers of createLinearScale):

Plugin Had its own guard?
WorldMap Yes (??)
CountryMap Yes (?? + fallback fn)
Calendar Yes (fallback fn)
Sunburst No — likely had same bug
ParallelCoordinates Partial
DeckGL Heatmap Indirect
DeckGL utils No

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — behavioral fix, no UI changes.

TESTING INSTRUCTIONS

  1. Create a World Map chart with sequential (metric-based) coloring
  2. Include data where some country metric values are NULL
  3. Verify all countries render with a valid fill color (previously some appeared without fill)
  4. Run npm run test -- --testPathPatterns="SequentialScheme" — 3 new tests for null/NaN/undefined
  5. Run npm run test -- --testPathPatterns="WorldMap" — 3 new end-to-end tests

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Related: #38602 (WorldMap-specific fix with caller-side guard)

🤖 Generated with Claude Code

…NaN input

d3's scaleLinear returns undefined for null, undefined, and NaN inputs
by default. This sets .unknown(this.colors[0]) on the scale so it
always returns a valid color string, fixing issues across all plugins
that use sequential color scales with nullable metric values.

Adds tests for null/NaN/undefined inputs in SequentialScheme and
an end-to-end test in WorldMap proving the fix works without
caller-side guards.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rebenitez1802 rebenitez1802 force-pushed the rebenitez1802/fix/sequential-scale-always-return-color branch from 2afb23d to 0e5c67b Compare March 13, 2026 16:55
@pull-request-size pull-request-size bot added size/S and removed size/M labels Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant