@dagrejs/dagre 1.0.1 → 1.0.4
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/README.md +0 -7
- package/dist/dagre.js +443 -445
- package/dist/dagre.min.js +52 -52
- package/index.d.ts +139 -0
- package/lib/acyclic.js +13 -13
- package/lib/add-border-segments.js +7 -7
- package/lib/coordinate-system.js +8 -8
- package/lib/data/list.js +34 -32
- package/lib/debug.js +9 -11
- package/lib/greedy-fas.js +29 -29
- package/lib/layout.js +96 -96
- package/lib/nesting-graph.js +20 -22
- package/lib/normalize.js +13 -13
- package/lib/order/add-subgraph-constraints.js +3 -3
- package/lib/order/barycenter.js +3 -3
- package/lib/order/build-layer-graph.js +8 -8
- package/lib/order/cross-count.js +11 -11
- package/lib/order/index.js +15 -15
- package/lib/order/init-order.js +7 -7
- package/lib/order/resolve-conflicts.js +12 -12
- package/lib/order/sort-subgraph.js +16 -16
- package/lib/order/sort.js +7 -7
- package/lib/parent-dummy-chains.js +19 -19
- package/lib/position/bk.js +67 -67
- package/lib/position/index.js +6 -6
- package/lib/rank/feasible-tree.js +1 -1
- package/lib/rank/network-simplex.js +4 -4
- package/lib/util.js +32 -32
- package/lib/version.js +1 -1
- package/package.json +3 -1
package/lib/util.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
"use strict";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let Graph = require("@dagrejs/graphlib").Graph;
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
8
|
addBorderNode,
|
|
@@ -30,7 +30,7 @@ module.exports = {
|
|
|
30
30
|
* Adds a dummy node to the graph and return v.
|
|
31
31
|
*/
|
|
32
32
|
function addDummyNode(g, type, attrs, name) {
|
|
33
|
-
|
|
33
|
+
let v;
|
|
34
34
|
do {
|
|
35
35
|
v = uniqueId(name);
|
|
36
36
|
} while (g.hasNode(v));
|
|
@@ -45,11 +45,11 @@ function addDummyNode(g, type, attrs, name) {
|
|
|
45
45
|
* associated with multi-edges.
|
|
46
46
|
*/
|
|
47
47
|
function simplify(g) {
|
|
48
|
-
|
|
48
|
+
let simplified = new Graph().setGraph(g.graph());
|
|
49
49
|
g.nodes().forEach(v => simplified.setNode(v, g.node(v)));
|
|
50
50
|
g.edges().forEach(e => {
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
let simpleLabel = simplified.edge(e.v, e.w) || { weight: 0, minlen: 1 };
|
|
52
|
+
let label = g.edge(e);
|
|
53
53
|
simplified.setEdge(e.v, e.w, {
|
|
54
54
|
weight: simpleLabel.weight + label.weight,
|
|
55
55
|
minlen: Math.max(simpleLabel.minlen, label.minlen)
|
|
@@ -59,7 +59,7 @@ function simplify(g) {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
function asNonCompoundGraph(g) {
|
|
62
|
-
|
|
62
|
+
let simplified = new Graph({ multigraph: g.isMultigraph() }).setGraph(g.graph());
|
|
63
63
|
g.nodes().forEach(v => {
|
|
64
64
|
if (!g.children(v).length) {
|
|
65
65
|
simplified.setNode(v, g.node(v));
|
|
@@ -72,8 +72,8 @@ function asNonCompoundGraph(g) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
function successorWeights(g) {
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
let weightMap = g.nodes().map(v => {
|
|
76
|
+
let sucs = {};
|
|
77
77
|
g.outEdges(v).forEach(e => {
|
|
78
78
|
sucs[e.w] = (sucs[e.w] || 0) + g.edge(e).weight;
|
|
79
79
|
});
|
|
@@ -83,8 +83,8 @@ function successorWeights(g) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function predecessorWeights(g) {
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
let weightMap = g.nodes().map(v => {
|
|
87
|
+
let preds = {};
|
|
88
88
|
g.inEdges(v).forEach(e => {
|
|
89
89
|
preds[e.v] = (preds[e.v] || 0) + g.edge(e).weight;
|
|
90
90
|
});
|
|
@@ -98,21 +98,21 @@ function predecessorWeights(g) {
|
|
|
98
98
|
* ({x, y, width, height}) if it were pointing at the rectangle's center.
|
|
99
99
|
*/
|
|
100
100
|
function intersectRect(rect, point) {
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
let x = rect.x;
|
|
102
|
+
let y = rect.y;
|
|
103
103
|
|
|
104
104
|
// Rectangle intersection algorithm from:
|
|
105
105
|
// http://math.stackexchange.com/questions/108113/find-edge-between-two-boxes
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
106
|
+
let dx = point.x - x;
|
|
107
|
+
let dy = point.y - y;
|
|
108
|
+
let w = rect.width / 2;
|
|
109
|
+
let h = rect.height / 2;
|
|
110
110
|
|
|
111
111
|
if (!dx && !dy) {
|
|
112
112
|
throw new Error("Not possible to find intersection inside of the rectangle");
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
|
|
115
|
+
let sx, sy;
|
|
116
116
|
if (Math.abs(dy) * w > Math.abs(dx) * h) {
|
|
117
117
|
// Intersection is top or bottom of rect.
|
|
118
118
|
if (dy < 0) {
|
|
@@ -137,10 +137,10 @@ function intersectRect(rect, point) {
|
|
|
137
137
|
* function will produce a matrix with the ids of each node.
|
|
138
138
|
*/
|
|
139
139
|
function buildLayerMatrix(g) {
|
|
140
|
-
|
|
140
|
+
let layering = range(maxRank(g) + 1).map(() => []);
|
|
141
141
|
g.nodes().forEach(v => {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
let node = g.node(v);
|
|
143
|
+
let rank = node.rank;
|
|
144
144
|
if (rank !== undefined) {
|
|
145
145
|
layering[rank][node.order] = v;
|
|
146
146
|
}
|
|
@@ -153,8 +153,8 @@ function buildLayerMatrix(g) {
|
|
|
153
153
|
* rank(v) >= 0 and at least one node w has rank(w) = 0.
|
|
154
154
|
*/
|
|
155
155
|
function normalizeRanks(g) {
|
|
156
|
-
|
|
157
|
-
|
|
156
|
+
let min = Math.min(...g.nodes().map(v => {
|
|
157
|
+
let rank = g.node(v).rank;
|
|
158
158
|
if (rank === undefined) {
|
|
159
159
|
return Number.MAX_VALUE;
|
|
160
160
|
}
|
|
@@ -162,7 +162,7 @@ function normalizeRanks(g) {
|
|
|
162
162
|
return rank;
|
|
163
163
|
}));
|
|
164
164
|
g.nodes().forEach(v => {
|
|
165
|
-
|
|
165
|
+
let node = g.node(v);
|
|
166
166
|
if (node.hasOwnProperty("rank")) {
|
|
167
167
|
node.rank -= min;
|
|
168
168
|
}
|
|
@@ -171,19 +171,19 @@ function normalizeRanks(g) {
|
|
|
171
171
|
|
|
172
172
|
function removeEmptyRanks(g) {
|
|
173
173
|
// Ranks may not start at 0, so we need to offset them
|
|
174
|
-
|
|
174
|
+
let offset = Math.min(...g.nodes().map(v => g.node(v).rank));
|
|
175
175
|
|
|
176
|
-
|
|
176
|
+
let layers = [];
|
|
177
177
|
g.nodes().forEach(v => {
|
|
178
|
-
|
|
178
|
+
let rank = g.node(v).rank - offset;
|
|
179
179
|
if (!layers[rank]) {
|
|
180
180
|
layers[rank] = [];
|
|
181
181
|
}
|
|
182
182
|
layers[rank].push(v);
|
|
183
183
|
});
|
|
184
184
|
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
let delta = 0;
|
|
186
|
+
let nodeRankFactor = g.graph().nodeRankFactor;
|
|
187
187
|
Array.from(layers).forEach((vs, i) => {
|
|
188
188
|
if (vs === undefined && i % nodeRankFactor !== 0) {
|
|
189
189
|
--delta;
|
|
@@ -194,7 +194,7 @@ function removeEmptyRanks(g) {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
function addBorderNode(g, prefix, rank, order) {
|
|
197
|
-
|
|
197
|
+
let node = {
|
|
198
198
|
width: 0,
|
|
199
199
|
height: 0
|
|
200
200
|
};
|
|
@@ -207,7 +207,7 @@ function addBorderNode(g, prefix, rank, order) {
|
|
|
207
207
|
|
|
208
208
|
function maxRank(g) {
|
|
209
209
|
return Math.max(...g.nodes().map(v => {
|
|
210
|
-
|
|
210
|
+
let rank = g.node(v).rank;
|
|
211
211
|
if (rank === undefined) {
|
|
212
212
|
return Number.MIN_VALUE;
|
|
213
213
|
}
|
|
@@ -222,7 +222,7 @@ function maxRank(g) {
|
|
|
222
222
|
* into `rhs.
|
|
223
223
|
*/
|
|
224
224
|
function partition(collection, fn) {
|
|
225
|
-
|
|
225
|
+
let result = { lhs: [], rhs: [] };
|
|
226
226
|
collection.forEach(value => {
|
|
227
227
|
if (fn(value)) {
|
|
228
228
|
result.lhs.push(value);
|
|
@@ -238,7 +238,7 @@ function partition(collection, fn) {
|
|
|
238
238
|
* time it takes to execute the function.
|
|
239
239
|
*/
|
|
240
240
|
function time(name, fn) {
|
|
241
|
-
|
|
241
|
+
let start = Date.now();
|
|
242
242
|
try {
|
|
243
243
|
return fn();
|
|
244
244
|
} finally {
|
package/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
module.exports = "1.0.
|
|
1
|
+
module.exports = "1.0.4";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dagrejs/dagre",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Graph layout for JavaScript",
|
|
5
5
|
"author": "Chris Pettitt <cpettitt@gmail.com>",
|
|
6
6
|
"contributors": [
|
|
@@ -14,9 +14,11 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"index.js",
|
|
17
|
+
"index.d.ts",
|
|
17
18
|
"dist/",
|
|
18
19
|
"lib/"
|
|
19
20
|
],
|
|
21
|
+
"types": "index.d.ts",
|
|
20
22
|
"keywords": [
|
|
21
23
|
"graph",
|
|
22
24
|
"layout"
|