Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Cytoscape.js预设布局文档_Javascript_Dictionary_Cytoscape.js - Fatal编程技术网

Javascript Cytoscape.js预设布局文档

Javascript Cytoscape.js预设布局文档,javascript,dictionary,cytoscape.js,Javascript,Dictionary,Cytoscape.js,我有一个cytoscape.js图形可以渲染。我感兴趣的是利用预设布局来放置节点。cytoscape.js文档显示了预设布局的以下内容: var options = { name: 'preset', positions: undefined, // map of (node id) => (position obj); or function(node){ return somPos; } zoom: undefined, // the zoom level to set (

我有一个cytoscape.js图形可以渲染。我感兴趣的是利用预设布局来放置节点。cytoscape.js文档显示了预设布局的以下内容:

var options = {
  name: 'preset',
  positions: undefined, // map of (node id) => (position obj); or function(node){ return somPos; }
  zoom: undefined, // the zoom level to set (prob want fit = false if set)
  pan: undefined, // the pan level to set (prob want fit = false if set)
  fit: true, // whether to fit to viewport
  padding: 30, // padding on fit
  animate: false, // whether to transition the node positions
  animationDuration: 500, // duration of animation in ms if enabled
  animationEasing: undefined, // easing of animation if enabled
  ready: undefined, // callback on layoutready
  stop: undefined // callback on layoutstop
};
有人能帮助我理解或举例说明文档中的以下内容是什么意思吗

// map of (node id) => (position obj); or function(node){ return somPos; }
我使用以下列将所有节点存储在MySQL数据库表中

id、起点、终点、x位置、y位置

cytoscape.js位置是否采用如下所示的字典:


{'id':1,{'x':10,'y':45},{'id':2,{'x':21,'y':32}
etc?

这意味着当
位置设置为
未定义时,需要创建一个函数来获取每个节点的位置

例如:

cy.nodes().forEach(函数(n){
var x=n.数据(“x”);
var y=n.数据(“y”);
});
这将返回节点位置

编辑

可以在创建节点时设置节点位置。例如:

var元素;

元素:[{“data”:{“id”:“yourID”,“name”:“name”},“position”{“x”:“0.0”,“y”:“0.0”}]感谢您对原始问题的回答,它更多的是关于如何设置位置而不是获取位置。如果您在元素JSON中定义位置,比如@MFigueredo的示例,那么您只需在init处指定
layout:{name:'preset'}
。默认情况下,预设布局不执行任何操作,只使用已定义的位置。布局的其他功能用于手动指定新位置、使用动画等。