1. jsPlumb概述
    jsPlumb是一个在dom元素之间绘制连接线的javascript框架,它使用svg技术绘制连接线。
  2. 基本概念
    很明显,一个连线主要要解决的问题包括谁和谁连,在哪里连(连接点在哪里),连接点长啥样,如何画线等问题
    1:Anchor,锚点,它是一个逻辑概念,解决连线的连接点位置问题。
    2:Endpoint,端点,它是一个可视化的点,解决 连接点长啥样的问题
    3:Connector,连线,解决如何画线的问题
    4:Overlay,覆盖物,它主要为连接添加一些装饰物,不如标签文本,连接点的箭头。Anchor:
    锚点的定义方式主要有下面几种
    1:用数组来定义
    [x位置,y位置,x方向,y方向]
    [x位置,y位置,x方向,y方向,x像素偏移,y像素偏移]
    位置的值在0~1之间
    方向的值为0,1,-1
    9个静态的值为:
    Top TopRight
    Right BottomRight
    Bottom BottomLeft
    Left TopLeft
    Center
    AutoDefault 包括Top, Right, Bottom, Left
    需要注意的是,坐标使用第四象限的坐标
    一个常用的组合是:
    var defaultAnchors = ["Top", "Right", "Bottom", "Left", [0.25, 0, 0, -1], [0.75, 0, 0, -1], [0.25, 1, 0, 1], [0.75, 1, 0, 1]
    , [0, 0.25, 0, -1], [0, 0.75, 0, -1], [1, 0.25, 0, 1], [1, 0.75, 0, 1]];
    2:几何图形的周边
    Circle Ellipse Triangle Diamond Rectangle Square
    anchor:[{ shape:"Triangle", anchorCount:150, rotation:25 } ]
    3:连续
    anchor:["Continuous", { faces:[ "top", "left" ] } ]

    Endpoint:
    jsPlumb提供了四种类型的端点,
    Dot,Rectangle,
    Blank,使用失败了。
    Image,使用失败了。

    Connectors
    jsPlumb提供了四种类型的连线,
    Bezier,StateMachine,Flowchart,Straight

    Overlay
    jsPlumb提供了3种类型的覆盖物,
    Arrow:箭头
    Label:标签
    Custom:自定义的html元素
    ConnectionOverlays: [
    ["Arrow", {
    location: 1,
    //foldback: 1,
    foldback: 0.618, ///0.618: 普通箭头,1:平底箭头,2:钻石箭头
    visible: true,
    id: "arrow"
    }],
    ["Label", { location: 0.5,
    cssClass: "endpointTargetLabel",
    visible: true,
    id: "label" }]
    ]

  3. 几个需要注意的地方:
    1:所有的子元素在一个父容器中,并且子元素都要使用绝对布局
    position: absolute;
    2:端点可以通过样式隐藏,直接使用"Blank"报错了。
    3:性能,在多个连接的时候,需要使用批处理模式来绘制。
    sintoonUx.jsPlumbInstance.setSuspendDrawing(true)
    sintoonUx.jsPlumbInstance.setSuspendDrawing(false, true);
    4:设置可拖拽
    sintoonUx.jsPlumbInstance.draggable(btnDoms);
  4. 使用范例
        drawConnectLine: function () {
    var sintoonUx = this;
    /// 定义锚点的位置
    var defaultAnchors = ["Top", "Right", "Bottom", "Left", [0.25, 0, 0, -1], [0.75, 0, 0, -1], [0.25, 1, 0, 1], [0.75, 1, 0, 1]
    , [0, 0.25, 0, -1], [0, 0.75, 0, -1], [1, 0.25, 0, 1], [1, 0.75, 0, 1]];
    /// 创建实例,配置默认的绘制属性,建立通用绘图方式等
    sintoonUx.jsPlumbInstance = jsPlumb.getInstance({
    PaintStyle: {
    lineWidth: 2,
    strokeStyle: "blue",
    outlineColor: "blue",
    dashstyle: "4 2",
    outlineWidth: 1
    },
    // Connector: ["Bezier", { curviness: 30 }],
    // Connector: ["StateMachine"],
    // Connector: ["Flowchart", { stub: [40, 60], gap: 10, cornerRadius: 5, alwaysRespectStubs: true }],
    Connector: ["Straight", { stub: [20, 50], gap: 0 }], Endpoint: ["Dot", { radius: 5, cssClass: "displaynone" }],/// 通过样式来隐藏锚点
    //Endpoint: ["Image ", { src: "http://rmadyq.sintoon.cn/Content/16Icons/arrow_right.png" }],/// 通过样式来隐藏锚点
    // Endpoint: ["Blank", "Blank"], 失败报错了,
    EndpointStyle: { fillStyle: "#567567" },
    Anchor: [defaultAnchors],
    // Anchor: ["Perimeter", { shape: "Triangle" }],
    Container: sintoonUx.flowchartContainerId,
    DragOptions: { cursor: 'pointer', zIndex: 2000 },
    ConnectionOverlays: [
    ["Arrow", {
    location: 1,
    //foldback: 1,
    foldback: 0.618,
    visible: true,
    id: "arrow"
    }],
    ["Label", { location: 0.5, label: "zhu", cssClass: "endpointTargetLabel", visible: true, id: "label" }]
    ]
    }); /// 绘制标签
    sintoonUx.jsPlumbInstance.bind("connection",
    function (connInfo, originalEvent) {
    var connection = connInfo.connection;
    var labelText = connection.sourceId.substring(0, 15) + "-" + connection.targetId.substring(0, 15);
    labelText = Ext.String.format("{0}---{1}", Ext.getCmp(connection.sourceId).flowStage,
    Ext.getCmp(connection.targetId).flowStage);
    connection.getOverlay("label").setLabel(labelText);
    }); /// 批处理绘制
    sintoonUx.jsPlumbInstance.setSuspendDrawing(true);
    var searchPat = Ext.String.format("#{0} .btnDraggable", sintoonUx.flowchartContainerId);
    var btnDoms = sintoonUx.jsPlumbInstance.getSelector(searchPat); /// 设置dom元素的可拖拽性
    sintoonUx.jsPlumbInstance.draggable(btnDoms); /// 建立dom元素之间的连接,绘制连接线,锚点,覆盖物等
    for (var i = 0; i < sintoonUx.btnConfigs.length - 1; i++) {
    sintoonUx.jsPlumbInstance.connect({ reattach: true, source: sintoonUx.btnConfigs[i].btnId, target: sintoonUx.btnConfigs[i + 1].btnId });
    } /// 强制绘制整个界面
    sintoonUx.jsPlumbInstance.setSuspendDrawing(false, true);
    }

      

