All Downloads are FREE. Search and download functionalities are using the official Maven repository.

js.joint.layout.DirectedGraph.min.js Maven / Gradle / Ivy

There is a newer version: 5.2.2
Show newest version
/*! JointJS v0.9.2 - JavaScript diagramming library  2014-09-17 


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/.
 */
!function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;gg+1){for(var i=d,j=g+1,k=0;h>j;++j,++k){var l="_D"+ ++b,m={width:f.width,height:f.height,edge:{id:c,source:d,target:e,attrs:f},rank:j,dummy:!0};0===k?m.index=0:j+1===h&&(m.index=1),a.addNode(l,m),a.addEdge(null,i,l,{}),i=l}a.addEdge(null,i,e,{}),a.delEdge(c)}})}function j(a){a.eachNode(function(b,c){if(c.dummy){if("index"in c){var d=c.edge;a.hasEdge(d.id)||a.addEdge(d.id,d.source,d.target,d.attrs);var e=a.edge(d.id).points;e[c.index]={x:c.x,y:c.y,ul:c.ul,ur:c.ur,dl:c.dl,dr:c.dr}}a.delNode(b)}})}function k(a){a.eachEdge(function(a,b,c,d){d.reversed&&d.points.reverse()})}function l(a,b){var c=b?new g:new f;c.graph(a.graph()),a.eachNode(function(a,b){c.addNode(a,b)}),a.eachNode(function(b){c.parent(b,a.parent(b))}),a.eachEdge(function(a,b,d,e){c.addEdge(e.e,b,d,e)});var d=0,e=0;return a.eachNode(function(b,c){a.children(b).length||(d=Math.max(d,c.x+c.width/2),e=Math.max(e,c.y+c.height/2))}),a.eachEdge(function(a,b,c,f){var g=Math.max.apply(Math,f.points.map(function(a){return a.x})),h=Math.max.apply(Math,f.points.map(function(a){return a.y}));d=Math.max(d,g+f.width/2),e=Math.max(e,h+f.height/2)}),c.graph().width=d,c.graph().height=e,c}function m(a){return function(){return arguments.length?(a.apply(null,arguments),p):a()}}var n={debugLevel:0,orderMaxSweeps:e.DEFAULT_MAX_SWEEPS,rankSimplex:!1,rankDir:"TB"},o=a("./position")(),p={};return p.orderIters=c.propertyAccessor(p,n,"orderMaxSweeps"),p.rankSimplex=c.propertyAccessor(p,n,"rankSimplex"),p.nodeSep=m(o.nodeSep),p.edgeSep=m(o.edgeSep),p.universalSep=m(o.universalSep),p.rankSep=m(o.rankSep),p.rankDir=c.propertyAccessor(p,n,"rankDir"),p.debugAlignment=m(o.debugAlignment),p.debugLevel=c.propertyAccessor(p,n,"debugLevel",function(a){c.log.level=a,o.debugLevel(a)}),p.run=c.time("Total layout",h),p._normalize=i,p}},{"./order":4,"./position":9,"./rank":10,"./util":17,graphlib:24}],4:[function(a,b){function c(a,b){function c(){a.eachNode(function(a,b){n[a]=b.order})}arguments.length<2&&(b=o);var d=a.graph().orderRestarts||0,e=l(a);e.forEach(function(b){b=b.filterNodes(function(b){return!a.children(b).length})});for(var g,h=0,i=Number.MAX_VALUE,n={},p=0;p0),j.log(2,"Order phase start cross count: "+a.graph().orderInitCC);var q,r,s;for(q=0,r=0;4>r&&b>q&&g>0;++q,++r,++h)f(a,e,q),s=k(a),g>s&&(r=0,g=s,i>s&&(c(),i=s)),j.log(3,"Order phase start "+p+" iter "+q+" cross count: "+s)}Object.keys(n).forEach(function(b){a.children&&a.children(b).length||(a.node(b).order=n[b])}),a.graph().orderCC=i,j.log(2,"Order iterations: "+h),j.log(2,"Order phase best cross count: "+a.graph().orderCC)}function d(a,b){var c={};return b.forEach(function(b){c[b]=a.inEdges(b).map(function(b){return a.node(a.source(b)).order})}),c}function e(a,b){var c={};return b.forEach(function(b){c[b]=a.outEdges(b).map(function(b){return a.node(a.target(b)).order})}),c}function f(a,b,c){c%2===0?g(a,b,c):h(a,b,c)}function g(a,b){var c;for(i=1;i=0;--i)n(b[i],c,e(a,b[i].nodes()))}var j=a("./util"),k=a("./order/crossCount"),l=a("./order/initLayerGraphs"),m=a("./order/initOrder"),n=a("./order/sortLayer");b.exports=c;var o=24;c.DEFAULT_MAX_SWEEPS=o},{"./order/crossCount":5,"./order/initLayerGraphs":6,"./order/initOrder":7,"./order/sortLayer":8,"./util":17}],5:[function(a,b){function c(a){for(var b=0,c=e.ordering(a),f=1;fh;++h)g[h]=0;var i=0;return d.forEach(function(a){var b=a+e;for(++g[b];b>0;)b%2&&(i+=g[b+1]),b=b-1>>1,++g[b]}),i}var e=a("../util");b.exports=c},{"../util":17}],6:[function(a,b){function c(a){function b(d){if(null===d)return a.children(d).forEach(function(a){b(a)}),void 0;var f=a.node(d);f.minRank="rank"in f?f.rank:Number.MAX_VALUE,f.maxRank="rank"in f?f.rank:Number.MIN_VALUE;var g=new e;return a.children(d).forEach(function(c){var d=b(c);g=e.union([g,d]),f.minRank=Math.min(f.minRank,a.node(c).minRank),f.maxRank=Math.max(f.maxRank,a.node(c).maxRank)}),"rank"in f&&g.add(f.rank),g.keys().forEach(function(a){a in c||(c[a]=[]),c[a].push(d)}),g}var c=[];b(null);var f=[];return c.forEach(function(b,c){f[c]=a.filterNodes(d(b))}),f}var d=a("graphlib").filter.nodesFromList,e=a("cp-data").Set;b.exports=c},{"cp-data":19,graphlib:24}],7:[function(a,b){function c(a,b){var c=[];a.eachNode(function(b,d){var e=c[d.rank];a.children&&a.children(b).length>0||(e||(e=c[d.rank]=[]),e.push(b))}),c.forEach(function(c){b&&e.shuffle(c),c.forEach(function(b,c){a.node(b).order=c})});var f=d(a);a.graph().orderInitCC=f,a.graph().orderCC=Number.MAX_VALUE}var d=a("./crossCount"),e=a("../util");b.exports=c},{"../util":17,"./crossCount":5}],8:[function(a,b){function c(a,b,c){var e=[],f={};a.eachNode(function(a,b){e[b.order]=a;var g=c[a];g.length&&(f[a]=d.sum(g)/g.length)});var g=a.nodes().filter(function(a){return void 0!==f[a]});g.sort(function(b,c){return f[b]-f[c]||a.node(b).order-a.node(c).order});for(var h=0,i=0,j=g.length;j>i;++h)void 0!==f[e[h]]&&(a.node(g[i++]).order=h)}var d=a("../util");b.exports=c},{"../util":17}],9:[function(a,b){var c=a("./util");b.exports=function(){function a(a){a=a.filterNodes(c.filterNonSubgraphs(a));var b=c.ordering(a),g=d(a,b),h={};["u","d"].forEach(function(c){"d"===c&&b.reverse(),["l","r"].forEach(function(d){"r"===d&&k(b);var i=c+d,l=e(a,b,g,"u"===c?"predecessors":"successors");h[i]=f(a,b,l.pos,l.root,l.align),s.debugLevel>=3&&r(c+d,a,b,h[i]),"r"===d&&j(h[i]),"r"===d&&k(b)}),"d"===c&&b.reverse()}),i(a,b,h),a.eachNode(function(b){var c=[];for(var d in h){var e=h[d][b];p(d,a,b,e),c.push(e)}c.sort(function(a,b){return a-b}),o(a,b,(c[1]+c[2])/2)});var n=0,t="BT"===a.graph().rankDir||"RL"===a.graph().rankDir;b.forEach(function(b){var d=c.max(b.map(function(b){return m(a,b)}));n+=d/2,b.forEach(function(b){q(a,b,t?-n:n)}),n+=d/2+s.rankSep});var u=c.min(a.nodes().map(function(b){return o(a,b)-l(a,b)/2})),v=c.min(a.nodes().map(function(b){return q(a,b)-m(a,b)/2}));a.eachNode(function(b){o(a,b,o(a,b)-u),q(a,b,q(a,b)-v)})}function b(a,b){return b>a?a.toString().length+":"+a+"-"+b:b.toString().length+":"+b+"-"+a}function d(a,c){function d(a){var c=k[a];(g>c||c>i)&&(j[b(f[h],a)]=!0)}var e,f,g,h,i,j={},k={};if(c.length<=2)return j;c[1].forEach(function(a,b){k[a]=b});for(var l=1;l=h;++h)a.predecessors(f[h]).forEach(d);g=i}}}return j}function e(a,c,d,e){var f={},g={},h={};return c.forEach(function(a){a.forEach(function(a,b){g[a]=a,h[a]=a,f[a]=b})}),c.forEach(function(c){var i=-1;c.forEach(function(c){var j,k=a[e](c);k.length>0&&(k.sort(function(a,b){return f[a]-f[b]}),j=(k.length-1)/2,k.slice(Math.floor(j),Math.ceil(j)+1).forEach(function(a){h[c]===c&&!d[b(a,c)]&&i0){var j=e[l[c]];h(j),i[b]===b&&(i[b]=i[j]);var k=n(a,l[c])+n(a,c);i[b]!==i[j]?g(i[j],i[b],m[b]-m[j]-k):m[b]=Math.max(m[b],m[j]+k)}c=f[c]}while(c!==b)}}var i={},j={},k={},l={},m={};return b.forEach(function(a){a.forEach(function(b,c){i[b]=b,j[b]={},c>0&&(l[b]=a[c-1])})}),c.values(e).forEach(function(a){h(a)}),b.forEach(function(a){a.forEach(function(a){if(m[a]=m[e[a]],a===e[a]&&a===i[a]){var b=0;a in j&&Object.keys(j[a]).length>0&&(b=c.min(Object.keys(j[a]).map(function(b){return j[a][b]+(b in k?k[b]:0)}))),k[a]=b}})}),b.forEach(function(a){a.forEach(function(a){m[a]+=k[i[e[a]]]||0})}),m}function g(a,b,d){return c.min(b.map(function(a){var b=a[0];return d[b]}))}function h(a,b,d){return c.max(b.map(function(a){var b=a[a.length-1];return d[b]}))}function i(a,b,c){function d(a){c[l][a]+=j[l]}var e,f={},i={},j={},k=Number.POSITIVE_INFINITY;for(var l in c){var m=c[l];f[l]=g(a,b,m),i[l]=h(a,b,m);var n=i[l]-f[l];k>n&&(k=n,e=l)}["u","d"].forEach(function(a){["l","r"].forEach(function(b){var c=a+b;j[c]="l"===b?f[e]-f[c]:i[e]-i[c]})});for(l in c)a.eachNode(d)}function j(a){for(var b in a)a[b]=-a[b]}function k(a){a.forEach(function(a){a.reverse()})}function l(a,b){switch(a.graph().rankDir){case"LR":return a.node(b).height;case"RL":return a.node(b).height;default:return a.node(b).width}}function m(a,b){switch(a.graph().rankDir){case"LR":return a.node(b).width;case"RL":return a.node(b).width;default:return a.node(b).height}}function n(a,b){if(null!==s.universalSep)return s.universalSep;var c=l(a,b),d=a.node(b).dummy?s.edgeSep:s.nodeSep;return(c+d)/2}function o(a,b,c){if("LR"===a.graph().rankDir||"RL"===a.graph().rankDir){if(arguments.length<3)return a.node(b).y;a.node(b).y=c}else{if(arguments.length<3)return a.node(b).x;a.node(b).x=c}}function p(a,b,c,d){if("LR"===b.graph().rankDir||"RL"===b.graph().rankDir){if(arguments.length<3)return b.node(c)[a];b.node(c)[a]=d}else{if(arguments.length<3)return b.node(c)[a];b.node(c)[a]=d}}function q(a,b,c){if("LR"===a.graph().rankDir||"RL"===a.graph().rankDir){if(arguments.length<3)return a.node(b).x;a.node(b).x=c}else{if(arguments.length<3)return a.node(b).y;a.node(b).y=c}}function r(a,b,c,d){c.forEach(function(c,e){var f,g;c.forEach(function(c){var h=d[c];if(f){var i=n(b,f)+n(b,c);i>h-g&&console.log("Position phase: sep violation. Align: "+a+". Layer: "+e+". U: "+f+" V: "+c+". Actual sep: "+(h-g)+" Expected sep: "+i)}f=c,g=h})})}var s={nodeSep:50,edgeSep:10,universalSep:null,rankSep:30},t={};return t.nodeSep=c.propertyAccessor(t,s,"nodeSep"),t.edgeSep=c.propertyAccessor(t,s,"edgeSep"),t.universalSep=c.propertyAccessor(t,s,"universalSep"),t.rankSep=c.propertyAccessor(t,s,"rankSep"),t.debugLevel=c.propertyAccessor(t,s,"debugLevel"),t.run=a,t}},{"./util":17}],10:[function(a,b,c){function d(a,b){f(a),l.time("constraints.apply",p.apply)(a),g(a),l.time("acyclic",m)(a);var c=a.filterNodes(l.filterNonSubgraphs(a));n(c),r(c).forEach(function(a){var d=c.filterNodes(s.nodesFromList(a));j(d,b)}),l.time("constraints.relax",p.relax(a)),l.time("reorientEdges",i)(a)}function e(a){m.undo(a)}function f(a){a.eachEdge(function(b,c,d,e){if(c===d){var f=h(a,b,c,d,e,0,!1),g=h(a,b,c,d,e,1,!0),i=h(a,b,c,d,e,2,!1);a.addEdge(null,f,c,{minLen:1,selfLoop:!0}),a.addEdge(null,f,g,{minLen:1,selfLoop:!0}),a.addEdge(null,c,i,{minLen:1,selfLoop:!0}),a.addEdge(null,g,i,{minLen:1,selfLoop:!0}),a.delEdge(b)}})}function g(a){a.eachEdge(function(b,c,d,e){if(c===d){var f=e.originalEdge,g=h(a,f.e,f.u,f.v,f.value,0,!0);a.addEdge(null,c,g,{minLen:1}),a.addEdge(null,g,d,{minLen:1}),a.delEdge(b)}})}function h(a,b,c,d,e,f,g){return a.addNode(null,{width:g?e.width:0,height:g?e.height:0,edge:{id:b,source:c,target:d,attrs:e},dummy:!0,index:f})}function i(a){a.eachEdge(function(b,c,d,e){a.node(c).rank>a.node(d).rank&&(a.delEdge(b),e.reversed=!0,a.addEdge(b,d,c,e))})}function j(a,b){var c=o(a);b&&(l.log(1,"Using network simplex for ranking"),q(a,c)),k(a)}function k(a){var b=l.min(a.nodes().map(function(b){return a.node(b).rank}));a.eachNode(function(a,c){c.rank-=b})}var l=a("./util"),m=a("./rank/acyclic"),n=a("./rank/initRank"),o=a("./rank/feasibleTree"),p=a("./rank/constraints"),q=a("./rank/simplex"),r=a("graphlib").alg.components,s=a("graphlib").filter;c.run=d,c.restoreEdges=e},{"./rank/acyclic":11,"./rank/constraints":12,"./rank/feasibleTree":13,"./rank/initRank":14,"./rank/simplex":16,"./util":17,graphlib:24}],11:[function(a,b){function c(a){function b(e){e in d||(d[e]=c[e]=!0,a.outEdges(e).forEach(function(d){var g,h=a.target(d);e===h?console.error('Warning: found self loop "'+d+'" for node "'+e+'"'):h in c?(g=a.edge(d),a.delEdge(d),g.reversed=!0,++f,a.addEdge(d,h,e,g)):b(h)}),delete c[e])}var c={},d={},f=0;return a.eachNode(function(a){b(a)}),e.log(2,"Acyclic Phase: reversed "+f+" edge(s)"),f}function d(a){a.eachEdge(function(b,c,d,e){e.reversed&&(delete e.reversed,a.delEdge(b),a.addEdge(b,d,c,e))})}var e=a("../util");b.exports=c,b.exports.undo=d},{"../util":17}],12:[function(a,b,c){function d(a){return"min"!==a&&"max"!==a&&0!==a.indexOf("same_")?(console.error("Unsupported rank type: "+a),!1):!0}function e(a,b,c,d){a.inEdges(b).forEach(function(b){var e,f=a.edge(b);e=f.originalEdge?f:{originalEdge:{e:b,u:a.source(b),v:a.target(b),value:f},minLen:a.edge(b).minLen},f.selfLoop&&(d=!1),d?(a.addEdge(null,c,a.source(b),e),e.reversed=!0):a.addEdge(null,a.source(b),c,e)})}function f(a,b,c,d){a.outEdges(b).forEach(function(b){var e,f=a.edge(b);e=f.originalEdge?f:{originalEdge:{e:b,u:a.source(b),v:a.target(b),value:f},minLen:a.edge(b).minLen},f.selfLoop&&(d=!1),d?(a.addEdge(null,a.target(b),c,e),e.reversed=!0):a.addEdge(null,c,a.target(b),e)})}function g(a,b,c){void 0!==c&&a.children(b).forEach(function(b){b===c||a.outEdges(c,b).length||a.node(b).dummy||a.addEdge(null,c,b,{minLen:0})})}function h(a,b,c){void 0!==c&&a.children(b).forEach(function(b){b===c||a.outEdges(b,c).length||a.node(b).dummy||a.addEdge(null,b,c,{minLen:0})})}c.apply=function(a){function b(c){var i={};a.children(c).forEach(function(g){if(a.children(g).length)return b(g),void 0;var h=a.node(g),j=h.prefRank;if(void 0!==j){if(!d(j))return;j in i?i.prefRank.push(g):i.prefRank=[g];var k=i[j];void 0===k&&(k=i[j]=a.addNode(null,{originalNodes:[]}),a.parent(k,c)),e(a,g,k,"min"===j),f(a,g,k,"max"===j),a.node(k).originalNodes.push({u:g,value:h,parent:c}),a.delNode(g)}}),g(a,c,i.min),h(a,c,i.max)}b(null)},c.relax=function(a){var b=[];a.eachEdge(function(a,c,d,e){var f=e.originalEdge;f&&b.push(f)}),a.eachNode(function(b,c){var d=c.originalNodes;d&&(d.forEach(function(b){b.value.rank=c.rank,a.addNode(b.u,b.value),a.parent(b.u,b.parent)}),a.delNode(b))}),b.forEach(function(b){a.addEdge(b.e,b.u,b.v,b.value)})}},{}],13:[function(a,b){function c(a){function b(c){var e=!0;return a.predecessors(c).forEach(function(f){g.has(f)&&!d(a,f,c)&&(g.has(c)&&(h.addNode(c,{}),g.remove(c),h.graph({root:c})),h.addNode(f,{}),h.addEdge(null,f,c,{reversed:!0}),g.remove(f),b(f),e=!1)}),a.successors(c).forEach(function(f){g.has(f)&&!d(a,c,f)&&(g.has(c)&&(h.addNode(c,{}),g.remove(c),h.graph({root:c})),h.addNode(f,{}),h.addEdge(null,c,f,{}),g.remove(f),b(f),e=!1)}),e}function c(){var b=Number.MAX_VALUE;g.keys().forEach(function(c){a.predecessors(c).forEach(function(e){if(!g.has(e)){var f=d(a,e,c);Math.abs(f)k&&b(j[k]);++k);g.size()&&c()}return h}function d(a,b,c){var d=a.node(c).rank-a.node(b).rank,e=g.max(a.outEdges(b,c).map(function(b){return a.edge(b).minLen}));return d-e}var e=a("cp-data").Set,f=a("graphlib").Digraph,g=a("../util");b.exports=c},{"../util":17,"cp-data":19,graphlib:24}],14:[function(a,b){function c(a){var b=e(a);b.forEach(function(b){var c=a.inEdges(b);if(0===c.length)return a.node(b).rank=0,void 0;var e=c.map(function(b){return a.node(a.source(b)).rank+a.edge(b).minLen});a.node(b).rank=d.max(e)})}var d=a("../util"),e=a("graphlib").alg.topsort;b.exports=c},{"../util":17,graphlib:24}],15:[function(a,b){function c(a,b,c,d){return Math.abs(a.node(b).rank-a.node(c).rank)-d}b.exports={slack:c}},{}],16:[function(a,b){function c(a,b){for(d(a,b);;){var c=h(b);if(null===c)break;var e=i(a,b,c);j(a,b,c,e)}}function d(a,b){function c(d){var e=b.successors(d);for(var g in e){var h=e[g];c(h)}d!==b.graph().root&&f(a,b,d)}e(b),b.eachEdge(function(a,b,c,d){d.cutValue=0}),c(b.graph().root)}function e(a){function b(d){var e=a.successors(d),f=c;for(var g in e){var h=e[g];b(h),f=Math.min(f,a.node(h).low)}a.node(d).low=f,a.node(d).lim=c++}var c=0;b(a.graph().root)}function f(a,b,c){var d=b.inEdges(c)[0],e=[],f=b.outEdges(c);for(var h in f)e.push(b.target(f[h]));var i,j=0,k=0,l=0,m=0,n=0,o=a.outEdges(c);for(var p in o){var q=a.target(o[p]);for(i in e)g(b,q,e[i])&&k++;g(b,q,c)||m++}var r=a.inEdges(c);for(var s in r){var t=a.source(r[s]);for(i in e)g(b,t,e[i])&&l++;g(b,t,c)||n++}var u=0;for(i in e){var v=b.edge(f[i]).cutValue;b.edge(f[i]).reversed?u-=v:u+=v}b.edge(d).reversed?j-=u-k+l-m+n:j+=u-k+l-m+n,b.edge(d).cutValue=j}function g(a,b,c){return a.node(c).low<=a.node(b).lim&&a.node(b).lim<=a.node(c).lim}function h(a){var b=a.edges();for(var c in b){var d=b[c],e=a.edge(d);if(e.cutValue<0)return d}return null}function i(a,b,c){var d,e=b.source(c),f=b.target(c),h=b.node(f).liml&&(j=l,d=e)}}):a.eachEdge(function(e,f,i,k){if(e!==c&&!g(b,f,h)&&g(b,i,h)){var l=n.slack(a,f,i,k.minLen);j>l&&(j=l,d=e)}}),void 0===d){var k=[],l=[];throw a.eachNode(function(a){g(b,a,h)?l.push(a):k.push(a)}),new Error("No edge found from outside of tree to inside")}return d}function j(a,b,c,e){function f(a){var c=b.inEdges(a);for(var d in c){var e=c[d],g=b.source(e),h=b.edge(e);f(g),b.delEdge(e),h.reversed=!h.reversed,b.addEdge(e,a,g,h)}}b.delEdge(c);var g=a.source(e),h=a.target(e);f(h);for(var i=g,j=b.inEdges(i);j.length>0;)i=b.source(j[0]),j=b.inEdges(i);b.graph().root=i,b.addEdge(null,g,h,{cutValue:0}),d(a,b),k(a,b)}function k(a,b){function c(d){var e=b.successors(d);e.forEach(function(b){var e=l(a,d,b);a.node(b).rank=a.node(d).rank+e,c(b)})}c(b.graph().root)}function l(a,b,c){var d=a.outEdges(b,c);if(d.length>0)return m.max(d.map(function(b){return a.edge(b).minLen}));var e=a.inEdges(b,c);return e.length>0?-m.max(e.map(function(b){return a.edge(b).minLen})):void 0}var m=a("../util"),n=a("./rankUtil");b.exports=c},{"../util":17,"./rankUtil":15}],17:[function(a,b,c){function d(a,b){return function(){var c=(new Date).getTime();try{return b.apply(null,arguments)}finally{e(1,a+" time: "+((new Date).getTime()-c)+"ms")}}}function e(a){e.level>=a&&console.log.apply(console,Array.prototype.slice.call(arguments,1))}c.min=function(a){return Math.min.apply(Math,a)},c.max=function(a){return Math.max.apply(Math,a)},c.all=function(a,b){for(var c=0;c0;--i){var b=Math.floor(Math.random()*(i+1)),c=a[b];a[b]=a[i],a[i]=c}},c.propertyAccessor=function(a,b,c,d){return function(e){return arguments.length?(b[c]=e,d&&d(e),a):b[c]}},c.ordering=function(a){var b=[];return a.eachNode(function(a,c){var d=b[c.rank]||(b[c.rank]=[]);d[c.order]=a}),b},c.filterNonSubgraphs=function(a){return function(b){return 0===a.children(b).length}},d.enabled=!1,c.time=d,e.level=0,c.log=e},{}],18:[function(a,b){b.exports="0.4.5"},{}],19:[function(a,b,c){c.Set=a("./lib/Set"),c.PriorityQueue=a("./lib/PriorityQueue"),c.version=a("./lib/version")},{"./lib/PriorityQueue":20,"./lib/Set":21,"./lib/version":23}],20:[function(a,b){function c(){this._arr=[],this._keyIndices={}}b.exports=c,c.prototype.size=function(){return this._arr.length},c.prototype.keys=function(){return this._arr.map(function(a){return a.key})},c.prototype.has=function(a){return a in this._keyIndices},c.prototype.priority=function(a){var b=this._keyIndices[a];return void 0!==b?this._arr[b].priority:void 0},c.prototype.min=function(){if(0===this.size())throw new Error("Queue underflow");return this._arr[0].key},c.prototype.add=function(a,b){var c=this._keyIndices;if(!(a in c)){var d=this._arr,e=d.length;return c[a]=e,d.push({key:a,priority:b}),this._decrease(e),!0}return!1},c.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var a=this._arr.pop();return delete this._keyIndices[a.key],this._heapify(0),a.key},c.prototype.decrease=function(a,b){var c=this._keyIndices[a];if(b>this._arr[c].priority)throw new Error("New priority is greater than current priority. Key: "+a+" Old: "+this._arr[c].priority+" New: "+b);this._arr[c].priority=b,this._decrease(c)},c.prototype._heapify=function(a){var b=this._arr,c=2*a,d=c+1,e=a;c>1,!(c[b].priorityb;++b)this.add(a[b])}function d(a){var b,c=Object.keys(a),d=c.length,e=new Array(d);for(b=0;d>b;++b)e[b]=a[c[b]];return e}var e=a("./util");b.exports=c,c.intersect=function(a){if(0===a.length)return new c;for(var b=new c(e.isArray(a[0])?a[0]:a[0].keys()),d=1,f=a.length;f>d;++d)for(var g=b.keys(),h=e.isArray(a[d])?new c(a[d]):a[d],i=0,j=g.length;j>i;++i){var k=g[i];h.has(k)||b.remove(k)}return b},c.union=function(a){for(var b=e.reduce(a,function(a,b){return a+(b.size?b.size():b.length)},0),d=new Array(b),f=0,g=0,h=a.length;h>g;++g)for(var i=a[g],j=e.isArray(i)?i:i.keys(),k=0,l=j.length;l>k;++k)d[f++]=j[k];return new c(d)},c.prototype.size=function(){return this._size},c.prototype.keys=function(){return d(this._keys)},c.prototype.has=function(a){return a in this._keys},c.prototype.add=function(a){return a in this._keys?!1:(this._keys[a]=a,++this._size,!0)},c.prototype.remove=function(a){return a in this._keys?(delete this._keys[a],--this._size,!0):!1}},{"./util":22}],22:[function(a,b,c){c.isArray=Array.isArray?Array.isArray:function(a){return"[object Array]"===Object.prototype.toString.call(a)},c.reduce="function"!=typeof Array.prototype.reduce?function(a,b,c){"use strict";if(null===a||"undefined"==typeof a)throw new TypeError("Array.prototype.reduce called on null or undefined");if("function"!=typeof b)throw new TypeError(b+" is not a function");var d,e,f=a.length>>>0,g=!1;for(1d;++d)a.hasOwnProperty(d)&&(g?e=b(e,a[d],d,a):(e=a[d],g=!0));if(!g)throw new TypeError("Reduce of empty array with no initial value");return e}:function(a,b,c){return a.reduce(b,c)}},{}],23:[function(a,b){b.exports="1.1.3"},{}],24:[function(a,b,c){c.Graph=a("./lib/Graph"),c.Digraph=a("./lib/Digraph"),c.CGraph=a("./lib/CGraph"),c.CDigraph=a("./lib/CDigraph"),a("./lib/graph-converters"),c.alg={isAcyclic:a("./lib/alg/isAcyclic"),components:a("./lib/alg/components"),dijkstra:a("./lib/alg/dijkstra"),dijkstraAll:a("./lib/alg/dijkstraAll"),findCycles:a("./lib/alg/findCycles"),floydWarshall:a("./lib/alg/floydWarshall"),postorder:a("./lib/alg/postorder"),preorder:a("./lib/alg/preorder"),prim:a("./lib/alg/prim"),tarjan:a("./lib/alg/tarjan"),topsort:a("./lib/alg/topsort")},c.converter={json:a("./lib/converter/json.js")};var d=a("./lib/filter");c.filter={all:d.all,nodesFromList:d.nodesFromList},c.version=a("./lib/version")},{"./lib/CDigraph":26,"./lib/CGraph":27,"./lib/Digraph":28,"./lib/Graph":29,"./lib/alg/components":30,"./lib/alg/dijkstra":31,"./lib/alg/dijkstraAll":32,"./lib/alg/findCycles":33,"./lib/alg/floydWarshall":34,"./lib/alg/isAcyclic":35,"./lib/alg/postorder":36,"./lib/alg/preorder":37,"./lib/alg/prim":38,"./lib/alg/tarjan":39,"./lib/alg/topsort":40,"./lib/converter/json.js":42,"./lib/filter":43,"./lib/graph-converters":44,"./lib/version":46}],25:[function(a,b){function c(){this._value=void 0,this._nodes={},this._edges={},this._nextId=0}function d(a,b,c){(a[b]||(a[b]=new f)).add(c)}function e(a,b,c){var d=a[b];d.remove(c),0===d.size()&&delete a[b]}var f=a("cp-data").Set;b.exports=c,c.prototype.order=function(){return Object.keys(this._nodes).length},c.prototype.size=function(){return Object.keys(this._edges).length},c.prototype.graph=function(a){return 0===arguments.length?this._value:(this._value=a,void 0)},c.prototype.hasNode=function(a){return a in this._nodes},c.prototype.node=function(a,b){var c=this._strictGetNode(a);return 1===arguments.length?c.value:(c.value=b,void 0)},c.prototype.nodes=function(){var a=[];return this.eachNode(function(b){a.push(b)}),a},c.prototype.eachNode=function(a){for(var b in this._nodes){var c=this._nodes[b];a(c.id,c.value)}},c.prototype.hasEdge=function(a){return a in this._edges},c.prototype.edge=function(a,b){var c=this._strictGetEdge(a);return 1===arguments.length?c.value:(c.value=b,void 0)},c.prototype.edges=function(){var a=[];return this.eachEdge(function(b){a.push(b)}),a},c.prototype.eachEdge=function(a){for(var b in this._edges){var c=this._edges[b];a(c.id,c.u,c.v,c.value)}},c.prototype.incidentNodes=function(a){var b=this._strictGetEdge(a);return[b.u,b.v]},c.prototype.addNode=function(a,b){if(void 0===a||null===a){do a="_"+ ++this._nextId;while(this.hasNode(a))}else if(this.hasNode(a))throw new Error("Graph already has node '"+a+"'");return this._nodes[a]={id:a,value:b},a},c.prototype.delNode=function(a){this._strictGetNode(a),this.incidentEdges(a).forEach(function(a){this.delEdge(a)},this),delete this._nodes[a]},c.prototype._addEdge=function(a,b,c,e,f,g){if(this._strictGetNode(b),this._strictGetNode(c),void 0===a||null===a){do a="_"+ ++this._nextId;while(this.hasEdge(a))}else if(this.hasEdge(a))throw new Error("Graph already has edge '"+a+"'");return this._edges[a]={id:a,u:b,v:c,value:e},d(f[c],b,a),d(g[b],c,a),a},c.prototype._delEdge=function(a,b,c){var d=this._strictGetEdge(a);e(b[d.v],d.u,a),e(c[d.u],d.v,a),delete this._edges[a]},c.prototype.copy=function(){var a=new this.constructor;return a.graph(this.graph()),this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(b,c,d,e)}),a._nextId=this._nextId,a},c.prototype.filterNodes=function(a){var b=new this.constructor;return b.graph(this.graph()),this.eachNode(function(c,d){a(c)&&b.addNode(c,d)}),this.eachEdge(function(a,c,d,e){b.hasNode(c)&&b.hasNode(d)&&b.addEdge(a,c,d,e)}),b},c.prototype._strictGetNode=function(a){var b=this._nodes[a];if(void 0===b)throw new Error("Node '"+a+"' is not in graph");return b},c.prototype._strictGetEdge=function(a){var b=this._edges[a];if(void 0===b)throw new Error("Edge '"+a+"' is not in graph");return b}},{"cp-data":19}],26:[function(a,b){var c=a("./Digraph"),d=a("./compoundify"),e=d(c);b.exports=e,e.fromDigraph=function(a){var b=new e,c=a.graph();return void 0!==c&&b.graph(c),a.eachNode(function(a,c){void 0===c?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){void 0===e?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b},e.prototype.toString=function(){return"CDigraph "+JSON.stringify(this,null,2)}},{"./Digraph":28,"./compoundify":41}],27:[function(a,b){var c=a("./Graph"),d=a("./compoundify"),e=d(c);b.exports=e,e.fromGraph=function(a){var b=new e,c=a.graph();return void 0!==c&&b.graph(c),a.eachNode(function(a,c){void 0===c?b.addNode(a):b.addNode(a,c)}),a.eachEdge(function(a,c,d,e){void 0===e?b.addEdge(null,c,d):b.addEdge(null,c,d,e)}),b},e.prototype.toString=function(){return"CGraph "+JSON.stringify(this,null,2)}},{"./Graph":29,"./compoundify":41}],28:[function(a,b){function c(){e.call(this),this._inEdges={},this._outEdges={}}var d=a("./util"),e=a("./BaseGraph"),f=a("cp-data").Set;b.exports=c,c.prototype=new e,c.prototype.constructor=c,c.prototype.isDirected=function(){return!0},c.prototype.successors=function(a){return this._strictGetNode(a),Object.keys(this._outEdges[a]).map(function(a){return this._nodes[a].id},this)},c.prototype.predecessors=function(a){return this._strictGetNode(a),Object.keys(this._inEdges[a]).map(function(a){return this._nodes[a].id},this)},c.prototype.neighbors=function(a){return f.union([this.successors(a),this.predecessors(a)]).keys()},c.prototype.sources=function(){var a=this;return this._filterNodes(function(b){return 0===a.inEdges(b).length})},c.prototype.sinks=function(){var a=this;return this._filterNodes(function(b){return 0===a.outEdges(b).length})},c.prototype.source=function(a){return this._strictGetEdge(a).u},c.prototype.target=function(a){return this._strictGetEdge(a).v},c.prototype.inEdges=function(a,b){this._strictGetNode(a);var c=f.union(d.values(this._inEdges[a])).keys();return arguments.length>1&&(this._strictGetNode(b),c=c.filter(function(a){return this.source(a)===b},this)),c},c.prototype.outEdges=function(a,b){this._strictGetNode(a);var c=f.union(d.values(this._outEdges[a])).keys();return arguments.length>1&&(this._strictGetNode(b),c=c.filter(function(a){return this.target(a)===b},this)),c},c.prototype.incidentEdges=function(a,b){return arguments.length>1?f.union([this.outEdges(a,b),this.outEdges(b,a)]).keys():f.union([this.inEdges(a),this.outEdges(a)]).keys()},c.prototype.toString=function(){return"Digraph "+JSON.stringify(this,null,2)},c.prototype.addNode=function(a,b){return a=e.prototype.addNode.call(this,a,b),this._inEdges[a]={},this._outEdges[a]={},a},c.prototype.delNode=function(a){e.prototype.delNode.call(this,a),delete this._inEdges[a],delete this._outEdges[a]},c.prototype.addEdge=function(a,b,c,d){return e.prototype._addEdge.call(this,a,b,c,d,this._inEdges,this._outEdges)},c.prototype.delEdge=function(a){e.prototype._delEdge.call(this,a,this._inEdges,this._outEdges)},c.prototype._filterNodes=function(a){var b=[];return this.eachNode(function(c){a(c)&&b.push(c)}),b}},{"./BaseGraph":25,"./util":45,"cp-data":19}],29:[function(a,b){function c(){e.call(this),this._incidentEdges={}}var d=a("./util"),e=a("./BaseGraph"),f=a("cp-data").Set;b.exports=c,c.prototype=new e,c.prototype.constructor=c,c.prototype.isDirected=function(){return!1},c.prototype.neighbors=function(a){return this._strictGetNode(a),Object.keys(this._incidentEdges[a]).map(function(a){return this._nodes[a].id},this)},c.prototype.incidentEdges=function(a,b){return this._strictGetNode(a),arguments.length>1?(this._strictGetNode(b),b in this._incidentEdges[a]?this._incidentEdges[a][b].keys():[]):f.union(d.values(this._incidentEdges[a])).keys()
},c.prototype.toString=function(){return"Graph "+JSON.stringify(this,null,2)},c.prototype.addNode=function(a,b){return a=e.prototype.addNode.call(this,a,b),this._incidentEdges[a]={},a},c.prototype.delNode=function(a){e.prototype.delNode.call(this,a),delete this._incidentEdges[a]},c.prototype.addEdge=function(a,b,c,d){return e.prototype._addEdge.call(this,a,b,c,d,this._incidentEdges,this._incidentEdges)},c.prototype.delEdge=function(a){e.prototype._delEdge.call(this,a,this._incidentEdges,this._incidentEdges)}},{"./BaseGraph":25,"./util":45,"cp-data":19}],30:[function(a,b){function c(a){function b(c,d){e.has(c)||(e.add(c),d.push(c),a.neighbors(c).forEach(function(a){b(a,d)}))}var c=[],e=new d;return a.nodes().forEach(function(a){var d=[];b(a,d),d.length>0&&c.push(d)}),c}var d=a("cp-data").Set;b.exports=c},{"cp-data":19}],31:[function(a,b){function c(a,b,c,e){function f(b){var d=a.incidentNodes(b),e=d[0]!==i?d[0]:d[1],f=g[e],k=c(b),l=j.distance+k;if(0>k)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+b+" Weight: "+k);l0&&(i=h.removeMin(),j=g[i],j.distance!==Number.POSITIVE_INFINITY);)e(i).forEach(f);return g}var d=a("cp-data").PriorityQueue;b.exports=c},{"cp-data":19}],32:[function(a,b){function c(a,b,c){var e={};return a.eachNode(function(f){e[f]=d(a,f,b,c)}),e}var d=a("./dijkstra");b.exports=c},{"./dijkstra":31}],33:[function(a,b){function c(a){return d(a).filter(function(a){return a.length>1})}var d=a("./tarjan");b.exports=c},{"./tarjan":39}],34:[function(a,b){function c(a,b,c){var d={},e=a.nodes();return b=b||function(){return 1},c=c||(a.isDirected()?function(b){return a.outEdges(b)}:function(b){return a.incidentEdges(b)}),e.forEach(function(f){d[f]={},d[f][f]={distance:0},e.forEach(function(a){f!==a&&(d[f][a]={distance:Number.POSITIVE_INFINITY})}),c(f).forEach(function(c){var e=a.incidentNodes(c),g=e[0]!==f?e[0]:e[1],h=b(c);hj&&(h[e]=f,i.decrease(e,j))}}var f,g=new d,h={},i=new e;if(0===a.order())return g;a.eachNode(function(a){i.add(a,Number.POSITIVE_INFINITY),g.addNode(a)}),i.decrease(a.nodes()[0],0);for(var j=!1;i.size()>0;){if(f=i.removeMin(),f in h)g.addEdge(null,f,h[f]);else{if(j)throw new Error("Input graph is not connected: "+a);j=!0}a.incidentEdges(f).forEach(c)}return g}var d=a("../Graph"),e=a("cp-data").PriorityQueue;b.exports=c},{"../Graph":29,"cp-data":19}],39:[function(a,b){function c(a){function b(g){var h=e[g]={onStack:!0,lowlink:c,index:c++};if(d.push(g),a.successors(g).forEach(function(a){a in e?e[a].onStack&&(h.lowlink=Math.min(h.lowlink,e[a].index)):(b(a),h.lowlink=Math.min(h.lowlink,e[a].lowlink))}),h.lowlink===h.index){var i,j=[];do i=d.pop(),e[i].onStack=!1,j.push(i);while(g!==i);f.push(j)}}if(!a.isDirected())throw new Error("tarjan can only be applied to a directed graph. Bad input: "+a);var c=0,d=[],e={},f=[];return a.nodes().forEach(function(a){a in e||b(a)}),f}b.exports=c},{}],40:[function(a,b){function c(a){function b(g){if(g in e)throw new d;g in c||(e[g]=!0,c[g]=!0,a.predecessors(g).forEach(function(a){b(a)}),delete e[g],f.push(g))}if(!a.isDirected())throw new Error("topsort can only be applied to a directed graph. Bad input: "+a);var c={},e={},f=[],g=a.sinks();if(0!==a.order()&&0===g.length)throw new d;return a.sinks().forEach(function(a){b(a)}),f}function d(){}b.exports=c,c.CycleException=d,d.prototype.toString=function(){return"Graph has at least one cycle"}},{}],41:[function(a,b){function c(a){function b(){a.call(this),this._parents={},this._children={},this._children[null]=new d}return b.prototype=new a,b.prototype.constructor=b,b.prototype.parent=function(a,b){if(this._strictGetNode(a),arguments.length<2)return this._parents[a];if(a===b)throw new Error("Cannot make "+a+" a parent of itself");null!==b&&this._strictGetNode(b),this._children[this._parents[a]].remove(a),this._parents[a]=b,this._children[b].add(a)},b.prototype.children=function(a){return null!==a&&this._strictGetNode(a),this._children[a].keys()},b.prototype.addNode=function(b,c){return b=a.prototype.addNode.call(this,b,c),this._parents[b]=null,this._children[b]=new d,this._children[null].add(b),b},b.prototype.delNode=function(b){var c=this.parent(b);return this._children[b].keys().forEach(function(a){this.parent(a,c)},this),this._children[c].remove(b),delete this._parents[b],delete this._children[b],a.prototype.delNode.call(this,b)},b.prototype.copy=function(){var b=a.prototype.copy.call(this);return this.nodes().forEach(function(a){b.parent(a,this.parent(a))},this),b},b.prototype.filterNodes=function(b){function c(a){var b=d.parent(a);return null===b||e.hasNode(b)?(f[a]=b,b):b in f?f[b]:c(b)}var d=this,e=a.prototype.filterNodes.call(this,b),f={};return e.eachNode(function(a){e.parent(a,c(a))}),e},b}var d=a("cp-data").Set;b.exports=c},{"cp-data":19}],42:[function(a,b,c){function d(a){return Object.prototype.toString.call(a).slice(8,-1)}var e=a("../Graph"),f=a("../Digraph"),g=a("../CGraph"),h=a("../CDigraph");c.decode=function(a,b,c){if(c=c||f,"Array"!==d(a))throw new Error("nodes is not an Array");if("Array"!==d(b))throw new Error("edges is not an Array");if("string"==typeof c)switch(c){case"graph":c=e;break;case"digraph":c=f;break;case"cgraph":c=g;break;case"cdigraph":c=h;break;default:throw new Error("Unrecognized graph type: "+c)}var i=new c;return a.forEach(function(a){i.addNode(a.id,a.value)}),i.parent&&a.forEach(function(a){a.children&&a.children.forEach(function(b){i.parent(b,a.id)})}),b.forEach(function(a){i.addEdge(a.id,a.u,a.v,a.value)}),i},c.encode=function(a){var b=[],c=[];a.eachNode(function(c,d){var e={id:c,value:d};if(a.children){var f=a.children(c);f.length&&(e.children=f)}b.push(e)}),a.eachEdge(function(a,b,d,e){c.push({id:a,u:b,v:d,value:e})});var d;if(a instanceof h)d="cdigraph";else if(a instanceof g)d="cgraph";else if(a instanceof f)d="digraph";else{if(!(a instanceof e))throw new Error("Couldn't determine type of graph: "+a);d="graph"}return{nodes:b,edges:c,type:d}}},{"../CDigraph":26,"../CGraph":27,"../Digraph":28,"../Graph":29}],43:[function(a,b,c){var d=a("cp-data").Set;c.all=function(){return function(){return!0}},c.nodesFromList=function(a){var b=new d(a);return function(a){return b.has(a)}}},{"cp-data":19}],44:[function(a){var b=a("./Graph"),c=a("./Digraph");b.prototype.toDigraph=b.prototype.asDirected=function(){var a=new c;return this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(null,c,d,e),a.addEdge(null,d,c,e)}),a},c.prototype.toGraph=c.prototype.asUndirected=function(){var a=new b;return this.eachNode(function(b,c){a.addNode(b,c)}),this.eachEdge(function(b,c,d,e){a.addEdge(b,c,d,e)}),a}},{"./Digraph":28,"./Graph":29}],45:[function(a,b,c){c.values=function(a){var b,c=Object.keys(a),d=c.length,e=new Array(d);for(b=0;d>b;++b)e[b]=a[c[b]];return e}},{}],46:[function(a,b){b.exports="0.7.4"},{}]},{},[1]),joint.layout.DirectedGraph={layout:function(a,b){b=b||{};var c=this._prepareData(a),d=dagre.layout();b.debugLevel&&d.debugLevel(b.debugLevel),b.rankDir&&d.rankDir(b.rankDir),b.rankSep&&d.rankSep(b.rankSep),b.edgeSep&&d.edgeSep(b.edgeSep),b.nodeSep&&d.nodeSep(b.nodeSep);var e=d.run(c);return e.eachNode(function(c,d){if(!d.dummy){var e=a.getCell(c);b.setPosition?b.setPosition(e,d):a.get("cells").get(c).set("position",{x:d.x-d.width/2,y:d.y-d.height/2})}}),b.setLinkVertices&&e.eachEdge(function(c,d,e,f){var g=a.getCell(c);g&&(b.setVertices?b.setVertices(g,f.points):g.set("vertices",f.points))}),{width:e.graph().width,height:e.graph().height}},_prepareData:function(a){var b=new dagre.Digraph;return _.each(a.getElements(),function(a){b.hasNode(a.id)||b.addNode(a.id,{width:a.get("size").width,height:a.get("size").height,rank:a.get("rank")})}),_.each(a.getLinks(),function(a){if(!b.hasEdge(a.id)){var c=a.get("source").id,d=a.get("target").id;b.addEdge(a.id,c,d,{minLen:a.get("minLen")||1})}}),b}};




© 2015 - 2024 Weber Informatics LLC | Privacy Policy