NoteZ_技术博客 NoteZ_技术博客
🏠 首页
  • 📚 Web技术
  • 📋 Npm笔记
  • 📑 Markdown
  • 📄 Git笔记
  • 📝 Nginx文档
  • 📓 Linux文档
  • 📖 技术文档
  • 📜 其他文档
  • 🧊 NodeJs
  • 🎡 Express
  • 🔥 Rust
  • 🎉 Koa2
  • 🍃 MongoDB
  • 🐬 MySql
  • 🥦 Oracle
  • 🍁 Python
  • 🍄 JavaScript
  • 🌰 CSS
  • 🧄 HTML
  • 🥑 Canvas
  • 🌽 Nuxt
  • 🍆 React
  • 🥜 Vue
  • 🧅 TypeScript
  • 🌶️ AI
  • 📘 分类
  • 📗 标签
  • 📙 归档
⚜️ 在线编辑 (opens new window)
  • 📁 站点收藏
  • 📦 前端组件库
  • 📊 数据可视化
  • 🌈 开源插件
  • 🎗️ 关于我
  • 🔗 友情链接
GitHub (opens new window)

NoteZ_技术博客

前端界的小学生
🏠 首页
  • 📚 Web技术
  • 📋 Npm笔记
  • 📑 Markdown
  • 📄 Git笔记
  • 📝 Nginx文档
  • 📓 Linux文档
  • 📖 技术文档
  • 📜 其他文档
  • 🧊 NodeJs
  • 🎡 Express
  • 🔥 Rust
  • 🎉 Koa2
  • 🍃 MongoDB
  • 🐬 MySql
  • 🥦 Oracle
  • 🍁 Python
  • 🍄 JavaScript
  • 🌰 CSS
  • 🧄 HTML
  • 🥑 Canvas
  • 🌽 Nuxt
  • 🍆 React
  • 🥜 Vue
  • 🧅 TypeScript
  • 🌶️ AI
  • 📘 分类
  • 📗 标签
  • 📙 归档
⚜️ 在线编辑 (opens new window)
  • 📁 站点收藏
  • 📦 前端组件库
  • 📊 数据可视化
  • 🌈 开源插件
  • 🎗️ 关于我
  • 🔗 友情链接
