antv X6

graph配置项

https://x6.antv.antgroup.com/api/graph/graph

力导向图

https://x6.antv.antgroup.com/examples/layout/general#force

路由router

https://x6.antv.antgroup.com/api/registry/router

initGraph () {
  // https://x6.antv.antgroup.com/api/graph/graph
  this.graphIns = new Graph({
    container: document.getElementById('container'),
    // width: 800,
    // height: 600,
    background: {
      color: '#F2F7FA',
    },
    autoResize:true, // 是否监听容器大小改变,并自动更新画布大小。默认false
    // https://x6.antv.antgroup.com/api/graph/grid
    grid: {
      visible: true, // 网格默认不可见
      size: 10, // 网格大小 10px
      type: 'doubleMesh', // dot 点状网格。(默认值)  fixedDot  mesh 网状网格。 doubleMesh双线网状网格。
      args: [
        {
          color: '#eee', // 主网格线颜色
          thickness: 1, // 主网格线宽度
        },
        {
          color: '#ddd', // 次网格线颜色
          thickness: 1, // 次网格线宽度
          factor: 4, // 主次网格线间隔
        },
      ],
    },
    panning: true, // 画布是否可以拖拽平移,默认禁用。
    mousewheel: true, // 鼠标滚轮缩放,默认禁用。
    // 连线选项。类似defaultEdge的
    connecting: {
      // router: 'orth', // normal orth manhattan  oneSide metro  er
     /* router:{
        name: 'orth',
        args: {
          // padding: {
          //   bottom: 24,
          //   top:24,
          //   left:24,
          //   right:24,
          // },
          // padding:24,
          padding:{
            vertical:24,
            horizontal:24,
          }
        },
      },*/
      router:{
        name: 'er',
        // args: {
        //   // offset: 12,
        //   offset: 'center',
        // },
      },

      // connector: 'rounded',
      connectionPoint: 'anchor',
      // snap:true,
    },
  })

  const mockData ={
    "nodes": [
      {
        "id": "1722565963387195392",
        "label": "企业信息同步测试4"
      },
      {
        "id": "1727253635897049088",
        "label": "ks电能表一级-01"
      },
      {
        "id": "1727255697414242304",
        "label": "ks电能表一级-02"
      },
      {
        "id": "1731968551085125632",
        "label": "一级03"
      },
      {
        "id": "1727253787416281088",
        "label": "电能表二级-01"
      },
      {
        "id": "1731954552142540800",
        "label": "ks二级02"
      },
      {
        "id": "1727254037606514688",
        "label": "ks电能表三级-01"
      },
      {
        "id": "1727259731038650368",
        "label": "ks电能表三级-03"
      },
      {
        "id": "1727257737720840192",
        "label": "电能表三级-02"
      },
      {
        "id": "1727260183792795648",
        "label": "电能表四级-01"
      }
    ],
    "edges": [
      {
        "source": "1722565963387195392",
        "target": "1727253635897049088"
      },
      {
        "source": "1722565963387195392",
        "target": "1727255697414242304"
      },
      {
        "source": "1722565963387195392",
        "target": "1731968551085125632"
      },
      {
        "source": "1727253635897049088",
        "target": "1727253787416281088"
      },
      {
        "source": "1727253635897049088",
        "target": "1731954552142540800"
      },
      {
        "source": "1727253787416281088",
        "target": "1727254037606514688"
      },
      {
        "source": "1727253787416281088",
        "target": "1727259731038650368"
      },
      {
        "source": "1727253787416281088",
        "target": "1727257737720840192"
      },
      {
        "source": "1727254037606514688",
        "target": "1727260183792795648"
      },
      {
        "source": "1727259731038650368",
        "target": "1727260183792795648"
      },
      {
        "source": "1727257737720840192",
        "target": "1727260183792795648"
      },
      {
        "source": "1731954552142540800",
        "target": "1727254037606514688"
      },
      {
        "source": "1731954552142540800",
        "target": "1727259731038650368"
      },
      {
        "source": "1731954552142540800",
        "target": "1727257737720840192"
      },
      {
        "source": "1727254037606514688",
        "target": "1727260183792795648"
      },
      {
        "source": "1727259731038650368",
        "target": "1727260183792795648"
      },
      {
        "source": "1727257737720840192",
        "target": "1727260183792795648"
      },
      {
        "source": "1727255697414242304",
        "target": "1727253787416281088"
      },
      {
        "source": "1727255697414242304",
        "target": "1731954552142540800"
      },
      {
        "source": "1727253787416281088",
        "target": "1727254037606514688"
      },
      {
        "source": "1727253787416281088",
        "target": "1727259731038650368"
      },
      {
        "source": "1727253787416281088",
        "target": "1727257737720840192"
      },
      {
        "source": "1727254037606514688",
        "target": "1727260183792795648"
      },
      {
        "source": "1727259731038650368",
        "target": "1727260183792795648"
      },
      {
        "source": "1727257737720840192",
        "target": "1727260183792795648"
      },
      {
        "source": "1731954552142540800",
        "target": "1727254037606514688"
      },
      {
        "source": "1731954552142540800",
        "target": "1727259731038650368"
      },
      {
        "source": "1731954552142540800",
        "target": "1727257737720840192"
      },
      {
        "source": "1727254037606514688",
        "target": "1727260183792795648"
      },
      {
        "source": "1727259731038650368",
        "target": "1727260183792795648"
      },
      {
        "source": "1727257737720840192",
        "target": "1727260183792795648"
      },
      {
        "source": "1731968551085125632",
        "target": "1731954552142540800"
      },
      {
        "source": "1731954552142540800",
        "target": "1727254037606514688"
      },
      {
        "source": "1731954552142540800",
        "target": "1727259731038650368"
      },
      {
        "source": "1731954552142540800",
        "target": "1727257737720840192"
      },
      {
        "source": "1727254037606514688",
        "target": "1727260183792795648"
      },
      {
        "source": "1727259731038650368",
        "target": "1727260183792795648"
      },
      {
        "source": "1727257737720840192",
        "target": "1727260183792795648"
      }
    ],
    "tips": false
  }

  mockData.nodes.forEach(v=>{
    // v.width = 150
    // v.height = 32
    v.size = {width:160,height:32,}
  })

  mockData.edges.forEach(v=>{
    v.source = {
      cell:v.source,
      anchor:'bottom', // 锚点
    }
    v.target= {
      cell:v.target,
      anchor:'top',
    }
  })
  
  // 布局
  const dagreLayout = new DagreLayout({
    type: 'dagre',
    rankdir: 'TB',
    ranksep: 85,
    // nodesep: 55,
  })

  const model = dagreLayout.layout(mockData)
  this.graphIns.fromJSON(model) // 渲染元素

  /*this.graphIns.fromJSON(mockData) // 渲染元素
  this.graphIns.centerContent() // 居中显示*/
},
  • 11
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值