Skip to content

Commit

Permalink
don’t coerce null percent to zero (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jun 8, 2024
1 parent af2c3bb commit 8f7d6ea
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 47 additions & 0 deletions test/output/percentNull.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
7 changes: 7 additions & 0 deletions test/plots/percent-null.ts
Original file line number Diff line number Diff line change
@@ -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}});
}

0 comments on commit 8f7d6ea

Please sign in to comment.