Skip to content

Commit 3e8b4c0

Browse files
Filmbostock
authored andcommitted
fix {reverse} for "threshold" and "quantile" scales.
It did not work, because: - scaleThreshold relies on an ascending domain (and breaks if it's not ascending); let's check for this situation and reverse the scale if the domain is descending - scaleQuantile ignores the domain order
1 parent 06688db commit 3e8b4c0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/scales/quantitative.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
ascending,
23
interpolateHcl,
34
interpolateHsl,
45
interpolateLab,
@@ -108,8 +109,10 @@ export function ScaleQuantile(key, channels, {
108109
scheme,
109110
domain = inferFullDomain(channels),
110111
range = ordinalScheme(scheme === undefined ? "rdylbu" : scheme)({length: quantiles}).slice(0, quantiles),
112+
reverse,
111113
...options
112114
}) {
115+
if (reverse) range = reverseof(range);
113116
return ScaleQ(key, scaleQuantile(), [], {domain, range, ...options});
114117
}
115118

@@ -121,8 +124,11 @@ export function ScaleThreshold(key, channels, {
121124
domain = inferDomain(channels),
122125
scheme,
123126
range = ordinalScheme(scheme === undefined ? "rdylbu" : scheme)({length: domain.length + 1}),
127+
reverse,
124128
...options
125129
}) {
130+
if (ascending(domain[domain.length-1], domain[0]) < 0) domain.sort(ascending), reverse = !reverse;
131+
if (reverse) range = reverseof(range);
126132
return ScaleQ(key, scaleThreshold(), channels, {domain, range, ...options});
127133
}
128134

0 commit comments

Comments
 (0)