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;
}
同样在默认值中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
为“证明”和两者randomize
和animate
。false
我也尝试添加positions: undefined
,但是上述更改都没有对节点定位产生任何影响。我怎样才能做到这一点fCose
?
解决方案
在 fCoSE 中,如果 randomize 为真,则节点最初会散布到随机位置,然后算法会尝试找到图的良好布局。
如果 randomize 为 false,则算法从节点的当前位置开始。从当前位置开始,我的意思是在每个 cytoscape 节点中找到的位置属性。如果要从所需位置开始布局,首先需要使用node.position()
or将这些位置分配给节点nodes.positions()
,然后使用 randomize: false 开始布局。否则,布局当前不直接接受初始位置。
推荐阅读
- excel - 如何在由类动态创建的组合框上使用 ComboBox_Change() - VBA
- python - 从熊猫数据框创建表
- android - 项目 API 19 之间的 Recyclerview 差距
- flutter - 在文本字段顶部的 fireOS firetv/firestick 上颤振文本字段
- protractor - 使用前摄器运行 e2e 测试用例并且未创建会话
- javascript - JQuery AJAX - 将数据从表单传递到 PHP 脚本
- ruby-on-rails - Rails - 为调试、信息和错误配置单独的日志文件
- python - python中的SQL COALESCE()方法
- c# - Xamarin Form setter FontFamily 在同一文件主题中引用自定义字体
- scala - 通过 UDF、Spark - Scala 加密 CSV 列