Skip to content

fix: categorical color scale maps all categories to distinct colors#17

Open
yhaefligsib wants to merge 1 commit into
DessimozLab:masterfrom
yhaefligsib:master
Open

fix: categorical color scale maps all categories to distinct colors#17
yhaefligsib wants to merge 1 commit into
DessimozLab:masterfrom
yhaefligsib:master

Conversation

@yhaefligsib

Copy link
Copy Markdown

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'.

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>
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.

1 participant