2021-7-13 动画开始

76

有一种水博客的感觉。。。
就记录一下写的动画吧,用环路检测,安装了antv的算法包

import { detectDirectedCycle } from '@antv/algorithm'
// import { detectDirectedCycle, detectAllCycles } from '@antv/algorithm'
vertifyCircle () {
      const circle = detectDirectedCycle(this.model)
      console.log('circle', circle)
      if (circle) {
        this.circleNodeArr = Object.keys(circle)
        console.log('this.circleNodeArr', this.circleNodeArr)
        const lastnode = this.graph.getCellById(this.circleNodeArr[1])
        lastnode.isfirst = 1
        this.graph.trigger('signal', lastnode)
      }
    },
Object.keys() //键,冒号前的
Object.value() //值,冒号后的

遇到了一个问题就是他不会从第一个我指定的节点出发高亮,所以添加了isfirst来判断
这个是节点高亮

flash (cell) {
      const cellView = this.graph.findViewByCell(cell)
      if (cellView) {
        cellView.highlight()
        setTimeout(() => cellView.unhighlight(), 300)
      }
    },
this.graph.on('signal', cell => {
        if (cell.isEdge()) {
          const view = this.graph.findViewByCell(cell)
          if (view) {
            const token = Vector.create('circle', { r: 8, fill: '#feb662' })
            const target = cell.getTargetCell()
            setTimeout(() => {
              view.sendToken(token.node, 400, () => {
                if (target) {
                  this.graph.trigger('signal', target)
                }
              })
            }, 300)
          }
        } else {
          if (cell.isfirst === 1) {
            console.log('first')
            cell.isfirst = 0
          } else {
            this.flash(cell)
          }
          const edges = this.graph.model.getConnectedEdges(cell, {
            outgoing: true
          })
          const theEdge = edges.find(item =>
            this.circleNodeArr.includes(item.store.data.target.cell)
          )
          this.graph.trigger('signal', theEdge)
        }
      })

这个是监听,动画代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值