diff --git a/src/index.js b/src/index.js index 5f646f3628..283568e6b3 100644 --- a/src/index.js +++ b/src/index.js @@ -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"; diff --git a/src/transforms/bin.js b/src/transforms/bin.js index 0c1a11b070..b7d6395831 100644 --- a/src/transforms/bin.js +++ b/src/transforms/bin.js @@ -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}; } @@ -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); diff --git a/src/transforms/group.js b/src/transforms/group.js index 5f89f41ff0..352b67ac69 100644 --- a/src/transforms/group.js +++ b/src/transforms/group.js @@ -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}; } diff --git a/test/output/athletesWeight.svg b/test/output/athletesWeight.svg index 7a04a6d9b6..46c6f6c084 100644 --- a/test/output/athletesWeight.svg +++ b/test/output/athletesWeight.svg @@ -113,6 +113,80 @@ weight → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -172,6 +246,143 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -202,221 +413,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -443,145 +439,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -614,28 +521,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -661,6 +546,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -680,197 +611,68 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -897,6 +699,98 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -921,30 +815,136 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/plots/aapl-volume.js b/test/plots/aapl-volume.js index e3c48ef90f..79bea5d073 100644 --- a/test/plots/aapl-volume.js +++ b/test/plots/aapl-volume.js @@ -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]) ] }); diff --git a/test/plots/athletes-weight.js b/test/plots/athletes-weight.js index 176c9b81c5..54a1ea506d 100644 --- a/test/plots/athletes-weight.js +++ b/test/plots/athletes-weight.js @@ -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"] + }) ] }); } diff --git a/test/plots/fruit-sales.js b/test/plots/fruit-sales.js index 56139f3efa..2c7317f48f 100644 --- a/test/plots/fruit-sales.js +++ b/test/plots/fruit-sales.js @@ -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]) ] }); diff --git a/test/plots/moby-dick-faceted.js b/test/plots/moby-dick-faceted.js index 489790ff44..56730fd469 100644 --- a/test/plots/moby-dick-faceted.js +++ b/test/plots/moby-dick-faceted.js @@ -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]) ] }); diff --git a/test/plots/moby-dick-letter-frequency.js b/test/plots/moby-dick-letter-frequency.js index a531036f2b..970f37595e 100644 --- a/test/plots/moby-dick-letter-frequency.js +++ b/test/plots/moby-dick-letter-frequency.js @@ -9,7 +9,7 @@ export default async function() { grid: true }, marks: [ - Plot.barY(letters, Plot.groupX()), + Plot.barY(letters, Plot.groupY()), Plot.ruleY([0]) ] }); diff --git a/test/plots/penguin-mass-sex-species.js b/test/plots/penguin-mass-sex-species.js index 8627b3c789..f861848119 100644 --- a/test/plots/penguin-mass-sex-species.js +++ b/test/plots/penguin-mass-sex-species.js @@ -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]) ] }); diff --git a/test/plots/penguin-mass-sex.js b/test/plots/penguin-mass-sex.js index ac225aa47b..b650a99ae5 100644 --- a/test/plots/penguin-mass-sex.js +++ b/test/plots/penguin-mass-sex.js @@ -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]) ] }); diff --git a/test/plots/penguin-mass-species.js b/test/plots/penguin-mass-species.js index 8d822f8103..75d7ef8341 100644 --- a/test/plots/penguin-mass-species.js +++ b/test/plots/penguin-mass-species.js @@ -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]) ] }); diff --git a/test/plots/penguin-mass.js b/test/plots/penguin-mass.js index 831d9749a7..ae1d3d5342 100644 --- a/test/plots/penguin-mass.js +++ b/test/plots/penguin-mass.js @@ -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]) ] }); diff --git a/test/plots/penguin-species-group.js b/test/plots/penguin-species-group.js index f915e9b7d9..1ddf44063e 100644 --- a/test/plots/penguin-species-group.js +++ b/test/plots/penguin-species-group.js @@ -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]) ] }); diff --git a/test/plots/penguin-species-island.js b/test/plots/penguin-species-island.js index d06d3bb097..77cebb7de8 100644 --- a/test/plots/penguin-species-island.js +++ b/test/plots/penguin-species-island.js @@ -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]) ] }); diff --git a/test/plots/uniform-random-difference.js b/test/plots/uniform-random-difference.js index fb719734d9..e93fb60c37 100644 --- a/test/plots/uniform-random-difference.js +++ b/test/plots/uniform-random-difference.js @@ -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]) ] }); diff --git a/test/plots/word-length-moby-dick.js b/test/plots/word-length-moby-dick.js index 9eaf23e7ae..151845bb69 100644 --- a/test/plots/word-length-moby-dick.js +++ b/test/plots/word-length-moby-dick.js @@ -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})) ] }); }