containerSize() not working in Firefox
See original GitHub issueExample: https://codepen.io/andrewbanchich/pen/NzwxBB
I have it set to update the width and height using the containerSize
expression, but in the latest version of Firefox it just expands continuously.
I feel like the best way to solve this is to allow us to set the width and height of the SVG element itself separately from the viewBox
value. In my opinion, the two have very different uses, and in many cases (including mine) it makes more sense to set the width
and height
attributes of the SVG to 100%
and have a set value for viewBox
.
Allowing us to set width
and height
to a string (so we can set a percentage value) fixes issues with resizing, would be more performant than resizing the DOM using JavaScript, and would reduce cross browser compatibility issues since any browser that supports SVG should also support percentages set for the width and height attributes of the SVG element itself.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
You can fix your example directly, without new Vega features. If you were to switch to D3, you will still need to right custom JS code to change chart size upon resize. Instead, you can update your current example in one of two ways to get proper resizing. (Both assume you are using
"autosize": {"type": "fit", "contains": "padding"}
in your Vega spec.)Instead of
containerSize[0]
for your width, usecontainerSize[0] - 20
(and similarly for height). This adjusts the size to account for the 10px padding (which adds 20px total to the component width and height, respectively) you’re adding in your CSS. Of course, it is a bit hacky to hardwire your CSS info into your Vega spec, which leads to option 2…Don’t perform resizing in your Vega spec at all. Write a small bit of JavaScript to track window resize events and perform the resizing yourself. Expand the link below for a complete working example, which uses the
window.getComputedStyle
method to get the component width/height without padding.Click to expand resizing example
@mattijn Agreed. It worked for me because I am not changing the height of my container and I have it explicitly set.
I think the only / best real solution to this is allow us to set width, height, and viewBox. This is the whole point of viewBox and browsers have optimized for that, not for manipulating complex DOM objects with JavaScript.