Skip to content

Commit 075bdc8

Browse files
Filmbostock
andauthored
fix tip flicker (#1826)
* closes #1805 * tests * conditional postrender --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent ec4e8f0 commit 075bdc8

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/marks/tip.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export class Tip extends Mark {
241241
text.setAttribute("y", `${+getLineOffset(a, text.childNodes.length, lineHeight).toFixed(6)}em`);
242242
text.setAttribute("transform", `translate(${getTextTranslate(a, m, r, w, h)})`);
243243
});
244+
g.attr("visibility", null);
244245
}
245246

246247
// Wait until the plot is inserted into the page so that we can use getBBox
@@ -250,8 +251,11 @@ export class Tip extends Mark {
250251
// this step. Perhaps this could be done synchronously; getting the
251252
// dimensions of the SVG is easy, and although accurate text metrics are
252253
// hard, we could use approximate heuristics.
253-
if (svg.isConnected) Promise.resolve().then(postrender);
254-
else if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(postrender);
254+
if (index.length) {
255+
g.attr("visibility", "hidden"); // hide until postrender
256+
if (svg.isConnected) Promise.resolve().then(postrender);
257+
else if (typeof requestAnimationFrame !== "undefined") requestAnimationFrame(postrender);
258+
}
255259

256260
return g.node();
257261
}

test/output/tipNewLines.svg

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)