在 Cytoscape.js 中设置节点位置

Ebi*_*ser 5 javascript 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;
    }
Run Code Online (Sandbox Code Playgroud)

同样在默认值中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,
Run Code Online (Sandbox Code Playgroud)

所以我设置quality为“证明”,并都randomizeanimatefalse

我也尝试添加positions: undefined,但是上述更改均未对节点定位产生任何影响。我怎样才能做到这一点fCose

Has*_*lcı 1

在 fCoSE 中,如果 randomize 为 true,节点最初会分布到随机位置,然后算法尝试找到良好的图形布局。

如果 randomize 为 false,算法从节点的当前位置开始。从当前位置开始,我的意思是在每个 cytoscape 节点中找到的位置属性。如果要从所需位置开始布局,首先需要使用node.position()或将这些位置分配给节点nodes.positions(),然后使用 randomize: false 开始布局。否则,布局当前不直接接受初始位置。