15 lines
197 KiB
JavaScript
15 lines
197 KiB
JavaScript
/*
|
|
* Kendo UI v2015.3.1111 (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(){!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&&d.sign(n-e)!=d.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,u=1e-6,d={};l(d,{isNearZero:function(e){return Math.abs(e)<u},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)||d.isString(e))return 0===e.length;for(var t in e)if(d.has(e,t))return!1;return!0},simpleExtend:function(e,t){if(d.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]}}),d.sign=function(e){return e?0>e?-1:1:0},d.findAngle=function(e,t){return 180*i(e,t)/Math.PI},d.forEach=function(e,t,n){for(var i=0;e.length>i;i++)t.call(n,e[i],i,e)},d.any=function(e,t){for(var n=0;e.length>n;++n)if(t(e[n]))return e[n];return null},d.remove=function(e,t){for(var n;-1!==(n=d.indexOf(e,t));)e.splice(n,1);return e},d.contains=function(e,t){return-1!==d.indexOf(e,t)},d.indexOf=function(t,n){return e.inArray(n,t)},d.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},d.find=function(e,t,n){var i;return d.any(e,function(e,r,o){return t.call(n,e,r,o)?(i=e,!0):!1}),i},d.first=function(e,t,n){return 0===e.length?null:d.isUndefined(t)?e[0]:d.find(e,t,n)},d.insert=function(e,t,n){return e.splice(n,0,t),e},d.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},d.clear=function(e){e.splice(0,e.length)},d.bisort=function(e,t,n){if(d.isUndefined(e))throw"First array is not specified.";if(d.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(d.isUndefined(n)?function(e,t){return e.x-t.x}:function(e,t){return n(e.x,t.x)}),d.clear(e),d.clear(t),i=0;r.length>i;i++)e.push(r[i].x),t.push(r[i].y)},d.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&&d.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:d,Range:n,Ticker:o})}(window.kendo.jQuery)}(),function(){!function(e,t){function n(e){return Math.abs(e)<P}function i(e,t,i,r,o){var a,s,l,c,u=(t.x-e.x)*(r.y-i.y)-(t.y-e.y)*(r.x-i.x);if(!n(u)&&(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/u,c=s/u,!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,u,d,h,f,p,g,m,v,_,b,y,w,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,E=D.contains,I=e.map,R=3,P=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 d(0,0);if(this.y>0)return new d(i,r*n);if(0>this.y)return new d(i,3*r*n)}else if(this.x>0){if(0===this.y)return new d(i,0);if(this.y>0)return new d(i,r*t);if(0>this.y)return new d(i,r*(4*n-t))}else{if(0===this.y)return new d(i,2*n);if(this.y>0)return new d(i,r*(2*n-t));if(0>this.y)return new d(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(R,R),r=new s(t.x,t.y).inflate(R,R),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},overlaps:function(e){var t=this.bottomRight(),n=e.bottomRight(),i=!(e.x>t.x||e.y>t.y||this.x>n.x||this.y>n.y);return i}}),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(),u=t.center();return n&&(o=o.rotate(u,n),a=a.rotate(u,n),s=s.rotate(u,n),l=l.rotate(u,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(u,r),a=a.rotate(u,r),s=s.rotate(u,r),l=l.rotate(u,r)),i=t.contains(o)||t.contains(a)||t.contains(s)||t.contains(l)),i}},u=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}}),d=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(I(t,function(e){return parseFloat(e)}));if(t=n.split(" "),6===t.length)return h.fromList(I(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(I(t,function(e){return parseFloat(e)}));if(e.indexOf(" ")>0&&(t=e.split(" "),6===t.length))return h.fromList(I(t,function(e){return parseFloat(e)}))}return t}}),f=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 f;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}}),p={_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}}),b=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 b;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 E(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}}),y=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 b(e):e,a=D.isString(t)?new b(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 E(this.source.links,e)||E(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 y(this.source,this.target);return e}}),w=x.Class.extend({init:function(e){this.links=[],this.nodes=[],this._nodeMap=new m,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 w;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,u,d,h,f=new w,p=new m;for(f.root=e.clone(),f.root.level=0,f.root.id=e.id,p.add(e,f.root),e.level=0,i=[],r=[],f._addNode(f.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),E(i,c)||(c.level=a.level+1,c.level+1>o&&(o=c.level+1),E(r,c)||r.push(c),E(i,c)||i.push(c),p.containsKey(a)?t=p.get(a):(t=a.clone(),t.level=a.level,t.id=a.id,p.add(a,t)),p.containsKey(c)?n=p.get(c):(n=c.clone(),n.level=c.level,n.id=c.id,p.add(c,n)),u=new y(t,n),f.addLink(u));for(d=[],h=0;o>h;h++)d.push([]);return D.forEach(f.nodes,function(e){d[e.level].push(e)}),f.treeLevels=d,f.cacheRelationships(),f},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 E(t,this.nodes[0])?null:this.nodes[0];var i=e.grep(this.nodes,function(e){return!E(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 E(this.nodes,e.source)&&E(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 y(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 E(this.links,e);throw"The given object is neither an identifier nor a Link."},getNode:function(e){var n=e.id||e;return this._nodeMap.containsKey(n)?this._nodeMap.get(n):t},hasNode:function(e){var t=e.id||e;return this._nodeMap.containsKey(t)},_addNode:function(e){this.nodes.push(e),this._nodeMap.add(e.id,e)},_removeNode:function(e){D.remove(this.nodes,e),this._nodeMap.remove(e.id)},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);this._removeNode(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 b(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._addNode(i),i},addNodeAndOutgoings:function(e){this.hasNode(e)||this._addNode(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 w,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._addNode(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 w.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],E(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],E(r,c)||E(i,c)||i.enqueue(c)},_stronglyConnectedComponents:function(e,t,n,i,r,o,a){var s,l,c,u,d;for(n.add(t,a),i.add(t,a),a++,o.push(t),s=t.getChildren(),c=0,u=s.length;u>c;c++)l=s[c],n.containsKey(l)?E(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)){d=[];do l=o.pop(),d.push(l);while(l!==t);(!e||d.length>1)&&r.push(d)}},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 E(n,e)})},makeAcyclic:function(){var e,t,n,i,r,o,a,s,l,c,u,d,h,f,p,g,v,_,b,y,w,x,k,C,S,T,A,M,E,I,R,P;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,u=function(e){return 0===e.outgoing.length?2-l:0===e.incoming.length?l-2:e.outgoing.length-e.incoming.length},d=function(e,t){var n=u(e,l);t.containsKey(n)||t.set(n,[]),t.get(n).push(e)},D.forEach(s.nodes,function(e){
|
|
d(e,c)}),h=[],f=[];s.nodes.length>0;){if(c.containsKey(2-l))for(_=c.get(2-l);_.length>0;){for(g=_.pop(),b=0;g.links.length>b;b++)y=g.links[b],p=y.getComplement(g),v=u(p,l),D.remove(c.get(v),p),p.removeLink(y),d(p,c);s._removeNode(g),f.unshift(g)}if(c.containsKey(l-2))for(w=c.get(l-2);w.length>0;){for(p=w.pop(),x=0;p.links.length>x;x++)k=p.links[x],g=k.getComplement(p),v=u(g,l),D.remove(c.get(v),g),g.removeLink(k),d(g,c);h.push(p),s._removeNode(p)}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],E=M.getComplement(T),v=u(E,l),D.remove(c.get(v),E),E.removeLink(M),d(E,c);h.push(T),s._removeNode(T);break}}for(h=h.concat(f),I=new m,R=0;this.nodes.length>R;R++)I.set(s.nodeMap.get(h[R]),R);return P=[],D.forEach(this.links,function(e){I.get(e.source)>I.get(e.target)&&(e.reverse(),P.push(e))}),P}}),w.Predefined={EightGraph:function(){return w.Utils.parse(["1->2","2->3","3->4","4->1","3->5","5->6","6->7","7->3"])},Mindmap:function(){return w.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 w.Utils.parse(["1->2","2->3","3->1"])},BinaryTree:function(e){return D.isUndefined(e)&&(e=5),w.Utils.createBalancedTree(e,2)},Linear:function(e){return D.isUndefined(e)&&(e=10),w.Utils.createBalancedTree(e,1)},Tree:function(e,t){return w.Utils.createBalancedTree(e,t)},Forest:function(e,t,n){return w.Utils.createBalancedForest(e,t,n)},Workflow:function(){return w.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 b(""+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}},w.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 y(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,u,d,h,f,p,g,m,v,_,b,y;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=[],u=0,d=t.nodes.length;d>u;u++)l=t.nodes[u],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))),f={},"0"===l.id||i&&x.deepExtend(f,{width:150*Math.random()+20,height:80*Math.random()+50,data:"rectangle",fill:{color:"#778899"}}),c=this._addShape(e,h,l.id,f),p=c.bounds(),D.isDefined(p)&&(l.x=p.x,l.y=p.y,l.width=p.width,l.height=p.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(b=new e.SpringLayout(e),b.layoutGraph(t,{limitToView:!1}),y=0;t.nodes.length>y;y++)l=t.nodes[y],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,u,d;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 b(""+ ++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],u=0;t>u;u++)d=new b(""+ ++i),n.addLink(c,d),o.push(d);r=o}return n},createBalancedForest:function(e,t,n){var i,r,o,a,s,l,c,u,d,h,f;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 b(""+ ++r),i.addNode(l),o=[l],c=0;e>c;c++){for(a=[],u=0;o.length>u;u++)for(d=o[u],h=0;t>h;h++)f=new b(""+ ++r),i.addLink(d,f),a.push(f);o=a}return i},createRandomConnectedGraph:function(e,t,n){var i,r,o,a,s,l,c,u,d,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 b(""+ ++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),u=0;c>u;u++)d=i.takeRandomNode([],t),h=i.takeRandomNode([],t),d&&h&&!i.areConnected(d,h)&&i.addLink(d,h);return i}},randomDiagram:function(e,t,n,i,r){var o=x.dataviz.diagram.Graph.Utils.createRandomConnectedGraph(t,n,i);w.Utils.createDiagramFromGraph(e,o,!1,r)}},x.deepExtend(k,{init:function(e){x.init(e,k.ui)},Point:A,Intersect:c,Geometry:p,Rect:s,Size:l,RectAlign:u,Matrix:h,MatrixVector:f,normalVariable:r,randomId:o,Dictionary:m,HashTable:g,Queue:v,Set:_,Node:b,Link:y,Graph:w,PathDefiner:a})}(window.kendo.jQuery)}(),function(){!function(e,t){function n(e,t){var n,i,r,o=this.options,a=!1;for(r=0;t.length>r;r++)i=t[r],n=e[i],H(n)&&o[i]!==n&&(o[i]=n,a=!0);return a}function i(e){return{x:e.x||0,y:e.y||0,width:e.width||0,height:e.height||0}}function r(e){if(e){var t=e;return N(t)&&(t={color:t}),t.color&&(t.color=o(t.color)),t}}function o(e){var t;return t=e!=q?new U.Color(e).toHex():e}function a(e,t){var n=t.x-e.x,i=t.y-e.y,r=E.util.deg(Math.atan2(i,n));return r}function s(e,t){return new U.Segment(new V.Point(e,t))}function l(e){return e?new V.Rect([e.x,e.y],[e.width,e.height]):t}var c,u,d,h,f,p,g,m,v,_,b,y,w,x,k,C,S,T,D,A,M,E=window.kendo,I=E.dataviz.diagram,R=E.Class,P=E.deepExtend,F=I.Point,B=I.Rect,z=I.Matrix,L=I.Utils,H=L.isNumber,N=L.isString,O=I.MatrixVector,V=E.geometry,U=E.drawing,W=E.util.defined,j=e.inArray,q="transparent",G={none:"none",arrowStart:"ArrowStart",filledCircle:"FilledCircle",arrowEnd:"ArrowEnd"},$=360,Y="start",K="end",Q="width",X="height",J="x",Z="y";I.Markers=G,c=R.extend({init:function(e,t){this.x=e,this.y=t},toMatrix:function(){return z.scaling(this.x,this.y)},toString:function(){return E.format("scale({0},{1})",this.x,this.y)},invert:function(){return new c(1/this.x,1/this.y)}}),u=R.extend({init:function(e,t){this.x=e,this.y=t},toMatrixVector:function(){return new O(0,0,0,0,this.x,this.y)},toMatrix:function(){return z.translation(this.x,this.y)},toString:function(){return E.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 u(-this.x,-this.y)}}),d=R.extend({init:function(e,t,n){this.x=t||0,this.y=n||0,this.angle=e},toString:function(){return this.x&&this.y?E.format("rotate({0},{1},{2})",this.angle,this.x,this.y):E.format("rotate({0})",this.angle)},toMatrix:function(){return z.rotation(this.angle,this.x,this.y)},center:function(){return new F(this.x,this.y)},invert:function(){return new d($-this.angle,this.x,this.y)}}),d.ZERO=new d(0),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},h=R.extend({init:function(e,n,i,r,o,a){this.translate=new u(e,n),i!==t&&r!==t&&(this.scale=new c(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=z.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():z.unit(),o=this.scale?this.scale.invert():t,a=o?o.toMatrix():z.unit(),s=new F(-this.translate.x,-this.translate.y);return s=r.times(a).apply(s),e=new u(s.x,s.y),n=new h,n.translate=e,n.rotate=i,n.scale=o,n}}),f={_setScale:function(){var e=this.options,t=this._originWidth,n=this._originHeight,i=e.width/t,r=e.height/n;H(i)||(i=1),H(r)||(r=1),this._transform.scale=new c(i,r)},_setTranslate:function(){var e=this.options,t=e.x||0,n=e.y||0;this._transform.translate=new u(t,n)},_initSize:function(){var e=this.options,t=!1;e.autoSize!==!1&&(W(e.width)||W(e.height))&&(this._measure(!0),this._setScale(),t=!0),(W(e.x)||W(e.y))&&(this._setTranslate(),t=!0),t&&this._renderTransform()},_updateSize:function(e){var t=!1;return this.options.autoSize!==!1&&this._diffNumericOptions(e,[Q,X])&&(t=!0,this._measure(!0),this._setScale()),this._diffNumericOptions(e,[J,Z])&&(t=!0,this._setTranslate()),t&&this._renderTransform(),t}},p=R.extend({init:function(e){var t=this;t.options=P({},t.options,e),t.id=t.options.id,t._originSize=B.empty(),t._transform=new h},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 W(e)?(W(n)?(i.x=e,i.y=n):e instanceof F&&(i.x=e.x,i.y=e.y),this._transform.translate=new u(i.x,i.y),this._renderTransform(),t):new F(i.x,i.y)},rotate:function(e,t){return W(e)&&(this._transform.rotate=new d(e,t.x,t.y),this._renderTransform()),this._transform.rotate||d.ZERO},drawingContainer:function(){return this.drawingElement},_renderTransform:function(){var e=this._transform.toMatrix();this.drawingContainer().transform(new V.Matrix(e.a,e.b,e.c,e.d,e.e,e.f))},_hover:function(){},_diffNumericOptions:n,_measure:function(e){var t,n,i;return!this._measured||e?(n=this._boundingBox()||new V.Rect,i=n.topLeft(),t=new B(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()}}),g=p.extend({init:function(e){p.fn.init.call(this,e),e=this.options,e.fill=r(e.fill),e.stroke=r(e.stroke)},options:{stroke:{color:"gray",width:1},fill:{color:q}},fill:function(e,t){this._fill({color:o(e),opacity:t})},stroke:function(e,t,n){this._stroke({color:o(e),width:t,opacity:n})},redraw:function(e){var t,n;e&&(t=e.stroke,n=e.fill,t&&this._stroke(r(t)),n&&this._fill(r(n)),p.fn.redraw.call(this,e))},_hover:function(e){var t,n=this.drawingElement,i=this.options,o=i.hover;o&&o.fill&&(t=e?r(o.fill):i.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?U.RadialGradient:U.LinearGradient,this.drawingElement.fill(new i(n))):this.drawingElement.fill(t.color,t.opacity)}}),m=g.extend({init:function(e){this._textColor(e),g.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 U.Text(W(e.text)?e.text:"",new V.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&&W(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),g.fn.redraw.call(this,e),(e.fontFamily||W(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(m.fn,f),v=g.extend({init:function(e){g.fn.init.call(this,e),this._initPath(),this._setPosition()},_setPosition:function(){var e=this.options,t=e.x,n=e.y;(W(t)||W(n))&&this.position(t||0,n||0)},redraw:function(e){e&&(g.fn.redraw.call(this,e),this._diffNumericOptions(e,[Q,X])&&this._drawPath(),this._diffNumericOptions(e,[J,Z])&&this._setPosition())},_initPath:function(){var e=this.options;this.drawingElement=new U.Path({stroke:e.stroke,closed:!0}),this._fill(),this._drawPath()},_drawPath:function(){var e=this.drawingElement,t=i(this.options),n=t.width,r=t.height;e.segments.elements([s(0,0),s(n,0),s(n,r),s(0,r)])}}),_=g.extend({init:function(e){g.fn.init.call(this,e);var t=this.options.anchor;this.anchor=new V.Point(t.x,t.y),this.createElement()},options:{stroke:{color:q,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),g.fn.redraw.call(this,e))}}),b=_.extend({options:{radius:4,anchor:{x:0,y:0}},createElement:function(){var e=this.options;this.drawingElement=new U.Circle(new V.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==Y?o[0]:o[o.length-1],t&&(n=this._transformToPath(t.anchor(),e),this.drawingElement.transform(V.transform().translate(n.x,n.y)))}}),y=_.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=U.Path.parse(e.path,{fill:e.fill,stroke:e.stroke})},positionMarker:function(e){var t,n,i=this._linePoints(e),r=i.start,o=i.end,s=V.transform();r&&s.rotate(a(r,o),o),o&&(t=this.anchor,n=o.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==Y?(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 U.MultiPath&&(n=e==Y?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;N(t)&&(e.startCap={type:t}),N(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[Y]=this._createMarker(e.startCap,Y),this._markers[K]=this._createMarker(e.endCap,K)},_createMarker:function(e,n){var i,r,o=(e||{}).type,a=this._getPath(n);return a?(o==G.filledCircle?i=b:o==G.arrowStart||o==G.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,Y,t)&&e&&this._positionMarker(Y),!this._redrawMarker(e,K,t)&&e&&this._positionMarker(K)}},x=g.extend({init:function(e){g.fn.init.call(this,e),this.container=new U.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&&(g.fn.redraw.call(this,e),t=this.options,n=e.data,W(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=U.Path.parse(e.data||"",{stroke:e.stroke}),this._fill(),this.container.append(this.drawingElement),this._createMarkers()},_setData:function(e){var t=this.drawingElement,n=U.Path.parse(e||""),i=n.paths.slice(0);n.paths.elements([]),t.paths.elements(i)}}),P(x.fn,f),P(x.fn,w),k=g.extend({init:function(e){g.fn.init.call(this,e),this.container=new U.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),g.fn.redraw.call(this,e))},_initPath:function(){var e=this.options,t=this.drawingElement=new U.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 F,i=e.to||new F;t.segments.elements([s(n.x,n.y),s(i.x,i.y)])}}),P(k.fn,w),C=g.extend({init:function(e){g.fn.init.call(this,e),this.container=new U.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;g.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 U.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(C.fn,w),S=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,[Q,X,J,Z])&&this.drawingElement.rect(this._rect()),p.fn.redraw.call(this,e))},_initImage:function(){var e=this.options,t=this._rect();this.drawingElement=new U.Image(e.source,t,{})},_rect:function(){var e=i(this.options),t=new V.Point(e.x,e.y),n=new V.Size(e.width,e.height);return new V.Rect(t,n)}}),T=p.extend({init:function(e){this.children=[],p.fn.init.call(this,e),this.drawingElement=new U.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=j(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,u=H(t);for(n=0;e.length>n;n++)a=e[n],o=a.drawingContainer(),i=j(a,c),i>=0&&(l.splice(i,1),c.splice(i,1),r=u?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?B.union(e,n):n));return e}}),P(T.fn,f),D=T.extend({init:function(e,t){this.children=[],p.fn.init.call(this,t),this.drawingElement=new U.Layout(l(e),t),this._initSize()},rect:function(e){if(e)this.drawingElement.rect(l(e));else{var t=this.drawingElement.rect();if(t)return new B(t.origin.x,t.origin.y,t.size.width,t.size.height)}},reflow:function(){this.drawingElement.reflow()},redraw:function(e){E.deepExtend(this.drawingElement.options,e),T.fn.redraw.call(this,e)}}),A=g.extend({init:function(e){g.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),g.fn.redraw.call(this,e)}},_initCircle:function(){var e,t=this.options,n=t.width,i=t.height,r=t.radius;W(r)||(W(n)||(n=i),W(i)||(i=n),t.radius=r=Math.min(n,i)/2),e=t.center||{x:r,y:r},this._center=new V.Point(e.x,e.y),this._circle=new V.Circle(this._center,r),this.drawingElement=new U.Circle(this._circle,{stroke:t.stroke}),this._fill()}}),P(A.fn,f),M=R.extend({init:function(e,t){t=t||{},this.element=e,this.surface=U.Surface.create(e,t),E.isFunction(this.surface.translate)&&(this.translate=this._translate),this.drawingElement=new U.Group,this._viewBox=new B(0,0,t.width,t.height),this.size(this._viewBox)},bounds:function(){var e=this.drawingElement.clippedBBox();return new B(0,0,e.width(),e.height())},size:function(e){var t=this._viewBox;return W(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 W(e)&&W(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()}}),E.deepExtend(I,{init:function(e){E.init(e,I.ui)},diffNumericOptions:n,Element:p,Scale:c,Translation:u,Rotation:d,Circle:A,Group:T,Rectangle:v,Canvas:M,Path:x,Layout:D,Line:k,MarkerBase:_,ArrowMarker:y,CircleMarker:b,Polyline:C,CompositeTransform:h,TextBlock:m,Image:S,VisualBase:g})}(window.kendo.jQuery)}(),function(){!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 G(i.x,i.y),r.inflate(ae,ae),r.contains(t))return n}var c,u,d,h,f,p,g,m,v,_,b,y,w,x,k,C,S,T,D,A,M,E,I,R,P,F,B,z,L,H,N,O,V=window.kendo,U=V.dataviz,W=U.diagram,j=V.Class,q=W.Group,G=W.Rect,$=W.Rectangle,Y=W.Utils,K=Y.isUndefined,Q=W.Point,X=W.Circle,J=W.Ticker,Z=V.deepExtend,ee=V.ui.Movable,te=V.support.browser,ne=V.util.defined,ie=e.inArray,re=e.proxy,oe={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"},ae=10,se="Auto",le="Top",ce="Right",ue="Left",de="Bottom",he=10,fe=10,pe="dragStart",ge="drag",me="dragEnd",ve="itemRotate",_e="itemBoundsChange",be=5,ye=5,we="mouseEnter",xe="mouseLeave",ke="zoomStart",Ce="zoomEnd",Se=-2e4,Te=2e4,De=.9,Ae=.93,Me=5,Ee="transparent",Ie="pan",Re="rotated";W.Cursors=oe,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))}}),u=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 J,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)}))}}),d=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,ne(t)&&(this._undoSource=e.source()),ne(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()}}),f=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()}}),p=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)}}),b=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)}}),y=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())}}),w=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 d},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 oe.arrow}}),S=C.extend({init:function(t){var n,i,r,o,a=this,s=V.support.mobileOS?Ae:De;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:Me,mousewheelScrolling:!1,zoom:!1,scroll:re(a._move,a)}).data("kendoMobileScroller"),i.translate&&(a.movableCanvas=new ee(i.element)),o=function(e,t,n){e.makeVirtual(),e.virtualSize(t||Se,n||Te)},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 ne(r.key)&&(o=r.key&&"none"!=r.key?t[r.key+"Key"]&&!(t.ctrlKey&&ne(n.hoveredItem)):i(t)),
|
|
r!==!1&&o&&!ne(n.hoveredAdorner)&&!ne(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(Ie,{pan:r})},end:function(){this.scroller.disable()},getCursor:function(){return oe.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(pe,{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(ge,{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(me,{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):oe.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&&!ne(n.hoveredItem)&&!ne(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 oe.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(pe,{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(ge,{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(se)||o.getConnector(e):e,r.target(t),i.trigger(me,{shapes:[],connections:[r]})?(i.remove(r,!1),i.undoRedoService.pop()):(r.updateModel(),i._syncConnectionChanges()),n._connectionManipulation())},getCursor:function(){return oe.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(pe,{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(ge,{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(me,{shapes:[],connections:[i]})?n.undo():(a.undoRedoService.add(n,!1),i.updateModel(),a._syncConnectionChanges())))},getCursor:function(){return oe.move}}),E=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=Z({},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=Z({},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=Z({},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=Z({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(ke,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(Ce,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):oe.arrow;t.css({cursor:n}),te.msie&&7==te.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(xe,{item:this.hoveredItem}),this.hoveredItem._hover(!1)),n&&n.options.enable?(i.trigger(we,{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=ie(a.visual,n.children),r=ie(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}}),I=V.Class.extend({init:function(){}}),R=I.extend({init:function(e){var t=this;I.fn.init.call(t),this.connection=e},hitTest:function(e){var t=this.getBounds().inflate(ae);return t.contains(e)?W.Geometry.distanceToPolyline(e,this.connection.allPoints())<ae:!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 G(o,a,r-o,s-a)}}),P=R.extend({init:function(e){var t=this;R.fn.init.call(t),this.connection=e},route:function(){}}),F=R.extend({SAME_SIDE_DISTANCE_RATIO:5,init:function(e){var t=this;R.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(Re),c={topLeft:l.topLeft(),bottomRight:l.bottomRight()},u=this._connectorSides,d=V.util.MAX_NUM;for(a=0;u.length>a;a++)o=u[a],r=o.axis,n=Math.round(Math.abs(s[r]-c[o.boundsPoint][r])),d>n?(d=n,i=o):n===d&&(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(Re);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,u=this._sameSideDistance(n),d=[];return a===le||a==de?s==le||s==de?a==s?(o=a==le?Math.min(e.y,t.y)-u:Math.max(e.y,t.y)+u,d=[new Q(e.x,o),new Q(t.x,o)]):d=[new Q(e.x,e.y+c/2),new Q(t.x,e.y+c/2)]:d=[new Q(e.x,t.y)]:s==ue||s==ce?a==s?(r=a==ue?Math.min(e.x,t.x)-u:Math.max(e.x,t.x)+u,d=[new Q(r,e.y),new Q(r,t.y)]):d=[new Q(e.x+l/2,e.y),new Q(e.x+l/2,e.y+c)]:d=[new Q(t.x,e.y)],d},_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,u=t.y-e.y,d=l.length;for(o=1;d-1>o;++o)s?o%2!==0?(i=c/(d/2),r=0):(i=0,r=u/((d-1)/2)):o%2!==0?(i=0,r=u/(d/2)):(i=c/((d-1)/2),r=0),l[o]=new Q(l[o-1].x+i,l[o-1].y+r);return o--,l[d-2]=s&&o%2!==0||!s&&o%2===0?new Q(l[d-1].x,l[d-2].y):new Q(l[d-2].x,l[d-1].y),[l[1],l[2]]},_startHorizontal:function(e,t,n){var i;return i=null===n||n!==ce&&n!==ue?Math.abs(e.x-t.x)>Math.abs(e.y-t.y):!0}}),B=j.extend({init:function(e,t){var n=this;n.diagram=e,n.options=Z({},n.options,t),n.visual=new q,n.diagram._adorners.push(n)},refresh:function(){}}),z=B.extend({init:function(e,t){var n,i,r,o=this;o.connection=e,n=o.connection.diagram,o._ts=n.toolService,B.fn.init.call(o,n,t),i=o.connection.sourcePoint(),r=o.connection.targetPoint(),o.spVisual=new X(Z(o.options.handles,{center:i})),o.epVisual=new X(Z(o.options.handles,{center:r})),o.visual.append(o.spVisual),o.visual.append(o.epVisual)},options:{handles:{}},_getCursor:function(){return oe.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(se)||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 f(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 G(t.x,t.y).inflate(i,r),a=new G(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=B.extend({init:function(e,t){var n=this;B.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(_e,r._refreshHandler),t=e.connectors.length,r.connectors=[],r.visual.clear(),n=0;t>n;n++)i=new O(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(_e,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=B.extend({init:function(e,t){var n=this;B.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(_e,n._refreshHandler).bind(ve,n._rotatedHandler),n.refreshBounds(),n.refresh()},options:{handles:{fill:{color:"#fff"},stroke:{color:"#282828"},height:7,width:7,hover:{fill:{color:"#282828"},stroke:{color:"#282828"}}},selectable:{stroke:{color:"#778899",width:1,dashType:"dash"},fill:{color:Ee}},offset:10},_initSelection:function(){var e=this,t=e.diagram,n=t.options.selectable,i=Z({},e.options.selectable,n);e.rect=new $(i),e.visual.append(e.rect)},_resizable:function(){return this.options.editable&&this.options.editable.resize!==!1},_handleOptions:function(){return(this.options.editable.resize||{}).handles||this.options.handles},_createHandles:function(){var e,t,n,i;if(this._resizable())for(e=this._handleOptions(),i=-1;1>=i;i++)for(n=-1;1>=n;n++)(0!==i||0!==n)&&(t=new $(e),t.drawingElement._hover=re(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.map.length;if(this._angle&&(a=a.clone().rotate(this._bounds.center(),this._angle)),this._resizable())for(n=0;s>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){if(this._resizable()){var t=this._handleOptions(),n=t.width,i=t.height,r=new G(0,0,n,i);return 0>e.x?r.x=-n/2:0===e.x?r.x=Math.floor(this._bounds.width/2)-n/2:e.x>0&&(r.x=this._bounds.width+1-n/2),0>e.y?r.y=-i/2:0===e.y?r.y=Math.floor(this._bounds.height/2)-i/2:e.y>0&&(r.y=this._bounds.height+1-i/2),r}},_getCursor:function(e){var t,n=this._hitTest(e);if(n&&n.x>=-1&&1>=n.x&&n.y>=-1&&1>=n.y&&this._resizable()){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?oe.move:oe.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){if(this._resizable()){var n=this._handleOptions(),i=n.hover,r=n.stroke,o=n.fill;e&&Y.isDefined(i.stroke)&&(r=Z({},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._resizable();for(e=0;this.map.length>e;e++)t=this.map[e],t.visual.visible(n)},angle:function(e){return ne(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,u,d,h,f,p,g,m,v,_,b=new Q,y=new Q,w=0;if(-2===e.y&&-1===e.x){for(l=this._innerBounds.center(),this._angle=this._truncateAngle(Y.findAngle(l,n)),u=0;this.shapes.length>u;u++)c=this.shapes[u],d=(this._angle+this.initialRotates[u]-this._startAngle)%360,c.rotate(d,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)?(y=b=i,r=!0):(this._angle&&i.rotate(new Q(0,0),this._angle),-1==e.x?b.x=i.x:1==e.x&&(y.x=i.x),-1==e.y?b.y=i.y:1==e.y&&(y.y=i.y)),r||(f=a(e,this._innerBounds),p=(this._innerBounds.width+i.x*e.x)/this._innerBounds.width,g=(this._innerBounds.height+i.y*e.y)/this._innerBounds.height),u=0;this.shapes.length>u;u++){if(c=this.shapes[u],o=c.bounds(),r){if(!s(c))continue;h=this._displaceBounds(o,b,y,r)}else h=o.clone(),h.scale(p,g,f,this._innerBounds.center(),c.rotate().angle),v=h.center(),v.rotate(o.center(),-this._angle),h=new G(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),w+=1)}w&&(w==u?(h=this._displaceBounds(this._innerBounds,b,y,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||fe,ye);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||he,be),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=G.fromPoints(o,a);return i||(r=s.center(),r.rotate(e.center(),-this._angle),s=new G(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 y(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 G(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)}}),N=j.extend({init:function(e){var t=e.options.selectable;this.options=Z({},this.options,t),this.visual=new $(this.options),this.diagram=e},options:{stroke:{color:"#778899",width:1,dashType:"dash"},fill:{color:Ee}},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=G.fromPoints(this.diagram.modelToLayer(this._sp),this.diagram.modelToLayer(this._ep));this.bounds(G.fromPoints(this._sp,this._ep)),this.visual.position(e.topLeft()),this.visual.redraw({height:e.height+1,width:e.width+1})}}}),O=j.extend({init:function(e){this.options=Z({},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=Z({},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 G(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)}}),Z(W,{CompositeUnit:d,TransformUnit:m,PanUndoUnit:b,AddShapeUnit:_,AddConnectionUnit:v,DeleteShapeUnit:g,DeleteConnectionUnit:p,ConnectionEditAdorner:z,ConnectionTool:A,ConnectorVisual:O,UndoRedoService:k,ResizingAdorner:H,Selector:N,ToolService:E,ConnectorsAdorner:L,LayoutUndoUnit:u,ConnectionEditUnit:h,ToFrontUnit:w,ToBackUnit:x,ConnectionRouterBase:I,PolylineRouter:P,CascadingRouter:F,SelectionTool:D,ScrollerTool:S,PointerTool:T,ConnectionEditTool:M,RotateUnit:y})}(window.kendo.jQuery)}(),function(){!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,u=n.Set,d=n.Graph,h=n.Utils,f=n.Point,p=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,u,d,p,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,u=[],d=[];e.length>0;){for(s>=t&&(s=o,l+=r+i,r=0),p=e.pop(),this.moveToOffset(p,new f(s,l)),c=0;p.nodes.length>c;c++)d.push(p.nodes[c]);for(c=0;p.links.length>c;c++)u.push(p.links[c]);g=p.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:d,links:u}},moveToOffset:function(e,t){var n,i,r,o,a,s,c,u,d=e.bounds,h=t.x-d.x,p=t.y-d.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+=p,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++)u=c[i],u.x+=h,u.y+=p,s.push(u);a.points=s}return this.currentHorizontalOffset+=d.width+this.options.grid.offsetX,new f(h,p)},transferOptions:function(e){this.options=t.deepExtend({},this.defaultOptions),h.isUndefined(e)||(this.options=t.deepExtend(this.options,e||{}))}}),b=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.get(e.id)},mapShape:function(e){return this.nodeMap.get(e.id)},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 d: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(n.id,i),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(n.id,l),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})}}),y=_.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 b(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})}}),w=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 f(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 f(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 f(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 f(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 f(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 f(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,u,d,p=0;if(e.parents.length>1)throw"Node is not part of a tree.";if(n=e.parents[0],n&&(i=new f(n.x,n.y),r=new f(e.x,e.y),p=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 f(l.x,l.y),s[t]=t,a[t]=this.normalizeAngle(-p+Math.atan2(c.y-c.y,c.x-c.x));for(h.bisort(a,s),u=[],d=e.children,t=0;o>t;++t)u.push(d[s[t]]);return u},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,u=c/2,d=e.sectorAngle,h=0,f=this.sortChildren(e);for(r=0,o=f.length;o>r;r++)a=f[r],s=a,l=s.sectorAngle/d,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*u),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,u=0,d=0,f=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))f=new s(Math.abs(r)<p?50:r,Math.abs(o)<p?25:o);else if(1===e.children.length){switch(e.treeDirection){case"Radial":n=this.measure(e.children[0],t),u=r+this.options.radialSeparation*Math.cos(e.AngleToParent)+n.width,d=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),u=r+n.width+this.options.underneathHorizontalOffset,d=o+this.options.underneathVerticalTopOffset+n.height;break;case"Default":n=this.measure(e.children[0],t),u=r+this.options.horizontalSeparation+n.width,d=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),u=Math.max(r,n.width+this.options.underneathHorizontalOffset),d=o+this.options.underneathVerticalTopOffset+n.height;break;case"Default":n=this.measure(e.children[0],t),d=o+this.options.verticalSeparation+n.height,u=Math.max(r,n.width);break;default:throw"Unhandled TreeDirection in the Down layout measuring."}break;default:throw"Unhandled TreeDirection in the layout measuring."}f=new s(u,d)}else{switch(e.treeDirection){case"Left":case"Right":switch(e.childrenLayout){case"TopAlignedWithParent":case"BottomAlignedWithParent":break;case"Underneath":for(u=r,d=o+this.options.underneathVerticalTopOffset,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),u=Math.max(u,n.width+this.options.underneathHorizontalOffset),d+=n.height+this.options.underneathVerticalSeparation;d-=this.options.underneathVerticalSeparation;break;case"Default":for(u=r,d=0,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),u=Math.max(u,r+this.options.horizontalSeparation+n.width),d+=n.height+this.options.verticalSeparation;d-=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(u=r,d=o+this.options.underneathVerticalTopOffset,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),u=Math.max(u,n.width+this.options.underneathHorizontalOffset),d+=n.height+this.options.underneathVerticalSeparation;d-=this.options.underneathVerticalSeparation;break;case"Default":for(u=0,d=0,l=0;e.children.length>l;l++)c=e.children[l],n=this.measure(c,t),u+=n.width+this.options.horizontalSeparation,d=Math.max(d,n.height+this.options.verticalSeparation+o);u-=this.options.horizontalSeparation;break;default:throw"Unhandled TreeDirection in the Down layout measuring."}break;default:throw"Unhandled TreeDirection in the layout measuring."}f=new s(u,d)}return e.SectorAngle=Math.sqrt(u*u/4+d*d/4),e.Size=f,f},arrange:function(e,t){var n,i,r,o,a,s,c,u,d=e.associatedShape.bounds(),g=d.width,m=d.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(u=t,e.x=u.x,e.y=u.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=u.x-o.associatedShape.width-this.options.underneathHorizontalOffset,i=new f(s,c),this.arrange(o,i),c+=o.Size.height+this.options.underneathVerticalSeparation;break;case"Default":for(u=new f(t.x+e.Size.width-g,t.y+(e.Size.height-m)/2),e.x=u.x,e.y=u.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),s=u.x-this.options.horizontalSeparation,c=t.y,n=0;e.children.length>n;n++)o=e.children[n],i=new f(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(u=t,e.x=u.x,e.y=u.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 f(s,c),this.arrange(o,i),c+=o.Size.height+this.options.underneathVerticalSeparation;break;case"Default":for(u=new f(t.x,t.y+(e.Size.height-m)/2),e.x=u.x,e.y=u.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 f(s,c),this.arrange(o,i),c+=o.Size.height+this.options.verticalSeparation;break;default:throw"Unsupported TreeDirection"}break;case"Up":if(u=new f(t.x+(e.Size.width-g)/2,t.y+e.Size.height-m),e.x=u.x,e.y=u.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),Math.abs(u.x-t.x)<p){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=u.y-this.options.verticalSeparation-o.Size.height,i=new f(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(u=t,e.x=u.x,e.y=u.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 f(s,c),this.arrange(o,i),c+=o.Size.height+this.options.underneathVerticalSeparation;break;case"Default":if(u=new f(t.x+(e.Size.width-g)/2,t.y),e.x=u.x,e.y=u.y,e.BoundingRectangle=new l(e.x,e.y,e.width,e.height),Math.abs(u.x-t.x)<p){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=u.y+this.options.verticalSeparation+m,i=new f(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 b(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 w(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 b(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,u,d,f,p=[],g=new c,v=0;for(h.forEach(e.nodes,function(e){0===e.incoming.length&&(g.set(e,0),p.push(e))});p.length>0;)for(o=p.shift(),t=0;o.outgoing.length>t;t++)i=o.outgoing[t],a=i.target,r=g.containsKey(a)?Math.max(g.get(o)+1,g.get(a)):g.get(o)+1,g.set(a,r),r>v&&(v=r),m(p,a)||p.push(a);for(s=g.keys(),s.sort(function(e,t){var n=g.get(e),i=g.get(t);return h.sign(i-n)}),l=0;s.length>l;++l)if(u=s[l],d=Number.MAX_VALUE,0!==u.outgoing.length){for(n=0;u.outgoing.length>n;++n)i=u.outgoing[n],d=Math.min(d,g.get(i.target));d>1&&g.set(u,d-1)}for(this.layers=[],t=0;v+1>t;t++)f=[],f.linksTo={},this.layers.push(f);for(g.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,u,d,f=new c;for(i=0;this.layers.length>i;++i)if(r=e[i]){for(t=0;r.length>t;t++)n=r[t],f.containsKey(n)||this.placeLeft(n,f,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,f.get(a)-f.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)),u=0;l.length>u;u++)d=l[u],this.nodeLeftClass.get(d)<i&&s.push(f.get(d)-f.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],f.set(n,f.get(n)+o)}return f},placeRightToLeft:function(e){var t,n,i,r,o,a,s,l,u,d,f=new c;for(i=0;this.layers.length>i;++i)if(r=e[i]){for(t=0;r.length>t;t++)n=r[t],f.containsKey(n)||this.placeRight(n,f,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,f.get(a)-f.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)),u=0;l.length>u;u++)d=l[u],this.nodeRightClass.get(d)<i&&s.push(f.get(n)-f.get(d));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],f.set(n,f.get(n)+o)}return f},_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,u,d,h=0,f=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],f.containsKey(o))h=f.get(o);else if(f.set(o,h),o.isVirtual)for(a=this._nodesInLink(o),s=0;a.length>s;s++)l=a[s],f.set(l,h);for(u=[],d=0;this.layers.length>d;d++)u.push(null);return f.forEach(function(e,t){null===u[t]&&(u[t]=[]),u[t].push(e)}),u},_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,u,d,f,p,g,m,v,_,b,y,w,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&&(u=this.downNodes.get(i)[0],u.isVirtual&&l.gridPosition>u.gridPosition&&(d=l.gridPosition,l.gridPosition=u.gridPosition,u.gridPosition=d,f=l.layerIndex,p=u.layerIndex,this.layers[n+1][f]=u,this.layers[n+1][p]=l,l.layerIndex=p,u.layerIndex=f));for(g=this._getLeftWing(),m=this._getRightWing(),v=this.placeLeftToRight(g),_=this.placeRightToLeft(m),b=new c,h.forEach(this.graph.nodes,function(e){b.set(e,(v.get(e)+_.get(e))/2)}),y=new c,w=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],y.set(i,0),w.set(i,!1),i.isVirtual&&(-1===x?x=o:x===o-1?x=o:(k=o,y.set(r[x],0),b.get(i)-b.get(r[x])===this.getMinDist(r[x],i)?w.set(r[x],!0):w.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(b,null,o,e,a),t=0;a.length-1>t;++t)this.setMinDist(a[t],a[t+1],b.get(a[t+1])-b.get(a[t]));o&&this.setMinDist(a[a.length-1],o,b.get(o)-b.get(a[a.length-1]))}for(;o;){if(s=this.nextVirtualNode(i,o)){if(y.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(b,o,s,e,a),w.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(b,o,null,e,a),t=0;a.length-1>t;++t)this.setMinDist(a[t],a[t+1],b.get(a[t+1])-b.get(a[t]));this.setMinDist(o,a[0],b.get(a[0])-b.get(o))}}o=s}this.adjustDirections(n,e,y,w)}},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=b.get(i),i.y=A+M/2):(i.x=A+M/2,i.y=b.get(i));A+=this.options.layerSeparation+M}},adjustDirections:function(e,t,n,i){var r,o,a,s,l,c,u,d,h,f,p,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(u=i.get(o),d=this.layers[e],h=o.layerIndex,f=c.layerIndex,p=h+1;f>p;++p)d[p].isVirtual&&(u=u&&i.get(d[p]));if(u)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,u,d,h,f,p,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),d=[],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--,d.push({k:e.get(c)-this.getMinDist(r[o],r[m]),v:2}));d.push({k:e.get(r[o])-this.getMinDist(r[o],r[m]),v:a})}for(n&&d.push({k:e.get(n)-this.getMinDist(n,r[m]),v:Number.MAX_VALUE}),d.sort(this._positionAscendingComparer),h=0,f=0,p=this.getMinDist(r[m-1],r[m]);e.get(r[m])-e.get(r[m-1])<p;)if(f>h){if(0===v.length){e.set(r[m-1],e.get(r[m])-p);break}u=v.shift(),h+=u.v,e.set(r[m-1],u.k),e.set(r[m-1],Math.max(e.get(r[m-1]),e.get(r[m])-p))}else{if(0===d.length){e.set(r[m],e.get(r[m-1])+p);break}u=d.shift(),f+=u.v,e.set(r[m],u.k),e.set(r[m],Math.min(e.get(r[m]),e.get(r[m-1])+p))}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,u,d,f,p,g,m,v,_,b,y,w,x,k;for(this.linkToNodeMap=new c,this.nodeToLinkMap=new c,d=this.graph.links.slice(0),f=this.layers,p=function(e,t,n){f[e].linksTo[t]=f[e].linksTo[t]||[],f[e].linksTo[t].push(n)},u=0;d.length>u;u++)if(g=d[u],m=g.source,v=g.target,_=m.layer,b=v.layer,y=m.gridPosition,w=v.gridPosition,x=(w-y)/Math.abs(b-_),k=m,_-b>1){for(l=_-1;l>b;l--){for(n=new r,n.x=m.x,n.y=m.y,n.width=m.width/100,n.height=m.height/100,e=f[l],t=(l-b)*x+y,t>e.length&&(t=e.length),y>=f[_].length-1&&w>=f[b].length-1?t=e.length:0===y&&0===w&&(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(k,n),s.depthOfDumminess=0,p(l-1,l,s),k=n,this.graph._addNode(n),this.graph.addLink(s),n.index=this.graph.nodes.length-1,this.mapVirtualNode(n,g)}p(b-1,b,s),g.changeSource(k),g.depthOfDumminess=_-b-1}else if(-1>_-b){for(l=_+1;b>l;l++){for(n=new r,n.x=m.x,n.y=m.y,n.width=m.width/100,n.height=m.height/100,e=f[l],t=(l-_)*x+y,t>e.length&&(t=e.length),y>=f[_].length-1&&w>=f[b].length-1?t=e.length:0===y&&0===w&&(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(k,n),s.depthOfDumminess=0,p(l-1,l,s),k=n,this.graph._addNode(n),this.graph.addLink(s),n.index=this.graph.nodes.length-1,this.mapVirtualNode(n,g)}p(b-1,b,g),g.changeSource(k),g.depthOfDumminess=b-_-1}else p(_,b,g)},_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],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 u,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 u,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,u,d,h,f,p,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,u=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,u=l+c):u=a,0!==u&&(d=i[s],h=i[s+1],f=d.gridPosition,p=h.gridPosition,i[s]=h,i[s+1]=d,d.gridPosition=p,h.gridPosition=f,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>=u:g>u,m?(d=i[s],h=i[s+1],f=d.gridPosition,p=h.gridPosition,i[s]=h,i[s+1]=d,d.gridPosition=p,h.gridPosition=f,a=u,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,d,h,f,p=this.layers[e].linksTo[t],g=0,m=p.length;for(l=0;m>l;l++)for(n=p[l],c=l+1;m>c;c++)i=p[c],n.target.layer===t?(r=n.source,o=n.target):(r=n.target,o=n.source),i.target.layer===t?(a=i.source,s=i.target):(a=i.target,s=i.source),u=r.gridPosition,d=o.gridPosition,h=a.gridPosition,f=s.gridPosition,0>(u-h)*(d-f)&&g++;return g},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,u,d;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(u=this.diagram.shapes,d=this.diagram.connections,o=0;u.length>o;o++)r=u[o],this.nodeMap.set(r.visual.id,r.bounds());for(o=0;d.length>o;o++)a=d[o],this.linkMap.set(a.visual.id,a.points())}}});a(n,{init:function(e){t.init(e,n.ui)},SpringLayout:y,TreeLayout:x,GraphAdapter:b,LayeredLayout:k,LayoutBase:_,LayoutState:C})}(window.kendo.jQuery)}(),function(){!function(e,t){function n(e){var t=e.originalEvent,n=0;return t.wheelDelta?(n=-t.wheelDelta/40,n=n>0?_e.ceil(n):_e.floor(n)):t.detail&&(n=t.detail),n}function i(e){return e.options.name.toLowerCase()===Ee.toLowerCase()}function r(e,t){var n,r,o,a,s=Be,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={};return e=e||{},fe(e.text)&&null!==e.text&&(t.text=e.text),fe(e.x)&&null!==e.x&&(t.x=e.x),fe(e.y)&&null!==e.y&&(t.y=e.y),fe(e.width)&&null!==e.width&&(t.width=e.width),fe(e.height)&&null!==e.height&&(t.height=e.height),fe(e.type)&&null!==e.type&&(t.type=e.type),t}function s(e){var t={};return e=e||{},fe(e.text)&&null!==e.text&&(t.content=e.text),fe(e.type)&&null!==e.type&&(t.type=e.type),fe(e.from)&&null!==e.from&&(t.from=e.from),fe(e.fromConnector)&&null!==e.fromConnector&&(t.fromConnector=e.fromConnector),fe(e.fromX)&&null!==e.fromX&&(t.fromX=e.fromX),fe(e.fromY)&&null!==e.fromY&&(t.fromY=e.fromY),fe(e.to)&&null!==e.to&&(t.to=e.to),fe(e.toConnector)&&null!==e.toConnector&&(t.toConnector=e.toConnector),fe(e.toX)&&null!==e.toX&&(t.toX=e.toX),fe(e.toY)&&null!==e.toY&&(t.toY=e.toY),t}function l(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 c(e){this.dataItem=e,this.callbacks=[]}function u(){this.items={}}function d(e){var t=e;return e instanceof kendo.data.Model&&(t=e.toJSON(),t[e.idField]=e._defaultId),t}function h(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 p(e,t){fe(t[e])&&t.set(e,null)}function g(e,t,n){var i,r;for(r=0;n.length>r;r++)i=n[r],t&&!fe(t[i])&&(t[i]=e[i])}function m(e){var t=e.drawingContainer().clippedBBox(null);(0!==t.origin.x||0!==t.origin.y)&&e.position(-t.origin.x,-t.origin.y)}var v,_,b,y,w,x,k,C,S,T,D,A,M=kendo.dataviz,E=kendo.drawing,I=kendo.geometry,R=M.diagram,P=kendo.ui.Widget,F=kendo.Class,B=e.proxy,z=kendo.deepExtend,L=e.extend,H=kendo.data.HierarchicalDataSource,N=R.Canvas,O=R.Group,V=R.Rectangle,U=R.Circle,W=R.CompositeTransform,j=R.Rect,q=R.Path,G=R.DeleteShapeUnit,$=R.DeleteConnectionUnit,Y=R.TextBlock,K=R.Image,Q=R.Point,X=R.Intersect,J=R.ConnectionEditAdorner,Z=R.UndoRedoService,ee=R.ToolService,te=R.Selector,ne=R.ResizingAdorner,ie=R.ConnectorsAdorner,re=R.Cursors,oe=R.Utils,ae=kendo.Observable,se=R.ToBackUnit,le=R.ToFrontUnit,ce=R.PolylineRouter,ue=R.CascadingRouter,de=oe.isUndefined,he=oe.isDefined,fe=kendo.util.defined,pe=e.isArray,ge=kendo.isFunction,me=oe.isString,ve=e.isPlainObject,_e=Math,be=".kendoDiagram",ye="cascading",we="itemBoundsChange",xe="change",ke="click",Ce="drag",Se="dragEnd",Te="dragStart",De="mouseEnter",Ae="mouseLeave",Me="error",Ee="Auto",Ie="Top",Re="Right",Pe="Left",Fe="Bottom",Be=9007199254740992,ze="select",Le="itemRotate",He="pan",Ne="zoomStart",Oe="zoomEnd",Ve="none",Ue=600,We=600,je="rectangle",qe=100,Ge=100,$e=20,Ye=20,Ke=0,Qe="Yellow",Xe=Number.MAX_VALUE,Je=-Number.MAX_VALUE,Ze="absolute",et="transformed",tt="rotated",nt="transparent",it="width",rt="height",ot="x",at="y",st="DOMMouseScroll"+be+" mousewheel"+be,lt=.05,ct=5,ut='<a class="k-button k-button-icontext #=className#" href="\\#"><span class="#=iconClass# #=imageClass#"></span>#=text#</a>',dt=5;R.DefaultConnectors=[{name:Ie},{name:Fe},{name:Pe},{name:Re},{name:Ee,position:function(e){return e.getPosition("center")}}],v={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"}},R.shapeDefaults=function(e){var t={type:je,path:"",autoSize:!0,visual:null,x:Ke,y:Ke,minWidth:$e,minHeight:Ye,width:qe,height:Ge,hover:{},editable:{connect:!0,tools:[]},connectors:R.DefaultConnectors,rotation:{angle:0}};return oe.simpleExtend(t,e),t},_=ae.extend({init:function(e){var t=this;t.dataItem=(e||{}).dataItem,ae.fn.init.call(t),t.options=z({id:R.randomId()},t.options,e),t.isSelected=!1,t.visual=new O({id:t.options.id,autoSize:t.options.autoSize}),t.id=t.options.id,t._template()},options:{hover:{},cursor:re.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 de(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;return e!==t&&(n=this.options,R.Utils.isString(e)?n.content.text=e:z(n.content,e),i=n.content,r=this._contentVisual,r?this._updateContentVisual(i):this._createContentVisual(i)),this.options.content.text},_createContentVisual:function(e){e.text&&(this._contentVisual=new Y(e),this._contentVisual._includeInBBox=!1,this.visual.append(this._contentVisual))},_updateContentVisual:function(e){this._contentVisual.redraw(e)},_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}}}),b=F.extend({init:function(e,t){this.options=z({},this.options,t),this.connections=[],this.shape=e},options:{width:7,height:7,fill:{color:Qe},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}}}),b.parse=function(e,t){var n,i,r=t.split(":"),o=r[0],a=r[1]||Ee;for(n=0;e.shapes.length>n;n++)if(i=e.shapes[n],i.options.id==o)return i.getConnector(a.trim())},y=_.extend({init:function(e,t){var n=this;_.fn.init.call(n,e),this.diagram=t,this.updateOptionsFromModel(),e=n.options,n.connectors=[],n.type=e.type,n.createShapeVisual(),n.updateBounds(),n.content(n.content()),n._createConnectors()},options:R.shapeDefaults(),_setOptionsFromModel:function(e){var t=a(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=a(e||this.dataItem),e&&t?M.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.createShapeVisual(),this.updateBounds()},updateModel:function(e){var t,n,i=this.diagram;i&&i._isEditable&&(t=this._bounds,n=this.dataItem,n&&(i._suspendModelRefresh(),fe(n.x)&&t.x!==n.x&&n.set("x",t.x),fe(n.y)&&t.y!==n.y&&n.set("y",t.y),fe(n.width)&&t.width!==n.width&&n.set("width",t.width),fe(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 j(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 R.RectAlign(e),n=a.drawingElement.bbox(null),i=new j(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 b(this,z({},r,n.connectors[t])),this.connectors.push(e)},bounds:function(e){var t,n;if(e)if(me(e))switch(e){case et:t=this._transformedBounds();break;case Ze:t=this._transformedBounds(),n=this.diagram._pan,t.x+=n.x,t.y+=n.y;break;case tt:t=this._rotatedBounds();break;default:t=this._bounds}else this._setBounds(e),this._triggerBoundsChange(),this.diagram&&this.diagram._layouting||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=_e.max(e.width,t.minWidth),a=t.height=_e.max(e.height,t.minHeight);this._bounds=new j(i,r,o,a),this.visual.redraw({x:i,y:r,width:o,height:a})},position:function(e){return e?(this.bounds(new j(e.x,e.y,this._bounds.width,this._bounds.height)),t):this._bounds.topLeft()},clone:function(){var e=this.serialize();return e.options.id=R.randomId(),this.diagram&&this.diagram._isEditable&&fe(this.dataItem)&&(e.options.dataItem=d(this.dataItem)),new y(e.options)},select:function(e){var n,i,r=this.diagram;return de(e)&&(e=!0),this._canSelect()&&this.isSelected!=e?(n=[],i=[],this.isSelected=e,this.isSelected?(r._selectedItems.push(this),n.push(this)):(oe.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 R.RotateUnit(this.diagram._resizingAdorner,[this],[l.angle]),!1),r=this.bounds(),o=new Q(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(Le,{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(!me(e))return e instanceof Q?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 ge(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,[it,rt,ot,at])&&(this.bounds(new j(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:R.diffNumericOptions,_visualOptions:function(e){return{data:e.path,source:e.source,hover:e.hover,fill:e.fill,stroke:e.stroke}},_triggerBoundsChange:function(){this.diagram&&this.diagram.trigger(we,{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 j.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 j.fromPoints(t,n)},_rotate:function(){var e=this.options.rotation;e&&e.angle&&this.rotate(e.angle),this._rotationOffset=new Q},_hover:function(e){var t=this.options,n=t.hover,i=t.stroke,r=t.fill;e&&he(n.stroke)&&(i=z({},i,n.stroke)),e&&he(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 X.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}},createShapeVisual:function(){var e,t=this.options,n=this._visualOptions(t),i=t.visual,r=(t.type+"").toLocaleLowerCase();n.width=t.width,n.height=t.height,ge(i)?e=i.call(this,t):n.data?(e=new q(n),m(e)):e="rectangle"==r?new V(n):"circle"==r?new U(n):"text"==r?new Y(n):"image"==r?new K(n):new q(n),this.shapeVisual=e,this.visual.append(this.shapeVisual)}}),w=_.extend({init:function(e,t,n){var i=this;_.fn.init.call(i,n),this.updateOptionsFromModel(),this._initRouter(),i.path=new R.Polyline(i.options),i.path.fill(nt),i.visual.append(i.path),i._sourcePoint=i._targetPoint=new Q,i._setSource(e),i._setTarget(t),i.content(i.options.content),i.definers=[],fe(n)&&n.points&&i.points(n.points)},options:{hover:{stroke:{}},startCap:Ve,endCap:Ve,points:[],selectable:!0,fromConnector:Ee,toConenctor:Ee},_setOptionsFromModel:function(e){this.updateOptionsFromModel(e||this.dataItem)},updateOptionsFromModel:function(e){var t,n,i,r;this.diagram&&this.diagram._isEditable&&(t=this.diagram._dataMap,n=s(e||this.dataItem),e?(fe(n.from)?(i=t[n.from],i&&fe(n.fromConnector)&&(i=i.getConnector(n.fromConnector)),this.source(i)):fe(n.fromX)&&fe(n.fromY)&&this.source(new Q(n.fromX,n.fromY)),fe(n.to)?(r=t[n.to],r&&fe(n.toConnector)&&(r=r.getConnector(n.toConnector)),this.target(r)):fe(n.toX)&&fe(n.toY)&&this.target(new Q(n.toX,n.toY)),fe(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(),fe(this.options.fromX)&&null!==this.options.fromX?(p("from",t),p("fromConnector",t),t.set("fromX",this.options.fromX),t.set("fromY",this.options.fromY)):(t.set("from",this.options.from),fe(t.fromConnector)&&t.set("fromConnector",this.sourceConnector?this.sourceConnector.options.name:null),p("fromX",t),p("fromY",t)),fe(this.options.toX)&&null!==this.options.toX?(p("to",t),p("toConnector",t),t.set("toX",this.options.toX),t.set("toY",this.options.toY)):(t.set("to",this.options.to),fe(t.toConnector)&&t.set("toConnector",this.targetConnector?this.targetConnector.options.name:null),p("toX",t),p("toY",t)),fe(this.options.type)&&fe(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},_setSource:function(e){var n,i=e instanceof y,r=this.options.fromConnector||Ee;(!i||e.getConnector(r))&&(e!==t&&(this.from=e),this._removeFromSourceConnector(),null===e?this.sourceConnector&&(this._sourcePoint=(this._resolvedSourceConnector||this.sourceConnector).position(),this._clearSourceConnector(),this._setFromOptions(null,this._sourcePoint)):e instanceof b?(n=e.shape.dataItem,n&&this._setFromOptions(n.id),this.sourceConnector=e,this.sourceConnector.connections.push(this)):e instanceof Q?(this._setFromOptions(null,e),this._sourcePoint=e,this.sourceConnector&&this._clearSourceConnector()):i&&(n=e.dataItem,n&&this._setFromOptions(n.id),this.sourceConnector=e.getConnector(r),this.sourceConnector.connections.push(this)))},source:function(e,t){return he(e)&&(t&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new R.ConnectionEditUnit(this,e)),this._setSource(e),this.refresh()),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 R.PathDefiner(this.sourcePoint(),null,null)),this._sourceDefiner;if(!(e instanceof R.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},_setTarget:function(e){var n,i=e instanceof y,r=this.options.toConnector||Ee;(!i||e.getConnector(r))&&(e!==t&&(this.to=e),this._removeFromTargetConnector(),null===e?this.targetConnector&&(this._targetPoint=(this._resolvedTargetConnector||this.targetConnector).position(),this._clearTargetConnector(),this._setToOptions(null,this._targetPoint)):e instanceof b?(n=e.shape.dataItem,n&&this._setToOptions(n.id),this.targetConnector=e,this.targetConnector.connections.push(this)):e instanceof Q?(this._setToOptions(null,e),this._targetPoint=e,this.targetConnector&&this._clearTargetConnector()):i&&(n=e.dataItem,n&&this._setToOptions(n.id),this.targetConnector=e.getConnector(r),this.targetConnector.connections.push(this)))},target:function(e,n){return he(e)&&(n&&this.diagram&&this.diagram.undoRedoService.addCompositeItem(new R.ConnectionEditUnit(this,t,e)),this._setTarget(e),this.refresh()),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 R.PathDefiner(this.targetPoint(),null,null)),this._targetDefiner;if(!(e instanceof R.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 b&&!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 fe(e)&&this._alignContent(),t},_createContentVisual:function(e){var t;return ge(e.visual)?t=e.visual.call(this,e):e.text&&(t=new Y(e)),t&&(this._contentVisual=t,t._includeInBBox=!1,this.visual.append(t)),t},_updateContentVisual:function(e){ge(e.visual)?(this.visual.remove(this._contentVisual),this._createContentVisual(e)):this._contentVisual.redraw(e)},_alignContent:function(){var e,t,n,i,r,o,a,s,l,c,u,d,h,f,p,g;if(this._contentVisual){for(e=dt,t=this.allPoints(),n=_e.floor(t.length/2),i=n-1;i>0&&t[i].equals(t[n]);)i--,n++;r=t[n],o=t[i],a=this._contentVisual._measure(),s=a.width,l=a.height,c=t.length%2===0,u=o.distanceTo(r),c&&t.length>2&&u>0&&(o.y===r.y&&s>u||o.x===r.x&&l>u)&&(c=!1,e=0),c?(h=kendo.util.deg(_e.atan2(r.y-o.y,r.x-o.x)),d=new Q((r.x-o.x)/2+o.x,(r.y-o.y)/2+o.y),90===_e.abs(h)?(d.x+=e,d.y-=l/2):h%180===0?(d.x-=s/2,d.y-=l+e):-90>h||h>0&&90>h?d.y-=l:(0>h||h>90)&&(d.x-=s,d.y-=l)):(f=_e.floor(t.length/2),d=t[f].clone(),o=t[f-1],r=t[f+1],p=d.x>=o.x&&d.x>=r.x?e:-a.width-e,g=d.y>=o.y&&d.y>=r.y?e:-a.height-e,d.x+=p,d.y+=g),this._contentVisual.position(d)}},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 J(this,this.options.selection),r._adorn(this.adorner,!0),r._selectedItems.push(this),n.push(this)):this.adorner&&(r._adorn(this.adorner,!1),oe.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||me(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==ye?new ue(this):new ce(this)},points:function(e){var t,n,i,r;if(!e){if(i=[],he(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 R.Point)this.definers.push(new R.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 R.PathDefiner(new Q(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 Q?e=s:s instanceof b&&(i(s)?n=s.shape:(a._resolvedSourceConnector=s,e=s.position())),l instanceof Q?t=l:l instanceof b&&(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,u,d,h,f,p,g=Be,m=Be,v=e.connectors;for(h=0;v.length>h;h++)if(u=v[h],!i(u))for(a=u.position(),n=t.connectors,f=0;n.length>f;f++)d=n[f],i(d)||(s=d.position(),p=_e.round(a.distanceTo(s)),g>p&&this.diagram&&this._testRoutePoints(a,s,u,d)&&(g=p,r=u,o=d),m>p&&(l=u,c=d,m=p));r&&(l=r,c=o),this._resolvedSourceConnector=l,this._resolvedTargetConnector=c},_testRoutePoints:function(e,t,n,i){var r,o,a,s,l,c=this._router,u=!0;if(c instanceof ue)for(r=c.routePoints(e,t,n,i),r.unshift(e),r.push(t),l=1;r.length>l;l++)if(o=r[l-1],a=r[l],s=new j(_e.min(o.x,a.x),_e.min(o.y,a.y),_e.abs(o.x-a.x),_e.abs(o.y-a.y)),s.width>0&&(s.x++,s.width-=2),s.height>0&&(s.y++,s.height-=2),!s.isEmpty()&&this.diagram._shapesQuadTree.hitTestRect(s)){u=!1;break}return u},redraw:function(e){if(e){this.options=z({},this.options,e);var t=this.options.points;fe(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&&fe(this.dataItem)&&(e.options.dataItem=d(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 fe(this.dataItem)&&(n.dataItem=""+this.dataItem),n.options.points=this.points(),n},_hitTest:function(e){if(this.visible()){var t=new Q(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&&he(this.options.hover.stroke.color)&&(t=this.options.hover.stroke.color),this.path.redraw({stroke:{color:t}})},_refreshPath:function(){fe(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(){this.sourceConnector=t,this._resolvedSourceConnector=t},_clearTargetConnector:function(){this.targetConnector=t,this._resolvedTargetConnector=t},_removeFromSourceConnector:function(){this.sourceConnector&&oe.remove(this.sourceConnector.connections,this)},_removeFromTargetConnector:function(){this.targetConnector&&oe.remove(this.targetConnector.connections,this)},toJSON:function(){var e,t,n,i=this;return i.from&&i.from.toJSON?e=i.from.toJSON():(n=i._sourcePoint,e={x:n.x,y:n.y}),i.to&&i.to.toJSON?t=i.to.toJSON():(n=i._targetPoint,t={x:n.x,y:n.y}),{from:e,to:t}}}),x=P.extend({init:function(e,t){var n=this;kendo.destroy(e),P.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 A(n),n._pan=new Q,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 ne(n,{editable:n.options.editable}),n._connectorsAdorner=new ie(n),n._adorn(n._resizingAdorner,!0),n._adorn(n._connectorsAdorner,!0),n.selector=new te(n),n._clipboard=[],n.pauseMouseHandlers=!1,n._createOptionElements(),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:R.shapeDefaults({undoable:!0}),connectionDefaults:{editable:{tools:[]},type:ye},shapes:[],connections:[]},events:[Oe,Ne,He,ze,Le,we,xe,ke,De,Ae,"toolBarClick","save","cancel","edit","remove","add","dataBound",Te,Ce,Se],items:function(){return e()},_createGlobalToolBar:function(){var e,t=this.options.editable;t&&(e=t.tools,!this._isEditable||e===!1||e&&0!==e.length||(e=["createShape","undo","redo","rotateClockwise","rotateAnticlockwise"]),e&&e.length&&(this.toolBar=new k(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 Q,n||new Q,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(l,this),n=z({},{from:o,to:o},r.connectionEditors),i=r.connectionTemplate}this.editor=new S(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.wrapper};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 N(t,{width:n.width||Ue,height:n.height||We})},_createHandlers:function(){var e=this,t=e.element;t.on(st,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 ee(e),e.options.pannable!==!1&&e.scroller.enable()):(e.toolService=new ee(e),this.scroller.wrapper.on("mousemove"+be,B(e._mouseMove,e)).on("mouseup"+be,B(e._mouseUp,e)).on("mousedown"+be,B(e._mouseDown,e)).on("mouseover"+be,B(e._mouseover,e)).on("mouseout"+be,B(e._mouseout,e)),t.on("keydown"+be,B(e._keydown,e))),this._syncHandler=B(e._syncChanges,e),e._resizeHandler=B(e.resize,e,!1),kendo.onResize(e._resizeHandler),this.bind(Ne,B(e._destroyToolBar,e)),this.bind(He,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(Q(e.x.location,e.y.location))},_gestureStart:function(e){var t,n;this._destroyToolBar(),this.scroller.disable(),t=this.documentToModel(new Q(e.center.x,e.center.y)),n={point:t,zoom:this.zoom()},this.trigger(Ne,n)||(this._gesture=e,this._initialCenter=t)},_gestureChange:function(e){var t,n,i=this._gesture,r=this._initialCenter,o=this.documentToView(new Q(e.center.x,e.center.y)),a=e.distance/i.distance,s=this._zoom,l=!1;_e.abs(a-1)>=lt&&(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)>=ct)&&(this._panTransform(n),this._updateAdorners()),e.preventDefault()},_gestureEnd:function(){this.options.pannable!==!1&&this.scroller.enable(),this.trigger(Oe,{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=M.ui.themes||{},n=((e.options||{}).theme||"").toLowerCase(),i=(t[n]||{}).diagram;e.options=z({},i,e.options),e.options.editable===!0&&z(e.options,{editable:(i||{}).editable})},_createOptionElements:function(){var e=this.options,t=e.shapes.length;t&&this._createShapes(),e.connections.length&&this._createConnections(),t&&e.layout&&this.layout(e.layout)},_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._findConnectionTarget(e.from),n=r._findConnectionTarget(e.to),r.connect(t,n,z({},a,e))},_findConnectionTarget:function(e){var t,n=this,i=me(e)?e:e.shapeId||e.id;return i?(t=n.getShapeById(i),e.connector&&(t=t.getConnector(e.connector))):t=new Q(e.x||0,e.y||0),t},destroy:function(){var e=this;P.fn.destroy.call(e),this._userEvents&&this._userEvents.destroy(),kendo.unbindResize(e._resizeHandler),e.clear(),e.element.off(be),e.scroller.wrapper.off(be),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={shapes:[],connections:[]};for(e=0;this.shapes.length>e;e++)n=this.shapes[e],n.options.serializable&&i.shapes.push(n.options);for(e=0;this.connections.length>e;e++)t=this.connections[e],i.connections.push(z({},t.options,t.toJSON()));return i},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 R.AddConnectionUnit(e,this),!1),e.diagram=this,e._setOptionsFromModel(),e.refresh(),this.mainLayer.append(e.visual),this.connections.push(e),this.trigger(xe,{added:[e],removed:[]}),e},_addConnection:function(e,t){var n,i=this.connectionsDataSource;if(i&&this._isEditable){if(n=f(i,d(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)n=e;else{if(e instanceof kendo.Class)return;i=z({},i,e||{}),n=new y(i,this)}return t!==!1&&this.undoRedoService.add(new R.AddShapeUnit(n,this),!1),this.shapes.push(n),n.diagram!==this&&(this._shapesQuadTree.insert(n),n.diagram=this),this.mainLayer.append(n.visual),this.trigger(xe,{added:[n],removed:[]}),n},_addShape:function(e,t){var n,i,r=this,o=r.dataSource;if(o&&this._isEditable){if(n=f(o,d(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,t)},remove:function(e,t){var n,i,r,o;for(e=pe(e)?e.slice(0):[e],n=h(e),i=n.shapes,r=n.connections,fe(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(xe,{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(!he(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 _&&(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 j)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 _?r.push(e):he(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),!fe(t)||t?(i=o(this.mainLayer,n.visuals),r=new le(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),!fe(t)||t?(i=o(this.mainLayer,n.visuals),r=new se(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 R.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 _?i=e.bounds(et):pe(e)?i=this.boundingBox(e):e instanceof j&&(i=e.clone()),r=i.clone(),i.zoom(this._zoom),(i.width>a.width||i.height>a.height)&&(this._zoom=this._getValidZoom(_e.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(de(e)&&(e="Left"),t=this.select(),0!==t.length){switch(e.toLowerCase()){case"left":case"top":n=Xe;break;case"right":case"bottom":n=Je}for(r=0;t.length>r;r++)if(i=t[r],i instanceof y)switch(e.toLowerCase()){case"left":n=_e.min(n,i.options.x);break;case"top":n=_e.min(n,i.options.y);break;case"right":n=_e.max(n,i.options.x);break;case"bottom":n=_e.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 Q(n,i.options.y));break;case"top":case"bottom":i.position(new Q(i.options.x,n))}s=new R.TransformUnit(a,o),this.undoRedoService.add(s,!1)}},zoom:function(e,t){var n,i,r,o;return e&&(n=t?t.point:new R.Point(0,0),e=this._zoom=this._getValidZoom(e),de(n)||(n=new R.Point(_e.round(n.x),_e.round(n.y)),i=n.times(e),r=this.modelToView(n),o=r.minus(i),this._storePan(new R.Point(_e.round(o.x),_e.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 Q&&(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 j(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=h(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 Q(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 b&&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 Q(t[n+"Point"]().x+r.x,t[n+"Point"]().y+r.y))},boundingBox:function(e,t){var n,i,r,o=j.empty(),a=he(e)?this._getDiagramItems(e):{shapes:this.shapes};if(a.shapes.length>0)for(i=a.shapes[0],o=i.bounds(tt),r=1;a.shapes.length>r;r++)i=a.shapes[r],n=i.bounds(tt),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 Q(e.x-t.left,e.y-t.top)},viewToDocument:function(e){var t=this._containerOffset();return new Q(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 Q?t&&(r=t.apply(e)):(n=this._transformWithMatrix(e.topLeft(),t),i=this._transformWithMatrix(e.bottomRight(),t),r=j.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._layouting=!0,de(e)&&(e=this.options.layout),t=de(e)||de(e.type)?"Tree":e.type,t.toLowerCase()){case"tree":n=new R.TreeLayout(this);break;case"layered":n=new R.LayeredLayout(this);break;case"forcedirected":case"force":case"spring":case"springembedder":n=new R.SpringLayout(this);break;default:throw"Layout algorithm '"+t+"' is not supported."}i=new R.LayoutState(this),r=n.layout(e),r&&(o=new R.LayoutUndoUnit(i,r,e?e.animate:null),this.undoRedoService.add(o)),this._layouting=!1,this._redrawConnections()},getShapeById:function(e){var t;return(t=oe.first(this.shapes,function(t){return t.visual.id===e}))?t:t=oe.first(this.connections,function(t){return t.visual.id===e})},_extendLayoutOptions:function(e){e.layout&&(e.layout=z(R.LayoutBase.fn.defaultOptions||{},e.layout))},_selectionChanged:function(e,t){(e.length||t.length)&&this.trigger(ze,{selected:e,deselected:t})},_getValidZoom:function(e){return _e.min(_e.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(He,{total:this._pan,delta:Number.NaN})},_storePan:function(e){this._pan=e,this._storeViewMatrix()},_zoomMainLayer:function(){var e=this._zoom,t=new W(0,0,e,e);t.render(this.mainLayer),this._storeLayerMatrix(t),this._storeViewMatrix()},_transformMainLayer:function(){var e=this._pan,t=this._zoom,n=new W(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 W(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],oe.remove(this.shapes,i),oe.insert(this.shapes,i,r);for(n=0;e.cons.length>n;n++)i=e.cons[n],oe.remove(this.connections,i),oe.insert(this.connections,i,o)},_getDiagramItems:function(e){var t,n,i={},r=e;for(i.visuals=[],i.shapes=[],i.cons=[],e?pe(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)),oe.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&&M.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&&oe.remove(e.sourceConnector.connections,e),e.targetConnector&&oe.remove(e.targetConnector.connections,e),t&&this.undoRedoService.addCompositeItem(new $(e)),oe.remove(this.connections,e)},_removeDataItems:function(e,t){var n,i,r,o;for(e=pe(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(fe(e))return(n=this._dataMap[e.id])?n:(i=z({},this.options.shapeDefaults),i.dataItem=e,n=new y(i,this),this.addShape(n,t!==!1),this._dataMap[e.id]=n,n)},_addDataItemByUid:function(e){var t,n;if(fe(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,i=this,r=e.node,o=e.action,a=e.items,s=i.options;if(!e.field){if("remove"==o)this._removeDataItems(e.items,!0);else for(o&&"itemloaded"!==o||this._bindingRoots||(this._bindingRoots=!0,n=!0),o||r||i.clear(),this._addDataItems(a,r),t=0;a.length>t;t++)a[t].load();s.layout&&(n||"remove"==o||"add"==o)&&i.layout(s.layout),n&&(this.trigger("dataBound"),this._bindingRoots=!1)}},_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=this.toolService.diagram;this.singleToolBar||1!==c.select().length||(e=c.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 k(c,{tools:n,click:B(this._toolBarClick,this),modal:!0}),o=this.singleToolBar._popup.element.outerWidth(),a=this.singleToolBar._popup.element.outerHeight(),e instanceof y?(s=this.modelToView(e.bounds(tt)),r=Q(s.x,s.y).minus(Q((o-s.width)/2,a+i))):e instanceof w&&(l=this.modelToView(e.bounds()),r=Q(l.x,l.y).minus(Q((o-l.width-20)/2,a+i))),r?(this.canvas.translate||(r=r.minus(Q(this.scroller.scrollLeft,this.scroller.scrollTop))),r=this.viewToDocument(r),r=Q(_e.max(r.x,0),_e.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 Q(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=R.randomId()},_fetchFreshData:function(){var e=this;e._dataSource(),e._isEditable&&e._connectionDataSource(),e.options.autoBind&&(e._isEditable?(this._loadingShapes=!0,this._loadingConnections=!0,e.dataSource.fetch(),e.connectionsDataSource.fetch()):e.dataSource.fetch())},_dataSource:function(){var e,t;fe(this.options.connectionsDataSource)?(this._isEditable=!0,e=this.options.dataSource||{},t=pe(e)?{data:e}:e,this.dataSource&&this._shapesRefreshHandler?this.dataSource.unbind("change",this._shapesRefreshHandler).unbind("requestStart",this._shapesRequestStartHandler).unbind("error",this._shapesErrorHandler):(this._shapesRefreshHandler=B(this._refreshShapes,this),this._shapesRequestStartHandler=B(this._shapesRequestStart,this),this._shapesErrorHandler=B(this._error,this)),this.dataSource=kendo.data.DataSource.create(t).bind("change",this._shapesRefreshHandler).bind("requestStart",this._shapesRequestStartHandler).bind("error",this._shapesErrorHandler)):(this._treeDataSource(),this._isEditable=!1)},_connectionDataSource:function(){var e,t=this.options.connectionsDataSource;t&&(e=pe(t)?{data:t}:t,this.connectionsDataSource&&this._connectionsRefreshHandler?this.connectionsDataSource.unbind("change",this._connectionsRefreshHandler).unbind("requestStart",this._connectionsRequestStartHandler).unbind("error",this._connectionsErrorHandler):(this._connectionsRefreshHandler=B(this._refreshConnections,this),this._connectionsRequestStartHandler=B(this._connectionsRequestStart,this),this._connectionsErrorHandler=B(this._connectionsError,this)),this.connectionsDataSource=kendo.data.DataSource.create(e).bind("change",this._connectionsRefreshHandler).bind("requestStart",this._connectionsRequestStartHandler).bind("error",this._connectionsErrorHandler))},_shapesRequestStart:function(e){"read"==e.type&&(this._loadingShapes=!0)},_connectionsRequestStart:function(e){"read"==e.type&&(this._loadingConnections=!0)},_error:function(){this._loadingShapes=!1},_connectionsError:function(){this._loadingConnections=!1},_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=_e.max((this._suspended||0)-1,0)},refresh:function(){this._loadingShapes=!1,this._loadingConnections||this._rebindShapesAndConnections()},_rebindShapesAndConnections:function(){this.clear(),this._addShapes(this.dataSource.view()),this.connectionsDataSource&&this._addConnections(this.connectionsDataSource.view(),!1),this.options.layout?this.layout(this.options.layout):this._redrawConnections(),this.trigger("dataBound")},refreshConnections:function(){this._loadingConnections=!1,this._loadingShapes||this._rebindShapesAndConnections()},_redrawConnections:function(){var e,t=this.connections;for(e=0;t.length>e;e++)t[e].refresh()},_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,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;for(t=0;e.length>t;t++)n=e[t],i=this._connectionsDataMap[n.uid],i.updateOptionsFromModel(n)},_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),fe(n)&&null!==n||(n=new Q(e.fromX,e.fromY)),i=this._validateConnector(e.to),fe(i)&&null!==i||(i=new Q(e.toX,e.toY)),fe(n)&&fe(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 fe(e)&&null!==e&&(t=this._dataMap[e]),t},_treeDataSource:function(){var e=this,t=e.options,n=t.dataSource;n=pe(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=H.create(n).bind(xe,e._refreshHandler).bind(Me,e._errorHandler)},_unbindDataSource:function(){var e=this;e.dataSource.unbind(xe,e._refreshHandler).unbind(Me,e._errorHandler)},_adorn:function(e,n){n!==t&&e&&(n?(this._adorners.push(e),this.adornerLayer.append(e.visual)):(oe.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=E.Path.fromRect(n),r=new E.Group({transform:t}),o=new E.Group({clip:i}),a=this.canvas.drawingElement.children[0];return o.append(r),r.children.push(a),o},exportVisual:function(){var e=I.transform().scale(1/this._zoom),t=new E.Group({transform:e}),n=this.mainLayer.drawingElement;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=[])}}),M.ExportMixin.extend(x.fn,!0),kendo.PDFMixin&&kendo.PDFMixin.extend(x.fn),k=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||!fe(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=(ve(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=parseFloat(e.step||90);this._rotate(t)},rotateAnticlockwise:function(e){var t=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()}}),C=kendo.Observable.extend({init:function(e,t){kendo.Observable.fn.init.call(this),this.options=L(!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}}),S=C.extend({init:function(e,t){C.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.appendTo(this.element),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(ut)(v[e])},_attachButtonEvents:function(){this._cancelClickHandler=B(this._cancelClick,this),this.window.element.on(ke+be,"a.k-diagram-cancel",this._cancelClickHandler),this._updateClickHandler=B(this._updateClick,this),this.window.element.on(ke+be,"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(ke+be,"a.k-diagram-cancel",this._cancelClickHandler),this.window.element.off(ke+be,"a.k-diagram-update",this._updateClickHandler),this._cancelClickHandler=null,this._editUpdateClickHandler=null,this.window=null,C.fn.destroy.call(this)}}),c.fn=c.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 c(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]}},T=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){var t,n=this.shapes,i=n.length;for(t=0;i>t;t++)if(this._testRect(n[t].shape,e))return!0},_testRect:function(e,t){var n,i=e.rotate().angle,r=e.bounds();return n=i?X.rects(t,r,-i):r.overlaps(t)}}),D=T.extend({init:function(e){T.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.rect.overlaps(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 D(new j(n.x,n.y,a,s)),new D(new j(o.x,n.y,a,s)),new D(new j(n.x,o.y,a,s)),new D(new j(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){var t,n=this.children,i=n.length,r=!1;if(this.overlapsBounds(e))if(T.fn.hitTestRect.call(this,e))r=!0;else for(t=0;i>t;t++)if(n[t].hitTestRect(e)){r=!0;break}return r}}),A=F.extend({ROOT_SIZE:1e3,init:function(e){var t=B(this._boundsChange,this);e.bind(we,t),e.bind(Le,t),this.initRoots()},initRoots:function(){this.rootMap={},this.root=new T},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(tt),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 D(new j(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,n,i=this.ROOT_SIZE,r=e.bottomRight(),o=_e.floor(r.x/i),a=_e.floor(r.y/i),s=[[],[]];for(t=_e.floor(e.x/i);o>=t;t++)s[0].push(t);for(n=_e.floor(e.y/i);a>=n;n++)s[1].push(n);return s},hitTestRect:function(e){var t,n,i,r,o,a=this.getSectors(e);if(this.root.hitTestRect(e))return!0;for(t=0;a[0].length>t;t++)for(i=a[0][t],n=0;a[1].length>n;n++)if(r=a[1][n],o=(this.rootMap[i]||{})[r],o&&o.hitTestRect(e))return!0;return!1}}),M.ui.plugin(x),z(R,{Shape:y,Connection:w,Connector:b,DiagramToolBar:k,QuadNode:D,QuadRoot:T,ShapesQuadTree:A,PopupEditor:S})}(window.kendo.jQuery)}(),window.kendo},"function"==typeof define&&define.amd?define:function(e,t){t()}); |