Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
D3.js D3画布强制导向布局底部问题_D3.js - Fatal编程技术网

D3.js D3画布强制导向布局底部问题

D3.js D3画布强制导向布局底部问题,d3.js,D3.js,我试图在布局中拖动时包含/绑定节点。 我尝试修改示例并添加了以下代码: function dragstarted() { if (!d3.event.active) simulation.alphaTarget(0.3).restart(); d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.subject.x)) ; d3.event.subject.fy = Math.max(10, Math.min

我试图在布局中拖动时包含/绑定节点。 我尝试修改示例并添加了以下代码:

function dragstarted() {
  if (!d3.event.active) simulation.alphaTarget(0.3).restart();
  d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.subject.x)) ;
  d3.event.subject.fy = Math.max(10, Math.min(width - 10, d3.event.subject.y)) ;
}

function dragged() {
  d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.x));
  d3.event.subject.fy = Math.max(10, Math.min(width - 10, d3.event.y));
}

虽然我能够将移动限制在顶部、左侧和右侧方向,但底部拖动似乎有问题;到达矩形底部后不会停止。请提供帮助。

我想您刚才在x轴和y轴上使用了
width
变量,这是一个错误。对于y轴,使用
高度
变量应该可以,如下所示:

function dragstarted() {
  if (!d3.event.active) simulation.alphaTarget(0.3).restart();
  d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.subject.x)) ;
  d3.event.subject.fy = Math.max(10, Math.min(height - 10, d3.event.subject.y)) ;
}

function dragged() {
  d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.x));
  d3.event.subject.fy = Math.max(10, Math.min(height - 10, d3.event.y));
}

我猜您刚才犯了一个错误,将
width
变量用于x轴和y轴。对于y轴,使用
高度
变量应该可以,如下所示:

function dragstarted() {
  if (!d3.event.active) simulation.alphaTarget(0.3).restart();
  d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.subject.x)) ;
  d3.event.subject.fy = Math.max(10, Math.min(height - 10, d3.event.subject.y)) ;
}

function dragged() {
  d3.event.subject.fx = Math.max(10, Math.min(width - 10, d3.event.x));
  d3.event.subject.fy = Math.max(10, Math.min(height - 10, d3.event.y));
}