Skip to content

Commit 740605f

Browse files
committed
fix for truncated schemes
1 parent e458581 commit 740605f

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

src/legends/ramp.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {create, quantize, interpolateNumber, piecewise, format, scaleBand, scaleLinear, axisBottom} from "d3";
2+
import {interpolatePiecewise} from "../scales/quantitative.js";
23
import {applyInlineStyles, maybeClassName} from "../style.js";
34

45
export function legendRamp(color, {
@@ -59,9 +60,9 @@ export function legendRamp(color, {
5960
// Often interpolate is a “fixed” interpolator on the [0, 1] interval, as
6061
// with a built-in color scheme, but sometimes it is a function that takes
6162
// two arguments and is used in conjunction with the range.
62-
const interpolator = interpolate.length === 1
63-
? interpolate
64-
: piecewise(interpolate, range);
63+
const interpolator = range === undefined ? interpolate
64+
: piecewise(interpolate.length === 1 ? interpolatePiecewise(interpolate)
65+
: interpolate, range);
6566

6667
// Construct a D3 scale of the same type, but with a range that evenly
6768
// divides the horizontal extent of the legend. (In the common case, the
Lines changed: 37 additions & 0 deletions
Loading

test/plots/legend-color.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ export function colorLegendLinear() {
9898
return Plot.plot({color: {type: "linear", domain: [0, 10]}}).legend("color");
9999
}
100100

101+
export function colorLegendLinearTruncatedScheme() {
102+
return Plot.plot({color: {scheme: "rainbow", domain: [0, 1], range: [0.5, 1]}}).legend("color");
103+
}
104+
101105
export function colorLegendSqrt() {
102106
return Plot.plot({color: {type: "sqrt", domain: [0, 10]}}).legend("color");
103107
}

0 commit comments

Comments
 (0)