I'm trying to convert a dendrogram like this one into a picture (png/jpg). Look what I've tried to do:
function get_dendrogram(){
var svg = document.querySelector('svg');
var data = (new XMLSerializer()).serializeToString(svg);
var blob = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
saveAs(blob, "my_image.png");
}
To save the generated blob, I'm using FileSaver.js.
I don't know what I can be missing... When I try to open the file, It says that is corrupted.
I also tried converting the svg to canvas using html2canvas then saving with FileSaver or canvas2image. In these ways I got the image, but It is deformed.