10.折线连接--WEB设计器JQUERY插件讲解(含源码)

关键字:设计器源代码,Web设计器,工作流设计器,jQuery插件,组态设计器,SCADA系统设计器,流程图设计,表单设计建模,报表设计,可视化,设计时,运行时,轻量级开放平台。

前面章节已讲到如何在两个组件间通过曲线(贝塞尔曲线)进行连接,一般在实际应用中,贝塞尔曲线在数据流图、思维导图中应用比较多,许多如组织架构图等通过折线连接,本文在之前的基础上如何快速实现两个组件间的折线连接:

之前示例是用checkbox来指示是否画线状态,现在增加了一种线条所以需要修改一下用三种状态来识别是选择/曲线/折线之一,index.html中代码片断如下:

<ul class="lineTypeUL"><li class="arrowli active"></li><li class="lineCurve"></li><li class="linePoly"></li></ul>
//样式定义如下:
    <style>
        .lineTypeUL{
            display:inline-block;
            text-align:center;
            border:1px solid lightgray;
            border-radius: 3px;
        }
        .lineTypeUL li{
            display:inline-block;
            background-image: url("icons.png");
            width:18px;
            height:18px;
            margin:2px;
        }
        .lineTypeUL li:hover{
            background-color:lightgray;
        }
        .lineTypeUL .active{
            background-color:lightgray;
        }
        .arrowli{
            background-position:0 0px;
        }
        .lineCurve{
            background-position: -18px 0px;
        }
        .linePoly{
            background-position:-36px 0px;
        }
    </style>
//事件代码:
        $(".lineTypeUL li").each(
            function(){
                $(this).on("click", function () {
                    $(".lineTypeUL li").removeClass("active");
                    view.setLineStatus(this.className);
                    $(this).addClass("active");
                })
            }
        )

对于前端开发来说必须掌握的一个技能就是spirit图标,一个网站用到的图标通过合并在一个文件中,能够减少网站资源请求的次数(虽然是异步并行请求),提高效率,注意background的用法。

在visualDesigner.js中,增加一个PolyLine类,同BezierLine的写法:

function PolyLine() {
        this.properties={};
        this.properties.typeName = "折线";
        this.properties.strokeWidth = 2;
        this.properties.strokeColor = ‘red‘;
    }
    PolyLine.prototype = $.extend({}, Component.prototype);
    PolyLine.prototype = $.extend(PolyLine.prototype, {
        render: function (options) {

            this.properties=$.extend(this.properties,options)
            this.properties.x = Math.min(this.properties.sxy.x, this.properties.txy.x);
            this.properties.y = Math.min(this.properties.sxy.y, this.properties.txy.y);
            this.properties.width = Math.abs(this.properties.txy.x - this.properties.sxy.x);
            this.properties.height = Math.abs(this.properties.txy.y - this.properties.sxy.y);

            this.group=new paper.Group();
            this.properties.x=Math.min(this.properties.sxy.x,this.properties.txy.x);
            this.properties.y=Math.min(this.properties.sxy.y,this.properties.txy.y);
            this.properties.width = Math.abs(this.properties.txy.x - this.properties.sxy.x);
            this.properties.height = Math.abs(this.properties.txy.y - this.properties.sxy.y);

            if (this.properties.targetType=="left" || this.properties.targetType=="right")
            {
                if (this.properties.mxy1==undefined && this.properties.mxy2==undefined){
                    this.properties.mxy1=[this.properties.sxy.x+(this.properties.txy.x-this.properties.sxy.x)/2,this.properties.sxy.y];
                    this.properties.mxy2=[this.properties.sxy.x+(this.properties.txy.x-this.properties.sxy.x)/2,this.properties.txy.y];
                }
                else
                {
                    this.properties.mxy1[1]=this.properties.sxy.y;
                    this.properties.mxy2[1]=this.properties.txy.y;
                }
            }
            else
            {
                if (this.properties.mxy1==undefined && this.properties.mxy2==undefined){
                    this.properties.mxy1=[this.properties.sxy.x,(this.properties.txy.y-this.properties.sxy.y)/2+this.properties.sxy.y];
                    this.properties.mxy2=[this.properties.txy.x,(this.properties.txy.y-this.properties.sxy.y)/2+this.properties.sxy.y];
                }
                else
                {
                    this.properties.mxy1[0]=this.properties.sxy.x;
                    this.properties.mxy2[0]=this.properties.txy.x;
                }
            }

            this.group=new paper.Group();
            var me = this;
            var drag = false;
            var line = new paper.Path();
            line.strokeWidth = 2;

            line.strokeColor = this.properties.strokeColor;
            line.add(this.properties.sxy);
            line.add(this.properties.mxy1);
            line.add(this.properties.mxy2);
            line.add(this.properties.txy);
            //BezierArrow(line,targetType,this.properties.txy.x, this.properties.txy.y);
            this.group.addChild(line);

            //this.group.translate(this.properties.x, this.properties.y);
            return this;
        }
    });

