function download_png() {
  var html = d3.select('svg')
    .attr('version', 1.1)
    .attr('xmlns', 'http://www.w3.org/2000/svg')
    .node().parentNode.innerHTML;

  var canvas = document.createElement('canvas');
  canvas.width = radius * 2 + margin * 2;
  canvas.height = radius * 2 + margin * 2;
  var context = canvas.getContext('2d');

  var image = new Image();
  image.src = 'data:image/svg+xml;base64,' + btoa(html);
  image.onload = function() {
    context.drawImage(image, 0, 0);

    var a = document.createElement('a');
    a.download = get_file_name() + '.png';
    try {
      a.href = canvas.toDataURL('image/png');
      a.click();
    } catch(e) {
      var s = 'Error rendering PNG: see the "More Info" link for more information\n\n' + e;
      alert(s);
    }
  };
}
// download the current svg as a png
download the current svg as a png
download the current svg as a png
function download_png() {
  var html = d3.select('svg')
    .attr('version', 1.1)
    .attr('xmlns', 'http://www.w3.org/2000/svg')
    .node().parentNode.innerHTML;
  var canvas = document.createElement('canvas');
  canvas.width = radius * 2 + margin * 2;
  canvas.height = radius * 2 + margin * 2;
  var context = canvas.getContext('2d');
  var image = new Image();
  image.src = 'data:image/svg+xml;base64,' + btoa(html);
  image.onload = function() {
    context.drawImage(image, 0, 0);
    var a = document.createElement('a');
    a.download = get_file_name() + '.png';
    try {
      a.href = canvas.toDataURL('image/png');
      a.click();
    } catch(e) {
      var s = 'Error rendering PNG: see the "More Info" link for more information\n\n' + e;
      alert(s);
    }
  };
}
function download_png ( ) { var html = d3 . select ( 'svg' ) . attr ( 'version' , 1.1 ) . attr ( 'xmlns' , 'http://www.w3.org/2000/svg' ) . node ( ) . parentNode . innerHTML ; var canvas = document . createElement ( 'canvas' ) ; canvas . width = radius * 2 + margin * 2 ; canvas . height = radius * 2 + margin * 2 ; var context = canvas . getContext ( '2d' ) ; var image = new Image ( ) ; image . src = 'data:image/svg+xml;base64,' + btoa ( html ) ; image . onload = function ( ) { context . drawImage ( image , 0 , 0 ) ; var a = document . createElement ( 'a' ) ; a . download = get_file_name ( ) + '.png' ; try { a . href = canvas . toDataURL ( 'image/png' ) ; a . click ( ) ; } catch ( e ) { var s = 'Error rendering PNG: see the "More Info" link for more information\n\n' + e ; alert ( s ) ; } } ; }
download the current svg as a png
download the current svg as a png