Vis.js 固定节点相对于画布边界的位置
我试图在类似流程图的场景中使用Vis.js 我正在从数据库中获取流程图的信息,希望使用Vis.js帮助我正确地布置流程图节点 但是,我希望开始节点和结束节点始终位于容器左边缘的中心和右边缘的中心 我似乎不知道该怎么做 到目前为止,我的代码在此笔中:Vis.js 固定节点相对于画布边界的位置,vis.js,vis.js-network,Vis.js,Vis.js Network,我试图在类似流程图的场景中使用Vis.js 我正在从数据库中获取流程图的信息,希望使用Vis.js帮助我正确地布置流程图节点 但是,我希望开始节点和结束节点始终位于容器左边缘的中心和右边缘的中心 我似乎不知道该怎么做 到目前为止,我的代码在此笔中: var container = document.getElementById('visualization'); var nodes = []; var edges = []; nodes.push({ id: 1, label
var container = document.getElementById('visualization');
var nodes = [];
var edges = [];
nodes.push({
id: 1,
label: "START",
shape: "box",
fixed: {
x: true,
y: true,
},
x: 100,
y: 100,
});
nodes.push({
id: 2,
label: "test node 2"
});
nodes.push({
id: 3,
label: "test node 3"
});
nodes.push({
id: 4,
label: "test node 4\n Second line"
});
nodes.push({
id: 99,
label: "END",
fixed: true,
shape: "box",
});
edges.push({
from: 1,
to: 2,
label: 'text'
});
edges.push({
from: 1,
to: 3
});
edges.push({
from: 3,
to: 99
});
edges.push({
from: 2,
to: 4
});
edges.push({
from: 4,
to: 99
});
edges.push({
from: 3,
to: 4
});
var data = {
nodes: nodes,
edges: edges
};
var options = {
physics: {
enabled: true,
stabilization: true,
barnesHut: {
avoidOverlap: 1
},
},
edges: {
arrows: {
to: {
enabled: true,
scaleFactor: 1
},
middle: {
enabled: false,
scaleFactor: 1
},
from: {
enabled: false,
scaleFactor: 1
}
},
}
};
var timeline = new vis.Network(container, data, options);
如何确定相对于容器的开始和结束节点的位置,然后让VIS JS处理布局的其余部分 您需要添加
fixed: {
x: true,
y: true
}
到您的节点。我已经这样做了,我的问题是如何指定坐标,以便节点显示在画布上的固定坐标位置上。因此,即使移动/缩放画布,您也希望将它们固定在左右边缘?是的。我正在创建一个流程图。。让开始和结束点头漂浮在页面中间是没有意义的。