From 5da40d8833c41144c5ead78cf5acbe8768ca6d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 18 Mar 2026 12:04:21 +0100 Subject: [PATCH] fixes #2011 --- src/marks/tip.js | 8 ++++- test/output/tipAnchorOverflow.svg | 50 +++++++++++++++++++++++++++++++ test/plots/index.ts | 1 + test/plots/tip-anchor-overflow.ts | 11 +++++++ 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/output/tipAnchorOverflow.svg create mode 100644 test/plots/tip-anchor-overflow.ts diff --git a/src/marks/tip.js b/src/marks/tip.js index bfb9d04cb2..3c7e7ac61a 100644 --- a/src/marks/tip.js +++ b/src/marks/tip.js @@ -225,9 +225,15 @@ export class Tip extends Mark { : fitTop && fitBottom ? fitLeft ? "left" - : "right" + : fitRight + ? "right" + : "bottom" : (fitLeft || fitRight) && (fitTop || fitBottom) ? `${fitBottom ? "bottom" : "top"}-${fitLeft ? "left" : "right"}` + : fitLeft + ? "left" + : fitRight + ? "right" : mark.preferredAnchor; } const path = this.firstChild; // note: assumes exactly two children! diff --git a/test/output/tipAnchorOverflow.svg b/test/output/tipAnchorOverflow.svg new file mode 100644 index 0000000000..f347911520 --- /dev/null +++ b/test/output/tipAnchorOverflow.svg @@ -0,0 +1,50 @@ + + + + + 0.0 + 0.5 + 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 3c019e678f..9f45017f03 100644 --- a/test/plots/index.ts +++ b/test/plots/index.ts @@ -312,6 +312,7 @@ export * from "./text-overflow.js"; export * from "./this-is-just-to-say.js"; export * from "./tick-format.js"; export * from "./time-axis.js"; +export * from "./tip-anchor-overflow.js"; export * from "./tip-format.js"; export * from "./tip.js"; export * from "./title.js"; diff --git a/test/plots/tip-anchor-overflow.ts b/test/plots/tip-anchor-overflow.ts new file mode 100644 index 0000000000..55872e13ba --- /dev/null +++ b/test/plots/tip-anchor-overflow.ts @@ -0,0 +1,11 @@ +import * as Plot from "@observablehq/plot"; + +export async function tipAnchorOverflow() { + return Plot.rectX([1, 1, 1, 1, 1], { + x: Plot.identity, + fill: Plot.indexOf, + title: () => + "Lorem ipsum lorem ipsum lorem ipsum Lorem ipsum lorem ipsum lorem ipsum Lorem ipsum lorem ipsum lorem ipsum", + tip: true + }).plot({height: 100, marginTop: 20}); +}