logic-flow自定义节点

目前基于需要选择任一一种基本节点类型(如rectcirclepolygon等)来继承

新建节点文件(例:CustomCircle.js)

复制代码
// CustomCircle.js
import { CircleNode, CircleNodeModel } from "@logicflow/core";
// 继承基础节点
class customCircleModel extends CircleNodeModel {
    // 定义此注册类型节点的样式(获取样式相关的方法)
}
class customCircleView extends CircleNode {
    // 定义此注册类型节点svg dom(getShape定义更复杂的节点外观)
}
export default {
    type: "CustomCircleNode",
    view: customCircleView,
    model: customCircleModel
};
复制代码

引入注册+使用

复制代码
<template>
    <el-container>
        <div class="container" ref="container"></div>
    </el-container>
</template>

<script>
import LogicFlow from '@logicflow/core';
import '@logicflow/core/dist/style/index.css';
// 1.引入自定义节点
import CustomCircleNode from '../components/CustomCircle.js';

export default {
    data() {
        return {
            nodes: [
                {
                    id: '1',
                    // 3.使用自定义节点
                    type: 'CustomCircleNode',
                    x: 100,
                    y: 100,
                }
            ],
        };
    },
    mounted() {
        this.lf = new LogicFlow({
            container: this.$refs.container,
            grid: true,
        });
        // 2.注册自定义节点
        this.lf.register(CustomCircleNode);
        this.lf.render({
            nodes: this.nodes,
            edges: this.edges,
        });
    },
};
</script>

<style>
.container {
    width: 1000px;
    height: 500px;
}
</style>
复制代码

 

posted @   南无、  阅读(1317)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
点击右上角即可分享
微信分享提示