antv x6 实现连接线流动效果

import { Graph, FunctionExt, Point, Path } from '@antv/x6'
addData() {
  this.graph = new Graph({
      container: document.getElementById('container'), // 
      width: width, // 画布宽度
      height: height, // 画布高度
      grid: {
        // 网格设置
        size: 40, // 网格大小 10px
        visible: true, // 渲染网格背景
        type: 'mesh',
        args: {
          color: '#D0D0D0',
          thickness: 1, // 网格线宽度
          factor: 10
        }
      },
      autoResize: false, // 跟随窗口自动变化大小
      snapline: false, // 对齐线
      connecting: {
        allowBlank: true,
        snap: {
          radius: 20 // 自动吸附
        }
      },
      history: true, // 启动撤销重做功能
      selecting: true
      // background: {
      //   image: require('../../assets/img/fj.jpg')
      // }
    })
   const data = {
        // 节点
        nodes: [{
            id: 'node1',
            zIndex: 10,
            x: 10,
            y: 50,
            shape: 'custom-sc',
            width: 160,
            height: 140,
            ports: this.ports
          },
          {
            id: 'node2',
            zIndex: 10,
            shape: 'custom-sc2',
            x: 80,
            y: -300,
            width: 20,
            height: 80,
            ports: this.ports
          },
          {
            id: 'gif',
            shape: 'custom-gif',
            x: -200,
            y: 100,
            width: 140,
            height: 140,
            ports: this.ports
          }
        ],
        // 边
        edges: [{
          id: '1',
          source: { cell: 'node1', port: 'port1' },
          target: { cell: 'node2', port: 'port2' },
          vertices: [
            // { x: 140, y: 200 }, 
            { x: 90, y: 30 },
            { x: 70, y: 20 },
            { x: 90, y: 10 }
          ],
          shape: 'edge',
          zIndex: 10,
          label: '水流',
          attrs: {
            line: {
              stroke: 'rgba(92,165,238,0)',
              strokeWidth: 5,
              strokeDasharray: 0
              targetMarker: ''
            },
            style: {
              animation: 'ant-line 30s infinite linear'
            }
          }
        }, {
          id: '2',
          source: { cell: 'node1', port: 'port1' },
          target: { cell: 'node2', port: 'port2' },
          vertices: [
            { x: 90, y: 30 },
            { x: 70, y: 20 },
            { x: 90, y: 10 }
          ],
          shape: 'edge',
          zIndex: 10,
          attrs: {
            line: {
              stroke: 'rgba(92,165,238,0.5)',
              strokeWidth: 5,
              strokeDasharray: 0,
              targetMarker: ''
            },
            style: {
              animation: 'ant-line 30s infinite linear'
            }
          }
        }, {
          id: '3',
          source: { cell: 'node1', port: 'port1' },
          target: { cell: 'node2', port: 'port2' },
          vertices: [
            { x: 90, y: 30 },
            { x: 70, y: 20 },
            { x: 90, y: 10 }
          ],
          shape: 'edge',
          zIndex: 10,
          angle: 0, // 旋转
          attrs: {
            line: {
              stroke: 'rgba(92,165,238, 0.4)',
              strokeWidth: 12,
              strokeDasharray: 0,
              targetMarker: ''
            },
            style: {
              animation: 'ant-line 30s infinite linear'
            }
          }
        }]
      }
      this.graph.fromJSON(data)
      // 动画 -- 水流流动效果
      this.setAnimate('1')
},
setAnimate(id) {
    const edges = this.graph.getEdges()
    edges.forEach((edge) => {
      if (edge.id === id) {
        edge.attr('line', {
          strokeDasharray: 5,
          style: {
            animation: 'ant-line 30s infinite linear'
          }
        }) 
      }
    })
  },
// 撤销
  revoke() {
    this.graph.undo()
  }

  // 重做
  redo() {
    this.graph.redo()
  }

  // 重置视图--还原比例
  resetView() {
    this.graph.zoom(this.graph_zoom <= 0 ? Math.abs(this.graph_zoom) : -this.graph_zoom)
    this.mapZoom = 0
    
    this.graph.resize(1300, 820)
    this.setCenter()
  }

  // 地图放大缩小
  mapZoom(type) {
    if (type === '放大') {
      this.graph.zoom(0.1)
      this.mapZoom += 0.1
    } else if (type === '缩小') {
      this.graph.zoom(-0.1)
      this.mapZoom -= 0.1
    }
  }

  // 全屏浏览
  screenView() {
    this.graph.resize(1850, 850)
    this.setCenter()
  }

  // 加载json数据
  loadData(json) {
    this.graph.fromJSON(json)
  }

线条流动动画 

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我就是你的语法糖️

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值