Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/marks/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function applyMultilineText(selection, mark, T, TL) {
if (!T) return;
const {lineAnchor, lineHeight, textOverflow, splitLines, clipLine} = mark;
selection.each(function (i) {
const lines = splitLines(formatDefault(T[i])).map(clipLine);
const lines = splitLines(formatDefault(T[i]) ?? "").map(clipLine);
const n = lines.length;
const y = lineAnchor === "top" ? 0.71 : lineAnchor === "bottom" ? 1 - n : (164 - n * 100) / 200;
if (n > 1) {
Expand Down
382 changes: 382 additions & 0 deletions test/output/penguinNA1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
382 changes: 382 additions & 0 deletions test/output/penguinNA2.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
382 changes: 382 additions & 0 deletions test/output/penguinNA3.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 @@ -188,6 +188,7 @@ export * from "./penguin-mass-sex-species.js";
export * from "./penguin-mass-sex.js";
export * from "./penguin-mass-species.js";
export * from "./penguin-mass.js";
export * from "./penguin-na.js";
export * from "./penguin-quantile-unknown.js";
export * from "./penguin-sex-mass-culmen-species.js";
export * from "./penguin-sex.js";
Expand Down
23 changes: 23 additions & 0 deletions test/plots/penguin-na.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as Plot from "@observablehq/plot";
import * as d3 from "d3";

async function penguinNA(tickFormat: (x: number) => any = undefined) {
const sample = await d3.csv<any>("data/penguins.csv", d3.autoType);
const V = Plot.valueof(sample, "body_mass_g");
const [min, max] = d3.extent(V);
return Plot.tickX(sample, {x: V, stroke: (d) => (d.body_mass_g ? "black" : "red")}).plot({
x: {unknown: 10, ticks: [NaN, ...d3.ticks(min, max, 7)], tickFormat}
});
}

export async function penguinNA1() {
return penguinNA();
}

export async function penguinNA2() {
return penguinNA((d) => (isNaN(d) ? "N/A" : d));
}

export async function penguinNA3() {
return penguinNA((d) => d);
}