当前位置: 首页 > news >正文

通过anvt X6和vue3实现图编辑

通过anvt X6
X6地址:https://x6.antv.antgroup.com/tutorial/about;
由于节点比较复杂,使用vue实现的节点;
x6提供了一个独立的包 @antv/x6-vue-shape 来使用 Vue 组件渲染节点。
VUE3的案例:

<template><div class="app-content"><div id="container"></div><TeleportContainer /></div>
</template><script lang="ts">import { defineComponent } from 'vue'import ProgressNode from './components/ProgressNode.vue'import { Graph } from '@antv/x6'import { register, getTeleport } from '@antv/x6-vue-shape'register({shape: 'custom-vue-node',width: 100,height: 100,component: ProgressNode,})const TeleportContainer = getTeleport()export default defineComponent({name: 'App',components: {TeleportContainer,},mounted() {const graph = new Graph({container: document.getElementById('container')!,background: {color: '#F2F7FA', //画布背景颜色},panning: true,//是否可以平移 默认truemousewheel: true,//是否可以缩放 默认trueautoResize: true,interacting: function (cellView) {return {nodeMovable: false,//节点是否可以被移动。// vertexAddable: false,//是否可以添加边的路径点。// arrowheadMovable: false,//边的起始/终止箭头是否可以被移动// edgeMovable: false,//边是否可以被移动。}}})graph.addNode({shape: 'custom-vue-node',x: 100, //x位置 y: 60, //y位置 })//x,y设置为0节点添加的位置就是左上角},})
</script>

节点组件内容如下:

<template><el-progress type="dashboard" :percentage="percentage" :width="80"><template #default="{ percentage }"><span class="percentage-value">{{ percentage }}%</span></template></el-progress>
</template><script lang="ts">import { defineComponent } from 'vue'export default defineComponent({name: 'ProgressNode',inject: ['getNode',"getGraph"],//注入node和graph,可以在组件内使用了data() {return {percentage: 80,}},mounted() {const node = (this as any).getNode()console.log(node)const graph = (this as any).getGraph();const zoom = graph.zoom(); //获取缩放的比例// 画布缩放到0.5graph.zoomTo(.5, {center: {//缩放的中心x:0,y: 0}});},})
</script>

效果如下:代码运行的效果可以进行拖动进程图
在这里插入图片描述
后记:画布进行缩放之后不是1的情况下,设置节点内部的offset会出现bug,可以通过先zoomTo 1 然后进行offset设置,设置完成之后在进行zoomTo 回去。

const graph = (this as any).getGraph();const zoom = graph.zoom();graph.zoomTo(1, {center: {x: 0,y: 0}});
//进行offset设置.....graph.zoomTo(zoom, {center: {x: this.zoomX,y: this.height / 2}});
http://www.lryc.cn/news/117148.html

相关文章:

  • win2012 IIS8.5 安装PHP教程,一些版本不能用
  • sqlalchemy执行原生sql
  • Python-OpenCV中的图像处理-图像平滑
  • Mongoose http server 例子
  • 1、初识HTML
  • 线性代数(三) 线性方程组
  • Apoll 多项式规划求解
  • ssm亚盛汽车配件销售业绩管理统源码和论文PPT
  • 发布属于自己的 npm 包
  • Redis主从复制和哨兵架构图,集成Spring Boot项目实战分享
  • java中try-with-resources自动关闭io流
  • Games101学习笔记 -光栅化
  • Pytorch量化之Post Train Static Quantization(训练后静态量化)
  • Sql奇技淫巧之EXIST实现分层过滤
  • Linux下升级jdk1.8小版本
  • 【Mysql】数据库基础与基本操作
  • 87 | Python人工智能篇 —— 机器学习算法 决策树
  • 【计算机视觉】干货分享:Segmentation model PyTorch(快速搭建图像分割网络)
  • 解析湖仓一体的支撑技术及实践路径
  • 40.利用欧拉法求解微分方程组(matlab程序)
  • OpenAI-Translator 实战总结
  • 【工业机器人】用于轨迹规划和执行器分析的机械手和移动机器人模型(MatlabSimulink)
  • 开源在线文档服务OnlyOffice
  • 汽车基本常识
  • 百度资深PMO阚洁受邀为第十二届中国PMO大会演讲嘉宾
  • 为什么C++有多种整型?
  • 玩一玩通义千问Qwen开源版,Win11 RTX3060本地安装记录!
  • oracle积累增量和差异增量
  • 利用C++nlohmann库解析json文件
  • OpenCV 中的光流 (C++/Python)