diff --git a/src/plot.js b/src/plot.js index f0829af9cc..a091d8d8a8 100644 --- a/src/plot.js +++ b/src/plot.js @@ -403,7 +403,7 @@ function applyScaleTransform(channel, options) { type, percent, interval, - transform = percent ? (x) => x * 100 : maybeIntervalTransform(interval, type) + transform = percent ? (x) => (x == null ? NaN : x * 100) : maybeIntervalTransform(interval, type) } = options[scale] ?? {}; if (transform == null) return; channel.value = map(channel.value, transform); diff --git a/test/output/percentNull.svg b/test/output/percentNull.svg new file mode 100644 index 0000000000..3cd911e600 --- /dev/null +++ b/test/output/percentNull.svg @@ -0,0 +1,47 @@ + + + + + 100 + + + + 1.0 + 1.5 + 2.0 + 2.5 + 3.0 + 3.5 + 4.0 + 4.5 + 5.0 + + + + + \ No newline at end of file diff --git a/test/plots/index.ts b/test/plots/index.ts index 27efed9822..13231ea454 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -217,6 +217,7 @@ export * from "./penguin-species-island-sex.js"; export * from "./penguin-species-island.js"; export * from "./penguin-species.js"; export * from "./penguin-voronoi-1d.js"; +export * from "./percent-null.js"; export * from "./pointer-linked.js"; export * from "./pointer.js"; export * from "./polylinear.js"; diff --git a/test/plots/percent-null.ts b/test/plots/percent-null.ts new file mode 100644 index 0000000000..93c762ef9b --- /dev/null +++ b/test/plots/percent-null.ts @@ -0,0 +1,7 @@ +import * as Plot from "@observablehq/plot"; + +export async function percentNull() { + const time = [1, 2, 3, 4, 5]; + const value = [null, null, 1, null, null]; + return Plot.dot(time, {x: time, y: value}).plot({y: {percent: true}}); +}