G6 icon indicating copy to clipboard operation
G6 copied to clipboard

箭头被节点挡住

Open zhxzhx opened this issue 1 year ago • 2 comments

问题描述

箭头被节点挡住

重现链接

重现步骤

image

箭头显示的位置是节点的开头位置,箭头被节点挡住了,但是把我写的代码放在编辑器里面是可以显示出来箭头的,如下图

我看编辑器也是4.8.7的版本,我安装也是 4.8.7的版本 "@antv/g6": "^4.8.7",

image

预期行为

da7cb10345167c2b6c97f65f9d0bf99

平台

  • 操作系统: [macOS, Windows, Linux, React Native ...]
  • 网页浏览器: [Google Chrome, Safari, Firefox]
  • G6 版本: [4.5.1 ... ]

屏幕截图或视频(可选)

补充说明(可选)

G6.registerNode('card-node', { draw(cfg, group) { // const t: any = this // const styles = t.getShapeStyle(cfg) const { labelCfg = {} } = cfg

const w = cfg.size[0]
const h = cfg.size[1]

const keyShape = group.addShape('rect', {
  attrs: {
    // ...styles,
    x: -w / 2,
    y: -h / 2,
    width: w, //200,
    height: h, // 60
    fill:
      cfg.status == 1
        ? '#52c41a'
        : cfg.status == 2
        ? '#5f95ff'
        : '#808080'
  }
})
if (cfg.name) {
  group.addShape('text', {
    attrs: {
      ...labelCfg.style,
      text:
        cfg.name.split('&')[0].length > 8
          ? cfg.name.substring(0, 8) + '...'
          : cfg.name.split('&')[0],
      y: cfg.name.indexOf('&') >= 0 ? -10 : 0,
      textAlign: 'center',
      textBaseline: 'middle'
    }
  })
  group.addShape('text', {
    attrs: {
      ...labelCfg.style,
      text: cfg.name.split('&')[1],
      y: 22,
      textAlign: 'center'
    }
  })
  if (cfg.children && cfg.children.length) {
    group.addShape('rect', {
      attrs: {
        x: 68,
        y: -10,
        width: 16,
        height: 16,
        stroke: 'rgba(0, 0, 0, 0.25)',
        cursor: 'pointer',
        fill: '#fff',
        radius: 8
      },
      name: 'collapse-back',
      modelId: cfg.id
    })
    group.addShape('text', {
      attrs: {
        x: 80,
        y: 0,
        textAlign: 'center',
        textBaseline: 'middle',
        text: cfg.collapsed ? '+' : '-',
        fontSize: 20,
        cursor: 'pointer',
        fill: 'rgba(0, 0, 0, 0.25)'
      },
      name: 'collapse-text',
      modelId: cfg.id
    })
  }
}
return keyShape

}, setState(name, value, item) { if (name === 'collapse') { const group = item.getContainer() const collapseText = group.find( (e) => e.get('name') === 'collapse-text' ) if (collapseText) { if (!value) { collapseText.attr({ text: '-' }) } else { collapseText.attr({ text: '+' }) } } } } });

const data = { id: 'ffff', name: '北京能源ffff', echoDisplayId: null, status: 1, nextNodeId: '0', children: [] };

const container = document.getElementById('container'); const width = container.scrollWidth-8; const height = container.scrollHeight * 30 || 500;

const graph = new G6.TreeGraph({ container: 'container', width, height, modes: { default: ['drag-canvas','zoom-canvas'], }, defaultNode: { type: 'card-node', size: [160, 50], labelCfg: { style: { fill: '#fff', fontSize: 16 } } }, defaultEdge: { type: 'cubic-horizontal', // 线的展示方式 style: { startArrow: true, stroke: '#a2b1c3' } }, layout: { type: 'indented', direction: 'LR', dropCap: false, indent: 300, getHeight: function getHeight() { return 20 } } });

graph.data(data); graph.render(); graph.fitView();

zhxzhx avatar Jun 08 '23 05:06 zhxzhx

anchorPoints 了解一下哈 https://g6.antv.antgroup.com/manual/middle/elements/nodes/anchorpoint

Yanyan-Wang avatar Jun 08 '23 08:06 Yanyan-Wang

我也遇到类似的问题,我自定义了节点并拓展自 ‘circle’,最后发现是 KeyShape 的尺寸过小导致的,节点 KeyShape 应该由 size 属性控制,你可以检查一下是否正确?

另外好像也可能和 'defaultNode' 的配置有关,我只有设置为 'defaultNode' 的自定义节点会出现这样的问题,移除之后就没问题了。

KaygNas avatar Jul 20 '23 07:07 KaygNas

This issue has been closed because it has been outdate for a long time. Please open a new issue if you still need help.

这个 issue 已经被关闭,因为 它已经过期很久了。 如果你仍然需要帮助,请创建一个新的 issue。

github-actions[bot] avatar Jul 05 '24 08:07 github-actions[bot]