jointjs
Version:
JavaScript diagramming library
8 lines (6 loc) • 3.8 kB
JavaScript
/*! JointJS v3.4.4 (2021-09-27) - 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,p,c){"use strict";var d={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||[],a=new c.Polyline(o);if(e.setVertices||e.setLinkVertices)if(f.isFunction(e.setVertices))e.setVertices(n,o);else{a.simplify({threshold:.001});var s=a.points.map(function(e){return e.toJSON()}),l=s.length;n.set("vertices",s.slice(1,l-1))}if(e.setLabels&&"x"in r&&"y"in r){var h={x:r.x,y:r.y};if(f.isFunction(e.setLabels))e.setLabels(n,h,o);else{var p=a.closestPointLength(h),d=a.pointAtLength(p),g=p/a.length(),u=new c.Point(h).difference(d).toJSON();n.label(0,{position:{distance:g,offset:u}})}}},layout:function(e,t){var i;i=e instanceof p.Graph?e:(new p.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=d.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"),d.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 h=r.graph();return new c.Rect(a,s,Math.abs(h.width-2*a),Math.abs(h.height-2*s))},fromGraphLib:function(t,i){var n=(i=i||{}).importNode||f.noop,r=i.importEdge||f.noop,o=this instanceof p.Graph?this:new p.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"),h=0,p=l.length;h<p;h++){var d=l.at(h);if(d.isLink()){var g=d.get("source"),u=d.get("target");if(!g.id||!u.id)break;r.setEdge(g.id,u.id,a(d),s(d))}else if(r.setNode(d.id,o(d)),r.isCompound()&&d.has("parent")){var c=d.get("parent");l.has(c)&&r.setParent(d.id,c)}}return r}};p.Graph.prototype.toGraphLib=function(e){return d.toGraphLib(this,e)},p.Graph.prototype.fromGraphLib=function(e,t){return d.fromGraphLib.call(this,e,t)},e.DirectedGraph=d}(this.joint.layout.DirectedGraph=this.joint.layout.DirectedGraph||{},joint.util,joint.dia,g);