Skip to content

Commit 12ecfa7

Browse files
authored
don’t stack with indexOf (#2179)
* test areaY shorthand with null & NaN * don’t stack with indexOf
1 parent e0bf09e commit 12ecfa7

File tree

5 files changed

+166
-6
lines changed

5 files changed

+166
-6
lines changed

src/marks/area.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ export function area(data, options) {
7878

7979
export function areaX(data, options) {
8080
const {y = indexOf, ...rest} = maybeDenseIntervalY(options);
81-
return new Area(data, maybeStackX(maybeIdentityX({...rest, y1: y, y2: undefined})));
81+
return new Area(data, maybeStackX(maybeIdentityX({...rest, y1: y, y2: undefined}, y === indexOf ? "x2" : "x")));
8282
}
8383

8484
export function areaY(data, options) {
8585
const {x = indexOf, ...rest} = maybeDenseIntervalX(options);
86-
return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined})));
86+
return new Area(data, maybeStackY(maybeIdentityY({...rest, x1: x, x2: undefined}, x === indexOf ? "y2" : "y")));
8787
}

src/transforms/identity.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import {hasX, hasY, identity} from "../options.js";
22

3-
export function maybeIdentityX(options = {}) {
4-
return hasX(options) ? options : {...options, x: identity};
3+
export function maybeIdentityX(options = {}, k = "x") {
4+
return hasX(options) ? options : {...options, [k]: identity};
55
}
66

7-
export function maybeIdentityY(options = {}) {
8-
return hasY(options) ? options : {...options, y: identity};
7+
export function maybeIdentityY(options = {}, k = "y") {
8+
return hasY(options) ? options : {...options, [k]: identity};
99
}

test/output/shorthandAreaYNaN.svg

+75
Loading

test/output/shorthandAreaYNull.svg

+75
Loading

test/plots/shorthand-areaY.ts

+10
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,13 @@ export async function shorthandAreaY() {
88
];
99
return Plot.areaY(numbers).plot();
1010
}
11+
12+
export async function shorthandAreaYNaN() {
13+
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
14+
return Plot.areaY(numbers).plot();
15+
}
16+
17+
export async function shorthandAreaYNull() {
18+
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
19+
return Plot.areaY(numbers).plot();
20+
}

0 commit comments

Comments
 (0)