经过检查和记录后发现
mCenterX
和
mCenterY
是
NaN
结果是
d3.forceX
和
d3.forceY
南
.
@VincentDM发现
px
在
width
和
height
下面的内容也可以解决这个问题
mSvgWidth = iTargetElement.attr("width").replace("px","");
mSvgHeight = iTargetElement.attr("height").replace("px","");
svg
和
rect
宽度
和
高度
没有单位。
矩形
一个班,以防万一
rects
添加到
svg格式
mSvg.append("rect")
.attr("width", mSvgWidth)
.attr("height", mSvgHeight)
.attr("class", "background");
调整CSS
rect.background {
fill: none;
stroke: #888;
stroke-width: 2px;
pointer-events: all;
}
将节点添加到列表时
simulation
不再启动。向函数添加调用修复了
function addNode (iNode)
{
// ...
updateSimulation();
// ...
}
因为初始列表是空的,所以链接和节点的构造
g
s可以简化
// Create links structure
mSvg.append("g")
.attr("class", "links");
mLinksRef = mSvg.select(".links").selectAll(".link");
// Create nodes structure
mSvg.append("g")
.attr("class", "nodes")
.selectAll(".node");
mNodesRef = mSvg.select(".nodes").selectAll(".node");
如果您删除
克
g.node
转换将设置在
其结果是属于此节点的所有内容都被转换。
设置
alphaTarget
对于dragend结果,0.1表示模拟需要很长时间才能完成。似乎有一个替代站,但它需要很长的路。
function graphDragended (d)
{
if (!d3.event.active) mSimulation.alphaTarget(0);
d.fx = null;
d.fy = null;
};