使用joinjs绘制流程图(七)-实战-绘制流程图+节点设置样式+节点添加事件

news/2024/10/14 20:18:43

效果图

原理

joinjs中通过svg来绘制流程图,然后我们可以使用localToClientRect这个方法对节点(element)复制,它会在原来的element在svg位置上生成一个html元素,但是这样会造成原来的element节点监听的点击事件无法触发,我们可以使用原生来操作对这个元素(比如样式的设置和事件的监听)

代码

<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 = paper// const element = new joint.shapes.standard.Rectangle()// element.position(100, 50)// element.resize(100, 40)// element.addTo(this.graph)// Draw an HTML rectangle above the element.// var bbox = element.getBBox()// var clientRect1 = 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'>哈哈哈</span>`// $(div).click(() => {//   console.log('发生了点击')// })// paper.el.appendChild(div)// 整合const 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 }, '流程-2.1')const node7 = this.drawRect({ x: 350, y: 150 }, '流程-2.2')const node2_to_node6_vetices = [new joint.g.Point(250, 100)]const node2_to_node7_vetices = [new joint.g.Point(250, 150)]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: {fill: '#2c3e50',},label: {text,fill: '#3498DB',fontSize: 18,fontWeight: 'bold',fontVariant: 'Microsoft YaHei',},})rect.addTo(this.graph)this.transformHtml(rect, text)return rect},drawLine(node1, node2, vertices) {var link = new joint.shapes.standard.Link()link.source(node1)link.target(node2)link.addTo(this.graph)if (vertices) {link.vertices(vertices)link.router('orthogonal')// link.connector('rounded')}// link.vertices([//   new joint.g.Point(250, 100),//   new joint.g.Point(280, 100),//   new joint.g.Point(300, 120),// ])//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/26653.html

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

相关文章

webapi创建和调用WebService

首先需要引入soapcore包这个包提供了所需的类和soap终结点中间件。 引入这个这个包之后,我们需要定义提供的服务。 这里我写了一个用于查询省份面积的服务。省份信息服务 /// <summary> /// 省份信息服务接口 /// </summary> [ServiceContract] public interface …

Y2 知识和题单

Link。 0x01 进制 引入 计数原理,对于 \(N\) 进制,那么就是逢 \(N\) 进一。 计算机中常用二进制,对应电路中的通电(\(1\))断电(\(0\))。 人类从远古以来使用十进制。 常用的有二进制、三进制、八进制、十进制、十六进制等。 由于不同进制之间数值写法可能相同,在没有特…

m基于CCSDS标准的LDPC编码器的FPGA实现,包含testbench,码长1024,码率0.5

1.算法仿真效果 vivado2019.2仿真结果如下:2.算法涉及理论知识概要LDPC码是一种具有稀疏校验矩阵的线性分组码,由Robert G. Gallager在1962年首次提出。它利用图论中的 Tanner 图来表示其编解码结构,其中节点分为变量节点和校验节点。变量节点对应于消息比特,而校验节点则对…

【Qt 专栏】信号与槽详解

5个重要的结论: 1. 对于QT,GUI程序设计的逻辑需要4元素:信号、信号发射者、信号接受者、槽。例如,点击按键后,窗口关闭,这四者的关系如下所示: 2. 信号函数返回类型为void,不需要实现。参数类型可以重载。调用时前面可以加 emit(也可不加),表示信号释放。 3. 槽函数…

如何批量复制多个文件到多个目录中(批量复制文件,多对多文件高效操作的方法)

首先,需要用到的这个工具:度娘网盘 提取码:qwu2 蓝奏云 提取码:2r1z现在开始说具体操作 1、首先,我准备了3个文件夹和两个可爱的图片:当然,在实际使用的时候肯定不止这些,我这里只是演示一下下。 2、然后打开这个工具,按下CTRL+5,切换到文件批量复制的功能模块。 把两…

要看就看极品视频

有关西安的极品视频分享给各位,一场视觉盛宴。前言 不可多得的极品视频,大神制作,看到就想收藏并分享给各位。共同享受非常有底蕴的城市,西安。 极品视频在西安,你就能拥有时间魔法有魔法就可以为所欲为魔法西安丨你见过会动的大唐不夜城吗看完视频,我只感觉到任何事情做…

力扣-82. 删除排序链表中的重复元素

1.题目 题目地址(82. 删除排序链表中的重复元素 II - 力扣(LeetCode)) https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/ 题目描述 给定一个已排序的链表的头 head , 删除原始链表中所有重复数字的节点,只留下不同的数字 。返回 已排序的链表 。示例 …

联考物理T24

Solution — T24 题目描述 (本PDF为 JJL 所制)如图所示,一厚壁玻璃容器放在水平面桌面上,容器底内底面积为 $50\ cm^2 $,外底面积为 $100 \ cm^2 $。将一定质量的水倒入容器中,水的深度为 \(10 \ cm\) 。求:\((p_水=1.0 \times 10^3 kg/m^3 , g \text{取} 10 N/kg)\)(1) 水对…