I'm relatively new to Stack Overflow, so I will attempt to be as thorough and concise when asking this question. I'm working on a project, and have just implemented a function to print a png image of a graph (using D3.js). Now I want to add a date (or text) to the downloaded png (only when it has been downloaded). I have been trying various things, with no luck. Any ideas?
window.printPNG = function () {
// Inputs
var mySVG = document.getElementById('the-bubble-chart');
var myXML = (new XMLSerializer()).serializeToString(mySVG);
// Outputs
var myCanvas = document.getElementById('canvg-output');
var myImg = document.getElementById('png-output');
var myA = document.getElementById('png-link');
canvg(myCanvas, myXML);
var dataURL = myCanvas.toDataURL('image/png');
var dataURLHeaders = "data:application/octet-stream;headers=Content-Disposition%3A%20attachment%3B%20filename=download.png;";
// Format file name for download
var d = new Date(),
dateString = d.getMonth() + 1 + "-" + d.getDate() + "-" + d.getFullYear().toString();
myImg.src = dataURL;
myA.href = dataURL.replace('data:', dataURLHeaders);
myA.download = dateString + "_" + "download.png";
myA.click()
}