<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src=
"https://d3js.org/d3.v4.js">
</script>
<script src=
"https://d3js.org/d3-scale-chromatic.v1.min.js">
</script>
</head>
<body>
<center>
<h1 style="color:green;">GeeksForGeeks</h1>
<h3>D3.js | ribbon.source() Function</h3>
<div id="GFG"></div>
<script>
// Create the svg area
var svg = d3.select("#GFG")
.append("svg")
.attr("width", 320)
.attr("height", 320)
.append("g")
.attr("transform", "translate(160,160)");
// Create input data
var data = [[ 0, 58, 71, 89, 16, 28, 68],
[ 19, 51, 0, 20, 60, 61, 71],
[ 80, 10, 16, 145, 0, 80, 45],
[ 10, 13, 9, 90, 94, 0, 0],
[ 80, 10, 16, 145, 0, 80, 45],
[ 10, 13, 9, 90, 94, 0, 0]];
// 4 groups, so create a vector of 4 colors
var colors = [d3.schemeSet2[0], d3.schemeSet2[1],
d3.schemeSet2[2], d3.schemeSet2[3],
d3.schemeSet2[4], d3.schemeSet2[5],
d3.schemeSet2[6], d3.schemeSet2[7]];
// Give this matrix to d3.chord()
var chords = d3.chord()
.padAngle(0.175)
.sortSubgroups(d3.ascending)
(data);
var rib = d3.ribbon().radius(150);
// Use of ribbon.source() function
rib({
source: {startAngle: 0.7, endAngle: 1.2},
target: {startAngle: 1.6, endAngle: 1.9}
});
svg.datum(chords)
.append("g")
.selectAll("path")
.data(function (d) { return d; })
.enter()
.append("path")
.attr("d", rib)
.style("fill", function (d) {
return (colors[d.source.index])
})
.style("stroke", "black");
</script>
</center>
</body>
</html>