我正在尝试使用下面的 javascript 捆绑节点,任何帮助将不胜感激,原始代码可以在下面找到: https://codepen.io/suchibharani/pen/xxbgrKd
function bundleNodes(groupId) {
var bundleFactor = 0.1; // Adjust this value to control the bundling intensity
node
.filter(function(d) { return d.group == groupId; })
.each(function(d) {
var dx = centroid[0] - d.x;
var dy = centroid[1] - d.y;
d.x += dx * bundleFactor;
d.y += dy * bundleFactor;
// Optionally, you can fix the nodes' positions after bundling to prevent them from moving back due to the force simulation.
// d.fx = d.x;
// d.fy = d.y;
});
simulation.alphaTarget(0.3).restart(); // Reheat the simulation to reflect changes
}
我想根据组捆绑节点,真诚感谢任何专家的建议。谢谢你