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.

changing the size of the graph doesn't change the size of the SVG

See original GitHub issue

Describe the bug Hi! This bug relates to the flamegraph.width function [0].

In our application we added a resize function to change the size of the flamegraph based on the size of its container. We’re using the flamegraph.width function [0] and giving it a value based on the width of the container. What I’m noticing however is that if the graph is initialized at one size, and then the window size is increased, the graph gets cut off.

From a bit of debugging, it seems that the issue is the svg width is never updated after initialization. When the width is changed and the chart is redrawn, this line [1] gets hit, but because the svg exists already the following code that updates the dimensions is never reached. So if I opened a window at 800px width, resized it to 1000px, the graph displays at 1000px width but is cutoff because the svg is only 800px.

I can get around this by changing the svg width to be 100% from a stylesheet, but figured I’d bring this up anyways.

[0] https://github.com/spiermar/d3-flame-graph#width [1] https://github.com/spiermar/d3-flame-graph/blob/2.0.3/src/flamegraph.js#L489

To Reproduce Steps to reproduce the behavior:

Pre-req: needs an onresize function that updates the flamegraph width via flamegraph.width() with the new width of the container

  1. Draw a flamegraph
  2. Increase the size of the browser via dragging/etc.
  3. Notice that the chart is clipped

Expected behavior The svg width should update when the graph width is updated.

Screenshots In this image, the body is cyan, and the chart div is light green. After resizing larger, the frame is cutoff by the old width of the svg. hidden-rect(1)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
spiermarcommented, Oct 12, 2021

@pradyunsg the change above implements both suggestions you made. Thank you.

0reactions
pradyunsgcommented, Oct 12, 2021

Awesome. Thanks @spiermar! ^>^

Read more comments on GitHub >

github_iconTop Results From Across the Web

SVG moves out of position when screen size changes or ...
responsive design - SVG moves out of position when screen size changes or doesn't scale - Stack Overflow. Stack Overflow for Teams –...
Read more >
Resizing an SVG When the Window is Resized in d3.js - Chartio
When developing with SVG, it can often be difficult to scale SVG objects when the containing frame or even the entire browser window...
Read more >
Support setting svg size and scale the contained graph to fit or ...
These cases should be supported: Set the svg size, but don't scale the contained graph; Set the svg size and scale the contained...
Read more >
Sizing and Scaling SVG Images - SAS Help Center
In HTML5 output, SVG and SVGZ file height and width attributes are set to the size of the SVG. The reason is that...
Read more >
viewBox - SVG: Scalable Vector Graphics - MDN Web Docs
The viewBox attribute defines the position and dimension, in user space, of an SVG viewport.
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