简体   繁体   English

Cytoscape.js预设布局文档

[英]Cytoscape.js Preset Layout Documentation

I have a cytoscape.js graph that renders. 我有一个渲染的cytoscape.js图。 I'm interested in leveraging the preset layout to place the nodes. 我对利用预设布局放置节点感兴趣。 The cytoscape.js documentation shows the following for the preset layout: 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
};

Can some one help me understand or give an example of what the documentation means when it says the following 当有人说以下内容时,能否有人帮助我理解或举例说明文档的含义?

// map of (node id) => (position obj); or function(node){ return somPos; }

I store all the nodes in a MySQL database table with the following columns 我将所有节点存储在带有以下列的MySQL数据库表中

id, origin, destination, x position, y position

Does the cytoscape.js positions take a dictionary that looks like this: cytoscape.js位置是否采用如下形式的字典:

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

This means when the positions is set as undefined you need to create a function to get the positions of each node. 这意味着当positions设置为undefined您需要创建一个函数来获取每个节点的位置。

For example: 例如:

 cy.nodes().forEach(function(n){
    var x = n.data("x");
    var y = n.data("y");
 });

This should return your node position. 应该返回您的节点位置。

EDIT 编辑

You can set the node position when you are creating it. 您可以在创建节点时设置它的位置。 For example: 例如:

  var elements; elements: [{"data":{"id":"yourID","name":"name"},"position"{"x":"0.0","y":"0.0"}}]; 

For more, see this Demo on Cytoscape js site. 有关更多信息,请参见Cytoscape js网站上的演示。 Here they set the position manually. 他们在这里手动设置位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM