fix: categorical color scale maps all categories to distinct colors#17
Open
yhaefligsib wants to merge 1 commit into
Open
fix: categorical color scale maps all categories to distinct colors#17yhaefligsib wants to merge 1 commit into
yhaefligsib wants to merge 1 commit into
Conversation
Color_mapper had two bugs that caused categories beyond the midpoint of the domain to collapse to the same color: 1. this.scheme was stored as a d3.scaleSequential() object instead of a plain interpolator function. Wrapping a scale inside another scale in update() produced a compound mapping where the inner scale's compressed domain [0, 0.5] caused values to cycle and repeat colors. 2. update() passed a 3-element array to scaleSequential.domain(), but D3 v6 destructures only the first two elements ([x0, x1] = array), so the effective domain was [0, cpt/2] instead of [0, cpt]. Any category with a mapped value >= cpt/2 produced t > 1, which the interpolator clamps to its endpoint color — making those categories indistinguishable. Fix: store the raw interpolator in this.scheme and use a 2-element domain [0, this.cpt] so all categories are spread across the full color range. Also corrects scheme_name from 'Viridis' to 'Rainbow' to match the actual default interpolator and the name the color picker dropdown expects. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Fix for the issue with different categories using the same color coming from the d3 domain function taking only an array of 2 values (min, max) so ignoring the third parameter with total number and producing a range to half the size of cpt.
Also renamed the default scheme name to 'Rainbow' to correspond with the above d3.interpolateRainbow, or use d3.interpolateViridis if you prefer the default to be 'Viridis'.