参考文档

  • AntV X6 文档

可自定义设置以下属性

  • 容器宽度(width),类型:number | string,默认 ‘100%’
  • 容器高度(height),类型:number | string,默认 ‘100%’

效果如下图:

在这里插入图片描述

安装插件

pnpm add @antv/x6

创建DAG组件DAGChart.vue

<script setup lang="ts">
import type { Edge, Graph as X6Graph, Node } from '@antv/x6'
import { Graph } from '@antv/x6'
import { useResizeObserver, debounce } from 'vue-amazing-ui'interface Props {width?: string | number // 容器宽度height?: string | number // 容器高度
}
const props = withDefaults(defineProps<Props>(), {width: '100%',height: '100%'
})
const chartWidth = computed(() => {if (typeof props.width === 'number') {return `${props.width}px`}return props.width
})
const chartHeight = computed(() => {if (typeof props.height === 'number') {return `${props.height}px`}return props.height
})const chartRef = useTemplateRef('chartRef')
let graph: X6Graph | null = nulltype DagNodeData = {label: stringtype: 'source' | 'transform' | 'sink' | 'hello' | string
}function getDefaultNodePorts() {return {groups: {in: {position: 'left',zIndex: 1,attrs: {circle: { r: 4, magnet: false, stroke: '#5F95FF', strokeWidth: 1, fill: '#fff' }}},out: {position: 'right',zIndex: 1,attrs: {circle: { r: 4, magnet: false, stroke: '#52c41a', strokeWidth: 1, fill: '#fff' }}}},items: [{ id: 'in-1', group: 'in' },{ id: 'out-1', group: 'out' }]}
}function getGraphData() {const nodes: Node.Metadata[] = [{id: 'source-1',shape: 'rect', // 节点图形 'rect' | 'circle' | 'ellipse' | 'polygon' | 'polyline' | 'path' | 'image' | 'html' (HTML 节点,使用 foreignObject 渲染 HTML 片段)x: 80, // 节点位置 x 坐标,单位为 pxy: 140, // 节点位置 y 坐标,单位为 pxwidth: 140, // 节点宽度,单位为 pxheight: 42, // 节点高度,单位为 pxangle: 0, // 节点旋转角度,单位为度data: { label: 'Source: Kafka', type: 'source' } as DagNodeData,attrs: {body: { fill: '#e6f4ff', stroke: '#91caff', rx: 6, ry: 6 },label: { text: 'Source: Kafka', fill: '#1f1f1f' }},ports: getDefaultNodePorts()},{id: 'transform-1',shape: 'rect',x: 340,y: 120,width: 160,height: 42,data: { label: 'Transform: Clean', type: 'transform' } as DagNodeData,attrs: {body: { fill: '#f6ffed', stroke: '#b7eb8f', rx: 6, ry: 6 },label: { text: 'Transform: Clean', fill: '#1f1f1f' }},ports: getDefaultNodePorts()},{id: 'transform-2',shape: 'rect',x: 340,y: 200,width: 160,height: 42,data: { label: 'Transform: Enrich', type: 'transform' } as DagNodeData,attrs: {body: { fill: '#f6ffed', stroke: '#b7eb8f', rx: 6, ry: 6 },label: { text: 'Transform: Enrich', fill: '#1f1f1f' }},ports: getDefaultNodePorts()},{id: 'sink-1',shape: 'rect',x: 620,y: 160,width: 140,height: 42,data: { label: 'Sink: ClickHouse', type: 'sink' } as DagNodeData,attrs: {body: { fill: '#fff7e6', stroke: '#ffadd2', rx: 6, ry: 6 },label: { text: 'Sink: ClickHouse', fill: '#1f1f1f' }},ports: getDefaultNodePorts()},{id: 'hello-1',shape: 'rect',x: 880,y: 60,width: 140,height: 42,data: { label: 'Hello: World', type: 'hello' } as DagNodeData,attrs: {body: { fill: '#fff0f6', stroke: '#ffadd2', rx: 6, ry: 6 },label: { text: 'Hello: World', fill: '#1f1f1f' }},ports: getDefaultNodePorts()},{id: 'hello-2',shape: 'rect',x: 880,y: 160,width: 140,height: 42,data: { label: 'Hello: Forest', type: 'hello' } as DagNodeData,attrs: {body: { fill: '#fff0f6', stroke: '#ffadd2', rx: 6, ry: 6 },label: { text: 'Hello: Forest', fill: '#1f1f1f' }},ports: getDefaultNodePorts()},{id: 'hello-3',shape: 'rect',x: 880,y: 260,width: 140,height: 42,data: { label: 'Hello: Sea', type: 'hello' } as DagNodeData,attrs: {body: { fill: '#fff0f6', stroke: '#ffadd2', rx: 6, ry: 6 },label: { text: 'Hello: Sea', fill: '#1f1f1f' }},ports: getDefaultNodePorts()}]const edges: Edge.Metadata[] = [{id: 'edge-1',source: { cell: 'source-1', port: 'out-1' },target: { cell: 'transform-1', port: 'in-1' },connector: { name: 'smooth' }},{id: 'edge-2',source: { cell: 'source-1', port: 'out-1' },target: { cell: 'transform-2', port: 'in-1' },connector: { name: 'smooth' }},{id: 'edge-3',source: { cell: 'transform-1', port: 'out-1' },target: { cell: 'sink-1', port: 'in-1' },connector: { name: 'smooth' }},{id: 'edge-4',source: { cell: 'transform-2', port: 'out-1' },target: { cell: 'sink-1', port: 'in-1' },connector: { name: 'smooth' }},{id: 'edge-5',source: { cell: 'sink-1', port: 'out-1' },target: { cell: 'hello-1', port: 'in-1' },connector: { name: 'smooth' }},{id: 'edge-6',source: { cell: 'sink-1', port: 'out-1' },target: { cell: 'hello-2', port: 'in-1' },connector: { name: 'smooth' }},{id: 'edge-7',source: { cell: 'sink-1', port: 'out-1' },target: { cell: 'hello-3', port: 'in-1' },connector: { name: 'smooth' }}]return { nodes, edges }
}function initGraph() {if (!chartRef.value) returngraph = new Graph({container: chartRef.value,grid: {visible: true, // 绘制网格,默认绘制 dot 类型网格size: 10, // 网格大小,单位 pxtype: 'dot', // 网格类型,可选 'dot' | 'fixedDot' | 'mesh' | 'doubleMesh' | ''args: {color: '#ddd', // 网点颜色thickness: 1 // 网点大小}},background: { color: '#fafafa' }, // 背景panning: true, // 是否可以拖拽平移mousewheel: true, // 鼠标滚轮缩放interacting: { nodeMovable: true, edgeMovable: false, vertexMovable: false, edgeLabelMovable: false },autoResize: true // 监听容器大小改变,并自动更新画布大小})// 点击事件graph.on('node:click', ({ node }) => {const data = (node.getData ? node.getData() : node.getData) as DagNodeData | undefinedconsole.log(`节点被点击:${data?.label}`)})const data = getGraphData()graph.fromJSON(data) // 渲染元素fitView()centerView()useResizeObserver(chartRef,debounce(() => {console.log('centerView')fitView()centerView()}, 100) as ResizeObserverCallback)
}
// 将画布缩放级别增加 0.1
function zoomIn() {graph?.zoom(0.1)
}
// 将画布缩放级别减少 0.1
function zoomOut() {graph?.zoom(-0.1)
}
// 将画布中元素缩小或者放大一定级别,让画布正好容纳所有元素,可以通过 maxScale 配置最大缩放级别
function fitView() {graph?.zoomToFit({ padding: 20, maxScale: 1 })
}
// 将画布中元素居中展示
function centerView() {graph?.centerContent()
}
onMounted(() => {initGraph()
})
onBeforeUnmount(() => {graph?.dispose()graph = null
})
</script>
<template><div class="dag-container"><divref="chartRef"class="graph-container":style="`--chart-width: ${chartWidth}; --chart-height: ${chartHeight};`"></div></div>
</template>
<style lang="less" scoped>
.dag-container {.graph-container {width: var(--chart-width) !important;height: var(--chart-height) !important;padding: 16px 24px;border-radius: 4px;}
}
</style>

在要使用的页面引入

<script setup lang="ts">
import DAGChart from './DAGChart.vue'
</script>
<template><div><h1>DAGChart 参考文档</h1><ul class="m-list"><li><a class="u-file" href="https://x6.antv.antgroup.com/tutorial/about" target="_blank">AntV X6 文档</a></li></ul><DAGChart :height="500" /></div>
</template>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/diannao/96760.shtml
繁体地址,请注明出处:http://hk.pswp.cn/diannao/96760.shtml
英文地址,请注明出处:http://en.pswp.cn/diannao/96760.shtml

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【数据结构】跳表的概率模型详解与其 C 代码实现

文章目录介绍关键组成部分读者可以比对这张图片去理解跳表 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/c5704b6276a14c3f9facdc3e55015bcc.jpeg#pic_center) 核心操作原理算法的概率模型跳表的 C代码实现初始化跳跃表的节点、跳跃表本身跳表插入节点查找元素更新…

Verilog实现除法器

文章目录基本原理确定除数最高位移位相减基本原理 若想得到yx\frac{y}{x}xy​的商和余数&#xff0c;一种最直观的想法就是不断地用yyy减掉xxx&#xff0c;直到y<xy< xy<x为止&#xff0c;写成伪代码如下 z 0 while y<x:y - xz 1这种算实在是太低效了&#xff…

EasyLive的一些疑问

目录 一、pinia是什么 二、html的代码片段又失效&#xff1f; 三、Request.js 四 、状态管理库 五、main.js:19 Uncaught SyntaxError: The requested module /src/utils/Api.js?t1745328489985 does not provide an export named default (at main.js:19:8)​编辑 六、…

C++(String):

目录 string与C中字符串的区别&#xff1a; C字符串&#xff1a; string字符串&#xff1a; string的定义和初始化&#xff1a; 输入字符串&#xff1a; 方式1&#xff1a; 方式2&#xff1a; 字符串的拼接的操作&#xff1a; 方式1&#xff1a;使用“” 方式2&#…

【Linux】Java线上问题,一分钟日志定位

【Linux】Java线上问题&#xff0c;一分钟日志定位1. 查看异常堆栈2. 实时叮新日志3. 翻历史/压缩日志4. 统计异常数量5. 多种异常一起查6. 反向过滤7. 同时满足多个关键字查询8. 定位最近一次异常9. 异常排行榜1. 查看异常堆栈 # 在 a.log 文件中查找包含 NullPointerExcepti…

智慧农业温室大棚远程监控物联网系统解决方案

一、方案背景与目标随着现代农业向智能化、精准化转型&#xff0c;传统温室大棚管理面临效率低、响应慢、成本高等痛点。本方案通过部署御控农业物联网系统&#xff0c;实现温室环境参数实时监测、设备远程控制、数据智能分析及预警决策&#xff0c;助力农户降低人工成本&#…

【剖析高并发秒杀】从流量削峰到数据一致性的架构演进与实践

一、 挑战&#xff1a;三高背景下的数据库瓶颈秒杀场景的核心挑战可以归结为“三高”&#xff1a;高并发、高性能、高可用。而系统中最脆弱的一环&#xff0c;往往是我们的关系型数据库&#xff08;如MySQL&#xff09;。它承载着最终的数据落地&#xff0c;其连接数、IOPS和CP…

Redisson最新版本(3.50.0左右)启动时提示Netty的某些类找不到

文章目录一、写在前面二、解决方案1、解决方案2、一劳永逸3、确定redisson依赖netty的版本一、写在前面 Redisson最新版本&#xff0c;大概3.47.0&#xff0c;在JDK8环境下&#xff08;实测JDK17也一样&#xff09;会提示Netty的某些类找不到&#xff1a; Exception in threa…

MTK Linux DRM分析(八)- KMS drm_crtc.c

一、简介 Linux DRM(Direct Rendering Manager)子系统是内核中管理图形硬件的核心组件,而 CRTC(CRT Controller)又是其中的关键之一。它起源于过去控制阴极射线管(CRT)显示器的控制器概念,如今在现代图形显示中依旧扮演着至关重要的角色。 可以把 CRTC 想象成图形显示…

vue+openlayers示例:适配arcgis矢量瓦片服务以及样式(附源码下载)

由于单位这边有个项目是基于openlayers地图引擎框架实现webgis地图可视化功能&#xff0c;但是要调用第三方的arcgis矢量瓦片服务以及适配样式&#xff0c;在这个背景下&#xff0c;基于openlayersvue实现适配arcgis矢量瓦片服务以及样式效果&#xff0c;适合学习openlayers与前…

mybatis xml中表名 字段报红解决

mybatis xml中表名 字段报红解决

谷歌浏览器重定向url,谷歌浏览器浏览网页修改url到本地

谷歌应用商店搜索插件requestly&#xff08;有个相似名称的插件&#xff0c;选择这个Requestly: Supercharge your Development & QA&#xff09; 安装后打开插件网址https://app.requestly.io/rules/my-rules 新建规则rules->my rules-> new rule -> redirect …

教育场景下禁用html5播放器拖动进度条的例子

禁用视频课程进度条的拖动功能&#xff0c;主要是为了强制学员按照课程设计的顺序观看内容&#xff0c;防止跳过关键知识点&#xff0c;从而保证学习效果和课程的完整性。 1.防止应试作弊&#xff1a; 在一些需要观看视频才能解锁下一章节或完成测试的场景中&#xff0c;禁用…

async实战

一、协程 协程是程序员人为创造 协程是一种用户态内的上下文切换技术。通过一个线程实现代码块相互切换执行。yield返回生成器 yield from 代表&#xff0c;跳到 func2协程函数 通过函数名()&#xff0c;是执行不了的。需要把函数加入到loop里面来&#xff0c;才可以被执行。 把…

个人搭建小网站教程(云服务器Ubuntu版本)

目录 1.配置云服务器&#xff08;略讲&#xff09; 2.vscode连接&#xff08;ssh连接&#xff09; 3.本地压缩项目包 4.传输项目 5.配置项目依赖 6.运行项目 1.启动 FastAPI 后端&#xff08;Python 部分&#xff09; 2.启动 Next.js 前端&#xff08;Node.js 部分&…

pion/webrtc v4.1.4 版本发布:关键特性与性能优化全面解析

引言 实时通信技术在现代互联网应用中扮演着越来越重要的角色&#xff0c;从视频会议到在线教育&#xff0c;从远程医疗到物联网设备交互&#xff0c;WebRTC技术已经成为实时音视频通信的事实标准。作为Go语言中最成熟且广泛使用的WebRTC实现&#xff0c;pion/webrtc项目持续推…

集成算法(聚类)

下面简单集成算法代码from sklearn.datasets import make_blobs from sklearn.cluster import KMeans import matplotlib.pyplot as plt# 创建数据集&#xff0c;生成 3 个中心的聚类数据&#xff0c;共 300 个样本&#xff0c;每个样本 2 个特征 X, _ make_blobs(n_samples30…

01 网络信息内容安全--绪论

1 课程内容 网络信息内容获取技术网络信息内容预处理技术网络信息内容过滤技术社会网络分析技术入侵检测技术异常流量检测技术对抗攻击技术 2 理论研讨 分为16个组 2.1 网络信息内容获取技术&#xff1a;第1组 【用DeepSeek网站爬虫&#xff0c;数据获取零成本&#xff01…

GPT-5:天变了吗?还是风停了?

2025年8月8日&#xff0c;OpenAI 发布了 GPT-5。这次更新被许多人寄予厚望&#xff0c;也引发了不少争议。对普通用户来说&#xff0c;这是一场“又快又会做事”的智能盛宴&#xff1b;而对资深开发者和 AI 研究者而言&#xff0c;GPT-5 可能更像是一次不够激进、略显保守的版本…

生信分析自学攻略 | R语言数据筛选和修改

在《生信小白自学攻略》系列的前几篇文章中&#xff0c;我们已经了解了 R 和 RStudio 的安装、RStudio 的深度探索&#xff0c;以及 R 语言的基本数据类型和数据结构。现在&#xff0c;是时候深入探讨如何运用 R 语言对数据进行精细化处理了。本篇推文将详细介绍如何在 R 中对数…