viewBox="480 390 120 120"
would put the image in the window. I could try and figure out the maths on redoing the coordinate system for the path, but⌠i just plonked it in a CSV viewer and poked numbers till it worked.
Thanks for effort, but If I use the viewbox u generated for me, it only work for that path alone, it does not work for every other path I generated at run time .
Hello house , pls is there any other way i can determine the viewbox to set the svg to for each of tje path i put in the svg, pos kindly help me do that formula , its really giving me tough time plsâŚ
You would have to break down the path instructions into their coordinate pairs, find the extrema of each axis, and construct a bounding box that encompasses the path.
In your example, the X axis has extrema [472,610] and the Y axis has extrema [405,492].
The difference in the X extrema is 138; the difference in the Y extrema is 87. Your bounding box would need to be 138x138 to fit all of the shape in; the X coordinates are being used, so 472 would be the coordinate of the âleftâ indicator of the box; the âtopâ indicator of the box should be 405 + 43.5 - 69 = 379.5; to keep coordinates in the integer range, truncate;
Mathematically, your example should be viewboxed as 472 379 138 138.
Javascript does make this easier by having a function to get the bounding box (getBBox), but the box it returns is a rectangle, not a square, so youâve still got some manipulation to do.
Sort of. This generates a rect around multiple elements; I took âeachâ to mean âa series of single elementsâ; at which point, the code is just getBBox of the element. The article returns a rectangle, rather than a square.
I really appreciate u guys for ur contributions, all ideas worked for my project, and most especially the one given by PaulOB, i really appreciate this, this platform is awesome, stackoverflow didnt have the kind of response i got from here, thanks all.