Skip to content

rename transforms #104

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 1 commit 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ It’s not just line charts, of course. Here’s another useful chart type, the
Plot.plot({
height: 240,
marks: [
Plot.binX(data, {x: "Volume"}),
Plot.binRectY(data, {x: "Volume"}),
Plot.ruleY([0]) // add a rule at y = 0
]
})
Expand Down
8 changes: 4 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ export {plot} from "./plot.js";
export {Mark} from "./mark.js";
export {Area, area, areaX, areaY} from "./marks/area.js";
export {BarX, BarY, barX, barY} from "./marks/bar.js";
export {bin, binX, binY} from "./marks/bin.js";
export {binRect, binRectX, binRectY} from "./marks/bin.js";
export {Cell, cell, cellX, cellY} from "./marks/cell.js";
export {Dot, dot, dotX, dotY} from "./marks/dot.js";
export {Frame, frame} from "./marks/frame.js";
export {group, groupX, groupY} from "./marks/group.js";
export {groupCell, groupBarX, groupBarY} from "./marks/group.js";
export {Line, line, lineX, lineY} from "./marks/line.js";
export {Link, link} from "./marks/link.js";
export {Rect, rect, rectX, rectY} from "./marks/rect.js";
export {RuleX, RuleY, ruleX, ruleY} from "./marks/rule.js";
export {stackAreaX, stackAreaY, stackBarX, stackBarY} from "./marks/stack.js";
export {Text, text, textX, textY} from "./marks/text.js";
export {TickX, TickY, tickX, tickY} from "./marks/tick.js";
export {bin1, bin2} from "./transforms/bin.js";
export {group1, group2} from "./transforms/group.js";
export {bin} from "./transforms/bin.js";
export {group} from "./transforms/group.js";
export {stackX, stackY} from "./transforms/stack.js";
14 changes: 7 additions & 7 deletions src/marks/bin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {arrayify, identity, maybeLabel} from "../mark.js";
import {bin1, bin2} from "../transforms/bin.js";
import {bin} from "../transforms/bin.js";
import {rect, rectX, rectY} from "./rect.js";

