Skip to content

Commit 70e99dd

Browse files
committed
rename transforms
1 parent 890e727 commit 70e99dd

17 files changed

+47
-48
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ It’s not just line charts, of course. Here’s another useful chart type, the
120120
Plot.plot({
121121
height: 240,
122122
marks: [
123-
Plot.binX(data, {x: "Volume"}),
123+
Plot.binRectY(data, {x: "Volume"}),
124124
Plot.ruleY([0]) // add a rule at y = 0
125125
]
126126
})

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ export {plot} from "./plot.js";
22
export {Mark} from "./mark.js";
33
export {Area, area, areaX, areaY} from "./marks/area.js";
44
export {BarX, BarY, barX, barY} from "./marks/bar.js";
5-
export {bin, binX, binY} from "./marks/bin.js";
5+
export {binRect, binRectX, binRectY} from "./marks/bin.js";
66
export {Cell, cell, cellX, cellY} from "./marks/cell.js";
77
export {Dot, dot, dotX, dotY} from "./marks/dot.js";
88
export {Frame, frame} from "./marks/frame.js";
9-
export {group, groupX, groupY} from "./marks/group.js";
9+
export {groupCell, groupBarX, groupBarY} from "./marks/group.js";
1010
export {Line, line, lineX, lineY} from "./marks/line.js";
1111
export {Link, link} from "./marks/link.js";
1212
export {Rect, rect, rectX, rectY} from "./marks/rect.js";
1313
export {RuleX, RuleY, ruleX, ruleY} from "./marks/rule.js";
1414
export {stackAreaX, stackAreaY, stackBarX, stackBarY} from "./marks/stack.js";
1515
export {Text, text, textX, textY} from "./marks/text.js";
1616
export {TickX, TickY, tickX, tickY} from "./marks/tick.js";
17-
export {bin1, bin2} from "./transforms/bin.js";
18-
export {group1, group2} from "./transforms/group.js";
17+
export {bin} from "./transforms/bin.js";
18+
export {group} from "./transforms/group.js";
1919
export {stackX, stackY} from "./transforms/stack.js";

src/marks/bin.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {arrayify, identity, maybeLabel} from "../mark.js";
2-
import {bin1, bin2} from "../transforms/bin.js";
2+
import {bin} from "../transforms/bin.js";
33
import {rect, rectX, rectY} from "./rect.js";
44

