vue使用antv-x6 绘制流程图DAG图

注册节点两种方法:

import { Graph, Node, Path, Cell, Addon } from "@antv/x6";

import { register } from "@antv/x6-vue-shape";

1.x 的写法:

javascript 复制代码
registerCustomNode() {
      // demo
      Graph.registerNode(
        "custom-polygon",
        {
          inherit: "polygon",
          width: 66,
          height: 36,
          markup: [
            {
              tagName: "polygon",
              selector: "body",
            },
            {
              tagName: "text",
              selector: "label",
            },
          ],
          attrs: {
            body: {
              strokeWidth: 1,
              stroke: "#5F95FF",
              fill: "#EFF4FF",
            },
            text: {
              fontSize: 12,
              fill: "#262626",
            },
          },
          ports: {
            ...ports,
            // items: [ // 这里是限制连接点多少个的地方
            //   {
            //     group: 'top',
            //   },
            //   {
            //     group: 'bottom',
            //   },
            // ],
          },
        },
        true
      );

      Graph.registerNode(
        "custom-circle",
        {
          inherit: "circle",
          width: 45,
          height: 45,
          markup: [
            {
              tagName: "circle",
              selector: "body",
            },
            {
              tagName: "text",
              selector: "label",
            },
          ],
          attrs: {
            body: {
              strokeWidth: 1,
              stroke: "#5F95FF",
              fill: "#EFF4FF",
            },
            text: {
              fontSize: 12,
              fill: "#262626",
            },
          },
          ports: { ...ports },
        },
        true
      );

      // 自定义节点
      Graph.registerNode(
        "dag-node",
        {
          inherit: "rect",
          width: 180,
          height: 36,
          markup: [
            {
              tagName: "rect", // 标签名称
              selector: "body", // 选择器
            },
            {
              tagName: "image",
              selector: "image1",
            },
            {
              tagName: "text",
              selector: "label",
            },
            {
              tagName: "image",
              selector: "image2",
            },
          ],
          attrs: {
            body: {
              strokeWidth: 1,
              stroke: "rgba(255, 255, 255, 0.3)",
              fill: "#1D2035",
            },
            image1: {
              "xlink:href": imgCot.logo,
              width: 16,
              height: 16,
              x: 12,
              y: 12,
            },
            label: {
              fontSize: 12,
              fill: "rgba(255, 255, 255, 0.9)",
            },
            image2: {
              "xlink:href": imgCot.logo,
              width: 16,
              height: 16,
              x: 12,
              y: 12,
              refX: "80%",
            },
          },
          ports: {
            groups: {
              top: {
                position: "top",
                attrs: {
                  circle: {
                    r: 4,
                    magnet: true,
                    stroke: "#C2C8D5",
                    strokeWidth: 1,
                    fill: "#fff",
                  },
                },
              },
              bottom: {
                position: "bottom",
                attrs: {
                  circle: {
                    r: 4,
                    magnet: true,
                    stroke: "#C2C8D5",
                    strokeWidth: 1,
                    fill: "#fff",
                  },
                },
              },
            },
          },
        },
        true
      );
   },

2.x 的写法: 注册vue组件节点

javascript 复制代码
registerCustomVueNode() {
      register({
        shape: "dag-node",
        width: 185,
        height: 40,
        component: DataBase,
        ports: {
          groups: {
            top: {
              position: "top",
              attrs: {
                circle: {
                  r: 4,
                  magnet: true,
                  stroke: "#C2C8D5",
                  strokeWidth: 1,
                  fill: "#fff",
                },
              },
            },
            bottom: {
              position: "bottom",
              attrs: {
                circle: {
                  r: 4,
                  magnet: true,
                  stroke: "#C2C8D5",
                  strokeWidth: 1,
                  fill: "#fff",
                },
              },
            },
          },
        },
      });
    },
相关推荐
paopaokaka_luck3 分钟前
智能推荐社交分享小程序(websocket即时通讯、协同过滤算法、时间衰减因子模型、热度得分算法)
数据库·vue.js·spring boot·后端·websocket·小程序
老坛00114 分钟前
2025决策延迟的椭圆算子分析:锐减协同工具的谱间隙优化
前端
老坛00115 分钟前
从记录到预测:2025新一代预算工具如何通过AI实现前瞻性资金管理
前端
今禾18 分钟前
" 当Base64遇上Blob,图像转换不再神秘,让你的网页瞬间变身魔法画布! "
前端·数据可视化
华科云商xiao徐22 分钟前
高性能小型爬虫语言与代码示例
前端·爬虫
十盒半价23 分钟前
深入理解 React useEffect:从基础到实战的全攻略
前端·react.js·trae
攀登的牵牛花24 分钟前
Electron+Vue+Python全栈项目打包实战指南
前端·electron·全栈
iccb101324 分钟前
我是如何实现在线客服系统的极致稳定性与安全性的
前端·javascript·后端
一大树25 分钟前
Vue3祖孙组件通信方法总结
前端·vue.js
不要进入那温驯的良夜26 分钟前
跨平台UI自动化-Appium
前端