Skip to content

Instantly share code, notes, and snippets.

@HarryStevens
Forked from mbostock/.block
Last active February 14, 2019 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HarryStevens/c2c877a7e8e6bcd33a0fc1b21b31cbdf to your computer and use it in GitHub Desktop.
Save HarryStevens/c2c877a7e8e6bcd33a0fc1b21b31cbdf to your computer and use it in GitHub Desktop.
External SVG In Multipile Nodes
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
<div class="container"></div>
<script src="https://d3js.org/d3.v4.js"></script>
<script>
d3.xml("rect01.svg").mimeType("image/svg+xml").get(function(error, xml) {
if (error) throw error;
var el = xml.documentElement;
document.querySelectorAll(".container").forEach((container, container_index) => {
container.appendChild(el.cloneNode(true));
});
});
</script>
</body>
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="12cm" height="4cm" viewBox="0 0 1200 400"
xmlns="http://www.w3.org/2000/svg" version="1.1">
<desc>Example rect01 - rectangle with sharp corners</desc>
<!-- Show outline of canvas using 'rect' element -->
<rect x="1" y="1" width="1198" height="398"
fill="none" stroke="blue" stroke-width="2"/>
<rect x="400" y="100" width="400" height="200"
fill="yellow" stroke="navy" stroke-width="10" />
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment