Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting height/width percentages?

ANSWERED

I have gotten past not being able to create new elements within the SVG by creating a ton of blank elements with systematic IDs, but I now need to dynamically alter their width.  Ideally, I would be able to set a string for the percentage, but that doesn't work (throws an error about expecting a number).  My next thought is to get the width of the containing element and do the math in code, but I can't find a way to determine the width of any elements (at least not elements with percentages for width).

Any thoughts or suggestions?  I can just do it hard-coded, but I would like to make it dynamic if possible.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Create a top-level svg with a known id and set its width and height to 100%.

 

Then, in your javascript/typescript file in the app folder, use the document object to get the svg element by its id, and read off its width and height 🙂

View best answer in original post

Best Answer
0 Votes
2 REPLIES 2

Create a top-level svg with a known id and set its width and height to 100%.

 

Then, in your javascript/typescript file in the app folder, use the document object to get the svg element by its id, and read off its width and height 🙂

Best Answer
0 Votes

That's what I tried, and it returns height/width of zero.

 

To clarify, if I attach an ID to the root element, I get a value.  Any element below that which uses relative positioning returns a zero.  In the end, using the root element worked, but I have to keep track of proportions and do the math in the index.js files to keep in sync with the index.gui files (which is super annoying).

Thank you for the solution @skyway.

Best Answer
0 Votes