I have a D3JS tree and managed to download it as a SVG file. using the below code I managed to get the svg size and set the viewBox size accordingly (with 2% padding).