Skip to content

Commit

Permalink
only truncate the long visible text, not the title (observablehq#1913)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil authored and chaichontat committed Jan 14, 2024
1 parent 4954cdf commit 0013dbb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/marks/tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ export class Tip extends Mark {
const [k] = cut(value, w - widthof(label), widthof, ee);
if (k >= 0) {
// value is truncated
value = value.slice(0, k).trimEnd() + ellipsis;
title = value.trim();
value = value.slice(0, k).trimEnd() + ellipsis;
}
}
const line = selection.append("tspan").attr("x", 0).attr("dy", `${lineHeight}em`).text("\u200b"); // zwsp for double-click
Expand Down
31 changes: 31 additions & 0 deletions test/output/tipLongText.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions test/plots/tip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export async function tipLineY() {
return Plot.lineY(aapl, {x: "Date", y: "Close", tip: true}).plot();
}

export async function tipLongText() {
return Plot.tip([{x: "Long sentence that gets cropped after a certain length"}], {x: "x"}).plot();
}

export async function tipNewLines() {
return Plot.plot({
height: 40,
Expand Down

0 comments on commit 0013dbb

Please sign in to comment.