jsPlumb的简单使用的更多相关文章

  1. 使用 jsPlumb 绘制拓扑图 —— 异步加载与绘制的实现

    本文实现的方法可以边异步加载数据边绘制拓扑图. 有若干点需要说明一下: 1.  一次性获取所有数据并绘制拓扑图, 请参见文章: <使用 JsPlumb 绘制拓扑图的通用方法> ; 本文实现 ...

  2. 使用jsPlumb制作流程图设计器

    jsPlumb是一个比较强大的绘图组件,它提供了一种方法,主要用于连接网页上的元素.在现代浏览器中,它使用SVG或者Canvas技术,而对于IE8以下(含IE8)的古董浏览器,则使用VML技术. 项目 ...

  3. jsPlumb插件做一个模仿viso的可拖拉流程图

    前言 这是我第一次写博客,心情还是有点小小的激动!这次主要分享的是用jsPlumb,做一个可以给用户自定义拖拉的流程图,并且可以序列化保存在服务器端. 我在这次的实现上面做得比较粗糙,还有分享我在做j ...

  4. jsPlumb开发入门教程(实现html5拖拽连线)

    jsPlumb是一个强大的JavaScript连线库,它可以将html中的元素用箭头.曲线.直线等连接起来,适用于开发Web上的图表.建模工具等.它同时支持jQuery+jQuery UI.MooTo ...

  5. jsPlumb之流程图项目总结及实例

    在使用jsPlumb过程中,所遇到的问题,以及解决方案,文中引用了<数据结构与算法JavaScript描述>的相关图片和一部分代码.截图是有点多,有时比较懒,没有太多的时间去详细的编辑. ...

  6. jsplumb 中文教程

    https://wdd.js.org/jsplumb-chinese-tutorial/#/ 1. jsplumb 中文基础教程 后续更新会在仓库:https://github.com/wangdua ...

  7. 前端流程图jsplumb学习笔记

    1.这篇博客很好,另外两个是官网文档 http://www.cnblogs.com/leomYili/p/6346526.html https://jsplumbtoolkit.com/communi ...

  8. [转]jsPlumb插件做一个模仿viso的可拖拉流程图

    原贴:https://www.cnblogs.com/sggx/p/3836432.html 前言 这是我第一次写博客,心情还是有点小小的激动!这次主要分享的是用jsPlumb,做一个可以给用户自定义 ...

  9. jsPlumb学习笔记

    这就是一个给元素画连接线的工具. <!DOCTYPE html> <html> <head> <title>jsPlumb</title> ...

