Skip to content

Commit

Permalink
remove transform marks (observablehq#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Mar 10, 2021
1 parent fd08c0c commit 9772c7e
Show file tree
Hide file tree
Showing 25 changed files with 48 additions and 88 deletions.
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.binRectY(data, {x: "Volume"}),
Plot.rectY(data, Plot.binX({x: "Volume"})),
Plot.ruleY([0]) // add a rule at y = 0
]
})
Expand Down
7 changes: 2 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ 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 {binDot, 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 {groupCell, groupDot, 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 {bin, binX, binY, binR} from "./transforms/bin.js";
export {group, groupX, groupY} from "./transforms/group.js";
export {bin, binX, binY, binR, binFill} from "./transforms/bin.js";
export {group, groupX, groupY, groupR, groupFill} from "./transforms/group.js";
export {normalizeX, normalizeY} from "./transforms/normalize.js";
export {movingAverageX, movingAverageY} from "./transforms/movingAverage.js";
export {selectFirst, selectLast, selectMaxX, selectMaxY, selectMinX, selectMinY} from "./transforms/select.js";
Expand Down
19 changes: 0 additions & 19 deletions src/marks/bin.js

This file was deleted.

20 changes: 0 additions & 20 deletions src/marks/group.js

This file was deleted.

19 changes: 0 additions & 19 deletions src/marks/stack.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/transforms/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export function binR({x, y, ...options} = {}) {
return {x: mid(x1, x2), y: mid(y1, y2), r, ...transform, z, fill, stroke};
}

export function binFill(options) {
return bin({...options, out: "fill"});
}

export function bin({x, y, insetLeft = 1, insetTop = 1, out, ...options} = {}) {
const [transform, x1, x2, y1, y2, l, z, fill, stroke] = bin2(x, y, options);
return {x1, x2, y1, y2, ...transform, z, fill, stroke, insetLeft, insetTop, [out]: l};
Expand Down
8 changes: 8 additions & 0 deletions src/transforms/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ export function groupY({y, ...options} = {}) {
return {y: Y, x, ...transform, z, fill, stroke};
}

export function groupR(options) {
return group({...options, out: "r"});
}

export function groupFill(options) {
return group({...options, out: "fill"});
}

export function group({x, y, out, ...options} = {}) {
const [transform, X, Y, L, z, fill, stroke] = group2(x, y, options);
return {x: X, y: Y, ...transform, z, fill, stroke, [out]: L};
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.binRectY(data, {x: d => Math.log10(d.Volume), normalize: true}),
Plot.rectY(data, Plot.binX({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 @@ -16,7 +16,7 @@ export default async function() {
domain: [0, 100]
},
marks: [
Plot.binDot(data, {x: "carat", y: "price", thresholds: 100})
Plot.dot(data, Plot.binR({x: "carat", y: "price", thresholds: 100}))
]
});
}
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.binRect(data, {x: "carat", y: "price", thresholds: 100})
Plot.rect(data, Plot.binFill({x: "carat", y: "price", thresholds: 100}))
]
});
}
4 changes: 2 additions & 2 deletions test/plots/industry-unemployment-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export default async function() {
tickFormat: "%"
},
marks: [
Plot.stackAreaY(data, {
Plot.areaY(data, Plot.stackY({
x: "date",
y: "unemployed",
fill: "industry",
offset: "expand",
title: "industry"
}),
})),
Plot.ruleY([0])
]
});
Expand Down
4 changes: 2 additions & 2 deletions test/plots/industry-unemployment-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export default async function() {
axis: null
},
marks: [
Plot.stackAreaY(data, {
Plot.areaY(data, Plot.stackY({
x: "date",
y: "unemployed",
fill: "industry",
title: "industry",
offset: "wiggle"
})
}))
]
});
}
7 changes: 6 additions & 1 deletion test/plots/industry-unemployment.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export default async function() {
grid: true
},
marks: [
Plot.stackAreaY(data, {x: "date", y: "unemployed", fill: "industry", title: "industry"}),
Plot.areaY(data, Plot.stackY({
x: "date",
y: "unemployed",
fill: "industry",
title: "industry"
})),
Plot.ruleY([0])
]
});
Expand Down
4 changes: 2 additions & 2 deletions test/plots/learning-poverty.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export default async function() {
range: ["#aed9e0", "#edd382", "#ffa69e"]
},
marks: [
Plot.stackBarX(values, {
Plot.barX(values, Plot.stackX({
x: d => (d.type === "ok" ? -1 : 1) * d.share, // diverging bars
y: "Country Name",
fill: "type"
}),
})),
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.groupBarY(letters, {x: uppers}),
Plot.barY(letters, Plot.groupX({x: uppers})),
Plot.ruleY([0])
]
});
Expand Down
5 changes: 2 additions & 3 deletions test/plots/moby-dick-letter-frequency.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ import * as d3 from "d3";

export default async function() {
const mobydick = await d3.text("data/moby-dick-chapter-1.txt");
const letters = [...mobydick].filter(c => /[a-z]/i.test(c)).map(c => c.toUpperCase());
return Plot.plot({
y: {
grid: true
},
marks: [
Plot.groupBarY([...mobydick]
.filter(c => /[a-z]/i.test(c))
.map(c => c.toUpperCase())),
Plot.barY(letters, Plot.groupX()),
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.groupCell(positions, {insetTop: 1, insetLeft: 1})
Plot.cell(positions, Plot.groupFill({insetTop: 1, insetLeft: 1}))
]
});
}
2 changes: 1 addition & 1 deletion test/plots/music-revenue.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default async function() {
transform: d => d / 1000
},
marks: [
Plot.stackAreaY(data, {...stack, fill: "group", title: d => `${d.format}\n${d.group}`}),
Plot.areaY(data, Plot.stackY({...stack, fill: "group", title: d => `${d.format}\n${d.group}`})),
Plot.lineY(data, Plot.stackY2({...stack, stroke: "white", strokeWidth: 1})),
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.binRectY(data, {x: "body_mass_g"}),
Plot.rectY(data, Plot.binX({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.binRectY(data, {x: "body_mass_g"}),
Plot.rectY(data, Plot.binX({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.binRectY(data, {x: "body_mass_g"}),
Plot.rectY(data, Plot.binX({x: "body_mass_g"})),
Plot.ruleY([0])
]
});
Expand Down
4 changes: 2 additions & 2 deletions test/plots/police-deaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export default async function() {
axis: null
},
marks: [
Plot.stackAreaY(data, {
Plot.areaY(data, Plot.stackY({
...stack,
curve: curveLinkHorizontal,
fill: "race",
stroke: "white"
}),
})),
Plot.text(
data.filter(d => d.type === "police"),
Plot.stackYMid({
Expand Down
7 changes: 6 additions & 1 deletion test/plots/stacked-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export default async function() {
tickFormat: "%"
},
marks: [
Plot.stackBarX({length: 20}, {x: (d, i) => i, fill: (d, i) => i, insetLeft: 1, offset: "expand"})
Plot.barX({length: 20}, Plot.stackX({
x: (d, i) => i,
fill: (d, i) => i,
insetLeft: 1,
offset: "expand"
}))
]
});
}
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.binRectY({length: 10000}, {x: () => random() - random(), normalize: true}),
Plot.rectY({length: 10000}, Plot.binX({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.groupBarY(words, {x: d => d.length, normalize: true})
Plot.barY(words, Plot.groupX({x: d => d.length, normalize: true}))
]
});
}

0 comments on commit 9772c7e

Please sign in to comment.