chart = {
const toolTip = d3.select("body").selectAll('div.tool-tip')
.data([1]).join("div")
.attr("class", "tool-tip")
.style("opacity", 0);
const simulation = d3.forceSimulation(nodes)
.force("link", d3.forceLink(links).id(d => d.id).distance(d => {return forceVariables.nodeDistance}))
.force("charge", d3.forceManyBody().strength(d => forceVariables.charge))
.force("x", d3.forceX())
.force("y", d3.forceY())
.force('collision', d3.forceCollide().radius(getRadius))
const svg = d3.create("svg")
.attr("viewBox", [-width / 2, -height / 2, width, height]);
const link = svg.append("g")
.attr("stroke", "#999")
.attr("stroke-opacity", 0.6)
.selectAll("line")
.data(links)
.join("line")
.attr("stroke-width", 4);
const g = svg.append("g")
const defs = svg.append('defs')
.selectAll('clipPath')
.data([{ name: 'group'}])
.join('clipPath')
.attr('id', 'group-clip')
.append('circle')
.attr('r', d => forceVariables.nodeRadius - 2);
const node = g.append("g")
.selectAll("g")
.data(nodes)
.join("g")
.attr("data-name", d => d.name)
.attr("fill", "none")
.on("mouseover", function(event, d) {
toolTip.style("opacity", 1);
d3.select(this).style("cursor", "pointer");
})
.on("mouseout", function(event, d) {
toolTip.transition().duration(500).style('opacity', 0);
webIt(d, "out", nodes, link) //add css to illustrate all the connections
// d3.select(this)
// .style('stroke', "") //#72798C this is one of the Net Element Colors if we want to use it
// .style("stroke-opacity", "")
// .style("stroke-width", "");
})
.on("touchmove mousemove", function(event, d) {
buildToolTip(event, d, "node", toolTip);
webIt(d, "in", node, link)
})
.on("click", function(event, d){
d.fx = null;
d.fy = null;
window.open(d.url,d.name);
}).call(drag(simulation));
const cir = node
.append('circle')
.attr("id", d => d.id)
.attr('r', d => getRadius(d.group))
.attr("stroke", "#fff")
.attr("stroke-width", 1.5)
.attr('fill', '#999')
const img = node
.append('image')
.attr('xlink:href', function(d) {
let img = d.icon
return img
})
.attr('clip-path', d => `url(#group-clip)`)
.attr('width', d => getRadius(d.group) * 2)
.attr('height', d => getRadius(d.group) * 2)
.attr('x', d => getRadius(d.group) * -1)
.attr('y', d => getRadius(d.group) * -1)
.on("mouseover", function(event, d) {
let id = "#" + d.id
d3.select(id)
.style('stroke', "#18aef9").style('stroke-width', 6).style("stroke-opacity", 1);
})
.on("mouseout", function(event, d) {
let id = "#" + d.id
d3.select(id)
.style('stroke', "#fff").style('stroke-width', 1.5).style("stroke-opacity", 1)
});
// //add the mouseover functionality for the links: make tooltips and highlight links and nodes
// link.on("mouseover", function(event, d) {
// toolTip.style("opacity", 1);
// })
simulation.on("tick", () => {
link
.attr("x1", d => d.source.x)
.attr("y1", d => d.source.y)
.attr("x2", d => d.target.x)
.attr("y2", d => d.target.y);
// node.attr("cx", d => d.x)
// .attr("cy", d => d.y);
node.attr('transform', function(d) {
// d.x = Math.max(getRadius(d), Math.min(width - getRadius(d), d.x));
// d.y = Math.max(getRadius(d), Math.min(height - getRadius(d), d.y));
return `translate(${d.x},${d.y})`
});
});
invalidation.then(() => simulation.stop());
return svg.node();
}