Skip to content

Commit 70bb3c6

Browse files
authored
fix quantized ordinal color schemes (#638)
* fix burd and buylrd with n=2 * fix quantized ordinal schemes
1 parent edee778 commit 70bb3c6

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/scales/schemes.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,33 +143,33 @@ const ordinalSchemes = new Map([
143143

144144
function scheme9(scheme, interpolate) {
145145
return ({length: n}) => {
146-
n = n > 3 ? Math.floor(n) : 3;
146+
n = Math.max(3, Math.floor(n));
147147
return n > 9 ? quantize(interpolate, n) : scheme[n];
148148
};
149149
}
150150

151151
function scheme11(scheme, interpolate) {
152152
return ({length: n}) => {
153153
if (n === 2) return [scheme[3][0], scheme[3][2]]; // favor diverging extrema
154-
n = n > 3 ? Math.floor(n) : 3;
154+
n = Math.max(3, Math.floor(n));
155155
return n > 11 ? quantize(interpolate, n) : scheme[n];
156156
};
157157
}
158158

159159
function scheme11r(scheme, interpolate) {
160160
return ({length: n}) => {
161-
if (n === 2) return [scheme[3][0], scheme[3][2]]; // favor diverging extrema
162-
n = n > 3 ? Math.floor(n) : 3;
161+
if (n === 2) return [scheme[3][2], scheme[3][0]]; // favor diverging extrema
162+
n = Math.max(3, Math.floor(n));
163163
return n > 11 ? quantize(t => interpolate(1 - t), n) : scheme[n].slice().reverse();
164164
};
165165
}
166166

167167
function schemei(interpolate) {
168-
return ({length: n}) => quantize(interpolate, n > 0 ? Math.floor(n) : 0);
168+
return ({length: n}) => quantize(interpolate, Math.max(2, Math.floor(n)));
169169
}
170170

171171
function schemeicyclical(interpolate) {
172-
return ({length: n}) => quantize(interpolate, n > 0 ? Math.floor(n) + 1 : 1).slice(0, -1);
172+
return ({length: n}) => quantize(interpolate, Math.floor(n) + 1).slice(0, -1);
173173
}
174174

175175
export function ordinalScheme(scheme) {

test/output/colorSchemesOrdinal.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3295,7 +3295,7 @@
32953295
align-items: center;
32963296
margin-right: 1em;
32973297
}
3298-
</style><span class="plot-97-swatch" style="--color: #ef8a62;">burd</span><span class="plot-97-swatch" style="--color: #67a9cf;">1</span>
3298+
</style><span class="plot-97-swatch" style="--color: #67a9cf;">burd</span><span class="plot-97-swatch" style="--color: #ef8a62;">1</span>
32993299
</div>
33003300
<div class="plot-98" style="
33013301
--swatchWidth: 15px;
@@ -3465,7 +3465,7 @@
34653465
align-items: center;
34663466
margin-right: 1em;
34673467
}
3468-
</style><span class="plot-102-swatch" style="--color: #fc8d59;">buylrd</span><span class="plot-102-swatch" style="--color: #91bfdb;">1</span>
3468+
</style><span class="plot-102-swatch" style="--color: #91bfdb;">buylrd</span><span class="plot-102-swatch" style="--color: #fc8d59;">1</span>
34693469
</div>
34703470
<div class="plot-103" style="
34713471
--swatchWidth: 15px;
@@ -4621,7 +4621,7 @@
46214621
align-items: center;
46224622
margin-right: 1em;
46234623
}
4624-
</style><span class="plot-136-swatch" style="--color: rgb(NaN, NaN, NaN);">turbo</span>
4624+
</style><span class="plot-136-swatch" style="--color: rgb(35, 23, 27);">turbo</span>
46254625
</div>
46264626
<div class="plot-137" style="
46274627
--swatchWidth: 15px;
@@ -4791,7 +4791,7 @@
47914791
align-items: center;
47924792
margin-right: 1em;
47934793
}
4794-
</style><span class="plot-141-swatch">viridis</span>
4794+
</style><span class="plot-141-swatch" style="--color: #440154;">viridis</span>
47954795
</div>
47964796
<div class="plot-142" style="
47974797
--swatchWidth: 15px;
@@ -4961,7 +4961,7 @@
49614961
align-items: center;
49624962
margin-right: 1em;
49634963
}
4964-
</style><span class="plot-146-swatch">magma</span>
4964+
</style><span class="plot-146-swatch" style="--color: #000004;">magma</span>
49654965
</div>
49664966
<div class="plot-147" style="
49674967
--swatchWidth: 15px;
@@ -5131,7 +5131,7 @@
51315131
align-items: center;
51325132
margin-right: 1em;
51335133
}
5134-
</style><span class="plot-151-swatch">inferno</span>
5134+
</style><span class="plot-151-swatch" style="--color: #000004;">inferno</span>
51355135
</div>
51365136
<div class="plot-152" style="
51375137
--swatchWidth: 15px;
@@ -5301,7 +5301,7 @@
53015301
align-items: center;
53025302
margin-right: 1em;
53035303
}
5304-
</style><span class="plot-156-swatch">plasma</span>
5304+
</style><span class="plot-156-swatch" style="--color: #0d0887;">plasma</span>
53055305
</div>
53065306
<div class="plot-157" style="
53075307
--swatchWidth: 15px;
@@ -5471,7 +5471,7 @@
54715471
align-items: center;
54725472
margin-right: 1em;
54735473
}
5474-
</style><span class="plot-161-swatch" style="--color: rgb(NaN, NaN, NaN);">cividis</span>
5474+
</style><span class="plot-161-swatch" style="--color: rgb(0, 32, 81);">cividis</span>
54755475
</div>
54765476
<div class="plot-162" style="
54775477
--swatchWidth: 15px;
@@ -5811,7 +5811,7 @@
58115811
align-items: center;
58125812
margin-right: 1em;
58135813
}
5814-
</style><span class="plot-171-swatch" style="--color: rgb(0, 0, 0);">warm</span>
5814+
</style><span class="plot-171-swatch" style="--color: rgb(110, 64, 170);">warm</span>
58155815
</div>
58165816
<div class="plot-172" style="
58175817
--swatchWidth: 15px;
@@ -5981,7 +5981,7 @@
59815981
align-items: center;
59825982
margin-right: 1em;
59835983
}
5984-
</style><span class="plot-176-swatch" style="--color: rgb(0, 0, 0);">cool</span>
5984+
</style><span class="plot-176-swatch" style="--color: rgb(110, 64, 170);">cool</span>
59855985
</div>
59865986
<div class="plot-177" style="
59875987
--swatchWidth: 15px;

0 commit comments

Comments
 (0)