@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1 lines • 33.4 kB
JavaScript
module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var i=n[t]={exports:{},id:t,loaded:!1};return e[t].call(i.exports,i,i.exports,r),i.loaded=!0,i.exports}return r.m=e,r.c=n,r.p="",r(0)}({0:function(t,i,e){t.exports=e(912)},3:function(t,i){t.exports=function(){throw Error("define cannot be used indirect")}},891:function(t,i){t.exports=require("../../kendo.dataviz.core")},912:function(t,i,e){var n;e(3),e=[e(913),e(891)],void 0===(i="function"==typeof(n=function(){var n=window.kendo.jQuery,e=void 0,w=window.kendo,g=w.dataviz.diagram,t=w.Class,i=w.deepExtend,s,R=g.Utils,k=w.dataviz.Point2D,h=w.isFunction,v=R.contains,o=n.map,a=3,u=1e-6,f=(i(k.fn,{plus:function(t){return new k(this.x+t.x,this.y+t.y)},minus:function(t){return new k(this.x-t.x,this.y-t.y)},offset:function(t){return new k(this.x-t,this.y-t)},times:function(t){return new k(this.x*t,this.y*t)},normalize:function(){if(this.length()===0)return new k;return 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 t(i,e){return new k(e.x-i.x,e.y-i.y).times(.5).plus(i)},toPolar:function(t){var i=1;if(t)i=180/Math.PI;var e=Math.atan2(Math.abs(this.y),Math.abs(this.x));var n=Math.PI/2;var r=this.length();if(this.x===0){if(this.y===0)return new _(0,0);if(this.y>0)return new _(r,i*n);if(this.y<0)return new _(r,i*3*n)}else if(this.x>0){if(this.y===0)return new _(r,0);if(this.y>0)return new _(r,i*e);if(this.y<0)return new _(r,i*(4*n-e))}else{if(this.y===0)return new _(r,2*n);if(this.y>0)return new _(r,i*(2*n-e));if(this.y<0)return new _(r,i*(2*n+e))}},isOnLine:function(t,i){if(t.x>i.x){var e=i;i=t;t=e}var n=new b(t.x,t.y).inflate(a,a),r=new b(i.x,i.y).inflate(a,a),s,h;if(n.union(r).contains(this)){if(t.x===i.x||t.y===i.y)return true;else if(t.y<i.y){s=n.x+(r.x-n.x)*(this.y-(n.y+n.height))/(r.y+r.height-(n.y+n.height));h=n.x+n.width+(r.x+r.width-(n.x+n.width))*(this.y-n.y)/(r.y-n.y)}else{s=n.x+(r.x-n.x)*(this.y-n.y)/(r.y-n.y);h=n.x+n.width+(r.x+r.width-(n.x+n.width))*(this.y-(n.y+n.height))/(r.y+r.height-(n.y+n.height))}return this.x>s&&this.x<h}return false}}),i(k,{parse:function(t){var i=t.slice(1,t.length-1),e=i.split(","),n=parseInt(e[0],10),r=parseInt(e[1],10);if(!isNaN(n)&&!isNaN(r))return new k(n,r)}}),t.extend({init:function(t,i,e){this.point=t;this.left=i;this.right=e}})),b=t.extend({init:function(t,i,e,n){this.x=t||0;this.y=i||0;this.width=e||0;this.height=n||0},contains:function(t){return t.x>=this.x&&t.x<=this.x+this.width&&t.y>=this.y&&t.y<=this.y+this.height},inflate:function(t,i){if(i===e)i=t;this.x-=t;this.y-=i;this.width+=2*t+1;this.height+=2*i+1;return this},offset:function(t,i){var e=t,n=i;if(t instanceof k){e=t.x;n=t.y}this.x+=e;this.y+=n;return this},union:function(t){var i=Math.min(this.x,t.x);var e=Math.min(this.y,t.y);var n=Math.max(this.x+this.width,t.x+t.width);var r=Math.max(this.y+this.height,t.y+t.height);return new b(i,e,n-i,r-e)},center:function(){return new k(this.x+this.width/2,this.y+this.height/2)},top:function(){return new k(this.x+this.width/2,this.y)},right:function(){return new k(this.x+this.width,this.y+this.height/2)},bottom:function(){return new k(this.x+this.width/2,this.y+this.height)},left:function(){return new k(this.x,this.y+this.height/2)},topLeft:function(){return new k(this.x,this.y)},topRight:function(){return new k(this.x+this.width,this.y)},bottomLeft:function(){return new k(this.x,this.y+this.height)},bottomRight:function(){return new k(this.x+this.width,this.y+this.height)},clone:function(){return new b(this.x,this.y,this.width,this.height)},isEmpty:function(){return!this.width&&!this.height},equals:function(t){return this.x===t.x&&this.y===t.y&&this.width===t.width&&this.height===t.height},rotatedBounds:function(t){var i=this.clone(),e=this.rotatedPoints(t),n=e[0],r=e[1],s=e[2],h=e[3];i.x=Math.min(s.x,n.x,r.x,h.x);i.y=Math.min(s.y,n.y,r.y,h.y);i.width=Math.max(s.x,n.x,r.x,h.x)-i.x;i.height=Math.max(s.y,n.y,r.y,h.y)-i.y;return i},rotatedPoints:function(t){var i=this,e=i.center(),n=i.bottomRight().rotate(e,360-t),r=i.topLeft().rotate(e,360-t),s=i.topRight().rotate(e,360-t),h=i.bottomLeft().rotate(e,360-t);return[r,s,n,h]},toString:function(t){t=t||" ";return this.x+t+this.y+t+this.width+t+this.height},scale:function(t,i,e,n,r){var s=this.topLeft();var h=this.center();s.rotate(h,360-r).rotate(n,r);var o=e.minus(s);var a=new k(o.x*t,o.y*i);var u=o.minus(a);s=s.plus(u);s.rotate(n,360-r).rotate(h,r);this.x=s.x;this.y=s.y;this.width*=t;this.height*=i},zoom:function(t){this.x*=t;this.y*=t;this.width*=t;this.height*=t;return this},overlaps:function(t){var i=this.bottomRight();var e=t.bottomRight();var n=!(i.x<t.x||i.y<t.y||e.x<this.x||e.y<this.y);return n}}),d=t.extend({init:function(t,i){this.width=t;this.height=i}});function c(t){return Math.abs(t)<u}function l(t,i,e,n,r){var s=(i.x-t.x)*(n.y-e.y)-(i.y-t.y)*(n.x-e.x);if(c(s))return;var h=(t.y-e.y)*(n.x-e.x)-(t.x-e.x)*(n.y-e.y);var o=(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y);var a=h/s;var u=o/s;if(r&&(a<0||a>1||u<0||u>1))return;return new k(t.x+a*(i.x-t.x),t.y+a*(i.y-t.y))}d.prototype.Empty=new d(0,0),b.toRect=function(t){if(!(t instanceof b))t=new b(t.x,t.y,t.width,t.height);return t},b.empty=function(){return new b(0,0,0,0)},b.fromPoints=function(t,i){if(isNaN(t.x)||isNaN(t.y)||isNaN(i.x)||isNaN(i.y))throw"Some values are NaN.";return new b(Math.min(t.x,i.x),Math.min(t.y,i.y),Math.abs(t.x-i.x),Math.abs(t.y-i.y))};var m={lines:function(t,i,e,n){return l(t,i,e,n)},segments:function(t,i,e,n){return l(t,i,e,n,true)},rectWithLine:function(t,i,e){return m.segments(i,e,t.topLeft(),t.topRight())||m.segments(i,e,t.topRight(),t.bottomRight())||m.segments(i,e,t.bottomLeft(),t.bottomRight())||m.segments(i,e,t.topLeft(),t.bottomLeft())},rects:function(t,i,e){var n=i.topLeft(),r=i.topRight(),s=i.bottomLeft(),h=i.bottomRight();var o=i.center();if(e){n=n.rotate(o,e);r=r.rotate(o,e);s=s.rotate(o,e);h=h.rotate(o,e)}var a=t.contains(n)||t.contains(r)||t.contains(s)||t.contains(h)||m.rectWithLine(t,n,r)||m.rectWithLine(t,n,s)||m.rectWithLine(t,r,h)||m.rectWithLine(t,s,h);if(!a){n=t.topLeft();r=t.topRight();s=t.bottomLeft();h=t.bottomRight();if(e){var u=360-e;n=n.rotate(o,u);r=r.rotate(o,u);s=s.rotate(o,u);h=h.rotate(o,u)}a=i.contains(n)||i.contains(r)||i.contains(s)||i.contains(h)}return a}},x=t.extend({init:function(t){this.container=b.toRect(t)},align:function(t,i){var e=i.toLowerCase().split(" ");for(var n=0;n<e.length;n++)t=this._singleAlign(t,e[n]);return t},_singleAlign:function(t,i){if(h(this[i]))return this[i](t);else return t},left:function(t){return this._align(t,this._left)},center:function(t){return this._align(t,this._center)},right:function(t){return this._align(t,this._right)},stretch:function(t){return this._align(t,this._stretch)},top:function(t){return this._align(t,this._top)},middle:function(t){return this._align(t,this._middle)},bottom:function(t){return this._align(t,this._bottom)},_left:function(t,i){i.x=t.x},_center:function(t,i){i.x=(t.width-i.width)/2||0},_right:function(t,i){i.x=t.width-i.width},_top:function(t,i){i.y=t.y},_middle:function(t,i){i.y=(t.height-i.height)/2||0},_bottom:function(t,i){i.y=t.height-i.height},_stretch:function(t,i){i.x=0;i.y=0;i.height=t.height;i.width=t.width},_align:function(t,i){t=b.toRect(t);i(this.container,t);return t}}),_=t.extend({init:function(t,i){this.r=t;this.angle=i}}),r=t.extend({init:function(t,i,e,n,r,s){this.a=t||0;this.b=i||0;this.c=e||0;this.d=n||0;this.e=r||0;this.f=s||0},plus:function(t){this.a+=t.a;this.b+=t.b;this.c+=t.c;this.d+=t.d;this.e+=t.e;this.f+=t.f},minus:function(t){this.a-=t.a;this.b-=t.b;this.c-=t.c;this.d-=t.d;this.e-=t.e;this.f-=t.f},times:function(t){return new r(this.a*t.a+this.c*t.b,this.b*t.a+this.d*t.b,this.a*t.c+this.c*t.d,this.b*t.c+this.d*t.d,this.a*t.e+this.c*t.f+this.e,this.b*t.e+this.d*t.f+this.f)},apply:function(t){return new k(this.a*t.x+this.c*t.y+this.e,this.b*t.x+this.d*t.y+this.f)},applyRect:function(t){return b.fromPoints(this.apply(t.topLeft()),this.apply(t.bottomRight()))},toString:function(){return"matrix("+this.a+" "+this.b+" "+this.c+" "+this.d+" "+this.e+" "+this.f+")"}}),N=(i(r,{fromSVGMatrix:function(t){var i=new r;i.a=t.a;i.b=t.b;i.c=t.c;i.d=t.d;i.e=t.e;i.f=t.f;return i},fromMatrixVector:function(t){var i=new r;i.a=t.a;i.b=t.b;i.c=t.c;i.d=t.d;i.e=t.e;i.f=t.f;return i},fromList:function(t){if(t.length!==6)throw"The given list should consist of six elements.";var i=new r;i.a=t[0];i.b=t[1];i.c=t[2];i.d=t[3];i.e=t[4];i.f=t[5];return i},translation:function(t,i){var e=new r;e.a=1;e.b=0;e.c=0;e.d=1;e.e=t;e.f=i;return e},unit:function(){return new r(1,0,0,1,0,0)},rotation:function(t,i,e){var n=new r;n.a=Math.cos(t*Math.PI/180);n.b=Math.sin(t*Math.PI/180);n.c=-n.b;n.d=n.a;n.e=i-i*n.a+e*n.b||0;n.f=e-e*n.a-i*n.b||0;return n},scaling:function(t,i){var e=new r;e.a=t;e.b=0;e.c=0;e.d=i;e.e=0;e.f=0;return e},parse:function(t){var i,e;if(t){t=t.trim();if(t.slice(0,6).toLowerCase()==="matrix"){e=t.slice(7,t.length-1).trim();i=e.split(",");if(i.length===6)return r.fromList(o(i,function(t){return parseFloat(t)}));i=e.split(" ");if(i.length===6)return r.fromList(o(i,function(t){return parseFloat(t)}))}if(t.slice(0,1)==="("&&t.slice(t.length-1)===")")t=t.substr(1,t.length-1);if(t.indexOf(",")>0){i=t.split(",");if(i.length===6)return r.fromList(o(i,function(t){return parseFloat(t)}))}if(t.indexOf(" ")>0){i=t.split(" ");if(i.length===6)return r.fromList(o(i,function(t){return parseFloat(t)}))}}return i}}),t.extend({init:function(t,i,e,n,r,s){this.a=t||0;this.b=i||0;this.c=e||0;this.d=n||0;this.e=r||0;this.f=s||0},fromMatrix:function t(i){var e=new N;e.a=i.a;e.b=i.b;e.c=i.c;e.d=i.d;e.e=i.e;e.f=i.f;return e}}));function L(t,i){var e,n,r;do{e=Math.random()*2-1;n=Math.random()*2-1;r=e*e+n*n}while(!r||r>1);return t+i*e*Math.sqrt(-2*Math.log(r)/r)}function T(t){if(R.isUndefined(t))t=10;var i="";var e="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";for(var n=t;n>0;--n)i+=e.charAt(Math.round(Math.random()*(e.length-1)));return i}var U={_distanceToLineSquared:function(t,i,e){function n(t,i){return(t.x-i.x)*(t.x-i.x)+(t.y-i.y)*(t.y-i.y)}if(i===e)return n(t,i);var r=e.x-i.x,s=e.y-i.y,h=(t.x-i.x)*r+(t.y-i.y)*s;if(h<0)return n(i,t);h=(e.x-t.x)*r+(e.y-t.y)*s;if(h<0)return n(e,t);h=(e.x-t.x)*s-(e.y-t.y)*r;return h*h/(r*r+s*s)},distanceToLine:function(t,i,e){return Math.sqrt(this._distanceToLineSquared(t,i,e))},distanceToPolyline:function(t,i){var e=Number.MAX_VALUE;if(R.isUndefined(i)||i.length===0)return Number.MAX_VALUE;for(var n=0;n<i.length-1;n++){var r=i[n];var s=i[n+1];var h=this._distanceToLineSquared(t,r,s);if(h<e)e=h}return Math.sqrt(e)}},C=w.Class.extend({init:function(){this._buckets=[];this.length=0},add:function(t,i){var e=this._createGetBucket(t);if(R.isDefined(i))e.value=i;return e},get:function(t){if(this._bucketExists(t))return this._createGetBucket(t);return null},set:function(t,i){this.add(t,i)},containsKey:function(t){return this._bucketExists(t)},remove:function(t){if(this._bucketExists(t)){var i=this._hash(t);delete this._buckets[i];this.length--;return t}},forEach:function(t){var i=this._hashes();for(var e=0,n=i.length;e<n;e++){var r=i[e];var s=this._buckets[r];if(R.isUndefined(s))continue;t(s)}},clone:function(){var t=new C;var i=this._hashes();for(var e=0,n=i.length;e<n;e++){var r=i[e];var s=this._buckets[r];if(R.isUndefined(s))continue;t.add(s.key,s.value)}return t},_hashes:function(){var t=[];for(var i in this._buckets)if(this._buckets.hasOwnProperty(i))t.push(i);return t},_bucketExists:function(t){var i=this._hash(t);return R.isDefined(this._buckets[i])},_createGetBucket:function(t){var i=this._hash(t);var e=this._buckets[i];if(R.isUndefined(e)){e={key:t};this._buckets[i]=e;this.length++}return e},_hash:function(t){if(R.isNumber(t))return t;if(R.isString(t))return this._hashString(t);if(R.isObject(t))return this._objectHashId(t);throw"Unsupported key type."},_hashString:function(t){var i=0;if(t.length===0)return i;for(var e=0;e<t.length;e++){var n=t.charCodeAt(e);i=i*32-i+n}return i},_objectHashId:function(t){var i=t._hashId;if(R.isUndefined(i)){i=T();t._hashId=i}return i}}),D=w.Observable.extend({init:function(t){var i=this;w.Observable.fn.init.call(i);this._hashTable=new C;this.length=0;if(R.isDefined(t))if(Array.isArray(t))for(var e=0;e<t.length;e++)this.add(t[e]);else t.forEach(function(t,i){this.add(t,i)},this)},add:function(t,i){var e=this._hashTable.get(t);if(!e){e=this._hashTable.add(t);this.length++;this.trigger("changed")}e.value=i},set:function(t,i){this.add(t,i)},get:function(t){var i=this._hashTable.get(t);if(i)return i.value;throw new Error("Cannot find key "+t)},containsKey:function(t){return this._hashTable.containsKey(t)},remove:function(t){if(this.containsKey(t)){this.trigger("changed");this.length--;return this._hashTable.remove(t)}},forEach:function(i,e){this._hashTable.forEach(function(t){i.call(e,t.key,t.value)})},forEachValue:function(i,e){this._hashTable.forEach(function(t){i.call(e,t.value)})},forEachKey:function(i,e){this._hashTable.forEach(function(t){i.call(e,t.key)})},keys:function(){var i=[];this.forEachKey(function(t){i.push(t)});return i}}),M=w.Class.extend({init:function(){this._tail=null;this._head=null;this.length=0},enqueue:function(t){var i={value:t,next:null};if(!this._head){this._head=i;this._tail=this._head}else{this._tail.next=i;this._tail=this._tail.next}this.length++},dequeue:function(){if(this.length<1)throw new Error("The queue is empty.");var t=this._head.value;this._head=this._head.next;this.length--;return t},contains:function(t){var i=this._head;while(i){if(i.value===t)return true;i=i.next}return false}}),E=w.Observable.extend({init:function(t){var i=this;w.Observable.fn.init.call(i);this._hashTable=new C;this.length=0;if(R.isDefined(t))if(t instanceof C)t.forEach(function(t){this.add(t)});else if(t instanceof D)t.forEach(function(t,i){this.add({key:t,value:i})},this)},contains:function(t){return this._hashTable.containsKey(t)},add:function(t){var i=this._hashTable.get(t);if(!i){this._hashTable.add(t,t);this.length++;this.trigger("changed")}},get:function(t){if(this.contains(t))return this._hashTable.get(t).value;else return null},hash:function(t){return this._hashTable._hash(t)},remove:function(t){if(this.contains(t)){this._hashTable.remove(t);this.length--;this.trigger("changed")}},forEach:function(i,t){this._hashTable.forEach(function(t){i(t.value)},t)},toArray:function(){var i=[];this.forEach(function(t){i.push(t)});return i}}),p=w.Class.extend({init:function(t,i){this.links=[];this.outgoing=[];this.incoming=[];this.weight=1;if(R.isDefined(t))this.id=t;else this.id=T();if(R.isDefined(i)){this.associatedShape=i;var e=i.bounds();this.width=e.width;this.height=e.height;this.x=e.x;this.y=e.y}else this.associatedShape=null;this.data=null;this.type="Node";this.shortForm="Node '"+this.id+"'";this.isVirtual=false},isIsolated:function(){return R.isEmpty(this.links)},bounds:function(t){if(!R.isDefined(t))return new g.Rect(this.x,this.y,this.width,this.height);this.x=t.x;this.y=t.y;this.width=t.width;this.height=t.height},isLinkedTo:function(i){var e=this;return R.any(e.links,function(t){return t.getComplement(e)===i})},getChildren:function(){if(this.outgoing.length===0)return[];var t=[];for(var i=0,e=this.outgoing.length;i<e;i++){var n=this.outgoing[i];t.push(n.getComplement(this))}return t},getParents:function(){if(this.incoming.length===0)return[];var t=[];for(var i=0,e=this.incoming.length;i<e;i++){var n=this.incoming[i];t.push(n.getComplement(this))}return t},clone:function(){var t=new p;if(R.isDefined(this.weight))t.weight=this.weight;if(R.isDefined(this.balance))t.balance=this.balance;if(R.isDefined(this.owner))t.owner=this.owner;t.associatedShape=this.associatedShape;t.x=this.x;t.y=this.y;t.width=this.width;t.height=this.height;return t},adjacentTo:function(t){return this.isLinkedTo(t)!==null},removeLink:function(t){if(t.source===this){R.remove(this.links,t);R.remove(this.outgoing,t);t.source=null}if(t.target===this){R.remove(this.links,t);R.remove(this.incoming,t);t.target=null}},hasLinkTo:function(i){return R.any(this.outgoing,function(t){return t.target===i})},degree:function(){return this.links.length},incidentWith:function(t){return v(this.links,t)},getLinksWith:function(i){return R.all(this.links,function(t){return t.getComplement(this)===i},this)},getNeighbors:function(){var i=[];R.forEach(this.incoming,function(t){i.push(t.getComplement(this))},this);R.forEach(this.outgoing,function(t){i.push(t.getComplement(this))},this);return i}}),S=w.Class.extend({init:function(t,i,e,n){if(R.isUndefined(t))throw"The source of the new link is not set.";if(R.isUndefined(i))throw"The target of the new link is not set.";var r,s;if(R.isString(t))r=new p(t);else r=t;if(R.isString(i))s=new p(i);else s=i;this.source=r;this.target=s;this.source.links.push(this);this.target.links.push(this);this.source.outgoing.push(this);this.target.incoming.push(this);if(R.isDefined(e))this.id=e;else this.id=T();if(R.isDefined(n))this.associatedConnection=n;else this.associatedConnection=null;this.type="Link";this.shortForm="Link '"+this.source.id+"->"+this.target.id+"'"},getComplement:function(t){if(this.source!==t&&this.target!==t)throw"The given node is not incident with this link.";return this.source===t?this.target:this.source},getCommonNode:function(t){if(this.source===t.source||this.source===t.target)return this.source;if(this.target===t.source||this.target===t.target)return this.target;return null},isBridging:function(t,i){return this.source===t&&this.target===i||this.source===i&&this.target===t},getNodes:function(){return[this.source,this.target]},incidentWith:function(t){return this.source===t||this.target===t},adjacentTo:function(t){return v(this.source.links,t)||v(this.target.links,t)},changeSource:function(t){R.remove(this.source.links,this);R.remove(this.source.outgoing,this);t.links.push(this);t.outgoing.push(this);this.source=t},changeTarget:function(t){R.remove(this.target.links,this);R.remove(this.target.incoming,this);t.links.push(this);t.incoming.push(this);this.target=t},changesNodes:function(t,i){if(this.source===t)this.changeSource(i);else if(this.target===t)this.changeTarget(i)},reverse:function(){var t=this.source;var i=this.target;this.source=i;R.remove(t.outgoing,this);this.source.outgoing.push(this);this.target=t;R.remove(i.incoming,this);this.target.incoming.push(this);return this},directTo:function(t){if(this.source!==t&&this.target!==t)throw"The given node is not incident with this link.";if(this.target!==t)this.reverse()},createReverseEdge:function(){var t=this.clone();t.reverse();t.reversed=true;return t},clone:function(){var t=new S(this.source,this.target);return t}}),y=w.Class.extend({init:function(t){this.links=[];this.nodes=[];this._nodeMap=new D;this.diagram=null;this._root=null;if(R.isDefined(t))if(R.isString(t))this.id=t;else{this.diagram=t;this.id=t.id}else this.id=T();this.bounds=new b;this._hasCachedRelationships=false;this.type="Graph"},cacheRelationships:function(t){if(R.isUndefined(t))t=false;if(this._hasCachedRelationships&&!t)return;for(var i=0,e=this.nodes.length;i<e;i++){var n=this.nodes[i];n.children=this.getChildren(n);n.parents=this.getParents(n)}this._hasCachedRelationships=true},assignLevels:function(t,i,e){if(!t)throw"Start node not specified.";if(R.isUndefined(i))i=0;this.cacheRelationships();if(R.isUndefined(e)){e=new D;R.forEach(this.nodes,function(t){e.add(t,false)})}e.set(t,true);t.level=i;var n=t.children;for(var r=0,s=n.length;r<s;r++){var h=n[r];if(!h||e.get(h))continue;this.assignLevels(h,i+1,e)}},root:function(t){if(R.isUndefined(t))if(!this._root){var i=R.first(this.nodes,function(t){return t.incoming.length===0});if(i)return i;return R.first(this.nodes)}else return this._root;else this._root=t},getConnectedComponents:function(){this.componentIndex=0;this.setItemIndices();var t=R.initArray(this.nodes.length,-1);for(var i=0;i<this.nodes.length;i++)if(t[i]===-1){this._collectConnectedNodes(t,i);this.componentIndex++}var e=[],n;for(n=0;n<this.componentIndex;++n)e[n]=new y;for(n=0;n<t.length;++n){var r=e[t[n]];r.addNodeAndOutgoings(this.nodes[n])}e.sort(function(t,i){return i.nodes.length-t.nodes.length});return e},_collectConnectedNodes:function(n,t){n[t]=this.componentIndex;var r=this.nodes[t];R.forEach(r.links,function(t){var i=t.getComplement(r);var e=i.index;if(n[e]===-1)this._collectConnectedNodes(n,e)},this)},calcBounds:function(){if(this.isEmpty()){this.bounds=new b;return this.bounds}var t=null;for(var i=0,e=this.nodes.length;i<e;i++){var n=this.nodes[i];if(!t)t=n.bounds();else t=t.union(n.bounds())}this.bounds=t;return this.bounds},getSpanningTree:function(t){var i=new y;var e=new D,n,r;i.root=t.clone();i.root.level=0;i.root.id=t.id;e.add(t,i.root);t.level=0;var s=[];var h=[];i._addNode(i.root);s.push(t);h.push(t);var o=1;while(h.length>0){var a=h.pop();for(var f=0;f<a.links.length;f++){var d=a.links[f];var u=d.getComplement(a);if(v(s,u))continue;u.level=a.level+1;if(o<u.level+1)o=u.level+1;if(!v(h,u))h.push(u);if(!v(s,u))s.push(u);if(e.containsKey(a))n=e.get(a);else{n=a.clone();n.level=a.level;n.id=a.id;e.add(a,n)}if(e.containsKey(u))r=e.get(u);else{r=u.clone();r.level=u.level;r.id=u.id;e.add(u,r)}var c=new S(n,r);i.addLink(c)}}var l=[];for(var g=0;g<o;g++)l.push([]);R.forEach(i.nodes,function(t){l[t.level].push(t)});i.treeLevels=l;i.cacheRelationships();return i},takeRandomNode:function(i,e){if(R.isUndefined(i))i=[];if(R.isUndefined(e))e=4;if(this.nodes.length===0)return null;if(this.nodes.length===1)return v(i,this.nodes[0])?null:this.nodes[0];var t=n.grep(this.nodes,function(t){return!v(i,t)&&t.degree()<=e});if(R.isEmpty(t))return null;return t[R.randomInteger(0,t.length)]},isEmpty:function(){return R.isEmpty(this.nodes)},isHealthy:function(){return R.all(this.links,function(t){return v(this.nodes,t.source)&&v(this.nodes,t.target)},this)},getParents:function(t){if(!this.hasNode(t))throw"The given node is not part of this graph.";return t.getParents()},getChildren:function(t){if(!this.hasNode(t))throw"The given node is not part of this graph.";return t.getChildren()},addLink:function(t,i,e){if(R.isUndefined(t))throw"The source of the link is not defined.";if(R.isUndefined(i))if(R.isDefined(t.type)&&t.type==="Link"){this.addExistingLink(t);return}else throw"The target of the link is not defined.";var n=this.getNode(t);if(R.isUndefined(n))n=this.addNode(t);var r=this.getNode(i);if(R.isUndefined(r))r=this.addNode(i);var s=new S(n,r);if(R.isDefined(e))s.owner=e;this.links.push(s);return s},removeAllLinks:function(){while(this.links.length>0){var t=this.links[0];this.removeLink(t)}},addExistingLink:function(t){if(this.hasLink(t))return;this.links.push(t);if(this.hasNode(t.source.id)){var i=this.getNode(t.source.id);t.changeSource(i)}else this.addNode(t.source);if(this.hasNode(t.target.id)){var e=this.getNode(t.target.id);t.changeTarget(e)}else this.addNode(t.target)},hasLink:function(i){if(R.isString(i))return R.any(this.links,function(t){return t.id===i});if(i.type==="Link")return v(this.links,i);throw"The given object is neither an identifier nor a Link."},getNode:function(t){var i=t.id||t;if(this._nodeMap.containsKey(i))return this._nodeMap.get(i)},hasNode:function(t){var i=t.id||t;return this._nodeMap.containsKey(i)},_addNode:function(t){this.nodes.push(t);this._nodeMap.add(t.id,t)},_removeNode:function(t){R.remove(this.nodes,t);this._nodeMap.remove(t.id)},removeNode:function(t){var i=t;if(R.isString(t))i=this.getNode(t);if(R.isDefined(i)){var e=i.links;i.links=[];for(var n=0,r=e.length;n<r;n++){var s=e[n];this.removeLink(s)}this._removeNode(i)}else throw"The identifier should be a Node or the Id (string) of a node."},areConnected:function(i,e){return R.any(this.links,function(t){return t.source==i&&t.target==e||t.source==e&&t.target==i})},removeLink:function(t){R.remove(this.links,t);R.remove(t.source.outgoing,t);R.remove(t.source.links,t);R.remove(t.target.incoming,t);R.remove(t.target.links,t)},addNode:function(t,i,e){var n=null;if(!R.isDefined(t))throw"No Node or identifier for a new Node is given.";if(R.isString(t)){if(this.hasNode(t))return this.getNode(t);n=new p(t)}else{if(this.hasNode(t))return this.getNode(t);n=t}if(R.isDefined(i))n.bounds(i);if(R.isDefined(e))n.owner=e;this._addNode(n);return n},addNodeAndOutgoings:function(t){if(!this.hasNode(t))this._addNode(t);var i=t.outgoing;t.outgoing=[];R.forEach(i,function(t){this.addExistingLink(t)},this)},setItemIndices:function(){var t;for(t=0;t<this.nodes.length;++t)this.nodes[t].index=t;for(t=0;t<this.links.length;++t)this.links[t].index=t},clone:function(t){var e=new y;var n=R.isDefined(t)&&t===true;if(n){e.nodeMap=new D;e.linkMap=new D}var r=new D;R.forEach(this.nodes,function(t){var i=t.clone();r.set(t,i);e._addNode(i);if(n)e.nodeMap.set(i,t)});R.forEach(this.links,function(t){if(r.containsKey(t.source)&&r.containsKey(t.target)){var i=e.addLink(r.get(t.source),r.get(t.target));if(n)e.linkMap.set(i,t)}});return e},linearize:function(t){return y.Utils.linearize(this,t)},depthFirstTraversal:function(t,i){if(R.isUndefined(t))throw"You need to supply a starting node.";if(R.isUndefined(i))throw"You need to supply an action.";if(!this.hasNode(t))throw"The given start-node is not part of this graph";var e=this.getNode(t);var n=[];this._dftIterator(e,i,n)},_dftIterator:function(t,i,e){i(t);e.push(t);var n=t.getChildren();for(var r=0,s=n.length;r<s;r++){var h=n[r];if(v(e,h))continue;this._dftIterator(h,i,e)}},breadthFirstTraversal:function(t,i){if(R.isUndefined(t))throw"You need to supply a starting node.";if(R.isUndefined(i))throw"You need to supply an action.";if(!this.hasNode(t))throw"The given start-node is not part of this graph";var e=this.getNode(t);var n=new M;var r=[];n.enqueue(e);while(n.length>0){var s=n.dequeue();i(s);r.push(s);var h=s.getChildren();for(var o=0,a=h.length;o<a;o++){var u=h[o];if(v(r,u)||v(n,u))continue;n.enqueue(u)}}},_stronglyConnectedComponents:function(t,i,e,n,r,s,h){e.add(i,h);n.add(i,h);h++;s.push(i);var f=i.getChildren(),o;for(var a=0,d=f.length;a<d;a++){o=f[a];if(!e.containsKey(o)){this._stronglyConnectedComponents(t,o,e,n,r,s,h);n.add(i,Math.min(n.get(i),n.get(o)))}else if(v(s,o))n.add(i,Math.min(n.get(i),e.get(o)))}if(n.get(i)===e.get(i)){var u=[];do{o=s.pop();u.push(o)}while(o!==i);if(!t||u.length>1)r.push(u)}},findCycles:function(t){if(R.isUndefined(t))t=true;var i=new D;var e=new D;var n=[];var r=[];for(var s=0,h=this.nodes.length;s<h;s++){var o=this.nodes[s];if(i.containsKey(o))continue;this._stronglyConnectedComponents(t,o,i,e,n,r,0)}return n},isAcyclic:function(){return R.isEmpty(this.findCycles())},isSubGraph:function(t){var i=t.linearize();var e=this.linearize();return R.all(i,function(t){return v(e,t)})},makeAcyclic:function(){if(this.isEmpty()||this.nodes.length<=1||this.links.length<=1)return[];if(this.nodes.length==2){var f=[];if(this.links.length>1){var d=this.links[0];var c=d.source;for(var l=0,g=this.links.length;l<g;l++){var v=this.links[l];if(v.source==c)continue;var p=v.reverse();f.push(p)}}return f}var t=this.clone(true);var n=this.nodes.length;var i=new D;var r=function(t){if(t.outgoing.length===0)return 2-n;else if(t.incoming.length===0)return n-2;else return t.outgoing.length-t.incoming.length};var y=function(t,i){var e=r(t,n);if(!i.containsKey(e))i.set(e,[]);i.get(e).push(t)};R.forEach(t.nodes,function(t){y(t,i)});var e=[];var m=[];while(t.nodes.length>0){var s,h,o;if(i.containsKey(2-n)){var x=i.get(2-n);while(x.length>0){h=x.pop();for(var w=0;w<h.links.length;w++){var k=h.links[w];s=k.getComplement(h);o=r(s,n);R.remove(i.get(o),s);s.removeLink(k);y(s,i)}t._removeNode(h);m.unshift(h)}}if(i.containsKey(n-2)){var b=i.get(n-2);while(b.length>0){s=b.pop();for(var _=0;_<s.links.length;_++){var N=s.links[_];h=N.getComplement(s);o=r(h,n);R.remove(i.get(o),h);h.removeLink(N);y(h,i)}e.push(s);t._removeNode(s)}}if(t.nodes.length>0)for(var a=n-3;a>2-n;a--)if(i.containsKey(a)&&i.get(a).length>0){var L=i.get(a);var u=L.pop();for(var T=0;T<u.links.length;T++){var U=u.links[T];var C=U.getComplement(u);o=r(C,n);R.remove(i.get(o),C);C.removeLink(U);y(C,i)}e.push(u);t._removeNode(u);break}}e=e.concat(m);var M=new D;for(var E=0;E<this.nodes.length;E++)M.set(t.nodeMap.get(e[E]),E);var S=[];R.forEach(this.links,function(t){if(M.get(t.source)>M.get(t.target)){t.reverse();S.push(t)}});return S}});y.Predefined={EightGraph:function(){return y.Utils.parse(["1->2","2->3","3->4","4->1","3->5","5->6","6->7","7->3"])},Mindmap:function(){return y.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 y.Utils.parse(["1->2","2->3","3->1"])},BinaryTree:function(t){if(R.isUndefined(t))t=5;return y.Utils.createBalancedTree(t,2)},Linear:function(t){if(R.isUndefined(t))t=10;return y.Utils.createBalancedTree(t,1)},Tree:function(t,i){return y.Utils.createBalancedTree(t,i)},Forest:function(t,i,e){return y.Utils.createBalancedForest(t,i,e)},Workflow:function(){return y.Utils.parse(["0->1","1->2","2->3","1->4","4->3","3->5","5->6","6->3","6->7","5->4"])},Grid:function(t,i){var e=new g.Graph;if(t<=0&&i<=0)return e;for(var n=0;n<t+1;n++){var r=null;for(var s=0;s<i+1;s++){var h=new p(n.toString()+"."+s.toString());e.addNode(h);if(r)e.addLink(r,h);if(n>0){var o=e.getNode((n-1).toString()+"."+s.toString());e.addLink(o,h)}r=h}}return e}},y.Utils={parse:function(t){var i,e=new g.Graph,n=t.slice();for(var r=0,s=n.length;r<s;r++){var h=n[r];if(R.isString(h)){if(h.indexOf("->")<0)throw"The link should be specified as 'a->b'.";var o=h.split("->");if(o.length!=2)throw"The link should be specified as 'a->b'.";i=new S(o[0],o[1]);e.addLink(i)}if(R.isObject(h)){if(!i)throw"Specification found before Link definition.";w.deepExtend(i,h)}}return e},linearize:function(t,i){if(R.isUndefined(t))throw"Expected an instance of a Graph object in slot one.";if(R.isUndefined(i))i=false;var e=[];for(var n=0,r=t.links.length;n<r;n++){var s=t.links[n];e.push(s.source.id+"->"+s.target.id);if(i)e.push({id:s.id})}return e},_addShape:function(t,i,e,n){if(R.isUndefined(i))i=new g.Point(0,0);if(R.isUndefined(e))e=T();n=w.deepExtend({width:20,height:20,id:e,radius:10,fill:"#778899",data:"circle",undoable:false,x:i.x,y:i.y},n);return t.addShape(n)},_addConnection:function(t,i,e,n){return t.connect(i,e,n)},createDiagramFromGraph:function(t,i,e,n){if(R.isUndefined(t))throw"The diagram surface is undefined.";if(R.isUndefined(i))throw"No graph specification defined.";if(R.isUndefined(e))e=true;if(R.isUndefined(n))n=false;var f=t.element.clientWidth||200;var d=t.element.clientHeight||200;var r=[],s,h;for(var o=0,c=i.nodes.length;o<c;o++){s=i.nodes[o];var a=s.position;if(R.isUndefined(a))if(R.isDefined(s.x)&&R.isDefined(s.y))a=new k(s.x,s.y);else a=new k(R.randomInteger(10,f-20),R.randomInteger(10,d-20));var l={};if(s.id==="0");else if(n)w.deepExtend(l,{width:Math.random()*150+20,height:Math.random()*80+50,data:"rectangle",fill:{color:"#778899"}});h=this._addShape(t,a,s.id,l);var u=h.bounds();if(R.isDefined(u)){s.x=u.x;s.y=u.y;s.width=u.width;s.height=u.height}r[s.id]=h}for(var g=0;g<i.links.length;g++){var v=i.links[g];var p=r[v.source.id];if(R.isUndefined(p))continue;var y=r[v.target.id];if(R.isUndefined(y))continue;this._addConnection(t,p,y,{id:v.id})}if(e){var m=new t.SpringLayout(t);m.layoutGraph(i,{limitToView:false});for(var x=0;x<i.nodes.length;x++){s=i.nodes[x];h=r[s.id];h.bounds(new b(s.x,s.y,s.width,s.height))}}},createBalancedTree:function(t,i){if(R.isUndefined(t))t=3;if(R.isUndefined(i))i=3;var e=new g.Graph,n=-1,r=[],s;if(t<=0||i<=0)return e;var h=new p((++n).toString());e.addNode(h);e.root=h;r.push(h);for(var o=0;o<t;o++){s=[];for(var a=0;a<r.length;a++){var f=r[a];for(var u=0;u<i;u++){var d=new p((++n).toString());e.addLink(f,d);s.push(d)}}r=s}return e},createBalancedForest:function(t,i,e){if(R.isUndefined(t))t=3;if(R.isUndefined(i))i=3;if(R.isUndefined(e))e=5;var n=new g.Graph,r=-1,s=[],h;if(t<=0||i<=0||e<=0)return n;for(var o=0;o<e;o++){var a=new p((++r).toString());n.addNode(a);s=[a];for(var f=0;f<t;f++){h=[];for(var u=0;u<s.length;u++){var d=s[u];for(var c=0;c<i;c++){var l=new p((++r).toString());n.addLink(d,l);h.push(l)}}s=h}}return n},createRandomConnectedGraph:function(t,i,e){if(R.isUndefined(t))t=40;if(R.isUndefined(i))i=4;if(R.isUndefined(e))e=false;var n=new g.Graph,r=-1;if(t<=0)return n;var f=new p((++r).toString());n.addNode(f);if(t===1)return n;if(t>1){for(var s=1;s<t;s++){var h=n.takeRandomNode([],i);if(!h)break;var d=n.addNode(s.toString());n.addLink(h,d)}if(!e&&t>1){var c=R.randomInteger(1,t);for(var o=0;o<c;o++){var a=n.takeRandomNode([],i);var u=n.takeRandomNode([],i);if(a&&u&&!n.areConnected(a,u))n.addLink(a,u)}}return n}},randomDiagram:function(t,i,e,n,r){var s=w.dataviz.diagram.Graph.Utils.createRandomConnectedGraph(i,e,n);y.Utils.createDiagramFromGraph(t,s,false,r)}},w.deepExtend(g,{init:function(t){w.init(t,g.ui)},Point:k,Intersect:m,Geometry:U,Rect:b,Size:d,RectAlign:x,Matrix:r,MatrixVector:N,normalVariable:L,randomId:T,Dictionary:D,HashTable:C,Queue:M,Set:E,Node:p,Link:S,Graph:y,PathDefiner:f})})?n.apply(i,e):n)||(t.exports=i)},913:function(t,i){t.exports=require("./utils")}});