Skip to content

Instantly share code, notes, and snippets.

@d3byex
Created November 23, 2015 07:38
Show Gist options
  • Select an option

  • Save d3byex/52e153041a25b07c5852 to your computer and use it in GitHub Desktop.

Select an option

Save d3byex/52e153041a25b07c5852 to your computer and use it in GitHub Desktop.
D3byEX 9.11: Diagonals
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="D3byEX 9.11" />
<meta charset="utf-8">
</head>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var svg = d3.select('body')
.append('svg')
.attr({
width: 1000,
height: 200
});
var source = { x: 500, y: 50 };
var targets = [
{ x: 100, y: 150 },
{ x: 300, y: 150 },
{ x: 500, y: 150 },
{ x: 700, y: 150 },
{ x: 900, y: 150 }
];
var links = targets.map(function (target) {
return { source: source, target: target };
});
svg.selectAll('path')
.data(links)
.enter()
.append('path')
.attr({
d: d3.svg.diagonal(),
fill: 'none',
stroke: '#ccc'
});
var nodes = targets.concat(source);
svg.selectAll('circle')
.data(nodes)
.enter().append('circle')
.attr({
r: 20,
cx: function (d) { return d.x; },
cy: function (d) { return d.y; },
fill: 'orange',
stroke: '#333'
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment