如何使用 cytoscape 同心布局创建图层

我试图用同心布局创建一个内层和外层。但我不让它工作。

这就是我的样子:

内部和外部节点混淆了。

http://img3.mukewang.com/61dfed3a0001bd9c05150511.jpg

这就是我所期望的:

http://img2.mukewang.com/61dfed4c0001eee405860528.jpg

我的数据:


{

 data: [

  {data: {

    id: 'innerA', level: 1 },

    group: 'nodes'

  },

  ....

  {data: {

    id: 'outA', level: 2 },

    group: 'nodes'

   },

  ....

  {

    data: { source: 'innerA', target: 'outA' },

    group: 'edges',

  },

  ....

  ],

}

还有我的布局


layout: {

  concentric: function( node ){

    return node.data("level");

  },

  levelWidth: function( ){

    return 2;

  },

  name: 'concentric',

  minNodeSpacing: 50,

  }

}

从我所期望的布局中的同心功能来看,将根据节点中的图层属性分配节点。


希望有人有想法。先感谢您。

慕婉清6462132
浏览 479回答 1
1回答

神不在的星期二

首先,布局将更高级别的节点放在中心,因此您的内部节点应该有级别 2,而外部节点应该有级别 1。其次,我不知道 levelWidth 选项是如何工作的,但是使用默认值而不是 2 工作.var cy = window.cy = cytoscape({&nbsp; container: document.getElementById('cy'),&nbsp; style: [{&nbsp; &nbsp; &nbsp; selector: 'node',&nbsp; &nbsp; &nbsp; css: {&nbsp; &nbsp; &nbsp; &nbsp; 'content': 'data(id)'&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; },&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; selector: 'edge',&nbsp; &nbsp; &nbsp; css: {&nbsp; &nbsp; &nbsp; &nbsp; 'curve-style': 'straight',&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; ],&nbsp; elements: [&nbsp; {data: {&nbsp; &nbsp; id: 'innerA', level: 2 },&nbsp; &nbsp; group: 'nodes'&nbsp; },&nbsp; {data: {&nbsp; &nbsp; id: 'innerB', level: 2 },&nbsp; &nbsp; group: 'nodes'&nbsp; },&nbsp; {data: {&nbsp; &nbsp; id: 'innerC', level: 2 },&nbsp; &nbsp; group: 'nodes'&nbsp; },&nbsp; {data: {&nbsp; &nbsp; id: 'innerD', level: 2 },&nbsp; &nbsp; group: 'nodes'&nbsp; },&nbsp;&nbsp;&nbsp; {data: {&nbsp; &nbsp; id: 'outA', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outB', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outC', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outD', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outE', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outF', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outG', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; {data: {&nbsp; &nbsp; id: 'outH', level: 1 },&nbsp; &nbsp; group: 'nodes'&nbsp; &nbsp;},&nbsp; &nbsp;&nbsp; {&nbsp; &nbsp; data: { source: 'innerA', target: 'outA' },&nbsp; &nbsp; group: 'edges',&nbsp; },&nbsp; {&nbsp; &nbsp; data: { source: 'innerB', target: 'outC' },&nbsp; &nbsp; group: 'edges',&nbsp; },&nbsp; {&nbsp; &nbsp; data: { source: 'innerC', target: 'outE' },&nbsp; &nbsp; group: 'edges',&nbsp; },&nbsp; {&nbsp; &nbsp; data: { source: 'innerD', target: 'outG' },&nbsp; &nbsp; group: 'edges',&nbsp; },&nbsp;&nbsp;&nbsp; ],&nbsp; layout: {&nbsp; &nbsp; name: 'concentric',&nbsp; &nbsp; concentric: function( node ){&nbsp; &nbsp; &nbsp; return node.data("level");&nbsp; &nbsp; },&nbsp; &nbsp; minNodeSpacing: 50&nbsp; }&nbsp;&nbsp;});body {&nbsp; font: 14px helvetica neue, helvetica, arial, sans-serif;}#cy {&nbsp; height: 95%;&nbsp; width: 95%;&nbsp; left: 0;&nbsp; top: 0;&nbsp; position: absolute;}<html><head>&nbsp; <meta charset=utf-8 />&nbsp; <meta name="viewport" content="user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, minimal-ui">&nbsp; <script src="https://unpkg.com/cytoscape@3.10.0/dist/cytoscape.min.js">&nbsp; </script></head><body>&nbsp; <div id="cy"></div></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript