Skip to content

Commit c92b022

Browse files
committed
fix for scheme + range
1 parent 73a5782 commit c92b022

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/scales/quantitative.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export function ScaleQ(key, scale, channels, {
5555
round,
5656
range = registry.get(key) === radius ? inferRadialRange(channels, domain) : registry.get(key) === opacity ? unit : undefined,
5757
type,
58-
scheme = type === "cyclical" ? "rainbow" : "turbo",
59-
interpolate = registry.get(key) === color ? (range !== undefined ? interpolateRgb : quantitativeScheme(scheme)) : round ? interpolateRound : interpolateNumber,
58+
scheme,
59+
interpolate = registry.get(key) === color ? (scheme == null && range !== undefined ? interpolateRgb : quantitativeScheme(scheme !== undefined ? scheme : type === "cyclical" ? "rainbow" : "turbo")) : round ? interpolateRound : interpolateNumber,
6060
reverse,
6161
inset = 0
6262
}) {

test/scales/scales-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,32 @@ it("plot(…).scale(name) reflects the given custom interpolator", async () => {
11801180
});
11811181
});
11821182

1183+
it("plot(…).scale('color') allows a range to be specified in conjunction with a scheme", async () => {
1184+
const gistemp = await d3.csv("data/gistemp.csv", d3.autoType);
1185+
const plot = Plot.dot(gistemp, {x: "Date", fill: "Anomaly"}).plot({color: {range: [0, 0.5], scheme: "cool"}});
1186+
assert.deepStrictEqual(plot.scale("color"), {
1187+
type: "linear",
1188+
domain: [-0.78, 1.35],
1189+
range: [0, 0.5],
1190+
interpolate: d3.interpolateCool,
1191+
clamp: false,
1192+
label: "Anomaly"
1193+
});
1194+
});
1195+
1196+
it("plot(…).scale('color') allows a range to be specified in conjunction with a single-argument interpolator", async () => {
1197+
const gistemp = await d3.csv("data/gistemp.csv", d3.autoType);
1198+
const plot = Plot.dot(gistemp, {x: "Date", fill: "Anomaly"}).plot({color: {range: [0, 0.5], interpolate: d3.interpolateCool}});
1199+
assert.deepStrictEqual(plot.scale("color"), {
1200+
type: "linear",
1201+
domain: [-0.78, 1.35],
1202+
range: [0, 0.5],
1203+
interpolate: d3.interpolateCool,
1204+
clamp: false,
1205+
label: "Anomaly"
1206+
});
1207+
});
1208+
11831209
it("plot(…).scale('color') promotes the given scheme option to an interpolator for quantitative scales", () => {
11841210
assert.strictEqual(Plot.dotX([], {fill: "x"}).plot().scale("color").interpolate, d3.interpolateTurbo);
11851211
assert.strictEqual(Plot.dotX([], {fill: "x"}).plot({color: {scheme: "warm"}}).scale("color").interpolate, d3.interpolateWarm);

0 commit comments

Comments
 (0)