@dagrejs/dagre 1.0.4 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/dagre.js CHANGED
@@ -1309,7 +1309,12 @@ module.exports = order;
1309
1309
  * 1. Graph nodes will have an "order" attribute based on the results of the
1310
1310
  * algorithm.
1311
1311
  */
1312
- function order(g) {
1312
+ function order(g, opts) {
1313
+ if (opts && typeof opts.customOrder === 'function') {
1314
+ opts.customOrder(g, order);
1315
+ return;
1316
+ }
1317
+
1313
1318
  let maxRank = util.maxRank(g),
1314
1319
  downLayerGraphs = buildLayerGraphs(g, util.range(1, maxRank + 1), "inEdges"),
1315
1320
  upLayerGraphs = buildLayerGraphs(g, util.range(maxRank - 1, -1, -1), "outEdges");
@@ -1317,6 +1322,10 @@ function order(g) {
1317
1322
  let layering = initOrder(g);
1318
1323
  assignOrder(g, layering);
1319
1324
 
1325
+ if (opts && opts.disableOptimalOrderHeuristic) {
1326
+ return;
1327
+ }
1328
+
1320
1329
  let bestCC = Number.POSITIVE_INFINITY,
1321
1330
  best;
1322
1331
 
@@ -1810,7 +1819,8 @@ function findType1Conflicts(g, layering) {
1810
1819
  return layer;
1811
1820
  }
1812
1821
 
1813
- layering.reduce(visitLayer);
1822
+ layering.length && layering.reduce(visitLayer);
1823
+
1814
1824
  return conflicts;
1815
1825
  }
1816
1826
 
@@ -1855,7 +1865,8 @@ function findType2Conflicts(g, layering) {
1855
1865
  return south;
1856
1866
  }
1857
1867
 
1858
- layering.reduce(visitLayer);
1868
+ layering.length && layering.reduce(visitLayer);
1869
+
1859
1870
  return conflicts;
1860
1871
  }
1861
1872
 
@@ -2948,7 +2959,7 @@ function zipObject(props, values) {
2948
2959
  }
2949
2960
 
2950
2961
  },{"@dagrejs/graphlib":29}],28:[function(require,module,exports){
2951
- module.exports = "1.0.4";
2962
+ module.exports = "1.1.1";
2952
2963
 
2953
2964
  },{}],29:[function(require,module,exports){
2954
2965
  /**
@@ -4342,7 +4353,7 @@ function read(json) {
4342
4353
  }
4343
4354
 
4344
4355
  },{"./graph":44}],47:[function(require,module,exports){
4345
- module.exports = '2.1.13';
4356
+ module.exports = '2.2.1';
4346
4357
 
4347
4358
  },{}]},{},[1])(1)
4348
4359
  });
package/dist/dagre.min.js CHANGED
@@ -207,7 +207,7 @@ let cc=0;southEntries.forEach(entry=>{let index=entry.pos+firstIndex;tree[index]
207
207
  *
208
208
  * 1. Graph nodes will have an "order" attribute based on the results of the
209
209
  * algorithm.
210
- */function order(g){let maxRank=util.maxRank(g),downLayerGraphs=buildLayerGraphs(g,util.range(1,maxRank+1),"inEdges"),upLayerGraphs=buildLayerGraphs(g,util.range(maxRank-1,-1,-1),"outEdges");let layering=initOrder(g);assignOrder(g,layering);let bestCC=Number.POSITIVE_INFINITY,best;for(let i=0,lastBest=0;lastBest<4;++i,++lastBest){sweepLayerGraphs(i%2?downLayerGraphs:upLayerGraphs,i%4>=2);layering=util.buildLayerMatrix(g);let cc=crossCount(g,layering);if(cc<bestCC){lastBest=0;best=Object.assign({},layering);bestCC=cc}}assignOrder(g,best)}function buildLayerGraphs(g,ranks,relationship){return ranks.map(function(rank){return buildLayerGraph(g,rank,relationship)})}function sweepLayerGraphs(layerGraphs,biasRight){let cg=new Graph;layerGraphs.forEach(function(lg){let root=lg.graph().root;let sorted=sortSubgraph(lg,root,cg,biasRight);sorted.vs.forEach((v,i)=>lg.node(v).order=i);addSubgraphConstraints(lg,cg,sorted.vs)})}function assignOrder(g,layering){Object.values(layering).forEach(layer=>layer.forEach((v,i)=>g.node(v).order=i))}},{"../util":27,"./add-subgraph-constraints":11,"./build-layer-graph":13,"./cross-count":14,"./init-order":16,"./sort-subgraph":18,"@dagrejs/graphlib":29}],16:[function(require,module,exports){"use strict";let util=require("../util");module.exports=initOrder;
210
+ */function order(g,opts){if(opts&&typeof opts.customOrder==="function"){opts.customOrder(g,order);return}let maxRank=util.maxRank(g),downLayerGraphs=buildLayerGraphs(g,util.range(1,maxRank+1),"inEdges"),upLayerGraphs=buildLayerGraphs(g,util.range(maxRank-1,-1,-1),"outEdges");let layering=initOrder(g);assignOrder(g,layering);if(opts&&opts.disableOptimalOrderHeuristic){return}let bestCC=Number.POSITIVE_INFINITY,best;for(let i=0,lastBest=0;lastBest<4;++i,++lastBest){sweepLayerGraphs(i%2?downLayerGraphs:upLayerGraphs,i%4>=2);layering=util.buildLayerMatrix(g);let cc=crossCount(g,layering);if(cc<bestCC){lastBest=0;best=Object.assign({},layering);bestCC=cc}}assignOrder(g,best)}function buildLayerGraphs(g,ranks,relationship){return ranks.map(function(rank){return buildLayerGraph(g,rank,relationship)})}function sweepLayerGraphs(layerGraphs,biasRight){let cg=new Graph;layerGraphs.forEach(function(lg){let root=lg.graph().root;let sorted=sortSubgraph(lg,root,cg,biasRight);sorted.vs.forEach((v,i)=>lg.node(v).order=i);addSubgraphConstraints(lg,cg,sorted.vs)})}function assignOrder(g,layering){Object.values(layering).forEach(layer=>layer.forEach((v,i)=>g.node(v).order=i))}},{"../util":27,"./add-subgraph-constraints":11,"./build-layer-graph":13,"./cross-count":14,"./init-order":16,"./sort-subgraph":18,"@dagrejs/graphlib":29}],16:[function(require,module,exports){"use strict";let util=require("../util");module.exports=initOrder;
211
211
  /*
212
212
  * Assigns an initial order value for each node by performing a DFS search
213
213
  * starting from nodes in the first rank. Nodes are assigned an order in their
@@ -277,7 +277,7 @@ parent=w;while((parent=g.parent(parent))!==lca){wPath.push(parent)}return{path:v
277
277
  k0=0,
278
278
  // Tracks the last node in this layer scanned for crossings with a type-1
279
279
  // segment.
280
- scanPos=0,prevLayerLength=prevLayer.length,lastNode=layer[layer.length-1];layer.forEach((v,i)=>{let w=findOtherInnerSegmentNode(g,v),k1=w?g.node(w).order:prevLayerLength;if(w||v===lastNode){layer.slice(scanPos,i+1).forEach(scanNode=>{g.predecessors(scanNode).forEach(u=>{let uLabel=g.node(u),uPos=uLabel.order;if((uPos<k0||k1<uPos)&&!(uLabel.dummy&&g.node(scanNode).dummy)){addConflict(conflicts,u,scanNode)}})});scanPos=i+1;k0=k1}});return layer}layering.reduce(visitLayer);return conflicts}function findType2Conflicts(g,layering){let conflicts={};function scan(south,southPos,southEnd,prevNorthBorder,nextNorthBorder){let v;util.range(southPos,southEnd).forEach(i=>{v=south[i];if(g.node(v).dummy){g.predecessors(v).forEach(u=>{let uNode=g.node(u);if(uNode.dummy&&(uNode.order<prevNorthBorder||uNode.order>nextNorthBorder)){addConflict(conflicts,u,v)}})}})}function visitLayer(north,south){let prevNorthPos=-1,nextNorthPos,southPos=0;south.forEach((v,southLookahead)=>{if(g.node(v).dummy==="border"){let predecessors=g.predecessors(v);if(predecessors.length){nextNorthPos=g.node(predecessors[0]).order;scan(south,southPos,southLookahead,prevNorthPos,nextNorthPos);southPos=southLookahead;prevNorthPos=nextNorthPos}}scan(south,southPos,south.length,nextNorthPos,north.length)});return south}layering.reduce(visitLayer);return conflicts}function findOtherInnerSegmentNode(g,v){if(g.node(v).dummy){return g.predecessors(v).find(u=>g.node(u).dummy)}}function addConflict(conflicts,v,w){if(v>w){let tmp=v;v=w;w=tmp}let conflictsV=conflicts[v];if(!conflictsV){conflicts[v]=conflictsV={}}conflictsV[w]=true}function hasConflict(conflicts,v,w){if(v>w){let tmp=v;v=w;w=tmp}return!!conflicts[v]&&conflicts[v].hasOwnProperty(w)}
280
+ scanPos=0,prevLayerLength=prevLayer.length,lastNode=layer[layer.length-1];layer.forEach((v,i)=>{let w=findOtherInnerSegmentNode(g,v),k1=w?g.node(w).order:prevLayerLength;if(w||v===lastNode){layer.slice(scanPos,i+1).forEach(scanNode=>{g.predecessors(scanNode).forEach(u=>{let uLabel=g.node(u),uPos=uLabel.order;if((uPos<k0||k1<uPos)&&!(uLabel.dummy&&g.node(scanNode).dummy)){addConflict(conflicts,u,scanNode)}})});scanPos=i+1;k0=k1}});return layer}layering.length&&layering.reduce(visitLayer);return conflicts}function findType2Conflicts(g,layering){let conflicts={};function scan(south,southPos,southEnd,prevNorthBorder,nextNorthBorder){let v;util.range(southPos,southEnd).forEach(i=>{v=south[i];if(g.node(v).dummy){g.predecessors(v).forEach(u=>{let uNode=g.node(u);if(uNode.dummy&&(uNode.order<prevNorthBorder||uNode.order>nextNorthBorder)){addConflict(conflicts,u,v)}})}})}function visitLayer(north,south){let prevNorthPos=-1,nextNorthPos,southPos=0;south.forEach((v,southLookahead)=>{if(g.node(v).dummy==="border"){let predecessors=g.predecessors(v);if(predecessors.length){nextNorthPos=g.node(predecessors[0]).order;scan(south,southPos,southLookahead,prevNorthPos,nextNorthPos);southPos=southLookahead;prevNorthPos=nextNorthPos}}scan(south,southPos,south.length,nextNorthPos,north.length)});return south}layering.length&&layering.reduce(visitLayer);return conflicts}function findOtherInnerSegmentNode(g,v){if(g.node(v).dummy){return g.predecessors(v).find(u=>g.node(u).dummy)}}function addConflict(conflicts,v,w){if(v>w){let tmp=v;v=w;w=tmp}let conflictsV=conflicts[v];if(!conflictsV){conflicts[v]=conflictsV={}}conflictsV[w]=true}function hasConflict(conflicts,v,w){if(v>w){let tmp=v;v=w;w=tmp}return!!conflicts[v]&&conflicts[v].hasOwnProperty(w)}
281
281
  /*
282
282
  * Try to align nodes into vertical "blocks" where possible. This algorithm
283
283
  * attempts to align a node with one of its median neighbors. If the edge
@@ -495,7 +495,7 @@ let offset=Math.min(...g.nodes().map(v=>g.node(v).rank));let layers=[];g.nodes()
495
495
  /*
496
496
  * Returns a new function that wraps `fn` with a timer. The wrapper logs the
497
497
  * time it takes to execute the function.
498
- */function time(name,fn){let start=Date.now();try{return fn()}finally{console.log(name+" time: "+(Date.now()-start)+"ms")}}function notime(name,fn){return fn()}let idCounter=0;function uniqueId(prefix){var id=++idCounter;return toString(prefix)+id}function range(start,limit,step=1){if(limit==null){limit=start;start=0}let endCon=i=>i<limit;if(step<0){endCon=i=>limit<i}const range=[];for(let i=start;endCon(i);i+=step){range.push(i)}return range}function pick(source,keys){const dest={};for(const key of keys){if(source[key]!==undefined){dest[key]=source[key]}}return dest}function mapValues(obj,funcOrProp){let func=funcOrProp;if(typeof funcOrProp==="string"){func=val=>val[funcOrProp]}return Object.entries(obj).reduce((acc,[k,v])=>{acc[k]=func(v,k);return acc},{})}function zipObject(props,values){return props.reduce((acc,key,i)=>{acc[key]=values[i];return acc},{})}},{"@dagrejs/graphlib":29}],28:[function(require,module,exports){module.exports="1.0.4"},{}],29:[function(require,module,exports){
498
+ */function time(name,fn){let start=Date.now();try{return fn()}finally{console.log(name+" time: "+(Date.now()-start)+"ms")}}function notime(name,fn){return fn()}let idCounter=0;function uniqueId(prefix){var id=++idCounter;return toString(prefix)+id}function range(start,limit,step=1){if(limit==null){limit=start;start=0}let endCon=i=>i<limit;if(step<0){endCon=i=>limit<i}const range=[];for(let i=start;endCon(i);i+=step){range.push(i)}return range}function pick(source,keys){const dest={};for(const key of keys){if(source[key]!==undefined){dest[key]=source[key]}}return dest}function mapValues(obj,funcOrProp){let func=funcOrProp;if(typeof funcOrProp==="string"){func=val=>val[funcOrProp]}return Object.entries(obj).reduce((acc,[k,v])=>{acc[k]=func(v,k);return acc},{})}function zipObject(props,values){return props.reduce((acc,key,i)=>{acc[key]=values[i];return acc},{})}},{"@dagrejs/graphlib":29}],28:[function(require,module,exports){module.exports="1.1.1"},{}],29:[function(require,module,exports){
499
499
  /**
500
500
  * Copyright (c) 2014, Chris Pettitt
501
501
  * All rights reserved.
@@ -798,4 +798,4 @@ module.exports={Graph:require("./graph"),version:require("./version")}},{"./grap
798
798
  * // ['a', 'b']
799
799
  * g2.edges()
800
800
  * // [ { v: 'a', w: 'b' } ]
801
- */function read(json){var g=new Graph(json.options).setGraph(json.value);json.nodes.forEach(function(entry){g.setNode(entry.v,entry.value);if(entry.parent){g.setParent(entry.v,entry.parent)}});json.edges.forEach(function(entry){g.setEdge({v:entry.v,w:entry.w,name:entry.name},entry.value)});return g}},{"./graph":44}],47:[function(require,module,exports){module.exports="2.1.13"},{}]},{},[1])(1)});
801
+ */function read(json){var g=new Graph(json.options).setGraph(json.value);json.nodes.forEach(function(entry){g.setNode(entry.v,entry.value);if(entry.parent){g.setParent(entry.v,entry.parent)}});json.edges.forEach(function(entry){g.setEdge({v:entry.v,w:entry.w,name:entry.name},entry.value)});return g}},{"./graph":44}],47:[function(require,module,exports){module.exports="2.2.1"},{}]},{},[1])(1)});
package/index.d.ts CHANGED
@@ -105,11 +105,18 @@ declare module '@dagrejs/dagre' {
105
105
  weight?: number | undefined;
106
106
  width?: number | undefined;
107
107
  height?: number | undefined;
108
- lablepos?: 'l' | 'c' | 'r' | undefined;
108
+ labelpos?: 'l' | 'c' | 'r' | undefined;
109
109
  labeloffest?: number | undefined;
110
110
  }
