Skip to content

Unify group, bin, and reduce. #272

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

Merged
merged 48 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
8ae6d9b
checkpoint new group
mbostock Mar 25, 2021
82f9457
group boxplot!
mbostock Mar 25, 2021
4dad4a0
check for value-less reduce
mbostock Mar 25, 2021
73fcb93
update example
mbostock Mar 25, 2021
e578c54
require reduce
mbostock Mar 25, 2021
a81ac42
don’t compute z twice
mbostock Mar 25, 2021
75e0b87
reorder
mbostock Mar 25, 2021
c2f3af6
missing imports
mbostock Mar 25, 2021
b80380e
bin groups
mbostock Mar 25, 2021
f0dff40
fix reducer test
Fil Mar 25, 2021
1978ee7
half-fix plots that need default {x: count} or {fill: count}
Fil Mar 25, 2021
99de814
fix plots (reduce => group)
Fil Mar 25, 2021
43fbf3a
firstof {z, fill, stroke}
mbostock Mar 25, 2021
73fcb56
reduce proportion
mbostock Mar 25, 2021
ffd3b47
maybeGroup
mbostock Mar 25, 2021
7203487
reduce percent
mbostock Mar 25, 2021
6cf3fc4
fix value-less reducers
mbostock Mar 25, 2021
4bcfb86
remove unused import
mbostock Mar 25, 2021
16ed1e0
update tests
mbostock Mar 25, 2021
b66c361
more tests
mbostock Mar 25, 2021
d7dc200
smarter facet axis position
mbostock Mar 25, 2021
c12160f
percent-z, percent-facet
mbostock Mar 25, 2021
cfd94fa
generalize normalize
mbostock Mar 25, 2021
e66e141
add test output
mbostock Mar 25, 2021
6353dd2
normalize
mbostock Mar 25, 2021
5a09d11
proportional reducers
mbostock Mar 26, 2021
2b7bb68
allow external scoped reducers
mbostock Mar 26, 2021
cb03034
bad vscode
mbostock Mar 26, 2021
a717b7c
require group channels
mbostock Mar 26, 2021
cbfbdf8
bin outputs
mbostock Mar 26, 2021
ed98699
fix inset
mbostock Mar 26, 2021
5c97c25
cumulative bins
mbostock Mar 26, 2021
7bcff91
reorder export
mbostock Mar 26, 2021
1213979
no insets for binMid
mbostock Mar 26, 2021
4f0ed81
restore labels
mbostock Mar 26, 2021
e37b196
reverse cumulative
mbostock Mar 26, 2021
8bdfcd7
fix secondary group dimension
mbostock Mar 26, 2021
c3e05c5
proportion-group
mbostock Mar 26, 2021
d9ad9fa
fix tests
mbostock Mar 26, 2021
779fa07
apply maybeReduce to data channel
mbostock Mar 27, 2021
aa785ba
remove noop
mbostock Mar 27, 2021
4bcabf0
shorten
mbostock Mar 27, 2021
1f70b72
binned replaces input
mbostock Mar 27, 2021
0e144f8
don’t subgroup if output
mbostock Mar 27, 2021
7e52ab6
restore test
mbostock Mar 27, 2021
f08e17f
scale percent
mbostock Mar 27, 2021
b3fc587
rm proportion-group
mbostock Mar 28, 2021
5251f50
update snapshot
mbostock Mar 28, 2021
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
19 changes: 10 additions & 9 deletions src/axes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ export function Axes(
let {axis: yAxis = true} = y;
let {axis: fxAxis = true} = fx;
let {axis: fyAxis = true} = fy;
if (xAxis === true) xAxis = "bottom";
if (yAxis === true) yAxis = "left";
if (fxAxis === true) fxAxis = xAxis === "bottom" ? "top" : "bottom";
if (fyAxis === true) fyAxis = yAxis === "left" ? "right" : "left";
if (!xScale) xAxis = null; else if (xAxis === true) xAxis = "bottom";
if (!yScale) yAxis = null; else if (yAxis === true) yAxis = "left";
if (!fxScale) fxAxis = null; else if (fxAxis === true) fxAxis = xAxis === "bottom" ? "top" : "bottom";
if (!fyScale) fyAxis = null; else if (fyAxis === true) fyAxis = yAxis === "left" ? "right" : "left";
return {
...xScale && xAxis && {x: new AxisX({grid, ...x, axis: xAxis})},
...yScale && yAxis && {y: new AxisY({grid, ...y, axis: yAxis})},
...fxScale && fxAxis && {fx: new AxisX({name: "fx", grid: facetGrid, ...fx, axis: fxAxis})},
...fyScale && fyAxis && {fy: new AxisY({name: "fy", grid: facetGrid, ...fy, axis: fyAxis})}
...xAxis && {x: new AxisX({grid, ...x, axis: xAxis})},
...yAxis && {y: new AxisY({grid, ...y, axis: yAxis})},
...fxAxis && {fx: new AxisX({name: "fx", grid: facetGrid, ...fx, axis: fxAxis})},
...fyAxis && {fy: new AxisY({name: "fy", grid: facetGrid, ...fy, axis: fyAxis})}
};
}

