Skip to content

identity transform #262

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 4 commits into from
Mar 20, 2021
Merged
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 src/mark.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export function valueof(data, value, type) {

export const field = label => Object.assign(d => d[label], {label});
export const indexOf = (d, i) => i;
export const identity = d => d;
export const identity = {transform: d => d};
export const zero = () => 0;
export const string = x => x == null ? undefined : x + "";
export const number = x => x == null ? undefined : +x;
Expand Down
4 changes: 2 additions & 2 deletions test/marks/bar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tape("barX() has the expected defaults", test => {
test.strictEqual(bar.data, undefined);
test.strictEqual(bar.transform, undefined);
test.deepEqual(bar.channels.map(c => c.name), ["x1", "x2"]);
test.deepEqual(bar.channels.map(c => c.value(1, 0)), [0, 1]);
test.deepEqual(bar.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[0, 0, 0], [1, 2, 3]]);
test.deepEqual(bar.channels.map(c => c.scale), ["x", "x"]);
test.strictEqual(bar.fill, undefined);
test.strictEqual(bar.fillOpacity, undefined);
Expand Down Expand Up @@ -100,7 +100,7 @@ tape("barY() has the expected defaults", test => {
test.strictEqual(bar.data, undefined);
test.strictEqual(bar.transform, undefined);
test.deepEqual(bar.channels.map(c => c.name), ["y1", "y2"]);
test.deepEqual(bar.channels.map(c => c.value(1, 0)), [0, 1]);
test.deepEqual(bar.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[0, 0, 0], [1, 2, 3]]);
test.deepEqual(bar.channels.map(c => c.scale), ["y", "y"]);
test.strictEqual(bar.fill, undefined);
test.strictEqual(bar.fillOpacity, undefined);
Expand Down
6 changes: 3 additions & 3 deletions test/marks/cell-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tape("cell() has the expected defaults", test => {
test.strictEqual(cell.data, undefined);
test.strictEqual(cell.transform, undefined);
test.deepEqual(cell.channels.map(c => c.name), ["x", "y"]);
test.deepEqual(cell.channels.map(c => c.value([1, 2])), [1, 2]);
test.deepEqual(cell.channels.map(c => Plot.valueof([[1, 2], [3, 4]], c.value)), [[1, 3], [2, 4]]);
test.deepEqual(cell.channels.map(c => c.scale), ["x", "y"]);
test.strictEqual(cell.channels.find(c => c.name === "x").type, "band");
test.strictEqual(cell.channels.find(c => c.name === "y").type, "band");
Expand Down Expand Up @@ -81,7 +81,7 @@ tape("cellX() defaults x to identity and y to null", test => {
test.strictEqual(cell.data, undefined);
test.strictEqual(cell.transform, undefined);
test.deepEqual(cell.channels.map(c => c.name), ["x"]);
test.deepEqual(cell.channels.map(c => c.value("foo")), ["foo"]);
test.deepEqual(cell.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[1, 2, 3]]);
test.deepEqual(cell.channels.map(c => c.scale), ["x"]);
test.strictEqual(cell.channels.find(c => c.name === "x").type, "band");
});
Expand All @@ -91,7 +91,7 @@ tape("cellY() defaults y to identity and x to null", test => {
test.strictEqual(cell.data, undefined);
test.strictEqual(cell.transform, undefined);
test.deepEqual(cell.channels.map(c => c.name), ["y"]);
test.deepEqual(cell.channels.map(c => c.value("foo")), ["foo"]);
test.deepEqual(cell.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[1, 2, 3]]);
test.deepEqual(cell.channels.map(c => c.scale), ["y"]);
test.strictEqual(cell.channels.find(c => c.name === "y").type, "band");
});
2 changes: 1 addition & 1 deletion test/marks/dot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tape("dot() has the expected defaults", test => {
test.strictEqual(dot.data, undefined);
test.strictEqual(dot.transform, undefined);
test.deepEqual(dot.channels.map(c => c.name), ["x", "y"]);
test.deepEqual(dot.channels.map(c => c.value([1, 2])), [1, 2]);
test.deepEqual(dot.channels.map(c => Plot.valueof([[1, 2], [3, 4]], c.value)), [[1, 3], [2, 4]]);
test.deepEqual(dot.channels.map(c => c.scale), ["x", "y"]);
test.strictEqual(dot.r, 3);
test.strictEqual(dot.fill, "none");
Expand Down
2 changes: 1 addition & 1 deletion test/marks/line-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tape("line() has the expected defaults", test => {
test.strictEqual(line.data, undefined);
test.strictEqual(line.transform, undefined);
test.deepEqual(line.channels.map(c => c.name), ["x", "y"]);
test.deepEqual(line.channels.map(c => c.value([1, 2])), [1, 2]);
test.deepEqual(line.channels.map(c => Plot.valueof([[1, 2], [3, 4]], c.value)), [[1, 3], [2, 4]]);
test.deepEqual(line.channels.map(c => c.scale), ["x", "y"]);
test.strictEqual(line.curve, curveLinear);
test.strictEqual(line.fill, "none");
Expand Down
4 changes: 2 additions & 2 deletions test/marks/rule-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tape("ruleX() has the expected defaults", test => {
test.strictEqual(rule.data, undefined);
test.strictEqual(rule.transform, undefined);
test.deepEqual(rule.channels.map(c => c.name), ["x"]);
test.deepEqual(rule.channels.map(c => c.value("foo")), ["foo"]);
test.deepEqual(rule.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[1, 2, 3]]);
test.deepEqual(rule.channels.map(c => c.scale), ["x"]);
test.strictEqual(rule.fill, undefined);
test.strictEqual(rule.fillOpacity, undefined);
Expand Down Expand Up @@ -100,7 +100,7 @@ tape("ruleY() has the expected defaults", test => {
test.strictEqual(rule.data, undefined);
test.strictEqual(rule.transform, undefined);
test.deepEqual(rule.channels.map(c => c.name), ["y"]);
test.deepEqual(rule.channels.map(c => c.value("foo")), ["foo"]);
test.deepEqual(rule.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[1, 2, 3]]);
test.deepEqual(rule.channels.map(c => c.scale), ["y"]);
test.strictEqual(rule.fill, undefined);
test.strictEqual(rule.fillOpacity, undefined);
Expand Down
2 changes: 1 addition & 1 deletion test/marks/text-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tape("text() has the expected defaults", test => {
test.strictEqual(text.data, undefined);
test.strictEqual(text.transform, undefined);
test.deepEqual(text.channels.map(c => c.name), ["x", "y", "text"]);
test.deepEqual(text.channels.map(c => c.value([1, 2], 0)), [1, 2, 0]);
test.deepEqual(text.channels.map(c => Plot.valueof([[1, 2], [3, 4]], c.value)), [[1, 3], [2, 4], [0, 1]]);
test.deepEqual(text.channels.map(c => c.scale), ["x", "y", undefined]);
test.strictEqual(text.fill, undefined);
test.strictEqual(text.fillOpacity, undefined);
Expand Down
4 changes: 2 additions & 2 deletions test/marks/tick-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tape("tickX() has the expected defaults", test => {
test.strictEqual(tick.data, undefined);
test.strictEqual(tick.transform, undefined);
test.deepEqual(tick.channels.map(c => c.name), ["x"]);
test.deepEqual(tick.channels.map(c => c.value("foo", 0)), ["foo"]);
test.deepEqual(tick.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[1, 2, 3]]);
test.deepEqual(tick.channels.map(c => c.scale), ["x"]);
test.strictEqual(tick.fill, undefined);
test.strictEqual(tick.fillOpacity, undefined);
Expand Down Expand Up @@ -65,7 +65,7 @@ tape("tickY() has the expected defaults", test => {
test.strictEqual(tick.data, undefined);
test.strictEqual(tick.transform, undefined);
test.deepEqual(tick.channels.map(c => c.name), ["y"]);
test.deepEqual(tick.channels.map(c => c.value("foo", 0)), ["foo"]);
test.deepEqual(tick.channels.map(c => Plot.valueof([1, 2, 3], c.value)), [[1, 2, 3]]);
test.deepEqual(tick.channels.map(c => c.scale), ["y"]);
test.strictEqual(tick.fill, undefined);
test.strictEqual(tick.fillOpacity, undefined);
Expand Down