-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·62 lines (48 loc) · 1.24 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env node
var fs = require('fs')
, graphviz = require('graphviz')
;
var file = process.argv[2];
var fileContents = fs.readFileSync(file);
var wf = JSON.parse(fileContents);
var g = graphviz.digraph("G");
var signals = (wf.data || wf.signals);
var processes = (wf.processes || wf.tasks );
var sigMap = {};
signals.forEach(function(sig, ix) {
sigMap[sig.name] = ix;
});
var sigToId = function(sig) {
if(!isNaN(parseInt(sig))) {
return sig;
} else {
return sigMap[sig];
}
};
(wf.tasks || wf.processes).forEach(function(e, ix) {
var id = "t_" + ix;
var n = g.addNode(id);
n.set('label', e.name);
e.ins.forEach(function(e){
var n = e.toString().split(":")[0];
g.addEdge("d_" + sigToId(n), id);
})
e.outs.forEach(function(e){
var n = e.toString().split(":")[0];
g.addEdge(id, "d_" + sigToId(n));
})
});
var sigNodes = {};
(wf.data || wf.signals).forEach(function(e, ix) {
var n = g.addNode("d_" + ix);
n.set('label', e.name);
n.set('shape', "folder");
sigNodes[ix] = n;
});
wf.ins.forEach(function(e){
sigNodes[sigToId(e)].set('color', 'green');
});
wf.outs.forEach(function(e){
sigNodes[sigToId(e)].set('color', 'red');
});
fs.writeFileSync(file + ".dot", g.to_dot());