export function bin(data, {x, y, domain, thresholds, normalize, transform, ...options} = {}) {
export function binRect(data, {x, y, domain, thresholds, normalize, transform, ...options} = {}) {
data = arrayify(data);
if (transform !== undefined) data = arrayify(transform(data));
return rect(
Expand All @@ -11,7 +11,7 @@ export function bin(data, {x, y, domain, thresholds, normalize, transform, ...op
insetTop: 1,
insetLeft: 1,
...options,
transform: bin2({x, y, domain, thresholds}),
transform: bin({x, y, domain, thresholds}),
fill: normalize ? normalizer(normalize, data.length) : length,
x1: maybeLabel(x0, x),
x2: x1,
Expand All @@ -21,7 +21,7 @@ export function bin(data, {x, y, domain, thresholds, normalize, transform, ...op
);
}

export function binX(data, {
export function binRectY(data, {
x = identity,
domain,
thresholds,
Expand All @@ -37,15 +37,15 @@ export function binX(data, {
{
insetLeft: 1,
...options,
transform: bin1({value: x, domain, thresholds, cumulative}),
transform: bin({x, domain, thresholds, cumulative}),
y: normalize ? normalizer(normalize, data.length) : length,
x1: maybeLabel(x0, x),
x2: x1
}
);
}

export function binY(data, {
export function binRectX(data, {
y = identity,
domain,
thresholds,
Expand All @@ -61,7 +61,7 @@ export function binY(data, {
{
insetTop: 1,
...options,
transform: bin1({value: y, domain, thresholds, cumulative}),
transform: bin({x: y, domain, thresholds, cumulative}),
x: normalize ? normalizer(normalize, data.length) : length,
y1: maybeLabel(x0, y),
y2: x1
Expand Down
14 changes: 7 additions & 7 deletions src/marks/group.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {arrayify, identity, first, second, maybeLabel, maybeZero} from "../mark.js";
import {group1, group2} from "../transforms/group.js";
import {group} from "../transforms/group.js";
import {barX, barY} from "./bar.js";
import {cell} from "./cell.js";

export function group(data, {
export function groupCell(data, {
x = first,
y = second,
transform,
Expand All @@ -14,15 +14,15 @@ export function group(data, {
data,
{
...options,
transform: group2(x, y),
transform: group(x, y),
x: maybeLabel(first, x),
y: maybeLabel(second, y),
fill: length3
}
);
}

export function groupX(data, {
export function groupBarY(data, {
x = identity,
y,
y1,
Expand All @@ -37,15 +37,15 @@ export function groupX(data, {
data,
{
...options,
transform: group1(x),
transform: group(x),
x: maybeLabel(first, x),
y1,
y2
}
);
}

export function groupY(data, {
export function groupBarX(data, {
y = identity,
x,
x1,
Expand All @@ -60,7 +60,7 @@ export function groupY(data, {
data,
{
...options,
transform: group1(y),
transform: group(y),
x1,
x2,
y: maybeLabel(first, y)
Expand Down
16 changes: 8 additions & 8 deletions src/transforms/bin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {bin as binner, cross} from "d3-array";
import {valueof, first, second, maybeValue, range, offsetRange} from "../mark.js";
import {valueof, first, second, maybeValue, range, offsetRange, identity} from "../mark.js";

export function bin1(options = {}) {
let {value, domain, thresholds, cumulative} = maybeValue(options);
const bin = binof({value, domain, thresholds});
return (data, facets) => rebin(bin(data), facets, subset1, cumulative);
}

export function bin2({x = {}, y = {}, domain, thresholds} = {}) {
export function bin(options = {}) {
if (options.y === undefined) {
const {x = {}, domain, thresholds, cumulative} = options;
const bin = binof({domain, thresholds, value: identity, ...maybeValue(x)});
return (data, facets) => rebin(bin(data), facets, subset1, cumulative);
}
const {x = {}, y, domain, thresholds} = options;
const binX = binof({domain, thresholds, value: first, ...maybeValue(x)});
const binY = binof({domain, thresholds, value: second, ...maybeValue(y)});
return (data, facets) => rebin(
Expand Down
19 changes: 9 additions & 10 deletions src/transforms/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import {groups} from "d3-array";
import {defined} from "../defined.js";
import {valueof, maybeValue, range, offsetRange} from "../mark.js";

export function group1(x) {
const {value} = maybeValue({value: x});
return (data, facets) => {
const values = valueof(data, value);
let g = groups(range(data), i => values[i]).filter(defined1);
return regroup(g, facets);
};
}

export function group2(vx, vy) {
export function group(vx, vy) {
if (vy === undefined) {
const {value} = maybeValue({value: vx});
return (data, facets) => {
const values = valueof(data, value);
let g = groups(range(data), i => values[i]).filter(defined1);
return regroup(g, facets);
};
}
const {value: x} = maybeValue({value: vx});
const {value: y} = maybeValue({value: vy});
return (data, facets) => {
Expand Down
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.binX(data, {x: d => Math.log10(d.Volume), normalize: true}),
Plot.binRectY(data, {x: d => Math.log10(d.Volume), normalize: true}),
Plot.ruleY([0])
]
});
Expand Down
2 changes: 1 addition & 1 deletion test/plots/diamonds-carat-price-dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default async function() {
},
marks: [
Plot.dot(data, {
transform: Plot.bin2({x: "carat", y: "price", thresholds: 100}),
transform: Plot.bin({x: "carat", y: "price", thresholds: 100}),
x: d => (d.x0 + d.x1) / 2,
y: d => (d.y0 + d.y1) / 2,
r: "length"
Expand Down
2 changes: 1 addition & 1 deletion test/plots/diamonds-carat-price.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function() {
type: "symlog"
},
marks: [
Plot.bin(data, {x: "carat", y: "price", thresholds: 100})
Plot.binRect(data, {x: "carat", y: "price", thresholds: 100})
]
});
}
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.groupX(letters, {x: uppers}),
Plot.groupBarY(letters, {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 @@ -8,7 +8,7 @@ export default async function() {
grid: true
},
marks: [
Plot.groupX([...mobydick]
Plot.groupBarY([...mobydick]
.filter(c => /[a-z]/i.test(c))
.map(c => c.toUpperCase())),
Plot.ruleY([0])
Expand Down
2 changes: 1 addition & 1 deletion test/plots/moby-dick-letter-position.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function() {
scheme: "blues"
},
marks: [
Plot.group(positions, {insetTop: 1, insetLeft: 1})
Plot.groupCell(positions, {insetTop: 1, insetLeft: 1})
]
});
}
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.binX(data, {x: "body_mass_g"}),
Plot.binRectY(data, {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.binX(data, {x: "body_mass_g"}),
Plot.binRectY(data, {x: "body_mass_g"}),
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.binX(data, {x: "body_mass_g"}),
Plot.binRectY(data, {x: "body_mass_g"}),
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.binX({length: 10000}, {x: () => random() - random(), normalize: true}),
Plot.binRectY({length: 10000}, {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.groupX(words, {x: d => d.length, normalize: true})
Plot.groupBarY(words, {x: d => d.length, normalize: true})
]
});
}