Skip to content

Instantly share code, notes, and snippets.

@morinted
Created June 19, 2018 18:08
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 morinted/1befd0f7ea11532af4510f3a8f819012 to your computer and use it in GitHub Desktop.
Save morinted/1befd0f7ea11532af4510f3a8f819012 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Line (using curveCardinal)</title>
</head>
<style>
path {
fill: none;
stroke: #999;
}
circle {
fill: none;
stroke: #aaa;
}
</style>
<body>
<svg width="700" height="300">
<path></path>
</svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
var lineGenerator = d3.line()
.curve(d3.curveCardinalClosed);
var points = [
[50, 40],
[220, 80],
[550, 30],
[550, 80],
[400, 170],
[220, 200],
[50, 140],
];
var pathData = lineGenerator(points);
d3.select('path')
.attr('d', pathData);
// Also draw points for reference
d3.select('svg')
.selectAll('circle')
.data(points)
.enter()
.append('circle')
.attr('cx', function(d) {
return d[0];
})
.attr('cy', function(d) {
return d[1];
})
.attr('r', 3);
</script>
<script id="jsbin-javascript">
sadfsdfsafsdsdsadf
</script>
<script id="jsbin-source-javascript" type="text/javascript">sadfsdfsafsdsdsadf</script></body>
</html>
sadfsdfsafsdsdsadf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment