e;e++)i=o[e],u.set(i,u.get(i)+s)}return u},_getLeftWing:function(){var t={value:null},e=this.computeClasses(t,1);return this.nodeLeftClass=t.value,e},_getRightWing:function(){var t={value:null},e=this.computeClasses(t,-1);return this.nodeRightClass=t.value,e},computeClasses:function(t,e){var i,n,o,s,r,a,h,c,l,u=0,f=t.value=new d;for(i=0;this.layers.length>i;++i)for(u=i,n=this.layers[i],o=1===e?0:n.length-1;o>=0&&n.length>o;o+=e)if(s=n[o],f.containsKey(s))u=f.get(s);else if(f.set(s,u),s.isVirtual)for(r=this._nodesInLink(s),a=0;r.length>a;a++)h=r[a],f.set(h,u);for(c=[],l=0;this.layers.length>l;l++)c.push(null);return f.forEach(function(t,e){null===c[e]&&(c[e]=[]),c[e].push(t)}),c},_isVerticalLayout:function(){return"up"===this.options.subtype.toLowerCase()||"down"===this.options.subtype.toLowerCase()||"vertical"===this.options.subtype.toLowerCase()},_isHorizontalLayout:function(){return"right"===this.options.subtype.toLowerCase()||"left"===this.options.subtype.toLowerCase()||"horizontal"===this.options.subtype.toLowerCase()},_isIncreasingLayout:function(){return"right"===this.options.subtype.toLowerCase()||"down"===this.options.subtype.toLowerCase()},_moveThingsAround:function(){function t(t,e){var i,n,o=Number.MIN_VALUE;for(i=0;t.length>i;++i)n=t[i],o=e._isVerticalLayout()?Math.max(o,n.height):Math.max(o,n.width);return o}var e,i,n,o,s,r,a,h,c,l,u,p,g,m,_,v,y,w,x,C,b,S,k,T,M,D,P;for(i=0;this.layers.length>i;++i)o=this.layers[i],o.sort(this._gridPositionComparer);for(this.minDistances=[],i=0;this.layers.length>i;++i)for(o=this.layers[i],this.minDistances[i]=[],s=0;o.length>s;++s)n=o[s],n.layerIndex=s,this.minDistances[i][s]=this.options.nodeDistance,o.length-1>s&&(this.minDistances[i][s]+=this._isVerticalLayout()?(n.width+o[s+1].width)/2:(n.height+o[s+1].height)/2);for(this.downNodes=new d,this.upNodes=new d,f.forEach(this.graph.nodes,function(t){this.downNodes.set(t,[]),this.upNodes.set(t,[])},this),f.forEach(this.graph.links,function(t){var e=t.source,i=t.target,n=null,o=null;e.layer>i.layer?(n=t.source,o=t.target):(o=t.source,n=t.target),this.downNodes.get(o).push(n),this.upNodes.get(n).push(o)},this),this.downNodes.forEachValue(function(t){t.sort(this._gridPositionComparer)},this),this.upNodes.forEachValue(function(t){t.sort(this._gridPositionComparer)},this),i=0;this.layers.length-1>i;++i)for(o=this.layers[i],r=0;o.length-1>r;r++)if(a=o[r],a.isVirtual&&(h=this.downNodes.get(a)[0],h.isVirtual))for(s=r+1;o.length>s;++s)n=o[s],n.isVirtual&&(c=this.downNodes.get(n)[0],c.isVirtual&&h.gridPosition>c.gridPosition&&(l=h.gridPosition,h.gridPosition=c.gridPosition,c.gridPosition=l,u=h.layerIndex,p=c.layerIndex,this.layers[i+1][u]=c,this.layers[i+1][p]=h,h.layerIndex=p,c.layerIndex=u));for(g=this._getLeftWing(),m=this._getRightWing(),_=this.placeLeftToRight(g),v=this.placeRightToLeft(m),y=new d,f.forEach(this.graph.nodes,function(t){y.set(t,(_.get(t)+v.get(t))/2)}),w=new d,x=new d,i=0;this.layers.length>i;++i)for(o=this.layers[i],C=-1,b=-1,s=0;o.length>s;++s)n=o[s],w.set(n,0),x.set(n,!1),n.isVirtual&&(-1===C?C=s:C===s-1?C=s:(b=s,w.set(o[C],0),y.get(n)-y.get(o[C])===this.getMinDist(o[C],n)?x.set(o[C],!0):x.set(o[C],!1),C=s));for(S=[1,-1],f.forEach(S,function(t){var i,n,o,s,r,a,h,c=1===t?0:this.layers.length-1;for(i=c;i>=0&&this.layers.length>i;i+=t){if(n=this.layers[i],o=this._firstVirtualNode(n),s=null,r=null,-1!==o)for(s=n[o],r=[],e=0;o>e;e++)r.push(n[e]);else s=null,r=n;if(r.length>0){for(this._sequencer(y,null,s,t,r),e=0;r.length-1>e;++e)this.setMinDist(r[e],r[e+1],y.get(r[e+1])-y.get(r[e]));s&&this.setMinDist(r[r.length-1],s,y.get(s)-y.get(r[r.length-1]))}for(;s;){if(a=this.nextVirtualNode(n,s)){if(w.get(s)===t){for(o=s.layerIndex,h=a.layerIndex,r=[],e=o+1;h>e;e++)r.push(n[e]);r.length>0&&this._sequencer(y,s,a,t,r),x.set(s,!0)}}else{for(o=s.layerIndex,r=[],e=o+1;n.length>e;e++)r.push(n[e]);if(r.length>0){for(this._sequencer(y,s,null,t,r),e=0;r.length-1>e;++e)this.setMinDist(r[e],r[e+1],y.get(r[e+1])-y.get(r[e]));this.setMinDist(s,r[0],y.get(r[0])-y.get(s))}}s=a}this.adjustDirections(i,t,w,x)}},this),k=this._isIncreasingLayout()?0:this.layers.length-1,T=function(t,e){return e._isIncreasingLayout()?e.layers.length>t:t>=0},M=this._isIncreasingLayout()?1:-1,D=0,e=k;T(e,this);e+=M){for(o=this.layers[e],P=t(o,this),s=0;o.length>s;++s)n=o[s],this._isVerticalLayout()?(n.x=y.get(n),n.y=D+P/2):(n.x=D+P/2,n.y=y.get(n));D+=this.options.layerSeparation+P}},adjustDirections:function(t,e,i,n){var o,s,r,a,h,c,d,l,u,f,p,g,m,_;if(!(0>t+e||t+e>=this.layers.length))for(o=null,s=null,r=this.layers[t+e],a=0;r.length>a;++a)if(h=r[a],h.isVirtual&&(c=this.getNeighborOnLayer(h,t),c.isVirtual)){if(o){for(d=n.get(s),l=this.layers[t],u=s.layerIndex,f=c.layerIndex,p=u+1;f>p;++p)l[p].isVirtual&&(d=d&&n.get(l[p]));if(d)for(i.set(o,e),g=o.layerIndex,m=h.layerIndex,_=g+1;m>_;++_)r[_].isVirtual&&i.set(r[_],e)}o=h,s=c}},getNeighborOnLayer:function(t,e){
var i=this.upNodes.get(t)[0];return i.layer===e?i:(i=this.downNodes.get(t)[0],i.layer===e?i:null)},_sequencer:function(t,e,i,n,o){if(1===o.length&&this._sequenceSingle(t,e,i,n,o[0]),o.length>1){var s=o.length,r=this.intDiv(s,2);this._sequencer(t,e,i,n,o.slice(0,r)),this._sequencer(t,e,i,n,o.slice(r)),this.combineSequences(t,e,i,n,o)}},_sequenceSingle:function(t,e,i,n,o){var s=-1===n?this.downNodes.get(o):this.upNodes.get(o),r=s.length;0!==r&&(r%2===1?t.set(o,t.get(s[this.intDiv(r,2)])):t.set(o,(t.get(s[this.intDiv(r,2)-1])+t.get(s[this.intDiv(r,2)]))/2),e&&t.set(o,Math.max(t.get(o),t.get(e)+this.getMinDist(e,o))),i&&t.set(o,Math.min(t.get(o),t.get(i)-this.getMinDist(o,i))))},combineSequences:function(t,e,i,n,o){var s,r,a,h,c,d,l,u,f,p,g=o.length,m=this.intDiv(g,2),_=[];for(s=0;m>s;++s){for(r=0,h=-1===n?this.downNodes.get(o[s]):this.upNodes.get(o[s]),a=0;h.length>a;++a)c=h[a],t.get(c)>=t.get(o[s])?r++:(r--,_.push({k:t.get(c)+this.getMinDist(o[s],o[m-1]),v:2}));_.push({k:t.get(o[s])+this.getMinDist(o[s],o[m-1]),v:r})}for(e&&_.push({k:t.get(e)+this.getMinDist(e,o[m-1]),v:Number.MAX_VALUE}),_.sort(this._positionDescendingComparer),l=[],s=m;g>s;++s){for(r=0,h=-1===n?this.downNodes.get(o[s]):this.upNodes.get(o[s]),a=0;h.length>a;++a)c=h[a],t.get(c)<=t.get(o[s])?r++:(r--,l.push({k:t.get(c)-this.getMinDist(o[s],o[m]),v:2}));l.push({k:t.get(o[s])-this.getMinDist(o[s],o[m]),v:r})}for(i&&l.push({k:t.get(i)-this.getMinDist(i,o[m]),v:Number.MAX_VALUE}),l.sort(this._positionAscendingComparer),u=0,f=0,p=this.getMinDist(o[m-1],o[m]);t.get(o[m])-t.get(o[m-1])u){if(0===_.length){t.set(o[m-1],t.get(o[m])-p);break}d=_.shift(),u+=d.v,t.set(o[m-1],d.k),t.set(o[m-1],Math.max(t.get(o[m-1]),t.get(o[m])-p))}else{if(0===l.length){t.set(o[m],t.get(o[m-1])+p);break}d=l.shift(),f+=d.v,t.set(o[m],d.k),t.set(o[m],Math.min(t.get(o[m]),t.get(o[m-1])+p))}for(s=m-2;s>=0;s--)t.set(o[s],Math.min(t.get(o[s]),t.get(o[m-1])-this.getMinDist(o[s],o[m-1])));for(s=m+1;g>s;s++)t.set(o[s],Math.max(t.get(o[s]),t.get(o[m])+this.getMinDist(o[s],o[m])))},placeLeft:function(t,e,i){var n=Number.NEGATIVE_INFINITY;f.forEach(this._getComposite(t),function(t){var o=this.leftSibling(t);o&&this.nodeLeftClass.get(o)===this.nodeLeftClass.get(t)&&(e.containsKey(o)||this.placeLeft(o,e,i),n=Math.max(n,e.get(o)+this.getMinDist(o,t)))},this),n===Number.NEGATIVE_INFINITY&&(n=0),f.forEach(this._getComposite(t),function(t){e.set(t,n)})},placeRight:function(t,e,i){var n=Number.POSITIVE_INFINITY;f.forEach(this._getComposite(t),function(t){var o=this.rightSibling(t);o&&this.nodeRightClass.get(o)===this.nodeRightClass.get(t)&&(e.containsKey(o)||this.placeRight(o,e,i),n=Math.min(n,e.get(o)-this.getMinDist(t,o)))},this),n===Number.POSITIVE_INFINITY&&(n=0),f.forEach(this._getComposite(t),function(t){e.set(t,n)})},leftSibling:function(t){var e=this.layers[t.layer],i=t.layerIndex;return 0===i?null:e[i-1]},rightSibling:function(t){var e=this.layers[t.layer],i=t.layerIndex;return i===e.length-1?null:e[i+1]},_getComposite:function(t){return t.isVirtual?this._nodesInLink(t):[t]},arrangeNodes:function(){var t,e,i,n,o,s,r,a;for(e=0;this.layers.length>e;e++)for(n=this.layers[e],i=0;n.length>i;i++)o=n[i],o.upstreamPriority=o.upstreamLinkCount,o.downstreamPriority=o.downstreamLinkCount;for(s=2,r=0;s>r;r++){for(t=this.layers.length-1;t>=1;t--)this.layoutLayer(!1,t);for(t=0;this.layers.length-1>t;t++)this.layoutLayer(!0,t)}for(a=Number.MAX_VALUE,e=0;this.layers.length>e;e++)for(n=this.layers[e],i=0;n.length>i;i++)o=n[i],a=Math.min(a,o.gridPosition);if(0>a)for(e=0;this.layers.length>e;e++)for(n=this.layers[e],i=0;n.length>i;i++)o=n[i],o.gridPosition=o.gridPosition-a},layoutLayer:function(t,e){var i,n,o,s;for(n=t?this.layers[i=e+1]:this.layers[i=e-1],o=[],s=0;n.length>s;s++)o.push(n[s]);o.sort(function(t,e){var i=(t.upstreamPriority+t.downstreamPriority)/2,n=(e.upstreamPriority+e.downstreamPriority)/2;return Math.abs(i-n)<1e-4?0:n>i?1:-1}),f.forEach(o,function(t){var e=t.gridPosition,i=this.calcBaryCenter(t),o=(t.upstreamPriority+t.downstreamPriority)/2;if(!(Math.abs(e-i)<1e-4||Math.abs(e-i)<.2501))if(i>e)for(;i>e&&this.moveRight(t,n,o);)e=t.gridPosition;else for(;e>i&&this.moveLeft(t,n,o);)e=t.gridPosition},this),i>0&&this.calcDownData(i-1),this.layers.length-1>i&&this.calcUpData(i+1)},moveRight:function(t,e,i){var n,o,s=f.indexOf(e,t);return s===e.length-1?(t.gridPosition=t.gridPosition+.5,!0):(n=e[s+1],o=(n.upstreamPriority+n.downstreamPriority)/2,n.gridPosition>t.gridPosition+1?(t.gridPosition=t.gridPosition+.5,!0):o>i||Math.abs(o-i)<1e-4?!1:this.moveRight(n,e,i)?(t.gridPosition=t.gridPosition+.5,!0):!1)},moveLeft:function(t,e,i){var n,o,s=f.indexOf(e,t);return 0===s?(t.gridPosition=t.gridPosition-.5,!0):(n=e[s-1],o=(n.upstreamPriority+n.downstreamPriority)/2,t.gridPosition-1>n.gridPosition?(t.gridPosition=t.gridPosition-.5,!0):o>i||Math.abs(o-i)<1e-4?!1:this.moveLeft(n,e,i)?(t.gridPosition=t.gridPosition-.5,!0):!1)},mapVirtualNode:function(t,e){this.nodeToLinkMap.set(t,e),this.linkToNodeMap.containsKey(e)||this.linkToNodeMap.set(e,[]),this.linkToNodeMap.get(e).push(t)},_nodesInLink:function(t){return this.linkToNodeMap.get(this.nodeToLinkMap.get(t))},_dummify:function(){var t,e,i,n,o,a,h,c,l,u,p,g,m,_,v,y,w,x,C,b;for(this.linkToNodeMap=new d,this.nodeToLinkMap=new d,l=this.graph.links.slice(0),u=this.layers,p=function(t,e,i){u[t].linksTo[e]=u[t].linksTo[e]||[],u[t].linksTo[e].push(i)},c=0;l.length>c;c++)if(g=l[c],m=g.source,_=g.target,v=m.layer,y=_.layer,w=m.gridPosition,x=_.gridPosition,C=(x-w)/Math.abs(y-v),b=m,v-y>1){for(h=v-1;h>y;h--){for(i=new s,i.x=m.x,i.y=m.y,i.width=m.width/100,i.height=m.height/100,t=u[h],e=(h-y)*C+w,e>t.length&&(e=t.length),w>=u[v].length-1&&x>=u[y].length-1?e=t.length:0===w&&0===x&&(e=0),i.layer=h,i.uBaryCenter=0,i.dBaryCenter=0,i.upstreamLinkCount=0,i.downstreamLinkCount=0,i.gridPosition=e,i.isVirtual=!0,f.insert(t,i,e),o=e+1;t.length>o;o++)n=t[o],n.gridPosition=n.gridPosition+1;a=new r(b,i),a.depthOfDumminess=0,p(h-1,h,a),b=i,this.graph._addNode(i),this.graph.addLink(a),i.index=this.graph.nodes.length-1,this.mapVirtualNode(i,g)}p(y-1,y,a),g.changeSource(b),g.depthOfDumminess=v-y-1}else if(-1>v-y){for(h=v+1;y>h;h++){for(i=new s,i.x=m.x,i.y=m.y,i.width=m.width/100,i.height=m.height/100,t=u[h],e=(h-v)*C+w,e>t.length&&(e=t.length),w>=u[v].length-1&&x>=u[y].length-1?e=t.length:0===w&&0===x&&(e=0),i.layer=h,i.uBaryCenter=0,i.dBaryCenter=0,i.upstreamLinkCount=0,i.downstreamLinkCount=0,i.gridPosition=e,i.isVirtual=!0,e&=e,f.insert(t,i,e),o=e+1;t.length>o;o++)n=t[o],n.gridPosition=n.gridPosition+1;a=new r(b,i),a.depthOfDumminess=0,p(h-1,h,a),b=i,this.graph._addNode(i),this.graph.addLink(a),i.index=this.graph.nodes.length-1,this.mapVirtualNode(i,g)}p(y-1,y,g),g.changeSource(b),g.depthOfDumminess=y-v-1}else p(v,y,g)},_dedummify:function(){for(var t,e,i,n,o,s,r,a,h=!0;h;)for(h=!1,t=0;this.graph.links.length>t;t++)if(e=this.graph.links[t],e.depthOfDumminess){for(i=[],i.unshift({x:e.target.x,y:e.target.y}),i.unshift({x:e.source.x,y:e.source.y}),n=e,o=e.depthOfDumminess,s=0;o>s;s++)r=n.source,a=r.incoming[0],i.unshift({x:a.source.x,y:a.source.y}),n=a;e.changeSource(n.source),e.depthOfDumminess=0,i.length>2?(i.splice(0,1),i.splice(i.length-1),e.points=i):e.points=[],h=!0;break}},_optimizeCrossings:function(){for(var t,e=-1,i=3,n=0;0!==e&&!(n++>i);){for(e=0,t=this.layers.length-1;t>=1;t--)e+=this.optimizeLayerCrossings(!1,t);for(t=0;this.layers.length-1>t;t++)e+=this.optimizeLayerCrossings(!0,t)}},calcUpData:function(t){var e,i,n,o,s,r,a,h,c;if(0!==t){for(e=this.layers[t],s=new l,r=this.layers[t-1],i=0;r.length>i;i++)s.add(r[i]);for(i=0;e.length>i;i++){for(a=e[i],h=0,c=0,n=0;a.incoming.length>n;n++)o=a.incoming[n],s.contains(o.source)&&(c++,h+=o.source.gridPosition);for(n=0;a.outgoing.length>n;n++)o=a.outgoing[n],s.contains(o.target)&&(c++,h+=o.target.gridPosition);c>0?(a.uBaryCenter=h/c,a.upstreamLinkCount=c):(a.uBaryCenter=i,a.upstreamLinkCount=0)}}},calcDownData:function(t){var e,i,n,o,s,r,a,h,c;if(t!==this.layers.length-1){for(e=this.layers[t],s=new l,r=this.layers[t+1],i=0;r.length>i;i++)s.add(r[i]);for(i=0;e.length>i;i++){for(a=e[i],h=0,c=0,n=0;a.incoming.length>n;n++)o=a.incoming[n],s.contains(o.source)&&(c++,h+=o.source.gridPosition);for(n=0;a.outgoing.length>n;n++)o=a.outgoing[n],s.contains(o.target)&&(c++,h+=o.target.gridPosition);c>0?(a.dBaryCenter=h/c,a.downstreamLinkCount=c):(a.dBaryCenter=i,a.downstreamLinkCount=0)}}},optimizeLayerCrossings:function(t,e){var i,n,o,s,r,a,h,c;for(n=t?this.layers[i=e+1]:this.layers[i=e-1],o=n.slice(0),t?this.calcUpData(i):this.calcDownData(i),s=this,n.sort(function(t,e){var i,n=s.calcBaryCenter(t),o=s.calcBaryCenter(e);return Math.abs(n-o)<1e-4?t.degree()===e.degree()?s.compareByIndex(t,e):t.degree()0?-1:0>i?1:s.compareByIndex(t,e))}),a=0,r=0;n.length>r;r++)n[r]!==o[r]&&a++;if(a>0)for(h=0,r=0;n.length>r;r++)c=n[r],c.gridPosition=h++;return a},_swapPairs:function(){for(var t,e,i,n,o,s,r,a,h,c,d,l,u,f,p,g,m,_=this.options.layeredIterations,v=0;;){if(v++>_)break;for(t=1>=v%4,e=v%4===1,i=t?0:this.layers.length-1;t?this.layers.length-1>=i:i>=0;i+=t?1:-1){for(n=this.layers[i],o=!1,s=!0,r=0,a=0;n.length-1>a;a++)h=0,c=0,d=0,s?(0!==i&&(h=this.countLinksCrossingBetweenTwoLayers(i-1,i)),i!==this.layers.length-1&&(c=this.countLinksCrossingBetweenTwoLayers(i,i+1)),t?h*=2:c*=2,d=h+c):d=r,0!==d&&(l=n[a],u=n[a+1],f=l.gridPosition,p=u.gridPosition,n[a]=u,n[a+1]=l,l.gridPosition=p,u.gridPosition=f,h=0,0!==i&&(h=this.countLinksCrossingBetweenTwoLayers(i-1,i)),c=0,i!==this.layers.length-1&&(c=this.countLinksCrossingBetweenTwoLayers(i,i+1)),t?h*=2:c*=2,g=h+c,m=!1,m=e?g>=d:g>d,m?(l=n[a],u=n[a+1],f=l.gridPosition,p=u.gridPosition,n[a]=u,n[a+1]=l,l.gridPosition=p,u.gridPosition=f,r=d,s=!1):(o=!0,s=!0));o&&(i!==this.layers.length-1&&this.calcUpData(i+1),0!==i&&this.calcDownData(i-1))}}},countLinksCrossingBetweenTwoLayers:function(t,e){var i,n,o,s,r,a,h,c,d,l,u,f,p=this.layers[t].linksTo[e],g=0,m=p.length;for(h=0;m>h;h++)for(i=p[h],c=h+1;m>c;c++)n=p[c],i.target.layer===e?(o=i.source,s=i.target):(o=i.target,s=i.source),n.target.layer===e?(r=n.source,a=n.target):(r=n.target,a=n.source),d=o.gridPosition,l=s.gridPosition,u=r.gridPosition,f=a.gridPosition,0>(d-u)*(l-f)&&g++;return g},calcBaryCenter:function(t){var e=t.upstreamLinkCount,i=t.downstreamLinkCount,n=t.uBaryCenter,o=t.dBaryCenter;return e>0&&i>0?(n+o)/2:e>0?n:i>0?o:0},_gridPositionComparer:function(t,e){return e.gridPosition>t.gridPosition?-1:t.gridPosition>e.gridPosition?1:0},_positionAscendingComparer:function(t,e){return e.k>t.k?-1:t.k>e.k?1:0},_positionDescendingComparer:function(t,e){return e.k>t.k?1:t.k>e.k?-1:0},_firstVirtualNode:function(t){for(var e=0;t.length>e;e++)if(t[e].isVirtual)return e;return-1},compareByIndex:function(t,e){var i=t.index,n=e.index;return n>i?1:i>n?-1:0},intDiv:function(t,e){return(t-t%e)/e},nextVirtualNode:function(t,e){var i,n=e.layerIndex;for(i=n+1;t.length>i;++i)if(t[i].isVirtual)return t[i];return null}}),k=i.Class.extend({init:function(t,e){if(f.isUndefined(t))throw"No diagram given";this.diagram=t,this.nodeMap=new d,this.linkMap=new d,this.capture(e?e:t)},capture:function(t){var e,i,o,s,r,a,h,d,l;if(t instanceof n.Graph){for(s=0;t.nodes.length>s;s++)e=t.nodes[s],o=e.associatedShape,this.nodeMap.set(o.visual.id,new c(e.x,e.y,e.width,e.height));for(s=0;t.links.length>s;s++)a=t.links[s],r=a.associatedConnection,this.linkMap.set(r.visual.id,a.points())}else if(t instanceof Array)for(i=t,s=0;i.length>s;s++)e=i[s],o=e.associatedShape,o&&this.nodeMap.set(o.visual.id,new c(e.x,e.y,e.width,e.height));else if(t.hasOwnProperty("links")&&t.hasOwnProperty("nodes")){for(i=t.nodes,h=t.links,s=0;i.length>s;s++)e=i[s],o=e.associatedShape,o&&this.nodeMap.set(o.visual.id,new c(e.x,e.y,e.width,e.height));for(s=0;h.length>s;s++)a=h[s],r=a.associatedConnection,r&&this.linkMap.set(r.visual.id,a.points)}else{for(d=this.diagram.shapes,l=this.diagram.connections,s=0;d.length>s;s++)o=d[s],this.nodeMap.set(o.visual.id,o.bounds());for(s=0;l.length>s;s++)r=l[s],this.linkMap.set(r.visual.id,r.points())}}});a(n,{init:function(t){i.init(t,n.ui)},SpringLayout:x,TreeLayout:b,GraphAdapter:w,LayeredLayout:S,LayoutBase:y,LayoutState:k})}(window.kendo.jQuery)},"function"==typeof define&&define.amd?define:function(t,e,i){(i||e)()}),function(t,define){define("dataviz/diagram/dom.min",["kendo.data.min","kendo.draganddrop.min","kendo.toolbar.min","kendo.editable.min","kendo.window.min","kendo.dropdownlist.min","kendo.dataviz.core.min","kendo.dataviz.themes.min","dataviz/diagram/svg.min","dataviz/diagram/services.min","dataviz/diagram/layout.min"],t)}(function(){!function(t,e){function i(t){var e=t.originalEvent,i=0;return e.wheelDelta?(i=-e.wheelDelta/40,i=i>0?vt.ceil(i):vt.floor(i)):e.detail&&(i=e.detail),i}function n(t){return t.options.name.toLowerCase()===It.toLowerCase()}function o(t,e){var i,o,s,r,a=Rt,h=e.connectors;for(o=0;h.length>o;o++)s=h[o],n(s)||(r=t.distanceTo(s.position()),a>r&&(a=r,i=s));return i}function s(t,e){var i,n,o,s=[],r=t.drawingContainer().children,a=r.length;for(i=0;e.length>i;i++)for(n=e[i],o=0;a>o;o++)if(r[o]==n.drawingContainer()){s.push(o);break}return s}function r(t){var e={};return t=t||{},ft(t.text)&&null!==t.text&&(e.text=t.text),ft(t.x)&&null!==t.x&&(e.x=t.x),ft(t.y)&&null!==t.y&&(e.y=t.y),ft(t.width)&&null!==t.width&&(e.width=t.width),ft(t.height)&&null!==t.height&&(e.height=t.height),ft(t.type)&&null!==t.type&&(e.type=t.type),e}function a(t){var e={};return t=t||{},ft(t.text)&&null!==t.text&&(e.content=t.text),ft(t.type)&&null!==t.type&&(e.type=t.type),ft(t.from)&&null!==t.from&&(e.from=t.from),ft(t.fromConnector)&&null!==t.fromConnector&&(e.fromConnector=t.fromConnector),ft(t.fromX)&&null!==t.fromX&&(e.fromX=t.fromX),ft(t.fromY)&&null!==t.fromY&&(e.fromY=t.fromY),ft(t.to)&&null!==t.to&&(e.to=t.to),ft(t.toConnector)&&null!==t.toConnector&&(e.toConnector=t.toConnector),ft(t.toX)&&null!==t.toX&&(e.toX=t.toX),ft(t.toY)&&null!==t.toY&&(e.toY=t.toY),e}function h(e,i){var n,o=this.dataSource.reader.model;o&&(n=o.fn.fields.text?"text":o.idField,t("").appendTo(e).kendoDropDownList({dataValueField:o.idField,dataTextField:n,dataSource:this.dataSource.data().toJSON(),optionLabel:" ",valuePrimitive:!0}))}function c(t){this.dataItem=t,this.callbacks=[]}function d(){this.items={}}function l(t){var e=t;return t instanceof kendo.data.Model&&(e=t.toJSON(),e[t.idField]=t._defaultId),e}function u(t){var e,i,n=[],o=[];for(i=0;t.length>i;i++)e=t[i],e instanceof w?o.push(e):n.push(e);return{shapes:o,connections:n}}function f(t,e){return t.reader.model?new t.reader.model(e):new kendo.data.ObservableObject(e)}function p(t,e){ft(e[t])&&e.set(t,null)}function g(t,e,i){var n,o;for(o=0;i.length>o;o++)n=i[o],e&&!ft(e[n])&&(e[n]=t[n])}function m(t){var e=t.drawingContainer().clippedBBox(null);(0!==e.origin.x||0!==e.origin.y)&&t.position(-e.origin.x,-e.origin.y)}var _,v,y,w,x,C,b,S,k,T,M,D,P=kendo.dataviz,I=kendo.drawing,L=kendo.geometry,E=P.diagram,z=kendo.ui.Widget,N=kendo.Class,R=t.proxy,B=kendo.deepExtend,A=t.extend,O=kendo.data.HierarchicalDataSource,U=E.Canvas,V=E.Group,H=E.Rectangle,F=E.Circle,G=E.CompositeTransform,q=E.Rect,K=E.Path,W=E.DeleteShapeUnit,X=E.DeleteConnectionUnit,j=E.TextBlock,Y=E.Image,Q=E.Point,J=E.Intersect,Z=E.ConnectionEditAdorner,$=E.UndoRedoService,tt=E.ToolService,et=E.Selector,it=E.ResizingAdorner,nt=E.ConnectorsAdorner,ot=E.Cursors,st=E.Utils,rt=kendo.Observable,at=E.ToBackUnit,ht=E.ToFrontUnit,ct=E.PolylineRouter,dt=E.CascadingRouter,lt=st.isUndefined,ut=st.isDefined,ft=kendo.util.defined,pt=t.isArray,gt=kendo.isFunction,mt=st.isString,_t=t.isPlainObject,vt=Math,yt=".kendoDiagram",wt="cascading",xt="itemBoundsChange",Ct="change",bt="click",St="drag",kt="dragEnd",Tt="dragStart",Mt="mouseEnter",Dt="mouseLeave",Pt="error",It="Auto",Lt="Top",Et="Right",zt="Left",Nt="Bottom",Rt=9007199254740992,Bt="select",At="itemRotate",Ot="pan",Ut="zoomStart",Vt="zoomEnd",Ht="none",Ft=600,Gt=600,qt="rectangle",Kt=100,Wt=100,Xt=20,jt=20,Yt=0,Qt="Yellow",Jt=Number.MAX_VALUE,Zt=-Number.MAX_VALUE,$t="absolute",te="transformed",ee="rotated",ie="transparent",ne="width",oe="height",se="x",re="y",ae="DOMMouseScroll"+yt+" mousewheel"+yt,he=.05,ce=5,de='#=text#',le=5;E.DefaultConnectors=[{name:Lt},{name:Nt},{name:zt},{name:Et},{name:It,position:function(t){return t.getPosition("center")}}],_={cancel:{text:"Cancel",imageClass:"k-cancel",className:"k-diagram-cancel",iconClass:"k-icon"},update:{text:"Update",imageClass:"k-update",className:"k-diagram-update",iconClass:"k-icon"}},E.shapeDefaults=function(t){var e={type:qt,path:"",autoSize:!0,visual:null,x:Yt,y:Yt,minWidth:Xt,minHeight:jt,width:Kt,height:Wt,hover:{},editable:{connect:!0,tools:[]},connectors:E.DefaultConnectors,rotation:{angle:0}};return st.simpleExtend(e,t),e},v=rt.extend({init:function(t){var e=this;e.dataItem=(t||{}).dataItem,rt.fn.init.call(e),e.options=B({id:E.randomId()},e.options,t),e.isSelected=!1,e.visual=new V({id:e.options.id,autoSize:e.options.autoSize}),e.id=e.options.id,e._template()},options:{hover:{},cursor:ot.grip,content:{align:"center middle"},selectable:!0,serializable:!0,enable:!0},_getCursor:function(t){return this.adorner?this.adorner._getCursor(t):this.options.cursor},visible:function(t){return lt(t)?this.visual.visible():(this.visual.visible(t),e)},bounds:function(){},refresh:function(){this.visual.redraw()},position:function(t){this.options.x=t.x,this.options.y=t.y,this.visual.position(t)},toString:function(){return this.options.id},serialize:function(){var t=B({},{options:this.options});return this.dataItem&&(t.dataItem=""+this.dataItem),t},_content:function(t){var i,n,o;return t!==e&&(i=this.options,E.Utils.isString(t)?i.content.text=t:B(i.content,t),n=i.content,o=this._contentVisual,o?this._updateContentVisual(n):this._createContentVisual(n)),this.options.content.text},_createContentVisual:function(t){t.text&&(this._contentVisual=new j(t),this._contentVisual._includeInBBox=!1,this.visual.append(this._contentVisual))},_updateContentVisual:function(t){this._contentVisual.redraw(t)},_hitTest:function(t){var e=this.bounds();return this.visible()&&e.contains(t)&&this.options.enable},_template:function(){var t,e,i=this;i.options.content.template&&(t=i.dataItem||{},e=kendo.template(i.options.content.template,{paramName:"dataItem"}),i.options.content.text=e(t))},_canSelect:function(){return this.options.selectable!==!1},toJSON:function(){return{id:this.options.id}}}),y=N.extend({init:function(t,e){this.options=B({},this.options,e),this.connections=[],this.shape=t},options:{width:7,height:7,fill:{color:Qt},hover:{}},position:function(){return this.options.position?this.options.position(this.shape):this.shape.getPosition(this.options.name)},toJSON:function(){return{shapeId:""+this.shape,connector:this.options.name}}}),y.parse=function(t,e){var i,n,o=e.split(":"),s=o[0],r=o[1]||It;for(i=0;t.shapes.length>i;i++)if(n=t.shapes[i],n.options.id==s)return n.getConnector(r.trim())},w=v.extend({init:function(t,e){var i=this;v.fn.init.call(i,t),this.diagram=e,this.updateOptionsFromModel(),t=i.options,i.connectors=[],i.type=t.type,i.createShapeVisual(),i.updateBounds(),i.content(i.content()),i._createConnectors()},options:E.shapeDefaults(),_setOptionsFromModel:function(t){var e=r(t||this.dataItem);this.options=B({},this.options,e),this.redrawVisual(),this.options.content&&(this._template(),this.content(this.options.content))},updateOptionsFromModel:function(t,e){var i,n;this.diagram&&this.diagram._isEditable&&(i=r(t||this.dataItem),t&&e?P.inArray(e,["x","y","width","height"])?(n=this.bounds(),n[e]=t[e],this.bounds(n)):(this.options.visual?this.redrawVisual():i.type&&(this.options=B({},this.options,i),this.redrawVisual()),this.options.content&&(this._template(),this.content(this.options.content))):this.options=B({},this.options,i))},redrawVisual:function(){this.visual.clear(),this._contentVisual=null,this.options.dataItem=this.dataItem,this.createShapeVisual(),this.updateBounds()},updateModel:function(t){var e,i,n=this.diagram;n&&n._isEditable&&(e=this._bounds,i=this.dataItem,i&&(n._suspendModelRefresh(),ft(i.x)&&e.x!==i.x&&i.set("x",e.x),ft(i.y)&&e.y!==i.y&&i.set("y",e.y),ft(i.width)&&e.width!==i.width&&i.set("width",e.width),ft(i.height)&&e.height!==i.height&&i.set("height",e.height),this.dataItem=i,n._resumeModelRefresh(),t&&n._syncShapeChanges()))},updateBounds:function(){var t=this.visual._measure(!0),e=this.options;this.bounds(new q(e.x,e.y,t.width,t.height)),this._rotate(),this._alignContent()},content:function(t){var e=this._content(t);return this._alignContent(),e},_alignContent:function(){var t,e,i,n,o,s=this.options.content||{},r=this._contentVisual;r&&s.align&&(t=this.visual._measure(),e=new E.RectAlign(t),i=r.drawingElement.bbox(null),n=new q(0,0,i.width(),i.height()),o=e.align(n,s.align),r.position(o.topLeft()))},_createConnectors:function(){var t,e,i=this.options,n=i.connectors.length,o=i.connectorDefaults;for(e=0;n>e;e++)t=new y(this,B({},o,i.connectors[e])),this.connectors.push(t)},bounds:function(t){var e,i;if(t)if(mt(t))switch(t){case te:e=this._transformedBounds();break;case $t:e=this._transformedBounds(),i=this.diagram._pan,e.x+=i.x,e.y+=i.y;break;case ee:e=this._rotatedBounds();break;default:e=this._bounds}else this._setBounds(t),this._triggerBoundsChange(),this.diagram&&this.diagram._layouting||this.refreshConnections();else e=this._bounds;return e},_setBounds:function(t){var e=this.options,i=t.topLeft(),n=e.x=i.x,o=e.y=i.y,s=e.width=vt.max(t.width,e.minWidth),r=e.height=vt.max(t.height,e.minHeight);this._bounds=new q(n,o,s,r),this.visual.redraw({x:n,y:o,width:s,height:r})},position:function(t){return t?(this.bounds(new q(t.x,t.y,this._bounds.width,this._bounds.height)),e):this._bounds.topLeft()},clone:function(){var t=this.serialize();return t.options.id=E.randomId(),this.diagram&&this.diagram._isEditable&&ft(this.dataItem)&&(t.options.dataItem=l(this.dataItem)),new w(t.options)},select:function(t){var i,n,o=this.diagram;return lt(t)&&(t=!0),this._canSelect()&&this.isSelected!=t?(i=[],n=[],this.isSelected=t,this.isSelected?(o._selectedItems.push(this),i.push(this)):(st.remove(o._selectedItems,this),n.push(this)),o._internalSelection||o._selectionChanged(i,n),!0):e},rotate:function(t,i,n){var o,s,r,a,h=this.visual.rotate();return t!==e&&(n!==!1&&this.diagram&&this.diagram.undoRedoService&&t!==h.angle&&this.diagram.undoRedoService.add(new E.RotateUnit(this.diagram._resizingAdorner,[this],[h.angle]),!1),o=this.bounds(),s=new Q(o.width/2,o.height/2),i&&(r=t-h.angle,a=o.center().rotate(i,360-r).minus(s),this._rotationOffset=this._rotationOffset.plus(a.minus(o.topLeft())),this.position(a)),this.visual.rotate(t,s),this.options.rotation.angle=t,this.diagram&&this.diagram._connectorsAdorner&&this.diagram._connectorsAdorner.refresh(),this.refreshConnections(),this.diagram&&this.diagram.trigger(At,{item:this})),h},connections:function(t){var e,i,n,o,s,r,a,h=[];for(e=0;this.connectors.length>e;e++)for(s=this.connectors[e],o=s.connections,i=0,o;o.length>i;i++)n=o[i],"out"==t?(r=n.source(),r.shape&&r.shape==this&&h.push(n)):"in"==t?(a=n.target(),a.shape&&a.shape==this&&h.push(n)):h.push(n);return h},refreshConnections:function(){t.each(this.connections(),function(){this.refresh()})},getConnector:function(t){var e,i;if(!mt(t))return t instanceof Q?o(t,this):this.connectors.length?this.connectors[0]:null;for(t=t.toLocaleLowerCase(),e=0;this.connectors.length>e;e++)if(i=this.connectors[e],i.options.name.toLocaleLowerCase()==t)return i},getPosition:function(t){var e=this.bounds(),i=t.charAt(0).toLowerCase()+t.slice(1);return gt(e[i])?this._transformPoint(e[i]()):e.center()},redraw:function(t){var e,i;t&&(e=this.options,this.shapeVisual.redraw(this._visualOptions(t)),this._diffNumericOptions(t,[ne,oe,se,re])&&(this.bounds(new q(e.x,e.y,e.width,e.height)),i=!0),t.connectors&&(e.connectors=t.connectors,this._updateConnectors()),e=B(e,t),(t.rotation||i)&&this._rotate(),e.content&&this.content(e.content))},_updateConnectors:function(){var t,e,i,n,o=this.connections();for(this.connectors=[],this._createConnectors(),n=0;o.length>n;n++)t=o[n],e=t.source(),i=t.target(),e.shape&&e.shape===this?t.source(this.getConnector(e.options.name)||null):i.shape&&i.shape===this&&t.target(this.getConnector(i.options.name)||null),t.updateModel()},_diffNumericOptions:E.diffNumericOptions,_visualOptions:function(t){return{data:t.path,source:t.source,hover:t.hover,fill:t.fill,stroke:t.stroke}},_triggerBoundsChange:function(){this.diagram&&this.diagram.trigger(xt,{item:this,bounds:this._bounds.clone()})},_transformPoint:function(t){var e=this.rotate(),i=this.bounds(),n=i.topLeft();return e.angle&&t.rotate(e.center().plus(n),360-e.angle),t},_transformedBounds:function(){var t=this.bounds(),e=t.topLeft(),i=t.bottomRight();return q.fromPoints(this.diagram.modelToView(e),this.diagram.modelToView(i))},_rotatedBounds:function(){var t=this.bounds().rotatedBounds(this.rotate().angle),e=t.topLeft(),i=t.bottomRight();return q.fromPoints(e,i)},_rotate:function(){var t=this.options.rotation;t&&t.angle&&this.rotate(t.angle),this._rotationOffset=new Q},_hover:function(t){var e=this.options,i=e.hover,n=e.stroke,o=e.fill;t&&ut(i.stroke)&&(n=B({},n,i.stroke)),t&&ut(i.fill)&&(o=i.fill),this.shapeVisual.redraw({stroke:n,fill:o}),e.editable&&e.editable.connect&&this.diagram._showConnectors(this,t)},_hitTest:function(t){if(this.visible()){var e,i=this.bounds(),n=this.rotate().angle;if(t.isEmpty&&!t.isEmpty())return J.rects(t,i,n?n:0);if(e=t.clone().rotate(i.center(),n),i.contains(e))return this}},toJSON:function(){return{shapeId:this.options.id}},createShapeVisual:function(){var t,e=this.options,i=this._visualOptions(e),n=e.visual,o=(e.type+"").toLocaleLowerCase();i.width=e.width,i.height=e.height,gt(n)?t=n.call(this,e):i.data?(t=new K(i),m(t)):t="rectangle"==o?new H(i):"circle"==o?new F(i):"text"==o?new j(i):"image"==o?new Y(i):new K(i),this.shapeVisual=t,this.visual.append(this.shapeVisual)}}),x=v.extend({init:function(t,e,i){var n=this;v.fn.init.call(n,i),this.updateOptionsFromModel(),this._initRouter(),n.path=new E.Polyline(n.options),n.path.fill(ie),n.visual.append(n.path),n._sourcePoint=n._targetPoint=new Q,n._setSource(t),n._setTarget(e),n.content(n.options.content),n.definers=[],ft(i)&&i.points&&n.points(i.points)},options:{hover:{stroke:{}},startCap:Ht,endCap:Ht,points:[],selectable:!0,fromConnector:It,toConenctor:It},_setOptionsFromModel:function(t){this.updateOptionsFromModel(t||this.dataItem)},updateOptionsFromModel:function(t){var e,i,n,o;this.diagram&&this.diagram._isEditable&&(e=this.diagram._dataMap,i=a(t||this.dataItem),t?(ft(i.from)?(n=e[i.from],n&&ft(i.fromConnector)&&(n=n.getConnector(i.fromConnector)),this.source(n)):ft(i.fromX)&&ft(i.fromY)&&this.source(new Q(i.fromX,i.fromY)),ft(i.to)?(o=e[i.to],o&&ft(i.toConnector)&&(o=o.getConnector(i.toConnector)),this.target(o)):ft(i.toX)&&ft(i.toY)&&this.target(new Q(i.toX,i.toY)),ft(i.type)&&this.type()!==i.type&&(this.points([]),this.type(i.type)),this.dataItem=t,this._template(),this.redraw(this.options)):this.options=B({},i,this.options))},updateModel:function(t){if(this.diagram&&this.diagram._isEditable&&this.diagram.connectionsDataSource){var e=this.diagram.connectionsDataSource.getByUid(this.dataItem.uid);e&&(this.diagram._suspendModelRefresh(),ft(this.options.fromX)&&null!==this.options.fromX?(p("from",e),p("fromConnector",e),e.set("fromX",this.options.fromX),e.set("fromY",this.options.fromY)):(e.set("from",this.options.from),ft(e.fromConnector)&&e.set("fromConnector",this.sourceConnector?this.sourceConnector.options.name:null),p("fromX",e),p("fromY",e)),ft(this.options.toX)&&null!==this.options.toX?(p("to",e),p("toConnector",e),e.set("toX",this.options.toX),e.set("toY",this.options.toY)):(e.set("to",this.options.to),ft(e.toConnector)&&e.set("toConnector",this.targetConnector?this.targetConnector.options.name:null),p("toX",e),p("toY",e)),ft(this.options.type)&&ft(e.type)&&e.set("type",this.options.type),this.dataItem=e,this.diagram._resumeModelRefresh(),t&&this.diagram._syncConnectionChanges())}},sourcePoint:function(){return this._resolvedSourceConnector?this._resolvedSourceConnector.position():this._sourcePoint},_setSource:function(t){var i,n=t instanceof w,o=this.options.fromConnector||It;(!n||t.getConnector(o))&&(t!==e&&(this.from=t),this._removeFromSourceConnector(),null===t?this.sourceConnector&&(this._sourcePoint=(this._resolvedSourceConnector||this.sourceConnector).position(),this._clearSourceConnector(),this._setFromOptions(null,this._sourcePoint)):t instanceof y?(i=t.shape.dataItem,i&&this._setFromOptions(i.id),this.sourceConnector=t,this.sourceConnector.connections.push(this)):t instanceof Q?(this._setFromOptions(null,t),this._sourcePoint=t,this.sourceConnector&&this._clearSourceConnector()):n&&(i=t.dataItem,i&&this._setFromOptions(i.id),this.sourceConnector=t.getConnector(o),this.sourceConnector.connections.push(this)))},source:function(t,e){return ut(t)&&(e&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new E.ConnectionEditUnit(this,t)),this._setSource(t),this.refresh()),this.sourceConnector?this.sourceConnector:this._sourcePoint},_setFromOptions:function(t,e){this.options.from=t,e?(this.options.fromX=e.x,this.options.fromY=e.y):(this.options.fromX=null,this.options.fromY=null)},sourceDefiner:function(t){if(!t)return this._sourceDefiner||(this._sourceDefiner=new E.PathDefiner(this.sourcePoint(),null,null)),this._sourceDefiner;if(!(t instanceof E.PathDefiner))throw"The sourceDefiner needs to be a PathDefiner.";t.left=null,this._sourceDefiner=t,this.source(t.point)},targetPoint:function(){return this._resolvedTargetConnector?this._resolvedTargetConnector.position():this._targetPoint},_setTarget:function(t){var i,n=t instanceof w,o=this.options.toConnector||It;(!n||t.getConnector(o))&&(t!==e&&(this.to=t),this._removeFromTargetConnector(),null===t?this.targetConnector&&(this._targetPoint=(this._resolvedTargetConnector||this.targetConnector).position(),this._clearTargetConnector(),this._setToOptions(null,this._targetPoint)):t instanceof y?(i=t.shape.dataItem,i&&this._setToOptions(i.id),this.targetConnector=t,this.targetConnector.connections.push(this)):t instanceof Q?(this._setToOptions(null,t),this._targetPoint=t,this.targetConnector&&this._clearTargetConnector()):n&&(i=t.dataItem,i&&this._setToOptions(i.id),this.targetConnector=t.getConnector(o),this.targetConnector.connections.push(this)))},target:function(t,i){return ut(t)&&(i&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new E.ConnectionEditUnit(this,e,t)),this._setTarget(t),this.refresh()),this.targetConnector?this.targetConnector:this._targetPoint},_setToOptions:function(t,e){this.options.to=t,e?(this.options.toX=e.x,this.options.toY=e.y):(this.options.toX=null,this.options.toY=null)},targetDefiner:function(t){if(!t)return this._targetDefiner||(this._targetDefiner=new E.PathDefiner(this.targetPoint(),null,null)),this._targetDefiner;if(!(t instanceof E.PathDefiner))throw"The sourceDefiner needs to be a PathDefiner.";t.right=null,this._targetDefiner=t,this.target(t.point)},_updateConnectors:function(){this._updateConnector(this.source(),"source"),this._updateConnector(this.target(),"target")},_updateConnector:function(t,e){var i,n,o,s,r=this,a=r.diagram;t instanceof y&&!a.getShapeById(t.shape.id)?(i=t.shape.dataItem,n=t.options.name,o=function(){var o=a._dataMap[i.id];t=o.getConnector(n),r[e](t,!1),r.updateModel()},a._dataMap[i.id]?o():(s=a._inactiveShapeItems.getByUid(i.uid),s&&a._deferredConnectionUpdates.push(s.onActivate(o)))):r[e](t,!1)},content:function(t){var e=this._content(t);return ft(t)&&this._alignContent(),e},_createContentVisual:function(t){var e;return gt(t.visual)?e=t.visual.call(this,t):t.text&&(e=new j(t)),e&&(this._contentVisual=e,e._includeInBBox=!1,this.visual.append(e)),e},_updateContentVisual:function(t){gt(t.visual)?(this.visual.remove(this._contentVisual),
this._createContentVisual(t)):this._contentVisual.redraw(t)},_alignContent:function(){var t,e,i,n,o,s,r,a,h,c,d,l,u,f,p,g;if(this._contentVisual){for(t=le,e=this.allPoints(),i=vt.floor(e.length/2),n=i-1;n>0&&e[n].equals(e[i]);)n--,i++;o=e[i],s=e[n],r=this._contentVisual._measure(),a=r.width,h=r.height,c=e.length%2===0,d=s.distanceTo(o),c&&e.length>2&&d>0&&(s.y===o.y&&a>d||s.x===o.x&&h>d)&&(c=!1,t=0),c?(u=kendo.util.deg(vt.atan2(o.y-s.y,o.x-s.x)),l=new Q((o.x-s.x)/2+s.x,(o.y-s.y)/2+s.y),90===vt.abs(u)?(l.x+=t,l.y-=h/2):u%180===0?(l.x-=a/2,l.y-=h+t):-90>u||u>0&&90>u?l.y-=h:(0>u||u>90)&&(l.x-=a,l.y-=h)):(f=vt.floor(e.length/2),l=e[f].clone(),s=e[f-1],o=e[f+1],p=l.x>=s.x&&l.x>=o.x?t:-r.width-t,g=l.y>=s.y&&l.y>=o.y?t:-r.height-t,l.x+=p,l.y+=g),this._contentVisual.position(l)}},select:function(t){var i,n,o=this.diagram;return this._canSelect()&&this.isSelected!==t?(this.isSelected=t,i=[],n=[],this.isSelected?(this.adorner=new Z(this,this.options.selection),o._adorn(this.adorner,!0),o._selectedItems.push(this),i.push(this)):this.adorner&&(o._adorn(this.adorner,!1),st.remove(o._selectedItems,this),this.adorner=e,n.push(this)),this.adorner&&this.adorner.refresh(),o._internalSelection||o._selectionChanged(i,n),!0):e},bounds:function(t){return!t||mt(t)?this._bounds:(this._bounds=t,e)},type:function(t){var i=this.options;return t?(t!==i.type&&(i.type=t,this._initRouter(),this.refresh()),e):i.type},_initRouter:function(){var t=(this.options.type||"").toLowerCase();this._router=t==wt?new dt(this):new ct(this)},points:function(t){var e,i,n,o;if(!t){if(n=[],ut(this.definers))for(o=0;this.definers.length>o;o++)n.push(this.definers[o].point);return n}for(this.definers=[],e=0;t.length>e;e++)if(i=t[e],i instanceof E.Point)this.definers.push(new E.PathDefiner(i));else{if(!i.hasOwnProperty("x")||!i.hasOwnProperty("y"))throw"A Connection point needs to be a Point or an object with x and y properties.";this.definers.push(new E.PathDefiner(new Q(i.x,i.y)))}},allPoints:function(){var t,e=[this.sourcePoint()];if(this.definers)for(t=0;this.definers.length>t;t++)e.push(this.definers[t].point);return e.push(this.targetPoint()),e},refresh:function(){this._resolveConnectors(),this._refreshPath(),this._alignContent(),this.adorner&&this.adorner.refresh()},_resolveConnectors:function(){var t,e,i,s,r=this,a=r.source(),h=r.target();a instanceof Q?t=a:a instanceof y&&(n(a)?i=a.shape:(r._resolvedSourceConnector=a,t=a.position())),h instanceof Q?e=h:h instanceof y&&(n(h)?s=h.shape:(r._resolvedTargetConnector=h,e=h.position())),t?s&&(r._resolvedTargetConnector=o(t,s)):i&&(e?r._resolvedSourceConnector=o(e,i):s&&this._resolveAutoConnectors(i,s))},_resolveAutoConnectors:function(t,e){var i,o,s,r,a,h,c,d,l,u,f,p,g=Rt,m=Rt,_=t.connectors;for(u=0;_.length>u;u++)if(d=_[u],!n(d))for(r=d.position(),i=e.connectors,f=0;i.length>f;f++)l=i[f],n(l)||(a=l.position(),p=vt.round(r.distanceTo(a)),g>p&&this.diagram&&this._testRoutePoints(r,a,d,l)&&(g=p,o=d,s=l),m>p&&(h=d,c=l,m=p));o&&(h=o,c=s),this._resolvedSourceConnector=h,this._resolvedTargetConnector=c},_testRoutePoints:function(t,e,i,n){var o,s,r,a,h,c=this._router,d=!0;if(c instanceof dt)for(o=c.routePoints(t,e,i,n),o.unshift(t),o.push(e),h=1;o.length>h;h++)if(s=o[h-1],r=o[h],a=new q(vt.min(s.x,r.x),vt.min(s.y,r.y),vt.abs(s.x-r.x),vt.abs(s.y-r.y)),a.width>0&&(a.x++,a.width-=2),a.height>0&&(a.y++,a.height-=2),!a.isEmpty()&&this.diagram._shapesQuadTree.hitTestRect(a)){d=!1;break}return d},redraw:function(t){if(t){this.options=B({},this.options,t);var e=this.options.points;ft(e)&&e.length>0&&(this.points(e),this._refreshPath()),(t&&t.content||t.text)&&this.content(t.content),this.path.redraw({fill:t.fill,stroke:t.stroke,startCap:t.startCap,endCap:t.endCap})}},clone:function(){var t=this.serialize();return this.diagram&&this.diagram._isEditable&&ft(this.dataItem)&&(t.options.dataItem=l(this.dataItem)),new x(this.from,this.to,t.options)},serialize:function(){var t=this.from.toJSON?this.from.toJSON:""+this.from,e=this.to.toJSON?this.to.toJSON:""+this.to,i=B({},{options:this.options,from:t,to:e});return ft(this.dataItem)&&(i.dataItem=""+this.dataItem),i.options.points=this.points(),i},_hitTest:function(t){if(this.visible()){var e=new Q(t.x,t.y),i=this.sourcePoint(),n=this.targetPoint();if(t.isEmpty&&!t.isEmpty()&&t.contains(i)&&t.contains(n))return this;if(this._router.hitTest(e))return this}},_hover:function(t){var e=(this.options.stroke||{}).color;t&&ut(this.options.hover.stroke.color)&&(e=this.options.hover.stroke.color),this.path.redraw({stroke:{color:e}})},_refreshPath:function(){ft(this.path)&&(this._drawPath(),this.bounds(this._router.getBounds()))},_drawPath:function(){var t,e,i;this._router&&this._router.route(),t=this.sourcePoint(),e=this.targetPoint(),i=this.points(),this.path.redraw({points:[t].concat(i,[e])})},_clearSourceConnector:function(){this.sourceConnector=e,this._resolvedSourceConnector=e},_clearTargetConnector:function(){this.targetConnector=e,this._resolvedTargetConnector=e},_removeFromSourceConnector:function(){this.sourceConnector&&st.remove(this.sourceConnector.connections,this)},_removeFromTargetConnector:function(){this.targetConnector&&st.remove(this.targetConnector.connections,this)},toJSON:function(){var t,e,i,n=this;return n.from&&n.from.toJSON?t=n.from.toJSON():(i=n._sourcePoint,t={x:i.x,y:i.y}),n.to&&n.to.toJSON?e=n.to.toJSON():(i=n._targetPoint,e={x:i.x,y:i.y}),{from:t,to:e}}}),C=z.extend({init:function(t,e){var i=this;kendo.destroy(t),z.fn.init.call(i,t,e),i._initTheme(),i._initElements(),i._extendLayoutOptions(i.options),i._initDefaults(e),i._initCanvas(),i.mainLayer=new V({id:"main-layer"}),i.canvas.append(i.mainLayer),i._shapesQuadTree=new D(i),i._pan=new Q,i._adorners=[],i.adornerLayer=new V({id:"adorner-layer"}),i.canvas.append(i.adornerLayer),i._createHandlers(),i._initialize(),i._fetchFreshData(),i._createGlobalToolBar(),i._resizingAdorner=new it(i,{editable:i.options.editable}),i._connectorsAdorner=new nt(i),i._adorn(i._resizingAdorner,!0),i._adorn(i._connectorsAdorner,!0),i.selector=new et(i),i._clipboard=[],i.pauseMouseHandlers=!1,i._createOptionElements(),i.zoom(i.options.zoom),i.canvas.draw()},options:{name:"Diagram",theme:"default",layout:"",zoomRate:.1,zoom:1,zoomMin:0,zoomMax:2,dataSource:{},draggable:!0,template:"",autoBind:!0,editable:{rotate:{},resize:{},text:!0,tools:[],drag:{snap:{size:10,angle:10}},remove:!0},pannable:{key:"ctrl"},selectable:{key:"none"},tooltip:{enabled:!0,format:"{0}"},copy:{enabled:!0,offsetX:20,offsetY:20},shapeDefaults:E.shapeDefaults({undoable:!0}),connectionDefaults:{editable:{tools:[]},type:wt},shapes:[],connections:[]},events:[Vt,Ut,Ot,Bt,At,xt,Ct,bt,Mt,Dt,"toolBarClick","save","cancel","edit","remove","add","dataBound",Tt,St,kt],items:function(){return t()},_createGlobalToolBar:function(){var t,e=this.options.editable;e&&(t=e.tools,!this._isEditable||t===!1||t&&0!==t.length||(t=["createShape","undo","redo","rotateClockwise","rotateAnticlockwise"]),t&&t.length&&(this.toolBar=new b(this,{tools:t||{},click:R(this._toolBarClick,this),modal:!1}),this.toolBar.element.css({textAlign:"left"}),this.element.prepend(this.toolBar.element),this._resize()))},createShape:function(){var t,e,i,n,o,s;(this.editor&&this.editor.end()||!this.editor)&&(t=this.dataSource,e=t.view()||[],i=e.length,n=f(t,{}),o=this._createShape(n,{}),this.trigger("add",{shape:o})||(t.insert(i,n),s=this._inactiveShapeItems.getByUid(n.uid),s.element=o,this.edit(o)))},_createShape:function(t,e){e=B({},this.options.shapeDefaults,e),e.dataItem=t;var i=new w(e,this);return i},createConnection:function(){var t,e,i,n,o;(this.editor&&this.editor.end()||!this.editor)&&(t=this.connectionsDataSource,e=t.view()||[],i=e.length,n=f(t,{}),o=this._createConnection(n),this.trigger("add",{connection:o})||(this._connectionsDataMap[n.uid]=o,t.insert(i,n),this.addConnection(o,!1),this.edit(o)))},_createConnection:function(t,e,i){var n,o=B({},this.options.connectionDefaults);return o.dataItem=t,n=new x(e||new Q,i||new Q,o)},editModel:function(t,e){var i,n,o,s;if(this.cancelEdit(),o=this.options.editable,"shape"==e)i=o.shapeEditors,n=o.shapeTemplate;else{if("connection"!=e)return;s=R(h,this),i=B({},{from:s,to:s},o.connectionEditors),n=o.connectionTemplate}this.editor=new k(this.element,{update:R(this._update,this),cancel:R(this._cancel,this),model:t,type:e,target:this,editors:i,template:n}),this.trigger("edit",this._editArgs())},edit:function(t){if(t.dataItem){var e=t instanceof w?"shape":"connection";this.editModel(t.dataItem,e)}},cancelEdit:function(){this.editor&&(this._getEditDataSource().cancelChanges(this.editor.model),this._destroyEditor())},saveEdit:function(){this.editor&&this.editor.end()&&!this.trigger("save",this._editArgs())&&this._getEditDataSource().sync()},_update:function(){this.editor&&this.editor.end()&&!this.trigger("save",this._editArgs())&&(this._getEditDataSource().sync(),this._destroyEditor())},_cancel:function(){var t,e;this.editor&&!this.trigger("cancel",this._editArgs())&&(t=this.editor.model,this._getEditDataSource().cancelChanges(t),e=this._connectionsDataMap[t.uid]||this._dataMap[t.id],e&&e._setOptionsFromModel(t),this._destroyEditor())},_getEditDataSource:function(){return"shape"===this.editor.options.type?this.dataSource:this.connectionsDataSource},_editArgs:function(){var t={container:this.editor.wrapper};return t[this.editor.options.type]=this.editor.model,t},_destroyEditor:function(){this.editor&&(this.editor.close(),this.editor=null)},_initElements:function(){this.wrapper=this.element.empty().css("position","relative").attr("tabindex",0).addClass("k-widget k-diagram"),this.scrollable=t("").appendTo(this.element)},_initDefaults:function(t){var e=this.options,i=e.editable,n=e.shapeDefaults,o=e.connectionDefaults,s=(t||{}).shapeDefaults;i===!1?(n.editable=!1,o.editable=!1):(g(i,n.editable,["drag","remove","connect"]),g(i,o.editable,["drag","remove"])),s&&s.connectors&&(e.shapeDefaults.connectors=s.connectors)},_initCanvas:function(){var e=t("").appendTo(this.scrollable)[0],i=this.viewport();this.canvas=new U(e,{width:i.width||Ft,height:i.height||Gt})},_createHandlers:function(){var t=this,e=t.element;e.on(ae,R(t._wheel,t)),kendo.support.touch||kendo.support.mobileOS?(t._userEvents=new kendo.UserEvents(e,{multiTouch:!0,tap:R(t._tap,t)}),t._userEvents.bind(["gesturestart","gesturechange","gestureend"],{gesturestart:R(t._gestureStart,t),gesturechange:R(t._gestureChange,t),gestureend:R(t._gestureEnd,t)}),t.toolService=new tt(t),t.options.pannable!==!1&&t.scroller.enable()):(t.toolService=new tt(t),this.scroller.wrapper.on("mousemove"+yt,R(t._mouseMove,t)).on("mouseup"+yt,R(t._mouseUp,t)).on("mousedown"+yt,R(t._mouseDown,t)).on("mouseover"+yt,R(t._mouseover,t)).on("mouseout"+yt,R(t._mouseout,t)),e.on("keydown"+yt,R(t._keydown,t))),this._syncHandler=R(t._syncChanges,t),t._resizeHandler=R(t.resize,t,!1),kendo.onResize(t._resizeHandler),this.bind(Ut,R(t._destroyToolBar,t)),this.bind(Ot,R(t._destroyToolBar,t))},_tap:function(t){var e,i=this.toolService,n=this._caculateMobilePosition(t);i._updateHoveredItem(n),i.hoveredItem&&(e=i.hoveredItem,this.options.selectable!==!1&&(this._destroyToolBar(),e.isSelected?e.select(!1):this.select(e,{addToSelection:!0}),this._createToolBar()),this.trigger("click",{item:e,point:n}))},_caculateMobilePosition:function(t){return this.documentToModel(Q(t.x.location,t.y.location))},_gestureStart:function(t){var e,i;this._destroyToolBar(),this.scroller.disable(),e=this.documentToModel(new Q(t.center.x,t.center.y)),i={point:e,zoom:this.zoom()},this.trigger(Ut,i)||(this._gesture=t,this._initialCenter=e)},_gestureChange:function(t){var e,i,n=this._gesture,o=this._initialCenter,s=this.documentToView(new Q(t.center.x,t.center.y)),r=t.distance/n.distance,a=this._zoom,h=!1;vt.abs(r-1)>=he&&(this._zoom=a=this._getValidZoom(a*r),this.options.zoom=a,this._gesture=t,h=!0),e=o.times(a),i=s.minus(e),(h||this._pan.distanceTo(i)>=ce)&&(this._panTransform(i),this._updateAdorners()),t.preventDefault()},_gestureEnd:function(){this.options.pannable!==!1&&this.scroller.enable(),this.trigger(Vt,{point:this._initialCenter,zoom:this.zoom()})},_resize:function(){var t=this.viewport();this.canvas&&this.canvas.size(t),this.scrollable&&this.toolBar&&this.scrollable.height(t.height)},_mouseover:function(t){var e=t.target._kendoNode;e&&e.srcElement._hover&&e.srcElement._hover(!0,e.srcElement)},_mouseout:function(t){var e=t.target._kendoNode;e&&e.srcElement._hover&&e.srcElement._hover(!1,e.srcElement)},_initTheme:function(){var t=this,e=P.ui.themes||{},i=((t.options||{}).theme||"").toLowerCase(),n=(e[i]||{}).diagram;t.options=B({},n,t.options),t.options.editable===!0&&B(t.options,{editable:(n||{}).editable})},_createOptionElements:function(){var t=this.options,e=t.shapes.length;e&&this._createShapes(),t.connections.length&&this._createConnections(),e&&t.layout&&this.layout(t.layout)},_createShapes:function(){var t,e,i=this,n=i.options,o=n.shapes;for(e=0;o.length>e;e++)t=o[e],i.addShape(t)},_createConnections:function(){var t,e,i,n,o=this,s=o.options,r=s.connectionDefaults,a=s.connections;for(n=0;a.length>n;n++)t=a[n],e=o._findConnectionTarget(t.from),i=o._findConnectionTarget(t.to),o.connect(e,i,B({},r,t))},_findConnectionTarget:function(t){var e,i=this,n=mt(t)?t:t.shapeId||t.id;return n?(e=i.getShapeById(n),t.connector&&(e=e.getConnector(t.connector))):e=new Q(t.x||0,t.y||0),e},destroy:function(){var t=this;z.fn.destroy.call(t),this._userEvents&&this._userEvents.destroy(),kendo.unbindResize(t._resizeHandler),t.clear(),t.element.off(yt),t.scroller.wrapper.off(yt),t.canvas.destroy(!0),t.canvas=e,t._destroyEditor(),t.destroyScroller(),t._destroyGlobalToolBar(),t._destroyToolBar()},destroyScroller:function(){var t=this.scroller;t&&(t.destroy(),t.element.remove(),this.scroller=null)},save:function(){var t,e,i,n={shapes:[],connections:[]};for(t=0;this.shapes.length>t;t++)i=this.shapes[t],i.options.serializable&&n.shapes.push(i.options);for(t=0;this.connections.length>t;t++)e=this.connections[t],n.connections.push(B({},e.options,e.toJSON()));return n},focus:function(){if(!this.element.is(kendo._activeElement())){var t,e=this.element,i=e[0],n=[],o=[],s=document.documentElement;do i=i.parentNode,i.scrollHeight>i.clientHeight&&(n.push(i),o.push(i.scrollTop));while(i!=s);for(e.focus(),t=0;n.length>t;t++)n[t].scrollTop=o[t]}},load:function(t){this.clear(),this.setOptions(t),this._createShapes(),this._createConnections()},setOptions:function(t){B(this.options,t)},clear:function(){var t=this;t.select(!1),t.mainLayer.clear(),t._shapesQuadTree.clear(),t._initialize()},connect:function(t,e,i){var n,o;return this.connectionsDataSource&&this._isEditable?(o=this.connectionsDataSource.add({}),n=this._connectionsDataMap[o.uid],n.source(t),n.target(e),n.redraw(i),n.updateModel()):(n=new x(t,e,B({},this.options.connectionDefaults,i)),this.addConnection(n)),n},connected:function(t,e){var i,n;for(i=0;this.connections.length>i;i++)if(n=this.connections[i],n.from==t&&n.to==e)return!0;return!1},addConnection:function(t,e){return e!==!1&&this.undoRedoService.add(new E.AddConnectionUnit(t,this),!1),t.diagram=this,t._setOptionsFromModel(),t.refresh(),this.mainLayer.append(t.visual),this.connections.push(t),this.trigger(Ct,{added:[t],removed:[]}),t},_addConnection:function(t,e){var i,n=this.connectionsDataSource;if(n&&this._isEditable){if(i=f(n,l(t.dataItem)),t.dataItem=i,t.updateModel(),!this.trigger("add",{connection:t}))return this._connectionsDataMap[i.uid]=t,n.add(i),this.addConnection(t,e),t._updateConnectors(),t}else if(!this.trigger("add",{connection:t}))return this.addConnection(t,e),t._updateConnectors(),t},addShape:function(t,e){var i,n=this.options.shapeDefaults;if(t instanceof w)i=t;else{if(t instanceof kendo.Class)return;n=B({},n,t||{}),i=new w(n,this)}return e!==!1&&this.undoRedoService.add(new E.AddShapeUnit(i,this),!1),this.shapes.push(i),i.diagram!==this&&(this._shapesQuadTree.insert(i),i.diagram=this),this.mainLayer.append(i.visual),this.trigger(Ct,{added:[i],removed:[]}),i},_addShape:function(t,e){var i,n,o=this,s=o.dataSource;if(s&&this._isEditable){if(i=f(s,l(t.dataItem)),t.dataItem=i,t.updateModel(),!this.trigger("add",{shape:t}))return this.dataSource.add(i),n=this._inactiveShapeItems.getByUid(i.uid),n.element=t,n.undoable=e,t}else if(!this.trigger("add",{shape:t}))return this.addShape(t,e)},remove:function(t,e){var i,n,o,s;for(t=pt(t)?t.slice(0):[t],i=u(t),n=i.shapes,o=i.connections,ft(e)||(e=!0),e&&this.undoRedoService.begin(),this._suspendModelRefresh(),s=n.length-1;s>=0;s--)this._removeItem(n[s],e,o);for(s=o.length-1;s>=0;s--)this._removeItem(o[s],e);this._resumeModelRefresh(),e&&this.undoRedoService.commit(!1),this.trigger(Ct,{added:[],removed:t})},_removeShapeDataItem:function(t){this._isEditable&&(this.dataSource.remove(t.dataItem),delete this._dataMap[t.dataItem.id])},_removeConnectionDataItem:function(t){this._isEditable&&(this.connectionsDataSource.remove(t.dataItem),delete this._connectionsDataMap[t.dataItem.uid])},_triggerRemove:function(t){var e,i,n,o,s=[];for(o=0;t.length>o;o++)e=t[o],n=e.options.editable,i=e instanceof w?{shape:e}:{connection:e},n&&n.remove!==!1&&!this.trigger("remove",i)&&s.push(e);return s},undo:function(){this.undoRedoService.undo()},redo:function(){this.undoRedoService.redo()},select:function(t,e){if(!ut(t))return this._selectedItems;e=B({addToSelection:!1},e);var i,n,o=e.addToSelection,s=[],r=[];for(o||this.deselect(),this._internalSelection=!0,t instanceof Array?s=t:t instanceof v&&(s=[t]),i=0;s.length>i;i++)n=s[i],n.select(!0)&&r.push(n);this._selectionChanged(r,[]),this._internalSelection=!1},selectAll:function(){this.select(this.shapes.concat(this.connections))},selectArea:function(t){var e,i,n,o;if(this._internalSelection=!0,o=[],t instanceof q)for(i=this.shapes.concat(this.connections),e=0;i.length>e;e++)n=i[e],t&&!n._hitTest(t)||!n.options.enable||n.select(!0)&&o.push(n);this._selectionChanged(o,[]),this._internalSelection=!1},deselect:function(t){this._internalSelection=!0;var e,i,n=[],o=[];for(t instanceof Array?o=t:t instanceof v?o.push(t):ut(t)||(o=this._selectedItems.slice(0)),i=0;o.length>i;i++)e=o[i],e.select(!1)&&n.push(e);this._selectionChanged([],n),this._internalSelection=!1},toFront:function(t,e){var i,n,o;t||(t=this._selectedItems.slice()),i=this._getDiagramItems(t),!ft(e)||e?(n=s(this.mainLayer,i.visuals),o=new ht(this,t,n),this.undoRedoService.add(o)):(this.mainLayer.toFront(i.visuals),this._fixOrdering(i,!0))},toBack:function(t,e){var i,n,o;t||(t=this._selectedItems.slice()),i=this._getDiagramItems(t),!ft(e)||e?(n=s(this.mainLayer,i.visuals),o=new at(this,t,n),this.undoRedoService.add(o)):(this.mainLayer.toBack(i.visuals),this._fixOrdering(i,!1))},bringIntoView:function(t,e){var i,n,o,s,r=this.viewport(),a=new E.RectAlign(r);0!==r.width&&0!==r.height&&(e=B({animate:!1,align:"center middle"},e),"none"==e.align&&(e.align="center middle"),t instanceof v?n=t.bounds(te):pt(t)?n=this.boundingBox(t):t instanceof q&&(n=t.clone()),o=n.clone(),n.zoom(this._zoom),(n.width>r.width||n.height>r.height)&&(this._zoom=this._getValidZoom(vt.min(r.width/o.width,r.height/o.height)),n=o.clone().zoom(this._zoom)),this._zoomMainLayer(),i=n.clone(),a.align(n,e.align),s=n.topLeft().minus(i.topLeft()),this.pan(s.times(-1),e.animate))},alignShapes:function(t){var e,i,n,o,s,r,a;if(lt(t)&&(t="Left"),e=this.select(),0!==e.length){switch(t.toLowerCase()){case"left":case"top":i=Jt;break;case"right":case"bottom":i=Zt}for(o=0;e.length>o;o++)if(n=e[o],n instanceof w)switch(t.toLowerCase()){case"left":i=vt.min(i,n.options.x);break;case"top":i=vt.min(i,n.options.y);break;case"right":i=vt.max(i,n.options.x);break;case"bottom":i=vt.max(i,n.options.y)}for(s=[],r=[],o=0;e.length>o;o++)if(n=e[o],n instanceof w)switch(r.push(n),s.push(n.bounds()),t.toLowerCase()){case"left":case"right":n.position(new Q(i,n.options.y));break;case"top":case"bottom":n.position(new Q(n.options.x,i))}a=new E.TransformUnit(r,s),this.undoRedoService.add(a,!1)}},zoom:function(t,e){var i,n,o,s;return t&&(i=e?e.point:new E.Point(0,0),t=this._zoom=this._getValidZoom(t),lt(i)||(i=new E.Point(vt.round(i.x),vt.round(i.y)),n=i.times(t),o=this.modelToView(i),s=o.minus(n),this._storePan(new E.Point(vt.round(s.x),vt.round(s.y)))),e&&(e.zoom=t),this._panTransform(),this._updateAdorners()),this._zoom},_getPan:function(t){var e=this.canvas;return e.translate||(t=t.plus(this._pan)),t},pan:function(t,e){var i,n;t instanceof Q&&(i=this,n=i.scroller,t=i._getPan(t),t=t.times(-1),e?n.animatedScrollTo(t.x,t.y,function(){i._updateAdorners()}):(n.scrollTo(t.x,t.y),i._updateAdorners()))},viewport:function(){var t=this.element,e=t.width(),i=t.height();return this.toolBar&&(i-=this.toolBar.element.outerHeight()),new q(0,0,e,i)},copy:function(){var t,e;if(this.options.copy.enabled)for(this._clipboard=[],this._copyOffset=1,t=0;this._selectedItems.length>t;t++)e=this._selectedItems[t],this._clipboard.push(e)},cut:function(){var t,e;if(this.options.copy.enabled){for(this._clipboard=[],this._copyOffset=0,t=0;this._selectedItems.length>t;t++)e=this._selectedItems[t],this._clipboard.push(e);this.remove(this._clipboard,!0)}},paste:function(){var t,e,i,n,o,s,r,a;if(this._clipboard.length>0){for(n={},o=u(this._clipboard),s=o.connections,r=o.shapes,a={x:this._copyOffset*this.options.copy.offsetX,y:this._copyOffset*this.options.copy.offsetY},this.deselect(),i=0;r.length>i;i++)t=r[i],e=t.clone(),n[t.id]=e,e.position(new Q(t.options.x+a.x,t.options.y+a.y)),e.diagram=this,e=this._addShape(e),e&&e.select();for(i=0;s.length>i;i++)t=s[i],e=this._addConnection(t.clone()),e&&(this._updateCopiedConnection(e,t,"source",n,a),this._updateCopiedConnection(e,t,"target",n,a),e.select(!0),e.updateModel());this._syncChanges(),this._copyOffset+=1}},_updateCopiedConnection:function(t,e,i,n,o){var s,r,a,h=e[i](),c=this;h instanceof y&&n[h.shape.id]?(a=n[h.shape.id],c.getShapeById(a.id)?t[i](a.getConnector(h.options.name)):(r=c._inactiveShapeItems.getByUid(a.dataItem.uid),r&&(s=function(e){a=c._dataMap[e.id],t[i](a.getConnector(h.options.name)),t.updateModel()},c._deferredConnectionUpdates.push(r.onActivate(s))))):t[i](new Q(e[i+"Point"]().x+o.x,e[i+"Point"]().y+o.y))},boundingBox:function(t,e){var i,n,o,s=q.empty(),r=ut(t)?this._getDiagramItems(t):{shapes:this.shapes};if(r.shapes.length>0)for(n=r.shapes[0],s=n.bounds(ee),o=1;r.shapes.length>o;o++)n=r.shapes[o],i=n.bounds(ee),e===!0&&(i.x-=n._rotationOffset.x,i.y-=n._rotationOffset.y),s=s.union(i);return s},_containerOffset:function(){var t=this.element.offset();return this.toolBar&&(t.top+=this.toolBar.element.outerHeight()),t},documentToView:function(t){var e=this._containerOffset();return new Q(t.x-e.left,t.y-e.top)},viewToDocument:function(t){var e=this._containerOffset();return new Q(t.x+e.left,t.y+e.top)},viewToModel:function(t){return this._transformWithMatrix(t,this._matrixInvert)},modelToView:function(t){return this._transformWithMatrix(t,this._matrix)},modelToLayer:function(t){return this._transformWithMatrix(t,this._layerMatrix)},layerToModel:function(t){return this._transformWithMatrix(t,this._layerMatrixInvert)},documentToModel:function(t){var e=this.documentToView(t);return this.canvas.translate||(e.x=e.x+this.scroller.scrollLeft,e.y=e.y+this.scroller.scrollTop),this.viewToModel(e)},modelToDocument:function(t){return this.viewToDocument(this.modelToView(t))},_transformWithMatrix:function(t,e){var i,n,o=t;return t instanceof Q?e&&(o=e.apply(t)):(i=this._transformWithMatrix(t.topLeft(),e),n=this._transformWithMatrix(t.bottomRight(),e),o=q.fromPoints(i,n)),o},setDataSource:function(t){this.options.dataSource=t,this._dataSource(),this.options.autoBind&&this.dataSource.fetch()},setConnectionsDataSource:function(t){this.options.connectionsDataSource=t,this._connectionDataSource(),this.options.autoBind&&this.connectionsDataSource.fetch()},layout:function(t){var e,i,n,o,s;switch(this._layouting=!0,lt(t)&&(t=this.options.layout),e=lt(t)||lt(t.type)?"Tree":t.type,e.toLowerCase()){case"tree":i=new E.TreeLayout(this);break;case"layered":i=new E.LayeredLayout(this);break;case"forcedirected":case"force":case"spring":case"springembedder":i=new E.SpringLayout(this);break;default:throw"Layout algorithm '"+e+"' is not supported."}n=new E.LayoutState(this),o=i.layout(t),o&&(s=new E.LayoutUndoUnit(n,o,t?t.animate:null),this.undoRedoService.add(s)),this._layouting=!1,this._redrawConnections()},getShapeById:function(t){var e;return(e=st.first(this.shapes,function(e){return e.visual.id===t}))?e:e=st.first(this.connections,function(e){return e.visual.id===t})},_extendLayoutOptions:function(t){t.layout&&(t.layout=B(E.LayoutBase.fn.defaultOptions||{},t.layout))},_selectionChanged:function(t,e){(t.length||e.length)&&this.trigger(Bt,{selected:t,deselected:e})},_getValidZoom:function(t){return vt.min(vt.max(t,this.options.zoomMin),this.options.zoomMax)},_panTransform:function(t){var e=this,i=t||e._pan;e.canvas.translate?(e.scroller.scrollTo(i.x,i.y),e._zoomMainLayer()):(e._storePan(i),e._transformMainLayer())},_finishPan:function(){this.trigger(Ot,{total:this._pan,delta:Number.NaN})},_storePan:function(t){this._pan=t,this._storeViewMatrix()},_zoomMainLayer:function(){var t=this._zoom,e=new G(0,0,t,t);e.render(this.mainLayer),this._storeLayerMatrix(e),this._storeViewMatrix()},_transformMainLayer:function(){var t=this._pan,e=this._zoom,i=new G(t.x,t.y,e,e);i.render(this.mainLayer),this._storeLayerMatrix(i),this._storeViewMatrix()},_storeLayerMatrix:function(t){this._layerMatrix=t.toMatrix(),this._layerMatrixInvert=t.invert().toMatrix()},_storeViewMatrix:function(){var t=this._pan,e=this._zoom,i=new G(t.x,t.y,e,e);this._matrix=i.toMatrix(),this._matrixInvert=i.invert().toMatrix()},_toIndex:function(t,e){var i=this._getDiagramItems(t);this.mainLayer.toIndex(i.visuals,e),this._fixOrdering(i,!1)},_fixOrdering:function(t,e){var i,n,o=e?this.shapes.length-1:0,s=e?this.connections.length-1:0;for(i=0;t.shapes.length>i;i++)n=t.shapes[i],st.remove(this.shapes,n),st.insert(this.shapes,n,o);for(i=0;t.cons.length>i;i++)n=t.cons[i],st.remove(this.connections,n),st.insert(this.connections,n,s)},_getDiagramItems:function(t){var e,i,n={},o=t;for(n.visuals=[],n.shapes=[],n.cons=[],t?pt(t)||(o=[t]):o=this._selectedItems.slice(),e=0;o.length>e;e++)i=o[e],i instanceof w?(n.shapes.push(i),n.visuals.push(i.visual)):i instanceof x&&(n.cons.push(i),n.visuals.push(i.visual));return n},_removeItem:function(t,e,i){t.select(!1),t instanceof w?(this._removeShapeDataItem(t),this._removeShape(t,e,i)):t instanceof x&&(this._removeConnectionDataItem(t),this._removeConnection(t,e)),this.mainLayer.remove(t.visual)},_removeShape:function(t,e,i){var n,o,s,r,a=[],h=[];for(this.toolService._removeHover(),e&&this.undoRedoService.addCompositeItem(new W(t)),st.remove(this.shapes,t),this._shapesQuadTree.remove(t),n=0;t.connectors.length>n;n++)for(s=t.connectors[n],r=0;s.connections.length>r;r++)o=s.connections[r],i&&P.inArray(o,i)||(o.sourceConnector==s?a.push(o):o.targetConnector==s&&h.push(o));for(n=0;a.length>n;n++)a[n].source(null,e),a[n].updateModel();for(n=0;h.length>n;n++)h[n].target(null,e),h[n].updateModel()},_removeConnection:function(t,e){t.sourceConnector&&st.remove(t.sourceConnector.connections,t),t.targetConnector&&st.remove(t.targetConnector.connections,t),e&&this.undoRedoService.addCompositeItem(new X(t)),st.remove(this.connections,t)},_removeDataItems:function(t,e){var i,n,o,s;for(t=pt(t)?t:[t];t.length;)if(i=t.shift(),o=this._dataMap[i.uid],o&&(this._removeShapeConnections(o),this._removeItem(o,!1),delete this._dataMap[i.uid],e&&i.hasChildren&&i.loaded()))for(n=i.children.data(),s=0;n.length>s;s++)t.push(n[s])},_removeShapeConnections:function(t){var e,i=t.connections();if(i)for(e=0;i.length>e;e++)this._removeItem(i[e],!1)},_addDataItem:function(t,e){var i,n;if(ft(t))return(i=this._dataMap[t.id])?i:(n=B({},this.options.shapeDefaults),n.dataItem=t,i=new w(n,this),this.addShape(i,e!==!1),this._dataMap[t.id]=i,i)},_addDataItemByUid:function(t){var e,i;if(ft(t))return(e=this._dataMap[t.uid])?e:(i=B({},this.options.shapeDefaults),i.dataItem=t,e=new w(i,this),this.addShape(e),this._dataMap[t.uid]=e,e)},_addDataItems:function(t,e){var i,n,o,s,r;for(n=0;t.length>n;n++)i=t[n],o=this._addDataItemByUid(i),s=this._addDataItemByUid(e),s&&!this.connected(s,o)&&(r=this.connect(s,o))},_refreshSource:function(t){var e,i,n=this,o=t.node,s=t.action,r=t.items,a=n.options;if(!t.field){if("remove"==s)this._removeDataItems(t.items,!0);else for(s&&"itemloaded"!==s||this._bindingRoots||(this._bindingRoots=!0,i=!0),s||o||n.clear(),this._addDataItems(r,o),e=0;r.length>e;e++)r[e].load();a.layout&&(i||"remove"==s||"add"==s)&&n.layout(a.layout),i&&(this.trigger("dataBound"),this._bindingRoots=!1)}},_mouseDown:function(t){var e=this._calculatePosition(t);1==t.which&&this.toolService.start(e,this._meta(t))&&(this._destroyToolBar(),t.preventDefault())},_addItem:function(t){t instanceof w?this.addShape(t):t instanceof x&&this.addConnection(t)},_mouseUp:function(t){var e=this._calculatePosition(t);1==t.which&&this.toolService.end(e,this._meta(t))&&(this._createToolBar(),t.preventDefault())},_createToolBar:function(){var t,e,i,n,o,s,r,a,h,c=this.toolService.diagram;this.singleToolBar||1!==c.select().length||(t=c.select()[0],t&&t.options.editable!==!1&&(e=t.options.editable,i=e.tools,this._isEditable&&0===i.length&&(t instanceof w?i=["edit","rotateClockwise","rotateAnticlockwise"]:t instanceof x&&(i=["edit"]),e&&e.remove!==!1&&i.push("delete")),i&&i.length&&(n=20,this.singleToolBar=new b(c,{tools:i,click:R(this._toolBarClick,this),modal:!0}),s=this.singleToolBar._popup.element.outerWidth(),r=this.singleToolBar._popup.element.outerHeight(),t instanceof w?(a=this.modelToView(t.bounds(ee)),o=Q(a.x,a.y).minus(Q((s-a.width)/2,r+n))):t instanceof x&&(h=this.modelToView(t.bounds()),o=Q(h.x,h.y).minus(Q((s-h.width-20)/2,r+n))),o?(this.canvas.translate||(o=o.minus(Q(this.scroller.scrollLeft,this.scroller.scrollTop))),o=this.viewToDocument(o),o=Q(vt.max(o.x,0),vt.max(o.y,0)),this.singleToolBar.showAt(o)):this._destroyToolBar())))},_toolBarClick:function(t){this.trigger("toolBarClick",t),this._destroyToolBar()},_mouseMove:function(t){if(!this.pauseMouseHandlers){var e=this._calculatePosition(t);0!==t.which&&1!=t.which||!this.toolService.move(e,this._meta(t))||t.preventDefault()}},_keydown:function(t){this.toolService.keyDown(t.keyCode,this._meta(t))&&t.preventDefault()},_wheel:function(t){var e=i(t),n=this._calculatePosition(t),o=B(this._meta(t),{delta:e});this.toolService.wheel(n,o)&&t.preventDefault()},_meta:function(t){return{ctrlKey:t.ctrlKey,metaKey:t.metaKey,altKey:t.altKey,shiftKey:t.shiftKey}},_calculatePosition:function(t){var i=t.pageX===e?t.originalEvent:t,n=new Q(i.pageX,i.pageY),o=this.documentToModel(n);return o},_normalizePointZoom:function(t){return t.times(1/this.zoom())},_initialize:function(){this.shapes=[],this._selectedItems=[],this.connections=[],this._dataMap={},this._connectionsDataMap={},this._inactiveShapeItems=new d,this._deferredConnectionUpdates=[],this.undoRedoService=new $({undone:this._syncHandler,redone:this._syncHandler}),this.id=E.randomId()},_fetchFreshData:function(){var t=this;t._dataSource(),t._isEditable&&t._connectionDataSource(),t.options.autoBind&&(t._isEditable?(this._loadingShapes=!0,this._loadingConnections=!0,t.dataSource.fetch(),t.connectionsDataSource.fetch()):t.dataSource.fetch())},_dataSource:function(){var t,e;ft(this.options.connectionsDataSource)?(this._isEditable=!0,t=this.options.dataSource||{},e=pt(t)?{data:t}:t,this.dataSource&&this._shapesRefreshHandler?this.dataSource.unbind("change",this._shapesRefreshHandler).unbind("requestStart",this._shapesRequestStartHandler).unbind("error",this._shapesErrorHandler):(this._shapesRefreshHandler=R(this._refreshShapes,this),this._shapesRequestStartHandler=R(this._shapesRequestStart,this),this._shapesErrorHandler=R(this._error,this)),this.dataSource=kendo.data.DataSource.create(e).bind("change",this._shapesRefreshHandler).bind("requestStart",this._shapesRequestStartHandler).bind("error",this._shapesErrorHandler)):(this._treeDataSource(),
this._isEditable=!1)},_connectionDataSource:function(){var t,e=this.options.connectionsDataSource;e&&(t=pt(e)?{data:e}:e,this.connectionsDataSource&&this._connectionsRefreshHandler?this.connectionsDataSource.unbind("change",this._connectionsRefreshHandler).unbind("requestStart",this._connectionsRequestStartHandler).unbind("error",this._connectionsErrorHandler):(this._connectionsRefreshHandler=R(this._refreshConnections,this),this._connectionsRequestStartHandler=R(this._connectionsRequestStart,this),this._connectionsErrorHandler=R(this._connectionsError,this)),this.connectionsDataSource=kendo.data.DataSource.create(t).bind("change",this._connectionsRefreshHandler).bind("requestStart",this._connectionsRequestStartHandler).bind("error",this._connectionsErrorHandler))},_shapesRequestStart:function(t){"read"==t.type&&(this._loadingShapes=!0)},_connectionsRequestStart:function(t){"read"==t.type&&(this._loadingConnections=!0)},_error:function(){this._loadingShapes=!1},_connectionsError:function(){this._loadingConnections=!1},_refreshShapes:function(t){"remove"===t.action?this._shouldRefresh()&&this._removeShapes(t.items):"itemchange"===t.action?this._shouldRefresh()&&this._updateShapes(t.items,t.field):"add"===t.action?this._inactiveShapeItems.add(t.items):"sync"===t.action?this._syncShapes(t.items):this.refresh()},_shouldRefresh:function(){return!this._suspended},_suspendModelRefresh:function(){this._suspended=(this._suspended||0)+1},_resumeModelRefresh:function(){this._suspended=vt.max((this._suspended||0)-1,0)},refresh:function(){this._loadingShapes=!1,this._loadingConnections||this._rebindShapesAndConnections()},_rebindShapesAndConnections:function(){this.clear(),this._addShapes(this.dataSource.view()),this.connectionsDataSource&&this._addConnections(this.connectionsDataSource.view(),!1),this.options.layout?this.layout(this.options.layout):this._redrawConnections(),this.trigger("dataBound")},refreshConnections:function(){this._loadingConnections=!1,this._loadingShapes||this._rebindShapesAndConnections()},_redrawConnections:function(){var t,e=this.connections;for(t=0;e.length>t;t++)e[t].refresh()},_removeShapes:function(t){var e,i,n=this._dataMap;for(i=0;t.length>i;i++)e=t[i],n[e.id]&&(this.remove(n[e.id],!1),n[e.id]=null)},_syncShapes:function(){var t=this,e=t._inactiveShapeItems;e.forEach(function(i){var n=i.dataItem,o=i.element;n.isNew()||(o?(o._setOptionsFromModel(),t.addShape(o,i.undoable),t._dataMap[n.id]=o):t._addDataItem(n),i.activate(),e.remove(n))})},_updateShapes:function(t,e){var i,n,o;for(i=0;t.length>i;i++)n=t[i],o=this._dataMap[n.id],o&&o.updateOptionsFromModel(n,e)},_addShapes:function(t){for(var e=0;t.length>e;e++)this._addDataItem(t[e],!1)},_refreshConnections:function(t){"remove"===t.action?this._shouldRefresh()&&this._removeConnections(t.items):"add"===t.action?this._addConnections(t.items):"sync"===t.action||("itemchange"===t.action?this._shouldRefresh()&&this._updateConnections(t.items):this.refreshConnections())},_removeConnections:function(t){for(var e=0;t.length>e;e++)this.remove(this._connectionsDataMap[t[e].uid],!1),this._connectionsDataMap[t[e].uid]=null},_updateConnections:function(t){var e,i,n;for(e=0;t.length>e;e++)i=t[e],n=this._connectionsDataMap[i.uid],n.updateOptionsFromModel(i)},_addConnections:function(t,e){var i,n,o=t.length;for(i=0;o>i;i++)n=t[i],this._addConnectionDataItem(n,e)},_addConnectionDataItem:function(t,e){var i,n,o,s;this._connectionsDataMap[t.uid]||(i=this._validateConnector(t.from),ft(i)&&null!==i||(i=new Q(t.fromX,t.fromY)),n=this._validateConnector(t.to),ft(n)&&null!==n||(n=new Q(t.toX,t.toY)),ft(i)&&ft(n)&&(o=B({},this.options.connectionDefaults),o.dataItem=t,s=new x(i,n,o),this._connectionsDataMap[t.uid]=s,this.addConnection(s,e)))},_validateConnector:function(t){var e;return ft(t)&&null!==t&&(e=this._dataMap[t]),e},_treeDataSource:function(){var t=this,e=t.options,i=e.dataSource;i=pt(i)?{data:i}:i,i.fields||(i.fields=[{field:"text"},{field:"url"},{field:"spriteCssClass"},{field:"imageUrl"}]),t.dataSource&&t._refreshHandler&&t._unbindDataSource(),t._refreshHandler=R(t._refreshSource,t),t._errorHandler=R(t._error,t),t.dataSource=O.create(i).bind(Ct,t._refreshHandler).bind(Pt,t._errorHandler)},_unbindDataSource:function(){var t=this;t.dataSource.unbind(Ct,t._refreshHandler).unbind(Pt,t._errorHandler)},_adorn:function(t,i){i!==e&&t&&(i?(this._adorners.push(t),this.adornerLayer.append(t.visual)):(st.remove(this._adorners,t),this.adornerLayer.remove(t.visual)))},_showConnectors:function(t,e){e?this._connectorsAdorner.show(t):this._connectorsAdorner.destroy()},_updateAdorners:function(){var t,e,i=this._adorners;for(t=0;i.length>t;t++)e=i[t],e.refreshBounds&&e.refreshBounds(),e.refresh()},_refresh:function(){for(var t=0;this.connections.length>t;t++)this.connections[t].refresh()},_destroyToolBar:function(){this.singleToolBar&&(this.singleToolBar.hide(),this.singleToolBar.destroy(),this.singleToolBar=null)},_destroyGlobalToolBar:function(){this.toolBar&&(this.toolBar.hide(),this.toolBar.destroy(),this.toolBar=null)},exportDOMVisual:function(){var t=this.canvas._viewBox,e=L.transform().translate(-t.x,-t.y),i=new L.Rect([0,0],[t.width,t.height]),n=I.Path.fromRect(i),o=new I.Group({transform:e}),s=new I.Group({clip:n}),r=this.canvas.drawingElement.children[0];return s.append(o),o.children.push(r),s},exportVisual:function(){var t=L.transform().scale(1/this._zoom),e=new I.Group({transform:t}),i=this.mainLayer.drawingElement;return e.children.push(i),e},_syncChanges:function(){this._syncShapeChanges(),this._syncConnectionChanges()},_syncShapeChanges:function(){this.dataSource&&this._isEditable&&this.dataSource.sync()},_syncConnectionChanges:function(){var e=this;e.connectionsDataSource&&e._isEditable&&(t.when.apply(t,e._deferredConnectionUpdates).then(function(){e.connectionsDataSource.sync()}),e.deferredConnectionUpdates=[])}}),P.ExportMixin.extend(C.fn,!0),kendo.PDFMixin&&kendo.PDFMixin.extend(C.fn),b=kendo.Observable.extend({init:function(t,e){kendo.Observable.fn.init.call(this),this.diagram=t,this.options=B({},this.options,e),this._tools=[],this.createToolBar(),this.createTools(),this.appendTools(),this.options.modal&&this.createPopup(),this.bind(this.events,e)},events:["click"],createPopup:function(){this.container=t("").append(this.element),this._popup=this.container.kendoPopup({}).getKendoPopup()},appendTools:function(){var t,e;for(t=0;this._tools.length>t;t++)e=this._tools[t],(e.buttons&&e.buttons.length||!ft(e.buttons))&&this._toolBar.add(e)},createToolBar:function(){this.element=t(""),this._toolBar=this.element.kendoToolBar({click:R(this.click,this),resizable:!1}).getKendoToolBar(),this.element.css("border","none")},createTools:function(){for(var t=0;this.options.tools.length>t;t++)this.createTool(this.options.tools[t])},createTool:function(t){var e=(_t(t)?t.name:t)+"Tool";this[e]?this[e](t):this._tools.push(t)},showAt:function(t){this._popup&&this._popup.open(t.x,t.y)},hide:function(){this._popup&&this._popup.close()},newGroup:function(){return{type:"buttonGroup",buttons:[]}},editTool:function(){this._tools.push({spriteCssClass:"k-icon k-i-pencil",showText:"overflow",type:"button",text:"Edit",attributes:this._setAttributes({action:"edit"})})},deleteTool:function(){this._tools.push({spriteCssClass:"k-icon k-i-close",showText:"overflow",type:"button",text:"Delete",attributes:this._setAttributes({action:"delete"})})},rotateAnticlockwiseTool:function(t){this._appendGroup("rotate"),this._rotateGroup.buttons.push({spriteCssClass:"k-icon k-i-rotateccw",showText:"overflow",text:"RotateAnticlockwise",group:"rotate",attributes:this._setAttributes({action:"rotateAnticlockwise",step:t.step})})},rotateClockwiseTool:function(t){this._appendGroup("rotate"),this._rotateGroup.buttons.push({spriteCssClass:"k-icon k-i-rotatecw",attributes:this._setAttributes({action:"rotateClockwise",step:t.step}),showText:"overflow",text:"RotateClockwise",group:"rotate"})},createShapeTool:function(){this._appendGroup("create"),this._createGroup.buttons.push({spriteCssClass:"k-icon k-i-shape",showText:"overflow",text:"CreateShape",group:"create",attributes:this._setAttributes({action:"createShape"})})},createConnectionTool:function(){this._appendGroup("create"),this._createGroup.buttons.push({spriteCssClass:"k-icon k-i-connector",showText:"overflow",text:"CreateConnection",group:"create",attributes:this._setAttributes({action:"createConnection"})})},undoTool:function(){this._appendGroup("history"),this._historyGroup.buttons.push({spriteCssClass:"k-icon k-i-undo",showText:"overflow",text:"Undo",group:"history",attributes:this._setAttributes({action:"undo"})})},redoTool:function(){this._appendGroup("history"),this._historyGroup.buttons.push({spriteCssClass:"k-icon k-i-redo",showText:"overflow",text:"Redo",group:"history",attributes:this._setAttributes({action:"redo"})})},_appendGroup:function(t){var e="_"+t+"Group";this[e]||(this[e]=this.newGroup(),this._tools.push(this[e]))},_setAttributes:function(t){var e={};return t.action&&(e[kendo.attr("action")]=t.action),t.step&&(e[kendo.attr("step")]=t.step),e},_getAttributes:function(t){var e,i={},n=t.attr(kendo.attr("action"));return n&&(i.action=n),e=t.attr(kendo.attr("step")),e&&(i.step=e),i},click:function(e){var i=this._getAttributes(t(e.target)),n=i.action;n&&this[n](i),this.trigger("click",this.eventData(n))},eventData:function(t){var e=this.selectedElements(),i=[],n=[];return e instanceof w?i.push(e):n.push(e),{shapes:i,connections:n,action:t}},"delete":function(){var t=this.diagram,e=t._triggerRemove(this.selectedElements());e.length&&(this.diagram.remove(e,!0),this.diagram._syncChanges())},edit:function(){this.diagram.edit(this.selectedElements()[0])},rotateClockwise:function(t){var e=parseFloat(t.step||90);this._rotate(e)},rotateAnticlockwise:function(t){var e=parseFloat(t.step||90);this._rotate(-e)},_rotate:function(t){var e=this.diagram._resizingAdorner;e.angle(e.angle()+t),e.rotate()},selectedElements:function(){return this.diagram.select()},createShape:function(){this.diagram.createShape()},createConnection:function(){this.diagram.createConnection()},undo:function(){this.diagram.undo()},redo:function(){this.diagram.redo()},destroy:function(){this.diagram=null,this.element=null,this.options=null,this._toolBar&&this._toolBar.destroy(),this._popup&&this._popup.destroy()}}),S=kendo.Observable.extend({init:function(t,e){kendo.Observable.fn.init.call(this),this.options=A(!0,{},this.options,e),this.element=t,this.model=this.options.model,this.fields=this._getFields(),this._initContainer(),this.createEditable()},options:{editors:{}},_initContainer:function(){this.wrapper=this.element},createEditable:function(){var t=this.options;this.editable=new kendo.ui.Editable(this.wrapper,{fields:this.fields,target:t.target,clearContainer:!1,model:this.model})},_isEditable:function(t){return this.model.editable&&this.model.editable(t)},_getFields:function(){var t,e,i,n=[],o=this.model.fields;for(t in o)e={},this._isEditable(t)&&(i=this.options.editors[t],i&&(e.editor=i),e.field=t,n.push(e));return n},end:function(){return this.editable.end()},destroy:function(){this.editable.destroy(),this.editable.element.find("["+kendo.attr("container-for")+"]").empty(),this.model=this.wrapper=this.element=this.columns=this.editable=null}}),k=S.extend({init:function(t,e){S.fn.init.call(this,t,e),this.bind(this.events,this.options),this.open()},events:["update","cancel"],options:{window:{modal:!0,resizable:!1,draggable:!0,title:"Edit",visible:!1}},_initContainer:function(){var e,i=this;this.wrapper=t('').attr(kendo.attr("uid"),this.model.uid),e="",this.options.template?(e+=this._renderTemplate(),this.fields=[]):e+=this._renderFields(),e+=this._renderButtons(),this.wrapper.append(t('').append(e)),this.window=new kendo.ui.Window(this.wrapper.appendTo(this.element),this.options.window),this.window.bind("close",function(t){t.userTriggered&&(t.sender.element.focus(),i._cancelClick(t))}),this._attachButtonEvents()},_renderTemplate:function(){var t=this.options.template;return"string"==typeof t&&(t=window.unescape(t)),t=kendo.template(t)(this.model)},_renderFields:function(){var t,e,i="";for(t=0;this.fields.length>t;t++)e=this.fields[t],i+='",this._isEditable(e.field)&&(i+="');return i},_renderButtons:function(){var t='';return t+=this._createButton("update"),t+=this._createButton("cancel"),t+="
"},_createButton:function(t){return kendo.template(de)(_[t])},_attachButtonEvents:function(){this._cancelClickHandler=R(this._cancelClick,this),this.window.element.on(bt+yt,"a.k-diagram-cancel",this._cancelClickHandler),this._updateClickHandler=R(this._updateClick,this),this.window.element.on(bt+yt,"a.k-diagram-update",this._updateClickHandler)},_updateClick:function(t){t.preventDefault(),this.trigger("update")},_cancelClick:function(t){t.preventDefault(),this.trigger("cancel")},open:function(){this.window.center().open()},close:function(){this.window.bind("deactivate",R(this.destroy,this)).close()},destroy:function(){this.window.close().destroy(),this.window.element.off(bt+yt,"a.k-diagram-cancel",this._cancelClickHandler),this.window.element.off(bt+yt,"a.k-diagram-update",this._updateClickHandler),this._cancelClickHandler=null,this._editUpdateClickHandler=null,this.window=null,S.fn.destroy.call(this)}}),c.fn=c.prototype={onActivate:function(e){var i=t.Deferred();return this.callbacks.push({callback:e,deferred:i}),i},activate:function(){var t,e,i=this.callbacks;for(e=0;i.length>e;e++)t=this.callbacks[e],t.callback(this.dataItem),t.deferred.resolve();this.callbacks=[]}},d.fn=d.prototype={add:function(t){for(var e=0;t.length>e;e++)this.items[t[e].uid]=new c(t[e])},forEach:function(t){for(var e in this.items)t(this.items[e])},getByUid:function(t){return this.items[t]},remove:function(t){delete this.items[t.uid]}},T=N.extend({init:function(){this.shapes=[]},_add:function(t,e){this.shapes.push({bounds:e,shape:t}),t._quadNode=this},insert:function(t,e){this._add(t,e)},remove:function(t){var e,i=this.shapes,n=i.length;for(e=0;n>e;e++)if(i[e].shape===t){i.splice(e,1);break}},hitTestRect:function(t){var e,i=this.shapes,n=i.length;for(e=0;n>e;e++)if(this._testRect(i[e].shape,t))return!0},_testRect:function(t,e){var i,n=t.rotate().angle,o=t.bounds();return i=n?J.rects(e,o,-n):o.overlaps(e)}}),M=T.extend({init:function(t){T.fn.init.call(this),this.children=[],this.rect=t},inBounds:function(t){var e=this.rect,i=e.bottomRight(),n=t.bottomRight(),o=t.x>=e.x&&t.y>=e.y&&i.x>=n.x&&i.y>=n.y;return o},overlapsBounds:function(t){return this.rect.overlaps(t)},insert:function(t,e){var i,n=!1,o=this.children,s=o.length;if(this.inBounds(e)){if(!s&&4>this.shapes.length)this._add(t,e);else{for(s||this._initChildren(),i=0;o.length>i;i++)if(o[i].insert(t,e)){n=!0;break}n||this._add(t,e)}n=!0}return n},_initChildren:function(){var t,e,i=this.rect,n=this.children,o=this.shapes,s=i.center(),r=i.width/2,a=i.height/2;for(n.push(new M(new q(i.x,i.y,r,a)),new M(new q(s.x,i.y,r,a)),new M(new q(i.x,s.y,r,a)),new M(new q(s.x,s.y,r,a))),e=o.length-1;e>=0;e--)for(t=0;n.length>t;t++)if(n[t].insert(o[e].shape,o[e].bounds)){o.splice(e,1);break}},hitTestRect:function(t){var e,i=this.children,n=i.length,o=!1;if(this.overlapsBounds(t))if(T.fn.hitTestRect.call(this,t))o=!0;else for(e=0;n>e;e++)if(i[e].hitTestRect(t)){o=!0;break}return o}}),D=N.extend({ROOT_SIZE:1e3,init:function(t){var e=R(this._boundsChange,this);t.bind(xt,e),t.bind(At,e),this.initRoots()},initRoots:function(){this.rootMap={},this.root=new T},clear:function(){this.initRoots()},_boundsChange:function(t){t.item._quadNode&&t.item._quadNode.remove(t.item),this.insert(t.item)},insert:function(t){var e=t.bounds(ee),i=this.ROOT_SIZE,n=this.getSectors(e),o=n[0][0],s=n[1][0];this.inRoot(n)?this.root.insert(t,e):(this.rootMap[o]||(this.rootMap[o]={}),this.rootMap[o][s]||(this.rootMap[o][s]=new M(new q(o*i,s*i,i,i))),this.rootMap[o][s].insert(t,e))},remove:function(t){t._quadNode&&t._quadNode.remove(t)},inRoot:function(t){return t[0].length>1||t[1].length>1},getSectors:function(t){var e,i,n=this.ROOT_SIZE,o=t.bottomRight(),s=vt.floor(o.x/n),r=vt.floor(o.y/n),a=[[],[]];for(e=vt.floor(t.x/n);s>=e;e++)a[0].push(e);for(i=vt.floor(t.y/n);r>=i;i++)a[1].push(i);return a},hitTestRect:function(t){var e,i,n,o,s,r=this.getSectors(t);if(this.root.hitTestRect(t))return!0;for(e=0;r[0].length>e;e++)for(n=r[0][e],i=0;r[1].length>i;i++)if(o=r[1][i],s=(this.rootMap[n]||{})[o],s&&s.hitTestRect(t))return!0;return!1}}),P.ui.plugin(C),B(E,{Shape:w,Connection:x,Connector:y,DiagramToolBar:b,QuadNode:M,QuadRoot:T,ShapesQuadTree:D,PopupEditor:k})}(window.kendo.jQuery)},"function"==typeof define&&define.amd?define:function(t,e,i){(i||e)()}),function(t,define){define("kendo.dataviz.diagram.min",["kendo.data.min","kendo.draganddrop.min","kendo.userevents.min","kendo.mobile.scroller.min","kendo.drawing.min","dataviz/diagram/utils.min","dataviz/diagram/math.min","dataviz/diagram/svg.min","dataviz/diagram/services.min","dataviz/diagram/layout.min","dataviz/diagram/dom.min"],t)}(function(){},"function"==typeof define&&define.amd?define:function(t,e,i){(i||e)()});
//# sourceMappingURL=kendo.dataviz.diagram.min.js.map