Skip to content

Commit 3cf7cdb

Browse files
authored
bugfix: Plot.cell respects dx, dy (#956)
* bugfix: Plot.cell respects dx, dy closes #955
1 parent e1dba89 commit 3cf7cdb

File tree

4 files changed

+168
-2
lines changed

4 files changed

+168
-2
lines changed

src/marks/cell.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {identity, indexOf, maybeColorChannel, maybeTuple} from "../options.js";
2+
import {applyTransform} from "../style.js";
23
import {AbstractBar} from "./bar.js";
34

45
const defaults = {
@@ -17,8 +18,9 @@ export class Cell extends AbstractBar {
1718
defaults
1819
);
1920
}
20-
_transform() {
21-
// noop
21+
_transform(selection, mark) {
22+
// apply dx, dy
23+
selection.call(applyTransform, mark, {}, 0, 0);
2224
}
2325
}
2426

test/output/gridChoroplethDx.svg

Lines changed: 124 additions & 0 deletions
Loading

test/plots/grid-choropleth-dx.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as Plot from "@observablehq/plot";
2+
import * as d3 from "d3";
3+
4+
export default async function() {
5+
const [grid, data] = await Promise.all([
6+
await d3.csv("data/us-state-grid.csv", d3.autoType).then(gridmap),
7+
await d3.csv("data/us-state-population-2010-2019.csv", d3.autoType)
8+
]);
9+
const states = data
10+
.filter(d => grid.has(d.State))
11+
.map(d => ({...d, ...grid.get(d.State)}));
12+
return Plot.plot({
13+
height: 420,
14+
x: {
15+
axis: null
16+
},
17+
y: {
18+
axis: null
19+
},
20+
color: {
21+
type: "diverging-log",
22+
scheme: "piyg"
23+
},
24+
marks: [
25+
Plot.cell(states, {x: "x", y: "y", fill: change, dx: -1.5, dy: -1.5}),
26+
Plot.cell(states, {x: "x", y: "y", stroke: "black", dx: 1.5, dy: 1.5}),
27+
Plot.text(states, {x: "x", y: "y", text: "key", dy: -6}),
28+
Plot.text(states, {x: "x", y: "y", text: (f => d => f(change(d) - 1))(d3.format("+.0%")), dy: 6, fillOpacity: 0.6})
29+
]
30+
});
31+
}
32+
33+
function gridmap(states) {
34+
return new Map(states.map(state => [state.name, state]));
35+
}
36+
37+
function change(d) {
38+
return d["2019"] / d["2010"];
39+
}

test/plots/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ export {default as gistempAnomalyTransform} from "./gistemp-anomaly-transform.js
8080
export {default as googleTrendsRidgeline} from "./google-trends-ridgeline.js";
8181
export {default as greekGods} from "./greek-gods.js";
8282
export {default as gridChoropleth} from "./grid-choropleth.js";
83+
export {default as gridChoroplethDx} from "./grid-choropleth-dx.js";
8384
export {default as groupedRects} from "./grouped-rects.js";
8485
export {default as hadcrutWarmingStripes} from "./hadcrut-warming-stripes.js";
8586
export {default as hexbin} from "./hexbin.js";

0 commit comments

Comments
 (0)