From 99c8995169de47e6a30130f550b36cae53287e05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 1 Nov 2023 18:13:02 +0100 Subject: [PATCH] only truncate the long visible text, not the title (#1913) --- src/marks/tip.js | 2 +- test/output/tipLongText.svg | 31 +++++++++++++++++++++++++++++++ test/plots/tip.ts | 4 ++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/output/tipLongText.svg diff --git a/src/marks/tip.js b/src/marks/tip.js index 071809aae0..5516e3859a 100644 --- a/src/marks/tip.js +++ b/src/marks/tip.js @@ -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 diff --git a/test/output/tipLongText.svg b/test/output/tipLongText.svg new file mode 100644 index 0000000000..3fb976b3e7 --- /dev/null +++ b/test/output/tipLongText.svg @@ -0,0 +1,31 @@ + + + + + + + Long sentence that gets cropped after a certain length + + + x + + + + + x Long sentence that gets cropped afte…Long sentence that gets cropped after a certain length + + + \ No newline at end of file diff --git a/test/plots/tip.ts b/test/plots/tip.ts index bd7103545a..7f48802072 100644 --- a/test/plots/tip.ts +++ b/test/plots/tip.ts @@ -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,