GitHub (opens new window)
  • Web技术

  • Git笔记

  • Linux文档

  • Markdown

  • Nginx文档

  • Npm笔记

  • 技术文档

  • 其他文档

    • 解决 bash_wget 未找到命令的解决办法
    • CentOS7 常见问题应对,如何升级make和gcc版本
    • CodeMirror代码编辑器实现自定义提示功能增强版(支持搜索、调用接口查询提示内容)
    • CSS 滚动条样式
    • d3 svg 基本图形绘制
    • d3.js中update,enter,exit的概念
    • dat.gui 基本使用方法
    • echarts 使用案例(demo)
    • jsplumb 中文基础教程
      • 1.什么是jsplumb?
      • 2.jsplumb能干什么?
      • 3.基本概念
      • 4.基础案例
        • 4.1. 连接两个节点
        • 4.2. 可拖动节点
        • 4.3. 连接的其他参数
        • 4.4. 设置连接的默认值
        • 4.5. 给连接加上样式
        • 4.6. 给连接加上箭头
        • 4.7. 增加一个端点
        • 4.8. 拖动创建连接
        • 4.9. 给端点增加样式
        • 4.10. 节点改变尺寸
        • 4.11. 限制节点拖动区域
        • 4.12. 节点网格对齐
        • 4.13. 给链接添加点击事件:点击删除连线
        • 4.14. 删除节点,包括节点相关的连接
        • 4.15. 通过编码连接endPoint
        • 4.16. 连接前的检查,判断是否建立连接
        • 4.17. 一个端点如何拖拽出多条连线
        • 4.18. 整个节点作为source或者target
        • 4.19. 节点缩放
      • 5. jsPlumb默认配置简介
      • 6. 有没有稍微复杂一点,带有拖放的栗子?
      • 7. 实战项目 一个可视化IVR编辑器
      • 8. 还有哪些类似的图形连线可视化项目
        • 8.1. G6 AntV
        • 8.2. VivaGraphJS
        • 8.3. springy
        • 8.4. graphviz
        • 8.5. visjs
        • 8.6. vue-jsplumb-workflow
      • 9. 参考资源
    • Linux服务器(centos7)使用LibreOffice将Word转换PDF文档出现中文乱码或方格解决方法
    • npm install 报错 npm ERR code UNABLE_TO_VERIFY_LEAF_SIGNATURE npm ERR errno UNABLE_TO_VERIFY_LEA 解决
    • Npm 清除缓存
    • Npm设置淘宝镜像
    • NPS内网穿透安装方法
    • ThreeJs 基础入门
    • unable to verify the first certificate 原因及解决方法
    • vue 安装node-sass报错解决方案(缺少python2.7支持)
    • windows下安装 stable-diffusion-webui 步骤
    • yarn的安装与使用
    • 关于微信支付 WeixinJSBridge.invoke 、 wx.chooseWXPay使用方法
    • 内网穿透的几款工具汇总
    • 前端使用 swd-deploy 自动化部署项目到服务器
    • 常用工具集(utils.js)
    • 开源项目大杂烩
    • 微信小程序-APP生命周期与运行机制总结
    • 微信小程序踩坑之布局适配单位(rpx、px、vw、vh)
    • 服务器常用的状态码
    • 解决google浏览器翻译无法使用的问题
    • 解决使用 Gitalk 登录授权报错的问题
    • 解决在使用 stable-diffusion-webui 时,安装 gfpgan 失败的方案(windows下的操作)
    • 通过 js 进行 shapefile 文件解析渲染方法
    • 部署脚本 deploy.sh
    • Tauri打包慢或者报错问题解决方法
    • Ubuntu和Nginx搭配Certbot配置SSL证书https访问网站
    • Centos下yum无法正常使用
    • Linux 系统下通过 Let‘s Encrypt 生成免费 https 证书的步骤
    • Mongo 风格的查询对象映射到 SQL 查询的 Node.js 库 json-sql
    • CentOS7安装与卸载anaconda3基础步骤
  • 前端开发
  • 其他文档
NoteZ
2022-08-29
目录

jsplumb 中文基础教程

# 1.什么是jsplumb?

你有没有想过在你的网站上展示图表或者甚至在浏览器应用程序中使用它?用jsPlumb你可以!它是完全免费的,并根据MIT许可证提供。您可以直接从jsPlumb github网站下载框架。

# 2.jsplumb能干什么?

那么如果你应该使用它取决于你想用jsPlumb做什么。该框架适用于必须绘制图表的Web应用程序,例如类似于Visio的应用程序或工作流程设计器等。由于图表项目和连接的所有参数都是非常精细可控的,因此您可以绘制您可以想到的任何类型的图表的!

# 3.基本概念

  • Souce 源节点
  • Target 目标节点
  • Anchor 锚点
  • Endpoint 端点
  • Connector 连接

官方文档

  • 官方GitHub:https://github.com/jsplumb/jsplumb (opens new window)
  • 官方DEMO:https://jsplumbtoolkit.com/demonstration/flowchart-builder (opens new window)

# 4.基础案例

# 4.1. 连接两个节点

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/01.html (opens new window)

jsPlumb.ready方法和jquery的ready方法差不多的功能,jsPlumb.connect用于建立连线

<div id="diagramContainer">
    <div id="item_left" class="item"></div>
    <div id="item_right" class="item" style="margin-left:50px;"></div>
</div>
<script src="https://cdn.bootcss.com/jsPlumb/2.6.8/js/jsplumb.min.js"></script>

<script>
    /* global jsPlumb */
    jsPlumb.ready(function () {
        jsPlumb.connect({
        source: 'item_left',
        target: 'item_right',
        endpoint: 'Dot'
        })
    })
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

参数说明:

