AntvX6-edge

前言

Edge 是边的基类,继承自 Cell,并定义了边的通用属性和方法。

属性

选项类型描述
sourceTerminalData起点或起始节点、连接桩信息。
targetTerminalData终点或终止节点、连接桩信息。
verticesPoint.PointLike[]路径点。
routerRouterData路由。
connectorConnectorData连接器。
labelsLabel[] string[]标签。
defaultLabelLabel默认标签

代码

1、容器
<!-- container.vue -->
<template>
  <div id="container"></div>
</template>
<script setup lang="ts">
import { Graph } from "@antv/x6";
import { onMounted } from "vue";
import { register } from "@antv/x6-vue-shape";
import elmNode from "./elmNode.vue";

register({
  shape: "elm-vue-node",
  component: elmNode,
});

onMounted(() => {
  const graph = new Graph({
    container: document.getElementById("container"),
    width: "800",
    height: "800",
  });

  graph.addNode({
    id: "site1",
    shape: "elm-vue-node",
    x: 100,
    y: 100,
    width: 80,
    height: 100,
    data: {
      classType: "test",
    },
  });

  graph.addNode({
    id: "site2",
    shape: "elm-vue-node",
    x: 400,
    y: 400,
    width: 80,
    height: 100,
    data: {
      classType: "test",
    },
  });

  graph.addEdge({
    source: {
      cell: "site1",
      connectionPoint: {
        name: "anchor",
      },
      anchor: {
        name: "top",
      },
    },
    target: {
      cell: "site2",
      connectionPoint: {
        name: "anchor",
      },
      anchor: {
        name: "bottom",
      },
    },
    connector: {
      name: "smooth",
      args: {
        radius: 20,
      },
    },
  });
});
</script>
2、组件
<!-- elmNode.vue -->
<template>
  <div>{{ label }}</div>
  <div class="node-main"></div>
</template>
<script setup lang='ts'>
import { inject, onMounted } from "vue-demi";

const getNode = inject("getNode");
let node = getNode();
let data = node.getData();
let label = data["classType"];
</script>
<style lang='less' scoped>
.node-main {
  width: 61px;
  height: 92px;
  background-image: url("../../assets/site.svg");
  background-size: 61px 92px;
}
</style>

总结

如果需要使用 connectionPointanchor 来限制锚点位置,则组件需要设置 widthheight
antvx6 中的边有非常多的用法:

相关链接

边:https://x6.antv.antgroup.com/api/model/edge
路由:https://x6.antv.antgroup.com/api/registry/router
连接器:https://x6.antv.antgroup.com/api/registry/connector
节点的锚点:https://x6.antv.antgroup.com/api/registry/node-anchor
边的锚点:https://x6.antv.antgroup.com/api/registry/edge-anchor
连接点:https://x6.antv.antgroup.com/api/registry/connection-point

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

若博豆

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

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

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

打赏作者

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

抵扣说明:

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

余额充值