在 d3js 中捆绑节点

问题描述 投票:0回答:1

我正在尝试使用下面的 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
}
javascript java d3.js error-handling encoding
1个回答
0
投票

我想根据组捆绑节点,真诚感谢任何专家的建议。谢谢你

© www.soinside.com 2019 - 2024. All rights reserved.