Skip to content

Instantly share code, notes, and snippets.

@d3indepth
Last active March 8, 2020 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save d3indepth/d4eb9c450e955225900ed73606a13b25 to your computer and use it in GitHub Desktop.
Save d3indepth/d4eb9c450e955225900ed73606a13b25 to your computer and use it in GitHub Desktop.
Chord layout
license: gpl-3.0
height: 520
border: no
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<title>Chord layout</title>
</head>
<style>
svg path {
fill: #ddd;
stroke: #ccc;
opacity: 0.8;
}
</style>
<body>
<svg width="500" height="500">
<g transform="translate(250, 250)"></g>
</svg>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.2.2/d3.min.js"></script>
<script>
var chordGenerator = d3.chord()
.sortSubgroups(d3.ascending)
.padAngle(0.04);
var ribbonGenerator = d3.ribbon().radius(200);
var data = [
[10, 20, 30],
[40, 60, 80],
[100, 200, 300]
];
var chords = chordGenerator(data);
d3.select('g')
.selectAll('path')
.data(chords)
.enter()
.append('path')
.attr('d', ribbonGenerator)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment