-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualizer.js
More file actions
76 lines (55 loc) · 2.38 KB
/
visualizer.js
File metadata and controls
76 lines (55 loc) · 2.38 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
function Visualizer(projects) {
this.page = new Page();
}
function onlyUniqueAndNonNull(value, index, self) {
return value !=null && self.indexOf(value) === index;
}
Visualizer.prototype = new Visualizer();
Visualizer.prototype.constructor = Visualizer;
Visualizer.prototype.edgeTemplate = '"$name" [shape="$shape", style="$style", color="$color"];';
Visualizer.prototype.verticeTemplate = '"$from" -> "$to" [dir="$dir", style="$style", label="$label", color="$color"];';
Visualizer.prototype.viz = function(projects) {
this.page.outputSpan().innerHTML = '';
_.each(projects, this.vizProject.bind(this));
};
Visualizer.prototype.gviz = function(digraph) {
this.page.outputSpan().innerHTML = '';
this.vizDigraph(digraph);
};
Visualizer.prototype.vizDigraph = function(digraph) {
var that = this;
console.log(digraph);
this.page.outputSpan().innerHTML += Viz(digraph);
}
Visualizer.prototype.vizProject = function(project) {
var that = this;
var digraph = 'digraph G { ';
digraph += _.reduce(project.components, function(s, comp) {
return s + that.vizComponent(comp);
}, '');
digraph += _.reduce(project.dependencies, function(s, dep) {
return s + that.vizDependency(dep);
}, '');
digraph += ' }';
console.log(digraph);
this.page.outputSpan().innerHTML += '<h1>'+project.name+'</h1>';
this.page.outputSpan().innerHTML += Viz(digraph);
}
Visualizer.prototype.vizComponent = function(comp) {
var compString = String(this.edgeTemplate);
compString = compString.replace('$name', comp.name);
compString = compString.replace('$shape', comp.shape == null ? '' : comp.shape);
compString = compString.replace('$style', comp.style == null ? '' : comp.style);
compString = compString.replace('$color', comp.color == null ? '' : comp.color);
return compString
};
Visualizer.prototype.vizDependency = function(dep) {
var depString = String(this.verticeTemplate);
depString = depString.replace('$from', dep.from);
depString = depString.replace('$to', dep.to);
depString = depString.replace('$dir', dep.dir == null ? '' : dep.dir);
depString = depString.replace('$style', dep.style == null ? '' : dep.style);
depString = depString.replace('$label', dep.label == null ? '' : dep.label);
depString = depString.replace('$color', dep.color == null ? '' : dep.color);
return depString;
};