当前位置:   article > 正文

AntV-G6实现微服务拓扑图_antv g6 拓扑

antv g6 拓扑

G6 是一个简单、易用、完备的图可视化引擎,它在高定制能力的基础上,提供了一系列设计优雅、便于使用的图可视化解决方案。能帮助开发者搭建属于自己的图可视化、图分析、或图编辑器应用。

项目已开源 欢迎 star

ms-topo

递归构建全部上下游

请添加图片描述

切换构建方式

请添加图片描述

核心代码

G6.registerNode(
    'background-animate',
    {
      afterDraw(cfg, group) {
        const r = cfg.size / 2;
        const back1 = group.addShape('circle', {
          zIndex: -3,
          attrs: {
            x: 0,
            y: 0,
            r,
            fill: cfg.color,
            opacity: 0.6,
          },
          name: 'back1-shape',
        });
        const back2 = group.addShape('circle', {
          zIndex: -2,
          attrs: {
            x: 0,
            y: 0,
            r,
            fill: cfg.color,
            opacity: 0.6,
          },
          name: 'back2-shape',
        });
        const back3 = group.addShape('circle', {
          zIndex: -1,
          attrs: {
            x: 0,
            y: 0,
            r,
            fill: cfg.color,
            opacity: 0.6,
          },
          name: 'back3-shape',
        });
        group.sort();
        back1.animate(
            {
              r: r + 20,
              opacity: 0.1,
            },
            {
              duration: 3000,
              easing: 'easeCubic',
              delay: 0,
              repeat: true,
            },
        );
        back2.animate(
            {
              r: r + 20,
              opacity: 0.1,
            },
            {
              duration: 3000,
              easing: 'easeCubic',
              delay: 1000,
              repeat: true,
            },
        ); // 1s delay
        back3.animate(
            {
              r: r + 20,
              opacity: 0.1,
            },
            {
              duration: 3000,
              easing: 'easeCubic',
              delay: 2000,
              repeat: true,
            },
        );
      },
    },
    'circle',
);
G6.registerEdge(
    'arrow-running',
    {
      afterDraw(cfg, group) {
        const shape = group.get('children')[0]
        const arrow = group.addShape('marker', {
          attrs: {
            x: 16,
            y: 0,
            r: 8,
            lineWidth: 2,
            stroke: '#3370ff',
            fill: '#fff',
            symbol: (x, y, r) => {
              return [
                ['M', x - 6, y - 4],
                ['L', x - 2, y],
                ['L', x - 6, y + 4]
              ]
            }
          }
        })

        arrow.animate(
            (ratio) => {
              const tmpPoint = shape.getPoint(ratio)
              const pos = getLabelPosition(shape, ratio)
              let matrix = [1, 0, 0, 0, 1, 0, 0, 0, 1]
              matrix = transform(matrix, [
                ['t', -tmpPoint.x, -tmpPoint.y],
                ['r', pos.angle],
                ['t', tmpPoint.x, tmpPoint.y]
              ])
              return {
                x: tmpPoint.x,
                y: tmpPoint.y,
                matrix
              }
            },
            {
              repeat: true,
              duration: 2000
            }
        )
      },
      setState(name, value, item) {
        const group = item.getContainer();
        const shape = group.get('children')[0];
        if (name === 'active') {
          if (value) {
            shape.attr('stroke', '#5394ef');
          } else {
            shape.attr('stroke', '#C2C8D5');
          }
        }
        if (name === 'selected') {
          if (value) {
            shape.attr('lineWidth', 2);
          } else {
            shape.attr('lineWidth', 2);
          }
        }
      },
    },
    'quadratic'
)
const graph = new G6.Graph({
  container: 'container',
  width,
  height,
  fitCenter: true,
  modes: {
    default: [
      'drag-canvas',
      'zoom-canvas',
      'click-select',
      'drag-node'
    ]
  },
  layout: {
    type: 'dagre',
    ranksep: 60,
    rankdir: 'LR',
    nodesep: 20
  },
  defaultNode: {
    type: 'circle',
    size: 60,
    labelCfg: {
      position: 'bottom'
    }
  },
  defaultEdge: {
    type: 'arrow-running',
    style: {
      endArrow: true,
      lineWidth: 2,
      lineAppendWidth: 15,
      stroke: '#C2C8D5'
    }
  },
  nodeStateStyles: {
    selected: {
      stroke: '#5394ef'
    }
  },
  fitView: true
})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/387374
推荐阅读
相关标签
  

闽ICP备14008679号