jsPlumb.connect(config) return connection
1
参数 参数类型 是否必须 说明
source String,Object,Endpoint 是 连线源的标识,可以是id, element, 或者Endpoint
target String,Object,Endpoint 是 连线目标的标识,可以是id, element, 或者Endpoint
endpoint String 可选 端点类型,形状

>>> connect方法详情 (opens new window)

# 4.2. 可拖动节点

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/02.html (opens new window)

使用draggable可以让节点被拖动,draggable方法参考 (opens new window)

<div id="diagramContainer">
    <div id="item_left" class="item"></div>
    <div id="item_right" class="item" style="left:150px;"></div>
</div>
<script src="https://cdn.bootcss.com/jsPlumb/2.6.8/js/jsplumb.min.js"></script>

<script>
    /* global jsPlumb */
    jsPlumb.ready(function () {
        jsPlumb.connect({
        source: 'item_left',
        target: 'item_right',
        endpoint: 'Rectangle'
        })

        jsPlumb.draggable('item_left')
        jsPlumb.draggable('item_right')
    })
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

# 4.3. 连接的其他参数

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/03.html (opens new window)

可以通过connector去设置链接线的形状,如直线或者曲线之类的。anchor可以去设置锚点的位置。

jsplumb连线的样式有四种

  • Bezier: 贝塞尔曲线
  • Flowchart: 具有90度转折点的流程线
  • StateMachine: 状态机
  • Straight: 直线
<div id="diagramContainer">
    <div id="item_left" class="item"></div>
    <div id="item_right" class="item" style="left:150px;"></div>
</div>
<script src="https://cdn.bootcss.com/jsPlumb/2.6.8/js/jsplumb.min.js"></script>

<script>
    /* global jsPlumb */
    jsPlumb.ready(function () {
        jsPlumb.connect({
        source: 'item_left',
        target: 'item_right',
        endpoint: 'Rectangle',
        connector: ['Bezier'],
        anchor: ['Left', 'Right']
        })

        jsPlumb.draggable('item_left')
        jsPlumb.draggable('item_right')
    })
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

# 4.4. 设置连接的默认值

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/04.html (opens new window)

很多连线都是相同设置的情况下,可以将配置抽离出来,作为一个单独的变量,作为connect的第二个参数传入。实际上connect的第二个参数会和第一个参数merge,作为一个整体。

<script>
    /* global jsPlumb */
    jsPlumb.ready(function () {
        var common = {
            endpoint: 'Rectangle',
            connector: ['Bezier'],
            anchor: ['Left', 'Right']
        }

        jsPlumb.connect({
            source: 'item_left',
            target: 'item_right'
        }, common)

        jsPlumb.draggable('item_left')
        jsPlumb.draggable('item_right')
    })
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# 4.5. 给连接加上样式

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/05.html (opens new window)

例如给连线设置不同的颜色,设置不同的粗细之类的。

jsPlumb.connect({
  source: 'item_left',
  target: 'item_right',
  paintStyle: { stroke: 'lightgray', strokeWidth: 3 },
  endpointStyle: { fill: 'lightgray', outlineStroke: 'darkgray', outlineWidth: 2 }
}, common)
1
2
3
4
5
6

# 4.6. 给连接加上箭头

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/06.html (opens new window)

箭头实际上是通过设置overlays去设置的,可以设置箭头的长宽以及箭头的位置,location 0.5表示箭头位于中间,location 1表示箭头设置在连线末端。 一根连线是可以添加多个箭头的。

overlays也是一个比较重要的概念,overlays可以理解为遮罩层。遮罩层不仅仅可以设置箭头,也可以设置其他内容。

overlays有五种类型,下面给出简介。具体使用方法参见 https://jsplumbtoolkit.com/community/doc/overlays.html

  • Arrow 一个可配置的箭头
  • Label 标签,可以在链接上显示文字信息
  • PlainArrow 原始类型的箭头
  • Diamond 菱形箭头
  • Custom 自定义类型
jsPlumb.connect({
  source: 'item_left',
  target: 'item_right',
  paintStyle: { stroke: 'lightgray', strokeWidth: 3 },
  endpointStyle: { fill: 'lightgray', outlineStroke: 'darkgray', outlineWidth: 2 },
  overlays: [ ['Arrow', { width: 12, length: 12, location: 0.5 }] ]
}, common)
1
2
3
4
5
6
7

