
var lastDownTarget;(function(){var root=this,bpmndiag={};if(typeof module!=='undefined'&&module.exports){module.exports=bpmndiag;}else{root.bpmndiag=root.bpmndiag||bpmndiag;}
var o={'x':0,'y':0,'line-width':4,'line-length':50,'text-margin':10,'font-size':14,'font-color':'black','line-color':'black','element-color':'black','fill':'white','yes-text':'yes','no-text':'no','arrow-end':'classic-wide-long','class':'bpmndiag','symbols':{'start':{},'end':{},'xor':{},'split':{},'join':{},'activity':{}}};function _defaults(options,defaultOptions){if(!options||typeof options==='function'){return defaultOptions;}
var merged={};for(var attrname in defaultOptions){merged[attrname]=defaultOptions[attrname];}
for(attrname in options){if(options[attrname]){if(typeof merged[attrname]==='object'){merged[attrname]=_defaults(merged[attrname],options[attrname]);}else{merged[attrname]=options[attrname];}}}
return merged;}
function _inherits(ctor,superCtor){if(typeof(Object.create)==='function'){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}});}else{ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor();ctor.prototype.constructor=ctor;}}
var f={defaults:_defaults,inherits:_inherits};function BPMNDiagram(container,options){options=options||{};this.paper=new Raphael(container);this.options=f.defaults(options,o);this.symbols=[];this.lines=[];this.start=null;}
BPMNDiagram.prototype.handle=function(symbol){if(this.symbols.indexOf(symbol)<=-1){this.symbols.push(symbol);}
var bpmnDiag=this;if(symbol instanceof(GatewayXOR)){symbol.yes=function(nextSymbol){symbol.yes_symbol=nextSymbol;if(symbol.no_symbol){symbol.pathOk=true;}
return bpmnDiag.handle(nextSymbol);};symbol.no=function(nextSymbol){symbol.no_symbol=nextSymbol;if(symbol.yes_symbol){symbol.pathOk=true;}
return bpmnDiag.handle(nextSymbol);};}else if(symbol instanceof(GatewayParallel)){symbol.addThen=function(nextSymbol){if(!symbol.nexts)
symbol.nexts=[];if(symbol.nexts.indexOf(nextSymbol)<=-1){this.nexts.push(nextSymbol);}
return bpmnDiag.handle(nextSymbol);};}else{symbol.then=function(nextSymbol){symbol.next=nextSymbol;symbol.pathOk=true;return bpmnDiag.handle(nextSymbol);};}
return symbol;};BPMNDiagram.prototype.startWith=function(symbol){this.start=symbol;return this.handle(symbol);};BPMNDiagram.prototype.render=function(){var maxWidth=0,maxHeight=0,i=0,len=0,maxX=0,maxY=0,symbol;for(i=0,len=this.symbols.length;i<len;i++){symbol=this.symbols[i];if(symbol.width>maxWidth){maxWidth=symbol.width;}
if(symbol.height>maxHeight){maxHeight=symbol.height;}}
if(!this.start.isPositioned){if(!this.start.positionUsingHints()){this.start.shiftY(this.start.getY()+this.start.height);this.start.setX(this.start.getX()+this.start.width/2);}
this.start.isPositioned=true;}
this.start.render();for(i=0,len=this.symbols.length;i<len;i++){symbol=this.symbols[i];symbol.renderLines();}
maxX=this.maxXFromLine;for(i=0,len=this.symbols.length;i<len;i++){symbol=this.symbols[i];var x=symbol.getX()+symbol.width;var y=symbol.getY()+symbol.height;if(x>maxX){maxX=x;}
if(y>maxY){maxY=y;}}
if(maxX>1000)
maxX=1000;maxX=Math.max(maxX+this.options['line-width']+500,800);maxY=Math.max(maxY+this.options['line-width']+500,900);this.paper.setSize(maxX,maxY);};BPMNDiagram.prototype.arc=function(center,radius,startAngle,endAngle){angle=startAngle;coords=this.toCoords(center,radius,angle);path="M "+coords[0]+" "+coords[1];while(angle<=endAngle){coords=this.toCoords(center,radius,angle);path+=" L "+coords[0]+" "+coords[1];angle+=1;}
return path;};BPMNDiagram.prototype.toCoords=function(center,radius,angle){var radians=(angle/180)*Math.PI;var x=center[0]+Math.cos(radians)*radius;var y=center[1]+Math.sin(radians)*radius;return[x,y];}
BPMNDiagram.prototype.clean=function(){if(this.paper){var paperDom=this.paper.canvas;if(paperDom.parentNode)
paperDom.parentNode.removeChild(paperDom);}};BPMNDiagram.prototype.clearLineSelection=function(){if(this.selectedLine)
this.selectedLine.attr({stroke:'black'});this.selectedLine=null;}
BPMNDiagram.prototype.clearSymbolSelection=function(){this.selectedSymbol.symbol.attr({stroke:this.selectedStroke});this.selectedSymbol=null;}
BPMNDiagram.prototype.updateSelectedSymbol=function(newText,hasLoopMarker){this.selectedSymbol.updateText(newText,hasLoopMarker);}
BPMNDiagram.prototype.updateIsComplex=function(isComplex){if(isComplex){this.selectedSymbol.crossComplex.show();}else{this.selectedSymbol.crossComplex.hide();}}
BPMNDiagram.prototype.deleteSymbol=function(deleteSymbol){var healFrom=null;var healTo=null;if(deleteSymbol.connectionsIn&&deleteSymbol.connectionsIn.length==1&&deleteSymbol.connectionsOut&&deleteSymbol.connectionsOut.length==1){healFrom=deleteSymbol.connectionsIn[0].source;healTo=deleteSymbol.connectionsOut[0].dest;}
else{if(deleteSymbol instanceof(Activity)&&(deleteSymbol.connectionsIn&&deleteSymbol.connectionsIn.length!=0)&&(deleteSymbol.connectionsOut&&deleteSymbol.connectionsOut.length!=0))
return;if(deleteSymbol instanceof(GatewayXOR)&&deleteSymbol.connectionsIn&&deleteSymbol.connectionsIn.length==1&&deleteSymbol.connectionsOut){healFrom=deleteSymbol.connectionsIn[0].source;healTo=deleteSymbol.getNonNoConnections(deleteSymbol.connectionsOut)[0].dest;}}
var symbolPos=this.symbols.indexOf(deleteSymbol);this.symbols.remove(symbolPos);deleteSymbol.deleteConnections();if(this.onDeleteSymbol){this.onDeleteSymbol(deleteSymbol.key);}
if(healFrom!=null){healFrom.joinTo(healTo);healFrom.redrawLines();}
deleteSymbol.cleanLines(true);removeAllUIElements(deleteSymbol.symbol);}
BPMNDiagram.prototype.keyup=function(event){this.ctrlPressed=event.ctrlKey;}
BPMNDiagram.prototype.keydown=function(event){this.ctrlPressed=event.ctrlKey;if(this.selectedSymbol&&event.keyCode==27){this.clearSymbolSelection();}
if(this.selectedSymbol&&event.keyCode==46){var deleteSymbol=this.selectedSymbol;this.clearSymbolSelection();this.clearLineSelection();if(deleteSymbol instanceof(Start)||deleteSymbol instanceof(End)||deleteSymbol instanceof(GatewayParallel)){return;}
this.deleteSymbol(deleteSymbol);this.fixParallels();}
if(this.selectedSymbol&&event.keyCode==13){if(this.onEditSymbol){this.onEditSymbol(this.selectedSymbol.key);}}
if(this.selectedLine&&event.keyCode==27){this.clearLineSelection();}
if(this.selectedLine&&event.keyCode==46){}}
BPMNDiagram.prototype.deleteLine=function(line){var source=line.sourceSymbol;var dest=line.destSymbol;var lineText=null;if(line.text&&line.text.attrs){lineText=line.text.attrs['text'];}
if(source){source.cleanLines();if(source instanceof(GatewayParallel)){if(source.nexts){var nextIdx=source.nexts.indexOf(dest);if(nextIdx>-1){source.nexts.splice(nextIdx,1);}}}else if(source instanceof(GatewayXOR)){if((source.yes_symbol==dest)&&(lineText=='yes'))
source.yes_symbol=null;if((source.no_symbol==dest)&&(lineText=='no'))
source.no_symbol=null;}else{source['next']=null;source['direction_next']=null;}
this.clearLineSelection();source.renderLines();}}
BPMNDiagram.prototype.deleteLineBetween=function(source,dest,text){for(var i=0;i<source.connectionsOut.length;i++){var c=source.connectionsOut[i];if(c.dest.key==dest.key&&(text==undefined||text==null||c.line.text.attrs['text']==text)){this.deleteLine(c.line);return;}}}
BPMNDiagram.prototype.animateLine=function(symbol,colorNumber,path){var canvas=symbol.chart.paper;var line=canvas.path(path).attr({stroke:colorNumber});var length=line.getTotalLength();var lastoffset=0;$('path[fill*="none"]').stop();if(this.dropLine){this.dropLine.remove();}
this.dropLine=line;line.hide();$('path[fill*="none"]').delay(100).animate({'to':1},{duration:750,step:function(pos,fx){var offset=length*fx.pos;if(offset!=lastoffset){if(offset<10)
offset=10;lastoffset=offset;var subpath=line.getSubpath(0,offset);if(subpath&&subpath.indexOf('NaN')==-1){for(var i=0;i<symbol.chart.symbols.length;i++){var clearSymbol=symbol.chart.symbols[i];if(clearSymbol.dropLine){clearSymbol.dropLine.remove();clearSymbol.dropLine=null;}}
var dropLine=canvas.path(subpath);symbol.dropLine=dropLine.attr({stroke:colorNumber,"stroke-dasharray":"--","stroke-width":'1.5','arrow-end':'block-wide-long'});}}},complete:function(){if(symbol.dropLine){symbol.dropLineAnimationComplete=true;symbol.dropLine.attr({stroke:'#000'});}}});return line;};BPMNDiagram.prototype.stopLineAnimation=function(draggingSymbol){return;$('path[fill*="none"]').stop();if(this.dropLine){this.dropLine.remove();this.dropLine=null;}
for(var i=0;i<this.symbols.length;i++){var symbol=this.symbols[i];if(symbol.dropLine){if(draggingSymbol!=null&&symbol.dropLineAnimationComplete==true){var source=symbol;var dest=draggingSymbol;source.joinTo(dest);source.renderLines();}
symbol.dropLine.remove();symbol.dropLine=null;symbol.dropLineAnimationComplete=false;}}}
BPMNDiagram.prototype.findNearbyConnections=function(draggingSymbol){return;this.stopLineAnimation(null);if(draggingSymbol.hasFreeInConnection()){var shortestLength=200;var nearestSymbol=null;for(var i=0;i<this.symbols.length;i++){var symbol=this.symbols[i];if(symbol==draggingSymbol)
continue;if(symbol.hasFreeOutConnection()){var connectionDir=symbol.calcConnectionDirection(draggingSymbol);var points=symbol.calcLinePoints(draggingSymbol,connectionDir);var location;if("E"==connectionDir[0]){location=symbol.getRight();}else if("S"==connectionDir[0]){location=symbol.getBottom();}else if("W"==connectionDir[0]){location=symbol.getLeft();}else if("N"==connectionDir[0]){location=symbol.getTop();}
var path='M'+location.x+','+location.y;for(var pathIdx=0,len=points.length;pathIdx<len;pathIdx++){path+=' L'+points[pathIdx].x+','+points[pathIdx].y;}
var line=symbol.chart.paper.path(path).attr({stroke:'#000000'});var length=line.getTotalLength();line.remove();if(length<shortestLength){shortestLength=length;nearestSymbol={symbol:symbol,path:path};}}}
if(nearestSymbol!=null){this.animateLine(nearestSymbol.symbol,"#32127A",nearestSymbol.path);}}}
BPMNDiagram.prototype.asJson=function(){return this.paper.toJSON();}
BPMNDiagram.prototype.moveBelow=function(top,downBy){for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];if(s.getTop().y>top){s.nudgeY(downBy);}}};BPMNDiagram.prototype.redrawAllLines=function(){for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];s.redrawLines();}}
BPMNDiagram.prototype.fixParallels=function(){var splitConnections=[];for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];if(s instanceof(GatewayParallel)&&s.symbolType=='split'){if(s.connectionsOut&&s.connectionsOut.length>1){for(var j=0;j<s.connectionsOut.length;j++){var gwDest=s.connectionsOut[j].dest;if(gwDest instanceof(GatewayParallel)&&gwDest.symbolType=='join'){splitConnections.push({s:s,d:gwDest});}}}}}
for(var i=0;i<splitConnections.length;i++){this.deleteLineBetween(splitConnections[i].s,splitConnections[i].d);}
for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];if(s instanceof(GatewayParallel)&&s.symbolType=='split'){if(s.connectionsOut&&s.connectionsOut.length==1&&s.connectionsIn&&s.connectionsIn.length==1){var s2=s.connectionsOut[0].dest;if(s2 instanceof(GatewayParallel)&&s2.symbolType=='join'){if(s2.connectionsIn&&s2.connectionsIn.length==1&&s2.connectionsOut&&s2.connectionsOut.length==1){var intoS1=s.connectionsIn[0].source;var outofS2=s.connectionsOut[0].dest;this.deleteSymbol(s);this.deleteSymbol(s2);i=0;}}}}}
for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];if(!(s instanceof(Start))){if(s.connectionsIn&&s.connectionsIn.length==0){this.deleteSymbol(s);i=0;}}}
var bottom=300;for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];var b=s.getBottom().y;if(b>bottom){bottom=b;}}
this.paper.setSize(this.paper.width,bottom+100);}
BPMNDiagram.prototype.getEnd=function(){for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];if(s.symbolType=='end'){return s;}}
return null;}
BPMNDiagram.prototype.replaceConnectionSource=function(connection,newSource){var text=null;if(connection.line.text&&connection.line.text.attrs)
{text=connection.line.text.attrs['text'];}
var source=connection.line.sourceSymbol;var dest=connection.line.destSymbol;this.deleteLineBetween(source,dest,text);newSource.joinTo(dest,text);}
BPMNDiagram.prototype.replaceConnectionDest=function(connection,newdest){var text=null;if(connection.line.text&&connection.line.text.attrs){text=connection.line.text.attrs['text'];}
var source=connection.line.sourceSymbol;var dest=connection.line.destSymbol;this.deleteLineBetween(source,dest,text);source.joinTo(newdest,text);};BPMNDiagram.prototype.layoutDiagram=function(positions){var extraLeft=100;if(this.symbols.length==2)
{extraLeft=400;}
for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];if(positions[s.key]){s.nudgeCenterTo(positions[s.key].x+extraLeft,positions[s.key].y*1.3);}}
for(var i=0;i<this.symbols.length;i++){var s=this.symbols[i];s.cleanLines();}
this.redrawAllLines();this.fixParallels();};function Symbol(chart,options,symbol){this.chart=chart;this.group=this.chart.paper.set();this.symbol=symbol;this.symbolType=options.symbolType;this.symbolstate=(options.symbolstate||undefined);this.key=options.key;this.rowHint=options.rowHint;this.colHint=options.colHint;this.stepPosX=options.stepPosX;this.stepPosY=options.stepPosY;this.next_direction=options.next&&options['direction_next']?options['direction_next']:undefined;this.text=this.chart.paper.text(0,0,options.text);if(options.key){this.text.node.id=options.key+'t';}
this.text.node.setAttribute('class',this.getAttr('class')+'t'+' draggable');this.text.attr({'text-anchor':'start','x':this.getAttr('text-margin'),'fill':this.getAttr('font-color'),'font-size':this.getAttr('font-size')});var font=this.getAttr('font');var fontF=this.getAttr('font-family');var fontW=this.getAttr('font-weight');if(font)this.text.attr({'font':font});if(fontF)this.text.attr({'font-family':fontF});if(fontW)this.text.attr({'font-weight':fontW});if(options.link){this.text.attr('href',options.link);}
if(options.target){this.text.attr('target',options.target);}
var maxWidth=this.getAttr('maxWidth');if(maxWidth){var words=options.text.split(' ');var tempText="";for(var i=0,ii=words.length;i<ii;i++){var word=words[i];this.text.attr("text",tempText+" "+word);if(this.text.getBBox().width>maxWidth){tempText+="\n"+word;}else{tempText+=" "+word;}}
this.text.attr("text",tempText.substring(1));}
if(options.text.length>0)
this.group.push(this.text);if(symbol){var tmpMargin=this.getAttr('text-margin');if(this.text.getBBox().width==0){symbol.attr({'fill':this.getAttr('fill'),'fill-opacity':this.getAttr('fill-opacity'),'stroke':this.getAttr('element-color'),'stroke-width':this.getAttr('line-width'),'width':this.getAttr('radius'),'height':this.getAttr('radius'),'r':this.getAttr('radius')});}
else
symbol.attr({'fill':this.getAttr('fill'),'fill-opacity':this.getAttr('fill-opacity'),'stroke':this.getAttr('element-color'),'stroke-width':this.getAttr('line-width'),'width':this.text.getBBox().width+2*tmpMargin,'height':this.text.getBBox().height+2*tmpMargin});symbol.node.setAttribute('class',this.getAttr('class')+' draggable');if(options.link){symbol.attr('href',options.link);}
if(options.target){symbol.attr('target',options.target);}
if(options.key){symbol.node.id=options.key;}
this.group.push(symbol);symbol.insertBefore(this.text);this.text.attr({'y':symbol.getBBox().height/2});this.addTooltips();if(this.chart.onCreatedSymbol){this.chart.onCreatedSymbol(this);}
this.initialize();}}
Symbol.prototype.addTooltips=function(){if(this.chart.getTooltip){var tooltip=this.chart.getTooltip(this);if(tooltip){var tspanNodes=$('tspan',$(this.text.node));if(tspanNodes.length>0){$('tspan',$(this.text.node)).each(function(){var titleEle=document.createElementNS('http://www.w3.org/2000/svg','title');$(titleEle).prependTo($(this)).text(tooltip);});}
else{var titleEle=document.createElementNS('http://www.w3.org/2000/svg','title');$(titleEle).prependTo($(this.text.node)).text(tooltip);}
var titleEle=document.createElementNS('http://www.w3.org/2000/svg','title');$(titleEle).prependTo($(this.symbol.node)).text(tooltip);}}};Symbol.prototype.getAttr=function(attName){if(!this.chart){return undefined;}
var opt3=(this.chart.options)?this.chart.options[attName]:undefined;var opt2=(this.chart.options.symbols)?this.chart.options.symbols[this.symbolType][attName]:undefined;var opt1;if(this.chart.options.symbolstate&&this.chart.options.symbolstate[this.symbolstate]){opt1=this.chart.options.symbolstate[this.symbolstate][attName];}
return(opt1||opt2||opt3);};Symbol.prototype.updateText=function(newText,loopMarker){if(this.symbolType=='activity'){var oldTextBb=this.text.getBBox();var tmpMargin=this.getAttr('text-margin');this.text.attr("text",newText);if(this.loopMarker){if(loopMarker){this.loopMarker.show();}else{this.loopMarker.hide();}}
var newTextBb=this.text.getBBox();var oldHeight=oldTextBb.height;var oldWidth=oldTextBb.width;var newHeight=newTextBb.height;var newWidth=newTextBb.width;var deltaWidth=newWidth-oldWidth;var deltaHeight=newHeight-oldHeight;this.symbol.attr({'width':newWidth+(2*tmpMargin),'height':newHeight+(2*tmpMargin),'x':this.symbol.attrs.x-(deltaWidth/2),'y':this.symbol.attrs.y-(deltaHeight/2)});this.width=newWidth+(2*tmpMargin);this.height=newHeight+(2*tmpMargin);this.text.attr({'x':this.text.attrs.x-(deltaWidth/2)});var loopDX=0;var loopDY=(deltaHeight/2);if(this.crossComplex){this.crossComplex.attr({x:this.crossComplex.attrs.x+loopDX,y:this.crossComplex.attrs.y+loopDY});}
if(this.loopMarker){this.loopMarker.attr({x:this.loopMarker.attrs.x+loopDX,y:this.loopMarker.attrs.y+loopDY});}
this.redrawLines();if(this.connectionsIn){var itemsToRedraw=[];for(var i=0;i<this.connectionsIn.length;i++){itemsToRedraw.push(this.connectionsIn[i].source);}
for(var i=0;i<itemsToRedraw.length;i++){itemsToRedraw[i].redrawLines();}}}
this.addTooltips();}
Symbol.prototype.initialize=function(){this.group.transform('t'+this.getAttr('line-width')+','+this.getAttr('line-width'));this.width=this.group.getBBox().width;this.height=this.group.getBBox().height;this.clicked=function(){if(this.chart.selectedSymbol!=null){var source=this.chart.selectedSymbol;var dest=this;if(source==dest){if(this.chart.onEditSymbol){this.chart.onEditSymbol(source.key);}
return;}
source.symbol.attr({stroke:this.chart.selectedStroke});this.chart.selectedSymbol=null;}else{this.chart.selectedSymbol=this;this.chart.selectedStroke=this.chart.selectedSymbol.symbol.attrs["stroke"];this.chart.selectedSymbol.symbol.attr({stroke:'blue'});this.chart.clearLineSelection();}};};Symbol.prototype.getRealBoundingBox=function(){var grp=this.group;var x=[],y=[],x2=[],y2=[];for(var i=grp.items.length;i--;){if(!grp.items[i].removed){var box=grp.items[i].getBBox();if(box.width==0)
continue;if(grp.items[i].type=="text"){}
x.push(box.x);y.push(box.y);x2.push(box.x+box.width);y2.push(box.y+box.height);}}
x=Math.min["apply"](0,x);y=Math.min["apply"](0,y);x2=Math.max["apply"](0,x2);y2=Math.max["apply"](0,y2);return{x:x,y:y,x2:x2,y2:y2,width:x2-x,height:y2-y}}
Symbol.prototype.getCenter=function(){return{x:this.getX()+this.width/2,y:this.getY()+this.height/2};};Symbol.prototype.getX=function(){return this.group.getBBox().x;};Symbol.prototype.getY=function(){return this.group.getBBox().y;};Symbol.prototype.redrawLines=function(){this.renderLines();};Symbol.prototype.shiftX=function(x){var bb=this.group.getBBox();var newX=snap(x+this.getX()+(bb.width/2),10);x=newX-((bb.width/2));this.group.transform('t'+x+','+this.getY());};Symbol.prototype.setX=function(x){var bb=this.group.getBBox();var newX=snap(x+(bb.width/2),10);x=newX-((bb.width/2));this.group.transform('t'+x+','+this.getY());};Symbol.prototype.shiftY=function(y){var bb=this.group.getBBox();var newY=snap(y+this.getY()+(bb.height/2),10);y=newY-((bb.height/2));this.group.transform('t'+this.getX()+','+y);};Symbol.prototype.nudgeY=function(y){dragStart.call(this.symbol);dragMove.call(this.symbol,0,y);dragEndInternal.call(this.symbol,false);};Symbol.prototype.nudgeX=function(x){dragStart.call(this.symbol);dragMove.call(this.symbol,x,0);dragEndInternal.call(this.symbol,false);};Symbol.prototype.nudgeXY=function(x,y){dragStart.call(this.symbol);dragMove.call(this.symbol,x,y);dragEndInternal.call(this.symbol,false);};Symbol.prototype.nudgeCenterTo=function(x,y){var c=this.getCenter();var dx=x-c.x;var dy=y-c.y;dx=snap(dx,10);dy=snap(dy,10);this.nudgeXY(dx,dy);};Symbol.prototype.nudgeTo=function(x,y){var bb=this.group.getBBox();var newX=snap(x-this.getX()+(bb.width/2),10);x=newX-((bb.width/2));var newY=snap(y-this.getY()+(bb.height/2),10);y=newY-((bb.height/2));x=snap(x,10);y=snap(y,10);this.nudgeXY(x,y);};Symbol.prototype.setY=function(y){var bb=this.group.getBBox();var newY=snap(y+(bb.height/2),10);y=newY-((bb.height/2));this.group.transform('t'+this.getX()+','+y);};Symbol.prototype.getTop=function(){var y=this.getY();var x=this.getX()+this.width/2;return{x:x,y:y};};Symbol.prototype.getBottom=function(){var y=this.getY()+this.height;var x=this.getX()+this.width/2;return{x:x,y:y};};Symbol.prototype.getLeft=function(){var y=this.getY()+this.group.getBBox().height/2;var x=this.getX();return{x:x,y:y};};Symbol.prototype.getRight=function(){var y=this.getY()+this.group.getBBox().height/2;var x=this.getX()+this.group.getBBox().width;return{x:x,y:y};};Symbol.prototype.positionUsingHints=function(){if(this.positionUsingPos())
return true;if(this.rowHint!=-1&&this.colHint!=-1){var lineLength=this.getAttr('line-length');this.setY(50+(this.rowHint*(lineLength*3.5))-(this.height/2));this.shiftX(300+(this.colHint*lineLength*4)-(this.width/2));return true;}
return false;}
Symbol.prototype.positionUsingPos=function(){if(this.stepPosX!=-1&&this.stepPosY!=-1){this.setY(this.stepPosY);this.shiftX(this.stepPosX);return true;}
return false;}
Symbol.prototype.render=function(){if(this.next){var lineLength=this.getAttr('line-length');if(this.next_direction==='right'){var rightPoint=this.getRight();var leftPoint=this.next.getLeft();if(!this.next.isPositioned){if(!this.next.positionUsingHints()){this.next.setY(rightPoint.y-this.next.height/2);this.next.shiftX(this.group.getBBox().x+this.width+lineLength);var self=this;(function shift(){var hasSymbolUnder=false;var symb;for(var i=0,len=self.chart.symbols.length;i<len;i++){symb=self.chart.symbols[i];var diff=Math.abs(symb.getCenter().x-self.next.getCenter().x);if(symb.getCenter().y>self.next.getCenter().y&&diff<=self.next.width/2){hasSymbolUnder=true;break;}}
if(hasSymbolUnder){self.next.setX(symb.getX()+symb.width+lineLength);shift();}})();}
this.next.isPositioned=true;this.next.render();}}else{var bottomPoint=this.getBottom();var topPoint=this.next.getTop();if(!this.next.isPositioned){if(!this.next.positionUsingHints()){this.next.shiftY(this.getY()+this.height+lineLength);this.next.setX(bottomPoint.x-this.next.width/2);}
this.next.isPositioned=true;this.next.render();}}}
var c=this.getCenter();addSnapPoint(c);};Symbol.prototype.cleanLines=function(removeAll){if(this.connectionsOut){for(var i=0;i<this.connectionsOut.length;i++){var thisConnection=this.connectionsOut[i];var thisLine=thisConnection.line;if(thisLine.text)
thisLine.text.remove();thisLine.remove();var chartLinePos=this.chart.lines.indexOf(thisLine);this.chart.lines.remove(chartLinePos);var destSymbol=thisConnection.dest;if(destSymbol.connectionsIn){for(var j=0;j<destSymbol.connectionsIn.length;j++){var destConnection=destSymbol.connectionsIn[j];if(thisLine==destConnection.line){destSymbol.connectionsIn.splice(j,1);break;}}}}}
this.connectionsOut=[];if(removeAll){if(this.connectionsIn){for(var i=0;i<this.connectionsIn.length;i++){var thisConnection=this.connectionsIn[i];var thisLine=thisConnection.line;if(thisLine.text)
thisLine.text.remove();thisLine.remove();var chartLinePos=this.chart.lines.indexOf(thisLine);this.chart.lines.remove(chartLinePos);var sourceSymbol=thisConnection.source;if(sourceSymbol.connectionsOut){for(var j=0;j<sourceSymbol.connectionsOut.length;j++){var sourceConnection=sourceSymbol.connectionsOut[j];if(thisLine==sourceConnection.line){sourceSymbol.connectionsOut.splice(j,1);break;}}}}}
this.connectionsIn=[];}};Symbol.prototype.hasFreeOutConnection=function(){if(this.connectionsOut&&this.connectionsOut.length>0)
return false;return true;}
Symbol.prototype.hasFreeInConnection=function(){if(this.connectionsIn&&this.connectionsIn.length>0)
return false;return true;}
Symbol.prototype.redrawLine=function(line){var dest=line.destSymbol;var lineText='';if(line.text&&line.text.attrs){lineText=line.text.attrs['text'];}
if(line.text)
line.text.remove();line.remove();var chartLinePos=this.chart.lines.indexOf(line);this.chart.lines.remove(chartLinePos);if(dest.connectionsIn){for(var j=0;j<dest.connectionsIn.length;j++){var destConnection=dest.connectionsIn[j];if(line==destConnection.line){dest.connectionsIn.splice(j,1);break;}}}
if(this.connectionsOut){for(var j=0;j<this.connectionsOut.length;j++){var sourceConnection=this.connectionsOut[j];if(line==sourceConnection.line){this.connectionsOut.splice(j,1);break;}}}
this.drawLineTo(dest,lineText);}
Symbol.prototype.renderLines=function(){this.cleanLines();if(this.next){if(this.next_direction){this.drawLineTo(this.next,'',this.next_direction);}else{this.drawLineTo(this.next);}}};Array.prototype.remove=function(from,to){var rest=this.slice((to||from)+1||this.length);this.length=from<0?this.length+from:from;return this.push.apply(this,rest);};Symbol.prototype.calcConnectionDirection=function(symbol,ignoreDirection){var x=this.getCenter().x,y=this.getCenter().y,top=this.getTop(),right=this.getRight(),bottom=this.getBottom(),left=this.getLeft();var symbolX=symbol.getCenter().x,symbolY=symbol.getCenter().y,symbolTop=symbol.getTop(),symbolRight=symbol.getRight(),symbolBottom=symbol.getBottom(),symbolLeft=symbol.getLeft();var width=right.x-left.x,height=bottom.y-top.y,symbolWidth=symbolRight.x-symbolLeft.x,symbolHeight=symbolBottom.y-symbolTop.y;var standardWidth=20;var ignoreOut='';if(this instanceof(GatewayXOR)){if(this.connectionsOut){if(this.connectionsOut.length==1){ignoreOut=this.connectionsOut[0].dir;}}}
var sourcePoint=bottom;var targetPoint=symbolTop;if((targetPoint.y-sourcePoint.y)>standardWidth){if(!this.hasLineIn("S")&&!symbol.hasLineOut("N")&&(ignoreDirection==undefined||(ignoreDirection[0]!="S"||ignoreDirection[1]!="N")))
if(ignoreOut!='S')
return["S","N"];}
sourcePoint=right
targetPoint=symbolLeft;if((targetPoint.x-sourcePoint.x)>standardWidth){if(!this.hasLineIn("E")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="E"||ignoreDirection[1]!="W")))
if(ignoreOut!='E')
return["E","W"];}
sourcePoint=left;targetPoint=symbolRight;if((sourcePoint.x-targetPoint.x)>standardWidth){if(!this.hasLineIn("W")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="W"||ignoreDirection[1]!="E")))
if(ignoreOut!='W')
return["W","E"];}
sourcePoint=top;targetPoint=symbolBottom;if((sourcePoint.y-targetPoint.y)>standardWidth){if(!this.hasLineIn("N")&&!symbol.hasLineOut("S")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="S")))
if(ignoreOut!='N')
return["N","S"];}
sourcePoint=right;targetPoint=symbolTop;if(((targetPoint.x-sourcePoint.x)>0.5*standardWidth)&&((targetPoint.y-sourcePoint.y)>standardWidth)){if(!this.hasLineIn("E")&&!symbol.hasLineOut("N")&&(ignoreDirection==undefined||(ignoreDirection[0]!="E"||ignoreDirection[1]!="N")))
if(ignoreOut!='E')
return["E","N"];}
targetPoint=symbolBottom;if(((targetPoint.x-sourcePoint.x)>0.5*standardWidth)&&((sourcePoint.y-targetPoint.y)>standardWidth)){if(!this.hasLineIn("E")&&!symbol.hasLineOut("S")&&(ignoreDirection==undefined||(ignoreDirection[0]!="E"||ignoreDirection[1]!="S")))
if(ignoreOut!='E')
return["E","S"];}
sourcePoint=left;targetPoint=symbolBottom;if(((sourcePoint.x-targetPoint.x)>0.5*standardWidth)&&((sourcePoint.y-targetPoint.y)>standardWidth)){if(!this.hasLineIn("W")&&!symbol.hasLineOut("S")&&(ignoreDirection==undefined||(ignoreDirection[0]!="W"||ignoreDirection[1]!="S")))
if(ignoreOut!='W')
return["W","S"];}
targetPoint=symbolTop;if(((sourcePoint.x-targetPoint.x)>0.5*standardWidth)&&((targetPoint.y-sourcePoint.y)>standardWidth)){if(!this.hasLineIn("W")&&!symbol.hasLineOut("N")&&(ignoreDirection==undefined||(ignoreDirection[0]!="W"||ignoreDirection[1]!="N")))
if(ignoreOut!='W')
return["W","N"];}
sourcePoint=top;targetPoint=symbolRight;if(((sourcePoint.y-targetPoint.y)>0.5*standardWidth)&&((sourcePoint.x-targetPoint.x)>standardWidth)){if(!this.hasLineIn("N")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="E")))
if(ignoreOut!='N')
return["N","E"];}
targetPoint=symbolLeft;if(((sourcePoint.y-targetPoint.y)>0.5*standardWidth)&&((targetPoint.x-sourcePoint.x)>standardWidth)){if(!this.hasLineIn("N")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="W")))
if(ignoreOut!='N')
return["N","W"];}
sourcePoint=bottom;targetPoint=symbolRight;if(((targetPoint.y-sourcePoint.y)>0.5*standardWidth)&&((sourcePoint.x-targetPoint.x)>standardWidth)){if(!this.hasLineIn("S")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="S"||ignoreDirection[1]!="E")))
if(ignoreOut!='S')
return["S","E"];}
targetPoint=symbolLeft;if(((targetPoint.y-sourcePoint.y)>0.5*standardWidth)&&((targetPoint.x-sourcePoint.x)>standardWidth)){if(!this.hasLineIn("S")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="S"||ignoreDirection[1]!="W")))
if(ignoreOut!='S')
return["S","W"];}
sourcePoint=top;targetPoint=symbolTop;if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if((sourcePoint.y-targetPoint.y)<0){if(Math.abs(sourcePoint.x-targetPoint.x)>((width+standardWidth)/2))
if(!this.hasLineIn("N")&&!symbol.hasLineOut("N")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="N")))
if(ignoreOut!='N')
return["N","N"];}else{if(Math.abs(sourcePoint.x-targetPoint.x)>(symbolWidth/2))
if(!this.hasLineIn("N")&&!symbol.hasLineOut("N")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="N")))
if(ignoreOut!='N')
return["N","N"];}}
sourcePoint=right;targetPoint=symbolRight;if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if((sourcePoint.x-targetPoint.x)>0){if(Math.abs(sourcePoint.y-targetPoint.y)>((height+standardWidth)/2))
if(!this.hasLineIn("E")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="E"||ignoreDirection[1]!="E")))
if(ignoreOut!='E')
return["E","E"];}else{if(Math.abs(sourcePoint.y-targetPoint.y)>(symbolHeight/2))
if(!this.hasLineIn("E")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="E"||ignoreDirection[1]!="E")))
if(ignoreOut!='E')
return["E","E"];}}
if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if((targetPoint.x-sourcePoint.x)>0){if(Math.abs(sourcePoint.y-targetPoint.y)>((height+standardWidth)/2))
if(!this.hasLineIn("W")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="W"||ignoreDirection[1]!="W")))
if(ignoreOut!='W')
return["W","W"];}else{if(Math.abs(sourcePoint.y-targetPoint.y)>(symbolHeight/2))
if(!this.hasLineIn("W")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="W"||ignoreDirection[1]!="W")))
if(ignoreOut!='W')
return["W","W"];}}
sourcePoint=top;targetPoint=symbolRight;if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if(!this.hasLineIn("N")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="E")))
if(ignoreOut!='N')
return["N","E"];}
targetPoint=symbolLeft;if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if(!this.hasLineIn("N")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="N"||ignoreDirection[1]!="W")))
if(ignoreOut!='N')
return["N","W"];}
sourcePoint=bottom;targetPoint=symbolRight;if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if(!this.hasLineIn("S")&&!symbol.hasLineOut("E")&&(ignoreDirection==undefined||(ignoreDirection[0]!="S"||ignoreDirection[1]!="E")))
if(ignoreOut!='S')
return["S","E"];}
targetPoint=symbolLeft;if((!symbol.isPointInside(sourcePoint))&&(!this.isPointInside(targetPoint))){if(!this.hasLineIn("S")&&!symbol.hasLineOut("W")&&(ignoreDirection==undefined||(ignoreDirection[0]!="S"||ignoreDirection[1]!="W")))
if(ignoreOut!='S')
return["S","W"];}
return["E","W"];}
Symbol.prototype.addLinePoint=function(point,points){points.push({x:snap(point.x,10),y:snap(point.y,10)});}
Symbol.prototype.calcLinePoints=function(symbol,connectionDir){var x=this.getCenter().x,y=this.getCenter().y,top=this.getTop(),right=this.getRight(),bottom=this.getBottom(),left=this.getLeft();var symbolX=symbol.getCenter().x,symbolY=symbol.getCenter().y,symbolTop=symbol.getTop(),symbolRight=symbol.getRight(),symbolBottom=symbol.getBottom(),symbolLeft=symbol.getLeft();var standardWidth=30;var points=[],startPoint,endPoint;if("E"==connectionDir[0]){startPoint=right;points.push(startPoint);if("S"==connectionDir[1]){endPoint=symbolBottom;this.addLinePoint({x:endPoint.x,y:startPoint.y},points);}else if("N"==connectionDir[1]){endPoint=symbolTop;this.addLinePoint({x:endPoint.x,y:startPoint.y},points);}else if("E"==connectionDir[1]){endPoint=symbolRight;this.addLinePoint({x:Math.max(startPoint.x,endPoint.x)+1.5*standardWidth,y:startPoint.y},points);this.addLinePoint({x:Math.max(startPoint.x,endPoint.x)+1.5*standardWidth,y:endPoint.y},points);}else{endPoint=symbolLeft;if(endPoint.y!=startPoint.y){this.addLinePoint({x:(startPoint.x+endPoint.x)/2,y:startPoint.y},points);this.addLinePoint({x:(startPoint.x+endPoint.x)/2,y:endPoint.y},points);}}}else if("W"==connectionDir[0]){startPoint=left;points.push(startPoint);if("S"==connectionDir[1]){endPoint=symbolBottom;this.addLinePoint({x:endPoint.x,y:startPoint.y},points);}else if("N"==connectionDir[1]){endPoint=symbolTop;this.addLinePoint({x:endPoint.x,y:startPoint.y},points);}else if("E"==connectionDir[1])
{endPoint=symbolRight;if(endPoint.y!=startPoint.y){this.addLinePoint({x:(startPoint.x+endPoint.x)/2,y:startPoint.y},points);this.addLinePoint({x:(startPoint.x+endPoint.x)/2,y:endPoint.y},points);}}
else{endPoint=symbolLeft;if(endPoint.y!=startPoint.y){this.addLinePoint({x:Math.min(startPoint.x,endPoint.x)-1.5*standardWidth,y:startPoint.y},points);this.addLinePoint({x:Math.min(startPoint.x,endPoint.x)-1.5*standardWidth,y:endPoint.y},points);}}}else if("N"==connectionDir[0]){startPoint=top;points.push(startPoint);if("E"==connectionDir[1]){endPoint=symbolRight;if((endPoint.x-startPoint.x)>0){this.addLinePoint({x:startPoint.x,y:startPoint.y-standardWidth},points);this.addLinePoint({x:endPoint.x+1.5*standardWidth,y:startPoint.y-standardWidth},points);this.addLinePoint({x:endPoint.x+1.5*standardWidth,y:endPoint.y},points);}else{this.addLinePoint({x:startPoint.x,y:endPoint.y},points);}}else if("W"==connectionDir[1]){endPoint=symbolLeft;if((endPoint.x-startPoint.x)<0){this.addLinePoint({x:startPoint.x,y:startPoint.y-standardWidth},points);this.addLinePoint({x:endPoint.x-1.5*standardWidth,y:startPoint.y-standardWidth},points);this.addLinePoint({x:endPoint.x-1.5*standardWidth,y:endPoint.y},points);}else{this.addLinePoint({x:startPoint.x,y:endPoint.y},points);}}else if("N"==connectionDir[1]){endPoint=symbolTop;this.addLinePoint({x:startPoint.x,y:Math.min(startPoint.y,endPoint.y)-1.5*standardWidth},points);this.addLinePoint({x:endPoint.x,y:Math.min(startPoint.y,endPoint.y)-1.5*standardWidth},points);}else{endPoint=symbolBottom;if(endPoint.x!=startPoint.x){this.addLinePoint({x:startPoint.x,y:(startPoint.y+endPoint.y)/2},points);this.addLinePoint({x:endPoint.x,y:(startPoint.y+endPoint.y)/2},points);}}}else if("S"==connectionDir[0]){startPoint=bottom;points.push(startPoint);if("E"==connectionDir[1]){endPoint=symbolRight;if((endPoint.x-startPoint.x)>0){this.addLinePoint({x:startPoint.x,y:startPoint.y+standardWidth},points);this.addLinePoint({x:endPoint.x+1.5*standardWidth,y:startPoint.y+standardWidth},points);this.addLinePoint({x:endPoint.x+1.5*standardWidth,y:endPoint.y},points);}else{this.addLinePoint({x:startPoint.x,y:endPoint.y},points);}}else if("W"==connectionDir[1]){endPoint=symbolLeft;if((endPoint.x-startPoint.x)<0){this.addLinePoint({x:startPoint.x,y:startPoint.y+standardWidth},points);this.addLinePoint({x:endPoint.x-1.5*standardWidth,y:startPoint.y+standardWidth},points);this.addLinePoint({x:endPoint.x-1.5*standardWidth,y:endPoint.y},points);}else{this.addLinePoint({x:startPoint.x,y:endPoint.y},points);}}else{endPoint=symbolTop;if(endPoint.x!=startPoint.x){this.addLinePoint({x:startPoint.x,y:(startPoint.y+endPoint.y)/2},points);this.addLinePoint({x:endPoint.x,y:(startPoint.y+endPoint.y)/2},points);}}}
points.push(endPoint);return points;}
Symbol.prototype.isPointInside=function(point){var top=this.getTop(),right=this.getRight(),bottom=this.getBottom(),left=this.getLeft();return point.x>left.x&&point.x<right.x&&point.y>top.y&&point.y<bottom.y;}
Symbol.prototype.isLineCrossing=function(fromPoint,toPoint){var top=this.getTop(),right=this.getRight(),bottom=this.getBottom(),left=this.getLeft();var fromX=(fromPoint.x<=toPoint.x)?fromPoint.x:toPoint.x;var toX=(fromPoint.x>toPoint.x)?fromPoint.x:toPoint.x;var fromY=(fromPoint.y<=toPoint.y)?fromPoint.y:toPoint.y;var toY=(fromPoint.y>toPoint.y)?fromPoint.y:toPoint.y;var horiCross=fromX<right.x&&toX>right.x&&fromY>top.y&&toY<bottom.y;var vertCross=fromY<bottom.y&&toY>bottom.y&&fromX>left.x&&toX<right.x;return(vertCross||horiCross);}
Symbol.prototype.hasLineIn=function(direction){if(this.connectionsIn){for(var i=0;i<this.connectionsIn.length;i++){var thisConnection=this.connectionsIn[i];if(thisConnection.dir==direction)
return true;}}
return false;}
Symbol.prototype.hasLineOut=function(direction){if(this.connectionsOut){for(var i=0;i<this.connectionsOut.length;i++){var thisConnection=this.connectionsOut[i];if(thisConnection.dir==direction)
return true;}}
return false;}
Symbol.prototype.add_child=function(parent,child){parent.children.push(child);child.parent=parent;child.drag(dragMove,dragStart,dragEnd);}
Symbol.prototype.getCorners=function(){var top=this.getTop().y;var bottom=this.getBottom().y;var left=this.getLeft().x;var right=this.getRight().x;var ret={tl:{x:left,y:top},bl:{x:left,y:bottom},tr:{x:right,y:top},br:{x:right,y:bottom}};return ret;}
Symbol.prototype.overlapsSymbol=function(s){var thisCorners=this.getCorners();var sCorners=s.getCorners();if((sCorners.tl.x>=thisCorners.tl.x)&&(sCorners.tl.x<=thisCorners.br.x)&&(sCorners.tl.y>=thisCorners.tl.y)&&(sCorners.tl.y<=thisCorners.br.y))
return true;if((sCorners.tr.x>=thisCorners.tl.x)&&(sCorners.tr.x<=thisCorners.br.x)&&(sCorners.tr.y>=thisCorners.tl.y)&&(sCorners.tr.y<=thisCorners.br.y))
return true;if((sCorners.bl.x>=thisCorners.tl.x)&&(sCorners.bl.x<=thisCorners.br.x)&&(sCorners.bl.y>=thisCorners.tl.y)&&(sCorners.bl.y<=thisCorners.br.y))
return true;if((sCorners.br.x>=thisCorners.tl.x)&&(sCorners.br.x<=thisCorners.br.x)&&(sCorners.br.y>=thisCorners.tl.y)&&(sCorners.br.y<=thisCorners.br.y))
return true;return false;}
Symbol.prototype.hitSymbol=function(top,bottom,left,right){if(this.symbolType=='activity'){return this.activityHitSymbol(top,bottom,left,right);}
return false;}
Symbol.prototype.isConnectedTo=function(symbol){if(this.connectionsOut){for(var i=0;i<this.connectionsOut.length;i++){var cOut=this.connectionsOut[i];if(cOut.dest.key==symbol.key){return cOut;}}}
return null;}
Symbol.prototype.getOverlappingSymbol=function(){for(var i=0;i<this.chart.symbols.length;i++){var s=this.chart.symbols[i];if(s.symbol.id!=this.symbol.id){if(s.overlapsSymbol(this)||this.overlapsSymbol(s)){return s;}}}
return null;}
Symbol.prototype.activityHitSymbol=function(top,bottom,left,right)
{var foundSymbol=this.getOverlappingSymbol();if(foundSymbol!=null)
{if(foundSymbol.symbolType=='activity'||foundSymbol.symbolType=='split')
{var firstSymbol=foundSymbol;if(this.isConnectedTo(foundSymbol)!=null){firstSymbol=this;}
var symbolBeforeGateway=null;for(var i=0;i<firstSymbol.connectionsIn.length;i++){var c=firstSymbol.connectionsIn[i];symbolBeforeGateway=c.source;}
var gatewayBefore=null;var gatewayAfter=null;if(foundSymbol.symbolType=='split'){gatewayBefore=foundSymbol;gatewayAfter=foundSymbol.getJoin();}
else{for(var i=0;i<foundSymbol.connectionsIn.length;i++){var con=foundSymbol.connectionsIn[i];if(con.source instanceof(GatewayParallel)&&con.source.symbolType=='split'){gatewayBefore=con.source;break;}}
for(var i=0;i<foundSymbol.connectionsOut.length;i++){var con=foundSymbol.connectionsOut[i];if(con.dest instanceof(GatewayParallel)&&con.dest.symbolType=='join'){gatewayAfter=con.dest;break;}}}
if(this.canDisconnect()){this.disconnect();}
if(gatewayBefore&&gatewayAfter){gatewayBefore.joinTo(this);this.joinTo(gatewayAfter);}
else{var oldTop=foundSymbol.getTop();var oldBottom=foundSymbol.getBottom();this.chart.moveBelow(oldBottom.y+5,130);this.chart.moveBelow(oldTop.y-5,50);gatewayBefore=chart.addSymbol('split','-',guid(),{x:oldTop.x-30,y:oldTop.y});gatewayBefore.dropped=true;var join=chart.addSymbol('join','-',guid(),{x:oldBottom.x-30,y:oldBottom.y+130});join.dropped=true;if(this.chart.onAddedParallelGateway){this.chart.onAddedParallelGateway(gatewayBefore,true);this.chart.onAddedParallelGateway(join,false);}
if(symbolBeforeGateway){this.chart.deleteLineBetween(symbolBeforeGateway,firstSymbol);symbolBeforeGateway.joinTo(gatewayBefore);}
gatewayBefore.joinTo(foundSymbol);gatewayBefore.joinTo(this);this.joinTo(join);foundSymbol.nudgeY(50);for(var i=0;i<foundSymbol.connectionsOut.length;i++){var c=foundSymbol.connectionsOut[i];join.joinTo(c.dest);}
foundSymbol.joinTo(join);}
this.chart.redrawAllLines();gatewayBefore.positionNewSymbol(this);this.chart.redrawAllLines();this.chart.fixParallels();return true;}}
return false;}
Symbol.prototype.hitLineTest=function(top,bottom,left,right){for(var i=0;i<this.chart.lines.length;i++){var l=this.chart.lines[i];var linePath=l.attrs.path;for(var j=1;j<linePath.length;j++){var xPt1=linePath[j-1][1];var yPt1=linePath[j-1][2];var xPt2=linePath[j][1];var yPt2=linePath[j][2];if((((yPt1<top)&&(yPt2>top))||(yPt1>top&&yPt2<bottom))&&(((xPt1<left)&&(xPt2>left))||(xPt1>left&&xPt2<right))){if(l.destSymbol.key!=this.key&&l.sourceSymbol.key!=this.key){var ret={from:linePath[j-1],to:linePath[j],line:l};return ret;}}}}
return null;}
Symbol.prototype.hitLine=function(top,bottom,left,right){var linePath=this.hitLineTest(top,bottom,left,right);if(linePath){var xPt1=linePath.from[1];var yPt1=linePath.from[2];var xPt2=linePath.to[1];var yPt2=linePath.to[2];var l=linePath.line;var destS=l.destSymbol;var sourceS=l.sourceSymbol;var lineText=null;if(l.text&&l.text.attrs){lineText=l.text.attrs['text'];}
var followDest=null;if(destS&&destS.connectionsOut&&destS.connectionsOut.length==1&&(this instanceof(GatewayXOR))){followDest=destS.connectionsOut[0].dest;}
if(this instanceof(GatewayXOR)&&followDest==null){followDest=destS;}
this.nudgeY(20);this.chart.moveBelow(bottom,70);if(xPt1==xPt2)
{var thisxCentre=this.getTop().x;this.nudgeX(xPt1-thisxCentre);}
this.chart.deleteLineBetween(sourceS,destS,lineText);sourceS.joinTo(this);this.joinTo(destS);if(followDest){this.joinTo(followDest);}
this.chart.redrawAllLines();this.chart.fixParallels();this.redrawConnectingLines();return true;}
return false;}
Symbol.prototype.getNonNoConnections=function(connections){var ret=[];if(connections){for(var i=0;i<connections.length;i++){var c=connections[i];if(c.line.text&&c.line.text.attrs&&c.line.text.attrs['text']=='no'){}
else{ret.push(c);}}}
return ret;}
Symbol.prototype.canDisconnect=function(){if(this.connectionsIn&&this.connectionsOut){var nonNoInputs=this.getNonNoConnections(this.connectionsIn);return(this.symbolType=='activity'&&nonNoInputs.length==1&&this.connectionsOut.length==1);}
return false;}
Symbol.prototype.disconnect=function(){var connectionIn=this.getNonNoConnections(this.connectionsIn)[0];var lineText=null;if(connectionIn.line.text&&connectionIn.line.text.attrs){lineText=connectionIn.line.text.attrs['text'];}
var s1=connectionIn.source;var s2=this.connectionsOut[0].dest;this.chart.deleteLineBetween(s1,this,lineText);this.chart.deleteLineBetween(this,s2);s1.joinTo(s2);var ret={source:s1,dest:s2};return ret;}
Symbol.prototype.existingHitTest=function(){var top=this.getTop().y;var bottom=this.getBottom().y;var left=this.getLeft().x;var right=this.getRight().x;if(this.hitSymbol(top,bottom,left,right)){this.chart.fixParallels();return null;}
var linePath=this.hitLineTest(top,bottom,left,right);if(linePath){if(linePath.line.sourceSymbol instanceof(GatewayXOR)&&!this.chart.ctrlPressed){if(linePath.line.text&&linePath.line.text.attrs['text']=='no'){if(this instanceof(Start)){var ret={snapBack:true};return ret;}
var sourceSymbol=linePath.line.sourceSymbol;this.chart.deleteLineBetween(linePath.line.sourceSymbol,linePath.line.destSymbol,'no');sourceSymbol.joinTo(this);this.chart.redrawAllLines();var ret={snapBack:true};this.chart.fixParallels();return ret;}}
if(this instanceof(Start)||this instanceof(End)){var ret={snapBack:true};return ret;}
var canDisconnect=this.canDisconnect();if((canDisconnect)||(!this.connectionsIn||this.connectionsIn.length==0&&!this.connectionsOut||this.connectionsOut.length==0)){var oldSource=linePath.line.sourceSymbol;var oldDest=linePath.line.destSymbol;var thisOldSource=null;var thisOldDest=null;if(canDisconnect){var disconnectRet=this.disconnect();thisOldSource=disconnectRet.source;thisOldDest=disconnectRet.dest;}
this.chart.deleteLineBetween(oldSource,oldDest);oldSource.joinTo(this);this.joinTo(oldDest);if(thisOldSource&&thisOldDest)
thisOldSource.joinTo(thisOldDest);this.chart.redrawAllLines();}}
this.chart.fixParallels();return null;}
Symbol.prototype.hitTest=function(){var top=this.getTop().y;var bottom=this.getBottom().y;var left=this.getLeft().x;var right=this.getRight().x;if(this.symbolType=='split'){var surroundSymbol=this.getOverlappingSymbol();if(surroundSymbol==null)
{var lineHit=this.hitLineTest(top,bottom,left,right);if(lineHit!=null)
{surroundSymbol=lineHit.line.destSymbol;}}
if(surroundSymbol!=null)
{if(surroundSymbol.symbolType=='end'){return false;}
var before=null;var after=null;if(surroundSymbol.symbolType=='activity')
{before=surroundSymbol;after=surroundSymbol;}
else if(surroundSymbol.symbolType=='split')
{before=surroundSymbol;after=surroundSymbol.getJoin();}
if(before&&after&&before.connectionsIn&&after.connectionsOut)
{var inBefore=before.getNonNoConnections(before.connectionsIn);var outAfter=after.getNonNoConnections(after.connectionsOut);if(inBefore.length==1&&outAfter.length==1)
{var oldTop=before.getTop();var oldBottom=after.getBottom();this.chart.moveBelow(oldBottom.y+5,130);this.chart.moveBelow(oldTop.y-5,50);inBefore=before.getNonNoConnections(before.connectionsIn);outAfter=after.getNonNoConnections(after.connectionsOut);var join=chart.addSymbol('join','-',guid(),{x:oldBottom.x-30,y:oldBottom.y+130});join.dropped=true;if(this.chart.onAddedParallelGateway){this.chart.onAddedParallelGateway(join,false);}
var beforeSource=inBefore[0].source;var afterDest=outAfter[0].dest;this.chart.deleteLine(inBefore[0].line);this.chart.deleteLine(outAfter[0].line);beforeSource.joinTo(this);this.joinTo(before);after.joinTo(join);join.joinTo(afterDest);this.chart.redrawAllLines();this.chart.fixParallels();return true;}}
if(surroundSymbol.symbolType=='start'){var endSymbol=this.chart.getEnd();if(endSymbol)
{var startTop=surroundSymbol.getTop();var endTop=endSymbol.getTop();this.chart.moveBelow(startTop.y+5,120);this.chart.moveBelow(endTop.y-5,80);this.nudgeY(100);var join=chart.addSymbol('join','-',guid(),{x:endTop.x-30,y:endTop.y+80});join.dropped=true;if(this.chart.onAddedParallelGateway){this.chart.onAddedParallelGateway(join,false);}
while(surroundSymbol.connectionsOut.length>0)
{var c=surroundSymbol.connectionsOut[0];this.chart.replaceConnectionSource(c,this);}
while(endSymbol.connectionsIn.length>0){var c=endSymbol.connectionsIn[0];this.chart.replaceConnectionDest(c,join);}
surroundSymbol.joinTo(this);join.joinTo(endSymbol);this.chart.redrawAllLines();this.chart.fixParallels();return true;}}}}
else{if(!this.hitSymbol(top,bottom,left,right)){return this.hitLine(top,bottom,left,right);}
else{return true;}}
return false;}
Symbol.prototype.joinTo=function(dest){if(this instanceof(GatewayParallel)){this.addThen(dest);}else if(this instanceof(GatewayXOR)){if(!this.yes_symbol)
this.yes_symbol=dest;else if(!this.no_symbol)
this.no_symbol=dest;}else{this['next']=dest;this['direction_next']='next';}}
Symbol.prototype.linesIntersectSymbols=function(linePoints){var intersections=0;for(var lIdx=0;lIdx<linePoints.length;lIdx++){var linePoint=linePoints[lIdx];var nextLinePoint=null;if(lIdx<linePoints.length-1){nextLinePoint=linePoints[lIdx+1];}
for(var i=0,len=this.chart.symbols.length;i<len;i++){var symb=this.chart.symbols[i];if(symb.isPointInside(linePoint)||(nextLinePoint!=null&&symb.isLineCrossing(linePoint,nextLinePoint))){intersections++;}}}
return intersections;}
Symbol.prototype.drawLineTo=function(symbol,text,origin){var symbolIntersections=0;var maxX=0,line,lineLength=this.getAttr('line-length'),lineWith=this.getAttr('line-width');var connectionDir=this.calcConnectionDirection(symbol);var linePoints=this.calcLinePoints(symbol,connectionDir);var checkIntersections=this.linesIntersectSymbols(linePoints);if(checkIntersections>0)
{var otherConnectionDir=this.calcConnectionDirection(symbol,connectionDir);var otherlinePoints=this.calcLinePoints(symbol,otherConnectionDir);var otherIntersections=this.linesIntersectSymbols(otherlinePoints);if(otherIntersections<checkIntersections)
{checkIntersections=otherIntersections;connectionDir=otherConnectionDir;linePoints=otherlinePoints;}}
symbolIntersections=checkIntersections;if("E"==connectionDir[0]){origin='right';line=drawLine(this.chart,this.getRight(),linePoints,text);}else if("S"==connectionDir[0]){origin='bottom';line=drawLine(this.chart,this.getBottom(),linePoints,text);}else if("W"==connectionDir[0]){origin='left';line=drawLine(this.chart,this.getLeft(),linePoints,text);}else if("N"==connectionDir[0]){origin='top';line=drawLine(this.chart,this.getTop(),linePoints,text);}
if(line){var self=this;for(var l=0,llen=this.chart.lines.length;l<llen;l++){var otherLine=this.chart.lines[l];var i,len,intersections,inter;var ePath=otherLine.attr('path'),lPath=line.attr('path');for(var iP=0,lenP=ePath.length-1;iP<lenP;iP++){var newPath=[];newPath.push(['M',ePath[iP][1],ePath[iP][2]]);newPath.push(['L',ePath[iP+1][1],ePath[iP+1][2]]);var line1_from_x=newPath[0][1];var line1_from_y=newPath[0][2];var line1_to_x=newPath[1][1];var line1_to_y=newPath[1][2];for(var lP=0,lenlP=lPath.length-1;lP<lenlP;lP++){var newLinePath=[];newLinePath.push(['M',lPath[lP][1],lPath[lP][2]]);newLinePath.push(['L',lPath[lP+1][1],lPath[lP+1][2]]);var line2_from_x=newLinePath[0][1];var line2_from_y=newLinePath[0][2];var line2_to_x=newLinePath[1][1];var line2_to_y=newLinePath[1][2];var res=checkLineIntersection(line1_from_x,line1_from_y,line1_to_x,line1_to_y,line2_from_x,line2_from_y,line2_to_x,line2_to_y);if(res.onLine1&&res.onLine2){var newSegment;if(line2_from_y===line2_to_y){if(line2_from_x>line2_to_x){newSegment=['L',res.x+lineWith*2,line2_from_y];lPath.splice(lP+1,0,newSegment);newSegment=['C',res.x+lineWith*2,line2_from_y,res.x,line2_from_y-lineWith*4,res.x-lineWith*2,line2_from_y];lPath.splice(lP+2,0,newSegment);line.attr('path',lPath);}else{newSegment=['L',res.x-lineWith*2,line2_from_y];lPath.splice(lP+1,0,newSegment);newSegment=['C',res.x-lineWith*2,line2_from_y,res.x,line2_from_y-lineWith*4,res.x+lineWith*2,line2_from_y];lPath.splice(lP+2,0,newSegment);line.attr('path',lPath);}}else{if(line2_from_y>line2_to_y){newSegment=['L',line2_from_x,res.y+lineWith*2];lPath.splice(lP+1,0,newSegment);newSegment=['C',line2_from_x,res.y+lineWith*2,line2_from_x+lineWith*4,res.y,line2_from_x,res.y-lineWith*2];lPath.splice(lP+2,0,newSegment);line.attr('path',lPath);}else{newSegment=['L',line2_from_x,res.y-lineWith*2];lPath.splice(lP+1,0,newSegment);newSegment=['C',line2_from_x,res.y-lineWith*2,line2_from_x+lineWith*4,res.y,line2_from_x,res.y+lineWith*2];lPath.splice(lP+2,0,newSegment);line.attr('path',lPath);}}
lP+=2;len+=2;}}}}
this.chart.lines.push(line);if(!this.connectionsOut)
this.connectionsOut=[];if(!symbol.connectionsIn)
symbol.connectionsIn=[];this.connectionsOut.push({line:line,dir:connectionDir[0],dest:symbol});symbol.connectionsIn.push({line:line,dir:connectionDir[1],source:this});line.click(function(ev){this.chart.clearLineSelection();this.chart.selectedLine=this;this.attr({stroke:'blue'});});line.sourceSymbol=this;line.destSymbol=symbol;line.node.setAttribute('class','selectable');}
if(!this.chart.maxXFromLine||(this.chart.maxXFromLine&&maxX>this.chart.maxXFromLine)){this.chart.maxXFromLine=maxX;}
return symbolIntersections;};Symbol.prototype.deleteConnections=function(){var deleteSymbol=this;if(deleteSymbol.connectionsIn){for(var i=0;i<deleteSymbol.connectionsIn.length;i++){var connectionIn=deleteSymbol.connectionsIn[i];var predecessor=connectionIn.source;if(predecessor.nexts){var nextIdx=predecessor.nexts.indexOf(deleteSymbol);if(nextIdx>-1){predecessor.nexts.splice(nextIdx,1);}}
else if(predecessor.yes_symbol&&predecessor.yes_symbol==deleteSymbol){predecessor.yes_symbol=null;}
else if(predecessor.no_symbol&&predecessor.no_symbol==deleteSymbol){predecessor.no_symbol=null;}
else if(predecessor.next==deleteSymbol){predecessor.next=null;}}}
if(deleteSymbol.connectionsOut){for(var i=0;i<deleteSymbol.connectionsOut.length;i++){var connectionOut=deleteSymbol.connectionsOut[i];var destSymbol=connectionOut.dest;if(destSymbol.connectionsIn){for(var j=0;j<destSymbol.connectionsIn.length;j++){var destConnection=destSymbol.connectionsIn[j];if(destConnection.source.key==deleteSymbol.key){destSymbol.connectionsIn.splice(j,1);break;}}}}}}
Symbol.prototype.redrawConnectingLines=function(x){this.renderLines();if(this.connectionsIn){for(var c=0;c<this.connectionsIn.length;c++){var connectionIn=this.connectionsIn[c];connectionIn.source.redrawLine(connectionIn.line);}}};function Start(chart,options){var symbol=chart.paper.rect(0,0,0,0,20);options=options||{};options.text=options.text.trim();Symbol.call(this,chart,options,symbol);symbol.children=[];symbol.bpmnObject=this;this.add_child(symbol,this.text);symbol.drag(dragMove,dragStart,dragEnd);}
f.inherits(Start,Symbol);function End(chart,options){var symbol=chart.paper.rect(0,0,0,0,20);options=options||{};options.text=options.text.trim();Symbol.call(this,chart,options,symbol);symbol.children=[];symbol.bpmnObject=this;this.add_child(symbol,this.text);symbol.drag(dragMove,dragStart,dragEnd);}
f.inherits(End,Symbol);function Activity(chart,options){var symbol=chart.paper.rect(0,0,0,0,10);options=options||{};if(options.text)
{options.text=wordwrap(options.text,Math.max(20,options.text.length/4),"\n",true);}
Symbol.call(this,chart,options,symbol);symbol.children=[];symbol.bpmnObject=this;this.add_child(symbol,this.text);this.indicatorSet=this.chart.paper.set();var complexWidth=10;var complexX=(symbol.bpmnObject.width/2)-(complexWidth/2);var complexY=(symbol.bpmnObject.height-complexWidth);this.crossComplex=chart.paper.image(_sroot+'/App_Themes/Default/images/procicon.png',complexX,complexY,complexWidth,complexWidth);this.indicatorSet.push(this.crossComplex);this.group.push(this.crossComplex);this.add_child(symbol,this.crossComplex);if(this.chart.onGetSymbolAttrib&&this.chart.onGetSymbolAttrib(this.key,'isComplex')){this.crossComplex.show();}else{this.crossComplex.hide();}
var loopRadius=10;var loopX=(symbol.bpmnObject.width/2)+complexWidth+(loopRadius/2);var loopY=(symbol.bpmnObject.height-(loopRadius)-1.5);this.loopMarker=chart.paper.image(_sroot+'/App_Themes/Default/images/itericon.png',loopX,loopY,loopRadius,loopRadius);this.indicatorSet.push(this.loopMarker);this.group.push(this.loopMarker);this.add_child(symbol,this.loopMarker);if(this.chart.onGetSymbolAttrib&&this.chart.onGetSymbolAttrib(this.key,'isLoop')){this.loopMarker.show();}else{this.loopMarker.hide();}
symbol.drag(dragMove,dragStart,dragEnd);if(this.chart.onCreatedActivity){this.chart.onCreatedActivity(this);}}
End.prototype.hasFreeOutConnection=function(){return false;}
f.inherits(Activity,Symbol);function GatewayXOR(chart,options){options=options||{};Symbol.call(this,chart,options);this.textMargin=this.getAttr('text-margin');this.yes_direction='right';this.no_direction='bottom';if(options.yes&&options['direction_yes']&&options.no&&!options['direction_no']){if(options['direction_yes']==='right'){this.no_direction='bottom';this.yes_direction='right';}else{this.no_direction='right';this.yes_direction='bottom';}}else if(options.yes&&!options['direction_yes']&&options.no&&options['direction_no']){if(options['direction_no']==='right'){this.yes_direction='bottom';this.no_direction='right';}else{this.yes_direction='right';this.no_direction='bottom';}}else{this.yes_direction='bottom';this.no_direction='right';}
this.yes_direction=this.yes_direction||'bottom';this.no_direction=this.no_direction||'right';this.text.attr({x:this.textMargin*2});var width=this.text.getBBox().width+3*this.textMargin;width+=width/2;var height=this.text.getBBox().height+2*this.textMargin;height+=height/2;height=Math.max(width*0.5,height);width=60;height=60;var startX=width/4;var startY=height/4;this.text.attr({x:startX+this.textMargin/2});var start={x:startX,y:startY};var points=[{x:startX-width/4,y:startY+height/4},{x:startX-width/4+width/2,y:startY+height/4+height/2},{x:startX-width/4+width,y:startY+height/4},{x:startX-width/4+width/2,y:startY+height/4-height/2},{x:startX-width/4,y:startY+height/4}];var symbol=drawPath(chart,start,points);this.symbol=symbol;symbol.attr({stroke:this.getAttr('element-color'),'stroke-width':this.getAttr('line-width'),fill:this.getAttr('fill')});if(options.link){symbol.attr('href',options.link);}
if(options.target){symbol.attr('target',options.target);}
if(options.key){symbol.node.id=options.key;}
symbol.node.setAttribute('class',this.getAttr('class')+' draggable');this.text.attr({y:symbol.getBBox().height/2});this.group.push(symbol);symbol.insertBefore(this.text);var start={x:width/2,y:height/2};this.donut=chart.paper.circle(start.x,start.y,12);this.donut.attr({stroke:'#555','stroke-width':'6'});this.donut.node.setAttribute('class',this.getAttr('class')+' draggable');this.group.push(this.donut);this.addTooltips();this.initialize();symbol.children=[];symbol.bpmnObject=this;this.add_child(symbol,this.text);this.add_child(symbol,this.donut);symbol.drag(dragMove,dragStart,dragEnd);}
f.inherits(GatewayXOR,Symbol);GatewayXOR.prototype.render=function(){if(this.yes_direction){this[this.yes_direction+'_symbol']=this.yes_symbol;}
if(this.no_direction){this[this.no_direction+'_symbol']=this.no_symbol;}
var lineLength=this.getAttr('line-length');if(this.bottom_symbol){var bottomPoint=this.getBottom();var topPoint=this.bottom_symbol.getTop();if(!this.bottom_symbol.isPositioned){if(!this.bottom_symbol.positionUsingHints()){this.bottom_symbol.shiftY(this.getY()+this.height+lineLength);this.bottom_symbol.setX(bottomPoint.x-this.bottom_symbol.width/2);}
this.bottom_symbol.isPositioned=true;this.bottom_symbol.render();}}
if(this.right_symbol){var rightPoint=this.getRight();var leftPoint=this.right_symbol.getLeft();if(!this.right_symbol.isPositioned){if(!this.right_symbol.positionUsingHints()){this.right_symbol.setY(rightPoint.y-this.right_symbol.height/2);this.right_symbol.shiftX(this.group.getBBox().x+this.width+lineLength);var self=this;(function shift(){var hasSymbolUnder=false;var symb;for(var i=0,len=self.chart.symbols.length;i<len;i++){symb=self.chart.symbols[i];var diff=Math.abs(symb.getCenter().x-self.right_symbol.getCenter().x);if(symb.getCenter().y>self.right_symbol.getCenter().y&&diff<=self.right_symbol.width/2){hasSymbolUnder=true;break;}}
if(hasSymbolUnder){self.right_symbol.setX(symb.getX()+symb.width+lineLength);shift();}})();}
this.right_symbol.isPositioned=true;this.right_symbol.render();}}};GatewayXOR.prototype.renderLines=function(){if(this.yes_symbol&&this.no_symbol){this.cleanLines();var yesThenNoIntersections=this.drawLineTo(this.yes_symbol,this.getAttr('yes-text'),this.yes_direction);yesThenNoIntersections+=this.drawLineTo(this.no_symbol,this.getAttr('no-text'),this.no_direction);this.cleanLines();var noThenYesIntersections=this.drawLineTo(this.no_symbol,this.getAttr('no-text'),this.no_direction);noThenYesIntersections+=this.drawLineTo(this.yes_symbol,this.getAttr('yes-text'),this.yes_direction);if(yesThenNoIntersections<noThenYesIntersections)
{this.cleanLines();this.drawLineTo(this.yes_symbol,this.getAttr('yes-text'),this.yes_direction);this.drawLineTo(this.no_symbol,this.getAttr('no-text'),this.no_direction);}}
else{this.cleanLines();if(this.yes_symbol){this.drawLineTo(this.yes_symbol,this.getAttr('yes-text'),this.yes_direction);}
if(this.no_symbol){this.drawLineTo(this.no_symbol,this.getAttr('no-text'),this.no_direction);}}};GatewayXOR.prototype.hasFreeOutConnection=function(){return(!(this.yes_symbol)||!(this.no_symbol));}
GatewayXOR.prototype.hasFreeInConnection=function(){return true;}
GatewayXOR.prototype.addTooltips=function(){if(this.chart.getTooltip){var tooltip=this.chart.getTooltip(this);if(tooltip){{var titleEle=document.createElementNS('http://www.w3.org/2000/svg','title');$(titleEle).prependTo($(this.symbol.node)).text(tooltip);}
{var titleEle=document.createElementNS('http://www.w3.org/2000/svg','title');$(titleEle).prependTo($(this.donut.node)).text(tooltip);}}}};var removeAllUIElements=function(parent){for(var i=0;i<parent.children.length;i++){parent.children[i].remove();}
parent.remove();}
function GatewayParallel(chart,options){options=options||{};Symbol.call(this,chart,options);this.textMargin=this.getAttr('text-margin');this.text.attr({x:this.textMargin*2});var width=this.text.getBBox().width+3*this.textMargin;width=40;width+=width/2;var height=this.text.getBBox().height+2*this.textMargin;height=40;height+=height/2;height=Math.max(width*0.5,height);var startX=width/4;var startY=height/4;this.text.attr({x:startX+this.textMargin/2});var start={x:startX,y:startY};var points=[{x:startX-width/4,y:startY+height/4},{x:startX-width/4+width/2,y:startY+height/4+height/2},{x:startX-width/4+width,y:startY+height/4},{x:startX-width/4+width/2,y:startY+height/4-height/2},{x:startX-width/4,y:startY+height/4}];var symbol=drawPath(chart,start,points);this.symbol=symbol;symbol.attr({stroke:this.getAttr('element-color'),'stroke-width':this.getAttr('line-width'),fill:this.getAttr('fill')});if(options.link){symbol.attr('href',options.link);}
if(options.target){symbol.attr('target',options.target);}
if(options.key){symbol.node.id=options.key;}
symbol.node.setAttribute('class',this.getAttr('class')+' draggable');this.text.attr({y:symbol.getBBox().height/2});this.group.push(symbol);symbol.insertBefore(this.text);var start={x:width/4,y:height/2};var points=[{x:width-(width/4),y:startY+height/4}];var vert=drawPath(chart,start,points);vert.attr({stroke:'#555','stroke-width':'6'});vert.node.setAttribute('class',this.getAttr('class')+' draggable');this.group.push(vert);var start={x:width/2,y:height/4};var points=[{x:width/2,y:height-height/4}];var hori=drawPath(chart,start,points);hori.attr({stroke:'#555','stroke-width':'6'});hori.node.setAttribute('class',this.getAttr('class')+' draggable');this.group.push(hori);this.initialize();symbol.children=[];symbol.bpmnObject=this;this.add_child(symbol,vert);this.add_child(symbol,hori);this.add_child(symbol,this.text);symbol.drag(dragMove,dragStart,dragEnd);}
f.inherits(GatewayParallel,Symbol);GatewayParallel.prototype.render=function(){var lineLength=this.getAttr('line-length');var i=0;do{var nextSymbol=this.nexts[i];var direction='bottom';if(i>=0){var bottomPoint=this.getBottom();var topPoint=nextSymbol.getTop();if(!nextSymbol.isPositioned){if(!nextSymbol.positionUsingHints()){nextSymbol.shiftY(this.getY()+this.height+lineLength);nextSymbol.setX(bottomPoint.x-nextSymbol.width/2);var self=this;(function shift(){var hasSymbolUnder=false;var symb;for(var i=0,len=self.chart.symbols.length;i<len;i++){symb=self.chart.symbols[i];if(symb===nextSymbol)
continue;var diff=Math.abs(symb.getCenter().x-nextSymbol.getCenter().x);if(symb.getCenter().y>=nextSymbol.getCenter().y&&diff<=nextSymbol.width/2){hasSymbolUnder=true;break;}}
if(hasSymbolUnder){nextSymbol.setX(symb.getX()+symb.width+lineLength);shift();}})();}
nextSymbol.isPositioned=true;nextSymbol.render();}}
else{var rightPoint=this.getRight();var leftPoint=nextSymbol.getLeft();if(!nextSymbol.isPositioned){if(!nextSymbol.positionUsingHints()){nextSymbol.setY(rightPoint.y-nextSymbol.height/2);nextSymbol.shiftX(this.group.getBBox().x+this.width+lineLength);var self=this;(function shift(){var hasSymbolUnder=false;var symb;for(var i=0,len=self.chart.symbols.length;i<len;i++){symb=self.chart.symbols[i];if(symb===nextSymbol)
continue;var diff=Math.abs(symb.getCenter().x-nextSymbol.getCenter().x);if(symb.getCenter().y>=nextSymbol.getCenter().y&&diff<=nextSymbol.width/2){hasSymbolUnder=true;break;}}
if(hasSymbolUnder){nextSymbol.setX(symb.getX()+symb.width+lineLength);shift();}})();}
nextSymbol.isPositioned=true;nextSymbol.render();}}
++i;}while(this.nexts[i]!=undefined)
if(this.yes_direction){this[this.yes_direction+'_symbol']=this.yes_symbol;}
if(this.no_direction){this[this.no_direction+'_symbol']=this.no_symbol;}
if(this.bottom_symbol){var bottomPoint=this.getBottom();var topPoint=this.bottom_symbol.getTop();if(!this.bottom_symbol.isPositioned){if(!this.bottom_symbol.positionUsingHints()){this.bottom_symbol.shiftY(this.getY()+this.height+lineLength);this.bottom_symbol.setX(bottomPoint.x-this.bottom_symbol.width/2);}
this.bottom_symbol.isPositioned=true;this.bottom_symbol.render();}}
if(this.right_symbol){var rightPoint=this.getRight();var leftPoint=this.right_symbol.getLeft();if(!this.right_symbol.isPositioned){if(!this.right_symbol.positionUsingHints()){this.right_symbol.setY(rightPoint.y-this.right_symbol.height/2);this.right_symbol.shiftX(this.group.getBBox().x+this.width+lineLength);var self=this;(function shift(){var hasSymbolUnder=false;var symb;for(var i=0,len=self.chart.symbols.length;i<len;i++){symb=self.chart.symbols[i];var diff=Math.abs(symb.getCenter().x-self.right_symbol.getCenter().x);if(symb.getCenter().y>self.right_symbol.getCenter().y&&diff<=self.right_symbol.width/2){hasSymbolUnder=true;break;}}
if(hasSymbolUnder){self.right_symbol.setX(symb.getX()+symb.width+lineLength);shift();}})();}
this.right_symbol.isPositioned=true;this.right_symbol.render();}}};GatewayParallel.prototype.renderLines=function(){if(!this.nexts)
this.nexts=[];this.cleanLines();var i=0;while(this.nexts[i]!=undefined){var nextSymbol=this.nexts[i];this.drawLineTo(nextSymbol);++i;}};GatewayParallel.prototype.hasFreeOutConnection=function(){return true;}
GatewayParallel.prototype.hasFreeInConnection=function(){return true;}
GatewayParallel.prototype.positionNewSymbol=function(symbol){var gatewayCenter=this.getBottom();var minX=gatewayCenter.x;var maxX=minX;var bottomY=gatewayCenter.y+10;for(var i=0;i<this.connectionsOut.length;i++){var c=this.connectionsOut[i];if(c.dest.key!=symbol.key){var cPosCorners=c.dest.getCorners();if(cPosCorners.tl.x<minX)
minX=cPosCorners.tl.x;if(cPosCorners.br.x>maxX)
maxX=cPosCorners.br.x;if(cPosCorners.tr.y>bottomY)
bottomY=cPosCorners.tr.y;}}
if((gatewayCenter.x-minX)>(maxX-gatewayCenter.x)){symbol.nudgeTo(maxX+10,bottomY);}
else{var symbolCorners=symbol.getCorners();symbol.nudgeTo(minX-(symbolCorners.tr.x-symbolCorners.tl.x)-10,bottomY);}}
GatewayParallel.prototype.getJoin=function()
{var splitCount=0;var checkRecursion=[];function followPaths(node,splitCount,recursed)
{if(node.symbolType=='join')
{if(splitCount==1){return node;}
else{splitCount--;}}
if(node.symbolType=='split')
splitCount++;for(var i=0;i<recursed.length;i++){if(recursed[i]==node)
return null;}
recursed.push(node);if(node.connectionsOut)
{var outNodes=node.getNonNoConnections(node.connectionsOut);if(outNodes.length>0)
{var ret=followPaths(outNodes[0].dest,splitCount,recursed);if(ret!=null)
{return ret;}}}
return null;}
return followPaths(this,0,checkRecursion);}
function parse(input){input=input||'';input=input.trim();var chart={symbols:{},start:null,drawSVG:function(container,options){var self=this;if(this.diagram){this.diagram.clean();}
var diagram=new BPMNDiagram(container,options);this.diagram=diagram;if(this.callbacks&&this.callbacks.onEditSymbol){this.diagram.onEditSymbol=this.callbacks.onEditSymbol;}
if(this.callbacks&&this.callbacks.onGetSymbolAttrib){this.diagram.onGetSymbolAttrib=this.callbacks.onGetSymbolAttrib;}
if(this.callbacks&&this.callbacks.onDeleteSymbol){this.diagram.onDeleteSymbol=this.callbacks.onDeleteSymbol;}
if(this.callbacks&&this.callbacks.onCreatedSymbol){this.diagram.onCreatedSymbol=this.callbacks.onCreatedSymbol;}
if(this.callbacks&&this.callbacks.onCreatedActivity){this.diagram.onCreatedActivity=this.callbacks.onCreatedActivity;}
if(this.callbacks&&this.callbacks.onAddedParallelGateway){this.diagram.onAddedParallelGateway=this.callbacks.onAddedParallelGateway;}
if(this.callbacks&&this.callbacks.getTooltip){this.diagram.getTooltip=this.callbacks.getTooltip;}
var dispSymbols={};function getDisplaySymbol(s){if(dispSymbols[s.key]){return dispSymbols[s.key];}
switch(s.symbolType){case'start':dispSymbols[s.key]=new Start(diagram,s);break;case'end':dispSymbols[s.key]=new End(diagram,s);break;case'activity':dispSymbols[s.key]=new Activity(diagram,s);break;case'split':case'join':dispSymbols[s.key]=new GatewayParallel(diagram,s);break;case'xor':dispSymbols[s.key]=new GatewayXOR(diagram,s);break;default:return new Error('Wrong symbol type!');}
return dispSymbols[s.key];}
(function constructChart(s,prevDisp,prev){var dispSymb=getDisplaySymbol(s);dispSymb.dropped=true;if(self.start===s){diagram.startWith(dispSymb);}else if(prevDisp&&prev&&!prevDisp.pathOk){if(prevDisp instanceof(GatewayXOR)){if(prev.yes===s){prevDisp.yes(dispSymb);}
if(prev.no===s){prevDisp.no(dispSymb);}}else if(prevDisp instanceof(GatewayParallel)){prevDisp.addThen(dispSymb);}
else{prevDisp.then(dispSymb);}}
if(dispSymb.pathOk){return dispSymb;}
if(dispSymb instanceof(GatewayXOR)){if(s.yes){constructChart(s.yes,dispSymb,s);}
if(s.no){constructChart(s.no,dispSymb,s);}}else if(dispSymb instanceof(GatewayParallel)){constructChart(s.next,dispSymb,s);var nextIdx=1;while(s['next'+nextIdx]!=undefined){constructChart(s['next'+nextIdx++],dispSymb,s);};}
else if(s.next){constructChart(s.next,dispSymb,s);}
return dispSymb;})(this.start);diagram.render();var outOfFlowX=0;for(var sKey in this.symbols){var s=this.symbols[sKey];var dispSymb=getDisplaySymbol(s);if(!dispSymb.isPositioned){var bb=dispSymb.group.getBBox();if(outOfFlowX==0)
outOfFlowX=bb.width/2;dispSymb.setX(outOfFlowX);outOfFlowX+=bb.width;dispSymb.setY(diagram.paper.height-(bb.height*2));}}},clean:function(){this.diagram.clean();},setCallbacks:function(callbacks){this.callbacks=callbacks;},addSymbol:function(type,text,key,addPoint){var symbol={key:key,symbolType:type,text:text,link:null,target:null,symbolstate:null};this.symbols[symbol.key]=symbol;var outOfFlowX=100;function getDisplaySymbol(chart,s){switch(s.symbolType){case'start':return new Start(chart.diagram,s);case'end':return new End(chart.diagram,s);case'activity':return new Activity(chart.diagram,s);case'split':case'join':return new GatewayParallel(chart.diagram,s);case'xor':return new GatewayXOR(chart.diagram,s);default:return new Error('Wrong symbol type!');}}
var dispSymb=getDisplaySymbol(this,symbol);if(!addPoint){var bb=dispSymb.group.getBBox();if(outOfFlowX==0)
outOfFlowX=bb.width/2;outOfFlowX+=bb.width;addPoint=new{x:outOfFlowX,y:this.diagram.paper.height-(bb.height*2)}}
if(!dispSymb.isPositioned){dispSymb.setX(addPoint.x);dispSymb.setY(addPoint.y);}
this.diagram.handle(dispSymb);return dispSymb;},getFlowDefinition:function(){var flowDefn="";for(i=0;i<this.diagram.symbols.length;i++){var symbol=this.diagram.symbols[i];if(symbol instanceof(GatewayXOR)){if(symbol.yes!=undefined)
flowDefn+=symbol.key+"(Yes)->"+symbol.yes_symbol.key+"\n";if(symbol.no!=undefined)
flowDefn+=symbol.key+"(No)->"+symbol.no_symbol.key+"\n";}
else if(symbol.connectionsOut){for(conIdx=0;conIdx<symbol.connectionsOut.length;conIdx++){var thisConnection=symbol.connectionsOut[conIdx];flowDefn+=symbol.key+"->"+thisConnection.dest.key+"\n";}}}
return flowDefn;},getPositionDefinition:function(){var posDefn=[];for(i=0;i<this.diagram.symbols.length;i++){var symbol=this.diagram.symbols[i];var pos={id:symbol.key,x:symbol.getX(),y:symbol.getY(),width:symbol.width,height:symbol.height};posDefn.push(pos);}
return posDefn;}};var lines=[];var prevBreak=0;for(var i0=1,i0len=input.length;i0<i0len;i0++){if(input[i0]==='\n'&&input[i0-1]!=='\\'){var line0=input.substring(prevBreak,i0);prevBreak=i0+1;lines.push(line0.replace(/\\\n/g,'\n'));}}
if(prevBreak<input.length){lines.push(input.substr(prevBreak));}
for(var l=1,len=lines.length;l<len;){var currentLine=lines[l];if(currentLine.indexOf(':')<0&&currentLine.indexOf('(')<0&&currentLine.indexOf(')')<0&&currentLine.indexOf('->')<0&&currentLine.indexOf('=>')<0){lines[l-1]+='\n'+currentLine;lines.splice(l,1);len--;}else{l++;}}
function getSymbol(s){var startIndex=s.indexOf('(')+1;var endIndex=s.indexOf(')');if(startIndex>=0&&endIndex>=0){return chart.symbols[s.substring(0,startIndex-1)];}
return chart.symbols[s];}
function getNextPath(s){var next='next';var startIndex=s.indexOf('(')+1;var endIndex=s.indexOf(')');if(startIndex>=0&&endIndex>=0){next=flowSymb.substring(startIndex,endIndex);if(next.indexOf(',')<0){if(next!=='yes'&&next!=='no'){next='next, '+next;}}}
return next;}
while(lines.length>0){var line=lines.splice(0,1)[0];if(line.indexOf('=>')>=0){var parts=line.split('=>');var symbol={key:parts[0],symbolType:parts[1],text:null,link:null,target:null,symbolstate:null,rowHint:-1,colHint:-1,stepPosX:-1,stepPosY:-1};var sub;if(symbol.symbolType.indexOf(':')>=0){sub=symbol.symbolType.split(':');symbol.symbolType=sub[0];symbol.text=sub[1];}
if(symbol.text&&symbol.text.indexOf(':>')>=0){sub=symbol.text.split(':>');symbol.text=sub[0];symbol.link=sub[1];}else if(symbol.symbolType.indexOf(':>')>=0){sub=symbol.symbolType.split(':>');symbol.symbolType=sub[0];symbol.link=sub[1];}
if(symbol.symbolType.indexOf('\n')>=0){symbol.symbolType=symbol.symbolType.split('\n')[0];}
if(symbol.link){var startIndex=symbol.link.indexOf('[')+1;var endIndex=symbol.link.indexOf(']');if(startIndex>=0&&endIndex>=0){symbol.target=symbol.link.substring(startIndex,endIndex);symbol.link=symbol.link.substring(0,startIndex-1);}}
if(symbol.text){if(symbol.text.indexOf('|')>=0){var txtAndState=symbol.text.split('|');symbol.text=txtAndState[0];symbol.symbolstate=txtAndState[1].trim();}}
chart.symbols[symbol.key]=symbol;}else if(line.indexOf('->')>=0){var flowSymbols=line.split('->');for(var i=0,lenS=flowSymbols.length;i<lenS;i++){var flowSymb=flowSymbols[i];var realSymb=getSymbol(flowSymb);var next=getNextPath(flowSymb);var direction=null;if(next.indexOf(',')>=0){var condOpt=next.split(',');next=condOpt[0];direction=condOpt[1].trim();}
if(!chart.start&&realSymb.symbolType=='start'){chart.start=realSymb;}
if(i+1<lenS){var nextSymb=flowSymbols[i+1].trim();if(realSymb[next]!=null){var nextIdx=1;while(realSymb[next+nextIdx]!=null)
++nextIdx;next=next+nextIdx;}
realSymb[next]=getSymbol(nextSymb);realSymb['direction_'+next]=direction;direction=null;}}}else if(line.indexOf('(')>0&&currentLine.indexOf(')')>0){var realSymb=getSymbol(line);var startIndex=line.indexOf('(')+1;var endIndex=line.indexOf(')');if(startIndex>=0&&endIndex>=0){if(line[startIndex]=='{'){var posObj=JSON.parse(line.substring(startIndex,endIndex));realSymb.stepPosX=posObj.x;realSymb.stepPosY=posObj.y;}
else{var coords=line.substring(startIndex,endIndex).split(',');if(coords.length==2){realSymb.rowHint=parseInt(coords[0]);realSymb.colHint=parseInt(coords[1]);}}}}}
return chart;}
bpmndiag.parse=parse;})();