loveActuallyArcs2 = {
const radius = 8
const container = d3.select(DOM.svg(width+margin.left+margin.right,
height+margin.top+margin.bottom))
const arcGroup = container
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
const nodes = arcGroup.selectAll("nodes")
.data(graphData.nodes)
.enter().append("circle")
.attr("cx", margin.left+300)
.attr("cy", d => yScale(d.name))
.attr("r", radius)
.attr("fill", d=> gender_color(d.gender))
.attr("id", d => d.id)
const nodeLabels = arcGroup.selectAll("nodeLabels")
.data(graphData.nodes)
.enter().append("text")
.attr("x", margin.left+280)
.attr("y", d => yScale(d.name)+5)
.attr("fill", "darkgrey")
.style("text-anchor", "end")
.text(d => d.name)
const actor = arcGroup.selectAll("actor")
.data(graphData.nodes)
.enter().append("text")
.attr("x", margin.left +20)
.attr("y", d => yScale(d.name)+5)
.attr("fill", "white")
.style("text-anchor", "start")
.text(d=> d.actor)
// This code builds up the SVG path element; see nodesAndArcs for details
function buildArc(d) {
let start = yScale(idToNode[d.source].name);
let end = yScale(idToNode[d.target].name);
const arcPath = ['M', margin.left+300, start, 'A', Math.abs(start - end)/2, ',', Math.abs(start-end)/2, 0,0,",",
start < end ? 1: 0, margin.left+300, end].join(' ');
return arcPath;
}
// create the arcs
const arcs = arcGroup.selectAll("arcs")
.data(graphData.links)
.enter().append("path")
.attr("d", d => buildArc(d))
.style("fill", "none")
.attr("stroke", d => color(d.relationship));
// mouseover animations
nodes.on('mouseover', function(d) {
// Highlight selected node
d3.select(this).style("fill", d=>gender_color2(d.gender));
// Highlight arcs
arcs
.style('stroke', function (arcd) {
return arcd.source === d.id || arcd.target === d.id ? d=> color(d.relationship): d=> color(d.relationship);})
.style('stroke-width', function (arcd) {
return arcd.source === d.id || arcd.target === d.id ? 4 : 1;})
// Show actor names
actor
.style('fill', function (actord) {
return actord.name === d.name ? 'steelblue' : 'white' ;});
// Highlight node labels
nodeLabels
.style("fill", function (nodeLabeld){
return nodeLabeld.id == d.id ? 'black' : 'lightgrey';})
.style('font-weight', function (nodeLabeld) {
return nodeLabeld.id == d.id ? 'bold' : 'normal';})
});
// remove highlighting when user mouse moves out of node by restoring default colors and thickness
nodes.on('mouseout', function (d) {
nodes.style("fill", d=> gender_color(d.gender));
arcs.style('stroke', d=>color(d.relationship));
arcs.style('stroke-width', 1);
actor.style('fill','white');
});
return container.node();
}