Skip to content

Commit 7b61534

Browse files
authored
fix raster crash when colors are set by hand (identity scale) (#1237)
* fix raster crash when colors are set by hand (identity scale) * formatHex (hex is deprecated)
1 parent 395f571 commit 7b61534

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/marks/raster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export class Raster extends AbstractRaster {
9898
return super.scale(channels, scales, context);
9999
}
100100
render(index, scales, channels, dimensions, context) {
101-
const {color} = scales;
101+
const color = scales.color ?? ((x) => x);
102102
const {x: X, y: Y} = channels;
103103
const {document} = context;
104104
const [x1, y1, x2, y2] = renderBounds(channels, dimensions, context);

test/output/rasterCa55Color.svg

Lines changed: 19 additions & 0 deletions
Loading

test/plots/raster-ca55.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ export async function rasterCa55Nearest() {
3333
return rasterCa55({interpolate: "nearest"});
3434
}
3535

36+
export async function rasterCa55Color() {
37+
const ca55 = await d3.csv("data/ca55-south.csv", d3.autoType);
38+
const domain = {type: "MultiPoint", coordinates: ca55.map((d) => [d.GRID_EAST, d.GRID_NORTH])};
39+
return Plot.plot({
40+
width: 640,
41+
height: 484,
42+
projection: {type: "reflect-y", inset: 3, domain},
43+
marks: [
44+
Plot.raster(ca55, {
45+
x: "GRID_EAST",
46+
y: "GRID_NORTH",
47+
interpolate: "random-walk",
48+
fill: (d) => d3.hcl(d.MAG_IGRF90, 120, 80).formatHex()
49+
})
50+
]
51+
});
52+
}
53+
3654
export async function contourCa55() {
3755
return plotCa55((ca55) =>
3856
Plot.contour(ca55, {

0 commit comments

Comments
 (0)