同时修改createLine方法

    VisualDesigner.prototype.createLine= function (typeName, options) {
        if (!options.id)
            options.id = this.createId(); //为元素增加id属性
        var element = null;
        switch (typeName) {
            case "曲线":
                element = new BezierLine().init().render(options);
                break;
            case "折线":
                element=new PolyLine().init().render(options);
                break;
        }
        this.lines[element.properties.id] = element;
        element.designer = this;

    } 

增加一创建线条的分支,当然还需要修改当前画线类型和画线结束的代码

    VisualDesigner.prototype.setLineStatus = function (status) {
        if (status=="arrowli")
            this.lining = false;
            else
            {
                this.lining=true;
                if (status=="lineCurve")
                    this.lineType="曲线";
                else if (status="linePoly")
                    this.lineType="折线";
            }
    }
。。。。
        dragEnd:function(co,pos)
        {
            var xy = co.node.getConnectorCenterByPos(pos); //获取当前鼠标位置处连接点的中央坐标
            if (this.line !== null  ) {
                if (this.start.node.properties.id!=co.node.properties.id){
                    this.designer.createLine(this.designer.lineType,{sourceType:this.start.node.getConnectorDirection(this.startPos),targetType:co.node.getConnectorDirection(pos),source:this.start.node.properties.id,target:co.node.properties.id,sxy:this.startPos,txy:xy});
                }
                this.line.remove();

            }
            this.start=null; //清除画线状态,等待重新画线
            this.startPos=null;

        },

至此就大功告成了,得益于之前我们以OOP的思路构建的框架,在扩展新的组件或连线时,代码变得如些精简。

同学们快动手试试增加更多的连线方式吧。

源代码:sample.1.8.rar

(本文为原创,在引用代码和文字时请注明出处)

原文地址:https://www.cnblogs.com/coolalam/p/9712828.html

时间: 2024-07-29 03:29:57

10.折线连接--WEB设计器JQUERY插件讲解(含源码)的相关文章

13.美化界面--WEB设计器JQUERY插件讲解(含源码)

今天花了一个小时对页面略做了一些美化,看起来更专业了点, 主要是一些背景图片之类的样式调整,初学者可以看下,如何切分spirit图片,遇到问题主要是LI中的元素如何垂直居中的问题(解决方案是li设置height和line-height相同),增加了一个span用于显示图片,但它的对齐花了不少时间. 代码如下: sample1.11.zip 关键字:设计器源代码,Web设计器,工作流设计器,jQuery插件,组态设计器,SCADA系统设计器,流程图设计,表单设计建模,报表设计,可视化,设计时,运行

jQuery插件pagination.js源码解读

pagination的github地址:https://github.com/gbirke/jquery_pagination 公司用的是1.2的版本,所以我就读1.2的了. jQuery.fn.pagination = function(maxentries, opts){ opts = $.extend({ isCurrentInfo: false,//是否显示当前页信息: 当前第1页,共10页 currentCls: '.current-info',//当前页class items_per

