-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.layout.treeLayout.min.js
More file actions
14 lines (8 loc) · 22.2 KB
/
joint.layout.treeLayout.min.js
File metadata and controls
14 lines (8 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! Rappid v3.1.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2020-06-11
This Source Code Form is subject to the terms of the Rappid Trial License
, v. 2.0. If a copy of the Rappid License was not distributed with this
file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
this.joint=this.joint||{},function(t,i,r){"use strict";function e(t,i,e){e=r.util.defaults(e||{},{siblingGap:0}),this.width=0,this.height=0,this.layoutAreas=this.sortLayoutAreas(t),this.parentArea=i,this.siblingGap=e.siblingGap,this.exists()&&this.computeSize(e)}i=i&&i.hasOwnProperty("default")?i.default:i,r.util.assign(e.prototype,{sortLayoutAreas:function(t){var i=r.util.sortBy(t,"siblingRank");return i.forEach(function(t,i){t.siblingRank=i}),i},move:function(t,i){for(var e=0,n=this.layoutAreas.length;e<n;e++)this.layoutAreas[e].dx+=t,this.layoutAreas[e].dy+=i},exists:function(){return 0<this.layoutAreas.length},sumGaps:function(t){return Math.max(this.layoutAreas.length-1,0)*t},getSiblingRankByPoint:function(t){if(!this.exists())return-1;var i=this.findAreaByPoint(t);return i?i.siblingRank-1:this.layoutAreas.length-1},getFirstChildConnectionPoints:function(){return[]},getConnectionPoints:function(t,i){if(!this.exists())return this.getFirstChildConnectionPoints(t);var e={dx:t.x-this.parentArea.rootCX,dy:t.y-this.parentArea.rootCY};return this.layoutAreas[0].getRootVertices(e,i)},getParentConnectionPoint:function(){var t=this.parentArea,i=this.proxyLayoutArea("getConnectionPoint",t.rootSize);return r.g.point(t.rootCX,t.rootCY).offset(i.x,i.y)},getChildConnectionPoint:function(t,i){var e=this.proxyLayoutArea("getConnectionPoint",i);return r.g.point(t).difference(e)},proxyLayoutArea:function(t){var i=Array.prototype.slice.call(arguments,1);return b.fromDirection(this.direction).prototype[t].apply(this.parentArea,i)}}),e.extend=i.Model.extend;var n=e.extend({getTopDY:function(){return-this.height/2},findAreaByPoint:function(i){return this.layoutAreas.find(function(t){return t.rootCY>i.y})},computeSize:function(e){this.height=this.sumGaps(e.siblingGap);var t=this.layoutAreas;this.height+=t.reduce(function(t,i){return t+i.height+i.prevSiblingGap+i.nextSiblingGap},0),t.reduce(function(t,i){return this.width=Math.max(this.width,i.getExtendedWidth()),i.dy+=t+i.getCY(),t+i.prevSiblingGap+i.height+i.nextSiblingGap+e.siblingGap}.bind(this),this.getTopDY())},getYTowardsParent:function(){return this.parentArea.rootCY},getXTowardsParent:function(){var t=this.parentArea;return t.rootCX+this.LRSign*(t.rootSize.width/2+t.gap)},getNeighborPointFromRank:function(t){var i,e=this.siblingGap;if(this.exists()){var n=this.layoutAreas[t],o=this.layoutAreas[t+1];i=n?o?(n.y+n.height+o.y)/2:n.y+n.height+e/2:o.y-e/2}else i=this.getYTowardsParent();return{x:this.getXTowardsParent(),y:i}}}),o=n.extend({direction:"L",LRSign:-1}),s=n.extend({direction:"R",LRSign:1}),h={getXTowardsParent:function(){var t=this.parentArea;return t.rootCX+this.LRSign*t.gap},getYTowardsParent:function(){var t=this.parentArea,i=t.getLRHeight(t.siblings)/2;return i+=Math.min(t.firstChildGap,this.siblingGap/2),t.rootCY+this.TBSign*i},getFirstChildConnectionPoints:function(t){return[r.g.point(this.parentArea.rootCX,t.y)]},getChildConnectionPoint:function(t,i){return r.g.point(t).offset(-this.LRSign*i.width/2,0)},getParentConnectionPoint:function(){var t=this.parentArea;return r.g.point(t.rootCX,t.rootCY).offset(0,this.TBSign*(t.rootSize.height-t.rootMargin)/2)}},a={getTopDY:function(){return 0}},g={getTopDY:function(){return-this.height}},u=n.extend({direction:"BR",LRSign:1,TBSign:1});r.util.assign(u.prototype,h,a);var c=n.extend({direction:"BL",LRSign:-1,TBSign:1});r.util.assign(c.prototype,h,a);var d=n.extend({direction:"TR",LRSign:1,TBSign:-1});r.util.assign(d.prototype,h,g);var l=n.extend({direction:"TL",LRSign:-1,TBSign:-1});r.util.assign(l.prototype,h,g);var f=e.extend({getLeftDX:function(){return-this.width/2},findAreaByPoint:function(i){return this.layoutAreas.find(function(t){return t.rootCX>i.x})},computeSize:function(e){this.width=this.sumGaps(e.siblingGap);var t=this.layoutAreas;this.width+=t.reduce(function(t,i){return t+i.width+i.prevSiblingGap+i.nextSiblingGap},0),t.reduce(function(t,i){return this.height=Math.max(this.height,i.getExtendedHeight()),i.dx+=t+i.getCX(),t+i.prevSiblingGap+i.width+i.nextSiblingGap+e.siblingGap}.bind(this),this.getLeftDX())},getNeighborPointFromRank:function(t){var i;if(this.exists()){var e=this.layoutAreas[t],n=this.layoutAreas[t+1];i=e?n?(e.x+e.width+n.x)/2:e.x+e.width+this.siblingGap/2:n.x-this.siblingGap/2}else i=this.parentArea.rootCX;return{x:i,y:this.getYTowardsParent()}}}),p=f.extend({direction:"T",getYTowardsParent:function(){var t=this.parentArea;return t.rootCY-t.getLRHeight()/2-t.gap}}),v=f.extend({direction:"B",getYTowardsParent:function(){var t=this.parentArea;return t.rootCY+t.getLRHeight()/2+t.gap}});function b(t,i){this.root=t;var e=r.util.assign({},i,this.getRootAttributes(t,i.attributeNames)),n=i.gap||0;r.util.defaults(e,{parentGap:n,siblingGap:n,firstChildGap:n}),this.siblingRank=e.siblingRank,this.rootOffset=e.rootOffset,this.rootMargin=e.rootMargin,this.siblingGap=e.siblingGap,this.gap=this.parentGap=e.parentGap,this.nextSiblingGap=e.nextSiblingGap,this.prevSiblingGap=e.prevSiblingGap,this.firstChildGap=e.firstChildGap,this.dx=0,this.dy=0,this.width=0,this.height=0}r.util.assign(b,{create:function(t,i,e){return new(b.fromDirection(t,e))(i,e)},fromDirection:function(t,i){var e;switch(t){case"L":e=R;break;case"T":e=x;break;case"R":e=m;break;case"B":e=y;break;case"BR":e=S;break;case"BL":e=A;break;case"TR":e=C;break;case"TL":e=B;break;default:e=b}return e}}),r.util.assign(b.prototype,{direction:null,compute:function(t){this.childAreas=t,this.computeRelativePosition(this.root,t)},getHeight:function(t,i){return this.getTHeight(t)+this.getBHeight(t)+this.getLRHeight()},getWidth:function(t,i){var e=Math.max(t.T.width,t.B.width)/2;return Math.max(this.getLWidth(t,i)+i.width/2,e)+Math.max(this.getRWidth(t,i)+i.width/2,e)},getLRHeight:function(){return Math.max(this.rootSize.height,this.siblings.L.height,this.siblings.R.height)},getTHeight:function(t){return t.T.height+this.getTXHeight(t)},getBHeight:function(t){return t.B.height+this.getBXHeight(t)},getXLRWidth:function(t,i){return this.getLWidth(t,i)+i.width+this.getRWidth(t,i)},getXRWidth:function(t,i){var e=Math.max(t.BR.width,t.TR.width);return 0<e&&(e-=i.width/2),e},getTXHeight:function(t){var i=Math.max(t.TR.height,t.TL.height);return 0<i&&(i+=this.firstChildGap),i},getBXHeight:function(t){var i=Math.max(t.BR.height,t.BL.height);return 0<i&&(i+=this.firstChildGap),i},getXLWidth:function(t,i){var e=Math.max(t.BL.width,t.TL.width);return 0<e&&(e-=i.width/2),e},getRWidth:function(t,i){return Math.max(t.R.width,this.getXRWidth(t,i))},getLWidth:function(t,i){return Math.max(t.L.width,this.getXLWidth(t,i))},getTBOverlap:function(t,i){var e=Math.max(t.T.width,t.B.width);return 0<e&&(e-=i.width,e/=2),e},getRootDX:function(t,i){var e=this.getTBOverlap(t,i),n=Math.max(this.getLWidth(t,i),e);return(n-=Math.max(this.getRWidth(t,i),e))/2},getMinimalGap:function(t){return Math.min(t.siblingGap,this.firstChildGap,this.parentGap)},getBBox:function(t){var i=r.g.rect(this),e=t&&t.expandBy;return e&&i.moveAndExpand({x:-e,y:-e,width:2*e,height:2*e}),i},containsPoint:function(t,i){return this.getBBox(i).containsPoint(t)},getLayoutSiblings:function(t){return this.siblings[t]},getExtendedWidth:function(){return this.width+this.gap+this.rootOffset},getExtendedHeight:function(){return this.height+this.gap+this.rootOffset},findMinimalAreaByPoint:function(i,e){return this.containsPoint(i,e)?(this.childAreas.some(function(t){return!!(n=t.findMinimalAreaByPoint(i,e))}),n||this):null;var n},getType:function(){return Object.keys(this.siblings).reduce(function(t,i){return this.siblings[i].exists()?t.concat(i):t}.bind(this),[]).sort().join("-")},getRootAttributes:function(t,i){var e={rootOffset:t.get(i.offset||"offset")||0,rootMargin:t.get(i.margin||"margin")||0,prevSiblingGap:t.get(i.prevSiblingGap||"prevSiblingGap")||0,nextSiblingGap:t.get(i.nextSiblingGap||"nextSiblingGap")||0},n=t.get(i.siblingRank||"siblingRank");r.util.isNumber(n)&&(e.siblingRank=n);var o=t.get(i.firstChildGap||"firstChildGap");return r.util.isNumber(o)&&(e.firstChildGap=o),e},getRootSize:function(t,i){var e=t.size();return e[this.marginDimension]+=i,e},createSiblings:function(t,i){var e=r.util.groupBy(t,"direction");return{L:new o(e.L,this,i),T:new p(e.T,this,i),R:new s(e.R,this,i),B:new v(e.B,this,i),BR:new u(e.BR,this,i),BL:new c(e.BL,this,i),TR:new d(e.TR,this,i),TL:new l(e.TL,this,i)}},computeSize:function(t,i){return{width:this.getWidth(t,i),height:this.getHeight(t,i)}},computeOrigin:function(){var t=this.siblings,i=this.rootSize,e=Math.max(this.getLWidth(t,i)+i.width/2,this.getXLWidth(t,i)+i.width/2,t.T.width/2,t.B.width/2);return{x:this.rootCX-e,y:this.rootCY-this.getTHeight(t)-this.getLRHeight()/2}},moveSiblings:function(t,i){if(this.hasHorizontalSiblings(t)){var e=i.width/2;t.L.move(-e,0),t.R.move(e,0)}if(this.hasVerticalSiblings(t)){var n=this.getLRHeight()/2;t.T.move(0,-n),t.B.move(0,n),t.BR.move(0,n),t.BL.move(0,n),t.B.move(0,this.getBXHeight(t)),t.TR.move(0,-n),t.TL.move(0,-n),t.T.move(0,-this.getTXHeight(t))}},moveRootToConnectionPoint:function(t){var i=this.getConnectionPoint(t);this.dx+=i.x,this.dy+=i.y},computeRelativePosition:function(t,i){var e=this.siblings=this.createSiblings(i,{siblingGap:this.siblingGap}),n=this.rootSize=this.getRootSize(t,this.rootMargin);r.util.assign(this,this.computeSize(e,n)),this.moveSiblings(e,n),this.moveRootToConnectionPoint(n),this.moveRootBehindSiblings(e,n),this.moveRootFromParent()},computeAbsolutePosition:function(){if(this.parentArea)this.rootCX=this.parentArea.rootCX+this.dx,this.rootCY=this.parentArea.rootCY+this.dy,this.level=this.parentArea.level+1;else{var t=this.root.getBBox().center();this.rootCX=t.x,this.rootCY=t.y,this.level=0}r.util.assign(this,this.computeOrigin())},hasVerticalSiblings:function(t){return t.T.exists()||t.B.exists()||t.BR.exists()||t.BL.exists()||t.TR.exists()||t.TL.exists()},hasHorizontalSiblings:function(t){return t.L.exists()||t.R.exists()},isSourceArea:function(){return!this.parentArea},isSinkArea:function(){return 0===this.childAreas.length},getRootPosition:function(){var t=this.root.get("size");return{x:this.rootCX-t.width/2,y:this.rootCY-t.height/2}},getRootVertices:function(t,i){if(i=i||{},0===(t=t||this)[this.deltaCoordinate]||!this.parentArea)return[];var e,n=this.parentArea.getInnerSize();if(!i.ignoreSiblings&&this.hasSiblingsBetweenParent()){var o=this.siblings[this.oppositeDirection];e=this.getRelativeVerticesAvoidingSiblings(n,t,o)}else e=this.getRelativeVertices(n,t);return r.util.invoke(e,"offset",this.parentArea.rootCX,this.parentArea.rootCY)},getInnerSize:function(){return{width:this.rootSize.width,height:this.getLRHeight()}},getConnectionPoint:function(){return null},getRelativeVertices:function(){return null},moveRootFromParent:function(){},moveRootBehindSiblings:function(){},hasSiblingsBetweenParent:function(){return!this.isSourceArea()&&this.siblings[this.oppositeDirection].exists()},getCY:function(){return this.height/2+this.prevSiblingGap},getCX:function(){return this.width/2+this.prevSiblingGap}}),b.extend=i.Model.extend;var m=b.extend({direction:"R",oppositeDirection:"L",deltaCoordinate:"dx",marginDimension:"height",getConnectionPoint:function(t){return r.g.point(t.width/2,0)},moveRootBehindSiblings:function(t,i){this.dx+=Math.max(this.getLWidth(t,i),this.getTBOverlap(t,i)),this.dy+=(this.getTHeight(t)-this.getBHeight(t))/2},moveRootFromParent:function(){this.dx+=this.parentGap+this.rootOffset},getRelativeVertices:function(t,i){var e=this.getConnectionPoint(t),n=this.parentGap/2;return[e.clone().offset(n,0),e.clone().offset(n,i.dy)]},getRelativeVerticesAvoidingSiblings:function(t,i,e){var n=this.getConnectionPoint(t),o=e.siblingGap/2,r=0<this.dx?-1:1,s=i.dy+r*(e.height+o)/2,h=i.dy+r*this.rootSize.height/4,a=this.gap/2,g=1.5*a+Math.max(this.getLWidth(this.siblings,this.rootSize),this.getTBOverlap(this.siblings,this.rootSize));return[n.clone().offset(a,0),n.clone().offset(a,s),n.clone().offset(g,s),n.clone().offset(g,h)]}}),R=b.extend({direction:"L",oppositeDirection:"R",deltaCoordinate:"dx",marginDimension:"height",getConnectionPoint:function(t){return r.g.point(-t.width/2,0)},moveRootBehindSiblings:function(t,i){this.dx-=Math.max(this.getRWidth(t,i),this.getTBOverlap(t,i)),this.dy+=(this.getTHeight(t)-this.getBHeight(t))/2},moveRootFromParent:function(){this.dx-=this.parentGap+this.rootOffset},getRelativeVertices:function(t,i){var e=this.getConnectionPoint(t),n=-this.parentGap/2;return[e.clone().offset(n,0),e.clone().offset(n,i.dy)]},getRelativeVerticesAvoidingSiblings:function(t,i,e){var n=this.getConnectionPoint(t),o=0<this.dx?-1:1,r=i.dy+o*(e.height+e.siblingGap/2)/2,s=i.dy+o*this.rootSize.height/4,h=this.gap/2,a=1.5*h+Math.max(this.getRWidth(this.siblings,this.rootSize),this.getTBOverlap(this.siblings,this.rootSize));return[n.clone().offset(-h,0),n.clone().offset(-h,r),n.clone().offset(-a,r),n.clone().offset(-a,s)]}}),x=b.extend({direction:"T",oppositeDirection:"B",deltaCoordinate:"dy",marginDimension:"width",getConnectionPoint:function(t){return r.g.point(0,-t.height/2)},moveRootBehindSiblings:function(t,i){this.dx+=this.getRootDX(t,i),this.hasHorizontalSiblings(t)&&(this.dy-=(this.getLRHeight()-i.height)/2),this.dy-=this.getBHeight(t)},moveRootFromParent:function(){this.dy-=this.parentGap+this.rootOffset},getRelativeVertices:function(t,i){var e=this.getConnectionPoint(t),n=-this.getTXHeight(this.parentArea.siblings)-this.parentGap/2;return[e.clone().offset(0,n),e.clone().offset(i.dx,n)]},getRelativeVerticesAvoidingSiblings:function(t,i){var e=this.getConnectionPoint(t),n=this.siblings,o=n.B,r=this.getTXHeight(this.parentArea.siblings)+this.parentGap/2,s=r+o.height;s+=this.getBXHeight(this.siblings)+this.parentGap/4;var h=this.dy<0?-1:1,a=n[0<h?"BR":"BL"].width,g=i.dx;g+=h*(Math.max(a,o.width/2)+o.siblingGap/4);var u=i.dx+h*this.rootSize.width/4;return[e.clone().offset(0,-r),e.clone().offset(g,-r),e.clone().offset(g,-s),e.clone().offset(u,-s)]}}),y=b.extend({direction:"B",oppositeDirection:"T",deltaCoordinate:"dy",marginDimension:"width",getConnectionPoint:function(t){return r.g.point(0,t.height/2)},moveRootBehindSiblings:function(t,i){this.dx+=this.getRootDX(t,i),this.dy+=this.getTHeight(t),this.hasHorizontalSiblings(t)&&(this.dy+=(this.getLRHeight()-i.height)/2)},moveRootFromParent:function(){this.dy+=this.parentGap+this.rootOffset},getRelativeVertices:function(t,i){var e=this.getConnectionPoint(t),n=this.getBXHeight(this.parentArea.siblings)+this.parentGap/2;return[e.clone().offset(0,n),e.clone().offset(i.dx,n)]},getRelativeVerticesAvoidingSiblings:function(t,i){var e=this.getConnectionPoint(t),n=this.siblings,o=n.T,r=this.getBXHeight(this.parentArea.siblings)+this.parentGap/2,s=r+o.height;s+=this.getTXHeight(n)+this.parentGap/4;var h=this.dy<0?-1:1,a=n[0<h?"TR":"TL"].width,g=i.dx;g+=h*(Math.max(a,o.width/2)+o.siblingGap/4);var u=i.dx+h*this.rootSize.width/4;return[e.clone().offset(0,r),e.clone().offset(g,r),e.clone().offset(g,s),e.clone().offset(u,s)]}}),S=b.extend({direction:"BR",oppositeDirection:"L",deltaCoordinate:"dy",marginDimension:"height",getConnectionPoint:function(t){return r.g.point(0,t.height/2)},getCY:function(){return this.prevSiblingGap},moveRootBehindSiblings:function(t,i){var e=Math.max(t.T.width,t.B.width);this.dx+=Math.max(this.getLWidth(t,i),(e-i.width)/2),this.dy+=this.getTHeight(t),this.hasHorizontalSiblings(t)&&(this.dy+=(this.getLRHeight()-i.height)/2)},moveRootFromParent:function(){var t=this.parentArea;t&&(this.dy+=t.firstChildGap),this.dx+=this.rootSize.width/2+this.rootOffset+this.parentGap},getRelativeVertices:function(t,i){return[this.getConnectionPoint(t).clone().offset(0,i.dy-t.height/2)]},getRelativeVerticesAvoidingSiblings:function(t,i,e){var n=i.dx-this.rootSize.width/4,o=i.dy;return o+=Math.max(e.height,this.rootSize.height)/2,o+=this.getMinimalGap(e)/2,[r.g.point(0,o),r.g.point(n,o)]}}),A=b.extend({direction:"BL",oppositeDirection:"R",deltaCoordinate:"dy",marginDimension:"height",getConnectionPoint:function(t){return r.g.point(0,t.height/2)},getCY:function(){return this.prevSiblingGap},moveRootBehindSiblings:function(t,i){var e=Math.max(t.T.width,t.B.width);this.dx-=Math.max(this.getRWidth(t,i),(e-i.width)/2),this.dy+=this.getTHeight(t),this.hasHorizontalSiblings(t)&&(this.dy+=(this.getLRHeight()-i.height)/2)},moveRootFromParent:function(){var t=this.parentArea;t&&(this.dy+=t.firstChildGap),this.dx-=this.rootSize.width/2+this.rootOffset+this.parentGap},getRelativeVertices:function(t,i){return[this.getConnectionPoint(t).clone().offset(0,i.dy-t.height/2)]},getRelativeVerticesAvoidingSiblings:function(t,i,e){var n=i.dx+this.rootSize.width/4,o=i.dy;return o+=Math.max(e.height,this.rootSize.height)/2,o+=this.getMinimalGap(e)/2,[r.g.point(0,o),r.g.point(n,o)]}}),C=b.extend({direction:"TR",oppositeDirection:"L",deltaCoordinate:"dy",marginDimension:"height",getConnectionPoint:function(t){return r.g.point(0,t.height/2)},getCY:function(){return this.height-this.rootSize.height+this.prevSiblingGap},moveRootBehindSiblings:function(t,i){this.dx+=Math.max(this.getLWidth(t,i),this.getTBOverlap(t,i)),this.dy-=this.getBHeight(t),this.hasHorizontalSiblings(t)&&(this.dy-=(this.getLRHeight()-i.height)/2)},moveRootFromParent:function(){var t=this.parentArea;t&&(this.dy-=t.firstChildGap),this.dx+=this.rootSize.width/2+this.rootOffset+this.parentGap},getRelativeVertices:function(t,i){return[this.getConnectionPoint(t).clone().offset(0,i.dy-t.height/2)]},getRelativeVerticesAvoidingSiblings:function(t,i,e){var n=i.dx-this.rootSize.width/4,o=i.dy;return o-=Math.max(e.height,this.rootSize.height)/2,o-=this.getMinimalGap(e)/2,[r.g.point(0,o),r.g.point(n,o)]}}),B=b.extend({direction:"TL",oppositeDirection:"R",deltaCoordinate:"dy",marginDimension:"height",getConnectionPoint:function(t){return r.g.point(0,t.height/2)},getCY:function(){return this.height-this.rootSize.height+this.prevSiblingGap},moveRootBehindSiblings:function(t,i){this.dx-=Math.max(this.getRWidth(t,i),this.getTBOverlap(t,i)),this.dy-=this.getBHeight(t),this.hasHorizontalSiblings(t)&&(this.dy-=(this.getLRHeight()-i.height)/2)},moveRootFromParent:function(){var t=this.parentArea;t&&(this.dy-=t.firstChildGap),this.dx-=this.rootSize.width/2+this.rootOffset+this.parentGap},getRelativeVertices:function(t,i){return[this.getConnectionPoint(t).clone().offset(0,i.dy-t.height/2)]},getRelativeVerticesAvoidingSiblings:function(t,i,e){var n=i.dx+this.rootSize.width/4,o=i.dy;return o-=Math.max(e.height,this.rootSize.height)/2,o-=this.getMinimalGap(e)/2,[r.g.point(0,o),r.g.point(n,o)]}}),G={rotate:function(t){var e="LRBT",n=e.indexOf(t[0])-e.indexOf(t[1]);return function(t){var i=e.indexOf(t);return 0<=i?e[(4+i-n)%4]:t}},flip:function(t){var i=t[0],e=t[1];return function(t){return t===i?e:t===e?i:t}},straighten:function(t){return function(){return t[1]}}},L=i.Model.extend({defaults:{graph:void 0,gap:20,parentGap:20,siblingGap:20,firstChildGap:20,direction:"R",directionRule:G.straighten,updatePosition:function(t,i,e){t.set("position",i,e)},updateVertices:function(t,i,e){t.set("vertices",i,e)},updateAttributes:null,filter:null,attributeNames:{}},initialize:function(){this._cacheOptions(this.attributes),this.layoutAreas={}},layout:function(t){this.layoutAreas={};for(var i=this.getGraphSources(t),e=0,n=i.length;e<n;e++)this.layoutTree(i[e],t);return this.trigger("layout:done",t),this},layoutTree:function(t,i){(i=i||{}).treeLayout=!0;var e=this._computeLayoutAreas(t,null,i);return this._computeAbsolutePositions(e),this._updateCells(e,i),this},getLayoutBBox:function(){return this.getRootLayoutAreas().reduce(function(t,i){var e=i.getBBox();return t?t.union(e):e},null)},getLayoutArea:function(t){return this.layoutAreas[t.id||t]||null},getRootLayoutAreas:function(){return this.getGraphSources().map(this.getLayoutArea,this)},getGraphSources:function(t){var i=this.graph.getSources();return this.filter&&0<i.length&&(i=this.filter(i,null,t)||i),i},getMinimalRootAreaByPoint:function(i){var t=this.getRootLayoutAreas().filter(function(t){return t.containsPoint(i)});return r.util.isEmpty(t)?null:t.reduce(function(t,i){return i.width*i.height<t.min&&(t.min=i.width*i.height,t.item=i),t},{min:1/0,item:void 0}).item},_computeLayoutAreas:function(t,i,e){var n=i?i.direction:this.get("direction"),o=t.get(this.getAttributeName("direction"))||n,r=b.create(o,t,this.attributes);r.parentArea=i,r.link=this.graph.getConnectedLinks(t,{inbound:!0})[0];var s=this._getChildren(t,e);this.layoutAreas[t.id]=r;for(var h=[],a=0,g=s.length;a<g;a++)h.push(this._computeLayoutAreas(s[a],r,e));return r.compute(h),r},_cacheOptions:function(i){["updateAttributes","updateVertices","updatePosition","filter"].forEach(function(t){this[t]=r.util.isFunction(i[t])?i[t]:null},this),this.graph=i.graph},_getChildren:function(t,i){if(this.layoutAreas[t.id])return[];var e=this.graph.getNeighbors(t,{outbound:!0});return this.filter&&0<e.length&&(e=this.filter(e,t,i)||e),e},_computeAbsolutePositions:function(t){t.computeAbsolutePosition(t);for(var i=0,e=t.childAreas.length;i<e;i++)this._computeAbsolutePositions(t.childAreas[i])},_updateCells:function(t,i){var e=t.root,n=t.link||null;n&&(this.updatePosition&&this.updatePosition(e,t.getRootPosition(),i),this.updateVertices&&this.updateVertices(n,t.getRootVertices(),i)),this.changeSiblingRank(e,t.siblingRank,i),this.updateAttributes&&this.updateAttributes(t,e,n,i);for(var o=0,r=t.childAreas.length;o<r;o++)this._updateCells(t.childAreas[o],i)},updateDirections:function(t,i,n){n=n||{};var o=this.getAttributeName("direction"),r=this.get("directionRule")(i);this.graph.search(t,function(t,i){if(0!==i){var e=r(t.get(o));this.changeDirection(t,e,n)}}.bind(this),{outbound:!0})},reconnectElement:function(t,i,e){e=e||{};var n=this.getLayoutArea(t),o=n.link;if(o){o.set("source",{id:i.id||i},e);var r=n.direction,s=e.direction||r,h=e.siblingRank||void 0;return this.changeSiblingRank(t,h,e),this.changeDirection(t,s,e),r!==s&&this.updateDirections(t,[r,e.direction],e),!0}return!1},changeSiblingRank:function(t,i,e){t.set(this.getAttributeName("siblingRank"),i,e)},changeDirection:function(t,i,e){t.set(this.getAttributeName("direction"),i,e)},getAttributeName:function(t){return this.get("attributeNames")[t]||t},getAttribute:function(t,i){return t.get(this.getAttributeName(i))},prepare:function(){return this}},{directionRules:G});t.TreeLayout=L}(this.joint.layout=this.joint.layout||{},Backbone,joint);