text: /*
  * Kendo UI v2015.2.624 (http://www.telerik.com/kendo-ui)
  * Copyright 2015 Telerik AD. All rights reserved.
  *
  * Kendo UI commercial licenses may be obtained at
  * http://www.telerik.com/purchase/license-agreement/kendo-ui-complete
  * If you do not own a commercial license, this file shall be governed by the trial license terms.
  */
  !function(e,define){define(["./kendo.data.min","./kendo.draganddrop.min","./kendo.userevents.min","./kendo.mobile.scroller.min","./kendo.drawing.min","./kendo.core.min","./kendo.dataviz.core.min","./kendo.toolbar.min","./kendo.editable.min","./kendo.window.min","./kendo.dropdownlist.min","./kendo.dataviz.themes.min"],e)}(function(){return function(e,t){function n(e,n,i){function r(e){for(var t=1;e*t%1;)t*=10;return t}var o,a,s,l;if(t===e||t===n)return[];if(i&&u.sign(n-e)!=u.sign(i))throw"The sign of the increment should allow to reach the stop-value.";if(i=i||1,e=e||0,n=n||e,(n-e)/i===1/0)throw"Infinite range defined.";if(o=[],a=-1,l=r(Math.abs(i)),e*=l,n*=l,i*=l,e>n&&i>0&&(i=-i),0>i)for(;(s=e+i*++a)>=n;)o.push(s/l);else for(;(s=e+i*++a)<=n;)o.push(s/l);return o}function i(e,t){if(e==t)return 0;var n=t.x-e.x,i=e.y-t.y,r=Math.atan(n/i);return i>=0?0>n?r+2*Math.PI:r:r+Math.PI}var r,o,a=window.kendo,s=a.dataviz.diagram={},l=a.deepExtend,c=e.isArray,d=1e-6,u={};l(u,{isNearZero:function(e){return Math.abs(e)<d},isDefined:function(e){return t!==e},isUndefined:function(e){return t===e||null===e},isObject:function(e){return e===Object(e)},has:function(e,t){return Object.hasOwnProperty.call(e,t)},isString:function(e){return"[object String]"==Object.prototype.toString.call(e)},isBoolean:function(e){return"[object Boolean]"==Object.prototype.toString.call(e)},isType:function(e,t){return Object.prototype.toString.call(e)=="[object "+t+"]"},isNumber:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},isEmpty:function(e){if(null===e)return!0;if(c(e)||u.isString(e))return 0===e.length;for(var t in e)if(u.has(e,t))return!1;return!0},simpleExtend:function(e,t){if(u.isObject(t))for(var n in t)e[n]=t[n]},initArray:function(e,t){var n,i=[];for(n=0;e>n;++n)i[n]=t;return i},serializePoints:function(e){var t,n,i=[];for(t=0;e.length>t;t++)n=e[t],i.push(n.x+";"+n.y);return i.join(";")},deserializePoints:function(e){var t,n=e.split(";"),i=[];if(n.length%2!==0)throw"Not an array of points.";for(t=0;n.length>t;t+=2)i.push(new s.Point(parseInt(n[t],10),parseInt(n[t+1],10)));return i},randomInteger:function(e,t){return parseInt(Math.floor(Math.random()*t)+e,10)},DFT:function(e,t){var n,i;if(t(e),e.childNodes)for(n=0;e.childNodes.length>n;n++)i=e.childNodes[n],this.DFT(i,t)},getMatrixAngle:function(e){return null===e||0===e.d?0:180*Math.atan2(e.b,e.d)/Math.PI},getMatrixScaling:function(e){var t=Math.sqrt(e.a*e.a+e.c*e.c),n=Math.sqrt(e.b*e.b+e.d*e.d);return[t,n]}}),u.sign=function(e){return e?0>e?-1:1:0},u.findAngle=function(e,t){return 180*i(e,t)/Math.PI},u.forEach=function(e,t,n){for(var i=0;e.length>i;i++)t.call(n,e[i],i,e)},u.any=function(e,t){for(var n=0;e.length>n;++n)if(t(e[n]))return e[n];return null},u.remove=function(e,t){for(var n;-1!==(n=u.indexOf(e,t));)e.splice(n,1);return e},u.contains=function(e,t){return-1!==u.indexOf(e,t)},u.indexOf=function(t,n){return e.inArray(n,t)},u.fold=function(e,t,n,i){var r,o,a=arguments.length>2;for(r=0;e.length>r;r++)o=e[r],a?n=t.call(i,n,o,r,e):(n=o,a=!0);if(!a)throw"Reduce of empty array with no initial value";return n},u.find=function(e,t,n){var i;return u.any(e,function(e,r,o){return t.call(n,e,r,o)?(i=e,!0):!1}),i},u.first=function(e,t,n){return 0===e.length?null:u.isUndefined(t)?e[0]:u.find(e,t,n)},u.insert=function(e,t,n){return e.splice(n,0,t),e},u.all=function(e,t,n){var i,r,o=!0;for(r=0;e.length>r&&(i=e[r],o=o&&t.call(n,i,r,e),o);r++);return o},u.clear=function(e){e.splice(0,e.length)},u.bisort=function(e,t,n){if(u.isUndefined(e))throw"First array is not specified.";if(u.isUndefined(t))throw"Second array is not specified.";if(e.length!=t.length)throw"The two arrays should have equal length";var i,r=[];for(i=0;e.length>i;i++)r.push({x:e[i],y:t[i]});for(r.sort(u.isUndefined(n)?function(e,t){return e.x-t.x}:function(e,t){return n(e.x,t.x)}),u.clear(e),u.clear(t),i=0;r.length>i;i++)e.push(r[i].x),t.push(r[i].y)},u.addRange=function(e,t){e.push.apply(e,t)},r={easeInOut:function(e){return-Math.cos(e*Math.PI)/2+.5}},o=a.Class.extend({init:function(){this.adapters=[],this.target=0,this.tick=0,this.interval=20,this.duration=800,this.lastTime=null,this.handlers=[];var e=this;this.transition=r.easeInOut,this.timerDelegate=function(){e.onTimerEvent()}},addAdapter:function(e){this.adapters.push(e)},onComplete:function(e){this.handlers.push(e)},removeHandler:function(t){this.handlers=e.grep(this.handlers,function(e){return e!==t})},trigger:function(){var e=this;this.handlers&&u.forEach(this.handlers,function(t){return t.call(null!==e.caller?e.caller:e)})},onStep:function(){},seekTo:function(e){this.seekFromTo(this.tick,e)},seekFromTo:function(e,t){this.target=Math.max(0,Math.min(1,t)),this.tick=Math.max(0,Math.min(1,e)),this.lastTime=(new Date).getTime(),this.intervalId||(this.intervalId=window.setInterval(this.timerDelegate,this.interval))},stop:function(){this.intervalId&&(window.clearInterval(this.intervalId),this.intervalId=null,this.trigger())},play:function(e){0!==this.adapters.length&&(null!==e&&(this.caller=e),this.initState(),this.seekFromTo(0,1))},reverse:function(){this.seekFromTo(1,0)},initState:function(){if(0!==this.adapters.length)for(var e=0;this.adapters.length>e;e++)this.adapters[e].initState()},propagate:function(){var e,t=this.transition(this.tick);for(e=0;this.adapters.length>e;e++)this.adapters[e].update(t)},onTimerEvent:function(){var e,t=(new Date).getTime(),n=t-this.lastTime;this.lastTime=t,e=n/this.duration*(this.target>this.tick?1:-1),Math.abs(e)>=Math.abs(this.tick-this.target)?this.tick=this.target:this.tick+=e;try{this.propagate()}finally{this.onStep.call(this),this.target==this.tick&&this.stop()}}}),a.deepExtend(s,{init:function(e){a.init(e,s.ui)},Utils:u,Range:n,Ticker:o})}(window.kendo.jQuery),function(e,t){function n(e){return Math.abs(e)<F}function i(e,t,i,r,o){var a,s,l,c,d=(t.x-e.x)*(r.y-i.y)-(t.y-e.y)*(r.x-i.x);if(!n(d)&&(a=(e.y-i.y)*(r.x-i.x)-(e.x-i.x)*(r.y-i.y),s=(e.y-i.y)*(t.x-e.x)-(e.x-i.x)*(t.y-e.y),l=a/d,c=s/d,!o||!(0>l||l>1||0>c||c>1)))return new A(e.x+l*(t.x-e.x),e.y+l*(t.y-e.y))}function r(e,t){var n,i,r;do n=2*Math.random()-1,i=2*Math.random()-1,r=n*n+i*i;while(!r||r>1);return e+t*n*Math.sqrt(-2*Math.log(r)/r)}function o(e){var t,n,i;for(D.isUndefined(e)&&(e=10),t="",n="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",i=e;i>0;--i)t+=n.charAt(Math.round(Math.random()*(n.length-1)));return t}var a,s,l,c,d,u,h,p,f,g,m,v,_,y,w,b,x=window.kendo,k=x.dataviz.diagram,C=x.Class,S=x.deepExtend,T=x.dataviz,D=k.Utils,A=T.Point2D,M=x.isFunction,I=D.contains,P=e.map,E=3,F=1e-6;S(A.fn,{plus:function(e){return new A(this.x+e.x,this.y+e.y)},minus:function(e){return new A(this.x-e.x,this.y-e.y)},offset:function(e){return new A(this.x-e,this.y-e)},times:function(e){return new A(this.x*e,this.y*e)},normalize:function(){return 0===this.length()?new A:this.times(1/this.length())},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},toString:function(){return"("+this.x+","+this.y+")"},lengthSquared:function(){return this.x*this.x+this.y*this.y},middleOf:function(e,t){return new A(t.x-e.x,t.y-e.y).times(.5).plus(e)},toPolar:function(e){var t,n,i,r=1;if(e&&(r=180/Math.PI),t=Math.atan2(Math.abs(this.y),Math.abs(this.x)),n=Math.PI/2,i=this.length(),0===this.x){if(0===this.y)return new u(0,0);if(this.y>0)return new u(i,r*n);if(0>this.y)return new u(i,3*r*n)}else if(this.x>0){if(0===this.y)return new u(i,0);if(this.y>0)return new u(i,r*t);if(0>this.y)return new u(i,r*(4*n-t))}else{if(0===this.y)return new u(i,2*n);if(this.y>0)return new u(i,r*(2*n-t));if(0>this.y)return new u(i,r*(2*n+t))}},isOnLine:function(e,t){var n,i,r,o,a;return e.x>t.x&&(n=t,t=e,e=n),i=new s(e.x,e.y).inflate(E,E),r=new s(t.x,t.y).inflate(E,E),i.union(r).contains(this)?e.x===t.x||e.y===t.y?!0:(t.y>e.y?(o=i.x+(r.x-i.x)*(this.y-(i.y+i.height))/(r.y+r.height-(i.y+i.height)),a=i.x+i.width+(r.x+r.width-(i.x+i.width))*(this.y-i.y)/(r.y-i.y)):(o=i.x+(r.x-i.x)*(this.y-i.y)/(r.y-i.y),a=i.x+i.width+(r.x+r.width-(i.x+i.width))*(this.y-(i.y+i.height))/(r.y+r.height-(i.y+i.height))),this.x>o&&a>this.x):!1}}),S(A,{parse:function(e){var n=e.slice(1,e.length-1),i=n.split(","),r=parseInt(i[0],10),o=parseInt(i[1],10);return isNaN(r)||isNaN(o)?t:new A(r,o)}}),a=C.extend({init:function(e,t,n){this.point=e,this.left=t,this.right=n}}),s=C.extend({init:function(e,t,n,i){this.x=e||0,this.y=t||0,this.width=n||0,this.height=i||0},contains:function(e){return e.x>=this.x&&this.x+this.width>=e.x&&e.y>=this.y&&this.y+this.height>=e.y},inflate:function(e,n){return n===t&&(n=e),this.x-=e,this.y-=n,this.width+=2*e+1,this.height+=2*n+1,this},offset:function(e,t){var n=e,i=t;return e instanceof A&&(n=e.x,i=e.y),this.x+=n,this.y+=i,this},union:function(e){var t=Math.min(this.x,e.x),n=Math.min(this.y,e.y),i=Math.max(this.x+this.width,e.x+e.width),r=Math.max(this.y+this.height,e.y+e.height);return new s(t,n,i-t,r-n)},center:function(){return new A(this.x+this.width/2,this.y+this.height/2)},top:function(){return new A(this.x+this.width/2,this.y)},right:function(){return new A(this.x+this.width,this.y+this.height/2)},bottom:function(){return new A(this.x+this.width/2,this.y+this.height)},left:function(){return new A(this.x,this.y+this.height/2)},topLeft:function(){return new A(this.x,this.y)},topRight:function(){return new A(this.x+this.width,this.y)},bottomLeft:function(){return new A(this.x,this.y+this.height)},bottomRight:function(){return new A(this.x+this.width,this.y+this.height)},clone:function(){return new s(this.x,this.y,this.width,this.height)},isEmpty:function(){return!this.width&&!this.height},equals:function(e){return this.x===e.x&&this.y===e.y&&this.width===e.width&&this.height===e.height},rotatedBounds:function(e){var t=this.clone(),n=this.rotatedPoints(e),i=n[0],r=n[1],o=n[2],a=n[3];return t.x=Math.min(o.x,i.x,r.x,a.x),t.y=Math.min(o.y,i.y,r.y,a.y),t.width=Math.max(o.x,i.x,r.x,a.x)-t.x,t.height=Math.max(o.y,i.y,r.y,a.y)-t.y,t},rotatedPoints:function(e){var t=this,n=t.center(),i=t.bottomRight().rotate(n,360-e),r=t.topLeft().rotate(n,360-e),o=t.topRight().rotate(n,360-e),a=t.bottomLeft().rotate(n,360-e);return[r,o,i,a]},toString:function(e){return e=e||" ",this.x+e+this.y+e+this.width+e+this.height},scale:function(e,t,n,i,r){var o,a,s,l=this.topLeft(),c=this.center();l.rotate(c,360-r).rotate(i,r),o=n.minus(l),a=new A(o.x*e,o.y*t),s=o.minus(a),l=l.plus(s),l.rotate(i,360-r).rotate(c,r),this.x=l.x,this.y=l.y,this.width*=e,this.height*=t},zoom:function(e){return this.x*=e,this.y*=e,this.width*=e,this.height*=e,this}}),l=C.extend({init:function(e,t){this.width=e,this.height=t}}),l.prototype.Empty=new l(0,0),s.toRect=function(e){return e instanceof s||(e=new s(e.x,e.y,e.width,e.height)),e},s.empty=function(){return new s(0,0,0,0)},s.fromPoints=function(e,t){if(isNaN(e.x)||isNaN(e.y)||isNaN(t.x)||isNaN(t.y))throw"Some values are NaN.";return new s(Math.min(e.x,t.x),Math.min(e.y,t.y),Math.abs(e.x-t.x),Math.abs(e.y-t.y))},c={lines:function(e,t,n,r){return i(e,t,n,r)},segments:function(e,t,n,r){return i(e,t,n,r,!0)},rectWithLine:function(e,t,n){return c.segments(t,n,e.topLeft(),e.topRight())||c.segments(t,n,e.topRight(),e.bottomRight())||c.segments(t,n,e.bottomLeft(),e.bottomRight())||c.segments(t,n,e.topLeft(),e.bottomLeft())},rects:function(e,t,n){var i,r,o=t.topLeft(),a=t.topRight(),s=t.bottomLeft(),l=t.bottomRight(),d=t.center();return n&&(o=o.rotate(d,n),a=a.rotate(d,n),s=s.rotate(d,n),l=l.rotate(d,n)),i=e.contains(o)||e.contains(a)||e.contains(s)||e.contains(l)||c.rectWithLine(e,o,a)||c.rectWithLine(e,o,s)||c.rectWithLine(e,a,l)||c.rectWithLine(e,s,l),i||(o=e.topLeft(),a=e.topRight(),s=e.bottomLeft(),l=e.bottomRight(),n&&(r=360-n,o=o.rotate(d,r),a=a.rotate(d,r),s=s.rotate(d,r),l=l.rotate(d,r)),i=t.contains(o)||t.contains(a)||t.contains(s)||t.contains(l)),i}},d=C.extend({init:function(e){this.container=s.toRect(e)},align:function(e,t){var n,i=t.toLowerCase().split(" ");for(n=0;i.length>n;n++)e=this._singleAlign(e,i[n]);return e},_singleAlign:function(e,t){return M(this[t])?this[t](e):e},left:function(e){return this._align(e,this._left)},center:function(e){return this._align(e,this._center)},right:function(e){return this._align(e,this._right)},stretch:function(e){return this._align(e,this._stretch)},top:function(e){return this._align(e,this._top)},middle:function(e){return this._align(e,this._middle)},bottom:function(e){return this._align(e,this._bottom)},_left:function(e,t){t.x=e.x},_center:function(e,t){t.x=(e.width-t.width)/2||0},_right:function(e,t){t.x=e.width-t.width},_top:function(e,t){t.y=e.y},_middle:function(e,t){t.y=(e.height-t.height)/2||0},_bottom:function(e,t){t.y=e.height-t.height},_stretch:function(e,t){t.x=0,t.y=0,t.height=e.height,t.width=e.width},_align:function(e,t){return e=s.toRect(e),t(this.container,e),e}}),u=C.extend({init:function(e,t){this.r=e,this.angle=t}}),h=C.extend({init:function(e,t,n,i,r,o){this.a=e||0,this.b=t||0,this.c=n||0,this.d=i||0,this.e=r||0,this.f=o||0},plus:function(e){this.a+=e.a,this.b+=e.b,this.c+=e.c,this.d+=e.d,this.e+=e.e,this.f+=e.f},minus:function(e){this.a-=e.a,this.b-=e.b,this.c-=e.c,this.d-=e.d,this.e-=e.e,this.f-=e.f},times:function(e){return new h(this.a*e.a+this.c*e.b,this.b*e.a+this.d*e.b,this.a*e.c+this.c*e.d,this.b*e.c+this.d*e.d,this.a*e.e+this.c*e.f+this.e,this.b*e.e+this.d*e.f+this.f)},apply:function(e){return new A(this.a*e.x+this.c*e.y+this.e,this.b*e.x+this.d*e.y+this.f)},applyRect:function(e){return s.fromPoints(this.apply(e.topLeft()),this.apply(e.bottomRight()))},toString:function(){return"matrix("+this.a+" "+this.b+" "+this.c+" "+this.d+" "+this.e+" "+this.f+")"}}),S(h,{fromSVGMatrix:function(e){var t=new h;return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.e=e.e,t.f=e.f,t},fromMatrixVector:function(e){var t=new h;return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.e=e.e,t.f=e.f,t},fromList:function(e){if(6!==e.length)throw"The given list should consist of six elements.";var t=new h;return t.a=e[0],t.b=e[1],t.c=e[2],t.d=e[3],t.e=e[4],t.f=e[5],t},translation:function(e,t){var n=new h;return n.a=1,n.b=0,n.c=0,n.d=1,n.e=e,n.f=t,n},unit:function(){return new h(1,0,0,1,0,0)},rotation:function(e,t,n){var i=new h;return i.a=Math.cos(e*Math.PI/180),i.b=Math.sin(e*Math.PI/180),i.c=-i.b,i.d=i.a,i.e=t-t*i.a+n*i.b||0,i.f=n-n*i.a-t*i.b||0,i},scaling:function(e,t){var n=new h;return n.a=e,n.b=0,n.c=0,n.d=t,n.e=0,n.f=0,n},parse:function(e){var t,n;if(e){if(e=e.trim(),"matrix"===e.slice(0,6).toLowerCase()){if(n=e.slice(7,e.length-1).trim(),t=n.split(","),6===t.length)return h.fromList(P(t,function(e){return parseFloat(e)}));if(t=n.split(" "),6===t.length)return h.fromList(P(t,function(e){return parseFloat(e)}))}if("("===e.slice(0,1)&&")"===e.slice(e.length-1)&&(e=e.substr(1,e.length-1)),e.indexOf(",")>0&&(t=e.split(","),6===t.length))return h.fromList(P(t,function(e){return parseFloat(e)}));if(e.indexOf(" ")>0&&(t=e.split(" "),6===t.length))return h.fromList(P(t,function(e){return parseFloat(e)}))}return t}}),p=C.extend({init:function(e,t,n,i,r,o){this.a=e||0,this.b=t||0,this.c=n||0,this.d=i||0,this.e=r||0,this.f=o||0},fromMatrix:function(e){var t=new p;return t.a=e.a,t.b=e.b,t.c=e.c,t.d=e.d,t.e=e.e,t.f=e.f,t}}),f={_distanceToLineSquared:function(e,t,n){function i(e,t){return(e.x-t.x)*(e.x-t.x)+(e.y-t.y)*(e.y-t.y)}if(t===n)return i(e,t);var r=n.x-t.x,o=n.y-t.y,a=(e.x-t.x)*r+(e.y-t.y)*o;return 0>a?i(t,e):(a=(n.x-e.x)*r+(n.y-e.y)*o,0>a?i(n,e):(a=(n.x-e.x)*o-(n.y-e.y)*r,a*a/(r*r+o*o)))},distanceToLine:function(e,t,n){return Math.sqrt(this._distanceToLineSquared(e,t,n))},distanceToPolyline:function(e,t){var n,i,r,o,a=Number.MAX_VALUE;if(D.isUndefined(t)||0===t.length)return Number.MAX_VALUE;for(n=0;t.length-1>n;n++)i=t[n],r=t[n+1],o=this._distanceToLineSquared(e,i,r),a>o&&(a=o);return Math.sqrt(a)}},g=x.Class.extend({init:function(){this._buckets=[],this.length=0},add:function(e,t){var n=this._createGetBucket(e);return D.isDefined(t)&&(n.value=t),n},get:function(e){return this._bucketExists(e)?this._createGetBucket(e):null},set:function(e,t){this.add(e,t)},containsKey:function(e){return this._bucketExists(e)},remove:function(e){if(this._bucketExists(e)){var t=this._hash(e);return delete this._buckets[t],this.length--,e}},forEach:function(e){var t,n,i,r,o=this._hashes();for(t=0,n=o.length;n>t;t++)i=o[t],r=this._buckets[i],D.isUndefined(r)||e(r)},clone:function(){var e,t,n,i,r=new g,o=this._hashes();for(e=0,t=o.length;t>e;e++)n=o[e],i=this._buckets[n],D.isUndefined(i)||r.add(i.key,i.value);return r},_hashes:function(){var e,t=[];for(e in this._buckets)this._buckets.hasOwnProperty(e)&&t.push(e);return t},_bucketExists:function(e){var t=this._hash(e);return D.isDefined(this._buckets[t])},_createGetBucket:function(e){var t=this._hash(e),n=this._buckets[t];return D.isUndefined(n)&&(n={key:e},this._buckets[t]=n,this.length++),n},_hash:function(e){if(D.isNumber(e))return e;if(D.isString(e))return this._hashString(e);if(D.isObject(e))return this._objectHashId(e);throw"Unsupported key type."},_hashString:function(e){var t,n,i=0;if(0===e.length)return i;for(t=0;e.length>t;t++)n=e.charCodeAt(t),i=32*i-i+n;return i},_objectHashId:function(e){var t=e._hashId;return D.isUndefined(t)&&(t=o(),e._hashId=t),t}}),m=x.Observable.extend({init:function(t){var n,i=this;if(x.Observable.fn.init.call(i),this._hashTable=new g,this.length=0,D.isDefined(t))if(e.isArray(t))for(n=0;t.length>n;n++)this.add(t[n]);else t.forEach(function(e,t){this.add(e,t)},this)},add:function(e,t){var n=this._hashTable.get(e);n||(n=this._hashTable.add(e),this.length++,this.trigger("changed")),n.value=t},set:function(e,t){this.add(e,t)},get:function(e){var t=this._hashTable.get(e);if(t)return t.value;throw Error("Cannot find key "+e)},containsKey:function(e){return this._hashTable.containsKey(e)},remove:function(e){return this.containsKey(e)?(this.trigger("changed"),this.length--,this._hashTable.remove(e)):t},forEach:function(e,t){this._hashTable.forEach(function(n){e.call(t,n.key,n.value)})},forEachValue:function(e,t){this._hashTable.forEach(function(n){e.call(t,n.value)})},forEachKey:function(e,t){this._hashTable.forEach(function(n){e.call(t,n.key)})},keys:function(){var e=[];return this.forEachKey(function(t){e.push(t)}),e}}),v=x.Class.extend({init:function(){this._tail=null,this._head=null,this.length=0},enqueue:function(e){var t={value:e,next:null};this._head?(this._tail.next=t,this._tail=this._tail.next):(this._head=t,this._tail=this._head),this.length++},dequeue:function(){if(1>this.length)throw Error("The queue is empty.");var e=this._head.value;return this._head=this._head.next,this.length--,e},contains:function(e){for(var t=this._head;t;){if(t.value===e)return!0;t=t.next}return!1}}),_=x.Observable.extend({init:function(e){var t=this;x.Observable.fn.init.call(t),this._hashTable=new g,this.length=0,D.isDefined(e)&&(e instanceof g?e.forEach(function(e){this.add(e)}):e instanceof m&&e.forEach(function(e,t){this.add({key:e,value:t})},this))},contains:function(e){return this._hashTable.containsKey(e)},add:function(e){var t=this._hashTable.get(e);t||(this._hashTable.add(e,e),this.length++,this.trigger("changed"))},get:function(e){return this.contains(e)?this._hashTable.get(e).value:null},hash:function(e){return this._hashTable._hash(e)},remove:function(e){this.contains(e)&&(this._hashTable.remove(e),this.length--,this.trigger("changed"))},forEach:function(e,t){this._hashTable.forEach(function(t){e(t.value)},t)},toArray:function(){var e=[];return this.forEach(function(t){e.push(t)}),e}}),y=x.Class.extend({init:function(e,t){if(this.links=[],this.outgoing=[],this.incoming=[],this.weight=1,this.id=D.isDefined(e)?e:o(),D.isDefined(t)){this.associatedShape=t;var n=t.bounds();this.width=n.width,this.height=n.height,this.x=n.x,this.y=n.y}else this.associatedShape=null;this.data=null,this.type="Node",this.shortForm="Node '"+this.id+"'",this.isVirtual=!1},isIsolated:function(){return D.isEmpty(this.links)},bounds:function(e){return D.isDefined(e)?(this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,t):new k.Rect(this.x,this.y,this.width,this.height)},isLinkedTo:function(e){var t=this;return D.any(t.links,function(n){return n.getComplement(t)===e})},getChildren:function(){var e,t,n,i;if(0===this.outgoing.length)return[];for(e=[],t=0,n=this.outgoing.length;n>t;t++)i=this.outgoing[t],e.push(i.getComplement(this));return e},getParents:function(){var e,t,n,i;if(0===this.incoming.length)return[];for(e=[],t=0,n=this.incoming.length;n>t;t++)i=this.incoming[t],e.push(i.getComplement(this));return e},clone:function(){var e=new y;return D.isDefined(this.weight)&&(e.weight=this.weight),D.isDefined(this.balance)&&(e.balance=this.balance),D.isDefined(this.owner)&&(e.owner=this.owner),e.associatedShape=this.associatedShape,e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e},adjacentTo:function(e){return null!==this.isLinkedTo(e)},removeLink:function(e){e.source===this&&(D.remove(this.links,e),D.remove(this.outgoing,e),e.source=null),e.target===this&&(D.remove(this.links,e),D.remove(this.incoming,e),e.target=null)},hasLinkTo:function(e){return D.any(this.outgoing,function(t){return t.target===e})},degree:function(){return this.links.length},incidentWith:function(e){return I(this.links,e)},getLinksWith:function(e){return D.all(this.links,function(t){return t.getComplement(this)===e},this)},getNeighbors:function(){var e=[];return D.forEach(this.incoming,function(t){e.push(t.getComplement(this))},this),D.forEach(this.outgoing,function(t){e.push(t.getComplement(this))},this),e}}),w=x.Class.extend({init:function(e,t,n,i){if(D.isUndefined(e))throw"The source of the new link is not set.";if(D.isUndefined(t))throw"The target of the new link is not set.";var r,a;r=D.isString(e)?new y(e):e,a=D.isString(t)?new y(t):t,this.source=r,this.target=a,this.source.links.push(this),this.target.links.push(this),this.source.outgoing.push(this),this.target.incoming.push(this),this.id=D.isDefined(n)?n:o(),this.associatedConnection=D.isDefined(i)?i:null,this.type="Link",this.shortForm="Link '"+this.source.id+"->"+this.target.id+"'"},getComplement:function(e){if(this.source!==e&&this.target!==e)throw"The given node is not incident with this link.";return this.source===e?this.target:this.source},getCommonNode:function(e){return this.source===e.source||this.source===e.target?this.source:this.target===e.source||this.target===e.target?this.target:null},isBridging:function(e,t){return this.source===e&&this.target===t||this.source===t&&this.target===e},getNodes:function(){return[this.source,this.target]},incidentWith:function(e){return this.source===e||this.target===e},adjacentTo:function(e){return I(this.source.links,e)||I(this.target.links,e)},changeSource:function(e){D.remove(this.source.links,this),D.remove(this.source.outgoing,this),e.links.push(this),e.outgoing.push(this),this.source=e},changeTarget:function(e){D.remove(this.target.links,this),D.remove(this.target.incoming,this),e.links.push(this),e.incoming.push(this),this.target=e},changesNodes:function(e,t){this.source===e?this.changeSource(t):this.target===e&&this.changeTarget(t)},reverse:function(){var e=this.source,t=this.target;return this.source=t,D.remove(e.outgoing,this),this.source.outgoing.push(this),this.target=e,D.remove(t.incoming,this),this.target.incoming.push(this),this},directTo:function(e){if(this.source!==e&&this.target!==e)throw"The given node is not incident with this link.";this.target!==e&&this.reverse()},createReverseEdge:function(){var e=this.clone();return e.reverse(),e.reversed=!0,e},clone:function(){var e=new w(this.source,this.target);return e}}),b=x.Class.extend({init:function(e){this.links=[],this.nodes=[],this.diagram=null,this._root=null,D.isDefined(e)?D.isString(e)?this.id=e:(this.diagram=e,this.id=e.id):this.id=o(),this.bounds=new s,this._hasCachedRelationships=!1,this.type="Graph"},cacheRelationships:function(e){var t,n,i;if(D.isUndefined(e)&&(e=!1),!this._hasCachedRelationships||e){for(t=0,n=this.nodes.length;n>t;t++)i=this.nodes[t],i.children=this.getChildren(i),i.parents=this.getParents(i);this._hasCachedRelationships=!0}},assignLevels:function(e,t,n){var i,r,o,a;if(!e)throw"Start node not specified.";for(D.isUndefined(t)&&(t=0),this.cacheRelationships(),D.isUndefined(n)&&(n=new m,D.forEach(this.nodes,function(e){n.add(e,!1)})),n.set(e,!0),e.level=t,i=e.children,r=0,o=i.length;o>r;r++)a=i[r],a&&!n.get(a)&&this.assignLevels(a,t+1,n)},root:function(e){if(D.isUndefined(e)){if(this._root)return this._root;var t=D.first(this.nodes,function(e){return 0===e.incoming.length});return t?t:D.first(this.nodes)}this._root=e},getConnectedComponents:function(){var e,t,n,i,r;for(this.componentIndex=0,this.setItemIndices(),e=D.initArray(this.nodes.length,-1),t=0;this.nodes.length>t;t++)-1===e[t]&&(this._collectConnectedNodes(e,t),this.componentIndex++);for(n=[],i=0;this.componentIndex>i;++i)n[i]=new b;for(i=0;e.length>i;++i)r=n[e[i]],r.addNodeAndOutgoings(this.nodes[i]);return n.sort(function(e,t){return t.nodes.length-e.nodes.length}),n},_collectConnectedNodes:function(e,t){e[t]=this.componentIndex;var n=this.nodes[t];D.forEach(n.links,function(t){var i=t.getComplement(n),r=i.index;-1===e[r]&&this._collectConnectedNodes(e,r)},this)},calcBounds:function(){var e,t,n,i;if(this.isEmpty())return this.bounds=new s;for(e=null,t=0,n=this.nodes.length;n>t;t++)i=this.nodes[t],e=e?e.union(i.bounds()):i.bounds();return this.bounds=e},getSpanningTree:function(e){var t,n,i,r,o,a,s,l,c,d,u,h,p=new b,f=new m;for(p.root=e.clone(),p.root.level=0,p.root.id=e.id,f.add(e,p.root),e.level=0,i=[],r=[],p.nodes.push(p.root),i.push(e),r.push(e),o=1;r.length>0;)for(a=r.pop(),s=0;a.links.length>s;s++)l=a.links[s],c=l.getComplement(a),I(i,c)||(c.level=a.level+1,c.level+1>o&&(o=c.level+1),I(r,c)||r.push(c),I(i,c)||i.push(c),f.containsKey(a)?t=f.get(a):(t=a.clone(),t.level=a.level,t.id=a.id,f.add(a,t)),f.containsKey(c)?n=f.get(c):(n=c.clone(),n.level=c.level,n.id=c.id,f.add(c,n)),d=new w(t,n),p.addLink(d));for(u=[],h=0;o>h;h++)u.push([]);return D.forEach(p.nodes,function(e){u[e.level].push(e)}),p.treeLevels=u,p.cacheRelationships(),p},takeRandomNode:function(t,n){if(D.isUndefined(t)&&(t=[]),D.isUndefined(n)&&(n=4),0===this.nodes.length)return null;if(1===this.nodes.length)return I(t,this.nodes[0])?null:this.nodes[0];var i=e.grep(this.nodes,function(e){return!I(t,e)&&e.degree()<=n});return D.isEmpty(i)?null:i[D.randomInteger(0,i.length)]},isEmpty:function(){return D.isEmpty(this.nodes)},isHealthy:function(){return D.all(this.links,function(e){return I(this.nodes,e.source)&&I(this.nodes,e.target)},this)},getParents:function(e){if(!this.hasNode(e))throw"The given node is not part of this graph.";return e.getParents()},getChildren:function(e){if(!this.hasNode(e))throw"The given node is not part of this graph.";return e.getChildren()},addLink:function(e,n,i){var r,o,a;if(D.isUndefined(e))throw"The source of the link is not defined.";if(D.isUndefined(n)){if(D.isDefined(e.type)&&"Link"===e.type)return this.addExistingLink(e),t;throw"The target of the link is not defined."}return r=this.getNode(e),D.isUndefined(r)&&(r=this.addNode(e)),o=this.getNode(n),D.isUndefined(o)&&(o=this.addNode(n)),a=new w(r,o),D.isDefined(i)&&(a.owner=i),this.links.push(a),a},removeAllLinks:function(){for(;this.links.length>0;){var e=this.links[0];this.removeLink(e)}},addExistingLink:function(e){var t,n;this.hasLink(e)||(this.links.push(e),this.hasNode(e.source.id)?(t=this.getNode(e.source.id),e.changeSource(t)):this.addNode(e.source),this.hasNode(e.target.id)?(n=this.getNode(e.target.id),e.changeTarget(n)):this.addNode(e.target))},hasLink:function(e){if(D.isString(e))return D.any(this.links,function(t){return t.id===e});if("Link"===e.type)return I(this.links,e);throw"The given object is neither an identifier nor a Link."},getNode:function(e){if(D.isUndefined(e))throw"No identifier or Node specified.";return D.isString(e)?D.find(this.nodes,function(t){return t.id==e}):this.hasNode(e)?e:null},hasNode:function(e){if(D.isString(e))return D.any(this.nodes,function(t){return t.id===e});if(D.isObject(e))return D.any(this.nodes,function(t){return t===e});throw"The identifier should be a Node or the Id (string) of a node."},removeNode:function(e){var t,n,i,r,o=e;if(D.isString(e)&&(o=this.getNode(e)),!D.isDefined(o))throw"The identifier should be a Node or the Id (string) of a node.";for(t=o.links,o.links=[],n=0,i=t.length;i>n;n++)r=t[n],this.removeLink(r);D.remove(this.nodes,o)},areConnected:function(e,t){return D.any(this.links,function(n){return n.source==e&&n.target==t||n.source==t&&n.target==e})},removeLink:function(e){D.remove(this.links,e),D.remove(e.source.outgoing,e),D.remove(e.source.links,e),D.remove(e.target.incoming,e),D.remove(e.target.links,e)},addNode:function(e,t,n){var i=null;if(!D.isDefined(e))throw"No Node or identifier for a new Node is given.";if(D.isString(e)){if(this.hasNode(e))return this.getNode(e);i=new y(e)}else{if(this.hasNode(e))return this.getNode(e);i=e}return D.isDefined(t)&&i.bounds(t),D.isDefined(n)&&(i.owner=n),this.nodes.push(i),i},addNodeAndOutgoings:function(e){I(this.nodes,e)||this.nodes.push(e);var t=e.outgoing;e.outgoing=[],D.forEach(t,function(e){this.addExistingLink(e)},this)},setItemIndices:function(){var e;for(e=0;this.nodes.length>e;++e)this.nodes[e].index=e;for(e=0;this.links.length>e;++e)this.links[e].index=e},clone:function(e){var t,n=new b,i=D.isDefined(e)&&e===!0;return i&&(n.nodeMap=new m,n.linkMap=new m),t=new m,D.forEach(this.nodes,function(e){var r=e.clone();t.set(e,r),n.nodes.push(r),i&&n.nodeMap.set(r,e)}),D.forEach(this.links,function(e){if(t.containsKey(e.source)&&t.containsKey(e.target)){var r=n.addLink(t.get(e.source),t.get(e.target));i&&n.linkMap.set(r,e)}}),n},linearize:function(e){return b.Utils.linearize(this,e)},depthFirstTraversal:function(e,t){var n,i;if(D.isUndefined(e))throw"You need to supply a starting node.";if(D.isUndefined(t))throw"You need to supply an action.";if(!this.hasNode(e))throw"The given start-node is not part of this graph";n=this.getNode(e),i=[],this._dftIterator(n,t,i)},_dftIterator:function(e,t,n){var i,r,o,a;for(t(e),n.push(e),i=e.getChildren(),r=0,o=i.length;o>r;r++)a=i[r],I(n,a)||this._dftIterator(a,t,n)},breadthFirstTraversal:function(e,t){var n,i,r,o,a,s,l,c;if(D.isUndefined(e))throw"You need to supply a starting node.";if(D.isUndefined(t))throw"You need to supply an action.";if(!this.hasNode(e))throw"The given start-node is not part of this graph";for(n=this.getNode(e),i=new v,r=[],i.enqueue(n);i.length>0;)for(o=i.dequeue(),t(o),r.push(o),a=o.getChildren(),s=0,l=a.length;l>s;s++)c=a[s],I(r,c)||I(i,c)||i.enqueue(c)},_stronglyConnectedComponents:function(e,t,n,i,r,o,a){var s,l,c,d,u;for(n.add(t,a),i.add(t,a),a++,o.push(t),s=t.getChildren(),c=0,d=s.length;d>c;c++)l=s[c],n.containsKey(l)?I(o,l)&&i.add(t,Math.min(i.get(t),n.get(l))):(this._stronglyConnectedComponents(e,l,n,i,r,o,a),i.add(t,Math.min(i.get(t),i.get(l))));if(i.get(t)===n.get(t)){u=[];do l=o.pop(),u.push(l);while(l!==t);(!e||u.length>1)&&r.push(u)}},findCycles:function(e){var t,n,i,r,o,a,s;for(D.isUndefined(e)&&(e=!0),t=new m,n=new m,i=[],r=[],o=0,a=this.nodes.length;a>o;o++)s=this.nodes[o],t.containsKey(s)||this._stronglyConnectedComponents(e,s,t,n,i,r,0);return i},isAcyclic:function(){return D.isEmpty(this.findCycles())},isSubGraph:function(e){var t=e.linearize(),n=this.linearize();return D.all(t,function(e){return I(n,e)})},makeAcyclic:function(){var e,t,n,i,r,o,a,s,l,c,d,u,h,p,f,g,v,_,y,w,b,x,k,C,S,T,A,M,I,P,E,F;if(this.isEmpty()||1>=this.nodes.length||1>=this.links.length)return[];if(2==this.nodes.length){if(e=[],this.links.length>1)for(t=this.links[0],n=t.source,i=0,r=this.links.length;r>i;i++)o=this.links[i],o.source!=n&&(a=o.reverse(),e.push(a));return e}for(s=this.clone(!0),l=this.nodes.length,c=new m,d=function(e){return 0===e.outgoing.length?2-l:0===e.incoming.length?l-2:e.outgoing.length-e.incoming.length},u=function(e,t){var n=d(e,l);t.containsKey(n)||t.set(n,[]),t.get(n).push(e)},D.forEach(s.nodes,function(e){u(e,c)}),h=[],p=[];s.nodes.length>0;){if(c.containsKey(2-l))for(_=c.get(2-l);_.length>0;){for(g=_.pop(),y=0;g.links.length>y;y++)w=g.links[y],f=w.getComplement(g),v=d(f,l),D.remove(c.get(v),f),f.removeLink(w),u(f,c);
  D.remove(s.nodes,g),p.unshift(g)}if(c.containsKey(l-2))for(b=c.get(l-2);b.length>0;){for(f=b.pop(),x=0;f.links.length>x;x++)k=f.links[x],g=k.getComplement(f),v=d(g,l),D.remove(c.get(v),g),g.removeLink(k),u(g,c);h.push(f),D.remove(s.nodes,f)}if(s.nodes.length>0)for(C=l-3;C>2-l;C--)if(c.containsKey(C)&&c.get(C).length>0){for(S=c.get(C),T=S.pop(),A=0;T.links.length>A;A++)M=T.links[A],I=M.getComplement(T),v=d(I,l),D.remove(c.get(v),I),I.removeLink(M),u(I,c);h.push(T),D.remove(s.nodes,T);break}}for(h=h.concat(p),P=new m,E=0;this.nodes.length>E;E++)P.set(s.nodeMap.get(h[E]),E);return F=[],D.forEach(this.links,function(e){P.get(e.source)>P.get(e.target)&&(e.reverse(),F.push(e))}),F}}),b.Predefined={EightGraph:function(){return b.Utils.parse(["1->2","2->3","3->4","4->1","3->5","5->6","6->7","7->3"])},Mindmap:function(){return b.Utils.parse(["0->1","0->2","0->3","0->4","0->5","1->6","1->7","7->8","2->9","9->10","9->11","3->12","12->13","13->14","4->15","4->16","15->17","15->18","18->19","18->20","14->21","14->22","5->23","23->24","23->25","6->26"])},ThreeGraph:function(){return b.Utils.parse(["1->2","2->3","3->1"])},BinaryTree:function(e){return D.isUndefined(e)&&(e=5),b.Utils.createBalancedTree(e,2)},Linear:function(e){return D.isUndefined(e)&&(e=10),b.Utils.createBalancedTree(e,1)},Tree:function(e,t){return b.Utils.createBalancedTree(e,t)},Forest:function(e,t,n){return b.Utils.createBalancedForest(e,t,n)},Workflow:function(){return b.Utils.parse(["0->1","1->2","2->3","1->4","4->3","3->5","5->6","6->3","6->7","5->4"])},Grid:function(e,t){var n,i,r,o,a,s=new k.Graph;if(0>=e&&0>=t)return s;for(n=0;e+1>n;n++)for(i=null,r=0;t+1>r;r++)o=new y(""+n+"."+r),s.addNode(o),i&&s.addLink(i,o),n>0&&(a=s.getNode(""+(n-1)+"."+r),s.addLink(a,o)),i=o;return s}},b.Utils={parse:function(e){var t,n,i,r,o,a=new k.Graph,s=e.slice();for(n=0,i=s.length;i>n;n++){if(r=s[n],D.isString(r)){if(r.indexOf("->")<0)throw"The link should be specified as 'a->b'.";if(o=r.split("->"),2!=o.length)throw"The link should be specified as 'a->b'.";t=new w(o[0],o[1]),a.addLink(t)}if(D.isObject(r)){if(!t)throw"Specification found before Link definition.";x.deepExtend(t,r)}}return a},linearize:function(e,t){var n,i,r,o;if(D.isUndefined(e))throw"Expected an instance of a Graph object in slot one.";for(D.isUndefined(t)&&(t=!1),n=[],i=0,r=e.links.length;r>i;i++)o=e.links[i],n.push(o.source.id+"->"+o.target.id),t&&n.push({id:o.id});return n},_addShape:function(e,t,n,i){return D.isUndefined(t)&&(t=new k.Point(0,0)),D.isUndefined(n)&&(n=o()),i=x.deepExtend({width:20,height:20,id:n,radius:10,fill:"#778899",data:"circle",undoable:!1,x:t.x,y:t.y},i),e.addShape(i)},_addConnection:function(e,t,n,i){return e.connect(t,n,i)},createDiagramFromGraph:function(e,t,n,i){var r,o,a,l,c,d,u,h,p,f,g,m,v,_,y,w;if(D.isUndefined(e))throw"The diagram surface is undefined.";if(D.isUndefined(t))throw"No graph specification defined.";for(D.isUndefined(n)&&(n=!0),D.isUndefined(i)&&(i=!1),r=e.element.clientWidth||200,o=e.element.clientHeight||200,a=[],d=0,u=t.nodes.length;u>d;d++)l=t.nodes[d],h=l.position,D.isUndefined(h)&&(h=D.isDefined(l.x)&&D.isDefined(l.y)?new A(l.x,l.y):new A(D.randomInteger(10,r-20),D.randomInteger(10,o-20))),p={},"0"===l.id||i&&x.deepExtend(p,{width:150*Math.random()+20,height:80*Math.random()+50,data:"rectangle",fill:{color:"#778899"}}),c=this._addShape(e,h,l.id,p),f=c.bounds(),D.isDefined(f)&&(l.x=f.x,l.y=f.y,l.width=f.width,l.height=f.height),a[l.id]=c;for(g=0;t.links.length>g;g++)m=t.links[g],v=a[m.source.id],D.isUndefined(v)||(_=a[m.target.id],D.isUndefined(_)||this._addConnection(e,v,_,{id:m.id}));if(n)for(y=new e.SpringLayout(e),y.layoutGraph(t,{limitToView:!1}),w=0;t.nodes.length>w;w++)l=t.nodes[w],c=a[l.id],c.bounds(new s(l.x,l.y,l.width,l.height))},createBalancedTree:function(e,t){var n,i,r,o,a,s,l,c,d,u;if(D.isUndefined(e)&&(e=3),D.isUndefined(t)&&(t=3),n=new k.Graph,i=-1,r=[],0>=e||0>=t)return n;for(a=new y(""+ ++i),n.addNode(a),n.root=a,r.push(a),s=0;e>s;s++){for(o=[],l=0;r.length>l;l++)for(c=r[l],d=0;t>d;d++)u=new y(""+ ++i),n.addLink(c,u),o.push(u);r=o}return n},createBalancedForest:function(e,t,n){var i,r,o,a,s,l,c,d,u,h,p;if(D.isUndefined(e)&&(e=3),D.isUndefined(t)&&(t=3),D.isUndefined(n)&&(n=5),i=new k.Graph,r=-1,o=[],0>=e||0>=t||0>=n)return i;for(s=0;n>s;s++)for(l=new y(""+ ++r),i.addNode(l),o=[l],c=0;e>c;c++){for(a=[],d=0;o.length>d;d++)for(u=o[d],h=0;t>h;h++)p=new y(""+ ++r),i.addLink(u,p),a.push(p);o=a}return i},createRandomConnectedGraph:function(e,t,n){var i,r,o,a,s,l,c,d,u,h;if(D.isUndefined(e)&&(e=40),D.isUndefined(t)&&(t=4),D.isUndefined(n)&&(n=!1),i=new k.Graph,r=-1,0>=e)return i;if(o=new y(""+ ++r),i.addNode(o),1===e)return i;if(e>1){for(a=1;e>a&&(s=i.takeRandomNode([],t),s);a++)l=i.addNode(""+a),i.addLink(s,l);if(!n&&e>1)for(c=D.randomInteger(1,e),d=0;c>d;d++)u=i.takeRandomNode([],t),h=i.takeRandomNode([],t),u&&h&&!i.areConnected(u,h)&&i.addLink(u,h);return i}},randomDiagram:function(e,t,n,i,r){var o=x.dataviz.diagram.Graph.Utils.createRandomConnectedGraph(t,n,i);b.Utils.createDiagramFromGraph(e,o,!1,r)}},x.deepExtend(k,{init:function(e){x.init(e,k.ui)},Point:A,Intersect:c,Geometry:f,Rect:s,Size:l,RectAlign:d,Matrix:h,MatrixVector:p,normalVariable:r,randomId:o,Dictionary:m,HashTable:g,Queue:v,Set:_,Node:y,Link:w,Graph:b,PathDefiner:a})}(window.kendo.jQuery),function(e,t){function n(e){return{x:e.x||0,y:e.y||0,width:e.width||0,height:e.height||0}}function i(e){if(e){var t=e;return L(t)&&(t={color:t}),t.color&&(t.color=r(t.color)),t}}function r(e){var t;return t=e!=W?new N.Color(e).toHex():e}function o(e,t){var n=t.x-e.x,i=t.y-e.y,r=A.util.deg(Math.atan2(i,n));return r}function a(e,t){var n,i,r,o=this.options,a=!1;for(r=0;t.length>r;r++)i=t[r],n=e[i],R(n)&&o[i]!==n&&(o[i]=n,a=!0);return a}function s(e,t){return new N.Segment(new O.Point(e,t))}var l,c,d,u,h,p,f,g,m,v,_,y,w,b,x,k,C,S,T,D,A=window.kendo,M=A.dataviz.diagram,I=A.Class,P=A.deepExtend,E=M.Point,F=M.Rect,B=M.Matrix,z=M.Utils,R=z.isNumber,L=z.isString,H=M.MatrixVector,O=A.geometry,N=A.drawing,V=A.util.defined,U=e.inArray,W="transparent",j={none:"none",arrowStart:"ArrowStart",filledCircle:"FilledCircle",arrowEnd:"ArrowEnd"},G=360,q="start",$="end",Y="width",K="height",Q="x",X="y";M.Markers=j,l=I.extend({init:function(e,t){this.x=e,this.y=t},toMatrix:function(){return B.scaling(this.x,this.y)},toString:function(){return A.format("scale({0},{1})",this.x,this.y)},invert:function(){return new l(1/this.x,1/this.y)}}),c=I.extend({init:function(e,t){this.x=e,this.y=t},toMatrixVector:function(){return new H(0,0,0,0,this.x,this.y)},toMatrix:function(){return B.translation(this.x,this.y)},toString:function(){return A.format("translate({0},{1})",this.x,this.y)},plus:function(e){this.x+=e.x,this.y+=e.y},times:function(e){this.x*=e,this.y*=e},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},normalize:function(){0!==this.Length&&this.times(1/this.length())},invert:function(){return new c(-this.x,-this.y)}}),d=I.extend({init:function(e,t,n){this.x=t||0,this.y=n||0,this.angle=e},toString:function(){return this.x&&this.y?A.format("rotate({0},{1},{2})",this.angle,this.x,this.y):A.format("rotate({0})",this.angle)},toMatrix:function(){return B.rotation(this.angle,this.x,this.y)},center:function(){return new E(this.x,this.y)},invert:function(){return new d(G-this.angle,this.x,this.y)}}),d.create=function(e){return new d(e.angle,e.x,e.y)},d.parse=function(e){var t=e.slice(1,e.length-1).split(","),n=t[0],i=t[1],r=t[2],o=new d(n,i,r);return o},u=I.extend({init:function(e,n,i,r,o,a){this.translate=new c(e,n),i!==t&&r!==t&&(this.scale=new l(i,r)),o!==t&&(this.rotate=a?new d(o,a.x,a.y):new d(o))},toString:function(){var e=function(e){return e?""+e:""};return e(this.translate)+e(this.rotate)+e(this.scale)},render:function(e){e._transform=this,e._renderTransform()},toMatrix:function(){var e=B.unit();return this.translate&&(e=e.times(this.translate.toMatrix())),this.rotate&&(e=e.times(this.rotate.toMatrix())),this.scale&&(e=e.times(this.scale.toMatrix())),e},invert:function(){var e,n,i=this.rotate?this.rotate.invert():t,r=i?i.toMatrix():B.unit(),o=this.scale?this.scale.invert():t,a=o?o.toMatrix():B.unit(),s=new E(-this.translate.x,-this.translate.y);return s=r.times(a).apply(s),e=new c(s.x,s.y),n=new u,n.translate=e,n.rotate=i,n.scale=o,n}}),h={_setScale:function(){var e=this.options,t=this._originWidth,n=this._originHeight,i=e.width/t,r=e.height/n;R(i)||(i=1),R(r)||(r=1),this._transform.scale=new l(i,r)},_setTranslate:function(){var e=this.options,t=e.x||0,n=e.y||0;this._transform.translate=new c(t,n)},_initSize:function(){var e=this.options,t=!1;e.autoSize!==!1&&(V(e.width)||V(e.height))&&(this._measure(!0),this._setScale(),t=!0),(V(e.x)||V(e.y))&&(this._setTranslate(),t=!0),t&&this._renderTransform()},_updateSize:function(e){var t=!1;return this.options.autoSize!==!1&&this._diffNumericOptions(e,[Y,K])&&(t=!0,this._measure(!0),this._setScale()),this._diffNumericOptions(e,[Q,X])&&(t=!0,this._setTranslate()),t&&this._renderTransform(),t}},p=I.extend({init:function(e){var t=this;t.options=P({},t.options,e),t.id=t.options.id,t._originSize=F.empty(),t._transform=new u},visible:function(e){return this.drawingContainer().visible(e)},redraw:function(e){e&&e.id&&(this.id=e.id)},position:function(e,n){var i=this.options;return V(e)?(V(n)?(i.x=e,i.y=n):e instanceof E&&(i.x=e.x,i.y=e.y),this._transform.translate=new c(i.x,i.y),this._renderTransform(),t):new E(i.x,i.y)},rotate:function(e,t){return V(e)&&(this._transform.rotate=new d(e,t.x,t.y),this._renderTransform()),this._transform.rotate||new d(0)},drawingContainer:function(){return this.drawingElement},_renderTransform:function(){var e=this._transform.toMatrix();this.drawingContainer().transform(new O.Matrix(e.a,e.b,e.c,e.d,e.e,e.f))},_hover:function(){},_diffNumericOptions:a,_measure:function(e){var t,n,i;return!this._measured||e?(n=this._boundingBox()||new O.Rect,i=n.topLeft(),t=new F(i.x,i.y,n.width(),n.height()),this._originSize=t,this._originWidth=t.width,this._originHeight=t.height,this._measured=!0):t=this._originSize,t},_boundingBox:function(){return this.drawingElement.rawBBox()}}),f=p.extend({init:function(e){p.fn.init.call(this,e),e=this.options,e.fill=i(e.fill),e.stroke=i(e.stroke)},options:{stroke:{color:"gray",width:1},fill:{color:W}},fill:function(e,t){this._fill({color:r(e),opacity:t})},stroke:function(e,t,n){this._stroke({color:r(e),width:t,opacity:n})},redraw:function(e){var t,n;e&&(t=e.stroke,n=e.fill,t&&this._stroke(i(t)),n&&this._fill(i(n)),p.fn.redraw.call(this,e))},_hover:function(e){var t,n=this.drawingElement,r=this.options,o=r.hover;o&&o.fill&&(t=e?i(o.fill):r.fill,n.fill(t.color,t.opacity))},_stroke:function(e){var t,n=this.options;P(n,{stroke:e}),e=n.stroke,t=null,e.width>0&&(t={color:e.color,width:e.width,opacity:e.opacity,dashType:e.dashType}),this.drawingElement.options.set("stroke",t)},_fill:function(e){var t,n,i,r=this.options;P(r,{fill:e}),t=r.fill,t.gradient?(n=t.gradient,i="radial"===n.type?N.RadialGradient:N.LinearGradient,this.drawingElement.fill(new i(n))):this.drawingElement.fill(t.color,t.opacity)}}),g=f.extend({init:function(e){this._textColor(e),f.fn.init.call(this,e),this._font(),this._initText(),this._initSize()},options:{fontSize:15,fontFamily:"sans-serif",stroke:{width:0},fill:{color:"black"},autoSize:!0},_initText:function(){var e=this.options;this.drawingElement=new N.Text(V(e.text)?e.text:"",new O.Point,{font:e.font}),this._fill(),this._stroke()},_textColor:function(e){e&&e.color&&P(e,{fill:{color:e.color}})},_font:function(){var e=this.options;e.fontFamily&&V(e.fontSize)?e.font=e.fontSize+"px "+e.fontFamily:delete e.font},content:function(e){return this.drawingElement.content(e)},redraw:function(e){var t,n;e&&(t=!1,n=this.options,this._textColor(e),f.fn.redraw.call(this,e),(e.fontFamily||V(e.fontSize))&&(P(n,{fontFamily:e.fontFamily,fontSize:e.fontSize}),this._font(),this.drawingElement.options.set("font",n.font),t=!0),e.text&&(this.content(e.text),t=!0),!this._updateSize(e)&&t&&this._initSize())}}),P(g.fn,h),m=f.extend({init:function(e){f.fn.init.call(this,e),this._initPath(),this._setPosition()},_setPosition:function(){var e=this.options,t=e.x,n=e.y;(V(t)||V(n))&&this.position(t||0,n||0)},redraw:function(e){e&&(f.fn.redraw.call(this,e),this._diffNumericOptions(e,[Y,K])&&this._drawPath(),this._diffNumericOptions(e,[Q,X])&&this._setPosition())},_initPath:function(){{var e=this.options;this.drawingElement=new N.Path({stroke:e.stroke,closed:!0})}this._fill(),this._drawPath()},_drawPath:function(){var e=this.drawingElement,t=n(this.options),i=t.width,r=t.height;e.segments.elements([s(0,0),s(i,0),s(i,r),s(0,r)])}}),v=f.extend({init:function(e){f.fn.init.call(this,e);var t=this.options.anchor;this.anchor=new O.Point(t.x,t.y),this.createElement()},options:{stroke:{color:W,width:0},fill:{color:"black"}},_transformToPath:function(e,t){var n=t.transform();return e&&n&&(e=e.transformCopy(n)),e},redraw:function(e){e&&(e.position&&(this.options.position=e.position),f.fn.redraw.call(this,e))}}),_=v.extend({options:{radius:4,anchor:{x:0,y:0}},createElement:function(){var e=this.options;this.drawingElement=new N.Circle(new O.Circle(this.anchor,e.radius),{fill:e.fill,stroke:e.stroke})},positionMarker:function(e){var t,n,i=this.options,r=i.position,o=e.segments;t=r==q?o[0]:o[o.length-1],t&&(n=this._transformToPath(t.anchor(),e),this.drawingElement.transform(O.transform().translate(n.x,n.y)))}}),y=v.extend({options:{path:"M 0 0 L 10 5 L 0 10 L 3 5 z",anchor:{x:10,y:5}},createElement:function(){var e=this.options;this.drawingElement=N.Path.parse(e.path,{fill:e.fill,stroke:e.stroke})},positionMarker:function(e){var t,n,i=this._linePoints(e),r=i.start,a=i.end,s=O.transform();r&&s.rotate(o(r,a),a),a&&(t=this.anchor,n=a.clone().translate(-t.x,-t.y),s.translate(n.x,n.y)),this.drawingElement.transform(s)},_linePoints:function(e){var n,i,r,o,a,s=this.options,l=e.segments;return s.position==q?(r=l[0],r&&(i=r.anchor(),n=r.controlOut(),o=l[1],!n&&o&&(n=o.anchor()))):(r=l[l.length-1],r&&(i=r.anchor(),n=r.controlIn(),a=l[l.length-2],!n&&a&&(n=a.anchor()))),i?{start:this._transformToPath(n,e),end:this._transformToPath(i,e)}:t}}),w={_getPath:function(e){var n=this.drawingElement;return n instanceof N.MultiPath&&(n=e==q?n.paths[0]:n.paths[n.paths.length-1]),n&&n.segments.length?n:t},_normalizeMarkerOptions:function(e){var t=e.startCap,n=e.endCap;L(t)&&(e.startCap={type:t}),L(n)&&(e.endCap={type:n})},_removeMarker:function(e){var t=this._markers[e];t&&(this.drawingContainer().remove(t.drawingElement),delete this._markers[e])},_createMarkers:function(){var e=this.options;this._normalizeMarkerOptions(e),this._markers={},this._markers[q]=this._createMarker(e.startCap,q),this._markers[$]=this._createMarker(e.endCap,$)},_createMarker:function(e,n){var i,r,o=(e||{}).type,a=this._getPath(n);return a?(o==j.filledCircle?i=_:o==j.arrowStart||o==j.arrowEnd?i=y:this._removeMarker(n),i?(r=new i(P({},e,{position:n})),r.positionMarker(a),this.drawingContainer().append(r.drawingElement),r):t):(this._removeMarker(n),t)},_positionMarker:function(e){var t,n=this._markers[e];n&&(t=this._getPath(e),t?n.positionMarker(t):this._removeMarker(e))},_capMap:{start:"startCap",end:"endCap"},_redrawMarker:function(e,t,n){var i,r,o,a,s;return this._normalizeMarkerOptions(n),i=this.options,r=this._capMap[t],o=(i[r]||{}).type,a=n[r],s=!1,a?(i[r]=P({},i[r],a),a.type&&o!=a.type?(this._removeMarker(t),this._markers[t]=this._createMarker(i[r],t),s=!0):this._markers[t]&&this._markers[t].redraw(a)):e&&!this._markers[t]&&i[r]&&(this._markers[t]=this._createMarker(i[r],t),s=!0),s},_redrawMarkers:function(e,t){!this._redrawMarker(e,q,t)&&e&&this._positionMarker(q),!this._redrawMarker(e,$,t)&&e&&this._positionMarker($)}},b=f.extend({init:function(e){f.fn.init.call(this,e),this.container=new N.Group,this._createElements(),this._initSize()},options:{autoSize:!0},drawingContainer:function(){return this.container},data:function(e){var n=this.options;return e?(n.data!=e&&(n.data=e,this._setData(e),this._initSize(),this._redrawMarkers(!0,{})),t):n.data},redraw:function(e){var t,n;e&&(f.fn.redraw.call(this,e),t=this.options,n=e.data,V(n)&&t.data!=n?(t.data=n,this._setData(n),this._updateSize(e)||this._initSize(),this._redrawMarkers(!0,e)):(this._updateSize(e),this._redrawMarkers(!1,e)))},_createElements:function(){var e=this.options;this.drawingElement=N.Path.parse(e.data||"",{stroke:e.stroke}),this._fill(),this.container.append(this.drawingElement),this._createMarkers()},_setData:function(e){var t=this.drawingElement,n=N.Path.parse(e||""),i=n.paths.slice(0);n.paths.elements([]),t.paths.elements(i)}}),P(b.fn,h),P(b.fn,w),x=f.extend({init:function(e){f.fn.init.call(this,e),this.container=new N.Group,this._initPath(),this._createMarkers()},drawingContainer:function(){return this.container},redraw:function(e){var t,n;e&&(e=e||{},t=e.from,n=e.to,t&&(this.options.from=t),n&&(this.options.to=n),t||n?(this._drawPath(),this._redrawMarkers(!0,e)):this._redrawMarkers(!1,e),f.fn.redraw.call(this,e))},_initPath:function(){var e=this.options,t=this.drawingElement=new N.Path({stroke:e.stroke});this._fill(),this._drawPath(),this.container.append(t)},_drawPath:function(){var e=this.options,t=this.drawingElement,n=e.from||new E,i=e.to||new E;t.segments.elements([s(n.x,n.y),s(i.x,i.y)])}}),P(x.fn,w),k=f.extend({init:function(e){f.fn.init.call(this,e),this.container=new N.Group,this._initPath(),this._createMarkers()},drawingContainer:function(){return this.container},points:function(e){var n=this.options;return e?(n.points=e,this._updatePath(),t):n.points},redraw:function(e){if(e){var t=e.points;f.fn.redraw.call(this,e),t&&this._pointsDiffer(t)?(this.points(t),this._redrawMarkers(!0,e)):this._redrawMarkers(!1,e)}},_initPath:function(){var e=this.options;this.drawingElement=new N.Path({stroke:e.stroke}),this._fill(),this.container.append(this.drawingElement),e.points&&this._updatePath()},_pointsDiffer:function(e){var t,n=this.options.points,i=n.length!==e.length;if(!i)for(t=0;e.length>t;t++)if(n[t].x!==e[t].x||n[t].y!==e[t].y){i=!0;break}return i},_updatePath:function(){var e,t,n=this.drawingElement,i=this.options,r=i.points,o=[];for(t=0;r.length>t;t++)e=r[t],o.push(s(e.x,e.y));n.segments.elements(o)},options:{points:[]}}),P(k.fn,w),C=p.extend({init:function(e){p.fn.init.call(this,e),this._initImage()},redraw:function(e){e&&(e.source&&this.drawingElement.src(e.source),this._diffNumericOptions(e,[Y,K,Q,X])&&this.drawingElement.rect(this._rect()),p.fn.redraw.call(this,e))},_initImage:function(){var e=this.options,t=this._rect();this.drawingElement=new N.Image(e.source,t,{})},_rect:function(){var e=n(this.options),t=new O.Point(e.x,e.y),i=new O.Size(e.width,e.height);return new O.Rect(t,i)}}),S=p.extend({init:function(e){this.children=[],p.fn.init.call(this,e),this.drawingElement=new N.Group,this._initSize()},options:{autoSize:!1},append:function(e){this.drawingElement.append(e.drawingContainer()),this.children.push(e),this._childrenChange=!0},remove:function(e){this._remove(e)&&(this._childrenChange=!0)},_remove:function(e){var n=U(e,this.children);return n>=0?(this.drawingElement.removeAt(n),this.children.splice(n,1),!0):t},clear:function(){this.drawingElement.clear(),this.children=[],this._childrenChange=!0},toFront:function(e){var t,n;for(n=0;e.length>n;n++)t=e[n],this._remove(t)&&this.append(t)},toBack:function(e){this._reorderChildren(e,0)},toIndex:function(e,t){this._reorderChildren(e,t)},_reorderChildren:function(e,t){var n,i,r,o,a,s=this.drawingElement,l=s.children.slice(0),c=this.children,d=R(t);for(n=0;e.length>n;n++)a=e[n],o=a.drawingContainer(),i=U(a,c),i>=0&&(l.splice(i,1),c.splice(i,1),r=d?t:t[n],l.splice(r,0,o),c.splice(r,0,a));s.clear(),s.append.apply(s,l)},redraw:function(e){e&&(this._childrenChange?(this._childrenChange=!1,this._updateSize(e)||this._initSize()):this._updateSize(e),p.fn.redraw.call(this,e))},_boundingBox:function(){var e,t,n,i,r=this.children;for(i=0;r.length>i;i++)t=r[i],t.visible()&&t._includeInBBox!==!1&&(n=t.drawingContainer().clippedBBox(null),n&&(e=e?F.union(e,n):n));return e}}),P(S.fn,h),T=f.extend({init:function(e){f.fn.init.call(this,e),this._initCircle(),this._initSize()},redraw:function(e){if(e){var t=this.options;e.center&&(P(t,{center:e.center}),this._center.move(t.center.x,t.center.y)),this._diffNumericOptions(e,["radius"])&&this._circle.setRadius(t.radius),this._updateSize(e),f.fn.redraw.call(this,e)}},_initCircle:function(){var e,t=this.options,n=t.width,i=t.height,r=t.radius;V(r)||(V(n)||(n=i),V(i)||(i=n),t.radius=r=Math.min(n,i)/2),e=t.center||{x:r,y:r},this._center=new O.Point(e.x,e.y),this._circle=new O.Circle(this._center,r),this.drawingElement=new N.Circle(this._circle,{stroke:t.stroke}),this._fill()}}),P(T.fn,h),D=I.extend({init:function(e,t){t=t||{},this.element=e,this.surface=N.Surface.create(e,t),A.isFunction(this.surface.translate)&&(this.translate=this._translate),this.drawingElement=new N.Group,this._viewBox=new F(0,0,t.width,t.height),this.size(this._viewBox)},bounds:function(){var e=this.drawingElement.clippedBBox();return new F(0,0,e.width(),e.height())},size:function(e){var t=this._viewBox;return V(e)&&(t.width=e.width,t.height=e.height,this.surface.setSize(e)),{width:t.width,height:t.height}},_translate:function(e,t){var n=this._viewBox;return V(e)&&V(t)&&(n.x=e,n.y=t,this.surface.translate({x:e,y:t})),{x:n.x,y:n.y}},draw:function(){this.surface.draw(this.drawingElement)},append:function(e){return this.drawingElement.append(e.drawingContainer()),this},remove:function(e){this.drawingElement.remove(e.drawingContainer())},insertBefore:function(){},clear:function(){this.drawingElement.clear()},destroy:function(t){this.surface.destroy(),t&&e(this.element).remove()}}),A.deepExtend(M,{init:function(e){A.init(e,M.ui)},diffNumericOptions:a,Element:p,Scale:l,Translation:c,Rotation:d,Circle:T,Group:S,Rectangle:m,Canvas:D,Path:b,Line:x,MarkerBase:v,ArrowMarker:y,CircleMarker:_,Polyline:k,CompositeTransform:u,TextBlock:g,Image:C,VisualBase:f})}(window.kendo.jQuery),function(e,t){function n(e,t){e.isSelected?t.ctrlKey&&e.select(!1):e.diagram.select(e,{addToSelection:t.ctrlKey})}function i(e){return e.ctrlKey===!1&&e.altKey===!1&&e.shiftKey===!1}function r(e,t){var n=e!==!1;return e.key&&"none"!=e.key&&(n=t[e.key+"Key"]),n}function o(e,t){return t.charCodeAt(0)==e||t.toUpperCase().charCodeAt(0)==e}function a(e,t){var n;return-1==e.x&&-1==e.y?n=t.bottomRight():1==e.x&&1==e.y?n=t.topLeft():-1==e.x&&1==e.y?n=t.topRight():1==e.x&&-1==e.y?n=t.bottomLeft():0===e.x&&-1==e.y?n=t.bottom():0===e.x&&1==e.y?n=t.top():1==e.x&&0===e.y?n=t.left():-1==e.x&&0===e.y&&(n=t.right()),n}function s(e){var t=e.options.editable;return t&&t.drag!==!1}function l(e,t){var n,i,r,o;for(o=0;e.connectors.length>o;o++)if(n=e.connectors[o],i=n.position(),r=new q(i.x,i.y),r.inflate(at,at),r.contains(t))return n}var c,d,u,h,p,f,g,m,v,_,y,w,b,x,k,C,S,T,D,A,M,I,P,E,F,B,z,R,L,H,O,N,V=window.kendo,U=V.dataviz,W=U.diagram,j=V.Class,G=W.Group,q=W.Rect,$=W.Rectangle,Y=W.Utils,K=Y.isUndefined,Q=W.Point,X=W.Circle,Z=W.Ticker,J=V.deepExtend,et=V.ui.Movable,tt=V.support.browser,nt=V.util.defined,it=e.inArray,rt=e.proxy,ot={arrow:"default",grip:"pointer",cross:"pointer",add:"pointer",move:"move",select:"pointer",south:"s-resize",east:"e-resize",west:"w-resize",north:"n-resize",rowresize:"row-resize",colresize:"col-resize"},at=10,st="Auto",lt="Top",ct="Right",dt="Left",ut="Bottom",ht=10,pt=10,ft="dragStart",gt="drag",mt="dragEnd",vt="itemRotate",_t="itemBoundsChange",yt=5,wt=5,bt="mouseEnter",xt="mouseLeave",kt="zoomStart",Ct="zoomEnd",St=-2e4,Tt=2e4,Dt=.9,At=.93,Mt=5,It="transparent",Pt="pan",Et="rotated";W.Cursors=ot,c=V.Class.extend({init:function(e){this.layoutState=e,this.diagram=e.diagram},initState:function(){function e(e,t){var n=this.diagram.getShapeById(e);n&&(this.subjects.push(n),this.froms.push(n.bounds().topLeft()),this.tos.push(t.topLeft()))}this.froms=[],this.tos=[],this.subjects=[],this.layoutState.nodeMap.forEach(e,this)},update:function(e){if(!(0>=this.subjects.length))for(var t=0;this.subjects.length>t;t++)this.subjects[t].position(new Q(this.froms[t].x+(this.tos[t].x-this.froms[t].x)*e,this.froms[t].y+(this.tos[t].y-this.froms[t].y)*e))}}),d=j.extend({init:function(e,t,n){this.animate=K(n)?!1:n,this._initialState=e,this._finalState=t,this.title="Diagram layout"},undo:function(){this.setState(this._initialState)},redo:function(){this.setState(this._finalState)},setState:function(e){var t,n=e.diagram;this.animate?(e.linkMap.forEach(function(e,t){var i=n.getShapeById(e);i.visible(!1),i&&i.points(t)}),t=new Z,t.addAdapter(new c(e)),t.onComplete(function(){e.linkMap.forEach(function(e){var t=n.getShapeById(e);t.visible(!0)})}),t.play()):(e.nodeMap.forEach(function(e,t){var i=n.getShapeById(e);i&&i.position(t.topLeft())}),e.linkMap.forEach(function(e,t){var i=n.getShapeById(e);i&&i.points(t)}))}}),u=j.extend({init:function(e){this.units=[],this.title="Composite unit",e!==t&&this.units.push(e)},add:function(e){this.units.push(e)},undo:function(){for(var e=0;this.units.length>e;e++)this.units[e].undo()},redo:function(){for(var e=0;this.units.length>e;e++)this.units[e].redo()}}),h=j.extend({init:function(e,t,n){this.item=e,this._redoSource=t,this._redoTarget=n,nt(t)&&(this._undoSource=e.source()),nt(n)&&(this._undoTarget=e.target()),this.title="Connection Editing"},undo:function(){this._undoSource!==t&&this.item._updateConnector(this._undoSource,"source"),this._undoTarget!==t&&this.item._updateConnector(this._undoTarget,"target"),this.item.updateModel()},redo:function(){this._redoSource!==t&&this.item._updateConnector(this._redoSource,"source"),this._redoTarget!==t&&this.item._updateConnector(this._redoTarget,"target"),this.item.updateModel()}}),p=j.extend({init:function(e,t,n){this.item=e,this._undoSource=t,this._undoTarget=n,this._redoSource=e.source(),this._redoTarget=e.target(),this.title="Connection Editing"},undo:function(){this.item._updateConnector(this._undoSource,"source"),this.item._updateConnector(this._undoTarget,"target"),this.item.updateModel()},redo:function(){this.item._updateConnector(this._redoSource,"source"),this.item._updateConnector(this._redoTarget,"target"),this.item.updateModel()}}),f=j.extend({init:function(e){this.connection=e,this.diagram=e.diagram,this.targetConnector=e.targetConnector,this.title="Delete connection"},undo:function(){this.diagram._addConnection(this.connection,!1)},redo:function(){this.diagram.remove(this.connection,!1)}}),g=j.extend({init:function(e){this.shape=e,this.diagram=e.diagram,this.title="Deletion"},undo:function(){this.diagram._addShape(this.shape,!1),this.shape.select(!1)},redo:function(){this.shape.select(!1),this.diagram.remove(this.shape,!1)}}),m=j.extend({init:function(e,t,n){var i,r;for(this.shapes=e,this.undoStates=t,this.title="Transformation",this.redoStates=[],this.adorner=n,i=0;this.shapes.length>i;i++)r=this.shapes[i],this.redoStates.push(r.bounds())},undo:function(){var e,t;for(e=0;this.shapes.length>e;e++)t=this.shapes[e],t.bounds(this.undoStates[e]),t.hasOwnProperty("layout")&&t.layout(t,this.redoStates[e],this.undoStates[e]),t.updateModel();this.adorner&&(this.adorner.refreshBounds(),this.adorner.refresh())},redo:function(){var e,t;for(e=0;this.shapes.length>e;e++)t=this.shapes[e],t.bounds(this.redoStates[e]),t.hasOwnProperty("layout")&&t.layout(t,this.undoStates[e],this.redoStates[e]),t.updateModel();this.adorner&&(this.adorner.refreshBounds(),this.adorner.refresh())}}),v=j.extend({init:function(e,t){this.connection=e,this.diagram=t,this.title="New connection"},undo:function(){this.diagram.remove(this.connection,!1)},redo:function(){this.diagram._addConnection(this.connection,!1)}}),_=j.extend({init:function(e,t){this.shape=e,this.diagram=t,this.title="New shape"},undo:function(){this.diagram.deselect(),this.diagram.remove(this.shape,!1)},redo:function(){this.diagram._addShape(this.shape,!1)}}),y=j.extend({init:function(e,t,n){this.initial=e,this.finalPos=t,this.diagram=n,this.title="Pan Unit"},undo:function(){this.diagram.pan(this.initial)},redo:function(){this.diagram.pan(this.finalPos)}}),w=j.extend({init:function(e,t,n){var i,r;for(this.shapes=t,this.undoRotates=n,this.title="Rotation",this.redoRotates=[],this.redoAngle=e._angle,this.adorner=e,this.center=e._innerBounds.center(),i=0;this.shapes.length>i;i++)r=this.shapes[i],this.redoRotates.push(r.rotate().angle)},undo:function(){var e,t;for(e=0;this.shapes.length>e;e++)t=this.shapes[e],t.rotate(this.undoRotates[e],this.center,!1),t.hasOwnProperty("layout")&&t.layout(t),t.updateModel();this.adorner&&(this.adorner._initialize(),this.adorner.refresh())},redo:function(){var e,t;for(e=0;this.shapes.length>e;e++)t=this.shapes[e],t.rotate(this.redoRotates[e],this.center,!1),t.hasOwnProperty("layout")&&t.layout(t),t.updateModel();this.adorner&&(this.adorner._initialize(),this.adorner.refresh())}}),b=j.extend({init:function(e,t,n){this.diagram=e,this.indices=n,this.items=t,this.title="Rotate Unit"},undo:function(){this.diagram._toIndex(this.items,this.indices)},redo:function(){this.diagram.toFront(this.items,!1)}}),x=j.extend({init:function(e,t,n){this.diagram=e,this.indices=n,this.items=t,this.title="Rotate Unit"},undo:function(){this.diagram._toIndex(this.items,this.indices)},redo:function(){this.diagram.toBack(this.items,!1)}}),k=V.Observable.extend({init:function(e){V.Observable.fn.init.call(this,e),this.bind(this.events,e),this.stack=[],this.index=0,this.capacity=100},events:["undone","redone"],begin:function(){this.composite=new u},cancel:function(){this.composite=t},commit:function(e){this.composite.units.length>0&&this._restart(this.composite,e),this.composite=t},addCompositeItem:function(e){this.composite?this.composite.add(e):this.add(e)},add:function(e,t){this._restart(e,t)},pop:function(){this.index>0&&(this.stack.pop(),this.index--)},count:function(){return this.stack.length},undo:function(){this.index>0&&(this.index--,this.stack[this.index].undo(),this.trigger("undone"))},redo:function(){this.stack.length>0&&this.stack.length>this.index&&(this.stack[this.index].redo(),this.index++,this.trigger("redone"))},_restart:function(e,t){this.stack.splice(this.index,this.stack.length-this.index),this.stack.push(e),t!==!1?this.redo():this.index++,this.stack.length>this.capacity&&(this.stack.splice(0,this.stack.length-this.capacity),this.index=this.capacity)},clear:function(){this.stack=[],this.index=0}}),C=j.extend({init:function(e){this.toolService=e},start:function(){},move:function(){},end:function(){},tryActivate:function(){return!1},getCursor:function(){return ot.arrow}}),S=C.extend({init:function(t){var n,i,r,o,a=this,s=V.support.mobileOS?At:Dt;C.fn.init.call(a,t),n=a.toolService.diagram,i=n.canvas,r=n.scroller=a.scroller=e(n.scrollable).kendoMobileScroller({friction:s,velocityMultiplier:Mt,mousewheelScrolling:!1,zoom:!1,scroll:rt(a._move,a)}).data("kendoMobileScroller"),i.translate&&(a.movableCanvas=new et(i.element)),o=function(e,t,n){e.makeVirtual(),e.virtualSize(t||St,n||Tt)},o(r.dimensions.x),o(r.dimensions.y),r.disable()},tryActivate:function(e,t){var n=this.toolService,r=n.diagram.options.pannable,o=t.ctrlKey;return nt(r.key)&&(o=r.key&&"none"!=r.key?t[r.key+"Key"]&&!(t.ctrlKey&&nt(n.hoveredItem)):i(t)),r!==!1&&o&&!nt(n.hoveredAdorner)&&!nt(n._hoveredConnector)},start:function(){this.scroller.enable()},move:function(){},_move:function(e){var t=this,n=t.toolService.diagram,i=n.canvas,r=new Q(e.scrollLeft,e.scrollTop);i.translate?(n._storePan(r.times(-1)),t.movableCanvas.moveTo(r),i.translate(r.x,r.y)):r=r.plus(n._pan.times(-1)),n.trigger(Pt,{pan:r})},end:function(){this.scroller.disable()},getCursor:function(){return ot.move}}),T=j.extend({init:function(e){this.toolService=e},tryActivate:function(){return!0},start:function(e,t){var i=this.toolService,o=i.diagram,a=i.hoveredItem,s=o.options.selectable;a&&(r(s,t)&&n(a,t),a.adorner&&(this.adorner=a.adorner,this.handle=this.adorner._hitTest(e))),this.handle||(this.handle=o._resizingAdorner._hitTest(e),this.handle&&(this.adorner=o._resizingAdorner)),this.adorner&&(this.adorner.isDragHandle(this.handle)&&o.trigger(ft,{shapes:this.adorner.shapes,connections:[]})?(i.startPoint=e,i.end(e)):this.adorner.start(e))
  },move:function(e){this.adorner&&(this.adorner.move(this.handle,e),this.adorner.isDragHandle(this.handle)&&this.toolService.diagram.trigger(gt,{shapes:this.adorner.shapes,connections:[]}))},end:function(e,n){var i,r=this.toolService.diagram,o=this.toolService,a=this.adorner;a&&(a.isDragHandle(this.handle)&&r.trigger(mt,{shapes:a.shapes,connections:[]})?a.cancel():(i=a.stop(),i&&r.undoRedoService.add(i,!1))),o.hoveredItem&&this.toolService.triggerClick({item:o.hoveredItem,point:e,meta:n}),this.adorner=t,this.handle=t},getCursor:function(e){return this.toolService.hoveredItem?this.toolService.hoveredItem._getCursor(e):ot.arrow}}),D=j.extend({init:function(e){this.toolService=e},tryActivate:function(e,t){var n=this.toolService,i=r(n.diagram.options.selectable,t);return i&&!nt(n.hoveredItem)&&!nt(n.hoveredAdorner)},start:function(e){var t=this.toolService.diagram;t.deselect(),t.selector.start(e)},move:function(e){var t=this.toolService.diagram;t.selector.move(e)},end:function(e,t){var n=this.toolService.diagram,i=this.toolService.hoveredItem,r=n.selector.bounds();i&&i.isSelected||t.ctrlKey||n.deselect(),r.isEmpty()||n.selectArea(r),n.selector.end()},getCursor:function(){return ot.arrow}}),A=j.extend({init:function(e){this.toolService=e,this.type="ConnectionTool"},tryActivate:function(){return this.toolService._hoveredConnector},start:function(e,t){var i=this.toolService.diagram,r=this.toolService._hoveredConnector,o=i._createConnection({},r._c,e);s(o)&&!i.trigger(ft,{shapes:[],connections:[o]})&&i._addConnection(o)?(this.toolService._connectionManipulation(o,r._c.shape,!0),this.toolService._removeHover(),n(this.toolService.activeConnection,t)):(o.source(null),this.toolService.end(e))},move:function(e){var t=this.toolService,n=t.activeConnection;return n.target(e),t.diagram.trigger(gt,{shapes:[],connections:[n]}),!0},end:function(e){var t,n=this.toolService,i=n.diagram,r=n.activeConnection,o=n.hoveredItem,a=n._hoveredConnector;r&&(t=a&&a._c!=r.sourceConnector?a._c:o&&o instanceof W.Shape?o.getConnector(st)||o.getConnector(e):e,r.target(t),i.trigger(mt,{shapes:[],connections:[r]})?(i.remove(r,!1),i.undoRedoService.pop()):(r.updateModel(),i._syncConnectionChanges()),n._connectionManipulation())},getCursor:function(){return ot.arrow}}),M=j.extend({init:function(e){this.toolService=e,this.type="ConnectionTool"},tryActivate:function(e,t){var n=this.toolService,i=n.diagram,o=i.options.selectable,a=n.hoveredItem,s=r(o,t)&&a&&a.path&&!(a.isSelected&&t.ctrlKey);return s&&(this._c=a),s},start:function(e,t){var i,r=this._c;n(r,t),i=r.adorner,s(r)&&i&&!this.toolService.diagram.trigger(ft,{shapes:[],connections:[r]})?(this.handle=i._hitTest(e),i.start(e)):(this.toolService.startPoint=e,this.toolService.end(e))},move:function(e){var n=this._c.adorner;return s(this._c)&&n?(n.move(this.handle,e),this.toolService.diagram.trigger(gt,{shapes:[],connections:[this._c]}),!0):t},end:function(e,t){var n,i=this._c,r=i.adorner,o=this.toolService,a=o.diagram;r&&(o.triggerClick({item:i,point:e,meta:t}),s(i)&&(n=r.stop(e),a.trigger(mt,{shapes:[],connections:[i]})?n.undo():(a.undoRedoService.add(n,!1),i.updateModel(),a._syncConnectionChanges())))},getCursor:function(){return ot.move}}),I=j.extend({init:function(e){this.diagram=e,this.tools=[new S(this),new M(this),new A(this),new D(this),new T(this)],this.activeTool=t},start:function(e,t){return t=J({},t),this.activeTool&&this.activeTool.end(e,t),this._updateHoveredItem(e),this._activateTool(e,t),this.activeTool.start(e,t),this._updateCursor(e),this.diagram.focus(),this.startPoint=e,!0},move:function(e,t){t=J({},t);var n=!0;return this.activeTool&&(n=this.activeTool.move(e,t)),n&&this._updateHoveredItem(e),this._updateCursor(e),!0},end:function(e,n){return n=J({},n),this.activeTool&&this.activeTool.end(e,n),this.activeTool=t,this._updateCursor(e),!0},keyDown:function(e,t){var n,i=this.diagram;if(t=J({ctrlKey:!1,metaKey:!1,altKey:!1},t),!t.ctrlKey&&!t.metaKey||t.altKey){if(46===e||8===e)return n=this.diagram._triggerRemove(i.select()),n.length&&(this.diagram.remove(n,!0),this.diagram._syncChanges(),this.diagram._destroyToolBar()),!0;if(27===e)return this._discardNewConnection(),i.deselect(),i._destroyToolBar(),!0}else{if(o(e,"a"))return i.selectAll(),i._destroyToolBar(),!0;if(o(e,"z"))return i.undo(),i._destroyToolBar(),!0;if(o(e,"y"))return i.redo(),i._destroyToolBar(),!0;o(e,"c")?(i.copy(),i._destroyToolBar()):o(e,"x")?(i.cut(),i._destroyToolBar()):o(e,"v")?(i.paste(),i._destroyToolBar()):o(e,"l")?(i.layout(),i._destroyToolBar()):o(e,"d")&&(i._destroyToolBar(),i.copy(),i.paste())}},wheel:function(e,t){var n=this.diagram,i=t.delta,r=n.zoom(),o=n.options,a=o.zoomRate,s={point:e,meta:t,zoom:r};if(!n.trigger(kt,s))return 0>i?r+=a:r-=a,r=V.dataviz.round(Math.max(o.zoomMin,Math.min(o.zoomMax,r)),2),s.zoom=r,n.zoom(r,s),n.trigger(Ct,s),!0},setTool:function(e,t){e.toolService=this,this.tools[t]=e},triggerClick:function(e){this.startPoint.equals(e.point)&&this.diagram.trigger("click",e)},_discardNewConnection:function(){this.newConnection&&(this.diagram.remove(this.newConnection),this.newConnection=t)},_activateTool:function(e,t){var n,i;for(n=0;this.tools.length>n;n++)if(i=this.tools[n],i.tryActivate(e,t)){this.activeTool=i;break}},_updateCursor:function(e){var t=this.diagram.element,n=this.activeTool?this.activeTool.getCursor(e):this.hoveredAdorner?this.hoveredAdorner._getCursor(e):this.hoveredItem?this.hoveredItem._getCursor(e):ot.arrow;t.css({cursor:n}),tt.msie&&7==tt.version&&(t[0].style.cssText=t[0].style.cssText)},_connectionManipulation:function(e,n,i){this.activeConnection=e,this.disabledShape=n,this.newConnection=i?this.activeConnection:t},_updateHoveredItem:function(e){var n=this._hitTest(e),i=this.diagram;n==this.hoveredItem||this.disabledShape&&n==this.disabledShape||(this.hoveredItem&&(i.trigger(xt,{item:this.hoveredItem}),this.hoveredItem._hover(!1)),n&&n.options.enable?(i.trigger(bt,{item:n}),this.hoveredItem=n,this.hoveredItem._hover(!0)):this.hoveredItem=t)},_removeHover:function(){this.hoveredItem&&(this.hoveredItem._hover(!1),this.hoveredItem=t)},_hitTest:function(e){var n,i,r,o,a=this.diagram;if(this._hoveredConnector&&(this._hoveredConnector._hover(!1),this._hoveredConnector=t),a._connectorsAdorner._visible&&(n=a._connectorsAdorner._hitTest(e)))return n;if(n=this.diagram._resizingAdorner._hitTest(e)){if(this.hoveredAdorner=a._resizingAdorner,0!==n.x||0!==n.y)return;n=t}else this.hoveredAdorner=t;if(!this.activeTool||"ConnectionTool"!==this.activeTool.type){for(o=[],r=0;a._selectedItems.length>r;r++)i=a._selectedItems[r],i instanceof W.Connection&&o.push(i);n=this._hitTestItems(o,e)}return n||this._hitTestElements(e)},_hitTestElements:function(e){var t,n,i,r,o=this.diagram,a=this._hitTestItems(o.shapes,e),s=this._hitTestItems(o.connections,e);return this.activeTool&&"ConnectionTool"==this.activeTool.type||!a||!s||l(a,e)||(n=o.mainLayer,i=it(a.visual,n.children),r=it(s.visual,n.children),t=i>r?a:s),t||a||s},_hitTestItems:function(e,t){var n,i,r;for(n=e.length-1;n>=0;n--)if(i=e[n],r=i._hitTest(t))return r}}),P=V.Class.extend({init:function(){}}),E=P.extend({init:function(e){var t=this;P.fn.init.call(t),this.connection=e},hitTest:function(e){var t=this.getBounds().inflate(at);return t.contains(e)?W.Geometry.distanceToPolyline(e,this.connection.allPoints())<at:!1},getBounds:function(){var e,t=this.connection.allPoints(),n=t[0],i=t[t.length-1],r=Math.max(n.x,i.x),o=Math.min(n.x,i.x),a=Math.min(n.y,i.y),s=Math.max(n.y,i.y);for(e=1;t.length-1>e;++e)r=Math.max(r,t[e].x),o=Math.min(o,t[e].x),a=Math.min(a,t[e].y),s=Math.max(s,t[e].y);return new q(o,a,r-o,s-a)}}),F=E.extend({init:function(e){var t=this;E.fn.init.call(t),this.connection=e},route:function(){}}),B=E.extend({SAME_SIDE_DISTANCE_RATIO:5,init:function(e){var t=this;E.fn.init.call(t),this.connection=e},routePoints:function(e,t,n,i){var r;return r=n&&i?this._connectorPoints(e,t,n,i):this._floatingPoints(e,t,n)},route:function(){var e=this.connection._resolvedSourceConnector,t=this.connection._resolvedTargetConnector,n=this.connection.sourcePoint(),i=this.connection.targetPoint(),r=this.routePoints(n,i,e,t);this.connection.points(r)},_connectorSides:[{name:"Top",axis:"y",boundsPoint:"topLeft",secondarySign:1},{name:"Left",axis:"x",boundsPoint:"topLeft",secondarySign:1},{name:"Bottom",axis:"y",boundsPoint:"bottomRight",secondarySign:-1},{name:"Right",axis:"x",boundsPoint:"bottomRight",secondarySign:-1}],_connectorSide:function(e,t){var n,i,r,o,a,s=e.position(),l=e.shape.bounds(Et),c={topLeft:l.topLeft(),bottomRight:l.bottomRight()},d=this._connectorSides,u=V.util.MAX_NUM;for(a=0;d.length>a;a++)o=d[a],r=o.axis,n=Math.round(Math.abs(s[r]-c[o.boundsPoint][r])),u>n?(u=n,i=o):n===u&&(s[r]-t[r])*o.secondarySign>(s[i.axis]-t[i.axis])*i.secondarySign&&(i=o);return i.name},_sameSideDistance:function(e){var t=e.shape.bounds(Et);return Math.min(t.width,t.height)/this.SAME_SIDE_DISTANCE_RATIO},_connectorPoints:function(e,t,n,i){var r,o,a=this._connectorSide(n,t),s=this._connectorSide(i,e),l=t.x-e.x,c=t.y-e.y,d=this._sameSideDistance(n),u=[];return a===lt||a==ut?s==lt||s==ut?a==s?(o=a==lt?Math.min(e.y,t.y)-d:Math.max(e.y,t.y)+d,u=[new Q(e.x,o),new Q(t.x,o)]):u=[new Q(e.x,e.y+c/2),new Q(t.x,e.y+c/2)]:u=[new Q(e.x,t.y)]:s==dt||s==ct?a==s?(r=a==dt?Math.min(e.x,t.x)-d:Math.max(e.x,t.x)+d,u=[new Q(r,e.y),new Q(r,t.y)]):u=[new Q(e.x+l/2,e.y),new Q(e.x+l/2,e.y+c)]:u=[new Q(t.x,e.y)],u},_floatingPoints:function(e,t,n){var i,r,o,a=n?this._connectorSide(n,t):null,s=this._startHorizontal(e,t,a),l=[e,e,t,t],c=t.x-e.x,d=t.y-e.y,u=l.length;for(o=1;u-1>o;++o)s?o%2!==0?(i=c/(u/2),r=0):(i=0,r=d/((u-1)/2)):o%2!==0?(i=0,r=d/(u/2)):(i=c/((u-1)/2),r=0),l[o]=new Q(l[o-1].x+i,l[o-1].y+r);return o--,l[u-2]=s&&o%2!==0||!s&&o%2===0?new Q(l[u-1].x,l[u-2].y):new Q(l[u-2].x,l[u-1].y),[l[1],l[2]]},_startHorizontal:function(e,t,n){var i;return i=null===n||n!==ct&&n!==dt?Math.abs(e.x-t.x)>Math.abs(e.y-t.y):!0}}),z=j.extend({init:function(e,t){var n=this;n.diagram=e,n.options=J({},n.options,t),n.visual=new G,n.diagram._adorners.push(n)},refresh:function(){}}),R=z.extend({init:function(e,t){var n,i,r,o=this;o.connection=e,n=o.connection.diagram,o._ts=n.toolService,z.fn.init.call(o,n,t),i=o.connection.sourcePoint(),r=o.connection.targetPoint(),o.spVisual=new X(J(o.options.handles,{center:i})),o.epVisual=new X(J(o.options.handles,{center:r})),o.visual.append(o.spVisual),o.visual.append(o.epVisual)},options:{handles:{}},_getCursor:function(){return ot.move},start:function(e){switch(this.handle=this._hitTest(e),this.startPoint=e,this._initialSource=this.connection.source(),this._initialTarget=this.connection.target(),this.handle){case-1:this.connection.targetConnector&&this._ts._connectionManipulation(this.connection,this.connection.targetConnector.shape);break;case 1:this.connection.sourceConnector&&this._ts._connectionManipulation(this.connection,this.connection.sourceConnector.shape)}},move:function(e,t){switch(e){case-1:this.connection.source(t);break;case 1:this.connection.target(t);break;default:var n=t.minus(this.startPoint);this.startPoint=t,this.connection.sourceConnector||this.connection.source(this.connection.sourcePoint().plus(n)),this.connection.targetConnector||this.connection.target(this.connection.targetPoint().plus(n))}return this.refresh(),!0},stop:function(e){var n,i=this.diagram.toolService,r=i.hoveredItem;return n=i._hoveredConnector?i._hoveredConnector._c:r&&r instanceof W.Shape?r.getConnector(st)||r.getConnector(e):e,-1===this.handle?this.connection.source(n):1===this.handle&&this.connection.target(n),this.handle=t,this._ts._connectionManipulation(),new p(this.connection,this._initialSource,this._initialTarget)},_hitTest:function(e){var t=this.connection.sourcePoint(),n=this.connection.targetPoint(),i=this.options.handles.width/2,r=this.options.handles.height/2,o=new q(t.x,t.y).inflate(i,r),a=new q(n.x,n.y).inflate(i,r);return o.contains(e)?-1:a.contains(e)?1:0},refresh:function(){this.spVisual.redraw({center:this.diagram.modelToLayer(this.connection.sourcePoint())}),this.epVisual.redraw({center:this.diagram.modelToLayer(this.connection.targetPoint())})}}),L=z.extend({init:function(e,t){var n=this;z.fn.init.call(n,e,t),n._refreshHandler=function(e){e.item==n.shape&&n.refresh()}},show:function(e){var t,n,i,r=this;for(r._visible=!0,r.shape=e,r.diagram.bind(_t,r._refreshHandler),t=e.connectors.length,r.connectors=[],r.visual.clear(),n=0;t>n;n++)i=new N(e.connectors[n]),r.connectors.push(i),r.visual.append(i.visual);r.visual.visible(!0),r.refresh()},destroy:function(){var e=this;e.diagram.unbind(_t,e._refreshHandler),e.shape=t,e._visible=t,e.visual.visible(!1)},_hitTest:function(e){var t,n;for(n=0;this.connectors.length>n;n++)if(t=this.connectors[n],t._hitTest(e)){t._hover(!0),this.diagram.toolService._hoveredConnector=t;break}},refresh:function(){if(this.shape){var t=this.shape.bounds();t=this.diagram.modelToLayer(t),this.visual.position(t.topLeft()),e.each(this.connectors,function(){this.refresh()})}}}),H=z.extend({init:function(e,t){var n=this;z.fn.init.call(n,e,t),n._manipulating=!1,n.map=[],n.shapes=[],n._initSelection(),n._createHandles(),n.redraw(),n.diagram.bind("select",function(e){n._initialize(e.selected)}),n._refreshHandler=function(){n._internalChange||(n.refreshBounds(),n.refresh())},n._rotatedHandler=function(){1==n.shapes.length&&(n._angle=n.shapes[0].rotate().angle),n._refreshHandler()},n.diagram.bind(_t,n._refreshHandler).bind(vt,n._rotatedHandler),n.refreshBounds(),n.refresh()},options:{editable:{},selectable:{stroke:{color:"#778899",width:1,dashType:"dash"},fill:{color:It}},offset:10},_initSelection:function(){var e=this,t=e.diagram,n=t.options.selectable,i=J({},e.options.selectable,n);e.rect=new $(i),e.visual.append(e.rect)},_createHandles:function(){var e,t,n,i,r=this.options.editable;if(r&&r.resize)for(e=r.resize.handles,i=-1;1>=i;i++)for(n=-1;1>=n;n++)(0!==i||0!==n)&&(t=new $(e),t.drawingElement._hover=rt(this._hover,this),this.map.push({x:i,y:n,visual:t}),this.visual.append(t))},bounds:function(e){return e?(this._innerBounds=e.clone(),this._bounds=this.diagram.modelToLayer(e).inflate(this.options.offset,this.options.offset),t):this._bounds},_hitTest:function(e){var n,i,r,o,a=this.diagram.modelToLayer(e),s=this.options.editable,l=this.map.length;if(this._angle&&(a=a.clone().rotate(this._bounds.center(),this._angle)),s&&s.rotate&&this._rotationThumbBounds&&this._rotationThumbBounds.contains(a))return new Q(-1,-2);if(s&&s.resize)for(n=0;l>n;n++)if(o=this.map[n],i=new Q(o.x,o.y),r=this._getHandleBounds(i),r.offset(this._bounds.x,this._bounds.y),r.contains(a))return i;return this._bounds.contains(a)?new Q(0,0):t},_getHandleBounds:function(e){var n,i,r,o,a=this.options.editable;return a&&a.resize?(n=a.resize.handles||{},i=n.width,r=n.height,o=new q(0,0,i,r),0>e.x?o.x=-i/2:0===e.x?o.x=Math.floor(this._bounds.width/2)-i/2:e.x>0&&(o.x=this._bounds.width+1-i/2),0>e.y?o.y=-r/2:0===e.y?o.y=Math.floor(this._bounds.height/2)-r/2:e.y>0&&(o.y=this._bounds.height+1-r/2),o):t},_getCursor:function(e){var t,n=this._hitTest(e);if(n&&n.x>=-1&&1>=n.x&&n.y>=-1&&1>=n.y&&this.options.editable&&this.options.editable.resize){if(t=this._angle,t&&(t=360-t,n.rotate(new Q(0,0),t),n=new Q(Math.round(n.x),Math.round(n.y))),-1==n.x&&-1==n.y)return"nw-resize";if(1==n.x&&1==n.y)return"se-resize";if(-1==n.x&&1==n.y)return"sw-resize";if(1==n.x&&-1==n.y)return"ne-resize";if(0===n.x&&-1==n.y)return"n-resize";if(0===n.x&&1==n.y)return"s-resize";if(1==n.x&&0===n.y)return"e-resize";if(-1==n.x&&0===n.y)return"w-resize"}return this._manipulating?ot.move:ot.select},_initialize:function(){var e,t,n=this,i=n.diagram.select();for(n.shapes=[],e=0;i.length>e;e++)t=i[e],t instanceof W.Shape&&(n.shapes.push(t),t._rotationOffset=new Q);n._angle=1==n.shapes.length?n.shapes[0].rotate().angle:0,n._startAngle=n._angle,n._rotates(),n._positions(),n.refreshBounds(),n.refresh(),n.redraw()},_rotates:function(){var e,t,n=this;for(n.initialRotates=[],e=0;n.shapes.length>e;e++)t=n.shapes[e],n.initialRotates.push(t.rotate().angle)},_positions:function(){var e,t,n=this;for(n.initialStates=[],e=0;n.shapes.length>e;e++)t=n.shapes[e],n.initialStates.push(t.bounds())},_hover:function(e,t){var n,i,r,o,a=this.options.editable;a&&a.resize&&(n=a.resize.handles,i=n.hover,r=n.stroke,o=n.fill,e&&Y.isDefined(i.stroke)&&(r=J({},r,i.stroke)),e&&Y.isDefined(i.fill)&&(o=i.fill),t.stroke(r.color,r.width,r.opacity),t.fill(o.color,o.opacity))},start:function(e){var t,n;for(this._sp=e,this._cp=e,this._lp=e,this._manipulating=!0,this._internalChange=!0,this.shapeStates=[],t=0;this.shapes.length>t;t++)n=this.shapes[t],this.shapeStates.push(n.bounds())},redraw:function(){var e,t,n=this,i=n.options.editable,r=i.resize,o=i.rotate,a=i&&r?!0:!1,s=i&&o?!0:!1;for(e=0;this.map.length>e;e++)t=this.map[e],t.visual.visible(a);n.rotationThumb&&n.rotationThumb.visible(s)},angle:function(e){return nt(e)&&(this._angle=e),this._angle},rotate:function(){var e,t,n=this._innerBounds.center(),i=this.angle();for(this._internalChange=!0,e=0;this.shapes.length>e;e++)t=this.shapes[e],i=(i+this.initialRotates[e]-this._startAngle)%360,t.rotate(i,n);this.refresh()},move:function(e,n){var i,r,o,l,c,d,u,h,p,f,g,m,v,_,y=new Q,w=new Q,b=0;if(-2===e.y&&-1===e.x){for(l=this._innerBounds.center(),this._angle=this._truncateAngle(Y.findAngle(l,n)),d=0;this.shapes.length>d;d++)c=this.shapes[d],u=(this._angle+this.initialRotates[d]-this._startAngle)%360,c.rotate(u,l),c.hasOwnProperty("layout")&&c.layout(c),this._rotating=!0;this.refresh()}else{if(this.shouldSnap()){if(m=this._truncateDistance(n.minus(this._lp)),0===m.x&&0===m.y)return this._cp=n,t;i=m,this._lp=new Q(this._lp.x+m.x,this._lp.y+m.y)}else i=n.minus(this._cp);for(this.isDragHandle(e)?(w=y=i,r=!0):(this._angle&&i.rotate(new Q(0,0),this._angle),-1==e.x?y.x=i.x:1==e.x&&(w.x=i.x),-1==e.y?y.y=i.y:1==e.y&&(w.y=i.y)),r||(p=a(e,this._innerBounds),f=(this._innerBounds.width+i.x*e.x)/this._innerBounds.width,g=(this._innerBounds.height+i.y*e.y)/this._innerBounds.height),d=0;this.shapes.length>d;d++){if(c=this.shapes[d],o=c.bounds(),r){if(!s(c))continue;h=this._displaceBounds(o,y,w,r)}else h=o.clone(),h.scale(f,g,p,this._innerBounds.center(),c.rotate().angle),v=h.center(),v.rotate(o.center(),-this._angle),h=new q(v.x-h.width/2,v.y-h.height/2,h.width,h.height);h.width>=c.options.minWidth&&h.height>=c.options.minHeight&&(_=o,c.bounds(h),c.hasOwnProperty("layout")&&c.layout(c,_,h),(_.width!==h.width||_.height!==h.height)&&c.rotate(c.rotate().angle),b+=1)}b&&(b==d?(h=this._displaceBounds(this._innerBounds,y,w,r),this.bounds(h)):this.refreshBounds(),this.refresh()),this._positions()}this._cp=n},isDragHandle:function(e){return 0===e.x&&0===e.y},cancel:function(){var e,n=this.shapes,i=this.shapeStates;for(e=0;n.length>e;e++)n[e].bounds(i[e]);this.refreshBounds(),this.refresh(),this._manipulating=t,this._internalChange=t,this._rotating=t},_truncatePositionToGuides:function(e){return this.diagram.ruler?this.diagram.ruler.truncatePositionToGuides(e):e},_truncateSizeToGuides:function(e){return this.diagram.ruler?this.diagram.ruler.truncateSizeToGuides(e):e},_truncateAngle:function(e){var t=this.snapOptions(),n=Math.max(t.angle||pt,wt);return t?Math.floor(e%360/n)*n:e%360},_truncateDistance:function(e){var t,n;return e instanceof W.Point?new W.Point(this._truncateDistance(e.x),this._truncateDistance(e.y)):(t=this.snapOptions()||{},n=Math.max(t.size||ht,yt),t?Math.floor(e/n)*n:e)},snapOptions:function(){var e=this.diagram.options.editable,t=((e||{}).drag||{}).snap||{};return t},shouldSnap:function(){var e=this.diagram.options.editable,t=(e||{}).drag,n=(t||{}).snap;return e!==!1&&t!==!1&&n!==!1},_displaceBounds:function(e,t,n,i){var r,o=e.topLeft().plus(t),a=e.bottomRight().plus(n),s=q.fromPoints(o,a);return i||(r=s.center(),r.rotate(e.center(),-this._angle),s=new q(r.x-s.width/2,r.y-s.height/2,s.width,s.height)),s},stop:function(){var e,n,i,r;if(this._cp!=this._sp)if(this._rotating)e=new w(this,this.shapes,this.initialRotates),this._rotating=!1;else if(this._diffStates()){if(this.diagram.ruler)for(n=0;this.shapes.length>n;n++)i=this.shapes[n],r=i.bounds(),r=this._truncateSizeToGuides(this._truncatePositionToGuides(r)),i.bounds(r),this.refreshBounds(),this.refresh();for(n=0;this.shapes.length>n;n++)i=this.shapes[n],i.updateModel();e=new m(this.shapes,this.shapeStates,this),this.diagram._syncShapeChanges()}return this._manipulating=t,this._internalChange=t,this._rotating=t,e},_diffStates:function(){var e,t=this.shapes,n=this.shapeStates;for(e=0;t.length>e;e++)if(!t[e].bounds().equals(n[e]))return!0;return!1},refreshBounds:function(){var e=1==this.shapes.length?this.shapes[0].bounds().clone():this.diagram.boundingBox(this.shapes,!0);this.bounds(e)},refresh:function(){var t,n,i,r,o=this;this.shapes.length>0?(n=this.bounds(),this.visual.visible(!0),this.visual.position(n.topLeft()),e.each(this.map,function(){t=o._getHandleBounds(new Q(this.x,this.y)),this.visual.position(t.topLeft())}),this.visual.position(n.topLeft()),i=new Q(n.width/2,n.height/2),this.visual.rotate(this._angle,i),this.rect.redraw({width:n.width,height:n.height}),this.rotationThumb&&(r=this.options.editable.rotate.thumb,this._rotationThumbBounds=new q(n.center().x,n.y+r.y,0,0).inflate(r.width),this.rotationThumb.redraw({x:n.width/2-r.width/2}))):this.visual.visible(!1)}}),O=j.extend({init:function(e){var t=e.options.selectable;this.options=J({},this.options,t),this.visual=new $(this.options),this.diagram=e},options:{stroke:{color:"#778899",width:1,dashType:"dash"},fill:{color:It}},start:function(e){this._sp=this._ep=e,this.refresh(),this.diagram._adorn(this,!0)},end:function(){this._sp=this._ep=t,this.diagram._adorn(this,!1)},bounds:function(e){return e&&(this._bounds=e),this._bounds},move:function(e){this._ep=e,this.refresh()},refresh:function(){if(this._sp){var e=q.fromPoints(this.diagram.modelToLayer(this._sp),this.diagram.modelToLayer(this._ep));this.bounds(q.fromPoints(this._sp,this._ep)),this.visual.position(e.topLeft()),this.visual.redraw({height:e.height+1,width:e.width+1})}}}),N=j.extend({init:function(e){this.options=J({},e.options),this._c=e,this.visual=new X(this.options),this.refresh()},_hover:function(e){var t=this.options,n=t.hover,i=t.stroke,r=t.fill;e&&Y.isDefined(n.stroke)&&(i=J({},i,n.stroke)),e&&Y.isDefined(n.fill)&&(r=n.fill),this.visual.redraw({stroke:i,fill:r})},refresh:function(){var e=this._c.shape.diagram.modelToView(this._c.position()),t=e.minus(this._c.shape.bounds("transformed").topLeft()),n=new q(e.x,e.y,0,0);n.inflate(this.options.width/2,this.options.height/2),this._visualBounds=n,this.visual.redraw({center:new Q(t.x,t.y)})},_hitTest:function(e){var t=this._c.shape.diagram.modelToView(e);return this._visualBounds.contains(t)}}),J(W,{CompositeUnit:u,TransformUnit:m,PanUndoUnit:y,AddShapeUnit:_,AddConnectionUnit:v,DeleteShapeUnit:g,DeleteConnectionUnit:f,ConnectionEditAdorner:R,ConnectionTool:A,ConnectorVisual:N,UndoRedoService:k,ResizingAdorner:H,Selector:O,ToolService:I,ConnectorsAdorner:L,LayoutUndoUnit:d,ConnectionEditUnit:h,ToFrontUnit:b,ToBackUnit:x,ConnectionRouterBase:P,PolylineRouter:F,CascadingRouter:B,SelectionTool:D,ScrollerTool:S,PointerTool:T,ConnectionEditTool:M,RotateUnit:w})}(window.kendo.jQuery),function(e){var t=window.kendo,n=t.dataviz.diagram,i=n.Graph,r=n.Node,o=n.Link,a=t.deepExtend,s=n.Size,l=n.Rect,c=n.Dictionary,d=n.Set,u=n.Graph,h=n.Utils,p=n.Point,f=1e-6,g=Math.PI/180,m=h.contains,v=e.grep,_=t.Class.extend({defaultOptions:{type:"Tree",subtype:"Down",roots:null,animate:!1,limitToView:!1,friction:.9,nodeDistance:50,iterations:300,horizontalSeparation:90,verticalSeparation:50,underneathVerticalTopOffset:15,underneathHorizontalOffset:15,underneathVerticalSeparation:15,grid:{width:1500,offsetX:50,offsetY:50,componentSpacingX:20,componentSpacingY:20},layerSeparation:50,layeredIterations:2,startRadialAngle:0,endRadialAngle:360,radialSeparation:150,radialFirstLevelSeparation:200,keepComponentsInOneRadialLayout:!1,ignoreContainers:!0,layoutContainerChildren:!1,ignoreInvisible:!0,animateTransitions:!1},init:function(){},gridLayoutComponents:function(e){var t,n,i,r,o,a,s,l,c,d,u,f,g,m,v;if(!e)throw"No components supplied.";for(h.forEach(e,function(e){e.calcBounds()}),e.sort(function(e,t){return t.bounds.width-e.bounds.width}),t=this.options.grid.width,n=this.options.grid.componentSpacingX,i=this.options.grid.componentSpacingY,r=0,o=this.options.grid.offsetX,a=this.options.grid.offsetY,s=o,l=a,d=[],u=[];e.length>0;){for(s>=t&&(s=o,l+=r+i,r=0),f=e.pop(),this.moveToOffset(f,new p(s,l)),c=0;f.nodes.length>c;c++)u.push(f.nodes[c]);for(c=0;f.links.length>c;c++)d.push(f.links[c]);g=f.bounds,m=g.height,(0>=m||isNaN(m))&&(m=0),v=g.width,(0>=v||isNaN(v))&&(v=0),m>=r&&(r=m),s+=v+n}return{nodes:u,links:d}},moveToOffset:function(e,t){var n,i,r,o,a,s,c,d,u=e.bounds,h=t.x-u.x,f=t.y-u.y;for(n=0;e.nodes.length>n;n++)r=e.nodes[n],o=r.bounds(),0===o.width&&0===o.height&&0===o.x&&0===o.y&&(o=new l(0,0,0,0)),o.x+=h,o.y+=f,r.bounds(o);for(n=0;e.links.length>n;n++)if(a=e.links[n],a.points){for(s=[],c=a.points,i=0;c.length>i;i++)d=c[i],d.x+=h,d.y+=f,s.push(d);a.points=s}return this.currentHorizontalOffset+=u.width+this.options.grid.offsetX,new p(h,f)},transferOptions:function(e){this.options=t.deepExtend({},this.defaultOptions),h.isUndefined(e)||(this.options=t.deepExtend(this.options,e||{}))}}),y=t.Class.extend({init:function(e){this.nodeMap=new c,this.shapeMap=new c,this.nodes=[],this.edges=[],this.edgeMap=new c,this.finalNodes=[],this.finalLinks=[],this.ignoredConnections=[],this.ignoredShapes=[],this.hyperMap=new c,this.hyperTree=new i,this.finalGraph=null,this.diagram=e},convert:function(e){if(h.isUndefined(this.diagram))throw"No diagram to convert.";return this.options=t.deepExtend({ignoreInvisible:!0,ignoreContainers:!0,layoutContainerChildren:!1},e||{}),this.clear(),this._renormalizeShapes(),this._renormalizeConnections(),this.finalNodes=new c(this.nodes),this.finalLinks=new c(this.edges),this.finalGraph=new i,this.finalNodes.forEach(function(e){this.finalGraph.addNode(e)},this),this.finalLinks.forEach(function(e){this.finalGraph.addExistingLink(e)},this),this.finalGraph},mapConnection:function(e){return this.edgeMap.first(function(t){return m(this.edgeMap.get(t),e)})},mapShape:function(e){var t,n,i,r=this.nodeMap.keys();for(t=0,n=r.length;n>t;t++)if(i=r[t],m(this.nodeMap.get(i),e))return i},getEdge:function(e,t){return h.first(e.links,function(n){return n.getComplement(e)===t})},clear:function(){this.finalGraph=null,this.hyperTree=!this.options.ignoreContainers&&this.options.layoutContainerChildren?new u:null,this.hyperMap=!this.options.ignoreContainers&&this.options.layoutContainerChildren?new c:null,this.nodeMap=new c,this.shapeMap=new c,this.nodes=[],this.edges=[],this.edgeMap=new c,this.ignoredConnections=[],this.ignoredShapes=[],this.finalNodes=[],this.finalLinks=[]},listToRoot:function(e){var t=[],n=e.container;if(!n)return t;for(t.push(n);n.parentContainer;)n=n.parentContainer,t.push(n);return t.reverse(),t},firstNonIgnorableContainer:function(e){return e.isContainer&&!this._isIgnorableItem(e)?e:e.parentContainer?this.firstNonIgnorableContainer(e.parentContainer):null},isContainerConnection:function(e,t){return e.isContainer&&this.isDescendantOf(e,t)?!0:t.isContainer&&this.isDescendantOf(t,e)},isDescendantOf:function(e,t){var n,i,r,o;if(!e.isContainer)throw"Expecting a container.";if(e===t)return!1;if(m(e.children,t))return!0;for(n=[],i=0,r=e.children.length;r>i;i++)o=e.children[i],o.isContainer&&this.isDescendantOf(o,t)&&n.push(o);return n.length>0},isIgnorableItem:function(e){return this.options.ignoreInvisible?e.isCollapsed&&this._isVisible(e)?!1:!e.isCollapsed&&this._isVisible(e)?!1:!0:e.isCollapsed&&!this._isTop(e)},isShapeMapped:function(e){return e.isCollapsed&&!this._isVisible(e)&&!this._isTop(e)},leastCommonAncestor:function(e,t){var n,i,r,o,a,s;if(!e)throw"Parameter should not be null.";if(!t)throw"Parameter should not be null.";if(!this.hyperTree)throw"No hypertree available.";if(n=this.listToRoot(e),i=this.listToRoot(t),r=null,h.isEmpty(n)||h.isEmpty(i))return this.hyperTree.root.data;for(o=n[0],a=i[0],s=0;o===a&&(r=n[s],s++,!(s>=n.length||s>=i.length));)o=n[s],a=i[s];return r?v(this.hyperTree.nodes,function(e){return e.data.container===r}):this.hyperTree.root.data},_isTop:function(e){return!e.parentContainer},_isVisible:function(e){return e.visible()?e.parentContainer?this._isVisible(e.parentContainer):e.visible():!1},_isCollapsed:function(e){return e.isContainer&&e.isCollapsed?!0:e.parentContainer&&this._isCollapsed(e.parentContainer)},_renormalizeShapes:function(){var e,t,n,i;if(!this.options.ignoreContainers)throw"Containers are not supported yet, but stay tuned.";for(e=0,t=this.diagram.shapes.length;t>e;e++)n=this.diagram.shapes[e],this.options.ignoreInvisible&&!this._isVisible(n)||n.isContainer?this.ignoredShapes.push(n):(i=new r(n.id,n),i.isVirtual=!1,this.nodeMap.add(i,[n]),this.nodes.push(i))},_renormalizeConnections:function(){var e,t,n,i,r,a,s,l;if(0!==this.diagram.connections.length)for(e=0,t=this.diagram.connections.length;t>e;e++)if(n=this.diagram.connections[e],this.isIgnorableItem(n))this.ignoredConnections.push(n);else if(i=n.sourceConnector?n.sourceConnector.shape:null,r=n.targetConnector?n.targetConnector.shape:null,i&&r)if(!m(this.ignoredShapes,i)||this.shapeMap.containsKey(i))if(!m(this.ignoredShapes,r)||this.shapeMap.containsKey(r))if(this.shapeMap.containsKey(i)&&(i=this.shapeMap[i]),this.shapeMap.containsKey(r)&&(r=this.shapeMap[r]),a=this.mapShape(i),s=this.mapShape(r),a===s||this.areConnectedAlready(a,s))this.ignoredConnections.push(n);else{if(null===a||null===s)throw"A shape was not mapped to a node.";if(!this.options.ignoreContainers)throw"Containers are not supported yet, but stay tuned.";a.isVirtual||s.isVirtual?this.ignoredConnections.push(n):(l=new o(a,s,n.id,n),this.edgeMap.add(l,[n]),this.edges.push(l))}else this.ignoredConnections.push(n);else this.ignoredConnections.push(n);else this.ignoredConnections.push(n)},areConnectedAlready:function(e,t){return h.any(this.edges,function(n){return n.source===e&&n.target===t||n.source===t&&n.target===e})}}),w=_.extend({init:function(e){var t=this;if(_.fn.init.call(t),h.isUndefined(e))throw"Diagram is not specified.";this.diagram=e},layout:function(e){var t,i,r,o,a,s;if(this.transferOptions(e),t=new y(this.diagram),i=t.convert(e),!i.isEmpty()&&(r=i.getConnectedComponents(),!h.isEmpty(r))){for(o=0;r.length>o;o++)a=r[o],this.layoutGraph(a,e);return s=this.gridLayoutComponents(r),new n.LayoutState(this.diagram,s)}},layoutGraph:function(e,t){var n,i,r;for(h.isDefined(t)&&this.transferOptions(t),this.graph=e,n=9*this.options.nodeDistance,this.temperature=n,i=this._expectedBounds(),this.width=i.width,this.height=i.height,r=0;this.options.iterations>r;r++)this.refineStage=r>=5*this.options.iterations/6,this.tick(),this.temperature=this.refineStage?n/30:n*(1-r/(2*this.options.iterations))},tick:function(){var e,t,n;for(e=0;this.graph.nodes.length>e;e++)this._repulsion(this.graph.nodes[e]);for(e=0;this.graph.links.length>e;e++)this._attraction(this.graph.links[e]);for(e=0;this.graph.nodes.length>e;e++){if(t=this.graph.nodes[e],n=Math.sqrt(t.dx*t.dx+t.dy*t.dy),0===n)return;t.x+=Math.min(n,this.temperature)*t.dx/n,t.y+=Math.min(n,this.temperature)*t.dy/n,this.options.limitToView&&(t.x=Math.min(this.width,Math.max(t.width/2,t.x)),t.y=Math.min(this.height,Math.max(t.height/2,t.y)))}},_shake:function(e){var t=Math.random()*this.options.nodeDistance/4,n=2*Math.random()*Math.PI;e.x+=t*Math.cos(n),e.y-=t*Math.sin(n)},_InverseSquareForce:function(e,t,n){var i,r,o,a,s,l,c;return this.refineStage?(r=t.x-n.x,o=t.y-n.y,a=t.width/2,s=t.height/2,l=n.width/2,c=n.height/2,i=Math.pow(r,2)/Math.pow(a+l+this.options.nodeDistance,2)+Math.pow(o,2)/Math.pow(s+c+this.options.nodeDistance,2)):i=Math.pow(e,2)/Math.pow(this.options.nodeDistance,2),4*i/3},_SquareForce:function(e,t,n){return 1/this._InverseSquareForce(e,t,n)},_repulsion:function(e){e.dx=0,e.dy=0,h.forEach(this.graph.nodes,function(t){var n,i,r,o;
  if(t!==e){for(;e.x===t.x&&e.y===t.y;)this._shake(t);n=e.x-t.x,i=e.y-t.y,r=Math.sqrt(n*n+i*i),o=2*this._SquareForce(r,e,t),e.dx+=n/r*o,e.dy+=i/r*o}},this)},_attraction:function(e){var t,n,i,r,o,a,s=e.target,l=e.source;if(l!==s){for(;l.x===s.x&&l.y===s.y;)this._shake(s);t=l.x-s.x,n=l.y-s.y,i=Math.sqrt(t*t+n*n),r=5*this._InverseSquareForce(i,l,s),o=t/i*r,a=n/i*r,s.dx+=o,s.dy+=a,l.dx-=o,l.dy-=a}},_expectedBounds:function(){var e,t,n,i,r,o=this.graph.nodes.length,a=1.5,s=4;return 0===o?e:(e=h.fold(this.graph.nodes,function(e,t){var n=t.width*t.height;return n>0?e+=Math.sqrt(n):0},0,this),t=e/o,n=t*Math.ceil(Math.sqrt(o)),i=n*Math.sqrt(a),r=n/Math.sqrt(a),{width:i*s,height:r*s})}}),b=t.Class.extend({init:function(e){this.center=null,this.options=e},layout:function(e,t){if(this.graph=e,this.graph.nodes&&0!==this.graph.nodes.length){if(!m(this.graph.nodes,t))throw"The given root is not in the graph.";this.center=t,this.graph.cacheRelationships(),this.layoutSwitch()}},layoutLeft:function(e){var t,n,i,r,o,a,l,c;for(this.setChildrenDirection(this.center,"Left",!1),this.setChildrenLayout(this.center,"Default",!1),t=0,n=0,r=0;e.length>r;r++)o=e[r],o.TreeDirection="Left",a=this.measure(o,s.Empty),n=Math.max(n,a.Width),t+=a.height+this.options.verticalSeparation;for(t-=this.options.verticalSeparation,l=this.center.x-this.options.horizontalSeparation,i=this.center.y+(this.center.height-t)/2,r=0;e.length>r;r++)o=e[r],c=new p(l-o.Size.width,i),this.arrange(o,c),i+=o.Size.height+this.options.verticalSeparation},layoutRight:function(e){var t,n,i,r,o,a,l,c;for(this.setChildrenDirection(this.center,"Right",!1),this.setChildrenLayout(this.center,"Default",!1),t=0,n=0,r=0;e.length>r;r++)o=e[r],o.TreeDirection="Right",a=this.measure(o,s.Empty),n=Math.max(n,a.Width),t+=a.height+this.options.verticalSeparation;for(t-=this.options.verticalSeparation,l=this.center.x+this.options.horizontalSeparation+this.center.width,i=this.center.y+(this.center.height-t)/2,r=0;e.length>r;r++)o=e[r],c=new p(l,i),this.arrange(o,c),i+=o.Size.height+this.options.verticalSeparation},layoutUp:function(e){var t,n,i,r,o,a,l;for(this.setChildrenDirection(this.center,"Up",!1),this.setChildrenLayout(this.center,"Default",!1),t=0,r=0;e.length>r;r++)i=e[r],i.TreeDirection="Up",o=this.measure(i,s.Empty),t+=o.width+this.options.horizontalSeparation;for(t-=this.options.horizontalSeparation,a=this.center.x+this.center.width/2-t/2,r=0;e.length>r;r++)i=e[r],n=this.center.y-this.options.verticalSeparation-i.Size.height,l=new p(a,n),this.arrange(i,l),a+=i.Size.width+this.options.horizontalSeparation},layoutDown:function(e){var t,n,i,r,o,a,l;for(this.setChildrenDirection(this.center,"Down",!1),this.setChildrenLayout(this.center,"Default",!1),i=0,n=0;e.length>n;n++)t=e[n],t.treeDirection="Down",o=this.measure(t,s.Empty),i+=o.width+this.options.horizontalSeparation;for(i-=this.options.horizontalSeparation,a=this.center.x+this.center.width/2-i/2,r=this.center.y+this.options.verticalSeparation+this.center.height,n=0;e.length>n;n++)t=e[n],l=new p(a,r),this.arrange(t,l),a+=t.Size.width+this.options.horizontalSeparation},layoutRadialTree:function(){var e,t;if(this.setChildrenDirection(this.center,"Radial",!1),this.setChildrenLayout(this.center,"Default",!1),this.previousRoot=null,e=this.options.startRadialAngle*g,t=this.options.endRadialAngle*g,e>=t)throw"Final angle should not be less than the start angle.";this.maxDepth=0,this.origin=new p(this.center.x,this.center.y),this.calculateAngularWidth(this.center,0),this.maxDepth>0&&this.radialLayout(this.center,this.options.radialFirstLevelSeparation,e,t),this.center.Angle=t-e},tipOverTree:function(e,t){var n,i,r,o,a,l,c;for(h.isUndefined(t)&&(t=0),this.setChildrenDirection(this.center,"Down",!1),this.setChildrenLayout(this.center,"Default",!1),this.setChildrenLayout(this.center,"Underneath",!1,t),n=0,o=0;e.length>o;o++)r=e[o],r.TreeDirection="Down",a=this.measure(r,s.Empty),n+=a.width+this.options.horizontalSeparation;for(n-=this.options.horizontalSeparation,n-=e[e.length-1].width,n+=e[e.length-1].associatedShape.bounds().width,l=this.center.x+this.center.width/2-n/2,i=this.center.y+this.options.verticalSeparation+this.center.height,o=0;e.length>o;o++)r=e[o],c=new p(l,i),this.arrange(r,c),l+=r.Size.width+this.options.horizontalSeparation},calculateAngularWidth:function(e,t){var n,i,r,o,a,s,l;if(t>this.maxDepth&&(this.maxDepth=t),n=0,i=1e3,r=1e3,o=0===t?0:Math.sqrt(i*i+r*r)/t,e.children.length>0){for(a=0,s=e.children.length;s>a;a++)l=e.children[a],n+=this.calculateAngularWidth(l,t+1);n=Math.max(o,n)}else n=o;return e.sectorAngle=n,n},sortChildren:function(e){var t,n,i,r,o,a,s,l,c,d,u,f=0;if(e.parents.length>1)throw"Node is not part of a tree.";if(n=e.parents[0],n&&(i=new p(n.x,n.y),r=new p(e.x,e.y),f=this.normalizeAngle(Math.atan2(i.y-r.y,i.x-r.x))),o=e.children.length,0===o)return null;for(a=[],s=[],t=0;o>t;++t)l=e.children[t],c=new p(l.x,l.y),s[t]=t,a[t]=this.normalizeAngle(-f+Math.atan2(c.y-c.y,c.x-c.x));for(h.bisort(a,s),d=[],u=e.children,t=0;o>t;++t)d.push(u[s[t]]);return d},normalizeAngle:function(e){for(;e>2*Math.PI;)e-=2*Math.PI;for(;0>e;)e+=2*Math.PI;return e},radialLayout:function(e,t,n,i){var r,o,a,s,l,c=i-n,d=c/2,u=e.sectorAngle,h=0,p=this.sortChildren(e);for(r=0,o=p.length;o>r;r++)a=p[r],s=a,l=s.sectorAngle/u,a.children.length>0&&this.radialLayout(a,t+this.options.radialSeparation,n+h*c,n+(h+l)*c),this.setPolarLocation(a,t,n+h*c+l*d),s.angle=l*c,h+=l},setPolarLocation:function(e,t,n){e.x=this.origin.x+t*Math.cos(n),e.y=this.origin.y+t*Math.sin(n),e.BoundingRectangle=new l(e.x,e.y,e.width,e.height)},setChildrenDirection:function(e,t,n){var i=e.treeDirection;this.graph.depthFirstTraversal(e,function(e){e.treeDirection=t}),n||(e.treeDirection=i)},setChildrenLayout:function(e,t,n,i){h.isUndefined(i)&&(i=0);var r=e.childrenLayout;i>0?(this.graph.assignLevels(e),this.graph.depthFirstTraversal(e,function(e){e.level>=i+1&&(e.childrenLayout=t)})):(this.graph.depthFirstTraversal(e,function(e){e.childrenLayout=t}),n||(e.childrenLayout=r))},measure:function(e,t){var n,i,r,o,a,l,c,d=0,u=0,p=new s(0,0);if(!e)throw"";if(i=e.associatedShape.bounds(),r=i.width,o=i.height,1!==e.parents.length)throw"Node not in a spanning tree.";if(a=e.parents[0],"Undefined"===e.treeDirection&&(e.treeDirection=a.treeDirection),h.isEmpty(e.children))p=new s(Math.abs(r)<f?50:r,Math.abs(o)<f?25:o);else if(1===e.children.length){switch(e.treeDirection){case"Radial":n=this.measure(e.children[0],t),d=r+this.options.radialSeparation*Math.cos(e.AngleToParent)+n.width,u=o+Math.abs(this.options.radialSeparation*Math.sin(e.AngleToParent))+n.height;break;case"Left":case"Right":switch(e.childrenLayout){case"TopAlignedWithParent":break;case"BottomAlignedWithParent":break;case"Underneath":n=this.measure(e.children[0],t),d=r+n.width+this.options.underneathHorizontalOffset,u=o+this.options.underneathVerticalTopOffset+n.height;break;case"Default":n=this.measure(e.children[0],t),d=r+this.options.horizontalSeparation+n.width,u=Math.max(o,n.height);break;default:throw"Unhandled TreeDirection in the Radial layout measuring."}break;case"Up":case"Down":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":n=this.measure(e.children[0],t),d=Math.max(r,n.width+this.options.underneathHorizontalOffset),u=o+this.options.underneathVerticalTopOffset+n.height;break;case"Default":n=this.measure(e.children[0],t),u=o+this.options.verticalSeparation+n.height,d=Math.max(r,n.width);break;default:throw"Unhandled TreeDirection in the Down layout measuring."}break;default:throw"Unhandled TreeDirection in the layout measuring."}p=new s(d,u)}else{switch(e.treeDirection){case"Left":case"Right":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=r,u=o+this.options.underneathVerticalTopOffset,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),d=Math.max(d,n.width+this.options.underneathHorizontalOffset),u+=n.height+this.options.underneathVerticalSeparation;u-=this.options.underneathVerticalSeparation;break;case"Default":for(d=r,u=0,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),d=Math.max(d,r+this.options.horizontalSeparation+n.width),u+=n.height+this.options.verticalSeparation;u-=this.options.verticalSeparation;break;default:throw"Unhandled TreeDirection in the Right layout measuring."}break;case"Up":case"Down":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=r,u=o+this.options.underneathVerticalTopOffset,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),d=Math.max(d,n.width+this.options.underneathHorizontalOffset),u+=n.height+this.options.underneathVerticalSeparation;u-=this.options.underneathVerticalSeparation;break;case"Default":for(d=0,u=0,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),d+=n.width+this.options.horizontalSeparation,u=Math.max(u,n.height+this.options.verticalSeparation+o);d-=this.options.horizontalSeparation;break;default:throw"Unhandled TreeDirection in the Down layout measuring."}break;default:throw"Unhandled TreeDirection in the layout measuring."}p=new s(d,u)}return e.SectorAngle=Math.sqrt(d*d/4+u*u/4),e.Size=p,p},arrange:function(e,t){var n,i,r,o,a,s,c,d,u=e.associatedShape.bounds(),g=u.width,m=u.height;if(h.isEmpty(e.children))e.x=t.x,e.y=t.y,e.BoundingRectangle=new l(t.x,t.y,g,m);else switch(e.treeDirection){case"Left":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=t,e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),c=t.y+m+this.options.underneathVerticalTopOffset,n=0;o.children.length>n;n++)o=o.children[n],s=d.x-o.associatedShape.width-this.options.underneathHorizontalOffset,i=new p(s,c),this.arrange(o,i),c+=o.Size.height+this.options.underneathVerticalSeparation;break;case"Default":for(d=new p(t.x+e.Size.width-g,t.y+(e.Size.height-m)/2),e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),s=d.x-this.options.horizontalSeparation,c=t.y,n=0;e.children.length>n;n++)o=e.children[n],i=new p(s-o.Size.width,c),this.arrange(o,i),c+=o.Size.height+this.options.verticalSeparation;break;default:throw"Unsupported TreeDirection"}break;case"Right":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=t,e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),s=t.x+g+this.options.underneathHorizontalOffset,c=t.y+m+this.options.underneathVerticalTopOffset,n=0;e.children.length>n;n++)o=e.children[n],i=new p(s,c),this.arrange(o,i),c+=o.Size.height+this.options.underneathVerticalSeparation;break;case"Default":for(d=new p(t.x,t.y+(e.Size.height-m)/2),e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),s=t.x+g+this.options.horizontalSeparation,c=t.y,n=0;e.children.length>n;n++)o=e.children[n],i=new p(s,c),this.arrange(o,i),c+=o.Size.height+this.options.verticalSeparation;break;default:throw"Unsupported TreeDirection"}break;case"Up":if(d=new p(t.x+(e.Size.width-g)/2,t.y+e.Size.height-m),e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),Math.abs(d.x-t.x)<f){for(a=0,n=0;e.children.length>n;n++)r=e.children[n],a+=r.Size.width+this.options.horizontalSeparation;a-=this.options.horizontalSeparation,s=t.x+(g-a)/2}else s=t.x;for(n=0;e.children.length>n;n++)o=e.children[n],c=d.y-this.options.verticalSeparation-o.Size.height,i=new p(s,c),this.arrange(o,i),s+=o.Size.width+this.options.horizontalSeparation;break;case"Down":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(d=t,e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),s=t.x+this.options.underneathHorizontalOffset,c=t.y+m+this.options.underneathVerticalTopOffset,n=0;e.children.length>n;n++)o=e.children[n],i=new p(s,c),this.arrange(o,i),c+=o.Size.height+this.options.underneathVerticalSeparation;break;case"Default":if(d=new p(t.x+(e.Size.width-g)/2,t.y),e.x=d.x,e.y=d.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),Math.abs(d.x-t.x)<f){for(a=0,n=0;e.children.length>n;n++)r=e.children[n],a+=r.Size.width+this.options.horizontalSeparation;a-=this.options.horizontalSeparation,s=t.x+(g-a)/2}else s=t.x;for(n=0;e.children.length>n;n++)o=e.children[n],c=d.y+this.options.verticalSeparation+m,i=new p(s,c),this.arrange(o,i),s+=o.Size.width+this.options.horizontalSeparation;break;default:throw"Unsupported TreeDirection"}break;case"None":break;default:throw"Unsupported TreeDirection"}},layoutSwitch:function(){var e,t,n,i,r,o;if(this.center&&!h.isEmpty(this.center.children))switch(e=this.options.subtype,h.isUndefined(e)&&(e="Down"),o=this.center.children,e.toLowerCase()){case"radial":case"radialtree":this.layoutRadialTree();break;case"mindmaphorizontal":case"mindmap":t=this.center.children,1===this.center.children.length?this.layoutRight(t):(r=o.length/2,n=v(this.center.children,function(e){return h.indexOf(o,e)<r}),i=v(this.center.children,function(e){return h.indexOf(o,e)>=r}),this.layoutLeft(n),this.layoutRight(i));break;case"mindmapvertical":t=this.center.children,1===this.center.children.length?this.layoutDown(t):(r=o.length/2,n=v(this.center.children,function(e){return h.indexOf(o,e)<r}),i=v(this.center.children,function(e){return h.indexOf(o,e)>=r}),this.layoutUp(n),this.layoutDown(i));break;case"right":this.layoutRight(this.center.children);break;case"left":this.layoutLeft(this.center.children);break;case"up":case"bottom":this.layoutUp(this.center.children);break;case"down":case"top":this.layoutDown(this.center.children);break;case"tipover":case"tipovertree":if(0>this.options.tipOverTreeStartLevel)throw"The tip-over level should be a positive integer.";this.tipOverTree(this.center.children,this.options.tipOverTreeStartLevel);break;case"undefined":case"none":}}}),x=_.extend({init:function(e){var t=this;if(_.fn.init.call(t),h.isUndefined(e))throw"No diagram specified.";this.diagram=e},layout:function(e){var t,i;return this.transferOptions(e),t=new y(this.diagram),this.graph=t.convert(),i=this.layoutComponents(),new n.LayoutState(this.diagram,i)},layoutComponents:function(){var e,t,n,i,r,o,a,s;if(!this.graph.isEmpty()&&(e=this.graph.getConnectedComponents(),!h.isEmpty(e))){for(t=new b(this.options),n=[],i=0;e.length>i;i++){if(r=e[i],o=this.getTree(r),!o)throw"Failed to find a spanning tree for the component.";a=o.root,s=o.tree,t.layout(s,a),n.push(s)}return this.gridLayoutComponents(n)}},getTree:function(e){var t,n,i,r,o,a=null;if(this.options.roots&&this.options.roots.length>0)for(t=0,n=e.nodes.length;n>t;t++)for(i=e.nodes[t],r=0;this.options.roots.length>r;r++)if(o=this.options.roots[r],o===i.associatedShape){a=i;break}if(!a&&(a=e.root(),!a))throw"Unable to find a root for the tree.";return this.getTreeForRoot(e,a)},getTreeForRoot:function(e,t){var n=e.getSpanningTree(t);return h.isUndefined(n)||n.isEmpty()?null:{tree:n,root:n.root}}}),k=_.extend({init:function(e){var t=this;if(_.fn.init.call(t),h.isUndefined(e))throw"Diagram is not specified.";this.diagram=e},layout:function(e){var t,i,r,o,a,s;if(this.transferOptions(e),t=new y(this.diagram),i=t.convert(e),!i.isEmpty()&&(r=i.getConnectedComponents(),!h.isEmpty(r))){for(o=0;r.length>o;o++)a=r[o],this.layoutGraph(a,e);return s=this.gridLayoutComponents(r),new n.LayoutState(this.diagram,s)}},_initRuntimeProperties:function(){var e,t;for(e=0;this.graph.nodes.length>e;e++)t=this.graph.nodes[e],t.layer=-1,t.downstreamLinkCount=0,t.upstreamLinkCount=0,t.isVirtual=!1,t.uBaryCenter=0,t.dBaryCenter=0,t.upstreamPriority=0,t.downstreamPriority=0,t.gridPosition=0},_prepare:function(e){var t,n,i,r,o,a,s,l,d,u,p,f,g=[];for(n=0;e.links.length>n;n++)e.links[n].depthOfDumminess=0;for(r=new c,h.forEach(e.nodes,function(e){0===e.incoming.length&&(r.set(e,0),g.push(e))});g.length>0;)for(o=g.shift(),t=0;o.outgoing.length>t;t++)i=o.outgoing[t],a=i.target,r.containsKey(a)?r.set(a,Math.max(r.get(o)+1,r.get(a))):r.set(a,r.get(o)+1),m(g,a)||g.push(a);for(s=0,r.forEachValue(function(e){s=Math.max(s,e)}),l=[],h.addRange(l,r.keys()),l.sort(function(e,t){var n=r.get(e),i=r.get(t);return h.sign(i-n)}),d=0;l.length>d;++d)if(u=l[d],p=Number.MAX_VALUE,0!==u.outgoing.length){for(n=0;u.outgoing.length>n;++n)i=u.outgoing[n],p=Math.min(p,r.get(i.target));p>1&&r.set(u,p-1)}for(this.layers=[],t=0;s+1>t;t++)this.layers.push([]);for(r.forEach(function(e,t){e.layer=t,this.layers[t].push(e)},this),n=0;this.layers.length>n;n++)for(f=this.layers[n],t=0;f.length>t;t++)f[t].gridPosition=t},layoutGraph:function(e,t){if(h.isUndefined(e))throw"No graph given or graph analysis of the diagram failed.";h.isDefined(t)&&this.transferOptions(t),this.graph=e,e.setItemIndices();var n=e.makeAcyclic();this._initRuntimeProperties(),this._prepare(e,t),this._dummify(),this._optimizeCrossings(),this._swapPairs(),this.arrangeNodes(),this._moveThingsAround(),this._dedummify(),h.forEach(n,function(e){e.points&&e.points.reverse()})},setMinDist:function(e,t,n){var i=e.layer,r=e.layerIndex;this.minDistances[i][r]=n},getMinDist:function(e,t){var n,i=0,r=e.layerIndex,o=t.layerIndex,a=e.layer,s=Math.min(r,o),l=Math.max(r,o);for(n=s;l>n;++n)i+=this.minDistances[a][n];return i},placeLeftToRight:function(e){var t,n,i,r,o,a,s,l,d,u,p=new c;for(i=0;this.layers.length>i;++i)if(r=e[i]){for(t=0;r.length>t;t++)n=r[t],p.containsKey(n)||this.placeLeft(n,p,i);for(o=Number.POSITIVE_INFINITY,t=0;r.length>t;t++)n=r[t],a=this.rightSibling(n),a&&this.nodeLeftClass.get(a)!==i&&(o=Math.min(o,p.get(a)-p.get(n)-this.getMinDist(n,a)));if(o===Number.POSITIVE_INFINITY){for(s=[],t=0;r.length>t;t++)for(n=r[t],l=[],h.addRange(l,this.upNodes.get(n)),h.addRange(l,this.downNodes.get(n)),d=0;l.length>d;d++)u=l[d],this.nodeLeftClass.get(u)<i&&s.push(p.get(u)-p.get(n));s.sort(),o=0===s.length?0:s.length%2===1?s[this.intDiv(s.length,2)]:(s[this.intDiv(s.length,2)-1]+s[this.intDiv(s.length,2)])/2}for(t=0;r.length>t;t++)n=r[t],p.set(n,p.get(n)+o)}return p},placeRightToLeft:function(e){var t,n,i,r,o,a,s,l,d,u,p=new c;for(i=0;this.layers.length>i;++i)if(r=e[i]){for(t=0;r.length>t;t++)n=r[t],p.containsKey(n)||this.placeRight(n,p,i);for(o=Number.NEGATIVE_INFINITY,t=0;r.length>t;t++)n=r[t],a=this.leftSibling(n),a&&this.nodeRightClass.get(a)!==i&&(o=Math.max(o,p.get(a)-p.get(n)+this.getMinDist(a,n)));if(o===Number.NEGATIVE_INFINITY){for(s=[],t=0;r.length>t;t++)for(n=r[t],l=[],h.addRange(l,this.upNodes.get(n)),h.addRange(l,this.downNodes.get(n)),d=0;l.length>d;d++)u=l[d],this.nodeRightClass.get(u)<i&&s.push(p.get(n)-p.get(u));s.sort(),o=0===s.length?0:s.length%2===1?s[this.intDiv(s.length,2)]:(s[this.intDiv(s.length,2)-1]+s[this.intDiv(s.length,2)])/2}for(t=0;r.length>t;t++)n=r[t],p.set(n,p.get(n)+o)}return p},_getLeftWing:function(){var e={value:null},t=this.computeClasses(e,1);return this.nodeLeftClass=e.value,t},_getRightWing:function(){var e={value:null},t=this.computeClasses(e,-1);return this.nodeRightClass=e.value,t},computeClasses:function(e,t){var n,i,r,o,a,s,l,d,u,h=0,p=e.value=new c;for(n=0;this.layers.length>n;++n)for(h=n,i=this.layers[n],r=1===t?0:i.length-1;r>=0&&i.length>r;r+=t)if(o=i[r],p.containsKey(o))h=p.get(o);else if(p.set(o,h),o.isVirtual)for(a=this._nodesInLink(o),s=0;a.length>s;s++)l=a[s],p.set(l,h);for(d=[],u=0;this.layers.length>u;u++)d.push(null);return p.forEach(function(e,t){null===d[t]&&(d[t]=[]),d[t].push(e)}),d},_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 e(e,t){var n,i,r=Number.MIN_VALUE;for(n=0;e.length>n;++n)i=e[n],r=t._isVerticalLayout()?Math.max(r,i.height):Math.max(r,i.width);return r}var t,n,i,r,o,a,s,l,d,u,p,f,g,m,v,_,y,w,b,x,k,C,S,T,D,A,M;for(n=0;this.layers.length>n;++n)r=this.layers[n],r.sort(this._gridPositionComparer);for(this.minDistances=[],n=0;this.layers.length>n;++n)for(r=this.layers[n],this.minDistances[n]=[],o=0;r.length>o;++o)i=r[o],i.layerIndex=o,this.minDistances[n][o]=this.options.nodeDistance,r.length-1>o&&(this.minDistances[n][o]+=this._isVerticalLayout()?(i.width+r[o+1].width)/2:(i.height+r[o+1].height)/2);for(this.downNodes=new c,this.upNodes=new c,h.forEach(this.graph.nodes,function(e){this.downNodes.set(e,[]),this.upNodes.set(e,[])},this),h.forEach(this.graph.links,function(e){var t=e.source,n=e.target,i=null,r=null;t.layer>n.layer?(i=e.source,r=e.target):(r=e.source,i=e.target),this.downNodes.get(r).push(i),this.upNodes.get(i).push(r)},this),this.downNodes.forEachValue(function(e){e.sort(this._gridPositionComparer)},this),this.upNodes.forEachValue(function(e){e.sort(this._gridPositionComparer)},this),n=0;this.layers.length-1>n;++n)for(r=this.layers[n],a=0;r.length-1>a;a++)if(s=r[a],s.isVirtual&&(l=this.downNodes.get(s)[0],l.isVirtual))for(o=a+1;r.length>o;++o)i=r[o],i.isVirtual&&(d=this.downNodes.get(i)[0],d.isVirtual&&l.gridPosition>d.gridPosition&&(u=l.gridPosition,l.gridPosition=d.gridPosition,d.gridPosition=u,p=l.layerIndex,f=d.layerIndex,this.layers[n+1][p]=d,this.layers[n+1][f]=l,l.layerIndex=f,d.layerIndex=p));for(g=this._getLeftWing(),m=this._getRightWing(),v=this.placeLeftToRight(g),_=this.placeRightToLeft(m),y=new c,h.forEach(this.graph.nodes,function(e){y.set(e,(v.get(e)+_.get(e))/2)}),w=new c,b=new c,n=0;this.layers.length>n;++n)for(r=this.layers[n],x=-1,k=-1,o=0;r.length>o;++o)i=r[o],w.set(i,0),b.set(i,!1),i.isVirtual&&(-1===x?x=o:x===o-1?x=o:(k=o,w.set(r[x],0),y.get(i)-y.get(r[x])===this.getMinDist(r[x],i)?b.set(r[x],!0):b.set(r[x],!1),x=o));for(C=[1,-1],h.forEach(C,function(e){var n,i,r,o,a,s,l,c=1===e?0:this.layers.length-1;for(n=c;n>=0&&this.layers.length>n;n+=e){if(i=this.layers[n],r=this._firstVirtualNode(i),o=null,a=null,-1!==r)for(o=i[r],a=[],t=0;r>t;t++)a.push(i[t]);else o=null,a=i;if(a.length>0){for(this._sequencer(y,null,o,e,a),t=0;a.length-1>t;++t)this.setMinDist(a[t],a[t+1],y.get(a[t+1])-y.get(a[t]));o&&this.setMinDist(a[a.length-1],o,y.get(o)-y.get(a[a.length-1]))}for(;o;){if(s=this.nextVirtualNode(i,o)){if(w.get(o)===e){for(r=o.layerIndex,l=s.layerIndex,a=[],t=r+1;l>t;t++)a.push(i[t]);a.length>0&&this._sequencer(y,o,s,e,a),b.set(o,!0)}}else{for(r=o.layerIndex,a=[],t=r+1;i.length>t;t++)a.push(i[t]);if(a.length>0){for(this._sequencer(y,o,null,e,a),t=0;a.length-1>t;++t)this.setMinDist(a[t],a[t+1],y.get(a[t+1])-y.get(a[t]));this.setMinDist(o,a[0],y.get(a[0])-y.get(o))}}o=s}this.adjustDirections(n,e,w,b)}},this),S=this._isIncreasingLayout()?0:this.layers.length-1,T=function(e,t){return t._isIncreasingLayout()?t.layers.length>e:e>=0},D=this._isIncreasingLayout()?1:-1,A=0,t=S;T(t,this);t+=D){for(r=this.layers[t],M=e(r,this),o=0;r.length>o;++o)i=r[o],this._isVerticalLayout()?(i.x=y.get(i),i.y=A+M/2):(i.x=A+M/2,i.y=y.get(i));A+=this.options.layerSeparation+M}},adjustDirections:function(e,t,n,i){var r,o,a,s,l,c,d,u,h,p,f,g,m,v;if(!(0>e+t||e+t>=this.layers.length))for(r=null,o=null,a=this.layers[e+t],s=0;a.length>s;++s)if(l=a[s],l.isVirtual&&(c=this.getNeighborOnLayer(l,e),c.isVirtual)){if(r){for(d=i.get(o),u=this.layers[e],h=o.layerIndex,p=c.layerIndex,f=h+1;p>f;++f)u[f].isVirtual&&(d=d&&i.get(u[f]));if(d)for(n.set(r,t),g=r.layerIndex,m=l.layerIndex,v=g+1;m>v;++v)a[v].isVirtual&&n.set(a[v],t)}r=l,o=c}},getNeighborOnLayer:function(e,t){var n=this.upNodes.get(e)[0];return n.layer===t?n:(n=this.downNodes.get(e)[0],n.layer===t?n:null)},_sequencer:function(e,t,n,i,r){if(1===r.length&&this._sequenceSingle(e,t,n,i,r[0]),r.length>1){var o=r.length,a=this.intDiv(o,2);this._sequencer(e,t,n,i,r.slice(0,a)),this._sequencer(e,t,n,i,r.slice(a)),this.combineSequences(e,t,n,i,r)}},_sequenceSingle:function(e,t,n,i,r){var o=-1===i?this.downNodes.get(r):this.upNodes.get(r),a=o.length;0!==a&&(a%2===1?e.set(r,e.get(o[this.intDiv(a,2)])):e.set(r,(e.get(o[this.intDiv(a,2)-1])+e.get(o[this.intDiv(a,2)]))/2),t&&e.set(r,Math.max(e.get(r),e.get(t)+this.getMinDist(t,r))),n&&e.set(r,Math.min(e.get(r),e.get(n)-this.getMinDist(r,n))))},combineSequences:function(e,t,n,i,r){var o,a,s,l,c,d,u,h,p,f,g=r.length,m=this.intDiv(g,2),v=[];for(o=0;m>o;++o){for(a=0,l=-1===i?this.downNodes.get(r[o]):this.upNodes.get(r[o]),s=0;l.length>s;++s)c=l[s],e.get(c)>=e.get(r[o])?a++:(a--,v.push({k:e.get(c)+this.getMinDist(r[o],r[m-1]),v:2}));v.push({k:e.get(r[o])+this.getMinDist(r[o],r[m-1]),v:a})}for(t&&v.push({k:e.get(t)+this.getMinDist(t,r[m-1]),v:Number.MAX_VALUE}),v.sort(this._positionDescendingComparer),u=[],o=m;g>o;++o){for(a=0,l=-1===i?this.downNodes.get(r[o]):this.upNodes.get(r[o]),s=0;l.length>s;++s)c=l[s],e.get(c)<=e.get(r[o])?a++:(a--,u.push({k:e.get(c)-this.getMinDist(r[o],r[m]),v:2}));u.push({k:e.get(r[o])-this.getMinDist(r[o],r[m]),v:a})}for(n&&u.push({k:e.get(n)-this.getMinDist(n,r[m]),v:Number.MAX_VALUE}),u.sort(this._positionAscendingComparer),h=0,p=0,f=this.getMinDist(r[m-1],r[m]);e.get(r[m])-e.get(r[m-1])<f;)if(p>h){if(0===v.length){e.set(r[m-1],e.get(r[m])-f);break}d=v.shift(),h+=d.v,e.set(r[m-1],d.k),e.set(r[m-1],Math.max(e.get(r[m-1]),e.get(r[m])-f))}else{if(0===u.length){e.set(r[m],e.get(r[m-1])+f);break}d=u.shift(),p+=d.v,e.set(r[m],d.k),e.set(r[m],Math.min(e.get(r[m]),e.get(r[m-1])+f))}for(o=m-2;o>=0;o--)e.set(r[o],Math.min(e.get(r[o]),e.get(r[m-1])-this.getMinDist(r[o],r[m-1])));for(o=m+1;g>o;o++)e.set(r[o],Math.max(e.get(r[o]),e.get(r[m])+this.getMinDist(r[o],r[m])))},placeLeft:function(e,t,n){var i=Number.NEGATIVE_INFINITY;h.forEach(this._getComposite(e),function(e){var r=this.leftSibling(e);r&&this.nodeLeftClass.get(r)===this.nodeLeftClass.get(e)&&(t.containsKey(r)||this.placeLeft(r,t,n),i=Math.max(i,t.get(r)+this.getMinDist(r,e)))},this),i===Number.NEGATIVE_INFINITY&&(i=0),h.forEach(this._getComposite(e),function(e){t.set(e,i)})},placeRight:function(e,t,n){var i=Number.POSITIVE_INFINITY;h.forEach(this._getComposite(e),function(e){var r=this.rightSibling(e);r&&this.nodeRightClass.get(r)===this.nodeRightClass.get(e)&&(t.containsKey(r)||this.placeRight(r,t,n),i=Math.min(i,t.get(r)-this.getMinDist(e,r)))},this),i===Number.POSITIVE_INFINITY&&(i=0),h.forEach(this._getComposite(e),function(e){t.set(e,i)})},leftSibling:function(e){var t=this.layers[e.layer],n=e.layerIndex;return 0===n?null:t[n-1]},rightSibling:function(e){var t=this.layers[e.layer],n=e.layerIndex;return n===t.length-1?null:t[n+1]},_getComposite:function(e){return e.isVirtual?this._nodesInLink(e):[e]},arrangeNodes:function(){var e,t,n,i,r,o,a,s;for(t=0;this.layers.length>t;t++)for(i=this.layers[t],n=0;i.length>n;n++)r=i[n],r.upstreamPriority=r.upstreamLinkCount,r.downstreamPriority=r.downstreamLinkCount;for(o=2,a=0;o>a;a++){for(e=this.layers.length-1;e>=1;e--)this.layoutLayer(!1,e);for(e=0;this.layers.length-1>e;e++)this.layoutLayer(!0,e)}for(s=Number.MAX_VALUE,t=0;this.layers.length>t;t++)for(i=this.layers[t],n=0;i.length>n;n++)r=i[n],s=Math.min(s,r.gridPosition);if(0>s)for(t=0;this.layers.length>t;t++)for(i=this.layers[t],n=0;i.length>n;n++)r=i[n],r.gridPosition=r.gridPosition-s},layoutLayer:function(e,t){var n,i,r,o;for(i=e?this.layers[n=t+1]:this.layers[n=t-1],r=[],o=0;i.length>o;o++)r.push(i[o]);r.sort(function(e,t){var n=(e.upstreamPriority+e.downstreamPriority)/2,i=(t.upstreamPriority+t.downstreamPriority)/2;return Math.abs(n-i)<1e-4?0:i>n?1:-1}),h.forEach(r,function(e){var t=e.gridPosition,n=this.calcBaryCenter(e),r=(e.upstreamPriority+e.downstreamPriority)/2;if(!(Math.abs(t-n)<1e-4||Math.abs(t-n)<.2501))if(n>t)for(;n>t&&this.moveRight(e,i,r);)t=e.gridPosition;else for(;t>n&&this.moveLeft(e,i,r);)t=e.gridPosition},this),n>0&&this.calcDownData(n-1),this.layers.length-1>n&&this.calcUpData(n+1)},moveRight:function(e,t,n){var i,r,o=h.indexOf(t,e);return o===t.length-1?(e.gridPosition=e.gridPosition+.5,!0):(i=t[o+1],r=(i.upstreamPriority+i.downstreamPriority)/2,i.gridPosition>e.gridPosition+1?(e.gridPosition=e.gridPosition+.5,!0):r>n||Math.abs(r-n)<1e-4?!1:this.moveRight(i,t,n)?(e.gridPosition=e.gridPosition+.5,!0):!1)},moveLeft:function(e,t,n){var i,r,o=h.indexOf(t,e);return 0===o?(e.gridPosition=e.gridPosition-.5,!0):(i=t[o-1],r=(i.upstreamPriority+i.downstreamPriority)/2,e.gridPosition-1>i.gridPosition?(e.gridPosition=e.gridPosition-.5,!0):r>n||Math.abs(r-n)<1e-4?!1:this.moveLeft(i,t,n)?(e.gridPosition=e.gridPosition-.5,!0):!1)},mapVirtualNode:function(e,t){this.nodeToLinkMap.set(e,t),this.linkToNodeMap.containsKey(t)||this.linkToNodeMap.set(t,[]),this.linkToNodeMap.get(t).push(e)},_nodesInLink:function(e){return this.linkToNodeMap.get(this.nodeToLinkMap.get(e))},_dummify:function(){var e,t,n,i,a,s,l,d,u,p,f,g,m,v,_,y,w,b;for(this.linkToNodeMap=new c,this.nodeToLinkMap=new c,u=this.graph.links.slice(0),d=0;u.length>d;d++){if(p=u[d],f=p.source,g=p.target,m=f.layer,v=g.layer,_=f.gridPosition,y=g.gridPosition,w=(y-_)/Math.abs(v-m),b=f,m-v>1){for(l=m-1;l>v;l--){for(n=new r,n.x=f.x,n.y=f.y,n.width=f.width/100,n.height=f.height/100,e=this.layers[l],t=(l-v)*w+_,t>e.length&&(t=e.length),_>=this.layers[m].length-1&&y>=this.layers[v].length-1?t=e.length:0===_&&0===y&&(t=0),n.layer=l,n.uBaryCenter=0,n.dBaryCenter=0,n.upstreamLinkCount=0,n.downstreamLinkCount=0,n.gridPosition=t,n.isVirtual=!0,h.insert(e,n,t),a=t+1;e.length>a;a++)i=e[a],i.gridPosition=i.gridPosition+1;s=new o(b,n),s.depthOfDumminess=0,b=n,this.graph.nodes.push(n),this.graph.addLink(s),n.index=this.graph.nodes.length-1,this.mapVirtualNode(n,p)}p.changeSource(b),p.depthOfDumminess=m-v-1}if(-1>m-v){for(l=m+1;v>l;l++){for(n=new r,n.x=f.x,n.y=f.y,n.width=f.width/100,n.height=f.height/100,e=this.layers[l],t=(l-m)*w+_,t>e.length&&(t=e.length),_>=this.layers[m].length-1&&y>=this.layers[v].length-1?t=e.length:0===_&&0===y&&(t=0),n.layer=l,n.uBaryCenter=0,n.dBaryCenter=0,n.upstreamLinkCount=0,n.downstreamLinkCount=0,n.gridPosition=t,n.isVirtual=!0,t&=t,h.insert(e,n,t),a=t+1;e.length>a;a++)i=e[a],i.gridPosition=i.gridPosition+1;s=new o(b,n),s.depthOfDumminess=0,b=n,this.graph.nodes.push(n),this.graph.addLink(s),n.index=this.graph.nodes.length-1,this.mapVirtualNode(n,p)}p.changeSource(b),p.depthOfDumminess=v-m-1}}},_dedummify:function(){for(var e,t,n,i,r,o,a,s,l=!0;l;)for(l=!1,e=0;this.graph.links.length>e;e++)if(t=this.graph.links[e],0!==t.depthOfDumminess){for(n=[],n.unshift({x:t.target.x,y:t.target.y}),n.unshift({x:t.source.x,y:t.source.y}),i=t,r=t.depthOfDumminess,o=0;r>o;o++)a=i.source,s=a.incoming[0],n.unshift({x:s.source.x,y:s.source.y}),i=s;t.changeSource(i.source),t.depthOfDumminess=0,n.length>2?(n.splice(0,1),n.splice(n.length-1),t.points=n):t.points=[],l=!0;break}},_optimizeCrossings:function(){for(var e,t=-1,n=3,i=0;0!==t&&!(i++>n);){for(t=0,e=this.layers.length-1;e>=1;e--)t+=this.optimizeLayerCrossings(!1,e);for(e=0;this.layers.length-1>e;e++)t+=this.optimizeLayerCrossings(!0,e)}},calcUpData:function(e){var t,n,i,r,o,a,s,l,c;if(0!==e){for(t=this.layers[e],o=new d,a=this.layers[e-1],n=0;a.length>n;n++)o.add(a[n]);for(n=0;t.length>n;n++){for(s=t[n],l=0,c=0,i=0;s.incoming.length>i;i++)r=s.incoming[i],o.contains(r.source)&&(c++,l+=r.source.gridPosition);for(i=0;s.outgoing.length>i;i++)r=s.outgoing[i],o.contains(r.target)&&(c++,l+=r.target.gridPosition);c>0?(s.uBaryCenter=l/c,s.upstreamLinkCount=c):(s.uBaryCenter=n,s.upstreamLinkCount=0)}}},calcDownData:function(e){var t,n,i,r,o,a,s,l,c;if(e!==this.layers.length-1){for(t=this.layers[e],o=new d,a=this.layers[e+1],n=0;a.length>n;n++)o.add(a[n]);for(n=0;t.length>n;n++){for(s=t[n],l=0,c=0,i=0;s.incoming.length>i;i++)r=s.incoming[i],o.contains(r.source)&&(c++,l+=r.source.gridPosition);for(i=0;s.outgoing.length>i;i++)r=s.outgoing[i],o.contains(r.target)&&(c++,l+=r.target.gridPosition);c>0?(s.dBaryCenter=l/c,s.downstreamLinkCount=c):(s.dBaryCenter=n,s.downstreamLinkCount=0)}}},optimizeLayerCrossings:function(e,t){var n,i,r,o,a,s,l,c;
  for(i=e?this.layers[n=t+1]:this.layers[n=t-1],r=i.slice(0),e?this.calcUpData(n):this.calcDownData(n),o=this,i.sort(function(e,t){var n,i=o.calcBaryCenter(e),r=o.calcBaryCenter(t);return Math.abs(i-r)<1e-4?e.degree()===t.degree()?o.compareByIndex(e,t):e.degree()<t.degree()?1:-1:(n=1e3*(r-i),n>0?-1:0>n?1:o.compareByIndex(e,t))}),s=0,a=0;i.length>a;a++)i[a]!==r[a]&&s++;if(s>0)for(l=0,a=0;i.length>a;a++)c=i[a],c.gridPosition=l++;return s},_swapPairs:function(){for(var e,t,n,i,r,o,a,s,l,c,d,u,h,p,f,g,m,v=this.options.layeredIterations,_=0;;){if(_++>v)break;for(e=1>=_%4,t=_%4===1,n=e?0:this.layers.length-1;e?this.layers.length-1>=n:n>=0;n+=e?1:-1){for(i=this.layers[n],r=!1,o=!0,a=0,s=0;i.length-1>s;s++)l=0,c=0,d=0,o?(0!==n&&(l=this.countLinksCrossingBetweenTwoLayers(n-1,n)),n!==this.layers.length-1&&(c=this.countLinksCrossingBetweenTwoLayers(n,n+1)),e?l*=2:c*=2,d=l+c):d=a,0!==d&&(u=i[s],h=i[s+1],p=u.gridPosition,f=h.gridPosition,i[s]=h,i[s+1]=u,u.gridPosition=f,h.gridPosition=p,l=0,0!==n&&(l=this.countLinksCrossingBetweenTwoLayers(n-1,n)),c=0,n!==this.layers.length-1&&(c=this.countLinksCrossingBetweenTwoLayers(n,n+1)),e?l*=2:c*=2,g=l+c,m=!1,m=t?g>=d:g>d,m?(u=i[s],h=i[s+1],p=u.gridPosition,f=h.gridPosition,i[s]=h,i[s+1]=u,u.gridPosition=f,h.gridPosition=p,a=d,o=!1):(r=!0,o=!0));r&&(n!==this.layers.length-1&&this.calcUpData(n+1),0!==n&&this.calcDownData(n-1))}}},countLinksCrossingBetweenTwoLayers:function(e,t){var n,i,r,o,a,s,l,c,u,p,f,g,m,v,_,y,w,b,x,k,C=0,S=new d,T=this.layers[e];for(n=0;T.length>n;n++)S.add(T[n]);for(i=new d,r=this.layers[t],n=0;r.length>n;n++)i.add(r[n]);for(o=new d,a=[],s=[],S.forEach(function(e){h.addRange(s,e.incoming),h.addRange(s,e.outgoing)}),l=0;s.length>l;l++)c=s[l],S.contains(c.source)&&i.contains(c.target)?(o.add(c),a.push(c)):i.contains(c.source)&&S.contains(c.target)&&a.push(c);for(u=0;a.length>u;u++)for(p=a[u],f=0;a.length>f;f++)u!==f&&(g=a[f],o.contains(p)?(m=p.source,v=p.target):(m=p.target,v=p.source),o.contains(g)?(_=g.source,y=g.target):(_=g.target,y=g.source),w=m.gridPosition,b=v.gridPosition,x=_.gridPosition,k=y.gridPosition,0>(w-x)*(b-k)&&C++);return C/2},calcBaryCenter:function(e){var t=e.upstreamLinkCount,n=e.downstreamLinkCount,i=e.uBaryCenter,r=e.dBaryCenter;return t>0&&n>0?(i+r)/2:t>0?i:n>0?r:0},_gridPositionComparer:function(e,t){return t.gridPosition>e.gridPosition?-1:e.gridPosition>t.gridPosition?1:0},_positionAscendingComparer:function(e,t){return t.k>e.k?-1:e.k>t.k?1:0},_positionDescendingComparer:function(e,t){return t.k>e.k?1:e.k>t.k?-1:0},_firstVirtualNode:function(e){for(var t=0;e.length>t;t++)if(e[t].isVirtual)return t;return-1},compareByIndex:function(e,t){var n=e.index,i=t.index;return i>n?1:n>i?-1:0},intDiv:function(e,t){return(e-e%t)/t},nextVirtualNode:function(e,t){var n,i=t.layerIndex;for(n=i+1;e.length>n;++n)if(e[n].isVirtual)return e[n];return null}}),C=t.Class.extend({init:function(e,t){if(h.isUndefined(e))throw"No diagram given";this.diagram=e,this.nodeMap=new c,this.linkMap=new c,this.capture(t?t:e)},capture:function(e){var t,i,r,o,a,s,c,d,u;if(e instanceof n.Graph){for(o=0;e.nodes.length>o;o++)t=e.nodes[o],r=t.associatedShape,this.nodeMap.set(r.visual.id,new l(t.x,t.y,t.width,t.height));for(o=0;e.links.length>o;o++)s=e.links[o],a=s.associatedConnection,this.linkMap.set(a.visual.id,s.points())}else if(e instanceof Array)for(i=e,o=0;i.length>o;o++)t=i[o],r=t.associatedShape,r&&this.nodeMap.set(r.visual.id,new l(t.x,t.y,t.width,t.height));else if(e.hasOwnProperty("links")&&e.hasOwnProperty("nodes")){for(i=e.nodes,c=e.links,o=0;i.length>o;o++)t=i[o],r=t.associatedShape,r&&this.nodeMap.set(r.visual.id,new l(t.x,t.y,t.width,t.height));for(o=0;c.length>o;o++)s=c[o],a=s.associatedConnection,a&&this.linkMap.set(a.visual.id,s.points)}else{for(d=this.diagram.shapes,u=this.diagram.connections,o=0;d.length>o;o++)r=d[o],this.nodeMap.set(r.visual.id,r.bounds());for(o=0;u.length>o;o++)a=u[o],this.linkMap.set(a.visual.id,a.points())}}});a(n,{init:function(e){t.init(e,n.ui)},SpringLayout:w,TreeLayout:x,GraphAdapter:y,LayeredLayout:k,LayoutBase:_,LayoutState:C})}(window.kendo.jQuery),function(e,t){function n(e){var t=e.originalEvent,n=0;return t.wheelDelta?(n=-t.wheelDelta/40,n=n>0?vt.ceil(n):vt.floor(n)):t.detail&&(n=t.detail),n}function i(e){return e.options.name.toLowerCase()===Mt.toLowerCase()}function r(e,t){var n,r,o,a,s=Bt,l=t.connectors;for(r=0;l.length>r;r++)o=l[r],i(o)||(a=e.distanceTo(o.position()),s>a&&(s=a,n=o));return n}function o(e,t){var n,i,r,o=[],a=e.drawingContainer().children,s=a.length;for(n=0;t.length>n;n++)for(i=t[n],r=0;s>r;r++)if(a[r]==i.drawingContainer()){o.push(r);break}return o}function a(e){var t=e.drawingContainer().clippedBBox(null);(0!==t.origin.x||0!==t.origin.y)&&e.position(-t.origin.x,-t.origin.y)}function s(e){var t={};return e=e||{},ht(e.text)&&null!==e.text&&(t.text=e.text),ht(e.x)&&null!==e.x&&(t.x=e.x),ht(e.y)&&null!==e.y&&(t.y=e.y),ht(e.width)&&null!==e.width&&(t.width=e.width),ht(e.height)&&null!==e.height&&(t.height=e.height),ht(e.type)&&null!==e.type&&(t.type=e.type),t}function l(e){var t={};return e=e||{},ht(e.text)&&null!==e.text&&(t.content=e.text),ht(e.type)&&null!==e.type&&(t.type=e.type),ht(e.from)&&null!==e.from&&(t.from=e.from),ht(e.fromX)&&null!==e.fromX&&(t.fromX=e.fromX),ht(e.fromY)&&null!==e.fromY&&(t.fromY=e.fromY),ht(e.to)&&null!==e.to&&(t.to=e.to),ht(e.toX)&&null!==e.toX&&(t.toX=e.toX),ht(e.toY)&&null!==e.toY&&(t.toY=e.toY),t}function c(t,n){var i,r=this.dataSource.reader.model;r&&(i=r.fn.fields.text?"text":r.idField,e("<input name='"+n.field+"' />").appendTo(t).kendoDropDownList({dataValueField:r.idField,dataTextField:i,dataSource:this.dataSource.data().toJSON(),optionLabel:" ",valuePrimitive:!0}))}function d(e){this.dataItem=e,this.callbacks=[]}function u(){this.items={}}function h(e){var t=e;return e instanceof kendo.data.Model&&(t=e.toJSON(),t[e.idField]=e._defaultId),t}function p(e){var t,n,i=[],r=[];for(n=0;e.length>n;n++)t=e[n],t instanceof y?r.push(t):i.push(t);return{shapes:r,connections:i}}function f(e,t){return e.reader.model?new e.reader.model(t):new kendo.data.ObservableObject(t)}function g(e,t,n){var i,r;for(r=0;n.length>r;r++)i=n[r],t&&!ht(t[i])&&(t[i]=e[i])}var m,v,_,y,w,b,x,k,C,S,T,D,A=kendo.dataviz,M=kendo.drawing,I=kendo.geometry,P=A.diagram,E=kendo.ui.Widget,F=kendo.Class,B=e.proxy,z=kendo.deepExtend,R=e.extend,L=kendo.data.HierarchicalDataSource,H=P.Canvas,O=P.Group,N=P.Rectangle,V=P.Circle,U=P.CompositeTransform,W=P.Rect,j=P.Path,G=P.DeleteShapeUnit,q=P.DeleteConnectionUnit,$=P.TextBlock,Y=P.Image,K=P.Point,Q=P.Intersect,X=P.ConnectionEditAdorner,Z=P.UndoRedoService,J=P.ToolService,et=P.Selector,tt=P.ResizingAdorner,nt=P.ConnectorsAdorner,it=P.Cursors,rt=P.Utils,ot=kendo.Observable,at=P.ToBackUnit,st=P.ToFrontUnit,lt=P.PolylineRouter,ct=P.CascadingRouter,dt=rt.isUndefined,ut=rt.isDefined,ht=kendo.util.defined,pt=e.isArray,ft=kendo.isFunction,gt=rt.isString,mt=e.isPlainObject,vt=Math,_t=".kendoDiagram",yt="cascading",wt="itemBoundsChange",bt="change",xt="click",kt="drag",Ct="dragEnd",St="dragStart",Tt="mouseEnter",Dt="mouseLeave",At="error",Mt="Auto",It="Top",Pt="Right",Et="Left",Ft="Bottom",Bt=9007199254740992,zt="select",Rt="itemRotate",Lt="pan",Ht="zoomStart",Ot="zoomEnd",Nt="none",Vt=600,Ut=600,Wt="rectangle",jt=100,Gt=100,qt=20,$t=20,Yt=0,Kt="Yellow",Qt=Number.MAX_VALUE,Xt=-Number.MAX_VALUE,Zt="absolute",Jt="transformed",en="rotated",tn="transparent",nn="width",rn="height",on="x",an="y",sn="DOMMouseScroll"+_t+" mousewheel"+_t,ln=.05,cn=5,dn='<a class="k-button k-button-icontext #=className#" href="\\#"><span class="#=iconClass# #=imageClass#"></span>#=text#</a>';P.DefaultConnectors=[{name:It},{name:Ft},{name:Et},{name:Pt},{name:Mt,position:function(e){return e.getPosition("center")}}],m={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"}},P.shapeDefaults=function(e){var t={type:Wt,path:"",autoSize:!0,visual:null,x:Yt,y:Yt,minWidth:qt,minHeight:$t,width:jt,height:Gt,hover:{},editable:{connect:!0,tools:[]},connectors:P.DefaultConnectors,rotation:{angle:0}};return rt.simpleExtend(t,e),t},v=ot.extend({init:function(e){var t=this;t.dataItem=(e||{}).dataItem,ot.fn.init.call(t),t.options=z({id:P.randomId()},t.options,e),t.isSelected=!1,t.visual=new O({id:t.options.id,autoSize:t.options.autoSize}),t._template()},options:{hover:{},cursor:it.grip,content:{align:"center middle"},selectable:!0,serializable:!0,enable:!0},_getCursor:function(e){return this.adorner?this.adorner._getCursor(e):this.options.cursor},visible:function(e){return dt(e)?this.visual.visible():(this.visual.visible(e),t)},bounds:function(){},refresh:function(){this.visual.redraw()},position:function(e){this.options.x=e.x,this.options.y=e.y,this.visual.position(e)},toString:function(){return this.options.id},serialize:function(){var e=z({},{options:this.options});return this.dataItem&&(e.dataItem=""+this.dataItem),e},_content:function(e){var n,i,r,o;return e!==t&&(n=this.options,i=this.bounds(),P.Utils.isString(e)?n.content.text=e:z(n.content,e),r=n.content,o=this._contentVisual,!o&&r.text?(this._contentVisual=new $(r),this._contentVisual._includeInBBox=!1,this.visual.append(this._contentVisual)):o&&o.redraw(r)),this.options.content.text},_hitTest:function(e){var t=this.bounds();return this.visible()&&t.contains(e)&&this.options.enable},_template:function(){var e,t,n=this;n.options.content.template&&(e=n.dataItem||{},t=kendo.template(n.options.content.template,{paramName:"dataItem"}),n.options.content.text=t(e))},_canSelect:function(){return this.options.selectable!==!1},toJSON:function(){return{id:this.options.id}}}),_=F.extend({init:function(e,t){this.options=z({},this.options,t),this.connections=[],this.shape=e},options:{width:7,height:7,fill:{color:Kt},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}}}),_.parse=function(e,t){var n,i,r=t.split(":"),o=r[0],a=r[1]||Mt;for(n=0;e.shapes.length>n;n++)if(i=e.shapes[n],i.options.id==o)return i.getConnector(a.trim())},y=v.extend({init:function(e,n){var i=this;v.fn.init.call(i,e),this.diagram=n,this.updateOptionsFromModel(),e=i.options,i.connectors=[],i.type=e.type,i.shapeVisual=y.createShapeVisual(i.options),i.visual.append(this.shapeVisual),i.updateBounds(),i.content(i.content()),i._createConnectors(),i.parentContainer=null,i.isContainer=!1,i.isCollapsed=!1,i.id=i.visual.id,e.hasOwnProperty("layout")&&e.layout!==t&&(i.layout=e.layout.bind(e))},options:P.shapeDefaults(),_setOptionsFromModel:function(e){var t=s(e||this.dataItem);this.options=z({},this.options,t),this.redrawVisual(),this.options.content&&(this._template(),this.content(this.options.content))},updateOptionsFromModel:function(e,t){var n,i;this.diagram&&this.diagram._isEditable&&(n=s(e||this.dataItem),e&&t?A.inArray(t,["x","y","width","height"])?(i=this.bounds(),i[t]=e[t],this.bounds(i)):(this.options.visual?this.redrawVisual():n.type&&(this.options=z({},this.options,n),this.redrawVisual()),this.options.content&&(this._template(),this.content(this.options.content))):this.options=z({},this.options,n))},redrawVisual:function(){this.visual.clear(),this._contentVisual=null,this.options.dataItem=this.dataItem,this.shapeVisual=y.createShapeVisual(this.options),this.visual.append(this.shapeVisual),this.updateBounds()},updateModel:function(e){var t,n,i=this.diagram;i&&i._isEditable&&(t=this._bounds,n=this.dataItem,n&&(i._suspendModelRefresh(),ht(n.x)&&t.x!==n.x&&n.set("x",t.x),ht(n.y)&&t.y!==n.y&&n.set("y",t.y),ht(n.width)&&t.width!==n.width&&n.set("width",t.width),ht(n.height)&&t.height!==n.height&&n.set("height",t.height),this.dataItem=n,i._resumeModelRefresh(),e&&i._syncShapeChanges()))},updateBounds:function(){var e=this.visual._measure(!0),t=this.options;this.bounds(new W(t.x,t.y,e.width,e.height)),this._rotate(),this._alignContent()},content:function(e){var t=this._content(e);return this._alignContent(),t},_alignContent:function(){var e,t,n,i,r,o=this.options.content||{},a=this._contentVisual;a&&o.align&&(e=this.visual._measure(),t=new P.RectAlign(e),n=a.drawingElement.bbox(null),i=new W(0,0,n.width(),n.height()),r=t.align(i,o.align),a.position(r.topLeft()))},_createConnectors:function(){var e,t,n=this.options,i=n.connectors.length,r=n.connectorDefaults;for(t=0;i>t;t++)e=new _(this,z({},r,n.connectors[t])),this.connectors.push(e)},bounds:function(e){var t,n;if(e)if(gt(e))switch(e){case Jt:t=this._transformedBounds();break;case Zt:t=this._transformedBounds(),n=this.diagram._pan,t.x+=n.x,t.y+=n.y;break;case en:t=this._rotatedBounds();break;default:t=this._bounds}else this._setBounds(e),this._triggerBoundsChange(),this.refreshConnections();else t=this._bounds;return t},_setBounds:function(e){var t=this.options,n=e.topLeft(),i=t.x=n.x,r=t.y=n.y,o=t.width=vt.max(e.width,t.minWidth),a=t.height=vt.max(e.height,t.minHeight);this._bounds=new W(i,r,o,a),this.visual.redraw({x:i,y:r,width:o,height:a})},position:function(e){return e?(this.bounds(new W(e.x,e.y,this._bounds.width,this._bounds.height)),t):this._bounds.topLeft()},clone:function(){var e=this.serialize();return e.options.id=P.randomId(),this.diagram&&this.diagram._isEditable&&ht(this.dataItem)&&(e.options.dataItem=h(this.dataItem)),new y(e.options)},select:function(e){var n,i,r=this.diagram;return dt(e)&&(e=!0),this._canSelect()&&this.isSelected!=e?(n=[],i=[],this.isSelected=e,this.isSelected?(r._selectedItems.push(this),n.push(this)):(rt.remove(r._selectedItems,this),i.push(this)),r._internalSelection||r._selectionChanged(n,i),!0):t},rotate:function(e,n,i){var r,o,a,s,l=this.visual.rotate();return e!==t&&(i!==!1&&this.diagram&&this.diagram.undoRedoService&&e!==l.angle&&this.diagram.undoRedoService.add(new P.RotateUnit(this.diagram._resizingAdorner,[this],[l.angle]),!1),r=this.bounds(),o=new K(r.width/2,r.height/2),n&&(a=e-l.angle,s=r.center().rotate(n,360-a).minus(o),this._rotationOffset=this._rotationOffset.plus(s.minus(r.topLeft())),this.position(s)),this.visual.rotate(e,o),this.options.rotation.angle=e,this.diagram&&this.diagram._connectorsAdorner&&this.diagram._connectorsAdorner.refresh(),this.refreshConnections(),this.diagram&&this.diagram.trigger(Rt,{item:this})),l},connections:function(e){var t,n,i,r,o,a,s,l=[];for(t=0;this.connectors.length>t;t++)for(o=this.connectors[t],r=o.connections,n=0,r;r.length>n;n++)i=r[n],"out"==e?(a=i.source(),a.shape&&a.shape==this&&l.push(i)):"in"==e?(s=i.target(),s.shape&&s.shape==this&&l.push(i)):l.push(i);return l},refreshConnections:function(){e.each(this.connections(),function(){this.refresh()})},getConnector:function(e){var t,n;if(!gt(e))return e instanceof K?r(e,this):this.connectors.length?this.connectors[0]:null;for(e=e.toLocaleLowerCase(),t=0;this.connectors.length>t;t++)if(n=this.connectors[t],n.options.name.toLocaleLowerCase()==e)return n},getPosition:function(e){var t=this.bounds(),n=e.charAt(0).toLowerCase()+e.slice(1);return ft(t[n])?this._transformPoint(t[n]()):t.center()},redraw:function(e){var t,n;e&&(t=this.options,this.shapeVisual.redraw(this._visualOptions(e)),this._diffNumericOptions(e,[nn,rn,on,an])&&(this.bounds(new W(t.x,t.y,t.width,t.height)),n=!0),e.connectors&&(t.connectors=e.connectors,this._updateConnectors()),t=z(t,e),(e.rotation||n)&&this._rotate(),t.content&&this.content(t.content))},_updateConnectors:function(){var e,t,n,i,r=this.connections();for(this.connectors=[],this._createConnectors(),i=0;r.length>i;i++)e=r[i],t=e.source(),n=e.target(),t.shape&&t.shape===this?e.source(this.getConnector(t.options.name)||null):n.shape&&n.shape===this&&e.target(this.getConnector(n.options.name)||null),e.updateModel()},_diffNumericOptions:P.diffNumericOptions,_visualOptions:function(e){return{data:e.path,source:e.source,hover:e.hover,fill:e.fill,stroke:e.stroke,startCap:e.startCap,endCap:e.endCap}},_triggerBoundsChange:function(){this.diagram&&this.diagram.trigger(wt,{item:this,bounds:this._bounds.clone()})},_transformPoint:function(e){var t=this.rotate(),n=this.bounds(),i=n.topLeft();return t.angle&&e.rotate(t.center().plus(i),360-t.angle),e},_transformedBounds:function(){var e=this.bounds(),t=e.topLeft(),n=e.bottomRight();return W.fromPoints(this.diagram.modelToView(t),this.diagram.modelToView(n))},_rotatedBounds:function(){var e=this.bounds().rotatedBounds(this.rotate().angle),t=e.topLeft(),n=e.bottomRight();return W.fromPoints(t,n)},_rotate:function(){var e=this.options.rotation;e&&e.angle&&this.rotate(e.angle),this._rotationOffset=new K},_hover:function(e){var t=this.options,n=t.hover,i=t.stroke,r=t.fill;e&&ut(n.stroke)&&(i=z({},i,n.stroke)),e&&ut(n.fill)&&(r=n.fill),this.shapeVisual.redraw({stroke:i,fill:r}),t.editable&&t.editable.connect&&this.diagram._showConnectors(this,e)},_hitTest:function(e){if(this.visible()){var t,n=this.bounds(),i=this.rotate().angle;if(e.isEmpty&&!e.isEmpty())return Q.rects(e,n,i?i:0);if(t=e.clone().rotate(n.center(),i),n.contains(t))return this}},toJSON:function(){return{shapeId:this.options.id}}}),y.createShapeVisual=function(e){var t,n,i,r;return delete e.diagram,t=z({},e,{x:0,y:0}),n=t.visual,i=(t.type+"").toLocaleLowerCase(),ft(n)?r=n.call(this,t):t.path?(t.data=t.path,r=new j(t),a(r)):r="rectangle"==i?new N(t):"circle"==i?new V(t):"text"==i?new $(t):"image"==i?new Y(t):new j(t),r},w=v.extend({init:function(e,t,n){var i=this;v.fn.init.call(i,n),this.updateOptionsFromModel(),this._initRouter(),i.path=new P.Polyline(i.options),i.path.fill(tn),i.visual.append(i.path),i._sourcePoint=i._targetPoint=new K,i.source(e),i.target(t),i.content(i.options.content),i.definers=[],ht(n)&&n.points&&i.points(n.points),i.refresh()},options:{hover:{stroke:{}},startCap:Nt,endCap:Nt,points:[],selectable:!0},_setOptionsFromModel:function(e){this.updateOptionsFromModel(e||this.dataItem)},updateOptionsFromModel:function(e){var t,n;this.diagram&&this.diagram._isEditable&&(t=this.diagram._dataMap,n=l(e||this.dataItem),e?(ht(n.from)?this.source(t[n.from]):ht(n.fromX)&&ht(n.fromY)&&this.source(new K(n.fromX,n.fromY)),ht(n.to)?this.target(t[n.to]):ht(n.toX)&&ht(n.toY)&&this.target(new K(n.toX,n.toY)),ht(n.type)&&this.type()!==n.type&&(this.points([]),this.type(n.type)),this.dataItem=e,this._template(),this.redraw(this.options)):this.options=z({},n,this.options))},updateModel:function(e){if(this.diagram&&this.diagram._isEditable&&this.diagram.connectionsDataSource){var t=this.diagram.connectionsDataSource.getByUid(this.dataItem.uid);t&&(this.diagram._suspendModelRefresh(),ht(this.options.fromX)&&null!==this.options.fromX?(t.set("from",null),t.set("fromX",this.options.fromX),t.set("fromY",this.options.fromY)):(t.set("from",this.options.from),t.set("fromX",null),t.set("fromY",null)),ht(this.options.toX)&&null!==this.options.toX?(t.set("to",null),t.set("toX",this.options.toX),t.set("toY",this.options.toY)):(t.set("to",this.options.to),t.set("toX",null),t.set("toY",null)),ht(this.options.type)&&ht(t.type)&&t.set("type",this.options.type),this.dataItem=t,this.diagram._resumeModelRefresh(),e&&this.diagram._syncConnectionChanges())}},sourcePoint:function(){return this._resolvedSourceConnector?this._resolvedSourceConnector.position():this._sourcePoint},source:function(e,n){var i,r;if(ut(e)){if(r=e instanceof y,r&&!e.getConnector(Mt))return;n&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new P.ConnectionEditUnit(this,e)),e!==t&&(this.from=e),this._removeFromSourceConnector(),null===e?this.sourceConnector&&(this._sourcePoint=this._resolvedSourceConnector.position(),this._clearSourceConnector(),this._setFromOptions(null,this._sourcePoint)):e instanceof _?(i=e.shape.dataItem,i&&this._setFromOptions(i.id),this.sourceConnector=e,this.sourceConnector.connections.push(this)):e instanceof K?(this._setFromOptions(null,e),this._sourcePoint=e,this.sourceConnector&&this._clearSourceConnector()):r&&(i=e.dataItem,i&&this._setFromOptions(i.id),this.sourceConnector=e.getConnector(Mt),this.sourceConnector.connections.push(this)),this.refresh()}return this.sourceConnector?this.sourceConnector:this._sourcePoint},_setFromOptions:function(e,t){this.options.from=e,t?(this.options.fromX=t.x,this.options.fromY=t.y):(this.options.fromX=null,this.options.fromY=null)},sourceDefiner:function(e){if(!e)return this._sourceDefiner||(this._sourceDefiner=new P.PathDefiner(this.sourcePoint(),null,null)),this._sourceDefiner;if(!(e instanceof P.PathDefiner))throw"The sourceDefiner needs to be a PathDefiner.";e.left=null,this._sourceDefiner=e,this.source(e.point)},targetPoint:function(){return this._resolvedTargetConnector?this._resolvedTargetConnector.position():this._targetPoint},target:function(e,n){var i,r;if(ut(e)){if(r=e instanceof y,r&&!e.getConnector(Mt))return;n&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new P.ConnectionEditUnit(this,t,e)),e!==t&&(this.to=e),this._removeFromTargetConnector(),null===e?this.targetConnector&&(this._targetPoint=this._resolvedTargetConnector.position(),this._clearTargetConnector(),this._setToOptions(null,this._targetPoint)):e instanceof _?(i=e.shape.dataItem,i&&this._setToOptions(i.id),this.targetConnector=e,this.targetConnector.connections.push(this)):e instanceof K?(this._setToOptions(null,e),this._targetPoint=e,this.targetConnector&&this._clearTargetConnector()):r&&(i=e.dataItem,i&&this._setToOptions(i.id),this.targetConnector=e.getConnector(Mt),this.targetConnector.connections.push(this)),this.refresh()}return this.targetConnector?this.targetConnector:this._targetPoint},_setToOptions:function(e,t){this.options.to=e,t?(this.options.toX=t.x,this.options.toY=t.y):(this.options.toX=null,this.options.toY=null)},targetDefiner:function(e){if(!e)return this._targetDefiner||(this._targetDefiner=new P.PathDefiner(this.targetPoint(),null,null)),this._targetDefiner;if(!(e instanceof P.PathDefiner))throw"The sourceDefiner needs to be a PathDefiner.";e.right=null,this._targetDefiner=e,this.target(e.point)},_updateConnectors:function(){this._updateConnector(this.source(),"source"),this._updateConnector(this.target(),"target")},_updateConnector:function(e,t){var n,i,r,o,a=this,s=a.diagram;e instanceof _&&!s.getShapeById(e.shape.id)?(n=e.shape.dataItem,i=e.options.name,r=function(){var r=s._dataMap[n.id];e=r.getConnector(i),a[t](e,!1),a.updateModel()},s._dataMap[n.id]?r():(o=s._inactiveShapeItems.getByUid(n.uid),o&&s._deferredConnectionUpdates.push(o.onActivate(r)))):a[t](e,!1)},content:function(e){var t=this._content(e);return ht(e)&&this._alignContent(),t},_alignContent:function(){var e,t,n,i;this._contentVisual&&(e=this._bounds.topLeft(),t=this.sourcePoint().minus(e),n=this.targetPoint().minus(e),i=K.fn.middleOf(t,n),this._contentVisual.position(new K(i.x+e.x,i.y+e.y)))},select:function(e){var n,i,r=this.diagram;return this._canSelect()&&this.isSelected!==e?(this.isSelected=e,n=[],i=[],this.isSelected?(this.adorner=new X(this,this.options.selection),r._adorn(this.adorner,!0),r._selectedItems.push(this),n.push(this)):this.adorner&&(r._adorn(this.adorner,!1),rt.remove(r._selectedItems,this),this.adorner=t,i.push(this)),this.adorner&&this.adorner.refresh(),r._internalSelection||r._selectionChanged(n,i),!0):t},bounds:function(e){return!e||gt(e)?this._bounds:(this._bounds=e,t)},type:function(e){var n=this.options;return e?(e!==n.type&&(n.type=e,this._initRouter(),this.refresh()),t):n.type},_initRouter:function(){var e=(this.options.type||"").toLowerCase();this._router=e==yt?new ct(this):new lt(this)},points:function(e){var t,n,i,r;if(!e){if(i=[],ut(this.definers))for(r=0;this.definers.length>r;r++)i.push(this.definers[r].point);return i}for(this.definers=[],t=0;e.length>t;t++)if(n=e[t],n instanceof P.Point)this.definers.push(new P.PathDefiner(n));else{if(!n.hasOwnProperty("x")||!n.hasOwnProperty("y"))throw"A Connection point needs to be a Point or an object with x and y properties.";this.definers.push(new P.PathDefiner(new K(n.x,n.y)))}},allPoints:function(){var e,t=[this.sourcePoint()];if(this.definers)for(e=0;this.definers.length>e;e++)t.push(this.definers[e].point);return t.push(this.targetPoint()),t},refresh:function(){this._resolveConnectors(),this._refreshPath(),this._alignContent(),this.adorner&&this.adorner.refresh()},_resolveConnectors:function(){var e,t,n,o,a=this,s=a.source(),l=a.target();s instanceof K?e=s:s instanceof _&&(i(s)?n=s.shape:(a._resolvedSourceConnector=s,e=s.position())),l instanceof K?t=l:l instanceof _&&(i(l)?o=l.shape:(a._resolvedTargetConnector=l,t=l.position())),e?o&&(a._resolvedTargetConnector=r(e,o)):n&&(t?a._resolvedSourceConnector=r(t,n):o&&this._resolveAutoConnectors(n,o))},_resolveAutoConnectors:function(e,t){var n,r,o,a,s,l,c,d,u,h,p,f,g=Bt,m=Bt,v=e.connectors;for(h=0;v.length>h;h++)if(d=v[h],!i(d))for(a=d.position(),n=t.connectors,p=0;n.length>p;p++)u=n[p],i(u)||(s=u.position(),f=vt.round(a.distanceTo(s)),g>f&&this.diagram&&this._testRoutePoints(a,s,d,u)&&(g=f,r=d,o=u),m>f&&(l=d,c=u,m=f));r&&(l=r,c=o),this._resolvedSourceConnector=l,this._resolvedTargetConnector=c},_testRoutePoints:function(e,t,n,i){var r,o,a,s,l,c,d=this._router,u=!0;if(d instanceof ct)for(r=d.routePoints(e,t,n,i),r.unshift(e),r.push(t),s=[n.shape,i.shape],c=1;r.length>c;c++)if(o=r[c-1],a=r[c],l=new W(vt.min(o.x,a.x),vt.min(o.y,a.y),vt.abs(o.x-a.x),vt.abs(o.y-a.y)),this.diagram._shapesQuadTree.hitTestRect(l,s)){u=!1;break}return u},redraw:function(e){if(e){this.options=z({},this.options,e);var t=this.options.points;ht(t)&&t.length>0&&(this.points(t),this._refreshPath()),(e&&e.content||e.text)&&this.content(e.content),this.path.redraw({fill:e.fill,stroke:e.stroke,startCap:e.startCap,endCap:e.endCap})}},clone:function(){var e=this.serialize();return this.diagram&&this.diagram._isEditable&&ht(this.dataItem)&&(e.options.dataItem=h(this.dataItem)),new w(this.from,this.to,e.options)},serialize:function(){var e=this.from.toJSON?this.from.toJSON:""+this.from,t=this.to.toJSON?this.to.toJSON:""+this.to,n=z({},{options:this.options,from:e,to:t});return ht(this.dataItem)&&(n.dataItem=""+this.dataItem),n.options.points=this.points(),n},_hitTest:function(e){if(this.visible()){var t=new K(e.x,e.y),n=this.sourcePoint(),i=this.targetPoint();if(e.isEmpty&&!e.isEmpty()&&e.contains(n)&&e.contains(i))return this;if(this._router.hitTest(t))return this}},_hover:function(e){var t=(this.options.stroke||{}).color;e&&ut(this.options.hover.stroke.color)&&(t=this.options.hover.stroke.color),this.path.redraw({stroke:{color:t}})},_refreshPath:function(){ht(this.path)&&(this._drawPath(),this.bounds(this._router.getBounds()))},_drawPath:function(){var e,t,n;this._router&&this._router.route(),e=this.sourcePoint(),t=this.targetPoint(),n=this.points(),this.path.redraw({points:[e].concat(n,[t])})},_clearSourceConnector:function(){rt.remove(this.sourceConnector.connections,this),this.sourceConnector=t,this._resolvedSourceConnector=t},_clearTargetConnector:function(){rt.remove(this.targetConnector.connections,this),this.targetConnector=t,this._resolvedTargetConnector=t},_removeFromSourceConnector:function(){this.sourceConnector&&rt.remove(this.sourceConnector.connections,this)},_removeFromTargetConnector:function(){this.targetConnector&&rt.remove(this.targetConnector.connections,this)}}),b=E.extend({init:function(e,t){var n=this;kendo.destroy(e),E.fn.init.call(n,e,t),n._initTheme(),n._initElements(),n._extendLayoutOptions(n.options),n._initDefaults(t),n._initCanvas(),n.mainLayer=new O({id:"main-layer"}),n.canvas.append(n.mainLayer),n._shapesQuadTree=new D(n),n._pan=new K,n._adorners=[],n.adornerLayer=new O({id:"adorner-layer"}),n.canvas.append(n.adornerLayer),n._createHandlers(),n._initialize(),n._fetchFreshData(),n._createGlobalToolBar(),n._resizingAdorner=new tt(n,{editable:n.options.editable}),n._connectorsAdorner=new nt(n),n._adorn(n._resizingAdorner,!0),n._adorn(n._connectorsAdorner,!0),n.selector=new et(n),n._clipboard=[],n.pauseMouseHandlers=!1,n._createShapes(),n._createConnections(),n.options.layout&&n.layout(n.options.layout),n.zoom(n.options.zoom),n.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:P.shapeDefaults({undoable:!0}),connectionDefaults:{editable:{tools:[]},type:yt},shapes:[],connections:[]},events:[Ot,Ht,Lt,zt,Rt,wt,bt,xt,Tt,Dt,"toolBarClick","save","cancel","edit","remove","add","dataBound",St,kt,Ct],_createGlobalToolBar:function(){var e,t=this.options.editable;t&&(e=t.tools,this._isEditable&&0===e.length&&(e=["createShape","undo","redo","rotateClockwise","rotateAnticlockwise"]),e&&e.length&&(this.toolBar=new x(this,{tools:e||{},click:B(this._toolBarClick,this),modal:!1}),this.toolBar.element.css({textAlign:"left"}),this.element.prepend(this.toolBar.element),this._resize()))},createShape:function(){var e,t,n,i,r,o;(this.editor&&this.editor.end()||!this.editor)&&(e=this.dataSource,t=e.view()||[],n=t.length,i=f(e,{}),r=this._createShape(i,{}),this.trigger("add",{shape:r})||(e.insert(n,i),o=this._inactiveShapeItems.getByUid(i.uid),o.element=r,this.edit(r)))},_createShape:function(e,t){t=z({},this.options.shapeDefaults,t),t.dataItem=e;var n=new y(t,this);return n},createConnection:function(){var e,t,n,i,r;(this.editor&&this.editor.end()||!this.editor)&&(e=this.connectionsDataSource,t=e.view()||[],n=t.length,i=f(e,{}),r=this._createConnection(i),this.trigger("add",{connection:r})||(this._connectionsDataMap[i.uid]=r,e.insert(n,i),this.addConnection(r,!1),this.edit(r)))},_createConnection:function(e,t,n){var i,r=z({},this.options.connectionDefaults);return r.dataItem=e,i=new w(t||new K,n||new K,r)},editModel:function(e,t){var n,i,r,o;if(this.cancelEdit(),r=this.options.editable,"shape"==t)n=r.shapeEditors,i=r.shapeTemplate;else{if("connection"!=t)return;o=B(c,this),n=z({},{from:o,to:o},r.connectionEditors),i=r.connectionTemplate}this.editor=new C(this.element,{update:B(this._update,this),cancel:B(this._cancel,this),model:e,type:t,target:this,editors:n,template:i}),this.trigger("edit",this._editArgs())},edit:function(e){if(e.dataItem){var t=e instanceof y?"shape":"connection";this.editModel(e.dataItem,t)}},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 e,t;this.editor&&!this.trigger("cancel",this._editArgs())&&(e=this.editor.model,this._getEditDataSource().cancelChanges(e),t=this._connectionsDataMap[e.uid]||this._dataMap[e.id],t&&t._setOptionsFromModel(e),this._destroyEditor())},_getEditDataSource:function(){return"shape"===this.editor.options.type?this.dataSource:this.connectionsDataSource},_editArgs:function(){var e={container:this.editor.element};return e[this.editor.options.type]=this.editor.model,e},_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=e("<div />").appendTo(this.element)},_initDefaults:function(e){var t=this.options,n=t.editable,i=t.shapeDefaults,r=t.connectionDefaults,o=(e||{}).shapeDefaults;n===!1?(i.editable=!1,r.editable=!1):(g(n,i.editable,["drag","remove","connect"]),g(n,r.editable,["drag","remove"])),o&&o.connectors&&(t.shapeDefaults.connectors=o.connectors)},_initCanvas:function(){var t=e("<div class='k-layer'></div>").appendTo(this.scrollable)[0],n=this.viewport();this.canvas=new H(t,{width:n.width||Vt,height:n.height||Ut})
  },_createHandlers:function(){var e=this,t=e.element;t.on(sn,B(e._wheel,e)),kendo.support.touch||kendo.support.mobileOS?(e._userEvents=new kendo.UserEvents(t,{multiTouch:!0,tap:B(e._tap,e)}),e._userEvents.bind(["gesturestart","gesturechange","gestureend"],{gesturestart:B(e._gestureStart,e),gesturechange:B(e._gestureChange,e),gestureend:B(e._gestureEnd,e)}),e.toolService=new J(e),e.options.pannable!==!1&&e.scroller.enable()):(e.toolService=new J(e),this.scroller.wrapper.on("mousemove"+_t,B(e._mouseMove,e)).on("mouseup"+_t,B(e._mouseUp,e)).on("mousedown"+_t,B(e._mouseDown,e)).on("mouseover"+_t,B(e._mouseover,e)).on("mouseout"+_t,B(e._mouseout,e)),t.on("keydown"+_t,B(e._keydown,e))),this._syncHandler=B(e._syncChanges,e),e._resizeHandler=B(e.resize,e,!1),kendo.onResize(e._resizeHandler),this.bind(Ht,B(e._destroyToolBar,e)),this.bind(Lt,B(e._destroyToolBar,e))},_tap:function(e){var t,n=this.toolService,i=this._caculateMobilePosition(e);n._updateHoveredItem(i),n.hoveredItem&&(t=n.hoveredItem,this.options.selectable!==!1&&(this._destroyToolBar(),t.isSelected?t.select(!1):this.select(t,{addToSelection:!0}),this._createToolBar()),this.trigger("click",{item:t,point:i}))},_caculateMobilePosition:function(e){return this.documentToModel(K(e.x.location,e.y.location))},_gestureStart:function(e){var t,n;this._destroyToolBar(),this.scroller.disable(),t=this.documentToModel(new K(e.center.x,e.center.y)),n={point:t,zoom:this.zoom()},this.trigger(Ht,n)||(this._gesture=e,this._initialCenter=t)},_gestureChange:function(e){var t,n,i=this._gesture,r=this._initialCenter,o=this.documentToView(new K(e.center.x,e.center.y)),a=e.distance/i.distance,s=this._zoom,l=!1;vt.abs(a-1)>=ln&&(this._zoom=s=this._getValidZoom(s*a),this.options.zoom=s,this._gesture=e,l=!0),t=r.times(s),n=o.minus(t),(l||this._pan.distanceTo(n)>=cn)&&(this._panTransform(n),this._updateAdorners()),e.preventDefault()},_gestureEnd:function(){this.options.pannable!==!1&&this.scroller.enable(),this.trigger(Ot,{point:this._initialCenter,zoom:this.zoom()})},_resize:function(){var e=this.viewport();this.canvas&&this.canvas.size(e),this.scrollable&&this.toolBar&&this.scrollable.height(e.height)},_mouseover:function(e){var t=e.target._kendoNode;t&&t.srcElement._hover&&t.srcElement._hover(!0,t.srcElement)},_mouseout:function(e){var t=e.target._kendoNode;t&&t.srcElement._hover&&t.srcElement._hover(!1,t.srcElement)},_initTheme:function(){var e=this,t=A.ui.themes||{},n=((e.options||{}).theme||"").toLowerCase(),i=(t[n]||{}).diagram;e.options=z({},i,e.options)},_createShapes:function(){var e,t,n=this,i=n.options,r=i.shapes;for(t=0;r.length>t;t++)e=r[t],n.addShape(e)},_createConnections:function(){var e,t,n,i,r=this,o=r.options,a=o.connectionDefaults,s=o.connections;for(i=0;s.length>i;i++)e=s[i],t=r._findConnectionShape(e.from),n=r._findConnectionShape(e.to),r.connect(t,n,z({},a,e))},_findConnectionShape:function(e){var t=this,n=gt(e)?e:e.shapeId,i=t.getShapeById(n);return i.getConnector(e.connector||Mt)},destroy:function(){var e=this;E.fn.destroy.call(e),this._userEvents&&this._userEvents.destroy(),kendo.unbindResize(e._resizeHandler),e.clear(),e.element.off(_t),e.scroller.wrapper.off(_t),e.canvas.destroy(!0),e.canvas=t,e._destroyEditor(),e.destroyScroller(),e._destroyGlobalToolBar(),e._destroyToolBar()},destroyScroller:function(){var e=this.scroller;e&&(e.destroy(),e.element.remove(),this.scroller=null)},save:function(){var e,t,n,i,r={};for(r.shapes=[],r.connections=[],e=0;this.shapes.length>e;e++)t=this.shapes[e],t.options.serializable&&r.shapes.push(t.options);for(e=0;this.connections.length>e;e++)n=this.connections[e],i=z({},n.options,{from:n.from.toJSON(),to:n.to.toJSON()}),r.connections.push(i);return r},focus:function(){if(!this.element.is(kendo._activeElement())){var e,t=this.element,n=t[0],i=[],r=[],o=document.documentElement;do n=n.parentNode,n.scrollHeight>n.clientHeight&&(i.push(n),r.push(n.scrollTop));while(n!=o);for(t.focus(),e=0;i.length>e;e++)i[e].scrollTop=r[e]}},load:function(e){this.clear(),this.setOptions(e),this._createShapes(),this._createConnections()},setOptions:function(e){z(this.options,e)},clear:function(){var e=this;e.select(!1),e.mainLayer.clear(),e._shapesQuadTree.clear(),e._initialize()},connect:function(e,t,n){var i,r;return this.connectionsDataSource&&this._isEditable?(r=this.connectionsDataSource.add({}),i=this._connectionsDataMap[r.uid],i.source(e),i.target(t),i.redraw(n),i.updateModel()):(i=new w(e,t,z({},this.options.connectionDefaults,n)),this.addConnection(i)),i},connected:function(e,t){var n,i;for(n=0;this.connections.length>n;n++)if(i=this.connections[n],i.from==e&&i.to==t)return!0;return!1},addConnection:function(e,t){return t!==!1&&this.undoRedoService.add(new P.AddConnectionUnit(e,this),!1),e.diagram=this,e._setOptionsFromModel(),e.refresh(),this.mainLayer.append(e.visual),this.connections.push(e),this.trigger(bt,{added:[e],removed:[]}),e},_addConnection:function(e,t){var n,i=this.connectionsDataSource;if(i&&this._isEditable){if(n=f(i,h(e.dataItem)),e.dataItem=n,e.updateModel(),!this.trigger("add",{connection:e}))return this._connectionsDataMap[n.uid]=e,i.add(n),this.addConnection(e,t),e._updateConnectors(),e}else if(!this.trigger("add",{connection:e}))return this.addConnection(e,t),e._updateConnectors(),e},addShape:function(e,t){var n,i=this.options.shapeDefaults;if(e instanceof y)i=z({},i,t),e.redraw(t),n=e;else{if(e instanceof kendo.Class)return;i=z({},i,e||{}),n=new y(i)}return i.undoable&&this.undoRedoService.add(new P.AddShapeUnit(n,this),!1),this.shapes.push(n),n.diagram=this,this.mainLayer.append(n.visual),this._shapesQuadTree.insert(n),this.trigger(bt,{added:[n],removed:[]}),n.hasOwnProperty("layout")&&n.layout(n),n},_addShape:function(e,t){var n,i,r=this,o=r.dataSource;if(o&&this._isEditable){if(n=f(o,h(e.dataItem)),e.dataItem=n,e.updateModel(),!this.trigger("add",{shape:e}))return this.dataSource.add(n),i=this._inactiveShapeItems.getByUid(n.uid),i.element=e,i.undoable=t,e}else if(!this.trigger("add",{shape:e}))return this.addShape(e,{undoable:t})},remove:function(e,t){var n,i,r,o;for(e=pt(e)?e.slice(0):[e],n=p(e),i=n.shapes,r=n.connections,ht(t)||(t=!0),t&&this.undoRedoService.begin(),this._suspendModelRefresh(),o=i.length-1;o>=0;o--)this._removeItem(i[o],t,r);for(o=r.length-1;o>=0;o--)this._removeItem(r[o],t);this._resumeModelRefresh(),t&&this.undoRedoService.commit(!1),this.trigger(bt,{added:[],removed:e})},_removeShapeDataItem:function(e){this._isEditable&&(this.dataSource.remove(e.dataItem),delete this._dataMap[e.dataItem.id])},_removeConnectionDataItem:function(e){this._isEditable&&(this.connectionsDataSource.remove(e.dataItem),delete this._connectionsDataMap[e.dataItem.uid])},_triggerRemove:function(e){var t,n,i,r,o=[];for(r=0;e.length>r;r++)t=e[r],i=t.options.editable,n=t instanceof y?{shape:t}:{connection:t},i&&i.remove!==!1&&!this.trigger("remove",n)&&o.push(t);return o},undo:function(){this.undoRedoService.undo()},redo:function(){this.undoRedoService.redo()},select:function(e,t){if(!ut(e))return this._selectedItems;t=z({addToSelection:!1},t);var n,i,r=t.addToSelection,o=[],a=[];for(r||this.deselect(),this._internalSelection=!0,e instanceof Array?o=e:e instanceof v&&(o=[e]),n=0;o.length>n;n++)i=o[n],i.select(!0)&&a.push(i);this._selectionChanged(a,[]),this._internalSelection=!1},selectAll:function(){this.select(this.shapes.concat(this.connections))},selectArea:function(e){var t,n,i,r;if(this._internalSelection=!0,r=[],e instanceof W)for(n=this.shapes.concat(this.connections),t=0;n.length>t;t++)i=n[t],e&&!i._hitTest(e)||!i.options.enable||i.select(!0)&&r.push(i);this._selectionChanged(r,[]),this._internalSelection=!1},deselect:function(e){this._internalSelection=!0;var t,n,i=[],r=[];for(e instanceof Array?r=e:e instanceof v?r.push(e):ut(e)||(r=this._selectedItems.slice(0)),n=0;r.length>n;n++)t=r[n],t.select(!1)&&i.push(t);this._selectionChanged([],i),this._internalSelection=!1},toFront:function(e,t){var n,i,r;e||(e=this._selectedItems.slice()),n=this._getDiagramItems(e),!ht(t)||t?(i=o(this.mainLayer,n.visuals),r=new st(this,e,i),this.undoRedoService.add(r)):(this.mainLayer.toFront(n.visuals),this._fixOrdering(n,!0))},toBack:function(e,t){var n,i,r;e||(e=this._selectedItems.slice()),n=this._getDiagramItems(e),!ht(t)||t?(i=o(this.mainLayer,n.visuals),r=new at(this,e,i),this.undoRedoService.add(r)):(this.mainLayer.toBack(n.visuals),this._fixOrdering(n,!1))},bringIntoView:function(e,t){var n,i,r,o,a=this.viewport(),s=new P.RectAlign(a);0!==a.width&&0!==a.height&&(t=z({animate:!1,align:"center middle"},t),"none"==t.align&&(t.align="center middle"),e instanceof v?i=e.bounds(Jt):pt(e)?i=this.boundingBox(e):e instanceof W&&(i=e.clone()),r=i.clone(),i.zoom(this._zoom),this._storePan(new K),(i.width>a.width||i.height>a.height)&&(this._zoom=this._getValidZoom(vt.min(a.width/r.width,a.height/r.height)),i=r.clone().zoom(this._zoom)),this._zoomMainLayer(),n=i.clone(),s.align(i,t.align),o=i.topLeft().minus(n.topLeft()),this.pan(o.times(-1),t.animate))},alignShapes:function(e){var t,n,i,r,o,a,s;if(dt(e)&&(e="Left"),t=this.select(),0!==t.length){switch(e.toLowerCase()){case"left":case"top":n=Qt;break;case"right":case"bottom":n=Xt}for(r=0;t.length>r;r++)if(i=t[r],i instanceof y)switch(e.toLowerCase()){case"left":n=vt.min(n,i.options.x);break;case"top":n=vt.min(n,i.options.y);break;case"right":n=vt.max(n,i.options.x);break;case"bottom":n=vt.max(n,i.options.y)}for(o=[],a=[],r=0;t.length>r;r++)if(i=t[r],i instanceof y)switch(a.push(i),o.push(i.bounds()),e.toLowerCase()){case"left":case"right":i.position(new K(n,i.options.y));break;case"top":case"bottom":i.position(new K(i.options.x,n))}s=new P.TransformUnit(a,o),this.undoRedoService.add(s,!1)}},zoom:function(e,t){var n,i,r,o;return e&&(n=t?t.point:new P.Point(0,0),e=this._zoom=this._getValidZoom(e),dt(n)||(n=new P.Point(vt.round(n.x),vt.round(n.y)),i=n.times(e),r=this.modelToView(n),o=r.minus(i),this._storePan(new P.Point(vt.round(o.x),vt.round(o.y)))),t&&(t.zoom=e),this._panTransform(),this._updateAdorners()),this._zoom},_getPan:function(e){var t=this.canvas;return t.translate||(e=e.plus(this._pan)),e},pan:function(e,t){var n,i;e instanceof K&&(n=this,i=n.scroller,e=n._getPan(e),e=e.times(-1),t?i.animatedScrollTo(e.x,e.y,function(){n._updateAdorners()}):(i.scrollTo(e.x,e.y),n._updateAdorners()))},viewport:function(){var e=this.element,t=e.width(),n=e.height();return this.toolBar&&(n-=this.toolBar.element.outerHeight()),new W(0,0,t,n)},copy:function(){var e,t;if(this.options.copy.enabled)for(this._clipboard=[],this._copyOffset=1,e=0;this._selectedItems.length>e;e++)t=this._selectedItems[e],this._clipboard.push(t)},cut:function(){var e,t;if(this.options.copy.enabled){for(this._clipboard=[],this._copyOffset=0,e=0;this._selectedItems.length>e;e++)t=this._selectedItems[e],this._clipboard.push(t);this.remove(this._clipboard,!0)}},paste:function(){var e,t,n,i,r,o,a,s;if(this._clipboard.length>0){for(i={},r=p(this._clipboard),o=r.connections,a=r.shapes,s={x:this._copyOffset*this.options.copy.offsetX,y:this._copyOffset*this.options.copy.offsetY},this.deselect(),n=0;a.length>n;n++)e=a[n],t=e.clone(),i[e.id]=t,t.position(new K(e.options.x+s.x,e.options.y+s.y)),t.diagram=this,t=this._addShape(t),t&&t.select();for(n=0;o.length>n;n++)e=o[n],t=this._addConnection(e.clone()),t&&(this._updateCopiedConnection(t,e,"source",i,s),this._updateCopiedConnection(t,e,"target",i,s),t.select(!0),t.updateModel());this._syncChanges(),this._copyOffset+=1}},_updateCopiedConnection:function(e,t,n,i,r){var o,a,s,l=t[n](),c=this;l instanceof _&&i[l.shape.id]?(s=i[l.shape.id],c.getShapeById(s.id)?e[n](s.getConnector(l.options.name)):(a=c._inactiveShapeItems.getByUid(s.dataItem.uid),a&&(o=function(t){s=c._dataMap[t.id],e[n](s.getConnector(l.options.name)),e.updateModel()},c._deferredConnectionUpdates.push(a.onActivate(o))))):e[n](new K(t[n+"Point"]().x+r.x,t[n+"Point"]().y+r.y))},boundingBox:function(e,t){var n,i,r,o=W.empty(),a=ut(e)?this._getDiagramItems(e):{shapes:this.shapes};if(a.shapes.length>0)for(i=a.shapes[0],o=i.bounds(en),r=1;a.shapes.length>r;r++)i=a.shapes[r],n=i.bounds(en),t===!0&&(n.x-=i._rotationOffset.x,n.y-=i._rotationOffset.y),o=o.union(n);return o},_containerOffset:function(){var e=this.element.offset();return this.toolBar&&(e.top+=this.toolBar.element.outerHeight()),e},documentToView:function(e){var t=this._containerOffset();return new K(e.x-t.left,e.y-t.top)},viewToDocument:function(e){var t=this._containerOffset();return new K(e.x+t.left,e.y+t.top)},viewToModel:function(e){return this._transformWithMatrix(e,this._matrixInvert)},modelToView:function(e){return this._transformWithMatrix(e,this._matrix)},modelToLayer:function(e){return this._transformWithMatrix(e,this._layerMatrix)},layerToModel:function(e){return this._transformWithMatrix(e,this._layerMatrixInvert)},documentToModel:function(e){var t=this.documentToView(e);return this.canvas.translate||(t.x=t.x+this.scroller.scrollLeft,t.y=t.y+this.scroller.scrollTop),this.viewToModel(t)},modelToDocument:function(e){return this.viewToDocument(this.modelToView(e))},_transformWithMatrix:function(e,t){var n,i,r=e;return e instanceof K?t&&(r=t.apply(e)):(n=this._transformWithMatrix(e.topLeft(),t),i=this._transformWithMatrix(e.bottomRight(),t),r=W.fromPoints(n,i)),r},setDataSource:function(e){this.options.dataSource=e,this._dataSource(),this.options.autoBind&&this.dataSource.fetch()},setConnectionsDataSource:function(e){this.options.connectionsDataSource=e,this._connectionDataSource(),this.options.autoBind&&this.connectionsDataSource.fetch()},layout:function(e){var t,n,i,r,o;switch(this.isLayouting=!0,dt(e)&&(e=this.options.layout),t=dt(e)||dt(e.type)?"Tree":e.type,t.toLowerCase()){case"tree":n=new P.TreeLayout(this);break;case"layered":n=new P.LayeredLayout(this);break;case"forcedirected":case"force":case"spring":case"springembedder":n=new P.SpringLayout(this);break;default:throw"Layout algorithm '"+t+"' is not supported."}i=new P.LayoutState(this),r=n.layout(e),r&&(o=new P.LayoutUndoUnit(i,r,e?e.animate:null),this.undoRedoService.add(o)),this.isLayouting=!1},getShapeById:function(e){var t;return(t=rt.first(this.shapes,function(t){return t.visual.id===e}))?t:t=rt.first(this.connections,function(t){return t.visual.id===e})},_extendLayoutOptions:function(e){e.layout&&(e.layout=z(P.LayoutBase.fn.defaultOptions||{},e.layout))},_selectionChanged:function(e,t){(e.length||t.length)&&this.trigger(zt,{selected:e,deselected:t})},_getValidZoom:function(e){return vt.min(vt.max(e,this.options.zoomMin),this.options.zoomMax)},_panTransform:function(e){var t=this,n=e||t._pan;t.canvas.translate?(t.scroller.scrollTo(n.x,n.y),t._zoomMainLayer()):(t._storePan(n),t._transformMainLayer())},_finishPan:function(){this.trigger(Lt,{total:this._pan,delta:Number.NaN})},_storePan:function(e){this._pan=e,this._storeViewMatrix()},_zoomMainLayer:function(){var e=this._zoom,t=new U(0,0,e,e);t.render(this.mainLayer),this._storeLayerMatrix(t),this._storeViewMatrix()},_transformMainLayer:function(){var e=this._pan,t=this._zoom,n=new U(e.x,e.y,t,t);n.render(this.mainLayer),this._storeLayerMatrix(n),this._storeViewMatrix()},_storeLayerMatrix:function(e){this._layerMatrix=e.toMatrix(),this._layerMatrixInvert=e.invert().toMatrix()},_storeViewMatrix:function(){var e=this._pan,t=this._zoom,n=new U(e.x,e.y,t,t);this._matrix=n.toMatrix(),this._matrixInvert=n.invert().toMatrix()},_toIndex:function(e,t){var n=this._getDiagramItems(e);this.mainLayer.toIndex(n.visuals,t),this._fixOrdering(n,!1)},_fixOrdering:function(e,t){var n,i,r=t?this.shapes.length-1:0,o=t?this.connections.length-1:0;for(n=0;e.shapes.length>n;n++)i=e.shapes[n],rt.remove(this.shapes,i),rt.insert(this.shapes,i,r);for(n=0;e.cons.length>n;n++)i=e.cons[n],rt.remove(this.connections,i),rt.insert(this.connections,i,o)},_getDiagramItems:function(e){var t,n,i={},r=e;for(i.visuals=[],i.shapes=[],i.cons=[],e?pt(e)||(r=[e]):r=this._selectedItems.slice(),t=0;r.length>t;t++)n=r[t],n instanceof y?(i.shapes.push(n),i.visuals.push(n.visual)):n instanceof w&&(i.cons.push(n),i.visuals.push(n.visual));return i},_removeItem:function(e,t,n){e.select(!1),e instanceof y?(this._removeShapeDataItem(e),this._removeShape(e,t,n)):e instanceof w&&(this._removeConnectionDataItem(e),this._removeConnection(e,t)),this.mainLayer.remove(e.visual)},_removeShape:function(e,t,n){var i,r,o,a,s=[],l=[];for(this.toolService._removeHover(),t&&this.undoRedoService.addCompositeItem(new G(e)),rt.remove(this.shapes,e),this._shapesQuadTree.remove(e),i=0;e.connectors.length>i;i++)for(o=e.connectors[i],a=0;o.connections.length>a;a++)r=o.connections[a],n&&A.inArray(r,n)||(r.sourceConnector==o?s.push(r):r.targetConnector==o&&l.push(r));for(i=0;s.length>i;i++)s[i].source(null,t),s[i].updateModel();for(i=0;l.length>i;i++)l[i].target(null,t),l[i].updateModel()},_removeConnection:function(e,t){e.sourceConnector&&rt.remove(e.sourceConnector.connections,e),e.targetConnector&&rt.remove(e.targetConnector.connections,e),t&&this.undoRedoService.addCompositeItem(new q(e)),rt.remove(this.connections,e)},_removeDataItems:function(e,t){var n,i,r,o;for(e=pt(e)?e:[e];e.length;)if(n=e.shift(),r=this._dataMap[n.uid],r&&(this._removeShapeConnections(r),this._removeItem(r,!1),delete this._dataMap[n.uid],t&&n.hasChildren&&n.loaded()))for(i=n.children.data(),o=0;i.length>o;o++)e.push(i[o])},_removeShapeConnections:function(e){var t,n=e.connections();if(n)for(t=0;n.length>t;t++)this._removeItem(n[t],!1)},_addDataItem:function(e,t){var n,i;if(ht(e))return(n=this._dataMap[e.id])?n:(i=z({},this.options.shapeDefaults),i.dataItem=e,n=new y(i,this),this.addShape(n,{undoable:t!==!1}),this._dataMap[e.id]=n,n)},_addDataItemByUid:function(e){var t,n;if(ht(e))return(t=this._dataMap[e.uid])?t:(n=z({},this.options.shapeDefaults),n.dataItem=e,t=new y(n,this),this.addShape(t),this._dataMap[e.uid]=t,t)},_addDataItems:function(e,t){var n,i,r,o,a;for(i=0;e.length>i;i++)n=e[i],r=this._addDataItemByUid(n),o=this._addDataItemByUid(t),o&&!this.connected(o,r)&&(a=this.connect(o,r))},_refreshSource:function(e){var t,n=this,i=e.node,r=e.action,o=e.items,a=n.options;if(!e.field){if("remove"==r)this._removeDataItems(e.items,!0);else for(r||i||n.clear(),this._addDataItems(o,i),t=0;o.length>t;t++)o[t].load();a.layout&&n.layout(a.layout)}},_mouseDown:function(e){var t=this._calculatePosition(e);1==e.which&&this.toolService.start(t,this._meta(e))&&(this._destroyToolBar(),e.preventDefault())},_addItem:function(e){e instanceof y?this.addShape(e):e instanceof w&&this.addConnection(e)},_mouseUp:function(e){var t=this._calculatePosition(e);1==e.which&&this.toolService.end(t,this._meta(e))&&(this._createToolBar(),e.preventDefault())},_createToolBar:function(){var e,t,n,i,r,o,a,s,l,c,d=this.toolService.diagram;this.singleToolBar||1!==d.select().length||(e=d.select()[0],e&&e.options.editable!==!1&&(t=e.options.editable,n=t.tools,this._isEditable&&0===n.length&&(e instanceof y?n=["edit","rotateClockwise","rotateAnticlockwise"]:e instanceof w&&(n=["edit"]),t&&t.remove!==!1&&n.push("delete")),n&&n.length&&(i=20,this.singleToolBar=new x(d,{tools:n,click:B(this._toolBarClick,this),modal:!0}),o=this.singleToolBar.element,a=this.singleToolBar._popup.element.outerWidth(),s=this.singleToolBar._popup.element.outerHeight(),e instanceof y?(l=this.modelToView(e.bounds(en)),r=K(l.x,l.y).minus(K((a-l.width)/2,s+i))):e instanceof w&&(c=this.modelToView(e.bounds()),r=K(c.x,c.y).minus(K((a-c.width-20)/2,s+i))),r?(this.canvas.translate||(r=r.minus(K(this.scroller.scrollLeft,this.scroller.scrollTop))),r=this.viewToDocument(r),r=K(vt.max(r.x,0),vt.max(r.y,0)),this.singleToolBar.showAt(r)):this._destroyToolBar())))},_toolBarClick:function(e){this.trigger("toolBarClick",e),this._destroyToolBar()},_mouseMove:function(e){if(!this.pauseMouseHandlers){var t=this._calculatePosition(e);0!==e.which&&1!=e.which||!this.toolService.move(t,this._meta(e))||e.preventDefault()}},_keydown:function(e){this.toolService.keyDown(e.keyCode,this._meta(e))&&e.preventDefault()},_wheel:function(e){var t=n(e),i=this._calculatePosition(e),r=z(this._meta(e),{delta:t});this.toolService.wheel(i,r)&&e.preventDefault()},_meta:function(e){return{ctrlKey:e.ctrlKey,metaKey:e.metaKey,altKey:e.altKey,shiftKey:e.shiftKey}},_calculatePosition:function(e){var n=e.pageX===t?e.originalEvent:e,i=new K(n.pageX,n.pageY),r=this.documentToModel(i);return r},_normalizePointZoom:function(e){return e.times(1/this.zoom())},_initialize:function(){this.shapes=[],this._selectedItems=[],this.connections=[],this._dataMap={},this._connectionsDataMap={},this._inactiveShapeItems=new u,this._deferredConnectionUpdates=[],this.undoRedoService=new Z({undone:this._syncHandler,redone:this._syncHandler}),this.id=P.randomId()},_fetchFreshData:function(){var t,n=this;n._dataSource(),n._isEditable&&n._connectionDataSource(),n.options.autoBind&&(n._isEditable?(n._preventRefresh=!0,n._preventConnectionsRefresh=!0,t=e.map([n.dataSource,n.connectionsDataSource],function(e){return e.fetch()}),e.when.apply(null,t).done(function(){n._preventRefresh=!1,n._preventConnectionsRefresh=!1,n.refresh()})):n.dataSource.fetch())},_dataSource:function(){var e,t;ht(this.options.connectionsDataSource)?(this._isEditable=!0,e=this.options.dataSource||{},t=pt(e)?{data:e}:e,this.dataSource&&this._shapesRefreshHandler?this.dataSource.unbind("change",this._shapesRefreshHandler).unbind("error",this._shapesErrorHandler):(this._shapesRefreshHandler=B(this._refreshShapes,this),this._shapesErrorHandler=B(this._error,this)),this.dataSource=kendo.data.DataSource.create(t).bind("change",this._shapesRefreshHandler).bind("error",this._shapesErrorHandler)):(this._treeDataSource(),this._isEditable=!1)},_connectionDataSource:function(){var e,t=this.options.connectionsDataSource;t&&(e=pt(t)?{data:t}:t,this.connectionsDataSource&&this._connectionsRefreshHandler?this.connectionsDataSource.unbind("change",this._connectionsRefreshHandler).unbind("error",this._connectionsErrorHandler):(this._connectionsRefreshHandler=B(this._refreshConnections,this),this._connectionsErrorHandler=B(this._error,this)),this.connectionsDataSource=kendo.data.DataSource.create(e).bind("change",this._connectionsRefreshHandler).bind("error",this._connectionsErrorHandler))},_refreshShapes:function(e){"remove"===e.action?this._shouldRefresh()&&this._removeShapes(e.items):"itemchange"===e.action?this._shouldRefresh()&&this._updateShapes(e.items,e.field):"add"===e.action?this._inactiveShapeItems.add(e.items):"sync"===e.action?this._syncShapes(e.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._preventRefresh||(this.trigger("dataBound"),this.clear(),this._addShapes(this.dataSource.view()),this.connectionsDataSource&&this._addConnections(this.connectionsDataSource.view(),!1),this.options.layout&&this.layout(this.options.layout))},refreshConnections:function(){this._preventConnectionsRefresh||(this.trigger("dataBound"),this._addConnections(this.connectionsDataSource.view(),!1),this.options.layout&&this.layout(this.options.layout))},_removeShapes:function(e){var t,n,i=this._dataMap;for(n=0;e.length>n;n++)t=e[n],i[t.id]&&(this.remove(i[t.id],!1),i[t.id]=null)},_syncShapes:function(){var e=this,t=e._inactiveShapeItems;t.forEach(function(n){var i=n.dataItem,r=n.element;i.isNew()||(r?(r._setOptionsFromModel(),e.addShape(r,{undoable:n.undoable}),e._dataMap[i.id]=r):e._addDataItem(i),n.activate(),t.remove(i))})},_updateShapes:function(e,t){var n,i,r;for(n=0;e.length>n;n++)i=e[n],r=this._dataMap[i.id],r&&r.updateOptionsFromModel(i,t)},_addShapes:function(e){for(var t=0;e.length>t;t++)this._addDataItem(e[t],!1)},_refreshConnections:function(e){"remove"===e.action?this._shouldRefresh()&&this._removeConnections(e.items):"add"===e.action?this._addConnections(e.items):"sync"===e.action||("itemchange"===e.action?this._shouldRefresh()&&this._updateConnections(e.items):this.refreshConnections())},_removeConnections:function(e){for(var t=0;e.length>t;t++)this.remove(this._connectionsDataMap[e[t].uid],!1),this._connectionsDataMap[e[t].uid]=null},_updateConnections:function(e){var t,n,i,r,o;for(t=0;e.length>t;t++)n=e[t],i=this._connectionsDataMap[n.uid],i.updateOptionsFromModel(n),r=this._validateConnector(n.from),r&&i.source(r),o=this._validateConnector(n.to),o&&i.target(o)},_addConnections:function(e,t){var n,i,r=e.length;for(n=0;r>n;n++)i=e[n],this._addConnectionDataItem(i,t)},_addConnectionDataItem:function(e,t){var n,i,r,o;this._connectionsDataMap[e.uid]||(n=this._validateConnector(e.from),ht(n)&&null!==n||(n=new K(e.fromX,e.fromY)),i=this._validateConnector(e.to),ht(i)&&null!==i||(i=new K(e.toX,e.toY)),ht(n)&&ht(i)&&(r=z({},this.options.connectionDefaults),r.dataItem=e,o=new w(n,i,r),this._connectionsDataMap[e.uid]=o,this.addConnection(o,t)))},_validateConnector:function(e){var t;return ht(e)&&null!==e&&(t=this._dataMap[e]),t},_treeDataSource:function(){var e=this,t=e.options,n=t.dataSource;n=pt(n)?{data:n}:n,n.fields||(n.fields=[{field:"text"},{field:"url"},{field:"spriteCssClass"},{field:"imageUrl"}]),e.dataSource&&e._refreshHandler&&e._unbindDataSource(),e._refreshHandler=B(e._refreshSource,e),e._errorHandler=B(e._error,e),e.dataSource=L.create(n).bind(bt,e._refreshHandler).bind(At,e._errorHandler)},_unbindDataSource:function(){var e=this;e.dataSource.unbind(bt,e._refreshHandler).unbind(At,e._errorHandler)},_error:function(){},_adorn:function(e,n){n!==t&&e&&(n?(this._adorners.push(e),this.adornerLayer.append(e.visual)):(rt.remove(this._adorners,e),this.adornerLayer.remove(e.visual)))},_showConnectors:function(e,t){t?this._connectorsAdorner.show(e):this._connectorsAdorner.destroy()},_updateAdorners:function(){var e,t,n=this._adorners;for(e=0;n.length>e;e++)t=n[e],t.refreshBounds&&t.refreshBounds(),t.refresh()},_refresh:function(){for(var e=0;this.connections.length>e;e++)this.connections[e].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 e=this.canvas._viewBox,t=I.transform().translate(-e.x,-e.y),n=new I.Rect([0,0],[e.width,e.height]),i=M.Path.fromRect(n),r=new M.Group({transform:t,clip:i}),o=this.canvas.drawingElement.children[0];return r.children.push(o),r},exportVisual:function(){var e=I.transform().scale(1/this._zoom),t=new M.Group({transform:e}),n=this.canvas.drawingElement.children[0];return t.children.push(n),t},_syncChanges:function(){this._syncShapeChanges(),this._syncConnectionChanges()},_syncShapeChanges:function(){this.dataSource&&this._isEditable&&this.dataSource.sync()},_syncConnectionChanges:function(){var t=this;t.connectionsDataSource&&t._isEditable&&(e.when.apply(e,t._deferredConnectionUpdates).then(function(){t.connectionsDataSource.sync()}),t.deferredConnectionUpdates=[])}}),A.ExportMixin.extend(b.fn,!0),kendo.PDFMixin&&kendo.PDFMixin.extend(b.fn),x=kendo.Observable.extend({init:function(e,t){kendo.Observable.fn.init.call(this),this.diagram=e,this.options=z({},this.options,t),this._tools=[],this.createToolBar(),this.createTools(),this.appendTools(),this.options.modal&&this.createPopup(),this.bind(this.events,t)},events:["click"],createPopup:function(){this.container=e("<div/>").append(this.element),this._popup=this.container.kendoPopup({}).getKendoPopup()},appendTools:function(){var e,t;for(e=0;this._tools.length>e;e++)t=this._tools[e],(t.buttons&&t.buttons.length||!ht(t.buttons))&&this._toolBar.add(t)},createToolBar:function(){this.element=e("<div/>"),this._toolBar=this.element.kendoToolBar({click:B(this.click,this),resizable:!1}).getKendoToolBar(),this.element.css("border","none")},createTools:function(){for(var e=0;this.options.tools.length>e;e++)this.createTool(this.options.tools[e])},createTool:function(e){var t=(mt(e)?e.name:e)+"Tool";this[t]?this[t](e):this._tools.push(e)},showAt:function(e){this._popup&&this._popup.open(e.x,e.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(e){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:e.step})})},rotateClockwiseTool:function(e){this._appendGroup("rotate"),this._rotateGroup.buttons.push({spriteCssClass:"k-icon k-i-rotatecw",attributes:this._setAttributes({action:"rotateClockwise",step:e.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(e){var t="_"+e+"Group";this[t]||(this[t]=this.newGroup(),this._tools.push(this[t]))},_setAttributes:function(e){var t={};return e.action&&(t[kendo.attr("action")]=e.action),e.step&&(t[kendo.attr("step")]=e.step),t},_getAttributes:function(e){var t,n={},i=e.attr(kendo.attr("action"));return i&&(n.action=i),t=e.attr(kendo.attr("step")),t&&(n.step=t),n},click:function(t){var n=this._getAttributes(e(t.target)),i=n.action;i&&this[i](n),this.trigger("click",this.eventData(i))},eventData:function(e){var t=this.selectedElements(),n=[],i=[];return t instanceof y?n.push(t):i.push(t),{shapes:n,connections:i,action:e}},"delete":function(){var e=this.diagram,t=e._triggerRemove(this.selectedElements());t.length&&(this.diagram.remove(t,!0),this.diagram._syncChanges())},edit:function(){this.diagram.edit(this.selectedElements()[0])},rotateClockwise:function(e){var t=(this.selectedElements(),parseFloat(e.step||90));this._rotate(t)},rotateAnticlockwise:function(e){var t=(this.selectedElements(),parseFloat(e.step||90));this._rotate(-t)},_rotate:function(e){var t=this.diagram._resizingAdorner;t.angle(t.angle()+e),t.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()}}),k=kendo.Observable.extend({init:function(e,t){kendo.Observable.fn.init.call(this),this.options=R(!0,{},this.options,t),this.element=e,this.model=this.options.model,this.fields=this._getFields(),this._initContainer(),this.createEditable()},options:{editors:{}},_initContainer:function(){this.wrapper=this.element},createEditable:function(){var e=this.options;this.editable=new kendo.ui.Editable(this.wrapper,{fields:this.fields,target:e.target,clearContainer:!1,model:this.model})
  },_isEditable:function(e){return this.model.editable&&this.model.editable(e)},_getFields:function(){var e,t,n,i=[],r=this.model.fields;for(e in r)t={},this._isEditable(e)&&(n=this.options.editors[e],n&&(t.editor=n),t.field=e,i.push(t));return i},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}}),C=k.extend({init:function(e,t){k.fn.init.call(this,e,t),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 t,n=this;this.wrapper=e('<div class="k-popup-edit-form"/>').attr(kendo.attr("uid"),this.model.uid),t="",this.options.template?(t+=this._renderTemplate(),this.fields=[]):t+=this._renderFields(),t+=this._renderButtons(),this.wrapper.append(e('<div class="k-edit-form-container"/>').append(t)),this.window=new kendo.ui.Window(this.wrapper,this.options.window),this.window.bind("close",function(e){e.userTriggered&&(e.sender.element.focus(),n._cancelClick(e))}),this._attachButtonEvents()},_renderTemplate:function(){var e=this.options.template;return"string"==typeof e&&(e=window.unescape(e)),e=kendo.template(e)(this.model)},_renderFields:function(){var e,t,n="";for(e=0;this.fields.length>e;e++)t=this.fields[e],n+='<div class="k-edit-label"><label for="'+t.field+'">'+(t.field||"")+"</label></div>",this._isEditable(t.field)&&(n+="<div "+kendo.attr("container-for")+'="'+t.field+'" class="k-edit-field"></div>');return n},_renderButtons:function(){var e='<div class="k-edit-buttons k-state-default">';return e+=this._createButton("update"),e+=this._createButton("cancel"),e+="</div>"},_createButton:function(e){return kendo.template(dn)(m[e])},_attachButtonEvents:function(){this._cancelClickHandler=B(this._cancelClick,this),this.window.element.on(xt+_t,"a.k-diagram-cancel",this._cancelClickHandler),this._updateClickHandler=B(this._updateClick,this),this.window.element.on(xt+_t,"a.k-diagram-update",this._updateClickHandler)},_updateClick:function(e){e.preventDefault(),this.trigger("update")},_cancelClick:function(e){e.preventDefault(),this.trigger("cancel")},open:function(){this.window.center().open()},close:function(){this.window.bind("deactivate",B(this.destroy,this)).close()},destroy:function(){this.window.close().destroy(),this.window.element.off(xt+_t,"a.k-diagram-cancel",this._cancelClickHandler),this.window.element.off(xt+_t,"a.k-diagram-update",this._updateClickHandler),this._cancelClickHandler=null,this._editUpdateClickHandler=null,this.window=null,k.fn.destroy.call(this)}}),d.fn=d.prototype={onActivate:function(t){var n=e.Deferred();return this.callbacks.push({callback:t,deferred:n}),n},activate:function(){var e,t,n=this.callbacks;for(t=0;n.length>t;t++)e=this.callbacks[t],e.callback(this.dataItem),e.deferred.resolve();this.callbacks=[]}},u.fn=u.prototype={add:function(e){for(var t=0;e.length>t;t++)this.items[e[t].uid]=new d(e[t])},forEach:function(e){for(var t in this.items)e(this.items[t])},getByUid:function(e){return this.items[e]},remove:function(e){delete this.items[e.uid]}},S=F.extend({init:function(){this.shapes=[]},_add:function(e,t){this.shapes.push({bounds:t,shape:e}),e._quadNode=this},insert:function(e,t){this._add(e,t)},remove:function(e){var t,n=this.shapes,i=n.length;for(t=0;i>t;t++)if(n[t].shape===e){n.splice(t,1);break}},hitTestRect:function(e,t){var n,i=this.shapes,r=i.length,o=!1;for(n=0;r>n;n++)if(this._overlaps(i[n].bounds,e)&&!A.inArray(i[n].shape,t)){o=!0;break}return o},_overlaps:function(e,t){var n=e.bottomRight(),i=t.bottomRight(),r=!(t.x>n.x||t.y>n.y||e.x>i.x||e.y>i.y);return r}}),T=S.extend({init:function(e){S.fn.init.call(this),this.children=[],this.rect=e},inBounds:function(e){var t=this.rect,n=t.bottomRight(),i=e.bottomRight(),r=e.x>=t.x&&e.y>=t.y&&n.x>=i.x&&n.y>=i.y;return r},overlapsBounds:function(e){return this._overlaps(this.rect,e)},insert:function(e,t){var n,i=!1,r=this.children,o=r.length;if(this.inBounds(t)){if(!o&&4>this.shapes.length)this._add(e,t);else{for(o||this._initChildren(),n=0;r.length>n;n++)if(r[n].insert(e,t)){i=!0;break}i||this._add(e,t)}i=!0}return i},_initChildren:function(){var e,t,n=this.rect,i=this.children,r=this.shapes,o=n.center(),a=n.width/2,s=n.height/2;for(i.push(new T(new W(n.x,n.y,a,s)),new T(new W(o.x,n.y,a,s)),new T(new W(n.x,o.y,a,s)),new T(new W(o.x,o.y,a,s))),t=r.length-1;t>=0;t--)for(e=0;i.length>e;e++)if(i[e].insert(r[t].shape,r[t].bounds)){r.splice(t,1);break}},hitTestRect:function(e,t){var n,i=this.children,r=i.length,o=!1;if(this.overlapsBounds(e))if(S.fn.hitTestRect.call(this,e,t))o=!0;else for(n=0;r>n;n++)if(i[n].hitTestRect(e,t)){o=!0;break}return o}}),D=F.extend({ROOT_SIZE:1e3,init:function(e){e.bind(wt,B(this._boundsChange,this)),e.bind(Rt,B(this._boundsChange,this)),this.initRoots()},initRoots:function(){this.rootMap={},this.root=new S},clear:function(){this.initRoots()},_boundsChange:function(e){e.item._quadNode&&(e.item._quadNode.remove(e.item),this.insert(e.item))},insert:function(e){var t=e.bounds(en),n=this.ROOT_SIZE,i=this.getSectors(t),r=i[0][0],o=i[1][0];this.inRoot(i)?this.root.insert(e,t):(this.rootMap[r]||(this.rootMap[r]={}),this.rootMap[r][o]||(this.rootMap[r][o]=new T(new W(r*n,o*n,n,n))),this.rootMap[r][o].insert(e,t))},remove:function(e){e._quadNode&&e._quadNode.remove(e)},inRoot:function(e){return e[0].length>1||e[1].length>1},getSectors:function(e){var t=this.ROOT_SIZE,n=e.bottomRight(),i=Math.floor(e.x/t),r=Math.floor(e.y/t),o=Math.floor(n.x/t),a=Math.floor(n.y/t),s=[[i],[r]];return i!==o&&s[0].push(o),r!==a&&s[1].push(a),s},hitTestRect:function(e,t){var n,i,r,o,a,s=this.getSectors(e);if(this.root.hitTestRect(e,t))return!0;for(n=0;s[0].length>n;n++)for(r=s[0][n],i=0;s[1].length>i;i++)if(o=s[1][i],a=(this.rootMap[r]||{})[o],a&&a.hitTestRect(e,t))return!0;return!1}}),A.ui.plugin(b),z(P,{Shape:y,Connection:w,Connector:_,DiagramToolBar:x,QuadNode:T,QuadRoot:S,ShapesQuadTree:D})}(window.kendo.jQuery),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()});