arc_plot = {
const radius =8
const svg = d3.select(DOM.svg(width+margin.left+margin.right,
height+margin.top+margin.bottom))
.attr("viewBox", [0, 0, width, 400])
.attr("font-family", "sans-serif")
.attr("align", "center")
.attr("justify-content", "center")
.attr("text-anchor", "middle")
.call(d3.zoom().on("zoom", function () {
svg.attr("transform", d3.event.transform)
}))
function zoomed({transform}) {
svg.svg("transform", transform);
}
const arcGroup = svg
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")")
const nodeLabels = arcGroup.selectAll("nodeLabels")
.data(graphData.nodes.sort(function(x, y){
return d3.descending(x.group, y.group);
}))
.enter().append("text")
.attr("x", margin.left+280)
.attr("y", d => yScale(d.label)+5)
.attr("fill", "black")
.style("text-anchor", "end")
.text(d => d.label)
// create the nodes
const nodes = arcGroup.selectAll("nodes")
.data(graphData.nodes.sort(function(x, y){
return d3.descending(x.group, y.group);
}))
.enter().append("circle")
.attr("cx", margin.left+300)
.attr("cy", d => yScale(d.label))
.attr("r", radius)
.attr("fill", d=> group_color(d.group))
.attr("id", d => d.id)
// This code builds up the SVG path element; see nodesAndArcs for details
function buildArc(d) {
let start = yScale(idToNode[d.source].label);
let end = yScale(idToNode[d.target].label);
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.predicate));
// mouseover animations
nodes.on('mouseover', function(d) {
// Highlight selected node
d3.select(this).style("fill", d=>group_color2(d.group));
// Highlight arcs
arcs
.style('stroke', function (arcd) {
return arcd.source === d.id || arcd.target === d.id ? d=> color(d.predicate): d=> color(d.predicate);})
.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.label === d.label ? 'steelblue' : 'white' ;});
// Highlight node labels
nodeLabels
.style("fill", function (nodeLabeld){
return nodeLabeld.id == d.id ? 'black' : 'black';})
.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=> group_color(d.group));
arcs.style('stroke', d=>color(d.predicate));
arcs.style('stroke-width', 1);
// actor.style('fill','white');
});
return svg.node();
}