Skip to content

Commit 0efda2c

Browse files
committed
the bin transform should not consume {reverse} since it doesn't make use of it…
instead pass it up so we can stack the resulting bins in the desired order. solves https://stackoverflow.com/questions/68056843/in-observable-plot-how-to-sort-order-the-stack-from-a-bin-transform/68057660
1 parent 068f8d8 commit 0efda2c

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

src/transforms/bin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function binn(
5858
// Greedily materialize the z, fill, and stroke channels (if channels and not
5959
// constants) so that we can reference them for subdividing groups without
6060
// computing them more than once.
61-
const {x, y, z, fill, stroke, ...options} = inputs;
61+
const {x, y, z, fill, stroke, reverse, ...options} = inputs;
6262
const [GZ, setGZ] = maybeLazyChannel(z);
6363
const [vfill] = maybeColor(fill);
6464
const [vstroke] = maybeColor(stroke);
@@ -69,6 +69,7 @@ function binn(
6969
..."z" in inputs && {z: GZ || z},
7070
..."fill" in inputs && {fill: GF || fill},
7171
..."stroke" in inputs && {stroke: GS || stroke},
72+
..."reverse" in inputs && {reverse},
7273
...maybeTransform(options, (data, facets) => {
7374
const K = valueof(data, k);
7475
const Z = valueof(data, z);

test/output/penguinMassSpecies.svg

Lines changed: 5 additions & 5 deletions
Loading

test/plots/penguin-mass-species.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default async function() {
1212
grid: true
1313
},
1414
marks: [
15-
Plot.rectY(data, Plot.binX({y: "count"}, {x: "body_mass_g", fill: "species"})),
15+
Plot.rectY(data, Plot.binX({y: "count"}, {x: "body_mass_g", fill: "species", order: "value", reverse: true})),
1616
Plot.ruleY([0])
1717
]
1818
});

0 commit comments

Comments
 (0)