function make_b1g_coord_diagram(w) {
let container = d3.create('div').style('width', `${w * width}px`);
let svg = container
.append("svg")
.style('background-color', 'white')
.attr("viewBox", [-0.5 * width, -0.5 * height, 1 * width, 1 * height])
.attr("font-size", 10)
.attr("font-family", "sans-serif");
let chords = chord(M.toArray());
let arcs = svg
.append("g")
.selectAll("g")
.data(chords.groups)
.join("g");
arcs
.append("path")
.attr("fill", d => team_colors(d.index)[0])
.attr("stroke", d => d3.rgb(team_colors(d.index)[0]).darker())
.attr("d", arc1);
arcs
.append("path")
.attr("fill", d => team_colors(d.index)[1])
.attr("stroke", d => d3.rgb(team_colors(d.index)[1]).darker())
.attr("d", arc2);
let ribbons = svg
.append("g")
.attr('opacity', 0.7)
.selectAll("path")
.data(chords)
.join("path")
.attr("d", ribbon)
.attr('class', function(d) {
let team1 = teams[d.source.index].name.replace(/ /g, '');
let team2 = teams[d.target.index].name.replace(/ /g, '');
return `chord ${team1} ${team2}`;
})
.attr("fill", d => team_colors(d.source.index)[0])
.attr("stroke", d => d3.rgb(team_colors(d.source.index)[0]).darker())
.on('mouseenter', function() {
svg.selectAll('.chord').attr('opacity', 0.1);
d3.select(this).attr('opacity', 1);
})
.on('mouseleave', function() {
svg.selectAll('.chord').attr('opacity', 1);
})
.attr('title', function(d) {
let score1 = M.toArray()[d.source.index][d.target.index];
let score2 = M.toArray()[d.target.index][d.source.index];
let team1 = teams[d.source.index].name;
let team2 = teams[d.target.index].name;
return `${team1} ${score1} \n ${team2} ${score2}`;
});
ribbons.nodes().forEach(e =>
tippy(e, {
delay: [200, 100],
duration: [100, 50],
followCursor: true
})
);
let logos = arcs
.append("g")
.selectAll("image")
.data(chords.groups)
.join("image")
.attr("x", function(d) {
let theta = (d.startAngle + d.endAngle) / 2;
return 0.97 * scale(Math.cos(theta - Math.PI / 2));
})
.attr("y", function(d) {
let theta = (d.startAngle + d.endAngle) / 2;
return 0.97 * scale(Math.sin(theta - Math.PI / 2));
})
.attr('width', function(d) {
if (teams[d.index].logo_size) {
return teams[d.index].logo_size;
} else {
return 30;
}
})
.attr('height', function(d) {
if (teams[d.index].logo_size) {
return teams[d.index].logo_size;
} else {
return 30;
}
})
.attr('transform', function(d) {
if (teams[d.index].logo_size) {
let shift = -teams[d.index].logo_size / 2;
return `translate(${shift}, ${shift})`;
} else {
return 'translate(-15,-15)';
}
})
.attr("xlink:href", d => teams[d.index].logo_url)
.on('mouseenter', function(d) {
let this_class = '.' + teams[d.index].name.replace(/ /g, '');
svg.selectAll('.chord').attr('opacity', 0.1);
svg.selectAll(this_class).attr('opacity', 1);
})
.on('mouseleave', function() {
svg.selectAll('.chord').attr('opacity', 1);
})
.attr('title', function(d) {
let name = teams[d.index].name;
let scored = d3.sum(M.toArray()[d.index]);
let scored_against = d3.sum(M.toArray().map(r => r[d.index]));
return `${name} scored ${scored} points against ${scored_against} scored by their opponents.`;
});
logos.nodes().forEach(e =>
tippy(e, {
delay: [200, 100],
duration: [100, 50]
})
);
return container.node();
}