Expand Down Expand Up @@ -102,10 +102,11 @@ function inferLabel(channels = [], scale, axis, key) {
else if (candidate !== label) return;
}
if (candidate !== undefined) {
const {invert} = scale;
const {percent, invert} = scale;
// Ignore the implicit label for temporal scales if it’s simply “date”.
if (scale.type === "temporal" && /^(date|time|year)$/i.test(candidate)) return;
if (scale.type !== "ordinal" && (key === "x" || key === "y")) {
if (percent) candidate = `${candidate} (%)`;
if (axis.labelAnchor === "center") {
candidate = `${candidate} →`;
} else if (key === "x") {
Expand Down
2 changes: 1 addition & 1 deletion src/facet.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Facet extends Mark {
}
const named = Object.create(null);
for (const [name, channel] of channels) {
if (name !== undefined) named[name] = channel.value;
if (name !== undefined) Object.defineProperty(named, name, {get: () => channel.value}); // scale transform
subchannels.push([undefined, channel]);
}
marksChannels.push(named);
Expand Down
5 changes: 2 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ export {Rect, rect, rectX, rectY} from "./marks/rect.js";
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 {bin, binMid, binX, binY, binXMid, binYMid} from "./transforms/bin.js";
export {group, groupX, groupY, groupZ} 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";
export {windowX, windowY} from "./transforms/window.js";
export {selectFirst, selectLast, selectMaxX, selectMaxY, selectMinX, selectMinY} from "./transforms/select.js";
export {stackX, stackX1, stackX2, stackXMid, stackY, stackY1, stackY2, stackYMid} from "./transforms/stack.js";
6 changes: 2 additions & 4 deletions src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ export function plot(options = {}) {
const {scale} = channel;
if (scale !== undefined) {
const scaled = scaleChannels.get(scale);
const {transform} = options[scale] || {};
if (transform !== undefined) {
channel.value = Array.from(channel.value, transform);
}
const {percent, transform = percent ? x => x * 100 : undefined} = options[scale] || {};
if (transform !== undefined) channel.value = Array.from(channel.value, transform);
if (scaled) scaled.push(channel);
else scaleChannels.set(scale, [channel]);
}
Expand Down
3 changes: 2 additions & 1 deletion src/scales/quantitative.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function ScaleQ(key, scale, channels, {
clamp,
zero,
domain = (registry.get(key) === radius ? inferRadialDomain : inferDomain)(channels),
percent,
round,
range = registry.get(key) === radius ? inferRadialRange(channels, domain) : undefined,
scheme,
Expand Down Expand Up @@ -167,7 +168,7 @@ export function ScaleQ(key, scale, channels, {

if (range !== undefined) scale.range(range);
if (clamp) scale.clamp(clamp);
return {type: "quantitative", invert, domain, range, scale, inset};
return {type: "quantitative", invert, domain, range, scale, inset, percent};
}

export function ScaleLinear(key, channels, options) {
Expand Down
Loading