I have a d3 graph (collapsable indented tree) and I'm saving it to a canvas element. This is working fine.
However after I save the svg to the canvas and interact with the three the graph gets rendered in really strange ways (i.e links and text disapearring). This strange behaviour onkly happens after I save the graph to canvas. It works fine if I do not save it to canvas.
I think this is because I used d3 to select all svg on my page in order to get the svg xml. Is there a way to do an unselect operation on a selection or is there a better way of getting the svg xml?
Here is the relevant code :
d3.selectAll("#view-on-canvas").on(
"click",
function(d) {
var graphSVG = d3.selectAll('svg').node() //I think this line is the problem
var ctx;
var serializer = new XMLSerializer();
var thumbnailImage = new Image();
var xmlString = serializer.serializeToString(graphSVG);
var imgData = 'data:image/svg+xml;base64,' + btoa(xmlString);
thumbnailImage.onload = function() {
var thumbnailCanvas = $("#canvas")[0];
ctx = thumbnailCanvas.getContext("2d");
ctx.drawSvg(text, 0, 0);
}
thumbnailImage.src = $("canvas")[0].toDataURL("image/png");
});