antv/x6 边添加鼠标悬浮高亮和删除功能

7 篇文章 0 订阅
7 篇文章 1 订阅

效果

在这里插入图片描述

添加悬浮效果和删除工具

this.graph.on('edge:mouseenter', ({ cell }) => {
  let cellId = cell.store.data.source.cell
   let sourceCell = _this.graph.getCellById(cellId)
   cell.attr('line', { stroke: '#cf1322', strokeWidth: 4, strokeDasharray: '0' })
   cell.zIndex = 100000000
   if (sourceCell.store.data.shape === 'CSA') {
     return false
   }
   if (sourceCell.store.data.shape === 'script') {
     let portID = cell.store.data.source.port
     let port = sourceCell.getPort(portID)
     if (port.attrs && port.attrs.noDEL) {
       return false
     }
   }
   cell.addTools([
     {
       name: 'button-remove',
       args: { distance: -40 },
     },
     {
       name: 'target-arrowhead',
       args: {
         attrs: {
           fill: '#1d39c4',
         },
       },
     },
   ])
 })
  • zIndex 设置100000为了让高亮的边在其他边上方,这样点击删除按钮时候更方便。

取消悬浮效果

    this.graph.on('edge:mouseleave', ({ cell }) => {
      console.log(cell)
      cell.removeTools()
      cell.attr('line', { stroke: '#7C8394', strokeWidth: 1, strokeDasharray: '4, 2' })
      cell.zIndex = 0
    })

边删除后的回调函数

    this.graph.on('cell:removed', ({ cell, index, options }) => {
      console.log(cell)
    })
  • 12
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值