@zklogic/draw.io
Version:
Draw.IO - Graph Editor integration in Angular-cli
1 lines • 11.8 kB
JavaScript
function mxOrgChartLayout(t,r,a,e){switch(mxGraphLayout.call(this,t),this.correctY=!1,parseInt(r)){case 0:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_LINEAR,this.correctY=!0;break;case 1:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_HANGER2,this.correctY=!0;break;case 3:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_FISHBONE1;break;case 4:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_FISHBONE2;break;case 5:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_1COLUMN_L;break;case 6:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_1COLUMN_R;break;case 7:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_SMART;break;default:this.branchOptimizer=mxOrgChartLayout.prototype.BRANCH_OPT_HANGER4,this.correctY=!0}this.parentChildSpacing=a>0?a:20,this.siblingSpacing=e>0?e:20}mxOrgChartLayout.prototype=new mxGraphLayout,mxOrgChartLayout.prototype.constructor=mxOrgChartLayout,mxOrgChartLayout.prototype.BRANCH_OPT_LINEAR="branchOptimizerAllLinear",mxOrgChartLayout.prototype.BRANCH_OPT_HANGER2="branchOptimizerAllHanger2",mxOrgChartLayout.prototype.BRANCH_OPT_HANGER4="branchOptimizerAllHanger4",mxOrgChartLayout.prototype.BRANCH_OPT_FISHBONE1="branchOptimizerAllFishbone1",mxOrgChartLayout.prototype.BRANCH_OPT_FISHBONE2="branchOptimizerAllFishbone2",mxOrgChartLayout.prototype.BRANCH_OPT_1COLUMN_L="branchOptimizerAllSingleColumnLeft",mxOrgChartLayout.prototype.BRANCH_OPT_1COLUMN_R="branchOptimizerAllSingleColumnRight",mxOrgChartLayout.prototype.BRANCH_OPT_SMART="branchOptimizerSmart",mxOrgChartLayout.prototype.execute=function(t){this.graph.model.beginUpdate();try{RPOrgChart.main(this.graph,t,this.branchOptimizer,this.parentChildSpacing,this.siblingSpacing,this.correctY)}finally{this.graph.model.endUpdate()}},Bridge.define("RPOrgChart",{statics:{config:{init:function(){}},main:function(t,r,a,e,n,i){Bridge.Console.log=console.log,Bridge.Console.error=console.error,Bridge.Console.debug=console.debug,RPOrgChart.graph=t,RPOrgChart.parent=r,RPOrgChart.dx=0,RPOrgChart.dy=0,"group"==r.style&&r.geometry&&(RPOrgChart.dx=r.geometry.x,RPOrgChart.dy=r.geometry.y),RPOrgChart.branchOptimizer=a,RPOrgChart.correctY=i,RPOrgChart.parentChildSpacing=parseInt(e),RPOrgChart.siblingSpacing=parseInt(n),RPOrgChart.buildChart(!0)},diagram:{},dataSource:{},buildChart:function(t){t&&RPOrgChart.initDiagram(),RPOrgChart.positionBoxes()},collapseAllBoxes:function(t,r){for(var a=t.getBoxesById().getValues().getEnumerator();a.moveNext();){var e=a.getCurrent();e.IsSpecial||(e.IsCollapsed=r)}},generateData:function(){for(var t=new OrgChart.Test.TestDataSource,r=RPOrgChart.graph,a=r.getChildVertices(RPOrgChart.parent),e=0;e<a.length;e++){var n=a[e];if(null!=n.geometry&&n.vertex&&n.parent==RPOrgChart.parent){var i=null,g=r.getIncomingEdges(n)[0];null!=g&&null!=g.source&&(i=g.source.id);var o=new OrgChart.Test.TestDataItem;o.Id=n.id,o.ParentId=i,t.Items.add(o.getId(),o)}}return t},initDiagram:function(){var t=RPOrgChart.generateData();RPOrgChart.dataSource=t;var r=new OrgChart.Layout.BoxContainer.$ctor1(t);RPOrgChart.diagram=new OrgChart.Layout.Diagram;var a=RPOrgChart.diagram;a.setBoxes(r);var e=new OrgChart.Layout.LinearLayoutStrategy;e.ParentAlignment=OrgChart.Layout.BranchParentAlignment.Center,e.ParentChildSpacing=RPOrgChart.parentChildSpacing,e.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("linear",e);var n=new OrgChart.Layout.MultiLineHangerLayoutStrategy;n.ParentAlignment=OrgChart.Layout.BranchParentAlignment.Center,n.MaxSiblingsPerRow=2,n.ParentChildSpacing=RPOrgChart.parentChildSpacing,n.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("hanger2",n),(n=new OrgChart.Layout.MultiLineHangerLayoutStrategy).ParentAlignment=OrgChart.Layout.BranchParentAlignment.Center,n.MaxSiblingsPerRow=4,n.ParentChildSpacing=RPOrgChart.parentChildSpacing,n.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("hanger4",n);var i=new OrgChart.Layout.SingleColumnLayoutStrategy;i.ParentAlignment=OrgChart.Layout.BranchParentAlignment.Right,i.ParentChildSpacing=RPOrgChart.parentChildSpacing,i.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("singleColumnRight",i),(i=new OrgChart.Layout.SingleColumnLayoutStrategy).ParentAlignment=OrgChart.Layout.BranchParentAlignment.Left,i.ParentChildSpacing=RPOrgChart.parentChildSpacing,i.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("singleColumnLeft",i);var g=new OrgChart.Layout.MultiLineFishboneLayoutStrategy;g.ParentAlignment=OrgChart.Layout.BranchParentAlignment.Center,g.MaxGroups=1,g.ParentChildSpacing=RPOrgChart.parentChildSpacing,g.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("fishbone1",g),(g=new OrgChart.Layout.MultiLineFishboneLayoutStrategy).ParentAlignment=OrgChart.Layout.BranchParentAlignment.Center,g.MaxGroups=2,g.ParentChildSpacing=RPOrgChart.parentChildSpacing,g.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("fishbone2",g);var o=new OrgChart.Layout.StackingLayoutStrategy;o.ParentAlignment=OrgChart.Layout.BranchParentAlignment.InvalidValue,o.Orientation=OrgChart.Layout.StackOrientation.SingleRowHorizontal,o.ParentChildSpacing=RPOrgChart.parentChildSpacing,o.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("hstack",o);var l=new OrgChart.Layout.StackingLayoutStrategy;l.ParentAlignment=OrgChart.Layout.BranchParentAlignment.InvalidValue,l.Orientation=OrgChart.Layout.StackOrientation.SingleColumnVertical,l.ParentChildSpacing=RPOrgChart.parentChildSpacing,l.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("vstack",l),(l=new OrgChart.Layout.StackingLayoutStrategy).ParentAlignment=OrgChart.Layout.BranchParentAlignment.InvalidValue,l.Orientation=OrgChart.Layout.StackOrientation.SingleColumnVertical,l.ParentChildSpacing=RPOrgChart.parentChildSpacing,l.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("vstackMiddle",l),(l=new OrgChart.Layout.StackingLayoutStrategy).ParentAlignment=OrgChart.Layout.BranchParentAlignment.InvalidValue,l.Orientation=OrgChart.Layout.StackOrientation.SingleColumnVertical,l.ParentChildSpacing=RPOrgChart.parentChildSpacing,l.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("vstackTop",l);var h=new OrgChart.Layout.FishboneAssistantsLayoutStrategy;h.ParentAlignment=OrgChart.Layout.BranchParentAlignment.Center,h.ParentChildSpacing=RPOrgChart.parentChildSpacing,h.SiblingSpacing=RPOrgChart.siblingSpacing,a.LayoutSettings.LayoutStrategies.add("assistants",h),a.LayoutSettings.DefaultLayoutStrategyId="vstack",a.LayoutSettings.DefaultAssistantLayoutStrategyId="assistants"},getBoxLevel:function(t,r){for(var a=0,e={};r.ParentId>0&&t.getBoxesById().tryGetValue(r.ParentId,e);)r=e.v,a++;return a},onLayoutStateChanged:function(t,r){r.State.getCurrentOperation()===OrgChart.Layout.LayoutState.Operation.PreprocessVisualTree&&RPOrgChart.renderBoxes()},renderBoxes:function(){RPOrgChart.diagram.getVisualTree().IterateParentFirst((function(t){var r=t.Element;if(r.getIsDataBound()){if(t.State.IsHidden)return!0;r.Size=RPOrgChart.getBoxElementSize(r.DataId)}return!0}))},getBranchOptimizerFunc:function(){return RPOrgChart[RPOrgChart.branchOptimizer]},branchOptimizerAllLinear:function(t){return t.getIsAssistantRoot()?null:"linear"},branchOptimizerAllHanger2:function(t){return t.getIsAssistantRoot()?null:"hanger2"},branchOptimizerAllHanger4:function(t){return t.getIsAssistantRoot()?null:"hanger4"},branchOptimizerAllFishbone1:function(t){return t.getIsAssistantRoot()?null:"fishbone1"},branchOptimizerAllFishbone2:function(t){return t.getIsAssistantRoot()?null:"fishbone2"},branchOptimizerAllSingleColumnLeft:function(t){return t.getIsAssistantRoot()?null:"singleColumnRight"},branchOptimizerAllSingleColumnRight:function(t){return t.getIsAssistantRoot()?null:"singleColumnLeft"},branchOptimizerStackers:function(t){return t.getIsAssistantRoot()?null:0===t.Level?"vstackTop":1===t.Level?"vstackMiddle":"hstack"},branchOptimizerSmart:function(t){if(t.getIsAssistantRoot())return null;var r=t.getChildCount();if(r<=1)return"vstack";for(var a=0,e=0;e<r;e++)t.Children.getItem(e).getChildCount()>0&&a++;return a<=1?r<=4?"vstack":r<=8?"fishbone1":"fishbone2":"hanger4"},boxSizeFunc:function(t){var r=RPOrgChart.diagram.getBoxes().getBoxesByDataId().getItem(t).Id;return RPOrgChart.diagram.getBoxes().getBoxesById().getItem(r).Size},getBoxElementSize:function(t){var r=RPOrgChart.graph.model.cells[t].geometry;return new OrgChart.Layout.Size.$ctor1(r.width,r.height)},positionBoxes:function(){var t=RPOrgChart.diagram,r=new OrgChart.Layout.LayoutState(t);r.addOperationChanged(RPOrgChart.onLayoutStateChanged),r.BoxSizeFunc=Bridge.fn.bind(this,RPOrgChart.boxSizeFunc,null,!0),r.LayoutOptimizerFunc=Bridge.fn.bind(this,RPOrgChart.getBranchOptimizerFunc(),null,!0),OrgChart.Layout.LayoutAlgorithm.Apply(r);var a=OrgChart.Layout.LayoutAlgorithm.ComputeBranchVisualBoundingRect(t.getVisualTree()),e=-a.getLeft()+a.getTop(),n=RPOrgChart.graph,i=n.model.cells,g=[];t.getVisualTree().IterateParentFirst((function(t){if(t.State.IsHidden)return!1;var r=t.Element;if(r.getIsDataBound()){var a=i[r.DataId],g=a.geometry.clone();g.x=t.State.TopLeft.X+e,g.y=t.State.TopLeft.Y,n.model.setGeometry(a,g)}return!0})),t.getVisualTree().IterateParentFirst((function(t){var r=RPOrgChart.correctY?Math.min(0,-RPOrgChart.parentChildSpacing/2+5):0;if(null!=t.State.Connector){for(var a=i[t.Element.DataId],o=n.getOutgoingEdges(a),l={},h=0;h<t.State.Connector.Segments.length;h++){(O=t.State.Connector.Segments[h]).mark=1<<h,O.From.X+=e,O.To.X+=e;var u=O.From.X,s=O.From.Y,c=O.To.X,C=O.To.Y;if(u==c&&s>C||s==C&&u>c){var p=O.From;O.From=O.To,O.To=p}}for(h=0;h<t.State.Connector.Segments.length;h++){u=(O=t.State.Connector.Segments[h]).From.X,s=O.From.Y,c=O.To.X,C=O.To.Y;var O,m=new mxPoint(u,s);g.push(m),m.mark=O.mark,null!=(A=l[u+","+s])?A.mark|=m.mark:l[u+","+s]=m;var y=new mxPoint(c,C);g.push(y),y.mark=O.mark,null!=(A=l[c+","+C])?A.mark|=y.mark:l[c+","+C]=y;for(var S=h+1;S<t.State.Connector.Segments.length;S++){var d=t.State.Connector.Segments[S],L=d.From.X,P=d.From.Y,R=d.To.X,b=d.To.Y;if(u==c&&s<=P&&C>=P&&L<=u&&R>=u){var f=new mxPoint(u,P);g.push(f),f.mark=O.mark|d.mark,null!=(A=l[u+","+P])?A.mark|=f.mark:l[u+","+P]=f}else if(s==C&&u<=L&&c>=L&&P<=s&&b>=s){var A;f=new mxPoint(L,s),g.push(f),f.mark=O.mark|d.mark,null!=(A=l[L+","+s])?A.mark|=f.mark:l[L+","+s]=f}}}var x=[];for(var v in l)x.push(l[v]);function B(t,r){return r.x>=t.x&&r.x<=t.x+t.width&&r.y>=t.y&&r.y<=t.y+t.height}function I(t,a){for(var e=t.geometry.clone(),i=0;a&&i<a.length;i++)a[i].corrected||(a[i].y+=r,a[i].corrected=!0);e.points=a,n.model.setGeometry(t,e),n.setCellStyles("entryX",null,[t]),n.setCellStyles("entryY",null,[t]),n.setCellStyles("exitX",null,[t]),n.setCellStyles("exitY",null,[t]),n.setCellStyles("edgeStyle","orthogonalEdgeStyle",[t])}if(x.sort((function(t,r){var a=t.y-r.y;return 0==a?t.x-r.x:a})),o=n.getOutgoingEdges(a),2==x.length&&1==o.length)I(o[0],x);else{for(var k,T,z=a.geometry,_=0;_<x.length;_++)if(B(z,x[_])){k=x[_];break}function H(t){for(var r=0;r<x.length;r++){var a=x[r];if(!T[a.x+","+a.y]&&a.mark&t.mark)return T[a.x+","+a.y]=!0,a}}for(S=0;S<o.length;S++)if(null!=o[S].target){(T={})[k.x+","+k.y]=!0;for(var N=o[S].target.geometry,w=[k],F=k,E=0;E<1e3;){E++;var M=H(F);if(null==M)w.pop(),F=w[w.length-1];else if(w.push(M),F=M,B(N,M))break}if(w.length>2){var V=w[0].x,Y=w[w.length-1].x;for(_=w.length-2;_>0;_--)(V>Y&&w[_].x<Y||V<Y&&w[_].x<V)&&w.splice(_,1)}var D=o[S].geometry.clone();D.points=w,RPOrgChart.graph.model.setGeometry(o[S],D),I(o[S],w)}}}return!0}));for(var o=0;o<g.length;o++)delete g[o].mark,delete g[o].corrected}}}),Bridge.init();