5-
export function bin(data, {x, y, domain, thresholds, normalize, transform, ...options} = {}) {
5+
export function binRect(data, {x, y, domain, thresholds, normalize, transform, ...options} = {}) {
66
data = arrayify(data);
77
if (transform !== undefined) data = arrayify(transform(data));
88
return rect(
@@ -11,7 +11,7 @@ export function bin(data, {x, y, domain, thresholds, normalize, transform, ...op
1111
insetTop: 1,
1212
insetLeft: 1,
1313
...options,
14-
transform: bin2({x, y, domain, thresholds}),
14+
transform: bin({x, y, domain, thresholds}),
1515
fill: normalize ? normalizer(normalize, data.length) : length,
1616
x1: maybeLabel(x0, x),
1717
x2: x1,
@@ -21,7 +21,7 @@ export function bin(data, {x, y, domain, thresholds, normalize, transform, ...op
2121
);
2222
}
2323

24-
export function binX(data, {
24+
export function binRectY(data, {
2525
x = identity,
2626
domain,
2727
thresholds,
@@ -37,15 +37,15 @@ export function binX(data, {
3737
{
3838
insetLeft: 1,
3939
...options,
40-
transform: bin1({value: x, domain, thresholds, cumulative}),
40+
transform: bin({x, domain, thresholds, cumulative}),
4141
y: normalize ? normalizer(normalize, data.length) : length,
4242
x1: maybeLabel(x0, x),
4343
x2: x1
4444
}
4545
);
4646
}
4747

48-
export function binY(data, {
48+
export function binRectX(data, {
4949
y = identity,
5050
domain,
5151
thresholds,
@@ -61,7 +61,7 @@ export function binY(data, {
6161
{
6262
insetTop: 1,
6363
...options,
64-
transform: bin1({value: y, domain, thresholds, cumulative}),
64+
transform: bin({x: y, domain, thresholds, cumulative}),
6565
x: normalize ? normalizer(normalize, data.length) : length,
6666
y1: maybeLabel(x0, y),
6767
y2: x1

src/marks/group.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {arrayify, identity, first, second, maybeLabel, maybeZero} from "../mark.js";
2-
import {group1, group2} from "../transforms/group.js";
2+
import {group} from "../transforms/group.js";
33
import {barX, barY} from "./bar.js";
44
import {cell} from "./cell.js";
55

6-
export function group(data, {
6+
export function groupCell(data, {
77
x = first,
88
y = second,
99
transform,
@@ -14,15 +14,15 @@ export function group(data, {
1414
data,
1515
{
1616
...options,
17-
transform: group2(x, y),
17+
transform: group(x, y),
1818
x: maybeLabel(first, x),
1919
y: maybeLabel(second, y),
2020
fill: length3
2121
}
2222
);
2323
}
2424

25-
export function groupX(data, {
25+
export function groupBarY(data, {
2626
x = identity,
2727
y,
2828
y1,
@@ -37,15 +37,15 @@ export function groupX(data, {
3737
data,
3838
{
3939
...options,
40-
transform: group1(x),
40+
transform: group(x),
4141
x: maybeLabel(first, x),
4242
y1,
4343
y2
4444
}
4545
);
4646
}
4747

48-
export function groupY(data, {
48+
export function groupBarX(data, {
4949
y = identity,
5050
x,
5151
x1,
@@ -60,7 +60,7 @@ export function groupY(data, {
6060
data,
6161
{
6262
...options,
63-
transform: group1(y),
63+
transform: group(y),
6464
x1,
6565
x2,
6666
y: maybeLabel(first, y)

src/transforms/bin.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import {bin as binner, cross} from "d3-array";
2-
import {valueof, first, second, maybeValue, range, offsetRange} from "../mark.js";
2+
import {valueof, first, second, maybeValue, range, offsetRange, identity} from "../mark.js";
33

4-
export function bin1(options = {}) {
5-
let {value, domain, thresholds, cumulative} = maybeValue(options);
6-
const bin = binof({value, domain, thresholds});
7-
return (data, facets) => rebin(bin(data), facets, subset1, cumulative);
8-
}
9-
10-
export function bin2({x = {}, y = {}, domain, thresholds} = {}) {
4+
export function bin(options = {}) {
5+
if (options.y === undefined) {
6+
const {x = {}, domain, thresholds, cumulative} = options;
7+
const bin = binof({domain, thresholds, value: identity, ...maybeValue(x)});
8+
return (data, facets) => rebin(bin(data), facets, subset1, cumulative);
9+
}
10+
const {x = {}, y, domain, thresholds} = options;
1111
const binX = binof({domain, thresholds, value: first, ...maybeValue(x)});
1212
const binY = binof({domain, thresholds, value: second, ...maybeValue(y)});
1313
return (data, facets) => rebin(

src/transforms/group.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import {groups} from "d3-array";
22
import {defined} from "../defined.js";
33
import {valueof, maybeValue, range, offsetRange} from "../mark.js";
44

5-
export function group1(x) {
6-
const {value} = maybeValue({value: x});
7-
return (data, facets) => {
8-
const values = valueof(data, value);
9-
let g = groups(range(data), i => values[i]).filter(defined1);
10-
return regroup(g, facets);
11-
};
12-
}
13-
14-
export function group2(vx, vy) {
5+
export function group(vx, vy) {
6+
if (vy === undefined) {
7+
const {value} = maybeValue({value: vx});
8+
return (data, facets) => {
9+
const values = valueof(data, value);
10+
let g = groups(range(data), i => values[i]).filter(defined1);
11+
return regroup(g, facets);
12+
};
13+
}
1514
const {value: x} = maybeValue({value: vx});
1615
const {value: y} = maybeValue({value: vy});
1716
return (data, facets) => {

test/plots/aapl-volume.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.binX(data, {x: d => Math.log10(d.Volume), normalize: true}),
15+
Plot.binRectY(data, {x: d => Math.log10(d.Volume), normalize: true}),
1616
Plot.ruleY([0])
1717
]
1818
});

test/plots/diamonds-carat-price-dots.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async function() {
1717
},
1818
marks: [
1919
Plot.dot(data, {
20-
transform: Plot.bin2({x: "carat", y: "price", thresholds: 100}),
20+
transform: Plot.bin({x: "carat", y: "price", thresholds: 100}),
2121
x: d => (d.x0 + d.x1) / 2,
2222
y: d => (d.y0 + d.y1) / 2,
2323
r: "length"

test/plots/diamonds-carat-price.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function() {
1010
type: "symlog"
1111
},
1212
marks: [
13-
Plot.bin(data, {x: "carat", y: "price", thresholds: 100})
13+
Plot.binRect(data, {x: "carat", y: "price", thresholds: 100})
1414
]
1515
});
1616
}

test/plots/moby-dick-faceted.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default async function() {
1717
y: cases
1818
},
1919
marks: [
20-
Plot.groupX(letters, {x: uppers}),
20+
Plot.groupBarY(letters, {x: uppers}),
2121
Plot.ruleY([0])
2222
]
2323
});

test/plots/moby-dick-letter-frequency.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default async function() {
88
grid: true
99
},
1010
marks: [
11-
Plot.groupX([...mobydick]
11+
Plot.groupBarY([...mobydick]
1212
.filter(c => /[a-z]/i.test(c))
1313
.map(c => c.toUpperCase())),
1414
Plot.ruleY([0])

test/plots/moby-dick-letter-position.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default async function() {
3030
scheme: "blues"
3131
},
3232
marks: [
33-
Plot.group(positions, {insetTop: 1, insetLeft: 1})
33+
Plot.groupCell(positions, {insetTop: 1, insetLeft: 1})
3434
]
3535
});
3636
}

test/plots/penguin-mass-sex-species.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default async function() {
1515
marginRight: 70
1616
},
1717
marks: [
18-
Plot.binX(data, {x: "body_mass_g"}),
18+
Plot.binRectY(data, {x: "body_mass_g"}),
1919
Plot.ruleY([0])
2020
]
2121
});

test/plots/penguin-mass-sex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default async function() {
1414
marginRight: 70
1515
},
1616
marks: [
17-
Plot.binX(data, {x: "body_mass_g"}),
17+
Plot.binRectY(data, {x: "body_mass_g"}),
1818
Plot.ruleY([0])
1919
]
2020
});

test/plots/penguin-mass.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.binX(data, {x: "body_mass_g"}),
15+
Plot.binRectY(data, {x: "body_mass_g"}),
1616
Plot.ruleY([0])
1717
]
1818
});

test/plots/uniform-random-difference.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default async function() {
1313
grid: true
1414
},
1515
marks: [
16-
Plot.binX({length: 10000}, {x: () => random() - random(), normalize: true}),
16+
Plot.binRectY({length: 10000}, {x: () => random() - random(), normalize: true}),
1717
Plot.ruleY([0])
1818
]
1919
});

test/plots/word-length-moby-dick.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default async function() {
2020
grid: true
2121
},
2222
marks: [
23-
Plot.groupX(words, {x: d => d.length, normalize: true})
23+
Plot.groupBarY(words, {x: d => d.length, normalize: true})
2424
]
2525
});
2626
}

0 commit comments

Comments
 (0)