9 lines
70 KiB
JavaScript
Executable File
9 lines
70 KiB
JavaScript
Executable File
/*!
|
|
* ZUI: ZUI FlowChart View - v1.10.0 - 2022-06-09
|
|
* http://openzui.com
|
|
* GitHub: https://github.com/easysoft/zui.git
|
|
* Copyright (c) 2022 cnezsoft.com; Licensed MIT
|
|
*/
|
|
!function(){"use strict";var t="function";Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(t){var e=this.length,o=Number(arguments[1]);for(isNaN(o)?o=e-1:(o=o<0?Math.ceil(o):Math.floor(o),o<0?o+=e:o>=e&&(o=e-1));o>-1;o--)if(o in this&&this[o]===t)return o;return-1}),Array.prototype.every||(Array.prototype.every=function(e){var o=this.length;if(typeof e!=t)throw new TypeError;for(var r=arguments[1],i=0;i<o;i++)if(i in this&&!e.call(r,this[i],i,this))return!1;return!0}),Array.prototype.filter||(Array.prototype.filter=function(e){var o=this.length;if(typeof e!=t)throw new TypeError;for(var r=[],i=arguments[1],n=0;n<o;n++)if(n in this){var a=this[n];e.call(i,a,n,this)&&r.push(a)}return r}),Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length,o=Number(arguments[1])||0;for(o=o<0?Math.ceil(o):Math.floor(o),o<0&&(o+=e);o<e;o++)if(o in this&&this[o]===t)return o;return-1}),Array.prototype.map||(Array.prototype.map=function(e){var o=this.length;if(typeof e!=t)throw new TypeError;for(var r=new Array(o),i=arguments[1],n=0;n<o;n++)n in this&&(r[n]=e.call(i,this[n],n,this));return r}),Array.prototype.where||(Array.prototype.where=function(e,o){o=o||[];var r,i,n;return this.forEach(function(a){i=!0;for(var l in e)if(r=e[l],typeof r===t?i=r(a):(n=a[l],i=n&&n===r),!i)break;i&&o.push(a)}),o}),Array.prototype.groupBy||(Array.prototype.groupBy=function(t){var e={};return this.forEach(function(o){var r=o[t];r||(r="unkown"),e[r]||(e[r]=[]),e[r].push(o)}),e}),Array.prototype.find||Object.defineProperty(Array.prototype,"find",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),o=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],i=0;i<o;){var n=e[i];if(t.call(r,n,i,e))return n;i++}}}),Array.prototype.findIndex||Object.defineProperty(Array.prototype,"findIndex",{value:function(t){if(null==this)throw new TypeError('"this" is null or not defined');var e=Object(this),o=e.length>>>0;if("function"!=typeof t)throw new TypeError("predicate must be a function");for(var r=arguments[1],i=0;i<o;){var n=e[i];if(t.call(r,n,i,e))return i;i++}return-1}})}(),function(t,e,o,r){"use strict";var i=function(t){var e,i=r,n=t[0];if(i.body.createTextRange)e=r.body.createTextRange(),e.moveToElementText(n),e.select();else if(o.getSelection){var a=o.getSelection();e=r.createRange(),e.selectNodeContents(n),a.removeAllRanges(),a.addRange(e)}},n=function(e){var o=[];return t.each(e,function(t,e){e&&o.push(t)}),o},a=function(t,e){var o=t.left-e.left,r=t.top-e.top;return Math.sqrt(o*o+r*r)},l=function(t,e){return{left:t.left+e.left,top:t.top+e.top}},s=function(t,o,r,i){return t!==e?t:o!==e?o:r!==e?r:i},h=function(t,o,r,i){return t!==e&&null!==t?t:o!==e&&null!==o?o:r!==e&&null!==r?r:i},p=function(e){var o=t.extend({},e);return o.background&&(o.fill=o.background,delete o.background),o.backgroundColor&&(o.fill=o.backgroundColor,delete o.backgroundColor),o.borderWidth&&(o["stroke-width"]=o.borderWidth,delete o.borderWidth),o.borderColor&&(o.stroke=o.borderColor,delete o.borderColor),o},f=function(o,i){"object"==typeof o?(i=o,o="svg"):o||(o="svg");var n=r.createElementNS("http://www.w3.org/2000/svg",o);return i&&t.each(i,function(t,o){o!==e&&null!==o&&n.setAttribute(t,o)}),n},d=function(o,r){t.each(r,function(t,r){r!==e&&null!==r?o.setAttribute(t,r):o.removeAttribute(t)})},c="zui.flowChart",u=1,m={top:"top",right:"right",bottom:"bottom",left:"left"},g={id:function(o){if(o!==e){if(o.indexOf(":")>-1)throw new Error('FlowChart: Do not allow ":" in element id "'+o+'".');if(o.indexOf(".")>-1)throw new Error('FlowChart: Do not allow "." in element id "'+o+'".');return o}return t.zui.uuid()},type:function(t,e){return e.name},text:function(t,o,r){return null===t&&(t="function"==typeof o.text?o.text(o,r):o.text),t===e||null===t?"":String(t)},order:function(t,o){return t===e?(o.isRelation?1e4:0)+u++:t},data:function(e,o,r){var i=t.extend({},e);return t.each(r,function(t,e){o.props[t]||(i[t]=e)}),i},style:"object",textStyle:"object",className:"string",visible:!1,$ele:!1,$text:!1,bounds:!1,elementType:!1,isRelation:!1,isNode:!1,flowChart:!1},y=t.extend({lineStyle:"string",lineWidth:"int",lineColor:"string",lineShape:"string",arrowSize:"int",position:function(e){return e&&"object"==typeof e&&e.shape&&"object"==typeof e.shape?t.extend({custom:!0},e):{}},from:function(t){return t&&(t=t.split(".")[0]),t},to:function(t){return t&&(t=t.split(".")[0]),t},fromPort:function(t,o,r){return t!==e&&null!==t&&t.length||!r.from||(t=r.from.split(".")[1]),t},toPort:function(t,o,r){return t!==e&&null!==t&&t.length||!r.to||(t=r.to.split(".")[1]),t},fromIndex:!1,toIndex:!1,fromNode:!1,toNode:!1,beginSideRels:!1,endSideRels:!1},g),v=t.extend({borderStyle:"string",borderWidth:"int",borderColor:"string",shapeStyle:"object",restPortsCounter:"object",position:function(e){return e&&"object"==typeof e&&(["left","top","centerLeft","centerTop","minHeight"].forEach(function(t){if("string"==typeof e[t]){var o=Number.parseInt(e[t]);Number.isNaN(o)||(e[t]=o)}}),"number"==typeof e.left&&"number"==typeof e.top||"number"==typeof e.centerLeft&&"number"==typeof e.centerTop||m[e.direction]&&"string"==typeof e.from)?t.extend({custom:!0},e):{}},hideArrowToSelf:"bool",width:"int",height:"int",maxWidth:"int",minWidth:"int",siblingsIndex:!1,fromRels:!1,toRels:!1,children:!1,parents:!1},g),w={top:1,bottom:1,left:1,right:1},b={top:3,bottom:3,left:1,right:1},x=[{from:"top1",to:"bottom1"},{from:"bottom1",to:"top1"},{from:"top1",to:"right1"},{from:"top1",to:"left1"},{from:"right1",to:"bottom1"},{from:"left1",to:"bottom1"}],C=[{from:"top3",to:"bottom3"},{from:"top2",to:"bottom2"},{from:"bottom2",to:"top2"},{from:"bottom1",to:"top1"},{from:"top3",to:"right1"},{from:"right1",to:"bottom3"},{from:"bottom1",to:"left1"},{from:"left1",to:"top1"},{from:"top2",to:"right1"},{from:"right1",to:"bottom2"},{from:"bottom2",to:"left1"},{from:"left1",to:"top2"}],E={relation:{props:y},rectangle:{shape:"rectangle",style:{borderRadius:"2px",borderStyle:"solid",borderWidth:1,borderColor:"#333"},textStyle:{lineHeight:1,minHeight:38,padding:6},props:v,ports:b,linkSelfPairs:C},box:{shape:"box",style:{borderRadius:"20px",borderStyle:"solid",borderWidth:1,borderColor:"#333"},textStyle:{lineHeight:1,minHeight:38,padding:6},props:v,ports:b,linkSelfPairs:C},diamond:{shape:"diamond",style:{borderWidth:0},textStyle:{lineHeight:1,minHeight:38,padding:"9px 20px"},shapeStyle:{fill:"#fff",strokeWidth:1,stroke:"#333"},props:v,ports:w},circle:{shape:"circle",minWidth:40,textStyle:{lineHeight:1,minHeight:38,padding:"6px 10px"},style:{borderRadius:"50%",borderStyle:"solid",borderWidth:1,borderColor:"#333",minWidth:40},props:v,ports:w,linkSelfPairs:x},connection:{minWidth:0,style:{padding:2},textStyle:{lineHeight:1,minHeight:12},shape:"connection",hideArrowToSelf:!0,props:v,quickAdd:!1,ports:w,linkSelfPairs:x},dot:{shape:"dot",width:16,height:16,shapeStyle:{borderRadius:"50%",borderStyle:"solid",borderWidth:1,borderColor:"#333",minWidth:0,minHeight:0,maxWidth:"none",maxHeight:"none",overflow:"visible"},props:t.extend({textPosition:"string"},v),ports:w,linkSelfPairs:x}},R={relation:{type:"relation"},action:{type:"rectangle"},start:{type:"box",beginType:!0},stop:{type:"box",endType:!0},judge:{type:"diamond"},result:{type:"circle"},connection:{type:"connection"},point:{type:"dot"}},T=function(o,r,i){"number"==typeof o?o={space:o}:"string"==typeof o&&(o={name:o}),t.extend(this,o),r=r||o.side,this.side=m[r]?r:"right",this.name=o.name,this.displayName,this.empty="string"!=typeof this.name||!this.name.length,this.direction="out"===o.direction?"out":"in"===o.direction?"in":"in-out",this.space=this.space===e?1:this.space,this.spaceBegin=o.spaceBegin||0,this.spaceEnd=o.spaceEnd||0,this.lineColor,this.lineWidth,this.lineStyle,this.lineLength,this.index=i,this.rest,this.maxLinkCount=this.rest?1:this.maxLinkCount?Math.max(1,this.maxLinkCount):1,this.free=!this.rest&&this.free!==!1,this.restMinIndex=this.restMinIndex===e?1:this.restMinIndex,this.restInitialCount=this.restInitialCount===e?1:this.restInitialCount};T.prototype.getMaxRestCount=function(){return this.rest===!0?Number.MAX_SAFE_INTEGER:this.rest&&"number"==typeof this.rest?this.rest:0},T.prototype.getRestNameRegex=function(){if(this.rest)return this._restNameRegex||(this._restNameRegex=new RegExp("^"+this.name.replace("*","(\\d+)")+"$")),this._restNameRegex},T.prototype.getRestPortIndex=function(t){var e=this.getRestNameRegex();if(e){var o=t.match(e)[1];if("string"==typeof o&&o.length)return o=Number.parseInt(o),Number.isNaN(o)?null:Math.max(0,o-this.restMinIndex)}},T.prototype.isMatchRestName=function(t){return!!this.rest&&this.getRestNameRegex().test(t)},T.prototype.getRestPortNameByIndex=function(t){return this.name.replace("*",t+this.restMinIndex)},T.prototype.getRestPortAt=function(t){return this.rest?this.getRestPortByName(this.getRestPortNameByIndex(t),t):null},T.prototype.getRestPortByName=function(t,e){if(this.isMatchRestName(t)){this._restPorts||(this._restPorts={});var o=this._restPorts[t];if(o)return o;var r=this.exportPort();return r.name=t,r.rest=!1,r._restPort=!0,r.maxLinkCount=1,e>=this.restMinIndex&&delete r.spaceBegin,o=new T(r),this._restPorts[t]=o,o}return null},T.prototype.exportPort=function(){var e={},o=this;return t.each(o,function(t){"_"!==t[0]&&(e[t]=o[t])}),e},T.createPortsMap=function(e){if(!e)return null;var o,r={$all:{},$free:[],$list:[],$rest:[]};return t.each(m,function(i){var n=e[i];if("number"==typeof n){for(var a=[],l=1;l<=n;++l)a.push(i+l);n=a}n&&!t.isArray(n)&&(n=[n]),n&&n.length&&(o=!0,r[i]=n.map(function(t,e){var o=new T(t,i,e);return o.empty||(r.$all[o.name]=o,r.$list.push(o),o.free&&r.$free.push(o),o.rest&&r.$rest.push(o)),o}))}),o?r:null};var S=function(e,o){t.extend(this,o.getElementData(e)),this.id,this.type,this.basicType,this.text,this.order,this.data,this.style,this.textStyle,this.className,this.visible,this.isRelation,this.isNode,this.flowChart,this.elementType,this.bounds=this.position?{left:this.position.left,top:this.position.top,minHeight:this.position.minHeight,shape:this.position.shape}:{},this.position,this.$ele,this.$text,this.lineStyle,this.lineWidth,this.lineColor,this.showTextOnSide,this.arrowSize,this.from,this.to,this.fromIndex,this.toIndex,this.fromNode,this.toNode,this.beginSideRels,this.endSideRels,this.shapeStyle,this.hideArrowToSelf,this.borderStyle,this.borderWidth,this.borderColor,this.width,this.maxWidth,this.minWidth,this.height,this.siblingsIndex,this.fromRels,this.toRels,this.children,this.parents};S.sort=function(t){return t.sort(function(t,e){return t.order-e.order})},S.prototype.exportData=function(){var o={},r=this;return t.each(r.elementType.props,function(t,i){if(i)if("position"===t){if(r.position.custom){var n=r.getBounds(),a=n.hasPosition?r.flowChart.options.exportDetailPosition?{left:n.left,top:n.top,right:n.right,bottom:n.bottom}:{left:n.left,top:n.top}:r.getPosition();n.minHeight&&(a.minHeight=n.minHeight),o[t]=a}}else{var l=r[t];l!==e&&(o[t]=l)}}),o},S.prototype.getBounds=function(){if(this._boundsCache)return this._boundsCache;var e=this.bounds,o=this.isNode&&"number"==typeof e.left&&"number"==typeof e.top,r=t.extend({hasPosition:o},e);return o&&(r.right=e.left+e.width,r.bottom=e.top+e.height,r.centerLeft=e.left+e.width/2,r.centerTop=e.top+e.height/2),this._boundsCache=r,r},S.prototype.changeType=function(t){var e=this;"string"==typeof t&&(t=e.flowChart.types[t]),t&&(e.type=t.name,e.basicType=t.type,e.isRelation=t.isRelation,e.isNode=t.isNode,e.elementType=t)},S.prototype.setBounds=function(o){var r=this,i=0,n=0,a=0,l=r.bounds;if("number"==typeof o.top&&(l.top=o.top,i+=1),"number"==typeof o.left&&(l.left=o.left,i+=2),"number"==typeof o.width&&o.width>=0&&(l.width=o.width,n+=1),"number"==typeof o.height&&o.height>=0&&(l.height=o.height,n+=2),"number"==typeof o.minHeight&&(l.minHeight=o.minHeight,n+=4),(3===i||7===i)&&3===n){var s=r.flowChart.bounds;s.left=Math.min(s.left,l.left),s.top=Math.min(s.top,l.top),s.width=Math.max(s.width,l.left+l.width),s.height=Math.max(l.minHeight||0,Math.max(s.height,l.top+l.height))}this.isRelation&&o.shape&&"object"==typeof o.shape&&(l.shape=t.extend({},l.shape,o.shape),t.each(l.shape,function(t){l.shape[t]&&a++}),a&&(r.position=r.position?t.extend(r.position,{custom:!0}):{custom:!0})),(r.isNode&&i||a)&&r.position.custom===e&&(r.position.custom=!0),(i||n||a)&&(r._boundsCache=null)},S.prototype.isIntersectWith=function(t){if(!this.isNode||!t.isNode)return!1;var e=this.getBounds(),o=t.getBounds();return!(o.right<e.left||o.left>e.right||o.bottom<e.top||o.top>e.bottom)},S.prototype.initBeforeRender=function(){var t=this;t.isNode&&(delete t.siblingsIndex,t.fromRels=[],t.toRels=[],t.children=[],t.parents=[])},S.prototype.getFromNodeOfRelation=function(){var t=this;return!t.fromNode&&t.from&&(t.fromNode=t.flowChart.getElement(t.from)),t.fromNode},S.prototype.getToNodeOfRelation=function(){var t=this;return!t.toNode&&t.to&&(t.toNode=t.flowChart.getElement(t.to)),t.toNode},S.prototype.getPortsInfoOfRelation=function(){var o=this;if(o._relationPortsInfo===e){var r=o.getFromNodeOfRelation(),i=o.getToNodeOfRelation();if(r&&i){var n,l;if(o.fromPort&&(n=r.getPortByName(o.fromPort)),o.toPort&&(l=i.getPortByName(o.toPort)),o.flowChart.options.allowFreePorts&&!o.fromPort||!o.toPort){var s=r.getBounds(),h=i.getBounds(),p={left:(s.centerLeft+h.centerLeft)/2,top:(s.centerTop+h.centerTop)/2},f=function(e){var r,i=e.$ports.find(".flowchart-port-free"),n=Number.MAX_VALUE;if(i.length&&i.each(function(){var e=t(this),i=e.find(".flowchart-port-dot"),l=o.flowChart.getPositionOf(i,!0),s=a(l,p);s<n&&(n=s,r=e.data("name"))}),r)return e.getPortByName(r)};o.fromPort||(n=f(r)),o.toPort||(l=f(i))}n&&l&&(o._relationPortsInfo={fromPort:n,toPort:l})}else o._relationPortsInfo=null}return o._relationPortsInfo},S.prototype.getFromPort=function(){var t=this.getPortsInfoOfRelation();return t&&t.fromPort},S.prototype.getToPort=function(){var t=this.getPortsInfoOfRelation();return t&&t.toPort},S.prototype.initRelationBeforeRender=function(){var t=this;if(t.isRelation){var e=t.flowChart.getElement(t.from),o=t.flowChart.getElement(t.to);t.visible=!(!e||!o),t.visible&&(t.fromIndex=e.fromRels.length,t.toIndex=e.toRels.length,t.fromNode=e,t.toNode=o,e.fromRels.push(t),o.toRels.push(t),e.children.push(o),o.parents.push(e))}},S.prototype.getDomID=function(t){return this.flowChart.getDomID(this,t)},S.prototype.$get=function(t){var e=this.flowChart.$findElement(this.id);return t?e.find(t):e},S.prototype.moveToTop=function(t){t===e&&(t=this.flowChart.newZIndex()),this.$ele.css("zIndex",t)},S.prototype.active=function(t){this.$ele.addClass("flowchart-active"),t&&this.moveToTop(),this.render(!0)},S.prototype.unactive=function(){this.blurText(),this.$ele.removeClass("flowchart-active"),this.render(!0)},S.prototype.focusText=function(){i(this.$text.attr("contenteditable",!0)),this.$ele.addClass("flowchart-element-focused"),this.$text.focus()},S.prototype.blurText=function(){this.$text.attr("contenteditable",!1),this.$ele.removeClass("flowchart-element-focused")},S.prototype.setText=function(t){if(t!==this.text)return this.text=t,!0},S.prototype.getPorts=function(t,e){if(this.isRelation)return null;"boolean"==typeof t&&(e=t,t=null);var o=t?this.elementType.ports[t]:this.elementType.ports.$list;if(e){var r=[],i=this;return o.forEach(function(t){if(t.rest){var e=i.getRestPorts(t,!1);e&&(r=r.concat(e))}else r.push(t)}),r}return o},S.prototype.getPortByName=function(t){return this.isRelation?null:this.elementType.getPortByName(t,!0)},S.prototype.isActive=function(){return this.flowChart.isElementActive(this.id)},S.prototype.isVisible=function(){var t=this;return!t._hide&&(!t.isRelation||!!(t.fromNode&&t.toNode&&t.getPortsInfoOfRelation()))},S.prototype.renderRelation=function(){var o=this,r=o.flowChart,i=r.options;delete o._relationPortsInfo;var n=o.$get();n.length&&n.data("type")!==o.type&&(n.remove(),o.relationLineID&&t("#"+o.relationLineID).remove(),n=null);var a=o.isVisible();if(a&&(!n||!n.length)){var p=h(o.elementType.template,i.relationTemplate);p="function"==typeof p?p(o):p.format(t.extend({domID:o.getDomID(!0)},o)),n=t(p).addClass(o.className).appendTo(r.$canvas)}if(n&&!a)return n.remove(),void(o.relationLineID&&t("#"+o.relationLineID).remove());o.$ele=n,n.data(o.data),n.toggleClass("flowchart-active",o.isActive());var f=t.extend({},i.relationTextStyle,o.elementType.textStyle,o.textStyle),d=n.find(".flowchart-text"),c=o.getText();d.css(f).text(c).attr("title",c).toggleClass("flowchart-has-text","string"==typeof c&&c.length>0),o.$text=d;var u=o.getFromNodeOfRelation(),m=o.getToNodeOfRelation(),g=o.isActive(),y=s(o.lineStyle,o.elementType.lineStyle,i.relationLineStyle),v=s(o.lineShape,o.elementType.lineShape,i.relationLineShape),w=g?i.activeColor:s(o.lineColor,o.elementType.lineColor,i.relationLineColor),b=s(o.lineWidth,o.elementType.lineWidth,i.relationLineWidth),x=s(o.showArrow,o.elementType.showArrow);x===e&&(x=!i.hideArrowToResult||"result"!==m.type);var C=s(o.arrowSize,o.elementType.arrowSize,i.relationArrowSize),E="begin"===x||"both"===x?C:0,R=x===!0||"end"===x||"both"===x?C:0,T=t.extend({},o.elementType.shapeStyle,o.shapeStyle);if(n.attr("data-shape",v),o.elementType.render){var S=t.extend({},i.relationStyle,o.elementType.style,o.style);return o.elementType.render.call(o,n,{style:S,shapeStyle:T,portsInfo:o.getPortsInfoOfRelation(),textStyle:f,lineStyle:y,isActive:g,lineSize:b,lineColor:w,beginArrow:E,endArrow:R,relation:o})}var P=o.getPortsInfoOfRelation(),N=u.$get('.flowchart-port[data-name="'+P.fromPort.name+'"]'),M=m.$get('.flowchart-port[data-name="'+P.toPort.name+'"]'),k=r.getPositionOf(N),A=r.getPositionOf(M),_=N.data("centerOffset"),I=M.data("centerOffset");k=l(k,_),A=l(A,I),k.top=Math.floor(k.top),k.left=Math.floor(k.left),A.top=Math.floor(A.top),A.left=Math.floor(A.left),o.setBounds({left:Math.min(k.left,A.left),top:Math.min(k.top,A.top),width:Math.max(b,Math.abs(k.left-A.left)),height:Math.max(b,Math.abs(k.top-A.top))});var L=o.getBounds(),D={left:k.left,top:k.top,offsetLeft:k.left-L.left,offsetTop:k.top-L.top,arrow:E,side:P.fromPort.side},B={left:A.left,top:A.top,offsetLeft:A.left-L.left,offsetTop:A.top-L.top,arrow:R,side:P.toPort.side},z=o.$get(".flowchart-relation-lines").empty();o.relationLineID="flowchart-"+r.id+"-line-"+o.id,r.drawRelationLine(o.relationLineID,D,B,{shapeStyle:T,style:y,width:b,color:w,shape:v,isActive:g,activeColor:i.activeColor,relation:o,className:"flowchart-relation-line"+(g?" flowchart-relation-line-active":""),bounds:L},z,d),n.css({top:L.top,left:L.left,width:L.width,height:L.height}),r.callCallback("onRenderRelation",[n,o])},S.prototype.getText=function(){var t=this.text;return this.elementType.textFormatter?t=this.elementType.textFormatter(t,this):(t===e&&(t=this.elementType.text),t=t===e||null===t?"":String(t)),t},S.prototype.appendRestPortHolder=function(t){var e=this.elementType.getPortByName(t);e&&this.restPortsCounter&&(this.restPortsCounter[e.name]=(this.restPortsCounter[e.name]||0)+1,this.freshRender())},S.prototype.deleteRestPort=function(t){for(var e=this,o=e.elementType.getPortByName(t),r=e.getRestPorts(o,!1),i=r.length-1;i>0;--i){var n=r[i];if(n.name===t)break;var a=e.getRelationsByPort(n.name);if(a&&a.length){var l=r[i-1];a.forEach(function(t){t.from===e.id&&t.fromPort===n.name?t.fromPort=l.name:t.to===e.id&&t.toPort===n.name&&(t.toPort=l.name)})}}e.restPortsCounter[o.name]-=1,e.freshRender()},S.prototype.getRelationsByPort=function(t){var e=this,o=[];return e.fromRels&&e.fromRels.length&&e.fromRels.forEach(function(e){e.fromPort&&e.fromPort===t&&o.push(e)}),e.toRels&&e.toRels.length&&e.toRels.forEach(function(e){e.toPort&&e.toPort===t&&o.push(e)}),o},S.prototype.getRestPorts=function(t,o){if("string"==typeof t&&(t=this.getPortByName(t)),t.rest){o===e&&(o=!0);var r=this;r.restPortsCounter||(r.restPortsCounter={}),r.restPortsCounter[t.name]||(r.restPortsCounter[t.name]=t.restInitialCount);var i={},n=r.restPortsCounter[t.name]-1;r.fromRels&&r.fromRels.length&&r.fromRels.forEach(function(e){if(e.fromPort&&t.isMatchRestName(e.fromPort)){for(var o=t.getRestPortIndex(e.fromPort);i[o];)o++;i[o]=1,n=Math.max(o,n),e.fromPort=t.getRestPortNameByIndex(o)}}),r.toRels&&r.toRels.length&&r.toRels.forEach(function(e){if(e.toPort&&t.isMatchRestName(e.toPort)){for(var o=t.getRestPortIndex(e.toPort);i[o];)o++;i[o]=1,n=Math.max(o,n),e.toPort=t.getRestPortNameByIndex(o)}}),r.restPortsCounter[t.name]=n+1;for(var a=[],l=0;l<=n;++l){var s=t.getRestPortAt(a.length);s._restHolder=!1,s._restIndex=a.length,a.push(s)}if(o&&n<t.getMaxRestCount()){var s=t.getRestPortAt(a.length);s._restHolder=!0,s._restIndex=a.length,a.push(s)}return a}return[]},S.prototype.renderPorts=function(e){e=e||0;var o=this,r=o.elementType,i=r.ports;if(i){var n=o.flowChart.options,a=o.$ele,l=a.find(".flowchart-ports");l.length||(l=t(['<div class="flowchart-ports" style="position:absolute;top:0;right:0;bottom:0;left:0; z-index: 6">','<div class="flowchart-ports-side flowchart-ports-top" style="position:absolute;top:0;left:50%"></div>','<div class="flowchart-ports-side flowchart-ports-bottom" style="position:absolute;bottom:0;left:50%"></div>','<div class="flowchart-ports-side flowchart-ports-left" style="position:absolute;top:50%;left:0"></div>','<div class="flowchart-ports-side flowchart-ports-right" style="position:absolute;top:50%;right:0"></div>',r.linkSelf?'<div class="flowchart-link-self-btn" title="'+o.flowChart.lang.linkSelf+'"></div>':"","</div>"].join("")).appendTo(a)),o.$ports=l;var h={left:0,right:0,top:0,bottom:0},p=n.portSpaceSize||20,f={left:[],right:[],top:[],bottom:[]},d=function(t,e){var o={size:Math.floor(e.space*p),begin:Math.floor(e.spaceBegin*p),end:Math.floor(e.spaceEnd*p),offset:h[t],port:e};if(o.total=o.size+o.begin+o.end,h[t]+=o.total,f[t].push(o),e.empty)return void(o.empty=!0)},c=function(e,i,a,l){var h=a.port,p=a.size*l,f=a.begin*l,d=a.offset*l,c=s(h.lineLength,r.portLineLength,n.portLineLength),u=Math.max(1,s(h.lineWidth,r.portLineWidth,n.portLineWidth)),m=s(h.lineStyle,r.portLineStyle,n.portLineStyle),g=s(h.lineColor,r.portLineColor,n.portLineColor),y={},v={width:0,height:0},w={width:u+8,height:u+8},b={};"left"===i||"right"===i?(y.top=d+f,y.width=c+2*w.width,y.left="left"===i?0-y.width:0,y.height=p,c&&(v.top=Math.floor((p-u)/2),v["left"===i?"right":"left"]=0,v.width=c,v.borderBottomStyle=m,v.borderBottomWidth=u,v.borderBottomColor=g),w.top=Math.floor((p-w.height)/2),w[i]=y.width-c-w.width,b.top=p/2,b.left="left"===i?y.width-v.width:v.width):(y.left=d+f,y.height=c+2*w.width,y.top="top"===i?0-y.height:0,y.width=p,c&&(v.left=Math.floor((p-u)/2),v["top"===i?"bottom":"top"]=0,v.height=c,v.borderRightStyle=m,v.borderRightWidth=u,v.borderRightColor=g),w.left=Math.floor((p-w.width)/2),w[i]=y.height-c-w.height,b.top="top"===i?y.height-v.height:v.height,b.left=p/2);var x=e.find('.flowchart-port[data-id="'+o.id+'"]');x.length?x.attr({"data-name":h.name}).removeClass("flowchart-port-expired"):(x=t(n.portTemplate.format({id:o.id,name:h.name,side:i})),x.css(y).appendTo(e).attr("title",h.name)),c&&t('<div class="flowchart-port-line" style="position:absolute"></div>').css(v).appendTo(x),x.data("centerOffset",b).toggleClass("flowchart-port-free",h.free).append(t('<div class="flowchart-port-dot" style="position:absolute"></div>').css(w)),x.toggleClass("flowchart-port-rest-holder",!!h._restHolder),x.toggleClass("flowchart-port-rest",!!h._restPort),h._restPort&&!h._restHolder&&x.toggleClass("flowchart-port-rest-empty",!o.getRelationsByPort(h.name).length)};t.each(h,function(t){var e=i[t];e&&e.forEach(function(e){return e.rest?o.getRestPorts(e).forEach(d.bind(null,t)):void d(t,e)})}),t.each(f,function(t){var o=l.find(".flowchart-ports-"+t),r=f[t];if(!r||!r.length)return void o.empty();o.find(".flowchart-port").addClass("flowchart-port-expired");var i=h[t],a=1;n.autoAdjustPortSpace&&("left"===t||"right"===t)&&e.minHeight>0&&i<e.minHeight&&(a=e.minHeight/i,i=e.minHeight),r.forEach(function(e){c(o,t,e,a)}),o.css("left"===t||"right"===t?"margin-top":"margin-left",0-Math.floor(i/2))}),l.find(".flowchart-port-expired").remove(),a.css({minWidth:Math.max(e.minWidth,Math.max(h.top,h.bottom)),minHeight:Math.max(e.minHeight||0,Math.max(h.left,h.right))})}},S.prototype.getClassMap=function(){return this._classNamesMap||(this._classNamesMap={},this.className&&this.setClass(this.className)),this._classNamesMap},S.prototype.setStyle=function(e){e.textStyle&&(this.setTextStyle(e.textStyle),delete e.textStyle),this.style=t.extend(this.style||{},e)},S.prototype.setTextStyle=function(e){this.textStyle=t.extend(this.textStyle||{},e)},S.prototype.setClass=function(e){if("string"==typeof e){var o=e.split(" "),r=!1;e={},o.forEach(function(o){o=t.trim(o),o.length&&("-"===o?r=!0:e[o]=!r)})}this._classNamesMap=t.extend(this._classNamesMap||{},e),this.className=n(this._classNamesMap).join(" ")},S.prototype.addClass=function(t){this.setClass(t)},S.prototype.removeClass=function(t){this.setClass("- "+t)},S.prototype.hasClass=function(t){return!!(this._classNamesMap&&_classNamesMap[t]||this.$ele&&this.$ele.hasClass(t))},S.prototype.toggleClass=function(t,o){o!==e&&(o=!this.hasClass(t)),o?this.addClass(t):this.removeClass(t)},S.prototype.renderNode=function(e){var o=this,r=o.flowChart,i=r.options,n=o.elementType,a=o.isActive(),l=o.$get();if(l.length&&l.data("type")!==o.type&&(l.remove(),l=null),!l||!l.length){var f=h(n.template,i.nodeTemplate);f="function"==typeof f?f(o):f.format(t.extend({domID:o.getDomID(!0),cursor:r.draggableEnable&&i.draggable&&i.readonly!==!0?"move":"default",zIndex:o.flowChart.newZIndex()},o)),l=t(f).appendTo(r.$canvas),n.resizable&&l.append('<div class="flowchart-resize-handler"></div>')}o.$ele=l,l.data(o.data),l.toggleClass("flowchart-has-ports",n.hasPorts()).toggleClass("flowchart-resizable",n.resizable).toggleClass("flowchart-active",a),t.each(this.getClassMap(),function(t,e){l.toggleClass(t,!!e)});var d=t.extend({},i.nodeTextStyle,n.textStyle,o.textStyle,{transform:"none",maxHeight:"none"}),c=l.find(".flowchart-text"),u=o.getText(),m="string"==typeof u&&u.length>0;c.css(d).text(m?u:" ").toggleClass("flowchart-has-text",m),o.$text=c,l.attr("title",u);var g=o.getBounds().minHeight||0,y=s(o.minWidth,n.minWidth,i.nodeMinWidth);l.css({maxHeight:Math.max(g,s(o.height,n.height,i.nodeHeight)),maxWidth:s(o.maxWidth,n.maxWidth,i.nodeMaxWidth),minWidth:y,minHeight:g,width:s(o.width,n.width),height:Math.max(g,s(o.height,n.height))});var v=t.extend({},i.nodeStyle,n.style,o.style),w=t.extend({background:i.nodeBackground},n.shapeStyle,o.shapeStyle,{borderStyle:o.borderStyle,borderWidth:o.borderWidth,borderColor:a?i.activeColor:o.borderColor});if(n.render)n.render.call(o,l,n,{style:v,shapeStyle:w,textStyle:d,text:u});else if(n.hasPorts()&&o.renderPorts({style:v,shapeStyle:w,textStyle:d,text:u,minHeight:g,minWidth:y}),"diamond"===n.shape){l.css(v);var b={width:l.outerWidth(),height:l.outerHeight()},x=l.children(".flowchart-shape,svg").first();x.length||(x=t('<svg class="flowchart-shape" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0"><polygon /></svg>').appendTo(l));var C=x.children("polygon");a&&(w.borderWidth=2),C.css(p(w));var E=[[0,b.height/2],[b.width/2,0],[b.width,b.height/2],[b.width/2,b.height]],R=[];E.forEach(function(e){R.push(t.isArray(e)?e.join(","):e)}),C.attr("points",R.join(" ")),x.css(b).show()}else if("dot"===n.shape){l.css(t.extend(v,w));var T={position:"absolute"};"top"===o.textPosition?T.bottom="100%":T.top="100%",c.css(T)}else"connection"===n.shape?(u?c.css("position","relative"):(w.padding=0,c.css("position","absolute")),l.css(t.extend(v,w))):l.css(t.extend(v,w));r.callCallback("onRenderNode",[l,o]);var S=l.outerHeight(),P=l.outerWidth();o.setBounds({width:P,height:S});var N=c.outerHeight();if(i.autoScaleText){var M=S/N;M<1&&c.css({transform:"scale("+M+")"})}else c.css("max-height",S).toggleClass("flowchart-node-text-limit",S<N);e||o.layoutNode()},S.prototype.getSize=function(){return{height:this.bounds.height,width:this.bounds.width}},S.prototype.getPosition=function(){return this.isRelation?{shape:this.bounds.shape}:{left:this.bounds.left,top:this.bounds.top}},S.prototype.getSiblingIndex=function(){if(this._siblingIndex===e){var t=this.parents;if(!this.elementType.beginType&&t&&t.length){var o=this.id;this._siblingIndex=t[0].children.findIndex(function(t){return o===t.id})}else this._siblingIndex=0}return this._siblingIndex},S.prototype.getDepth=function(){if(this._depth===e){var t=this.parents;!this.elementType.beginType&&t&&t.length?this._depth=Math.max(0,t[0].getDepth())+1:this._depth=0}return this._depth},S.prototype.getDeptSize=function(t,o){if(this._depthSize!==e)return this._depthSize;t===e&&(t="horz"===this.flowChart.options.autoLayoutDirection),o===e&&(o=this.flowChart.options.vertSpace);var r=this.children,i=this.getBounds(),n=this.getDepth()+1,a=t?i.height:i.width;if(r&&r.length){for(var l=0,s=0;s<r.length;++s){var h=r[s];h.getDepth()===n&&(l&&(l+=o),l+=h.getDeptSize(t,o))}a=Math.max(a,l)}return this._depthSize=a,a},S.prototype.hasPosition=function(){return this.getBounds().hasPosition},S.prototype.layoutNode=function(t){var o=this,r=o.flowChart,i=r.options,n=o.position,a=o.getBounds();if(!a.hasPosition||!n.custom){var l={};if("number"==typeof n.centerLeft&&"number"==typeof n.centerTop)l.left=n.centerLeft-Math.floor(a.width/2),l.top=n.centerTop-Math.floor(a.height/2);else{var s=o.parents,h=n.direction,p=n.from;if("string"==typeof p&&(p=r.getElement(p)),h&&m[h]&&p){var f=p.getBounds();"top"===h?(l.left=Math.floor(f.centerLeft-a.width/2),l.top=f.top-i.vertSpace-a.height):"left"===h?(l.left=f.left-i.horzSpace-a.width,l.top=Math.floor(f.centerTop-a.height/2)):"bottom"===h?(l.left=Math.floor(f.centerLeft-a.width/2),l.top=f.bottom+i.vertSpace):"right"===h&&(l.left=f.right+i.horzSpace,l.top=Math.floor(f.centerTop-a.height/2)),l.left=Math.max(0,l.left),l.top=Math.max(0,l.top),delete n.direction,delete n.from,n.custom="auto"}else if(s.length){var d,c=0;s.forEach(function(t){if(t.hasPosition()){var r=t.getPosition(),i=t.getSize();if(d?(d.left=Math.min(d.left,r.left),d.top=Math.min(d.top,r.top),d.right=Math.max(d.right,i.width+r.left),d.bottom=Math.max(d.bottom,i.height+r.top)):d={left:r.left,top:r.top,right:i.width+r.left,bottom:i.height+r.top},o.siblingsIndex===e){var n=t.children;n.length&&n.forEach(function(t){t.siblingsIndex===e&&(t.siblingsIndex=c++)})}}}),"horz"===i.autoLayoutDirection?(l.left=d.right+i.horzSpace,l.top=d.top+o.siblingsIndex*(i.nodeHeight+i.vertSpace)):(l.top=d.bottom+i.vertSpace,l.left=d.left+o.siblingsIndex*(i.nodeMinWidth+i.horzSpace))}else{var u=r.bounds;l.left=u.left,l.top=u.top+u.height+(u.height<=i.padding?0:i.vertSpace-i.padding)}}o.setBounds(l),n.custom===e&&(n.custom=!0)}var g=i.adsorptionGrid;return g&&(a=o.getBounds(),o.setBounds({left:Math.round(a.left/g)*g,top:Math.round(a.top/g)*g})),n=o.getPosition(),t||o.$ele.css(n),n},S.prototype.freshRender=function(){return this.flowChart._initElementsRelation(),this.flowChart.render(this.id)},S.prototype.render=function(t){return this.isRelation?this.renderRelation():this.renderNode(t)},S.prototype.layout=function(t){this.isNode&&this.layoutNode(t)},S.prototype.isHidden=function(){return!this.isVisible()},S.prototype.hide=function(t){this._hide||(this._hide=!0,t||this.freshRender())},S.prototype.show=function(t){this._hide&&(this._hide=!1,t||this.freshRender())},S.prototype.getData=function(o){return o===e?t.extend({},this.data):this.data[o]},S.prototype.setData=function(e,o){var r;"object"==typeof e&&null!==e?r=o:(r={},r[e]=o),this.flowChart.callCallback("beforeSetData",[r,this])!==!1&&(t.extend(this.data,r),this.flowChart.callCallback("afterSetData",[r,this]))},S.prototype.canLinkSelf=function(){return this.isNode&&!!this.elementType.linkSelf},S.prototype.isLinkSelf=function(){return this.isRelation&&this.elementType.cycle},S.prototype.linkSelf=function(t,o,r){var i=this;
|
|
if(i.canLinkSelf()){if(t===e||null===t){var n=i.elementType.linkSelfPairs;t=n.length>1?n.find(function(t){var e=i.getRelationsByPort(t.from),o=e.length&&e.find(function(e){return e.isLinkSelf()&&(t.from===e.fromPort&&t.to===e.toPort||t.to===e.fromPort&&t.from===e.toPort)});return!o}):n[0]}else if("number"==typeof t){var n=i.elementType.linkSelfPairs;t=n[t%n.length]}if(t){if(o!==e&&null!==o||(o=""),!r)if(i.flowChart.options.defaultCycleRelation)r=i.flowChart.options.defaultCycleRelation;else{var a=i.flowChart.findElementType(function(t){return t.cycle});a&&(r=a.name)}if(!r)return;var a=i.flowChart.getElementType(r);if(!a)return;i.flowChart.addRelation(i,t.from,i,t.to,o,r,{position:{shape:{arrX:2,arrY:2}}})}}};var P=function(e){t.isArray(e)?e.unshift(!0,this):e=[!0,this,e],t.extend.apply(null,e),this.isRelation="relation"===this.type,this.isNode=!this.isRelation,this.props,this.style,this.textStyle,this.shape,this.shapeStyle,this.hideArrowToSelf,this.height,this.maxWidth,this.minWidth,this.render,this.template,this.text,this.edit,this.desc,this.ports=T.createPortsMap(this.ports),this.resizable,this.linkSelf,this.cycle,this.linkSelfPairs};P.prototype.getPortByName=function(t,e){var o=this,r=o.ports;if(r){var i=r.$all[t];if(i)return i;if(r.$rest.length)for(var n=0;n<r.$rest.length;++n){var i=r.$rest[n];if(i.isMatchRestName(t))return e?i.getRestPortByName(t):i}}return null},P.prototype.hasPorts=function(){return!!this.ports},P.prototype.getElementData=function(e){var o={},r=this;return t.each(r.props,function(t,i){i&&(o[t]="function"==typeof i?i(e[t],r,e):e[t])}),o.type=r.name,o.basicType=r.type,o.isRelation=r.isRelation,o.isNode=r.isNode,o.elementType=r,o},P.prototype.createElement=function(t,e){var o=new S(t,this);return o.isNode&&o.data&&(o.data.from&&delete o.data.from,o.data.to&&delete o.data.to),o.flowChart=e,o},P.prototype.exportType=function(t){var e=this,o={name:e.name,shape:e.shape,isRelation:e.isRelation,isNode:e.isNode,displayName:e.displayName,internal:e.internal,type:e.type},r=e.ports;if(r){var i={};["left","top","right","bottom"].forEach(function(e){var o=r[e];if(o&&o.length){var n=[];o.forEach(function(e){if(!e.empty||t){var o=e.exportPort();delete o.empty,delete o.side,delete o.space,delete o.spaceBegin,delete o.spaceEnd,delete o.index,n.push(o)}}),n.length&&(i[e]=n)}}),o.ports=i}return o};var N=function(i,n){var s=this;s.name=c;var h=s.$container=t(i).addClass("scrollbar-hover").css("overflow","auto");s.id=h.attr("id")||"flowchart_"+t.zui.uuid(),h.attr("id")||h.attr("id",s.id);var p=t.extend({},N.DEFAULTS,h.data(),n);if(p.plugins){"string"==typeof p.plugins&&(p.plugins=p.plugins.split(","));var f={},d=[],u=function(e){var o=N.plugins[e];return!!o&&void(!f[e]&&o&&(o.plugins&&o.plugins.forEach(function(t){if(u(t)===!1)throw new Error('FlowChart: Plugin "'+t+'" not found, it required by plugin "'+e+'".')}),f[e]=1,d.push(e),o.defaultOptions&&t.extend(!0,p,"function"==typeof o.defaultOptions?o.defaultOptions.call(s,p):o.defaultOptions)))};p.plugins.forEach(function(t){if(u(t)===!1)throw new Error('FlowChart: Plugin "'+t+'" not found on init from options("'+p.plugins.join(",")+'").')}),t.extend(!0,p,h.data(),n),s.plugins=d}s.options=p;var m=t.extend({},N.LANGS,p.langs),g=p.lang||(t.zui&&t.zui.clientLang?t.zui.clientLang():"en");s.lang=m[g.replace("_","-")]||m.en;var y={};t.each(E,function(t,e){y[t]=new P([{type:t,internal:!0,name:t,displayName:s.lang["type."+t]},e])});var v={};t.each(R,function(e,o){v[e]=t.extend(!0,{},o,{internal:!p.initialTypes})}),t.each(t.extend(!0,{},v,p.elementTypes),function(t,e){if("relation"!==t)if(y[t]){var o=y[t];y[t]=new P([o,{internal:!1},"object"==typeof e?e:null])}else{var o=y[e.type];y[t]=new P([o,{internal:!1,name:t,displayName:s.lang["type."+t]},e])}}),this.types=y;var w=h.children(".flowchart-canvas");w.length||(w=t('<div class="flowchart-canvas" style="position: relative; user-select: none"></div>').appendTo(h));var b="flowchart-canvas-"+s.id;if(w.attr("id",b).toggleClass("flowchart-allow-free-ports",!!p.allowFreePorts),s.$canvas=w,p.width!==e&&h.css("width",p.width),p.height!==e&&"auto"!==p.height&&h.css("height",p.height),s.draggableEnable=!!t.fn.draggable,s.draggableEnable){if(p.draggable&&p.readonly!==!0){var x=function(e){var o={},r=s._dragCtrlPoint.data("name");if("por"===r){o=t.extend({porX:0,porY:0},s._dragElement.getBounds().shape);var i=s._dragElement.position.porx,n=s._dragElement.position.pory;i&&(o.porX+=e.smallOffset.x/i),n&&(o.porY+=e.smallOffset.y/n)}else if("arr"===r){o=t.extend({arrX:0,arrY:0},s._dragElement.getBounds().shape);var a=s._dragElement.position.arcd,l=s._dragElement.position.acdd;o["x"===l?"arrX":"arrY"]+=e.smallOffset[l]/a}else{var h=t.extend({bboX:0,bboY:0,bcoX:0,bcoY:0,beoX:0,beoY:0},s._dragElement.getBounds().shape);o["b"+r+"oX"]=h["b"+r+"oX"]+e.smallOffset.x,o["b"+r+"oY"]=h["b"+r+"oY"]+e.smallOffset.y}s._dragElement.setBounds({shape:o}),s._dragElement.render()},C=function(t){var e=s._dragElement.getSize().height,o=e+t.smallOffset.y;s._dragElement.setBounds({minHeight:o,height:o}),s._dragElement.freshRender()};w.draggable({move:!1,container:"#"+b,selector:".flowchart-node,.flowchart-relation-line-ctrl-point,.flowchart-relation-text",stopPropagation:!0,drag:function(e){if(!s._dragElement){var o=t(e.element),i=o.data("id"),n=null;if(o.hasClass("flowchart-relation-text")?(i=o.closest(".flowchart-relation").data("id"),n=t(r.getElementById("flowchart-"+s.id+"-line-"+i)).find(".flowchart-relation-primary-ctrl-point"),n.length||(n=null)):t(e.event.target).hasClass("flowchart-resize-handler")?s._dragResizeHandler=o:n=o.hasClass("flowchart-relation-line-ctrl-point")?o:null,null===i)return!1;var a=s.getElement(i);a.isNode&&a.moveToTop(),s._dragCtrlPoint=n,s._dragElement=a}s._dragCtrlPoint?x(e):s._dragResizeHandler?C(e):s.setElementBounds(s._dragElement.id,e.pos)},finish:function(e){s._dragElement&&(s._dragCtrlPoint?x(e):s._dragResizeHandler?C(e):(t(e.element).addClass("flowchart-dragged"),s.setElementBounds(s._dragElement.id,e.pos))),s._dragElement=null,s._dragCtrlPoint=null,s._dragResizeHandler=null},mouseButton:"left",before:function(e){var o=!s.isPreventDragNode;return(!o||!t(e.event.target).closest(".flowchart-ports-side").length)&&o}})}if(!p.readonly){var T,S,M,k,A,_,I,L,D,B,z,H=null;w.droppable({container:"#"+b,target:".flowchart-port,.flowchart-node",selector:".flowchart-port-dot",mouseButton:"left",nested:!0,flex:!1,before:function(t){s.isPreventDragNode=!0},start:function(e){T=t(e.element).closest(".flowchart-port"),S=T.closest(".flowchart-node"),H=S.data("id"),B=T.data("name");var o=s.getElement(H);D=o.getRelationsByPort(B).filter(function(t){return s.isElementActive(t.id)}),D&&D.length?(D=D[0],z=D.from===H?"from":"to",H=D["from"===z?"to":"from"],B=D[("from"===z?"to":"from")+"Port"],S=s.$findElement(H),T=S.find('.flowchart-port[data-name="'+B+'"]')):D=null,A=l(s.getPositionOf(T),T.data("centerOffset")),T.addClass("flowchart-drag-active"),S.addClass("flowchart-drag-active"),_=w.find(".flowchart-link-line"),_.length||(_=t('<svg class="flowchart-link-line" style="position: absolute; z-index: 30; top: 0; left: 0; right: 0; bottom: 0"><line x1="50" y1="50" x2="350" y2="350" stroke="'+p.activeColor+'" stroke-width="2"/></svg>').appendTo(w)),I=_.show().attr({width:w.width(),height:w.height()}).find("line"),D&&(D.hide(!0),D.render()),L=!1},drag:function(e){if(M&&M.removeClass("flowchart-drop-active"),k&&k.removeClass("flowchart-drop-active"),k=null,M=null,e.isIn&&e.target){var o=t(e.target),r=o.closest(".flowchart-port"),i=(r.length?r:o).closest(".flowchart-node");i.length&&i.data("id")!==H&&(k=i.addClass("flowchart-drop-active"),M=r.addClass("flowchart-drop-active"))}var n={left:e.position.left+8,top:e.position.top+8};I.attr({x1:A.left,y1:A.top,x2:n.left,y2:n.top})},drop:function(e){if(e.target){var o=t(e.target),r=o.closest(".flowchart-port"),i=(r.length?r:o).closest(".flowchart-node");if(i.length){var n=i.data("id");if(n!==H){var a=r.data("name");if(z)n&&a&&(D[z]=n,D[z+"Port"]=a);else{var l=p.confirmRelationType;if(l&&t.zui.ContextMenu){var h=[{label:s.lang.selectRelationType,disabled:!0}];"string"==typeof l&&(l=l.split(",")),t.isArray(l)?l.forEach(function(t){var e=s.types[t];e.isRelation&&!e.internal&&h.push({label:e.displayName||t,relationType:t})}):t.each(s.types,function(t,e){e.isRelation&&!e.internal&&h.push({label:e.displayName||t,relationType:t})});var f=H,d=B;if("string"==typeof f&&(f=s.getElement(f)),"string"==typeof n&&(n=s.getElement(n)),!f||!n||f===n)return;if(!(p.allowFreePorts||d&&a))return;t.zui.ContextMenu.show(h,{event:e.event,onClickItem:function(t){s.addRelation(f,d,n,a,null,t.relationType)}})}else s.addRelation(H,B,n,a)}}L=!0}}},always:function(e){if(s.isPreventDragNode=!1,T&&T.removeClass("flowchart-drag-active"),S&&S.removeClass("flowchart-drag-active"),M&&M.removeClass("flowchart-drop-active"),k&&k.removeClass("flowchart-drop-active"),_&&_.hide(),p.quickAdd&&!L&&(e.cancel||a(e.position,A)<20)){var o=t(e.event.target),r=o.closest(".flowchart-port"),i=(r.length?r:o).closest(".flowchart-node");s.addNode(p.defaultNodeType||"action",i.data("id"),r.data("name"),null,r.data("side"))}D&&D.show(),H=null,B=null,S=null,T=null,z=null,D=null}})}}if(!p.readonly&&p.addFromDrop){if("string"==typeof p.addFromDrop){var W=t(p.addFromDrop),$=function(e){var o=t(e.target).closest('[draggable="true"]').data();o.type&&(e.originalEvent.dataTransfer.setData("text",JSON.stringify(o)),h.addClass("flowchart-drag-start"),e.originalEvent.dataTransfer.effectAllowed="copy")},O=function(t){h.removeClass("flowchart-drag-start").removeClass("flowchart-drag-over")};W.is('[draggable="true"]')?W.on("dragstart",$).on("dragend",O):W.on("dragstart",'[draggable="true"]',$).on("dragend",'[draggable="true"]',O)}var X=function(e){p.onDragOver&&p.onDragOver.call(s,e)===!1||(h.toggleClass("flowchart-drag-over",!!t(e.target).closest(".flowchart-canvas").length),e.originalEvent.dataTransfer.effectAllowed="copy",e.preventDefault())};w.on("dragenter",X).on("dragover",X).on("dragleave",function(e){p.onDragLeave&&p.onDragLeave.call(s,e)===!1||h.toggleClass("flowchart-drag-over",!t(e.target).closest(".flowchart-canvas").length)}).on("drop",function(r){if(!p.onDrop||p.onDrop.call(s,r)!==!1){r.preventDefault();var i=r.originalEvent.dataTransfer.getData("text");if(i){try{i=t.parseJSON(i)}catch(r){console.error('FlowChart: Cannot get correct "newElement" data from drop event\'s dataTransfer.',i,r)}if(i&&"object"==typeof i&&i.type){var n=w.offset();r.clientX===e&&(r=r.originalEvent),s.addElement(t.extend({position:{centerLeft:r.clientX-n.left+t(o).scrollLeft(),centerTop:r.clientY-n.top+t(o).scrollTop()},text:null},i))}else console.warn('FlowChart: Data format error in "newElement" data from drop event\'s dataTransfer.',i)}}})}if(!p.readonly){p.doubleClickToEdit&&w.on("dblclick",".flowchart-element,.flowchart-relation-line",function(e){var o,r=t(this);t.isFunction(p.doubleClickToEdit)&&(o=p.doubleClickToEdit(s.getElement(r.data("id")),s,e)),o||s.focusElementText(r.data("id")),e.preventDefault()});var j=null;w.on("input",".flowchart-text[contenteditable=true]",function(e){var o=t(this);j&&(clearTimeout(j),j=null);var r=o.text();j=setTimeout(function(){var t=o.closest(".flowchart-element");s.setElementText(t.data("id"),r,!0)},1e3)}).on("keydown",function(t){if(13===t.keyCode&&!t.shiftKey)return t.preventDefault(),s.blurElementText(),!1}).on("blur",".flowchart-text",function(e){j&&(clearTimeout(j),j=null);var o=t(this),r=o.closest(".flowchart-element");s.setElementText(r.data("id"),o.text())})}p.showContextMenu&&t.zui.ContextMenu&&(w.on("mousedown",".flowchart-element,.flowchart-relation-line",function(e){2===e.button&&s.showContextMenu(t(this).data("id"),e),e.preventDefault(),e.returnValue=!1}).on("contextmenu",function(t){return t.preventDefault(),t.returnValue=!1,!1}),t(r).on("change",".flowchart-"+s.id+"-type-selector",function(){var e=t(this),o=e.data("id"),r=s.getElement(o);r&&(r.changeType(e.val()),s.render(r)),t.zui.ContextMenu.hide()})),w.on("click",function(e){var o=t(e.target),r=o.closest(".flowchart-element,.flowchart-relation-line");if(r.length){if(r.hasClass("flowchart-dragged"))return void r.removeClass("flowchart-dragged");var i=s.getElement(r.data("id"));if(i){var n=!1;if(!p.readonly)if(o.is(".flowchart-link-self-btn"))i.linkSelf(),n=!0;else{var a=o.closest(".flowchart-port-rest-holder");if(a.length)i.appendRestPortHolder(a.data("name")),n=!0;else{var l=o.closest(".flowchart-port-delete-handler");l.length&&(i.deleteRestPort(l.parent().data("name")),n=!0)}}if(!n){if(p.onClickElement)try{p.onClickElement(i,r)}catch(e){console.error('FlowChart: Call callback function "onClickElement" error.',e)}p.activeOnClick&&s.activeElement(i)}}}else s.unactiveElements()}),s.updateStyle(),s.elements={},this.activedElements={};var F=h.find(".flowchart-svg-canvas");F.length||(F=t('<svg class="flowchart-svg-canvas" style="position: absolute; left: 0; top: 0"><defs></defs></svg>').prependTo(w)),s.$svg=F,s.$svgMarkers=F.find("defs"),s.nodeZIndex=5,s.callCallback("onCreate",[p]),s.update(p.data,!0,!0),s.render(null,!0),s.callCallback("afterCreate",[this]),s.created=!0};N.prototype.newZIndex=function(){return this.nodeZIndex++},N.prototype.callCallback=function(t,e){var o,r=this;return r.plugins&&r.plugins.forEach(function(i){var n=N.plugins[i];n&&n[t]&&(o=n[t].apply(r,e))}),r.options[t]&&(o=r.options[t].apply(r,e)),o},N.prototype.getPositionOf=function(e,o){var r=this.$canvas.offset();if(!e)return r;var i;i=e instanceof S?e.$get():t(e);var n=i.offset(),a={left:n.left-r.left,top:n.top-r.top};return o&&(a.left+=i.width()/2,a.top+=i.height()/2),a},N.prototype.updateStyle=function(){var t=this,e=t.id,o=["#{id} {background: #fff; transition: box-shadow .2s;}","#{id}.flowchart-drag-start {box-shadow: inset 0 0 3px {activeColor}!important}","#{id}.flowchart-drag-over {box-shadow: inset 0 0 0 2px {activeColor}!important}","#{id} .flowchart-port-dot {opacity: 0; background: {activeColor}; border-radius: 50%; transition: .2s opacity, .2s transform; cursor: pointer;}","#{id} .flowchart-element:hover .flowchart-port-dot {opacity: 0.7}","#{id} .flowchart-element.flowchart-drop-active .flowchart-port-dot {opacity: 0.5; transform: scale(2); background: #333}","#{id} .flowchart-element.flowchart-drop-active .flowchart-drop-active > .flowchart-port-dot {background: {activeColor}}","#{id} .flowchart-element .flowchart-port-dot:hover, #{id} .flowchart-element .flowchart-drag-active > .flowchart-port-dot, #{id} .flowchart-element .flowchart-drop-active > .flowchart-port-dot {opacity: 1; transform: scale(2)}","#{id} .flowchart-node.flowchart-active,","#{id} .flowchart-node.flowchart-drag-active,","#{id} .flowchart-allow-free-ports .flowchart-node.flowchart-drop-active","{border-color: {activeColor}!important; box-shadow: 0 0 0 2px {activeColor}!important}",'#{id} .flowchart-node.flowchart-active[data-basic-type="diamond"] {box-shadow: none!important}',"#{id} .flowchart-relation {pointer-events: none}","#{id} .flowchart-relation.flowchart-element-focused {pointer-events: auto}",'#{id} .flowchart-relation:before {content: " "; display: block; top: -4px; right: -4px; bottom: -4px; left: -4px; position: absolute; border-radius: 50%;}',"#{id} .flowchart-relation-text {min-height: 14px; min-width: 12px; opacity: 0; pointer-events: auto}","#{id} .flowchart-relation-text.flowchart-has-text {opacity: 1; display: -webkit-box!important; -webkit-line-clamp: 2!important; -webkit-box-orient: vertical!important; overflow: hidden!important}",'#{id} .flowchart-relation[data-shape="polyline"] .flowchart-relation-text,','#{id} .flowchart-relation[data-shape="bessel"] .flowchart-relation-text,','#{id} .flowchart-relation[data-shape="arc"] .flowchart-relation-text {cursor: move}','#{id} .flowchart-relation-text.flowchart-has-text[data-shape="arc"] {white-space: nowrap;}',"#{id} .flowchart-node-text.flowchart-node-text-limit {align-items: flex-start!important; line-height: 1.3!important; pading-top: 5px!important; display: -webkit-box!important; -webkit-line-clamp: 2!important; -webkit-box-orient: vertical!important;}","#{id} .flowchart-element-focused .flowchart-relation-text {opacity: 1; pointer-events: auto; border: 1px solid {activeColor}}","#{id} .flowchart-svg-canvas .flowchart-relation-line:hover {stroke: {activeColor}!important}","#{id} .flowchart-port-expired {display: none!important}",'#{id} .flowchart-link-self-btn {position: absolute; bottom: -10px; right: -12px; width: 16px; height: 16px; border-radius: 8px; background: {activeColor}; opacity: 0; transition: .2s opacity; cursor: pointer; background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAAAcCAMAAABF0y+mAAAAbFBMVEUAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8+T+BWAAAAI3RSTlMAKzOqA7VVF9/aYl4iHRkI+PTUpXZwUhLlzMaZh/Whi4REQwySiHwAAAC4SURBVCjPtZLHDsIwEEQTx07vvVHf//8jPkBwUHxAgjnYGj1pNTta56fKPC+zQhfc72CR6ycVwgdfiNQg+RpR69/jKe/N2hNYoGygWnr3cOwFVGAJJKCRtrSKqLCVEEBsXdqHwQo7RnvRLeG+vmnKN5NQShP2UJjR7yZcqA0XocyWK66GjSHZjFRUgQHlTPmiRQPdLl8QgrrpVEMcwnnHNJ2BMhwBVvm5q4wjAFDi+HSStusH5/96AG7KECHX9nREAAAAAElFTkSuQmCC"); background-size: 14px 14px; background-repeat: no-repeat; background-position: center;}',"#{id} .flowchart-element:hover .flowchart-link-self-btn {opacity: .7;}","#{id} .flowchart-element .flowchart-link-self-btn:hover {opacity: 1;}","#{id} .flowchart-relation-line-ctrl-point {cursor: move; visibility: hidden}","#{id} .flowchart-relation-line:hover .flowchart-relation-line-ctrl-point,","#{id} .flowchart-relation-line-active .flowchart-relation-line-ctrl-point {visibility: visible; z-index: 10}","#{id} .flowchart-resize-handler {display: none}","#{id} .flowchart-resizable .flowchart-resize-handler {display: block; position: absolute; left: 0; right: 0; height: 6px; bottom: -3px; z-index: 100; cursor: ns-resize; transition: opacity .4s; border-radius: 3px; background: {activeColor}; opacity: 0;}","#{id} .flowchart-resizable .flowchart-resize-handler:hover {opacity: 0.4}"];t.plugins&&t.plugins.forEach(function(e){var r=N.plugins[e];r&&r.style&&o.push("function"==typeof r.style?r.style.call(t):r.style)}),o=o.join("\n").format({id:e,activeColor:t.options.activeColor});var i=r.getElementById("flowchartStyle-"+e);if(!i){var n=r.head||r.getElementsByTagName("head")[0],i=r.createElement("style");n.appendChild(i),i.type="text/css",i.id="flowchartStyle-"+e}i.styleSheet?i.styleSheet.cssText=o:i.appendChild(r.createTextNode(o))},N.prototype.createRelation=function(t){var e=this.types[t.type]||this.types[this.options.defaultRelationType];return e.createElement(t,this)},N.prototype.createElements=function(e){var o=this,r=o.types;if(e instanceof S)return[e];var i;"relation"===e.type&&(i=r[o.options.defaultRelationType]),i||(i=r[e.type]||r[o.options.defaultNodeType]);var n=i.createElement(e,o),a=[n];if(n.isNode){if(e.from){var l=t.isArray(e.from)?e.from:[e.from];l.forEach(function(t){var e=t.split(":");a.push(o.createRelation({from:e[0],to:l.length>2?n.id+"."+e[1]:n.id,text:e[l.length>2?2:1]}))})}if(e.to){var s=t.isArray(e.to)?e.to:[e.to];t.each(s,function(t,e){var r=e.split(":");a.push(o.createRelation({to:r[0],text:r[l.length>2?2:1],from:l.length>2?n.id+"."+fromInfo[1]:n.id}))})}}return a},N.prototype.activeElement=function(t,e){var o=this;"string"==typeof t&&(t=o.getElement(t)),e||o.unactiveElements([t.id]),t&&!o.isElementActive(t.id)&&(o.activedElements[t.id]=t,t.active(t.isNode),o.callCallback("onActiveElement",[t]))},N.prototype.unactiveElement=function(t){var e=this;"string"==typeof t&&(t=e.getElement(t)),t&&(delete this.activedElements[t.id],t.unactive(),e.callCallback("onUnactiveElement",[t]))},N.prototype.getActiveElements=function(e){var o=[];return this.activedElements&&t.each(this.activedElements,function(t,r){e&&e!==r.type||o.push(r)}),o},N.prototype.unactiveElements=function(e){var o,r=this;e&&("string"==typeof e&&(e=e.split(",")),o={},e.forEach(function(t){"object"==typeof t?o[t.id]=1:o[t]=1})),t.each(r.activedElements,function(t,e){o&&o[t]||r.unactiveElement(e)}),r.blurElementText()},N.prototype.isElementActive=function(t){return"object"==typeof t&&(t=t.id),!!this.activedElements[t]},N.prototype.blurElementText=function(){var t=this;if(t._focusedElement){var e=t.getElement(t._focusedElement);e&&e.blurText(),t._focusedElement=null}},N.prototype.focusElementText=function(t){var e=this;"string"==typeof t&&(t=e.getElement(t)),t&&(e.blurElementText(),e.activeElement(t),t.focusText(),e._focusedElement=t.id)},N.prototype.showContextMenu=function(e,o){var r=this;if("string"==typeof e&&(e=r.getElement(e)),e){var i=[];if(!r.options.readonly){var n=[];t.each(r.types,function(t,o){o.isNode!==e.isNode||o.internal||n.push("<option"+(e.type===t?" selected":"")+' value="'+t+'">'+(o.displayName||o.name)+"</option>")}),i.push({id:"type",html:['<div class="input-group" style="margin: 5px 10px 0 10px; min-width: 170px">','<span class="input-group-addon">'+r.lang.type+"</span>",'<select class="form-control flowchart-'+r.id+'-type-selector" data-id="'+e.id+'">',n.join(""),"</div>","</div>"].join("")},"-"),i.push({id:"edit",label:r.lang.edit,onClick:function(){r.focusElementText(e)}},{id:"delete",label:r.lang["delete"],onClick:function(){r.tryDeleteElement(e.id)}})}return"function"==typeof r.options.showContextMenu&&(i=r.options.showContextMenu(e,i,o)),i&&i.length?(r.activeElement(e),t.zui.ContextMenu.show(i,{event:o,className:"flowchart-contextmenu"}),!0):void 0}},N.prototype._forEachElement=function(e){t.each(this.elements,function(t,o){e(o,t)})},N.prototype._getPartialRenderMap=function(e){e&&!t.isArray(e)&&(e=[e]);var o=e&&e.length,r=null,i=this;return o&&(r={},e.forEach(function(t){"object"==typeof t&&(t=t.id);var e=i.getElement(t);if(e)if(r[t]=e,e.isNode){var o=function(t){r[t.id]=t},n=function(t){o(t)};e.fromRels.length&&e.fromRels.forEach(n),e.toRels.length&&e.toRels.forEach(n)}else e.fromNode&&(r[e.fromNode.id]=e.fromNode),e.toNode&&(r[e.toNode.id]=e.toNode)})),{map:r,enabled:o,canSkip:function(t){return o&&!r[t]}}},N.prototype.initArrowMarker=function(e,o,r){var i=this.$svgMarkers,n="flowchart-arrow-marker-"+e+"_"+t.zui.strCode(o)+(r?"_inverse":""),a=i.find("#"+n);if(!a.length){var l,s,h;r?(l="M0,"+e/2+" L0,"+e+" L"+e+","+e+" z",s=0,h=e/2,ref=' refx="'+e+'" refY="'+e/2+'"'):(l="M0,0 L0,"+e+" L"+e+","+e/2+" z",s=e,h=e/2);var p=f("marker",{id:n,orient:"auto",markerUnits:"strokeWidth",refX:s,refY:h,markerWidth:e,markerHeight:e});p.appendChild(f("path",{d:l,fill:o})),i.append(p)}return n},N.prototype._initElementsRelation=function(){var t=[],e=[];this._forEachElement(function(o){o.initBeforeRender(),(o.isRelation?e:t).push(o)}),this.nodeList=S.sort(t),this.relationList=S.sort(e),e.forEach(function(t){t.initRelationBeforeRender()})},N.prototype.render=function(t){var e=this,o=e.options,r=e._getPartialRenderMap(t);r.enabled||(e._initElementsRelation(),e.bounds={left:o.padding,top:o.padding,width:0,height:0});var i=e.nodeList,n=e.relationList,a=[],l=[];if(i.forEach(function(t){r.canSkip(t.id)||(t.renderNode(!0),t.getBounds().hasPosition||t.position&&t.position.custom||(delete t._depth,delete t._depthSize,delete t._siblingIndex,a.push(t)),l.push(t))}),a.length){for(var s=[],h="horz"===o.autoLayoutDirection,p=o.vertSpace,f=h?(o.nodeMinWidth+o.nodeMaxWidth)/2:o.nodeHeight,d=0,c=[],u=0;u<a.length;++u){var m=a[u];if(m.elementType.endType)c.push(m);else{var g=m.getDepth(),y=m.getDeptSize(h,p),v=s[g];v?(v.list.push(m),v.size+=y):(v={list:[m],size:y},s[g]=v),d=Math.max(d,y)}}for(var u=0;u<c.length;++u){var m=c[u],g=s.length;m._depth=g;var w=m.getBounds(),y=h?w.height:w.width,v=s[g];v?(v.list.push(m),v.size+=y):(v={list:[m],size:y},s[g]=v),d=Math.max(d,y)}for(var g=0;g<s.length;++g)for(var v=s[g],b=(d-v.size)/2,x=o.padding+b,u=0;u<v.list.length;++u){var C,m=v.list[u],y=m.getDeptSize(h),w=m.getBounds();C=h?{left:o.padding+g*(p+f),top:x+(y-w.height)/2}:{top:o.padding+g*(p+f),left:x+(y-w.width)/2},x+=y+p,m.setBounds(C)}for(var E=!0;E;){E=!1;for(var u=a.length-1;u>=0;--u)for(var R=a[u],T=a.length-1;T>=0;--T)if(!(u<=T)){var S=a[T];R.isIntersectWith(S)&&(E=!0,R.setBounds(h?{top:R.getPosition().top+o.vertSpace+R.getSize().height}:{left:R.getPosition().left+o.horzSpace+R.getSize().width}))}}}var P=!e.created&&o.centerOnCreate,N=e.$container.width(),M=e.$container.height();if(P){var k=Number.MAX_SAFE_INTEGER||Number.MAX_VALUE,A=Number.MAX_SAFE_INTEGER||Number.MAX_VALUE,_=Number.MIN_SAFE_INTEGER||Number.MIN_VALUE,I=Number.MIN_SAFE_INTEGER||Number.MIN_VALUE,L="horz"===P||P===!0,D="vert"===P||P===!0;l.forEach(function(t){t.layoutNode(!0);var e=t.getBounds();k=Math.min(e.left,k),A=Math.min(e.top,A),_=Math.max(e.right,_),I=Math.max(e.bottom,I)});var B=_-k,z=I-A,H=B<N?Math.floor((N-B)/2)-k:0,W=z<M?Math.floor((M-z)/2)-A:0;l.forEach(function(t){var e=t.getPosition();L&&(e.left+=H),D&&(e.top+=W),t.setBounds(e),t.$ele.css(e)})}else l.forEach(function(t){t.layoutNode()});n.forEach(function(t){r.canSkip(t.id)||t.renderRelation()});var $=Math.max(N,e.bounds.width+o.padding),O=Math.max(M,e.bounds.height+o.padding);e.$canvas.css({minWidth:$,minHeight:O}),e.$svg.attr({width:$,height:O})},N.prototype.drawRelationLine=function(e,o,r,i,n,l){var h,p=this,c=Math.floor((o.left+r.left)/2),u=Math.floor((o.top+r.top)/2),m=Math.floor((o.offsetLeft+r.offsetLeft)/2),g=Math.floor((o.offsetTop+r.offsetTop)/2),y=i.width;h="dashed"===i.style?4*y+" "+2*y:"dotted"===i.style?y+" "+y:"";var v=[],w={id:e+"-path","stroke-width":y,stroke:i.color,"stroke-dasharray":null,"marker-start":null,"marker-end":null,fill:"transparent"};h&&(w["stroke-dasharray"]=h),o.arrow&&(w["marker-start"]="url(#"+p.initArrowMarker(o.arrow,i.color,!0)+")"),r.arrow&&(w["marker-end"]="url(#"+p.initArrowMarker(r.arrow,i.color,!1)+")");var b=p.$svg.find("#"+e);if(b.length)d(b[0],{"class":i.className,"data-id":i.relation.id,id:e});else{var x=f("g",{"class":i.className,"data-id":i.relation.id,id:e});p.$svg.append(x),b=p.$svg.find("#"+e)}var C=function(t){return(t>0?1:-1)*Math.min(500,Math.abs(t))};if("polyline"===i.shape){var E=Math.abs(o.left-r.left),R=Math.abs(o.top-r.top),T=t.extend({porX:0,porY:0},i.bounds?i.bounds.shape:null);T.porX=C(T.porX),T.porY=C(T.porY);var S={x:Math.floor(c+Math.min(1,Math.max(-1,T.porX))*E/2),y:Math.floor(u+Math.min(1,Math.max(-1,T.porY))*R/2)};(T.porX||T.porY)&&i.relation.setBounds({shape:T}),v.push("M",o.left,o.top,"L","left"===o.side||"right"===o.side?S.x:o.left,"top"===o.side||"bottom"===o.side?S.y:o.top,"L",S.x,S.y,"L","left"===r.side||"right"===r.side?S.x:r.left,"top"===r.side||"bottom"===r.side?S.y:r.top,",",r.left,r.top),m+=S.x-c,g+=S.y-u;var P=e+"-point-por",N=b.find("#"+P);i.relation.position.porx=E/2,i.relation.position.pory=R/2;var M={id:P,"class":"flowchart-relation-line-ctrl-point flowchart-relation-primary-ctrl-point","data-name":"por","data-id":i.relation.id,cx:S.x,cy:S.y,r:3*y,"stroke-width":2*y,stroke:i.activeColor,fill:"transparent"};N.length?d(N[0],M):(N=f("circle",M),b.append(N))}else if("straight"===i.shape)v.push("M",o.left,o.top,"L",r.left,r.top);else if("bessel"===i.shape){var k=s(i.shapeStyle.besselCurvature,p.options.besselCurvature),A=Math.abs(o.left-r.left),_=Math.abs(o.top-r.top),I=Math.floor("right"===o.side?o.left+A*k/2:"left"===o.side?o.left-A*k/2:o.left),L=Math.floor("top"===o.side?o.top-_*k/2:"bottom"===o.side?o.top+_*k/2:o.top),D=c,B=u,z=Math.floor("right"===r.side?r.left+A*k/2:"left"===r.side?r.left-A*k/2:r.left),H=Math.floor("top"===r.side?r.top-_*k/2:"bottom"===r.side?r.top+_*k/2:r.top),T=t.extend({bboX:0,bboY:0,bcoX:0,bcoY:0,beoX:0,beoY:0},i.bounds?i.bounds.shape:null);T.bboX=C(T.bboX),T.bcoX=C(T.bcoX),T.beoX=C(T.beoX);var W={b:{x:I+T.bboX,y:L+T.bboY},c:{x:D+T.bcoX,y:B+T.bcoY},e:{x:z+T.beoX,y:H+T.beoY}};i.relation.setBounds({shape:T}),v.push("M",o.left,o.top,"Q",W.b.x,W.b.y,",",W.c.x,W.c.y,"Q",W.e.x,W.e.y,",",r.left,r.top),m+=W.c.x-D,g+=W.c.y-B,t.each(W,function(t){var o=W[t],r=e+"-point-"+t,n=b.find("#"+r),a={id:r,"class":"flowchart-relation-line-ctrl-point"+("c"===t?" flowchart-relation-primary-ctrl-point":""),"data-name":t,"data-id":i.relation.id,cx:o.x,cy:o.y,r:3*y,"stroke-width":2*y,stroke:i.activeColor,fill:"transparent"};n.length?d(n[0],a):(n=f("circle",a),b.append(n))})}else if("besselArc"===i.shape){var k=s(i.shapeStyle.besselCurvature,p.options.besselCurvature)/2,$=Math.min(o.left,r.left),O=Math.min(o.top,r.top),A=Math.abs(o.left-r.left),_=Math.abs(o.top-r.top),D=c+(o.left-r.left<0?1:-1)*_*k,B=u+(o.top-r.top<0?-1:1)*_*k,T=t.extend({bcoX:0,bcoY:0},i.bounds?i.bounds.shape:null);T.bcoX=C(T.bcoX),T.bcoY=C(T.bcoY);var W={c:{x:D+T.bcoX,y:B+T.bcoY}};i.relation.setBounds({shape:T}),v.push("M",o.left,o.top,"Q",W.c.x,W.c.y,",",r.left,r.top),m=Math.floor((c+W.c.x)/2)-$,g=Math.floor((u+W.c.y)/2)-O,t.each(W,function(t){var o=W[t],r=e+"-point-"+t,n=b.find("#"+r),a={id:r,"class":"flowchart-relation-line-ctrl-point"+("c"===t?" flowchart-relation-primary-ctrl-point":""),"data-name":t,"data-id":i.relation.id,cx:o.x,cy:o.y,r:3*y,"stroke-width":2*y,stroke:i.activeColor,fill:"transparent"};n.length?d(n[0],a):(n=f("circle",a),b.append(n))})}else if("arc"===i.shape){var E=Math.abs(o.left-r.left),R=Math.abs(o.top-r.top),X=a(o,r),j=Math.floor(X/2),T=t.extend({arrX:0,arrY:0},i.bounds?i.bounds.shape:null);T.arrX=C(T.arrX),T.arrY=C(T.arrY);var F=E>R?"y":"x",Y=function(t){return t*(o.left-r.left)/(r.top-o.top)+(r.left-o.left)/(r.top-o.top)*(o.left+r.left)/2+(o.top+r.top)/2},U=function(t){return(t-(r.left-o.left)/(r.top-o.top)*(o.left+r.left)/2-(o.top+r.top)/2)*(r.top-o.top)/(o.left-r.left)},S={left:c,top:u};(T.arrX||T.arrY)&&("x"===F?(S.left+=T.arrX*X,S.top=Y(S.left)):(S.top+=T.arrY*X,S.left=U(S.top)),j=a(S,o)),v.push("M",o.left,o.top,"A",j,j,0,1,T["x"===F?"arrX":"arrY"]*("y"===F?-1:1)>=0?1:0,r.left,r.top),m+=S.left-c,g+=S.top-u;var P=e+"-point-arr",N=b.find("#"+P);i.relation.position.arcd=X,i.relation.position.acdd=F;var M={id:P,"class":"flowchart-relation-line-ctrl-point flowchart-relation-primary-ctrl-point","data-name":"arr","data-id":i.relation.id,cx:S.left,cy:S.top,r:3*y,"stroke-width":2*y,stroke:i.activeColor,fill:"transparent"};N.length?d(N[0],M):(N=f("circle",M),b.append(N))}w.d=v.join(" ");var V=b.find("#"+w.id);if(V.length)d(V[0],w);else{var G=f("path",w);b.append(G)}if(l){l.css({position:"fixed",width:"",visiblity:"hidden"});var Q=l.outerWidth()+6,q=l.outerHeight();l.css({width:Q,visiblity:"visible",position:"absolute",left:Math.floor(m-Q/2),top:Math.floor(g-q/2)}).scrollTop(0)}},N.prototype.setElementBounds=function(t,e,o){var r=this,i=r.getElement(t);i&&(i.setBounds(e),o||r.render(i),r.callCallback("onChangeElementPosition",[e]))},N.prototype.addElement=function(t){var e=this.update(t);return e&&e.length&&this.focusElementText(e[0].id),e},N.prototype.addNode=function(t,o,r,i,n){if("string"==typeof o&&(o=this.getElement(o)),o){var a=o.id;"string"==typeof r&&r.length&&(a+="."+r);var l;return n&&(l={direction:n,from:o.id}),this.addElement({type:t,from:a,text:i===e?null:i,position:l})}},N.prototype.addRelation=function(o,r,i,n,a,l,s){var h=this;if("string"==typeof o&&(o=h.getElement(o)),"string"==typeof i&&(i=h.getElement(i)),o&&i&&(o!==i||o.canLinkSelf())&&(h.options.allowFreePorts||r&&n)){var p=t.extend({text:a===e?null:a,from:o.id,fromPort:r,to:i.id,toPort:n,type:l},s);return h.addElement(h.createRelation(p))}},N.prototype.resetPosition=function(){t.each(this.elements,function(t,e){"relation"!==e.type&&e.customPos&&delete e.customPos}),this.render()},N.prototype.getElement=function(t){return t?("string"!=typeof t&&(t=t.id),this.elements[t]):null},N.prototype.setElementText=function(t,e,o){var r=this;"string"==typeof t&&(t=r.getElement(t)),t&&t.setText(e)&&this.update(t,o)},N.prototype.resetData=function(e){e||(e=[{type:"start"}]);var o=this,r=[];t.each(o.elements,function(t,e){r.push(e)}),o["delete"](r,!0,!0),o.update(e,!1,!0),o.callCallback("onResetData",[e])},N.prototype.update=function(e,o,r){"object"!=typeof e||t.isArray(e)||(e=[e]);var i=this,n=[];if(e&&e.length){
|
|
var a=i.elements;if(t.each(e,function(t,e){var o=i.createElements(e);o.forEach(function(t){var e=a[t.id];e?e!==t&&(t.order=e.order,t.hasPosition()||t.setPosition(e.getPosition())):t.isNew=!0,n.push(t)})}),!r){var l=i.callCallback("onUpdateElement",[n]);if(l===!1)return;t.isArray(l)&&(n=l);var s=[];if(n.forEach(function(t){t.isNew&&s.push(t)}),s.length){var h=i.callCallback("onAddElement",[s]);if(h===!1)return;if(t.isArray(h)){var p={};h.forEach(function(t){p[t.id]=t});var f=[];n.forEach(function(t){t.isNew?p[t.id]&&f.push(p[t.id]):f.push(t)}),n=f}}}n.forEach(function(t){delete t.isNew,a[t.id]=t})}return i._initElementsRelation(),o||i.render(r?null:n),n.length&&i.callCallback("afterUpdateElement",[n]),n},N.prototype.replace=function(e,o,r){"string"!=typeof e&&(e=e.id);var i=this,n=i.createElements(o);o=n[0];var a=i.getElement(e);a&&i["delete"](e,!0),t.each(i.elements,function(t,r){r.isRelation&&(r.from===e?r.from=o.id:r.to===e&&(r.to=o.id))}),r||i.render()},N.prototype.getDomID=function(t,e){return"string"==typeof t?(e?"":"#")+this.id+"-"+t:(e?"":"#")+this.id+"-"+t.id},N.prototype.$findElement=function(t){return this.$canvas.find(this.getDomID(t))},N.prototype.tryDeleteElement=function(t){var e=this;if("string"==typeof t&&(t=e.getElement(t)),t){var o=e.options.deleteConfirm;return"function"==typeof o?o(t,function(){e["delete"](t.id)}):void(o&&!confirm(e.lang.confirmToDelete.format(t.text||t.id))||e["delete"](t.id))}},N.prototype["delete"]=function(e,o,r){var i=this;t.isArray(e)||(e=[e]);var n=[];t.each(e,function(e,o){"object"==typeof o&&(o=o.id),i.$findElement(o).remove();var r=i.getElement(o);if(r){if(n.push(r),r.isNode){var a=function(t){i["delete"](t.id,!0,!0)},l=r.fromRels&&r.fromRels,s=r.toRels&&r.toRels;l&&l.length&&(r.fromRels=[],l.forEach(a)),s&&s.length&&(r.toRels=[],s.forEach(a))}else{r.relationLineID&&t("#"+r.relationLineID).remove();var h=r.fromNode;if(h){if(h.fromRels&&h.fromRels.length){var p=h.fromRels.findIndex(function(t){return t.id===r.id});p>-1&&h.fromRels.splice(p,1)}r.fromNode=null}var f=r.toNode;if(f){if(f.fromRels&&f.fromRels.length){var p=f.fromRels.findIndex(function(t){return t.id===r.id});p>-1&&f.fromRels.splice(p,1)}r.toNode=null}}delete i.elements[o],i._focusedElement===o&&(i._focusedElement=null),i.activedElements[o]&&delete i.activedElements[o]}}),n.length&&(i._initElementsRelation(),o||i.render(),r||i.callCallback("onDeleteElement",[n]))},N.prototype.exportData=function(){var e=this,o=e.options.exportDataToSelf,r=[];return t.each(e.elements,function(e,i){var n=i.exportData();o&&n.data&&(t.extend(n,n.data),delete n.data),r.push(n)}),r.sort(function(t,e){return t.order-e.order}),t.each(r,function(t,e){delete e.order}),r},N.prototype.exportTypes=function(e){var o=this,r=[];return t.each(o.types,function(t,o){o.internal&&!e||r.push(o.exportType())}),r},N.prototype.findElementType=function(e){var o=null;return t.each(this.types,function(t,r){if(e(r,t))return o=r,!1}),o},N.prototype.getElementType=function(t){return this.findElementType(function(e){return e.name===t})},N.prototype.setOptions=function(e,o){t.extend(this.options,e),o||this.render()},N.plugins={},N.addPlugin=function(e,o){if(N.plugins[e])throw new Error('FlowChart: Add flowchart plugin failed, because there is already a plugin named "'+e+'".');o=t.extend(!0,{},o),o.plugins&&"string"==typeof o.plugins&&(o.plugins=o.plugins.split(",")),N.plugins[e]=o},N.LANGS={"zh-cn":{confirmToDelete:"确定删除【{0}】?",edit:"编辑","delete":"删除",type:"类型",selectRelationType:"请选择关系类型","type.rectangle":"矩形","type.box":"方框","type.circle":"圆形","type.diamond":"菱形","type.dot":"点","type.link":"连接线","type.action":"动作","type.start":"开始","type.stop":"结束","type.result":"结果","type.relation":"关系","type.judge":"判断","type.connection":"连接","type.point":"节点",linkSelf:"连接自身"},"zh-tw":{confirmToDelete:"確定刪除【{0}】?",edit:"編輯","delete":"刪除",type:"類型",selectRelationType:"請選擇關係類型","type.rectangle":"矩形","type.box":"方框","type.circle":"圓形","type.diamond":"菱形","type.dot":"點","type.link":"連接線","type.action":"動作","type.start":"開始","type.stop":"結束","type.result":"結果","type.relation":"關係","type.judge":"判斷","type.connection":"連接","type.point":"節點",linkSelf:"連接自身"},en:{confirmToDelete:'Confirm to delete "{0}"?',edit:"Edit","delete":"Delete",type:"Type",selectRelationType:"Please select relation type","type.rectangle":"Rectangle","type.box":"Box","type.circle":"Circle","type.diamond":"Diamond","type.dot":"Dot","type.link":"Link","type.action":"Action","type.start":"Start","type.stop":"Stop","type.result":"Result","type.relation":"Relation","type.judge":"Judge","type.connection":"Connection","type.point":"Point",linkSelf:"Link self"}},N.DEFAULTS={lang:null,langs:null,activeColor:"#3280fc",allowFreePorts:!1,adsorptionGrid:5,doubleClickToEdit:!0,readonly:!1,centerOnCreate:!0,showContextMenu:!0,addFromDrop:!0,editRelationByDrag:!0,quickAdd:!0,defaultNodeType:"action",defaultRelationType:"relation",deleteConfirm:!0,confirmRelationType:!0,draggable:!0,exportDataToSelf:!0,width:"auto",height:500,padding:40,nodeBackground:"#fff",nodeHeight:40,nodeMinWidth:70,nodeMaxWidth:250,autoLayoutDirection:"vert",horzSpace:80,vertSpace:60,relationArrowSize:8,relationLineWidth:1,relationLineStyle:"solid",relationLineColor:"#333",relationLineShape:"straight",besselCurvature:.8,portLineLength:0,portSpaceSize:20,portLineWidth:1,portLineStyle:"solid",portLineColor:"#333",autoAdjustPortSpace:!0,relationTextStyle:{},hideArrowToResult:!0,autoScaleText:!1,nodeStyle:{},nodeTextStyle:{},activeOnClick:!0,onClickElement:null,onUnactiveElement:null,onActiveElement:null,onDeleteElement:null,onUpdateElement:null,onAddElement:null,onRenderNode:null,onResetData:null,afterCreate:null,beforeCreate:null,nodeTemplate:'<div id="{domID}" data-basic-type="{basicType}" data-type="{type}" style="position: absolute; z-index: {zIndex}; display: flex; justify-content: center; align-items: center; cursor: {cursor}" class="flowchart-element flowchart-element-{type} flowchart-node" data-id="{id}"><div class="flowchart-text flowchart-node-text" style="position: relative; overflow: hidden; z-index: 5; outline: none; min-width: 10px; min-height: 20px; text-align: center; height: 100%; display: flex; flex-direction: row; align-items: center; justify-content: center"></div></div>',relationTemplate:'<div id="{domID}" data-basic-type="{basicType}" data-type="{type}" class="flowchart-element flowchart-element-{type} flowchart-relation" data-id="{id}" data-type="relation" style="position: absolute; z-index: 0;"><div class="flowchart-relation-lines" style="position:absolute;top:0;right:0;bottom:0;left:0;"></div><div class="flowchart-text flowchart-relation-text" style="background: rgba(255,255,255,.95); position: absolute; z-index: 5; line-height: 1; outline: none; max-width: 140px; text-align: center"></div></div>',portTemplate:'<div class="flowchart-port flowchart-port-{side}" id="flowchart-port-{id}-{name}" data-id="{id}-{name}" data-side="{side}" data-name="{name}" style="position:absolute;z-index:2"></div>',elementTypes:{},initialTypes:!0,data:[{id:"start",type:"start",text:"Start"}]},t.fn.flowChart=function(e){return this.each(function(){var o=t(this),r=o.data(c),i="object"==typeof e&&e;r||o.data(c,r=new N(this,i)),"string"==typeof e&&r[e]()})},N.NAME=c,N.supportElementTypes=R,N.convertCssToSvgStyle=p,N.createSVGElement=f,N.addTwoPoints=l,t.fn.flowChart.Constructor=N,t.zui({FlowChart:N,FlowChartElement:S})}(jQuery,void 0,window,document); |