Skip to content

Commit 8f7d6ea

Browse files
authored
don’t coerce null percent to zero (#2073)
1 parent af2c3bb commit 8f7d6ea

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

src/plot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ function applyScaleTransform(channel, options) {
403403
type,
404404
percent,
405405
interval,
406-
transform = percent ? (x) => x * 100 : maybeIntervalTransform(interval, type)
406+
transform = percent ? (x) => (x == null ? NaN : x * 100) : maybeIntervalTransform(interval, type)
407407
} = options[scale] ?? {};
408408
if (transform == null) return;
409409
channel.value = map(channel.value, transform);

test/output/percentNull.svg

Lines changed: 47 additions & 0 deletions
Loading

test/plots/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export * from "./penguin-species-island-sex.js";
217217
export * from "./penguin-species-island.js";
218218
export * from "./penguin-species.js";
219219
export * from "./penguin-voronoi-1d.js";
220+
export * from "./percent-null.js";
220221
export * from "./pointer-linked.js";
221222
export * from "./pointer.js";
222223
export * from "./polylinear.js";

test/plots/percent-null.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as Plot from "@observablehq/plot";
2+
3+
export async function percentNull() {
4+
const time = [1, 2, 3, 4, 5];
5+
const value = [null, null, 1, null, null];
6+
return Plot.dot(time, {x: time, y: value}).plot({y: {percent: true}});
7+
}

0 commit comments

Comments
 (0)