[ Launch Inlet ]
-
-
Save taivare/cf30117ff46df4c5baacc6c0e4216ea1 to your computer and use it in GitHub Desktop.
how to serialize d3 svgs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"endpoint":"","display":"svg","public":true,"require":[],"tab":"edit","display_percent":0.5245512449334112,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var svg=d3.select("svg"); | |
svg.append("rect") | |
.attr({ | |
width:200, | |
height:200, | |
x:100, | |
y:100, | |
fill: "#1A9224", | |
}) | |
svg.append("image") | |
.attr({ | |
width:200, | |
height:200, | |
"xlink:href":"https://twimg0-a.akamaihd.net/profile_images/2560186719/7f57h85fjrqelks62v75.jpeg", | |
x:325, | |
y:100 | |
}) | |
function cerealize(node){ | |
var svgxml=(new XMLSerializer()).serializeToString(node); | |
if($.browser.webkit){ | |
svgxml=svgxml.replace(/ xlink:xlink/g,' xmlns:xlink'); | |
svgxml=svgxml.replace(/ href/g, 'xlink:href'); | |
} | |
return svgxml; | |
} | |
//usage: this will output a string representation of the svg element | |
//generated by the javascript code which you can save to an .svg | |
//and view in your browser | |
var exp=cerealize(svg.node()); | |
console.log(exp); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment