使用joinjs绘制流程图(六)-自定义节点成html元素

news/发布时间2024/5/17 11:02:15

场景

有的时候流程图中的节点是多样化的

效果

代码

<template><div class="app"><el-button type="primary" size="small" @click="updateRectContent">修改Rect元素内容</el-button><hr /><div ref="myholder" id="paper"></div></div>
</template><script>
import * as joint from '@joint/core'
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,})// paper.on('element:pointerclick', function (elementView) {//   console.log(elementView)//   // var currentElement = elementView.model//   // currentElement.attr('body/stroke', 'orange')// })// 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)// 双击元素时触发// paper.on('element:pointerdblclick', function (elementView) {//   console.log(elementView)//   var currentElement = elementView.model//   console.log('currentElement:', currentElement)//   currentElement.attr('body/stroke', 'orange')// })// 单击元素时触发// paper.on('element:pointerclick', function (elementView) {//   console.log(elementView)//   // var currentElement = elementView.model//   // currentElement.attr('body/stroke', 'orange')// })// 创建可以自定义html的方法// joint.shapes.html = {}// joint.shapes.html.Element = joint.shapes.basic.Rect.extend({//   defaults: joint.util.defaultsDeep(//     {//       type: 'html.Element',//       attrs: {//         rect: { stroke: 'none', 'fill-opacity': 0 },//       },//     },//     joint.shapes.basic.Rect.prototype.defaults//   ),// })const element = new joint.shapes.standard.Rectangle()element.position(100, 50)element.resize(100, 40)element.addTo(this.graph)var bbox = element.getBBox()var clientRect1 = paper.localToClientRect(bbox)// alternative method signaturevar clientRect2 = paper.localToClientRect(bbox.x,bbox.y,bbox.width,bbox.height)// Draw an HTML rectangle above the element.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'const text = element.attr('label').textdiv.innerHTML = `<span class='yellow'>哈哈哈</span>`// console.log(element.attr('label'))paper.el.appendChild(div)// clientRect1.on('element:pointerclick', function () {//   console.log(11)// })},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)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',},})},updateRectContent() {console.log(this.graph)// console.log(this.graph.getElements())const elements = this.graph.getElements()console.log(elements[0])// 获取原来的文本// console.log(elements[0].attr('label'))const node_1 = elements[0]node_1.attr({label: {text: '测试',},})},},
}
</script><style lang="less" scoped>
#paper {border: 1px solid;
}/deep/.yellow {color: yellow;
}
</style>

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

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

相关文章

JAVA下唯一一款搞定OLTP+OLAP的强类型查询这就是最好用的ORM相见恨晚

JAVA下唯一一款搞定OLTP+OLAP的强类型查询这就是最好用的ORM相见恨晚 介绍 首先非常感谢 FreeSQL 提供的部分源码,让我借鉴了不少功能点,整体设计并没有参考FreeSQL(因为java压根没有expression所以没办法参考)只是在数据库方言上FreeSQL提供的SQL让我少走了很多弯路,所以才让e…

科目四

科四比科一多了多选题 不考:扣分题 罚款题 判刑题 动画题考:交通信号 案例多选(难)案例多选 酒驾 20-80 mg/ml 醉驾 >80 mg/ml 疲劳驾驶-开车4小时要休息20分钟l交通信号交警手势核心口诀:交警脸不对我,掌心对我,我要停车。交通标志核心口诀:会车哪边粗哪边先走,三…

海光处理器与软件栈

海光处理器与软件栈参考文献链接 https://www.hygon.cn/index人工智能芯片与自动驾驶

E-portfolio

Project 1 EmoDB dataset with SVM emotion classification Train SVM machine learning model using the IS09 feature set of the EmoDB dataset. Result of the project, accuracy more than 75% :Core code using Python:Project 2 Signal processing using MATLAB

.net8系列-05图文并茂手把手教你配置日志组件log4net

log4net是什么? log4net是Apache软件基金会为.NET平台开发的一个日志记录库。它是Apache log4j框架的.NET移植版本,属于Apache Logging Services项目的一部分。 为什么使用log4net? log4net设计用于帮助.NET应用程序的开发者控制日志信息的生成过程,使得日志信息可以根据配…

Spirng 当中 Bean的作用域

Spirng 当中 Bean的作用域 @目录Spirng 当中 Bean的作用域每博一文案1. Spring6 当中的 Bean的作用域1.2 singleton 默认1.3 prototype1.4 Spring 中的 bean 标签当中scope= 属性其他的值说明1.5 自定义作用域,一个线程一个 Bean2. 总结:3. 最后:每博一文案 青年,青年!无论受…