Debian Codegraph @

lib/rank/index.js

raw symbols SCIP
1 "use strict";
2
3 var rankUtil = require("./util");
4 var longestPath = rankUtil.longestPath;
5 var feasibleTree = require("./feasible-tree");
6 var networkSimplex = require("./network-simplex");
7
8 module.exports = rank;
9
10 /*
11 * Assigns a rank to each node in the input graph that respects the "minlen"
12 * constraint specified on edges between nodes.
13 *
14 * This basic structure is derived from Gansner, et al., "A Technique for
15 * Drawing Directed Graphs."
16 *
17 * Pre-conditions:
18 *
19 * 1. Graph must be a connected DAG
20 * 2. Graph nodes must be objects
21 * 3. Graph edges must have "weight" and "minlen" attributes
22 *
23 * Post-conditions:
24 *
25 * 1. Graph nodes will have a "rank" attribute based on the results of the
26 * algorithm. Ranks can start at any index (including negative), we'll
27 * fix them up later.
28 */
29 function rank(g) {
30 switch(g.graph().ranker) {
31 case "network-simplex": networkSimplexRanker(g); break;
32 case "tight-tree": tightTreeRanker(g); break;
33 case "longest-path": longestPathRanker(g); break;
34 default: networkSimplexRanker(g);
35 }
36 }
37
38 // A fast and simple ranker, but results are far from optimal.
39 var longestPathRanker = longestPath;
40
41 function tightTreeRanker(g) {
42 longestPath(g);
43 feasibleTree(g);
44 }
45
46 function networkSimplexRanker(g) {
47 networkSimplex(g);
48 }