Skip to content

Commit

Permalink
don’t stack with indexOf (#2179)
Browse files Browse the repository at this point in the history
* test areaY shorthand with null & NaN

* don’t stack with indexOf
  • Loading branch information
mbostock authored Sep 27, 2024
1 parent e0bf09e commit 12ecfa7
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/marks/area.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
}
8 changes: 4 additions & 4 deletions src/transforms/identity.js
Original file line number Diff line number Diff line change
@@ -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};
}
75 changes: 75 additions & 0 deletions test/output/shorthandAreaYNaN.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions test/output/shorthandAreaYNull.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions test/plots/shorthand-areaY.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 12ecfa7

Please sign in to comment.