antvis/G6

如何delete/remove shape? #4760

neolee6053 posted onGitHub

问题描述

我加了个shape进节点里。但如何delete/remove呢?因为这是用户可以自己加的. G6有deleteShape/removeShape 吗?或者得控制visibility? image

这是我的code,大概就是在update里,加进shape

update(cfg, node) { //@ts-ignore const update = G6.Shape.Node.circle.update.bind(this); update(cfg, node); const group = node.getContainer(); if (cfg.tag) { const nodeSize = ((Array.isArray(cfg.size) ? cfg.size[0] : cfg.size) || 15); const tagSize = nodeSize / 3; group.addShape('circle', { attrs: { x: -nodeSize / 2, y: -nodeSize / 2, r: tagSize, fill: cfg.nodeIconColor as string, lineWidth: 0.5, //stroke: '#FFFFFF', }, name: 'typeNode-tag-circle', });


graph.updateItem(n, { tag: true, nodeIcon: this.selectedIconValue, nodeIconColor : this.nodeIconColor });

重现链接

https://codesandbox.io/s/new

重现步骤

如上

预期行为

如上

平台

  • 操作系统: [ Windows]
  • 网页浏览器: [Firefox]
  • G6 版本: [4.8.15]

屏幕截图或视频(可选)

No response

补充说明(可选)

No response


找到一个办法 group?.get('children').find(c => c.get('name') == 'typeNode-tag-circle').remove();

posted by neolee6053 almost 2 years ago

自定义节点的话,就根据配置来进行图形的显示/隐藏/新增/移除操作 shape.remove() 移除 shape.hide() 隐藏 shape.show() 展示

posted by Yanyan-Wang over 1 year ago

Fund this Issue

$0.00
Funded

Pull requests