3

我想将特定节点(比如我有节点引用)移动到所需位置(比如画布的左上角)。我尝试在示例项目中做类似的事情,他们在用鼠标拖动时移动节点。但这似乎不起作用。我没有看到节点按预期移动。这是我的代码。

$("#someElement").click(function() {
  sys.eachNode(function(node, pt) {
    if (node.name === "specificNode") {
      // moveToOrigin
      var s = arbor.Point(1, 1);
      var p = sys.fromScreen(s);
      node.fixed = true;
      node.p = p;
      node.fixed = false;
      node.tempMass = 1000;
    }
  }
});
4

2 回答 2

1

To move a node to a desired position get the desired position relative to the canvas and set it via particle system's fromScreen(...) function:

var point = point;
var pos = canvas.offset();
var s = arbor.Point(point.x-pos.left, point.x-pos.top);
node.p = particleSystem.fromScreen(s);
于 2013-08-24T02:41:38.133 回答
1

您需要先设置节点的位置,然后再次为节点迭代每个循环。

redraw: function () {
    gfx.clear()

    particleSystem.eachNode(function (node, pt) {
        //var node = particleSystem.getNode("Carrol Wahi")
        if (node.data.color == "yellow") {
            var pos = $(canvas).offset();
            var point = particleSystem.fromScreen(arbor.Point(pos.left + 150, pos.top));
            node._fixed = true;
            node._p = point;
            //console.log("x=" + point.x + ", y=" + point.y);
            node.tempMass = .1
        }
    });

    particleSystem.eachEdge(function (edge, pt1, pt2) {
        //   your code goes here
      }
    particleSystem.eachNode(function (node, pt) {
       //your code goes here
    })

}

于 2015-06-10T11:07:32.357 回答