【问题标题】:js.cytoscape generating graph left to rightjs.cytoscape 从左到右生成图
【发布时间】:2023-03-30 03:33:01
【问题描述】:

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

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

code.js文件如下

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' } },

    ]
  },
});

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

请提出解决方案。 谢谢你

【问题讨论】:

    标签: javascript cytoscape.js flowchart


    【解决方案1】:

    截至cytoscape.js-dagre documentation,有一个布局选项可以改变图表的方向。只需添加到布局中:

    layout: {
        name: 'dagre'
        rankDir: 'LR', // 'TB' for top to bottom flow, 'LR' for left to right. default is undefined, making it plot top-bottom
    },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 2022-01-13
      • 2012-01-30
      相关资源
      最近更新 更多