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 2 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
12 changes: 6 additions & 6 deletions test/marks/bar-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as Plot from "@observablehq/plot";
import tape from "tape-await";

tape("barX() has the expected defaults", test => {
const bar = Plot.barX();
test.strictEqual(bar.data, undefined);
const bar = Plot.barX([1, 2, 3]);
test.deepEqual(bar.data, [1, 2, 3]);
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.initialize().channels.map(d => d[1].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 @@ -96,11 +96,11 @@ tape("barX(data, {x, y}) defaults x1 to zero and x2 to x", test => {
});

tape("barY() has the expected defaults", test => {
const bar = Plot.barY();
test.strictEqual(bar.data, undefined);
const bar = Plot.barY([1, 2, 3]);
test.deepEqual(bar.data, [1, 2, 3]);
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.initialize().channels.map(d => d[1].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
18 changes: 9 additions & 9 deletions test/marks/cell-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as Plot from "@observablehq/plot";
import tape from "tape-await";

tape("cell() has the expected defaults", test => {
const cell = Plot.cell();
test.strictEqual(cell.data, undefined);
const cell = Plot.cell([[0, 1], [0, 2]]);
test.deepEqual(cell.data, [[0, 1], [0, 2]]);
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.initialize().channels.map(d => d[1].value), [[0, 0], [1, 2]]);
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 @@ -77,21 +77,21 @@ tape("cell(data, {stroke}) allows stroke to be a variable color", test => {
});

tape("cellX() defaults x to identity and y to null", test => {
const cell = Plot.cellX();
test.strictEqual(cell.data, undefined);
const cell = Plot.cellX([12]);
test.deepEqual(cell.data, [12]);
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.initialize().channels.map(d => d[1].value), [[ 12 ]]);
test.deepEqual(cell.channels.map(c => c.scale), ["x"]);
test.strictEqual(cell.channels.find(c => c.name === "x").type, "band");
});

tape("cellY() defaults y to identity and x to null", test => {
const cell = Plot.cellY();
test.strictEqual(cell.data, undefined);
const cell = Plot.cellY([12]);
test.deepEqual(cell.data, [12]);
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.initialize().channels.map(d => d[1].value), [[ 12 ]]);
test.deepEqual(cell.channels.map(c => c.scale), ["y"]);
test.strictEqual(cell.channels.find(c => c.name === "y").type, "band");
});
12 changes: 6 additions & 6 deletions test/marks/rule-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as Plot from "@observablehq/plot";
import tape from "tape-await";

tape("ruleX() has the expected defaults", test => {
const rule = Plot.ruleX();
test.strictEqual(rule.data, undefined);
const rule = Plot.ruleX([42]);
test.deepEqual(rule.data, [42]);
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.initialize().channels.map(d => d[1].value), [[ 42 ]]);
test.deepEqual(rule.channels.map(c => c.scale), ["x"]);
test.strictEqual(rule.fill, undefined);
test.strictEqual(rule.fillOpacity, undefined);
Expand Down Expand Up @@ -96,11 +96,11 @@ tape("ruleX(data, {x, y1, y2}) specifies x, y1, y2", test => {
});

tape("ruleY() has the expected defaults", test => {
const rule = Plot.ruleY();
test.strictEqual(rule.data, undefined);
const rule = Plot.ruleY([42]);
test.deepEqual(rule.data, [42]);
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.initialize().channels.map(d => d[1].value), [[ 42 ]]);
test.deepEqual(rule.channels.map(c => c.scale), ["y"]);
test.strictEqual(rule.fill, undefined);
test.strictEqual(rule.fillOpacity, undefined);
Expand Down
12 changes: 6 additions & 6 deletions test/marks/tick-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as Plot from "@observablehq/plot";
import tape from "tape-await";

tape("tickX() has the expected defaults", test => {
const tick = Plot.tickX();
test.strictEqual(tick.data, undefined);
const tick = Plot.tickX([42]);
test.deepEqual(tick.data, [42]);
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.initialize().channels.map(d => d[1].value), [[ 42 ]]);
test.deepEqual(tick.channels.map(c => c.scale), ["x"]);
test.strictEqual(tick.fill, undefined);
test.strictEqual(tick.fillOpacity, undefined);
Expand Down Expand Up @@ -61,11 +61,11 @@ tape("tickX(data, {stroke}) allows stroke to be a variable color", test => {
});

tape("tickY() has the expected defaults", test => {
const tick = Plot.tickY();
test.strictEqual(tick.data, undefined);
const tick = Plot.tickY([42]);
test.deepEqual(tick.data, [42]);
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.initialize().channels.map(d => d[1].value), [[ 42 ]]);
test.deepEqual(tick.channels.map(c => c.scale), ["y"]);
test.strictEqual(tick.fill, undefined);
test.strictEqual(tick.fillOpacity, undefined);
Expand Down