Skip to content

Instantly share code, notes, and snippets.

@ariutta
Last active December 30, 2015 04:29
Show Gist options
  • Save ariutta/7776406 to your computer and use it in GitHub Desktop.
Save ariutta/7776406 to your computer and use it in GitHub Desktop.
d3.xml test case
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
width: 960px;
height: 500px;
position: relative;
}
</style>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var svg = d3.select("body").append("svg")
.attr("width", 1000)
.attr("height", 1000);
var defs = svg.append("defs");
var symbol = defs.append("symbol")
.attr("id", "oval-symbol");
d3.xml("oval.svg", "image/svg+xml", function(svgXml) {
var shape = d3.select(svgXml.documentElement)
var width = shape.attr('width');
var height = shape.attr('height');
symbol.attr('viewBox', '0 0 ' + width + ' ' + height);
var shapeChildren = shape[0][0].children;
var i = -1;
do {
i += 1;
symbol[0][0].appendChild(shapeChildren[i]);
} while (i < shapeChildren.length - 1);
});
</script>
Display the source blob
Display the rendered blob
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