Skip to content

Instantly share code, notes, and snippets.

@jkutianski
Last active May 3, 2018 03:36
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 jkutianski/bd32c81f876af95dbcfe7e20f3e289ff to your computer and use it in GitHub Desktop.
Save jkutianski/bd32c81f876af95dbcfe7e20f3e289ff to your computer and use it in GitHub Desktop.
Reading SVG files with D3js

d3.text() is the 1st key to include a SVG file on the DOM using D3js, the 2nd one is d3.selection().html(). After you inject the SVG you can manipulate the SVG using common D3js technics.

Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
d3.text('boom.svg', (textsvg) => {
d3.selectAll("body")
.html(textsvg)
.select("*")
.attr('width', `${width}px`)
.attr('height', `${height}px`);
});
</script>
</body>
</html>
These Pop Art Elements is licensed under Creative Commons Attribution 3.0 Unported License - http://creativecommons.org/licenses/by/3.0/.
Under this license, you are free to copy and redistribute the material in any medium or format, remix, transform and build upon the material for any purpose, even commercially. In exchange, you must give appropriate credit to Vecteezy (http://www.vecteezy.com/).
For more free resources, visit http://graphicflip.com/
- Monika Ratan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment