G6 icon indicating copy to clipboard operation
G6 copied to clipboard

Edge能实现终点没有节点吗

Open huliyou opened this issue 7 years ago • 1 comments

使用场景是: 从起始节点引出一条边,边的终点没有落在节点上,仍然可以绘制出边。 edge只有source没有target

image

huliyou avatar Jan 07 '19 11:01 huliyou

我用了一个空白不可见的节点作为 target,类似这样

/** 连接用的临时节点 */
G6.registerNode('link-moving-node', {
  draw(item) {
    const group = item.getGraphicGroup();

    return group.addShape('rect', {
      attrs: {
        // 连线的位置和鼠标位置需要错开一点
        // 测试发现 dragend 的时候,如果位置不错开,很容易 end 收到的 item 节点是 edge 本身,
        // 而不是期望的 state node 节点,导致连接错误,甚至会报错
        // dragend 时同样也处理了 不期望节点的判断来兜底
        x: -20,
        y: -20,
        width: 0,
        height: 0,
      },
    });
  },
});

ViccRondo avatar Mar 19 '19 09:03 ViccRondo