Skip to content

Commit

Permalink
fix tip flicker (observablehq#1826)
Browse files Browse the repository at this point in the history
* closes observablehq#1805

* tests

* conditional postrender

---------

Co-authored-by: Mike Bostock <mbostock@gmail.com>
  • Loading branch information
2 people authored and chaichontat committed Jan 14, 2024
1 parent 632e3a7 commit bab575e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/marks/tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export class Tip extends Mark {
text.setAttribute("y", `${+getLineOffset(a, text.childNodes.length, lineHeight).toFixed(6)}em`);
text.setAttribute("transform", `translate(${getTextTranslate(a, m, r, w, h)})`);
});
g.attr("visibility", null);
}

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

return g.node();
}
Expand Down
4 changes: 2 additions & 2 deletions test/output/tipNewLines.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bab575e

Please sign in to comment.