question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HTML-Labels re-rendered with incorrect size/position after zoom in/out

See original GitHub issue

Redrawing the graph after changing the zoom scale causes html labels to appear with the wrong size and position (too big or small for the node depending if zoomed in or out).

This may be related to issue #222

My (somewhat hacky) fix for this was to reset the zoom scale of the graph to 1 before making any changes to it. Once it has been reset, the required changes are made to the graph (add/remove nodes etc), and then it is redrawn. Finally the zoom scale is reset manually to whatever it was before. This has to be done through a callback:

svg.transition() .duration(0) .call( zoom.translate([0, 0]) .scale(1).event ) .each("end", function() { makeGraphChanges(); redraw(); resetZoom(); } );

Hopefully this helps in finding the solution.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

2reactions
agg23commented, Aug 6, 2018

This is still a current issue, and is trivially solved by resetting the scale to 1 before re-rendering the graph, as mentioned by @nicolas-mosch. It would be nice if this hack was not required, but I have not noticed any ill effects.

svg.call(this.zoom.scaleTo as any, 1);

1reaction
Elliot67commented, Jun 23, 2021

Hey, Sorry to update such an old issue but there is a slightly better way to implement this hacky solution without using zoom events with d3.zoomTransform(...). Here is a working exemple :

const currentTransform = d3.zoomTransform(svgG.node());

transform(currentTransform.x, currentTransform.y, 1);
render(svgG, g);
transform(currentTransform.x, currentTransform.y, currentTransform.k);

function transform(translateX: number, transalteY: number, scale: number): void {
  svg.call(d3.zoom().transform, d3.zoomIdentity.translate(translateX, transalteY).scale(scale)); // update internal graph transform
  svgG.attr("transform", `translate(${translateX}, ${transalteY}) scale(${scale})`); // update DOM transform
}

Hope this helps someone !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Video rendered in incorrect position - Zoom Developer Forum
Description When using renderVideo, the height, width, x and y coordinates are completely ignored. The video just fills the entire canvas.
Read more >
dagre-d3 - Bountysource
The following code produces an error due to the edge from A -> group. ... HTML-Labels re-rendered with incorrect size/position after zoom in/out...
Read more >
How do I stop a CSS layout from distorting when zooming in ...
To fix the problem with zooming in, try adding the min-width attribute to your outer countainer ( #container or #navbar ?)
Read more >
zoom - CSS: Cascading Style Sheets - MDN Web Docs
The non-standard zoom CSS property can be used to control the magnification level of an element. transform: scale() should be used instead ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found