javascript - 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 (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}}等等?

最佳答案

这意味着当positions设置为undefined时,您需要创建一个函数来获取每个节点的位置。

例如:

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

应该返回您的节点位置。

编辑

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

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

有关更多信息,请参阅this Cytoscape js 网站上的演示。在这里,他们手动设置位置。

关于javascript - Cytoscape.js 预设布局文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42841293/

相关文章:

dictionary - 名词、动词、形容词等的单独单词列表

cytoscape.js - 在 cytoscape 中显示和隐藏鼠标悬停时的节点信息

javascript - AngularJS View 未从与工厂关联的范围更新

javascript - RCharts - 按类别柱形图选择颜色

javascript - 如果在 IFrame 中打开应用程序宽度不适合窗口

cytoscape.js - 有没有办法在节点内部的顶部显示节点标签?

javascript - cytoscape.js 中的动态节点内容(标签)

javascript - Firebase 实时数据库 - "Error: Client is offline"。 react /NextJS

swift - 如何将符合 Codable 协议(protocol)的对象数组转换为 Dictionary 数组?

python - 将字典的字典展平为 python 中的列表