chart = ForceGraph(miserables, {
nodeId: d => d.id,
nodeGroup: d => d.group,
nodeTitle: d => `${d.id}\n${d.group}`,
linkStrokeWidth: l => Math.sqrt(l.value),
width,
height: 600,
invalidation,
nodeLabel: d => d.id,
onNodeHover: (node, prevNode) => {
if (node) {
const tooltip = document.createElement('div');
tooltip.innerHTML = `<b>${node.id}</b><br/>Group: ${node.group}`;
tooltip.style.position = 'absolute';
tooltip.style.top = `${node.y + 10}px`;
tooltip.style.left = `${node.x + 10}px`;
tooltip.style.backgroundColor = 'white';
tooltip.style.padding = '5px';
tooltip.style.border = '1px solid black';
tooltip.style.borderRadius = '5px';
tooltip.id = 'node-tooltip';
document.body.appendChild(tooltip);
} else {
const tooltip = document.getElementById('node-tooltip');
if (tooltip) {
tooltip.remove();
}
}
}
})