fix(color): ensure createLinearScale always returns a color for null/NaN input#38631
Draft
rebenitez1802 wants to merge 1 commit intomasterfrom
Draft
fix(color): ensure createLinearScale always returns a color for null/NaN input#38631rebenitez1802 wants to merge 1 commit intomasterfrom
rebenitez1802 wants to merge 1 commit intomasterfrom
Conversation
9 tasks
…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>
2afb23d to
0e5c67b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SUMMARY
SequentialScheme.createLinearScale()returns a d3scaleLinearthat returnsundefinedfornull,undefined, andNaNinputs. 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?? fallbackguards.Affected plugins (7 callers of
createLinearScale):??)??+ fallback fn)BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — behavioral fix, no UI changes.
TESTING INSTRUCTIONS
NULLnpm run test -- --testPathPatterns="SequentialScheme"— 3 new tests for null/NaN/undefinednpm run test -- --testPathPatterns="WorldMap"— 3 new end-to-end testsADDITIONAL INFORMATION
Related: #38602 (WorldMap-specific fix with caller-side guard)
🤖 Generated with Claude Code