随机推荐

  1. Quartz 线程处理

    官网 http://www.quartz-scheduler.net/ 相关的 Log 说明 http://netcommon.sourceforge.net/docs/2.1.0/reference ...

  2. 【MySQL】漫谈MySQL中的事务及其实现

    最近一直在做订单类的项目,使用了事务.我们的数据库选用的是MySQL,存储引擎选用innoDB,innoDB对事务有着良好的支持.这篇文章我们一起来扒一扒事务相关的知识. 为什么要有事务? 事务广泛的 ...

  3. 写出形似QML的C++代码

    最开始想出的标题是<Declarative C++ GUI库>,但太标题党了.只写了两行代码,连Demo都算不上,怎么能叫库呢……后来想换掉“库”这个字,但始终找不到合适词来替换.最后还是 ...

  4. vim常用操作

    vim filename 编辑一个文件 在一般模式里按yy是复制的意思(复制当前行),按yy之前先按相应的数字键就是复制光标所在行到指定的行,然后按p粘贴在一般模式里按dd是删除的意思(也叫做剪切), ...

  5. c# 进程间的通信实现之一简单字符串收发

       使用Windows API实现两个进程间(含窗体)的通信在Windows下的两个进程之间通信通常有多种实现方式,在.NET中,有如命名管道.消息队列.共享内存等实现方式,这篇文章要讲的是使用Wi ...

  6. Json序列化,date类型转换后前端显示错误的解决方案

    1.前台使用Jquery解决 (1)如果我们前台使用Jquery来解决这个问题的话,那么我们首先想到的是我们如何解析这个过程呢,当然我们就想到了自己写一个JavaScript脚本来解析这个过程,当然这 ...

  7. java class的property的get和set方法生成规则

    package rh.intellicareAppServer.dao; public class test { String aA; String aa; public String getaA() ...

  8. mysql分组函数

    组函数针对的是指定字段的非空值.注意:where子句中不能出现组函数!!! avg()    平均值(只能针对数值型 ) max()    最大值(不限制类型) min()    最小值(不限制类型) ...

  9. controller共享数据

    刚开始使用angularjs,能感受到他的强大,也在学习的途中遇到一些问题 一般我们在angularjs中共享数据使用DI的方法,具体代码如下: <script> angular.modu ...

  10. Java值传递以及引用的传递、数组的传递!!

    转(http://blog.csdn.net/niuniu20008/article/details/2953785) 许多编程语言都有2种方法将参数传递给方法------按值传递和按引用传递. 与其 ...