Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active August 2, 2017 11:24
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/a1fea300b04eaee5abbf58236fe01705 to your computer and use it in GitHub Desktop.
Save d3indepth/a1fea300b04eaee5abbf58236fe01705 to your computer and use it in GitHub Desktop.
Symbol generator
license: gpl-3.0
height: 130
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Symbol generator</title>
</head>
<style>
path {
fill: #ddd;
stroke: #999;
}
</style>
<body>
<svg width="700" height="120">
<g transform="translate(20, 10)"></g>
</svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
var symbolGenerator = d3.symbol()
.type(d3.symbolStar)
.size(80);
var points = [
[0, 80],
[100, 100],
[200, 30],
[300, 50],
[400, 40],
[500, 80]
];
var pathData = symbolGenerator();
d3.select('g')
.selectAll('path')
.data(points)
.enter()
.append('path')
.attr('transform', function(d) {
return 'translate(' + d + ')';
})
.attr('d', pathData);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment