首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >js.cytoscape生成图从左到右

js.cytoscape生成图从左到右
EN

Stack Overflow用户
提问于 2018-08-21 11:13:06
回答 1查看 1.3K关注 0票数 3

我使用的是js.cytoscape,需要从左到右生成一个图形。

当我使用布局时,它会从上到下生成图表。

code.js文件如下所示

代码语言:javascript
复制
var cy = window.cy = cytoscape({
  container: document.getElementById('cy'),

  boxSelectionEnabled: false,
  autounselectify: true,

  layout: {
    name: 'dagre'
  },

  style: [
    {
      selector: 'node',
      style: {
        'content': 'data(id)',
        'text-opacity': 0.5,
        'text-valign': 'center',
        'text-halign': 'right',
        'background-color': '#11479e'
      }
    },

    {
      selector: 'edge',
      style: {
        'curve-style': 'bezier',
        'width': 4,
        'target-arrow-shape': 'triangle',
        'line-color': '#9dbaea',
        'target-arrow-color': '#9dbaea'
      }
    }
  ],

  elements: {
    nodes: [
      { data: { id: 'n0' } , position: { x: 0, y: 0 }  },
      { data: { id: 'n1' } , position: { x: 100, y: 0 } },
      { data: { id: 'n2' } , position: { x: 200, y: 0 } }

    ],
    edges: [
      { data: { source: 'n0', target: 'n1' } },
      { data: { source: 'n1', target: 'n2' } },

    ]
  },
});

当您将布局设置为“预设”时,聊天将从左到右与给定位置生成。但是,当它假设使用用户给定的数据动态生成图表时,不可能定位所有的节点。

请提出解决办法。谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-22 19:29:05

cytoscape.js-dagre文档中,有一个布局选项可以更改图形的方向。只需添加到布局:

代码语言:javascript
复制
layout: {
    name: 'dagre'
    rankDir: 'LR', // 'TB' for top to bottom flow, 'LR' for left to right. default is undefined, making it plot top-bottom
},
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51947430

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档