Javascript d3力布局中的动态曲线

Javascript d3力布局中的动态曲线,javascript,d3.js,force-layout,bezier,Javascript,D3.js,Force Layout,Bezier,我想有一个动态贝塞尔曲线的线在一个部队布局像这样,可以在d3?看到这个,但使用圆弧。 我对算法一无所知,有人有主意吗 我已经看到了这个库,使用这个algorytm可以工作 function tick() { path.attr("d", function (d) { var coordinatesP = findEdgeControlPoints(d); return "M" + d.source.x + "," + d.source.y + "

我想有一个动态贝塞尔曲线的线在一个部队布局像这样,可以在d3?看到这个,但使用圆弧。 我对算法一无所知,有人有主意吗

我已经看到了这个库,使用这个algorytm可以工作

function tick() {
     path.attr("d", function (d) {
          var coordinatesP = findEdgeControlPoints(d);
          return "M" + d.source.x + "," + d.source.y + "S" + coordinatesP.xp + "," + coordinatesP.yp + " " + d.target.x + "," + d.target.y;
     });
     hashTable = {};
          nodes.attr("cx", function (d) { return d.x; })
               .attr("cy", function (d) { return d.y; });
}

var findEdgeControlPoints = function (d) {
        var midPointX = (d.source.x + d.target.x) / 2;
        var midPointY = (d.source.y + d.target.y) / 2;

        var displacementX, displacementY;

        displacementX = d.target.y - d.source.y;
        displacementY = d.source.x - d.target.x;

        var displacementLength = Math.sqrt(displacementX * displacementX + displacementY * displacementY);

        displacementX /= displacementLength;
        displacementY /= displacementLength;

        var distanceFromMidpoint = findPathDeltaControlPoint(d);


        var xp = midPointX + displacementX * distanceFromMidpoint;
        var yp = midPointY + displacementY * distanceFromMidpoint;

        return {xp : xp, yp : yp};

    };
    var findPathDeltaControlPoint = function (edge) {
        /*caso statico il primo al centro e tutti gli altri ai lati*/
        /*conto le occorrenze */
        var pairId,
            delta,
            TICK = 20;
        pairId = edge.source.id > edge.target.id ?
                edge.target.id + '-' + edge.source.id :
                edge.source.id + '-' + edge.target.id;

        if (hashTable[pairId] == undefined) {
            hashTable[pairId] = [];
        }
        if (edge[pairId] == undefined) {
            edge[pairId] = [];
        }
        if (edge[pairId].length == 0) {
            edge[pairId].push(pairId);
        }
        hashTable[pairId].push(edge);
        // Ceck if is the first occurence
        var pairIdOccurence = hashTable[pairId].length;
        if (pairIdOccurence == 1) {
            delta = 0;
        } else if (pairIdOccurence > 1) {
            // Check if is equal
            if (pairIdOccurence % 2 == 0) {
                delta = (TICK * pairIdOccurence) / 2;
            } else {
                delta = -((TICK * (pairIdOccurence - 1)) / 2);
            }
        }
        return delta;
    };

你说的“动态行为”是什么意思?是的,但我不确定它的动态是什么。你想要的只是一条曲线吗?我已经编辑了这个问题,你链接到的示例如何不能满足你的要求?不,因为圆弧行为不同于贝塞尔曲线行为,