From 12ecfa7dc266fb5538ca5902defd3401e4bcbe85 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Fri, 27 Sep 2024 10:13:13 -0700 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20stack=20with=20indexOf=20(#2179?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test areaY shorthand with null & NaN * don’t stack with indexOf --- src/marks/area.js | 4 +- src/transforms/identity.js | 8 ++-- test/output/shorthandAreaYNaN.svg | 75 ++++++++++++++++++++++++++++++ test/output/shorthandAreaYNull.svg | 75 ++++++++++++++++++++++++++++++ test/plots/shorthand-areaY.ts | 10 ++++ 5 files changed, 166 insertions(+), 6 deletions(-) create mode 100644 test/output/shorthandAreaYNaN.svg create mode 100644 test/output/shorthandAreaYNull.svg diff --git a/src/marks/area.js b/src/marks/area.js index bd8393926c..628088445a 100644 --- a/src/marks/area.js +++ b/src/marks/area.js @@ -78,10 +78,10 @@ export function area(data, options) { export function areaX(data, options) { const {y = indexOf, ...rest} = maybeDenseIntervalY(options); - return new Area(data, maybeStackX(maybeIdentityX({...rest, y1: y, y2: undefined}))); + return new Area(data, maybeStackX(maybeIdentityX({...rest, y1: y, y2: undefined}, y === indexOf ? "x2" : "x"))); } export function areaY(data, options) { const {x = indexOf, ...rest} = maybeDenseIntervalX(options); - return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined}))); + return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined}, x === indexOf ? "y2" : "y"))); } diff --git a/src/transforms/identity.js b/src/transforms/identity.js index 909511cc68..3b2ddf54cc 100644 --- a/src/transforms/identity.js +++ b/src/transforms/identity.js @@ -1,9 +1,9 @@ import {hasX, hasY, identity} from "../options.js"; -export function maybeIdentityX(options = {}) { - return hasX(options) ? options : {...options, x: identity}; +export function maybeIdentityX(options = {}, k = "x") { + return hasX(options) ? options : {...options, [k]: identity}; } -export function maybeIdentityY(options = {}) { - return hasY(options) ? options : {...options, y: identity}; +export function maybeIdentityY(options = {}, k = "y") { + return hasY(options) ? options : {...options, [k]: identity}; } diff --git a/test/output/shorthandAreaYNaN.svg b/test/output/shorthandAreaYNaN.svg new file mode 100644 index 0000000000..3605ae55cd --- /dev/null +++ b/test/output/shorthandAreaYNaN.svg @@ -0,0 +1,75 @@ + + + + + 0 + 5 + 10 + 15 + 20 + 25 + 30 + 35 + 40 + 45 + 50 + 55 + 60 + 65 + + + + 0 + 2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + + + + + \ No newline at end of file diff --git a/test/output/shorthandAreaYNull.svg b/test/output/shorthandAreaYNull.svg new file mode 100644 index 0000000000..3605ae55cd --- /dev/null +++ b/test/output/shorthandAreaYNull.svg @@ -0,0 +1,75 @@ + + + + + 0 + 5 + 10 + 15 + 20 + 25 + 30 + 35 + 40 + 45 + 50 + 55 + 60 + 65 + + + + 0 + 2 + 4 + 6 + 8 + 10 + 12 + 14 + 16 + 18 + + + + + \ No newline at end of file diff --git a/test/plots/shorthand-areaY.ts b/test/plots/shorthand-areaY.ts index 205425e766..9693c0bb87 100644 --- a/test/plots/shorthand-areaY.ts +++ b/test/plots/shorthand-areaY.ts @@ -8,3 +8,13 @@ export async function shorthandAreaY() { ]; return Plot.areaY(numbers).plot(); } + +export async function shorthandAreaYNaN() { + const numbers = [57.5, 37.6, 48.5, 42.4, NaN, NaN, NaN, NaN, 66.5, 67.7, 49.2, 58.7, 41.4, 54.4, 41.7, 49.8, 60.2, 44.5, 47.4, 33.5]; // prettier-ignore + return Plot.areaY(numbers).plot(); +} + +export async function shorthandAreaYNull() { + const numbers = [57.5, 37.6, 48.5, 42.4, null, null, null, null, 66.5, 67.7, 49.2, 58.7, 41.4, 54.4, 41.7, 49.8, 60.2, 44.5, 47.4, 33.5]; // prettier-ignore + return Plot.areaY(numbers).plot(); +}