# 4.7. 增加一个端点

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/07.html (opens new window)

addEndpoint方法可以用来增加端点,具体使用请看 (opens new window)

jsPlumb.ready(function () {
    jsPlumb.addEndpoint('item_left', {
    anchors: ['Right']
    })
})
1
2
3
4
5

# 4.8. 拖动创建连接

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/08.html (opens new window)

如果你将isSource和isTarget设置成true,那么久可以用户在拖动时,自动创建链接。

jsPlumb.ready(function () {
    jsPlumb.setContainer('diagramContainer')

    var common = {
        isSource: true,
        isTarget: true,
        connector: ['Straight']
    }

    jsPlumb.addEndpoint('item_left', {
        anchors: ['Right']
    }, common)

    jsPlumb.addEndpoint('item_right', {
        anchor: 'Left'
    }, common)

    jsPlumb.addEndpoint('item_right', {
        anchor: 'Right'
    }, common)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

一般来说拖动创建的链接,可以再次拖动,让链接断开。如果不想触发这种行为,可以设置。

  jsPlumb.importDefaults({
    ConnectionsDetachable: false
  })
1
2
3

# 4.9. 给端点增加样式

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/09.html (opens new window)

通过设置各种 *Style来改变链接或者端点的样式。

jsPlumb.ready(function () {
    jsPlumb.setContainer('diagramContainer')
    var common = {
    isSource: true,
    isTarget: true,
    connector: 'Straight',
    endpoint: 'Dot',
    paintStyle: {
        fill: 'white',
        outlineStroke: 'blue',
        strokeWidth: 3
    },
    hoverPaintStyle: {
        outlineStroke: 'lightblue'
    },
    connectorStyle: {
        outlineStroke: 'green',
        strokeWidth: 1
    },
    connectorHoverStyle: {
        strokeWidth: 2
    }
    }

    jsPlumb.addEndpoint('item_left', {
        anchors: ['Right']
    }, common)

    jsPlumb.addEndpoint('item_right', {
        anchor: 'Left'
    }, common)

    jsPlumb.addEndpoint('item_right', {
        anchor: 'Right'
    }, common)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

# 4.10. 节点改变尺寸

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/10.html (opens new window)

jsplumb实际上不支持改变节点大小,实际上只能通过jquery ui resizable 方法去改变。

<div id="diagramContainer">
    <div id="item_left" class="item"></div>
    <div id="item_right" class="item" style="left:150px;"></div>
</div>
  <script src="https://code.jquery.com/jquery-1.11.3.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script src="./lib/jquery.jsplumb.js"></script>

  <script>
    /* global jsPlumb, $ */
    $('.item').resizable({
      resize: function (event, ui) {
        jsPlumb.repaint(ui.helper)
      }
    })

    jsPlumb.ready(function () {
      jsPlumb.connect({
        source: 'item_left',
        target: 'item_right',
        endpoint: 'Rectangle'
      })

      jsPlumb.draggable('item_left')
      jsPlumb.draggable('item_right')
    })
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

# 4.11. 限制节点拖动区域

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/11.html (opens new window)

默认情况下,节点可以被拖动到区域外边,如果想只能在区域内拖动,需要设置containment,这样节点只能在固定区域内移动。

jsPlumb.setContainer('area-id')
1

# 4.12. 节点网格对齐

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/12.html (opens new window)

网格对齐实际上是设置了grid属性,使移动只能按照固定的尺寸移动。然后用一张图作为背景铺开作为网格来实现的。

#diagramContainer {
  padding: 20px;
  width: 80%;
  height: 400px;
  border: 1px solid gray;
  background-image: url(xxx.jpeg);
  background-repeat: repeat;
}
1
2
3
4
5
6
7
8
jsPlumb.draggable('item_left', {
  containment: 'parent',
  grid: [10, 10]
})
1
2
3
4

# 4.13. 给链接添加点击事件:点击删除连线

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/13.html (opens new window)

// 请单点击一下连接线, 
jsPlumb.bind('click', function (conn, originalEvent) {
  if (window.prompt('确定删除所点击的链接吗? 输入1确定') === '1') {
    jsPlumb.detach(conn)
  }
})
1
2
3
4
5
6

jsPlumb支持许多事件

jsPlumb Events列表

  • connection
  • connectionDetached
  • connectionMoved
  • click
  • dblclick
  • endpointClick
  • endpointDblClick
  • contextmenu
  • beforeDrop
  • beforeDetach
  • zoom
  • Connection Events
  • Endpoint Events
  • Overlay Events
  • Unbinding Events

参考用法参考:https://jsplumbtoolkit.com/community/doc/events.html#jsPlumbEvents (opens new window)

# 4.14. 删除节点,包括节点相关的连接

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/14.html (opens new window)

// nodeId为节点id, remove方法可以删除节点以及和节点相关的连线
console.log('3 秒后移除左边节点包括它的连线')
setTimeout(function () {
  jsPlumb.remove('item_left')
}, 3000)
1
2
3
4
5

注意remove方法有些情况下是无法删除干净连线的,查看详情:https://jsplumbtoolkit.com/community/doc/removing.html (opens new window)

# 4.15. 通过编码连接endPoint

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/15.html (opens new window)

初始化数据后,给节点加上了endPoint, 如果想编码让endPoint链接上。需要在addEndpoint时,就给该断点加上一个uuid, 然后通过connect()方法,将两个断点链接上。建议使用node-uuid (opens new window)给每个断点都加上唯一的uuid, 这样以后链接就方便多了。

jsPlumb.addEndpoint('item_left', {
  anchors: ['Right'],
  uuid: 'fromId'
})

jsPlumb.addEndpoint('item_right', {
  anchors: ['Left'],
  uuid: 'toId'
})

console.log('3 秒后建立连线')
setTimeout(function () {
  jsPlumb.connect({ uuids: ['fromId', 'toId'] })
}, 3000)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 4.16. 连接前的检查,判断是否建立连接

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/16.html (opens new window)

有时候当用户从A端点链接到B端点时,需要做一些检查,如果不符合条件,就不让链接建立。

// 当链接建立前
jsPlumb.bind('beforeDrop', function (info) {
  var a = 10
  var b = 2
  if (a < b) {
    console.log('链接会自动建立')
    return true // 链接会自动建立
  } else {
    console.log('链接取消')
    return false // 链接不会建立,注意,必须是false
  }
})
1
2
3
4
5
6
7
8
9
10
11
12

# 4.17. 一个端点如何拖拽出多条连线

默认情况下,maxConnections的值是1,也就是一个端点最多只能拉出一条连线。

你也可以设置成其他值,例如5,表示最多可以有5条连线。

如果你想不限制连线的数量,那么可以将该值设置为-1

var common = {
  isSource: true,
  isTarget: true,
  connector: ['Straight'],
  maxConnections: -1
}

jsPlumb.addEndpoint('item_left', {
  anchors: ['Right']
}, common)
1
2
3
4
5
6
7
8
9
10

# 4.18. 整个节点作为source或者target

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/18.html (opens new window)

整个节点作为source或者target, 并且将锚点设置成Continuous,那么锚点就会随着节点的位置改变而改变自己的位置。

jsPlumb的锚点分为四类

  • Static 静态 固定位置的锚点
  • Dynamic jsPlumb自动选择合适的锚点,动态锚点
  • Perimeter 边缘锚点,会根据节点形状去改变位置
  • Continuous 根据节点位置,自动调整位置的锚点

详情:https://jsplumbtoolkit.com/community/doc/anchors.html (opens new window)

window.jsPlumb.ready(function () {
    var jsPlumb = window.jsPlumb

    jsPlumb.makeSource('A', {
        endpoint:"Dot",
        anchor: "Continuous"
    })

    jsPlumb.makeTarget('B', {
        endpoint:"Dot",
        anchor: "Continuous"
    })

    jsPlumb.draggable('A')
    jsPlumb.draggable('B')
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# 4.19. 节点缩放

演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/19.html (opens new window)

window.jsPlumb.ready(function () {
    var jsPlumb = window.jsPlumb
    jsPlumb.setContainer("diagramContainer")

    jsPlumb.connect({
    source: 'A',
    target: 'B',
    endpoint: 'Dot'
    })
    
    var baseZoom = 1
    setInterval(() => {
    baseZoom -= 0.1
    if (baseZoom < 0.5) {
        baseZoom = 1
    }
    zoom(baseZoom)
    }, 1000)
})

function zoom (scale) {
    $("#diagramContainer").css({
        "-webkit-transform": `scale(${scale})`,
        "-moz-transform": `scale(${scale})`,
        "-ms-transform": `scale(${scale})`,
        "-o-transform": `scale(${scale})`,
        "transform": `scale(${scale})`
    })
    jsPlumb.setZoom(0.75);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

# 5. jsPlumb默认配置简介

参考地址: https://jsplumbtoolkit.com/community/doc/defaults.html (opens new window)

jsPlumb的配置项有很多,如果你不主动去设置,那么jsPlumb就使用默认的配置。

另外建议你不要修改默认的配置,而是使用自定义的方式。

另外一点要注意,如果你想修改默认配置,那么使用importDefaults方法,并且属性的首字母要大写。如果你用addEndpoint, 并使用类似maxConnections的属性,那么首字母要小写。

参见演示地址: https://wdd.js.org/jsplumb-chinese-tutorial/demos/17.html (opens new window)

demo上需要你自己手动拖动创建链接。

var common = {
  isSource: true,
  isTarget: true,
  connector: ['Straight'],
  maxConnections: -1
}

jsPlumb.addEndpoint('item_left', {
  anchors: ['Right']
}, common)
1
2
3
4
5
6
7
8
9
10
Anchor : "BottomCenter",
Anchors : [ null, null ],
ConnectionsDetachable   : true,
ConnectionOverlays  : [],
Connector : "Bezier",
Container : null,
DoNotThrowErrors  : false,
DragOptions : { },
DropOptions : { },
Endpoint : "Dot",
Endpoints : [ null, null ],
EndpointOverlays : [ ],
EndpointStyle : { fill : "#456" },
EndpointStyles : [ null, null ],
EndpointHoverStyle : null,
EndpointHoverStyles : [ null, null ],
HoverPaintStyle : null,
LabelStyle : { color : "black" },
LogEnabled : false,
Overlays : [ ],
MaxConnections : 1,
PaintStyle : { strokeWidth : 8, stroke : "#456" },
ReattachConnections : false,
RenderMode : "svg",
Scope : "jsPlumb_DefaultScope"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

你也可以从jsPlumb.Defaults对象中查看默认的配置。如果你想要更加个性化的设置连线,那么最好可以了解一下,它的默认设置有哪些,从而方便的来完成自己的设计需求。

默认参数的简介:

  • Anchor 锚点,即端点链接的位置
  • Anchors 多个锚点 [源锚点,目标锚点].
  • Connector 链接
  • ConnectionsDetachable 节点是否可以用鼠标拖动使其断开,默认为true。即用鼠标链接上的连线,也可以使用鼠标拖动让其断开。设置成false,可以让其拖动也不会自动断开。
  • Container 连线的容器
  • DoNotThrowErrors 是否抛出错误
  • ConnectionOverlays 链接遮罩层
  • DragOptions 拖动设置
  • DropOptions 拖放设置
  • Endpoint 端点
  • Endpoints 数组形式的,[源端点,目标端点]
  • EndpointOverlays 端点遮罩层
  • EndpointStyle 端点样式
  • EndpointStyles [源端点样式,目标端点样式]
  • EndpointHoverStyle 端点鼠标经过的样式
  • EndpointHoverStyles [源端点鼠标经过样式,目标端点鼠标经过样式]
  • HoverPaintStyle 鼠标经过链接线时的样式
  • LabelStyle 标签样式
  • LogEnabled 是否启用日志
  • Overlays 连接线和端点的遮罩层样式
  • MaxConnections 端点最大连接线数量默认为1, 设置成-1可以表示无数个链接
  • PaintStyle 连线样式
  • ReattachConnections 端点是否可以再次重新链接
  • RenderMode 渲染模式,默认是svg
  • Scope 作用域,用来区分哪些端点可以链接,作用域相同的可以链接
// 可以使用importDefaults,来重写某些默认设置
jsPlumb.importDefaults({
  PaintStyle : {
    strokeWidth:13,
    stroke: 'rgba(200,0,0,0.5)'
  },
  DragOptions : { cursor: "crosshair" },
  Endpoints : [ [ "Dot", { radius:7 } ], [ "Dot", { radius:11 } ] ],
  EndpointStyles : [{ fill:"#225588" }, { fill:"#558822" }]
});
1
2
3
4
5
6
7
8
9
10

# 6. 有没有稍微复杂一点,带有拖放的栗子?

项目地址:https://github.com/wangduanduan/visual-ivr (opens new window) ,将views目录下的drag-drop-demo.html拖放到浏览器中,就可以愉快的玩耍了。

从该demo中除了可以学到基本的jsplumb的api, 也可以学到其他的关于拖放的知识点。其中目前只做了语音节点的拖放,其他的还时间做。该demo没有使用webpack打包,代码写的有点乱,大家凑合着看,有问题可以提issue, 或者评论。

# 7. 实战项目 一个可视化IVR编辑器

项目地址:https://github.com/wangduanduan/visual-ivr (opens new window) 该项目还在开发完善中,不过已经具备基本功能。

该项目是用webpack打包的项目,所有文件都在src目录下。

图1是基于jsplumb做的最基础的版本,图2是最近优化后的版本,该版本未开源。

# 8. 还有哪些类似的图形连线可视化项目

# 8.1. G6 AntV

https://github.com/antvis/g6 (opens new window)

# 8.2. VivaGraphJS

https://github.com/anvaka/VivaGraphJS (opens new window)

# 8.3. springy

https://github.com/dhotson/springy (opens new window)

# 8.4. graphviz

https://www.graphviz.org/about (opens new window)

中文有个基本的介绍文档写的不错,参考:https://casatwy.com/shi-yong-dotyu-yan-he-graphvizhui-tu-fan-yi.html (opens new window)

graphviz可以把你写的.dot文件渲染成一张图。

mac上首先要安装:brew install graphviz

然后如果你用vscode的话,vscode上又graphviz的扩展插件,可以预览你的dot文件。

总体来说,graphviz的功能十分强大,同时它也提供了其他语言的脚本api来方便绘图。总之,如果你不想通过拖拉拽来绘制一些流程图,又对图形布局不是很感兴趣的话,graphviz是一个免费而且效率高而且能装逼的工具

# 8.5. visjs

http://visjs.org/index.html (opens new window)

该项目看起来不错,github上将近有7000 star, 但是它的开发者似乎没时间维护该项目了,正在给该项目找下家。

# 8.6. vue-jsplumb-workflow

https://gitee.com/zlluGitHub/vue-jsplumb-workflow (opens new window)

# 9. 参考资源

  • jsPlumb Class (opens new window)
  • freedevelopertutorials jsplumb-tutorial (opens new window)
#JsPlumb
上次更新: 2024/01/30, 00:35:17
echarts 使用案例(demo)
Linux服务器(centos7)使用LibreOffice将Word转换PDF文档出现中文乱码或方格解决方法

← echarts 使用案例(demo) Linux服务器(centos7)使用LibreOffice将Word转换PDF文档出现中文乱码或方格解决方法→

最近更新
01
Gitea数据备份与还原
03-10
02
Linux 中使用 rsync 同步文件目录教程
03-10
03
Linux 使用 rsync 互相传输同步文件的简单步骤
03-08
更多文章>
Theme by Vdoing | Copyright © 2019-2025 NoteZ,All rights reserved | 冀ICP备2021027292号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式