Published
Edited
Jan 13, 2020
Importers
12 stars
Insert cell
Insert cell
exampleSVG = svg`<svg width=100 height=100><circle r=50 cx=50 cy=50 /></svg>`
Insert cell
exampleButton = svgDownloadButton(exampleSVG)
Insert cell
function svgDownloadButton(svgnode, filename = 'download.svg') {
const downloadButton = html`<a class="download" download="${filename}" href="#" style="display: flex; align-items: center;">${download_icon.outerHTML} Save ${filename}</a>`;

downloadButton.onclick = function(e) {
var url = (downloadButton.href = URL.createObjectURL(serialize(svgnode)));
setTimeout(function() {
URL.revokeObjectURL(url);
}, 50);
};

return downloadButton;
}
Insert cell
Insert cell
import { serialize, download_icon } from '@kelleyvanevert/little-things'
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more