UNPKG

jointjs

Version:

JavaScript diagramming library

8 lines (6 loc) 3.69 kB
/*! JointJS v3.0.4 (2019-08-02) - JavaScript diagramming library This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ this.joint=this.joint||{},this.joint.layout=this.joint.layout||{},function(e,f,h,p){"use strict";var g={exportElement:function(e){return e.size()},exportLink:function(e){var t=e.get("labelSize")||{};return{minLen:e.get("minLen")||1,weight:e.get("weight")||1,labelpos:e.get("labelPosition")||"c",labeloffset:e.get("labelOffset")||0,width:t.width||0,height:t.height||0}},importElement:function(e,t,i){var n=this.getCell(t),r=i.node(t);e.setPosition?e.setPosition(n,r):n.set("position",{x:r.x-r.width/2,y:r.y-r.height/2})},importLink:function(e,t,i){var n=this.getCell(t.name),r=i.edge(t),o=r.points||[];if((e.setVertices||e.setLinkVertices)&&(f.isFunction(e.setVertices)?e.setVertices(n,o):n.set("vertices",o.slice(1,o.length-1))),e.setLabels&&"x"in r&&"y"in r){var a={x:r.x,y:r.y};if(f.isFunction(e.setLabels))e.setLabels(n,a,o);else{var s=p.Polyline(o),l=s.closestPointLength(a),d=s.pointAtLength(l),h=l/s.length();n.label(0,{position:{distance:h,offset:p.Point(a).difference(d).toJSON()}})}}},layout:function(e,t){var i;i=e instanceof h.Graph?e:(new h.Graph).resetCells(e,{dry:!0,sort:!1}),e=null;var n=(t=f.defaults(t||{},{resizeClusters:!0,clusterPadding:10,exportElement:this.exportElement,exportLink:this.exportLink})).dagre||("undefined"!=typeof dagre?dagre:void 0);if(void 0===n)throw new Error('The the "dagre" utility is a mandatory dependency.');var r=g.toGraphLib(i,{graphlib:t.graphlib,directed:!0,multigraph:!0,compound:!0,setNodeLabel:t.exportElement,setEdgeLabel:t.exportLink,setEdgeName:function(e){return e.id}}),o={},a=t.marginX||0,s=t.marginY||0;if(t.rankDir&&(o.rankdir=t.rankDir),t.align&&(o.align=t.align),t.nodeSep&&(o.nodesep=t.nodeSep),t.edgeSep&&(o.edgesep=t.edgeSep),t.rankSep&&(o.ranksep=t.rankSep),t.ranker&&(o.ranker=t.ranker),a&&(o.marginx=a),s&&(o.marginy=s),r.setGraph(o),n.layout(r,{debugTiming:!!t.debugTiming}),i.startBatch("layout"),g.fromGraphLib(r,{importNode:this.importElement.bind(i,t),importEdge:this.importLink.bind(i,t)}),t.resizeClusters){var l=r.nodes().filter(function(e){return 0<r.children(e).length}).map(i.getCell.bind(i)).sort(function(e,t){return t.getAncestors().length-e.getAncestors().length});f.invoke(l,"fitEmbeds",{padding:t.clusterPadding})}i.stopBatch("layout");var d=r.graph();return p.Rect(a,s,Math.abs(d.width-2*a),Math.abs(d.height-2*s))},fromGraphLib:function(t,i){var n=(i=i||{}).importNode||f.noop,r=i.importEdge||f.noop,o=this instanceof h.Graph?this:new h.Graph;return t.nodes().forEach(function(e){n.call(o,e,t,o,i)}),t.edges().forEach(function(e){r.call(o,e,t,o,i)}),o},toGraphLib:function(e,t){var i=(t=t||{}).graphlib||("undefined"!=typeof graphlib?graphlib:void 0);if(void 0===i)throw new Error('The the "graphlib" utility is a mandatory dependency.');for(var n=f.pick(t,"directed","compound","multigraph"),r=new i.Graph(n),o=t.setNodeLabel||f.noop,a=t.setEdgeLabel||f.noop,s=t.setEdgeName||f.noop,l=e.get("cells"),d=0,h=l.length;d<h;d++){var p=l.at(d);if(p.isLink()){var g=p.get("source"),c=p.get("target");if(!g.id||!c.id)break;r.setEdge(g.id,c.id,a(p),s(p))}else if(r.setNode(p.id,o(p)),r.isCompound()&&p.has("parent")){var u=p.get("parent");l.has(u)&&r.setParent(p.id,u)}}return r}};h.Graph.prototype.toGraphLib=function(e){return g.toGraphLib(this,e)},h.Graph.prototype.fromGraphLib=function(e,t){return g.fromGraphLib.call(this,e,t)},e.DirectedGraph=g}(this.joint.layout.DirectedGraph=this.joint.layout.DirectedGraph||{},joint.util,joint.dia,g);