문제

What I want to do is onClick, change the charge so that nodes are repelled by a higher force, but this is not working:

var force = d3.layout.force()
    .gravity(.05)
    .charge(function(d, i) { return i ? 0 : -2000; })
    .nodes(nodes)
    .size([w, h]);

svg.on("click", function() {
  force = force.charge(function(d, i) { return i ? 0 : -10000; })
  window.setTimeout(function() {
  force = force.charge(function(d, i) { return i ? 0 : -2000; })
  },3000);
});
도움이 되었습니까?

해결책

all you have to do is call force.start which runs through the declared nodes again and changes the charges and other properties on them.

svg.on("click", function() {
  force = force.charge(function(d, i) { return i ? 0 : -50000; })
  force.start()
  window.setTimeout(function() {
  force = force.charge(function(d, i) { return i ? 0 : -2000; })
  force.start()
  },3000);
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top