111
111
 
112
- export function layout(graph: graphlib.Graph, layout?: GraphLabel & NodeConfig & EdgeConfig): void;
112
+ export interface LayoutConfig {
113
+ customOrder?: (graph: graphlib.Graph, order: (graph: graphlib.Graph, opts: configUnion) => void) => void;
114
+ disableOptimalOrderHeuristic?: boolean;
115
+ }
116
+
117
+ type configUnion = GraphLabel & NodeConfig & EdgeConfig & LayoutConfig;
118
+
119
+ export function layout(graph: graphlib.Graph, layout?: configUnion): void;
113
120
 
114
121
  export interface Edge {
115
122
  v: string;
@@ -132,6 +139,7 @@ declare module '@dagrejs/dagre' {
132
139
  padding?: number | undefined;
133
140
  paddingX?: number | undefined;
134
141
  paddingY?: number | undefined;
142
+ rank?: number | undefined;
135
143
  rx?: number | undefined;
136
144
  ry?: number | undefined;
137
145
  shape?: string | undefined;
@@ -25,7 +25,12 @@ module.exports = order;
25
25
  * 1. Graph nodes will have an "order" attribute based on the results of the
26
26
  * algorithm.
27
27
  */
28
- function order(g) {
28
+ function order(g, opts) {
29
+ if (opts && typeof opts.customOrder === 'function') {
30
+ opts.customOrder(g, order);
31
+ return;
32
+ }
33
+
29
34
  let maxRank = util.maxRank(g),
30
35
  downLayerGraphs = buildLayerGraphs(g, util.range(1, maxRank + 1), "inEdges"),
31
36
  upLayerGraphs = buildLayerGraphs(g, util.range(maxRank - 1, -1, -1), "outEdges");
@@ -33,6 +38,10 @@ function order(g) {
33
38
  let layering = initOrder(g);
34
39
  assignOrder(g, layering);
35
40
 
41
+ if (opts && opts.disableOptimalOrderHeuristic) {
42
+ return;
43
+ }
44
+
36
45
  let bestCC = Number.POSITIVE_INFINITY,
37
46
  best;
38
47
 
@@ -75,7 +75,8 @@ function findType1Conflicts(g, layering) {
75
75
  return layer;
76
76
  }
77
77
 
78
- layering.reduce(visitLayer);
78
+ layering.length && layering.reduce(visitLayer);
79
+
79
80
  return conflicts;
80
81
  }
81
82
 
@@ -120,7 +121,8 @@ function findType2Conflicts(g, layering) {
120
121
  return south;
121
122
  }
122
123
 
123
- layering.reduce(visitLayer);
124
+ layering.length && layering.reduce(visitLayer);
125
+
124
126
  return conflicts;
125
127
  }
126
128
 
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- module.exports = "1.0.4";
1
+ module.exports = "1.1.1";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dagrejs/dagre",
3
- "version": "1.0.4",
3
+ "version": "1.1.1",
4
4
  "description": "Graph layout for JavaScript",
5
5
  "author": "Chris Pettitt <cpettitt@gmail.com>",
6
6
  "contributors": [
@@ -24,7 +24,7 @@
24
24
  "layout"
25
25
  ],
26
26
  "dependencies": {
27
- "@dagrejs/graphlib": "2.1.13"
27
+ "@dagrejs/graphlib": "2.2.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "benchmark": "2.1.4",
@@ -35,7 +35,6 @@
35
35
  "jshint-stylish": "2.2.1",
36
36
  "karma": "6.4.1",
37
37
  "karma-chrome-launcher": "3.1.1",
38
- "karma-firefox-launcher": "2.1.2",
39
38
  "karma-mocha": "2.0.1",
40
39
  "karma-requirejs": "1.1.0",
41
40
  "karma-safari-launcher": "1.0.0",