jQuery插件ajaxfileupload.js源码与使用

在网页应用中,一般会用到上传文件或者图片什么的到服务器,那么可以用ajaxfileupload.js,但是在使用ajaxfileupload.js时候,当服务器返回的json带有&符号的时候,返回的data数据里面所有的&被转义成了&.下面的ajaxfileupload.js是经过修改的文件上传库. jQuery.extend({ /** createUploadIframe 创建上传的iframe * @param id 传递当前系统的时间字符串 * @param uri 传入的

开源工作流引擎web设计器Activiti Modeler 5.17.0 与IE11的兼容性探究

一.源码下载 Activiti官网:http://activiti.org/ github:https://github.com/Activiti/Activiti 官网上下载的是lib库文件.文档和网站样例,推荐使用maven管理项目,可以不用下载库文件,直接下载源码,github上源码已经是5.18.0,但是官方还没有发布,从以下网址找到5.17.0的source code下载链接下载即可:https://github.com/Activiti/Activiti/releases,大小为20

安装Signavio Web设计器

在Jbpm3版本中,这个著名的开源项目并没有基于浏览器的图形化流程设计器,结果导致流程设计一直停留在CS阶段. 比如我之前做过的一个OA项目,项目中采用的就是Jbpm3,由于它不支持在浏览器中的图形化流程设计器,我们就需要跟客户进行充分沟通,然后在Eclipse中设计好流程,最后再将对应的图片与xml文件同时上传,然后再进行部署,想一想,这个过程是比较烦琐的. 在Jbpm4.1版本以后,开始支持网页设置业务流程,它就是Signavio Web设计器.本文将介绍安装这个设计器以及遇到的问题. Jb

10个web前端jQuery开发者必备的源码组件

1.Conditioniz – 探测浏览器并条件加载 JavaScript 和 CSS Conditioniz 是一个快速.轻量级(3KB)的 JavaScript 工具,用于探测浏览器和分辨率并条件加载 JavaScript 和 CSS 文件.Conditioniz 从它的 jQuery 前身重建,现在速度要快50%.结合类名添加和 Conditionizr 集成的脚本和样式加载功能,允许你为不同的浏览器指定想加载的脚本和样式.浏览器嗅探通常被认为是不可靠的,Conditionizr 的建立就

android插件化-apkplugdemo源码阅读指南-10

阅读本节内容前可先了解 apkplug基础教程 本教程是基于apkplug V1.6.8 版本编写  最新开发方式以官网为准 可下载最新的apkplugdemo源码http://git.oschina.net/plug/apkplugDemos apkplugdemo演示图 一 apkplugdemo工程源码结构 src |-com.apkplugdemo.adapter             --插件列表Adapter |-com.apkplugdemo.adapter.base     

分享一组很赞的 jQuery 特效【附源码下载】

作为最优秀的 JavaScript 库之一,jQuery 不仅使用简单灵活,同时还有许多成熟的插件可供选择,它可以帮助你在项目中加入漂亮的效果.这篇文章挑选了8个优秀的 jQuery 实例教程,这些 jQuery 教程将帮助你把你的网站提升到一个更高的水平. 您可能感兴趣的相关文章 Web 开发中很实用的10个效果[源码下载] 精心挑选的优秀jQuery Ajax分页插件和教程 12个让人惊叹的的创意的 404 错误页面设计 让网站动起来!12款优秀的 jQuery 动画插件 十分惊艳的8个 H

3种精美Web前端搜索框展示(附源码)

1.  jQuery按栏目搜索框代码 赶紧来体验一下. 源码下载/  在线演示 2.  CSS3带凹槽搜索框 这个插件集成了一些非常好的 JavaScript 库,提供一个方便使用的文本动画插件. 源码下载/  在线演示 3.jQuery视频侧边隐藏搜索框 jquery实现的,会在当鼠标光标移动到接近(或通过)视口(viewport)的顶部的时候触发. 源码下载 /   在线演示 3种精美Web前端搜索框展示(附源码)