score:1

Accepted answer

You can get the svg bounding box using svg.getBBox(), where svg is your svg node, e.g.

let svg = document.getElementsByTagName("svg")[0];
let box = svg.getBBox()

and then use box.x, .y, .width and .height to calculate the correct viewBox attribute value, width and height.


Related Query

More Query from same tag