首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >cytoscape.js dagre布局中的节点最大大小?

cytoscape.js dagre布局中的节点最大大小?
EN

Stack Overflow用户
提问于 2018-02-25 11:37:11
回答 1查看 832关注 0票数 1

我正在构建的项目的一个主要部分涉及允许用户流畅地创建和编辑DAG。我正在使用React、cytoscape.js、cytoscape edgehandles和dagre布局来完成这项工作,它工作得很好,除了一个恼人的问题。当图只有几个节点时,节点是巨大的!

这是因为我在布局选项中将fit设置为true (默认值)。我需要保留此设置,因为随着图形的增长,我希望它们缩小以适合用户,除非用户选择放大。我只是不想让前1-4个节点太大!有没有办法定义节点的最大高度/宽度,或者控制缩放级别,以便节点从合理的大小开始,只有在必要时才开始变小?

这是我的布局:

代码语言:javascript
复制
cy.layout({
      name: 'dagre',
      ranker: 'longest-path',
      padding: 15
    }).run();

下面是我的风格设置:

代码语言:javascript
复制
const cyConfig = {
  elements: [],
  style: [
    {
      selector: 'node',
      style: {
        'label': 'data(name)',
        'color': '#2C2029',
        'text-valign':'center',
        'text-halign': 'center',
        'font-size': '25px',
        'font-family': 'Nixie One, cursive',
        'shape': 'roundrectangle',
        'background-color': 'mapData(inDegree, 1, 8, rgba(163, 154, 164), rgba(240, 146, 60))',
        'background-opacity': 'mapData(inDegree, 1, 8, .3, 1)',
        'border-color': 'transparent',
        'width': 'label',
        'height': 'label',
        'padding': '7px'
      }
    }, {
      selector: 'edge',
      style: {
        'curve-style': 'bezier',
        'target-arrow-shape': 'triangle',
        'target-arrow-fill': 'hollow',
        'target-arrow-color': '#2C2029',
        'width': '1px',
        'color': '#2C2029',
      }
    }
  ]
};

EN

回答 1

Stack Overflow用户

发布于 2018-02-26 17:45:19

您始终可以像这样定义节点:

代码语言:javascript
复制
style: [
            {
                selector: 'node',
                style: {
                    'shape': 'data(faveShape)',
                    'content': 'data(DisplayName)',
                    'height': 'data(faveHeight)',
                    'width': 'data(faveWidth)',
                    'background-color': 'data(faveColor)',
                    'line-color': '#a8eae5',
                    'font-family': 'Segoe UI', 
                    'font-size': '15px',
                }
            }
]

如果这样做,您可以检查要添加到cytoscape窗口的节点数,然后根据要添加的节点数定义其宽度和高度属性:

代码语言:javascript
复制
jsonNew.push({
        data: {
               id: yourId,
               parent: '',
               faveShape: 'yourShape',
               faveHeight: ((nodes.length > 7) ? nodes.length * 3 : nodes.length * 6),
               faveWidth: ((nodes.length > 7) ? nodes.length * 5 : nodes.length * 10),
               faveColor: '#ffffff'                                       
        },
        position: {
                    x: '',
                    y: ''
        },
        parents: '',
        group: 'nodes',
        removed: false,
        selected: false,
        selectable: true,
        locked: false,
        grabbable: true,
        classes: ''
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48969982

复制
相关文章

相似问题

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