10-09-2017 23:04
10-09-2017 23:04
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.
Answered! Go to the Best Answer.
10-09-2017 23:23
10-09-2017 23:23
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 🙂
10-09-2017 23:23
10-09-2017 23:23
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 🙂
10-10-2017 10:22 - edited 10-10-2017 10:48
10-10-2017 10:22 - edited 10-10-2017 10:48
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.