Skip to content

Instantly share code, notes, and snippets.

@taivare
Last active March 30, 2016 04:01
Using SVG images w/D3
{"editor_editor":{"coffee":false,"vim":false,"emacs":false,"width":579,"height":508,"hide":false},"endpoint":"","description":"Using SVG images w/D3","display":"svg","public":true,"require":[],"fileconfigs":{"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"inlet.svg":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true,"thumbnail":"http://i.imgur.com/e4UyRlm.png"}
var svg = d3.select("svg");
svg.append("rect")
.attr({
width: 200,
height: 200,
x: 100,
y: 100,
fill: "#1A9224"
})
svg.append("image")
.attr({
width: 100%
height: 100%
xlink:href="https://www.dropbox.com/s/gtindax1177ewmx/BLANK_VOWEL_trapezoid.svg?dl=1"...
x: 10,
y: 20
})
function cerealize(node) {
var svgxml = (new XMLSerializer()).serializeToString(node);
if($.browser.webkit){
svgxml = svgxml.replace(/ xlink/g, ' xmlns:xlink');
svgxml = svgxml.replace(/ href/g, ' xlink:href');
}
return svgxml;
}
//usage:
var exp = cerealize(svg.node());
console.log(exp);
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment