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(); +}