针对不想检查D3js可视化代码,也不想复制粘贴等操作的最终用户。
给定一个包含所有形状和样式的D3 <svg>
元素(不在任何外部CSS中)。
是否有一种库/代码可以让最终用户点击按钮将代码下载为独立的SVG文件。
该文件应该有效地打开Inkscape和其他符合SVG标准的软件。这使最终用户有能力派生文件,将其打开到SVG编辑器中并进行更高级的设计。
针对不想检查D3js可视化代码,也不想复制粘贴等操作的最终用户。
给定一个包含所有形状和样式的D3 <svg>
元素(不在任何外部CSS中)。
是否有一种库/代码可以让最终用户点击按钮将代码下载为独立的SVG文件。
该文件应该有效地打开Inkscape和其他符合SVG标准的软件。这使最终用户有能力派生文件,将其打开到SVG编辑器中并进行更高级的设计。
.download {
background: #333;
color: #FFF;
font-weight: 900;
border: 2px solid #B10000;
padding: 4px;
margin:4px;
}
2) 定义您的按钮的 HTML/JS:
<a
class="download"
href="javascript:(function () { var e = document.createElement('script'); if (window.location.protocol === 'https:') { e.setAttribute('src', 'https://rawgit.com/NYTimes/svg-crowbar/gh-pages/svg-crowbar.js'); } else { e.setAttribute('src', 'http://nytimes.github.com/svg-crowbar/svg-crowbar.js'); } e.setAttribute('class', 'svg-crowbar'); document.body.appendChild(e); })();">
<!--⤋--><big>⇩</big> Download
</a>
javascript:(function (){
var e = document.createElement('script');
if (window.location.protocol === 'https:') {
e.setAttribute('src', 'https://rawgit.com/NYTimes/svg-crowbar/gh-pages/svg-crowbar.js');
} else {
e.setAttribute('src', 'http://nytimes.github.com/svg-crowbar/svg-crowbar.js');
}
e.setAttribute('class', 'svg-crowbar');
document.body.appendChild(e);
})();
3) 完成。 这将生成一个可以在Inkscape中打开的svg下载文件。
注意: svg-crowbar.js从https://rawgit.com或http://nytimes.github.com加载; 您可能更喜欢将其集成到您的网站/文件夹中。
<a>
标签相关联的数据URI。