Skip to content

groupX becomes groupY; removes groupZX et al. #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export {RuleX, RuleY, ruleX, ruleY} from "./marks/rule.js";
export {Text, text, textX, textY} from "./marks/text.js";
export {TickX, TickY, tickX, tickY} from "./marks/tick.js";
export {bin, binX, binY, binXMid, binYMid, binR} from "./transforms/bin.js";
export {group, groupX, groupY, groupR, groupZ, groupZX, groupZY, groupZR} from "./transforms/group.js";
export {group, groupX, groupY, groupR} from "./transforms/group.js";
export {normalizeX, normalizeY} from "./transforms/normalize.js";
export {map, mapX, mapY} from "./transforms/map.js";
export {reduce, reduceX, reduceY} from "./transforms/reduce.js";
Expand Down
10 changes: 6 additions & 4 deletions src/transforms/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import {offset} from "../style.js";
import {groups} from "./group.js";

// Group on y, z, fill, or stroke, if any, then bin on x.
export function binX({x, y, out = y == null ? "y" : "fill", inset, insetLeft, insetRight, ...options} = {}) {
export function binY({x, y, out = y == null ? "y" : "fill", inset, insetLeft, insetRight, ...options} = {}) {
([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight));
const [transform, x1, x2, l] = bin1(x, "y", {y, ...options});
return {x1, x2, ...transform, inset, insetLeft, insetRight, [out]: l};
}

// Group on y, z, fill, or stroke, if any, then bin on x.
export function binXMid({x, out = "r", ...options} = {}) {
export function binYMid({x, out = "r", ...options} = {}) {
const [transform, x1, x2, l] = bin1(x, "y", options);
return {x: mid(x1, x2), ...transform, [out]: l};
}

// Group on x, z, fill, or stroke, if any, then bin on y.
export function binY({y, x, out = x == null ? "x" : "fill", inset, insetTop, insetBottom, ...options} = {}) {
export function binX({y, x, out = x == null ? "x" : "fill", inset, insetTop, insetBottom, ...options} = {}) {
([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom));
const [transform, y1, y2, l] = bin1(y, "x", {x, ...options});
return {y1, y2, ...transform, inset, insetTop, insetBottom, [out]: l};
}

// Group on y, z, fill, or stroke, if any, then bin on x.
export function binYMid({y, out = "r", ...options} = {}) {
export function binXMid({y, out = "r", ...options} = {}) {
const [transform, y1, y2, l] = bin1(y, "x", options);
return {y: mid(y1, y2), ...transform, [out]: l};
}
Expand All @@ -38,6 +38,8 @@ export function binR({x, y, ...options} = {}) {

// Group on z, fill, or stroke, if any, then bin on x and y.
export function bin({x, y, out = "fill", inset, insetTop, insetRight, insetBottom, insetLeft, ...options} = {}) {
if (!x) return binX({y, out, inset, insetTop, insetRight, insetBottom, insetLeft, ...options});
if (!y) return binY({x, out, inset, insetTop, insetRight, insetBottom, insetLeft, ...options});
([insetTop, insetBottom] = maybeInset(inset, insetTop, insetBottom));
([insetLeft, insetRight] = maybeInset(inset, insetLeft, insetRight));
const [transform, x1, x2, y1, y2, l] = bin2(x, y, options);
Expand Down
22 changes: 2 additions & 20 deletions src/transforms/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,14 @@ import {group as grouper, sort, sum, InternSet} from "d3";
import {defined, firstof} from "../defined.js";
import {valueof, maybeColor, maybeTransform, maybeValue, maybeLazyChannel, lazyChannel, first, identity, take, maybeTuple, labelof} from "../mark.js";

// Group on {z, fill, stroke}.
export function groupZ({out = "fill", ...options} = {}) {
const [transform, L] = group2(null, null, options);
return {...transform, [out]: L};
}

export function groupZX(options) {
return groupZ({...options, out: "x"});
}

export function groupZY(options) {
return groupZ({...options, out: "y"});
}

export function groupZR(options) {
return groupZ({...options, out: "r"});
}

// Group on {z, fill, stroke}, then on x (optionally).
export function groupX({x = identity, out = "y", ...options} = {}) {
export function groupY({x = identity, out = "y", ...options} = {}) {
const [transform, L, X] = group2(x, null, options);
return {...transform, x: X, [out]: L};
}

// Group on {z, fill, stroke}, then on y (optionally).
export function groupY({y = identity, out = "x", ...options} = {}) {
export function groupX({y = identity, out = "x", ...options} = {}) {
const [transform, L,, Y] = group2(null, y, options);
return {...transform, y: Y, [out]: L};
}
Expand Down
1,184 changes: 592 additions & 592 deletions test/output/athletesWeight.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion test/plots/aapl-volume.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function() {
grid: true
},
marks: [
Plot.rectY(data, Plot.binX({x: d => Math.log10(d.Volume), normalize: true})),
Plot.rectY(data, Plot.binY({x: d => Math.log10(d.Volume), normalize: true})),
Plot.ruleY([0])
]
});
Expand Down
14 changes: 13 additions & 1 deletion test/plots/athletes-weight.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@ export default async function() {
x: {
grid: true
},
y: {
label: "sport"
},
color: {
scheme: "YlGnBu",
zero: true
},
marks: [
Plot.barX(athletes, Plot.binX({x: "weight", y: "sport", thresholds: 60, normalize: "z", out: "fill"}))
Plot.barX(athletes, {
...Plot.bin({
x: "weight",
y: null,
z: "sport",
thresholds: 60,
normalize: "z"
}),
y: ([d]) => d["sport"]
})
]
});
}
2 changes: 1 addition & 1 deletion test/plots/fruit-sales.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function() {
label: null
},
marks: [
Plot.barX(sales, Plot.groupY({y: "fruit", weight: "units"})),
Plot.barX(sales, Plot.groupX({y: "fruit", weight: "units"})),
Plot.ruleX([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/moby-dick-faceted.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function() {
y: cases
},
marks: [
Plot.barY(letters, Plot.groupX({x: uppers})),
Plot.barY(letters, Plot.groupY({x: uppers})),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/moby-dick-letter-frequency.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default async function() {
grid: true
},
marks: [
Plot.barY(letters, Plot.groupX()),
Plot.barY(letters, Plot.groupY()),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/penguin-mass-sex-species.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default async function() {
marginRight: 70
},
marks: [
Plot.rectY(data, Plot.binX({x: "body_mass_g"})),
Plot.rectY(data, Plot.binY({x: "body_mass_g"})),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/penguin-mass-sex.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function() {
marginRight: 70
},
marks: [
Plot.rectY(data, Plot.binX({x: "body_mass_g"})),
Plot.rectY(data, Plot.binY({x: "body_mass_g"})),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/penguin-mass-species.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function() {
grid: true
},
marks: [
Plot.rectY(data, Plot.stackY(Plot.binX({x: "body_mass_g", fill: "species"}))),
Plot.rectY(data, Plot.stackY(Plot.binY({x: "body_mass_g", fill: "species"}))),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/penguin-mass.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function() {
grid: true
},
marks: [
Plot.rectY(data, Plot.binX({x: "body_mass_g"})),
Plot.rectY(data, Plot.binY({x: "body_mass_g"})),
Plot.ruleY([0])
]
});
Expand Down
4 changes: 2 additions & 2 deletions test/plots/penguin-species-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export default async function() {
const penguins = await d3.csv("data/penguins.csv", d3.autoType);
return Plot.plot({
marks: [
Plot.barX(penguins, Plot.stackX(Plot.groupZX({fill: "species", normalize: true}))),
Plot.text(penguins, Plot.stackXMid(Plot.groupZX({z: "species", normalize: true, text: ([d]) => d.species}))),
Plot.barX(penguins, Plot.stackX(Plot.groupX({y: null, fill: "species", normalize: true}))),
Plot.text(penguins, Plot.stackXMid(Plot.groupX({y: null, z: "species", normalize: true, text: ([d]) => d.species}))),
Plot.ruleX([0, 100])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/penguin-species-island.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function() {
grid: true
},
marks: [
Plot.barY(data, Plot.stackY(Plot.groupX({x: "species", fill: "island"}))),
Plot.barY(data, Plot.stackY(Plot.groupY({x: "species", fill: "island"}))),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/uniform-random-difference.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default async function() {
grid: true
},
marks: [
Plot.rectY({length: 10000}, Plot.binX({x: () => random() - random(), normalize: true})),
Plot.rectY({length: 10000}, Plot.binY({x: () => random() - random(), normalize: true})),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/word-length-moby-dick.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function() {
grid: true
},
marks: [
Plot.barY(words, Plot.groupX({x: d => d.length, normalize: true}))
Plot.barY(words, Plot.groupY({x: d => d.length, normalize: true}))
]
});
}