Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active August 2, 2017 10:22
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 d3indepth/6e320e0fb89e5bc8bdde468d301880e5 to your computer and use it in GitHub Desktop.
Save d3indepth/6e320e0fb89e5bc8bdde468d301880e5 to your computer and use it in GitHub Desktop.
Selection insert
license: gpl-3.0
height: 170
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Selection Insert</title>
</head>
<style>
body {
font-family: "Helvetica Neue", Helvetica, sans-serif;
font-size: 14px;
color: #333;
}
circle {
fill: orange;
}
g.item text {
fill: #ddd;
font-size: 70px;
text-anchor: middle;
font-weight: bold;
}
</style>
<body>
<svg width="760" height="140">
<g transform="translate(70, 70)">
<g class="item" transform="translate(0, 0)"><circle r="40" /></g>
<g class="item" transform="translate(120, 0)"><circle r="40" /></g>
<g class="item" transform="translate(240, 0)"><circle r="40" /></g>
</g>
</svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
d3.selectAll('g.item')
.insert('text', 'circle')
.text(function(d, i) {
return i + 1;
})
.attr('y', 50)
.attr('x', 30);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment