使用joinjs绘制流程图(八)-实战-绘制流程图+节点路径自定义

news/2024/9/23 18:28:06

效果图

代码

<template><div class="app"><div ref="myholder" id="paper"></div></div>
</template><script>
import * as joint from '@joint/core'
import $ from 'jquery'
export default {data() {return {graph: null,}},mounted() {const namespace = joint.shapesvar graph = new joint.dia.Graph({}, { cellNamespace: namespace })this.graph = graphvar paper = new joint.dia.Paper({el: this.$refs.myholder,model: this.graph,width: 800,height: 300,cellViewNamespace: namespace,drawGrid: true,gridSize: 10,background: {color: 'rgba(0, 255, 0, 0.3)',},// 禁止交互interactive: false, // disable default interaction (e.g. dragging)// 当mousemove事件的数量超过clickThreshold时,在mouseup之后不会触发pointerclick事件clickThreshold: 10,})this.paper = paperconst node1 = this.drawRect({ x: 50, y: 30 }, '节点1')const node2 = this.drawRect({ x: 200, y: 30 }, '节点2')const node3 = this.drawRect({ x: 350, y: 30 }, '节点3')const node4 = this.drawRect({ x: 500, y: 30 }, '节点4')// const node5 = this.drawRect({ x: 50, y: 100 }, '流程-1.1')const node6 = this.drawRect({ x: 350, y: 100 }, '节点6')const node7 = this.drawRect({ x: 350, y: 150 }, '流程-2.2')//  自定义路径点const path_points = new joint.g.Path('M 300 50 L 325 50 L 325 120 L 350 120').segmentsconst points = path_points.map((item) => item.end)const path_points_2 = new joint.g.Path('M 300 50 L 325 50 L 325 120 L 325 170 L 350 170').segmentsconst points_2 = path_points_2.map((item) => item.end)const node2_to_node6_vetices = [...points]const node2_to_node7_vetices = [...points_2]this.drawLine(node1, node2)this.drawLine(node2, node3)this.drawLine(node3, node4)// this.drawLine(node1, node5)this.drawLine(node2, node6, node2_to_node6_vetices)this.drawLine(node2, node7, node2_to_node7_vetices)},methods: {drawRect({ x, y }, text) {var rect = new joint.shapes.standard.Rectangle()rect.position(x, y)rect.resize(100, 40)rect.attr({// body选择器修改的是 svg元素  [selector for the <rect> SVGElement]body: {fill: '#2c3e50',// strokeWidth: 0,// strokeDasharray: '10,2',// fill: 'transparent',// stroke: 'transparent',},// label选择器修改的是 text元素  [selector for the <text> SVGElement]label: {text,fill: '#3498DB',fontSize: 18,fontWeight: 'bold',fontVariant: 'Microsoft YaHei',},})rect.addTo(this.graph)// this.transformHtml(rect, text)return rect},// vertices 数组,从起始点到终点是否需要绕行  [https://resources.jointjs.com/tutorial/links]drawLine(node1, node2, vertices) {var link = new joint.shapes.standard.Link()link.source(node1)link.target(node2)link.addTo(this.graph)if (vertices && vertices.length) {link.vertices(vertices)// 注意:下面不能使用,使用下面后路径会自动去计算// link.router('orthogonal')// link.connector('rounded')}link.attr({line: {stroke: 'gray',},})},transformHtml(element, text) {var bbox = element.getBBox()// NOTE:重点方法  绘制一个html元素在element元素之上//  Draw an HTML rectangle above the element.var clientRect1 = this.paper.localToClientRect(bbox)var div = document.createElement('div')div.style.position = 'fixed'div.style.background = 'red'div.style.left = clientRect1.x + 'px'div.style.top = clientRect1.y + 'px'div.style.width = clientRect1.width + 'px'div.style.height = clientRect1.height + 'px'div.innerHTML = `<span class='yellow'>${text}</span>`$(div).click(function () {console.log(this)})this.paper.el.appendChild(div)},},
}
</script><style lang="less" scoped>
#paper {border: 1px solid;
}/deep/.yellow {color: yellow;
}
</style>

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

什么是数据中心?有哪些类型?如何工作?

数据中心是一种物理设施,提供操作程序的计算能力,处理信息的存储,以及将人们连接到执行任务和支持企业运营所需的资源的网络。一、什么是数据中心? 数据中心是一个房间、一座建筑物或一组建筑物,用于容纳后端计算机系统,设有用户界面和冷却能力、物理安全、网络设备等支持…

万事通,专精部分领域的多功能 Transformer 智能体

介绍 我们很高兴分享“万事通”(Jack of All Trades,简称 JAT) 项目,该项目旨在朝着通用智能体的方向发展。该项目最初是作为对 Gato (Reed 等,2022 年) 工作的公开复现启动的,Gato 提出训练一种能够执行视觉与语言以及决策任务的 Transformer。于是我们首先构建了 Gato 数…

WSL常用命令

WSL常用命令 WSL重启WSL中reboot和shutdown都无法使用, 我直接使用win下的WSL命令来实现重启的.wsl --shutdown # 关闭所有wsl wsl -l -v # 检查是否关闭关闭后再启动wsl即可. GUI程序中文字体显示为方块问题错误如下:检查已安装的字体$ fc-list # 若没有此命令,需先安装…

root用户远程登录云服务器失败 No supported authentication methods available (server sent: publickey)

1、平台:亚马逊AWS云、腾讯云服务器、MobaXterm2、问题:云服务器实例远程登录失败,显示:“No supported authentication methods available (server sent: publickey)”翻译:不支持可用的身份验证方法(服务器发送:publickey) 3、解决过程:初步判断:服务器远程登录配置文…

项目冲刺——第七篇Scrum冲刺博客

作业所属课程 所属课程作业要求 作业要求作业目标 总结第六天的敏捷开发,安排好第七天敏捷开发冲刺一、站立式会议 1、会议图片2、昨天已完成的内容成员 任务肖杨、梁丽贤 修改登陆模块的bug黄诃华、欧文杰 完成跨域支持的功能姚佳如、李慧娣 细化测试计划廖莹 协调团队、编写…

微信3.9.8.25机器人(Hook注入)搭建教程文档

开源地址 https://github.com/ttttupup/wxhelper 微信破解dll https://github.com/nefarius/Injector 注入工具 https://github.com/tom-snow/wechat-windows-versions/releases 微信历史版本 基本原理 启动指定版本PC微信以后,利用注入程序将dll文件注入到微信进程内,可…

【django学习-21】ModelForm方式,自定义数据校验

前言:我们在使用ModelForm新增数据时,除了使用默认的数据校验之外,还可以自定义数据校验 例如:有个靓号的列表,新增/编辑校验 1.代码示例1.1:modles.pyclass PrettyNum(models.Model):"""靓号表"""mobile = models.CharField(verbose_name=&…

【图像处理】使用matplotlib库显示灰度图像为自定义颜色(2)

在下面的代码中,facies_img的值只有[0,1,2]表明图像是灰度图像。通过下面的代码可以让图像显示为彩色图像 import matplotlib.pyplot as plt import matplotlib.colors as mcolors from PIL import Image import os import random import numpy as np# 路径设置 data_dir = da…