虽然启用了自动缩放,但节点仍会移出视图。不会发生自动缩放以保持视图中的所有节点。
我的控制台显示了这个:
interaction: Object
panning: Object
resizing: Object
selection: Object
zooming: Object
autoZoom: true
autoZoomDuration: 500
autoZoomSize: 0.9
doubleClickZoom: 1.5
fingers: true
sensitivity: 1
wheel: true
我使用此功能创建节点
function graphDoubleClick(event){
$("#nodemenu").css("display", "none");
$("#linkmenu").css("display", "none");
if (event.clickNode && event.shiftKey){//test the click was on a node
chart.addData({
nodes:[{
"id":"n"+nextId,
"type":"unknown",
"x":event.chartX,
"y":event.chartY,
"loaded":true,
"style":{"label":"newNode"}
}],
links:[{
"id":"ll"+nextId,
from:event.clickNode.id,
to:"n"+nextId,
"style":{"label":"unknown"}
}]
});
nextId += 1;
}
else if (!event.clickNode && !event.clickLink && event.shiftKey){
chart.addData({
nodes:[{
"id":"n"+nextId,
"loaded":true,
"type":"unknown",
"x":event.chartX,
"y":event.chartY,
"style":{"label":"newNode"}
}]
});
nextId += 1;
};
}
什么可能导致这种行为?
答案 0 :(得分:0)
默认的doubleClick操作是放大,它在内部禁用自动缩放。
在graphDoubleClick的末尾添加event.preventDefault(),你应该没问题。
或者通过设置settings.interaction.zooming.doubleClickZoom = 0来禁用双击缩放。