chart = {
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height]);
const chords = chord(matrix);
const textId = DOM.uid("text");
svg.append("path")
.attr("id", textId.id)
.attr("fill", "none")
.attr("d", d3.arc()({outerRadius, startAngle: 0, endAngle: 2 * Math.PI}));
var grads = svg.append("defs")
.selectAll("linearGradient")
.data(chords)
.enter()
.append("linearGradient")
.attr("id", getGradID)
.attr("gradientUnits", "userSpaceOnUse")
.attr("x1", function(d, i){ return innerRadius * Math.cos((d.source.endAngle-d.source.startAngle) / 2 + d.source.startAngle - Math.PI/2); })
.attr("y1", function(d, i){ return innerRadius * Math.sin((d.source.endAngle-d.source.startAngle) / 2 + d.source.startAngle - Math.PI/2); })
.attr("x2", function(d,i){ return innerRadius * Math.cos((d.target.endAngle-d.target.startAngle) / 2 + d.target.startAngle - Math.PI/2); })
.attr("y2", function(d,i){ return innerRadius * Math.sin((d.target.endAngle-d.target.startAngle) / 2 + d.target.startAngle - Math.PI/2); })
if (focusedTeamIndex >= 0) {
grads.append("stop")
.attr("offset", "0%")
.attr("stop-color", function(d){ return nodeIsFocusedTeam(d) ? nonFocusedTeamColor(d) : '#00000010'})
}
else {
grads.append("stop")
.attr("offset", "0%")
.attr("stop-color", function(d){ return color(d.source.index)})
grads.append("stop")
.attr("offset", "100%")
.attr("stop-color", function(d){ return color(d.target.index)})
}
svg.append("g")
.attr("fill-opacity", 0.75)
.selectAll("g")
.data(chords)
.join("path")
.attr("d", ribbon)
.attr("fill", d => `url(#${getGradID(d)}`)
.style("mix-blend-mode", "hue")//"multiply")
.append("title")
.text(d => `Trades between ${teamCodes[d.source.index].code} and ${teamCodes[d.target.index].code}`)
svg.append("g")
.attr("font-family", "Arial Narrow, sans-serif")
.attr("font-weight", "900")
.attr("font-size", 15)
.selectAll("g")
.data(chords.groups)
.join("g")
.call(g => g.append("path")
.attr("d", arc)
.attr("fill", d => color(d.index))
.attr("stroke", "#fff"))
.call(g => g.append("text")
.attr("dy", -3)
.append("textPath")
.attr("xlink:href", textId.href)
.attr("startOffset", d => d.startAngle * outerRadius)
.text(d => teamCodes[d.index].code))
.style('opacity', 0.7)
.style('cursor', 'hand')
.on('click', (_, {index}) => setFocusedTeamIndex(index))
.on("mouseover", function(){d3.select(this).style("opacity", "1");})
.on("mouseout", function(){d3.select(this).style("opacity", ".7");})
.call(g => g.append("title")
.text(d => teamCodes[d.index].code));
return svg.node();
}