在Cytoscape.js中设置节点位置

问题描述 投票:4回答:1

我正在使用出色的Cytoscape.js作图。

我以前一直在使用Cola选项,因为它使用力方向。

但是现在我想可视化多个没有连接的图,并意识到fCose在执行此操作方面要好得多。

我现在面临的问题是,当我已经有了坐标时,现在无法set节点位置。

我可以通过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设置为“标准”,并且将randomizeanimate都设置为false

我也尝试添加positions: undefined,但是以上更改均未对节点定位产生任何影响。如何使用fCose实现此目标?

javascript cytoscape.js
1个回答
0
投票

在fCoSE中,如果randomize为true,则首先将节点扩展到随机位置,然后算法尝试寻找图的良好布局。

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

© www.soinside.com 2019 - 2024. All rights reserved.