[英]Set node position in Cytoscape.js
我正在使用出色的Cytoscape.js進行繪圖。
我以前一直在為此使用可樂選項,因為它使用力方向。
然而,我現在想可視化多個沒有連接的圖表,並意識到fCose在這方面做得更好。
我現在面臨的問題是,當我已經有坐標可以設置節點位置時,我現在無法設置節點位置。
通過在布局選項中執行以下操作,我能夠使用Cola
實現這一目標 -
name: 'cola',
padding: layoutPadding,
nodeSpacing: 40,
edgeLengthVal: 20,
animate: false, // setting this to false
randomize: false, // and this to false allowed me to manually set the node position coordinates
maxSimulationTime: maxLayoutDuration,
boundingBox: {
x1: 0,
y1: 0,
x2: 10000,
y2: 10000
},
edgeLength: function (e) {
let w = e.data('weight');
return w;
}
同樣在Cola
的默認positions
設置為undefined
,我假設這意味着如果傳入坐標,它們將被相應地設置。
然而,我的問題在於fCose
,無論我做什么,當傳遞其中的節點坐標時,渲染時的影響為零。
在fCose
的默認值中,我看到了三個變量,我認為如果我改變了會產生影響 -
quality: "default",
// Use random node positions at beginning of layout
// if this is set to false, then quality option must be "proof"
randomize: true,
// Whether or not to animate the layout
animate: true,
所以我將quality
設置為“proof”,並將randomize
和animate
為false
。
我也嘗試添加positions: undefined
,但是上述更改都沒有對節點定位產生任何影響。 如何使用fCose
實現這一目標?
在 fCoSE 中,如果 randomize 為真,則節點最初會散布到隨機位置,然后算法會嘗試找到圖的良好布局。
如果 randomize 為 false,則算法從節點的當前位置開始。 從當前的 position 來看,我的意思是在每個 cytoscape 節點中找到的 position 屬性。 如果要從所需位置開始布局,首先需要使用node.position()
或nodes.positions()
將這些位置分配給節點,然后使用 randomize: false 開始布局。 否則,布局當前不直接接受初始位置。
我必須用 cytoscape js 解決同樣的問題,我通過使用“預設”布局選項實現了它。
如果您想在元素 JSON 中自己指定節點位置,您 > 可以使用預設布局 - 默認情況下它不設置任何位置,將 > 您的節點留在當前位置(即在 >initialisation time 在 options.elements 中指定)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.