I use this code snippet to center the viewport, which contains all the SVGs that I want to show almost the entire screen.
var elmnt = $(viewport); var wdif = screen.width - width; var hdif = screen.height - height; if (wdif < hdif){ var scale = (screen.width - 50) / width; var ty = (screen.height - (height * scale)) / 2 var tx = 20; }else{ var scale = (screen.height - 50) / height; var tx = (screen.width - (width * scale)) / 2 var ty = 20; } elmnt.setAttribute("transform", "scale("+scale+") translate("+tx+","+ty+")");
What he does is use the difference between the size of the viewport and the screen size and use it as a scale. Of course, you need all the elements to be wrapped in the viewport. Hope this works for you. Bye!
EDIT
I made this fiddle ... http://jsfiddle.net/MakKZ/
In the original snippet, I used the screen size, on the violin, you will see that I am using the size of the HTML element that jsfiddle uses. No matter how many circles (or the size of the circles) you draw on the screen, you always see them all.
source share