-
Notifications
You must be signed in to change notification settings - Fork 2
/
web.go
144 lines (133 loc) · 3.65 KB
/
web.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package main
import (
"fmt"
"net/http"
"github.com/fjukstad/gotoscapejs"
"github.com/fjukstad/walrus/pipeline"
)
var vis = `
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.2.12/cytoscape.js"></script>
<script
src="https://code.jquery.com/jquery-3.1.1.js"
integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA="
crossorigin="anonymous"></script>
<script src="https://unpkg.com/[email protected]/dist/dagre.js"></script>
<script src="https://cytoscape.github.io/cytoscape.js-dagre/cytoscape-dagre.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/qtip2/2.2.0/jquery.qtip.min.css" rel="stylesheet" type="text/css" />
<script src="https://cdn.rawgit.com/cytoscape/cytoscape.js-qtip/2.7.1/cytoscape-qtip.js"></script>
<style>
#cy {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="cy"></div>
<script>
var cy = cytoscape({
container: $('#cy'),
boxSelectionEnabled: false,
autounselectify: true,
layout: {
name:'dagre'
},
style: [
{
selector: 'node',
style: {
'content': 'data(id)',
'text-opacity': 0.5,
'text-valign': 'center',
'text-halign': 'right',
'background-color': '#11479e'
}
},
{
selector: 'edge',
style: {
'curve-style': 'bezier',
'width': 4,
'target-arrow-shape': 'triangle',
'line-color': '#9dbaea',
'target-arrow-color': '#9dbaea',
}
}
],
});
$.get( "/graph", function( data ) {
console.log(data)
cy.add(JSON.parse(data).elements)
console.log(cy.nodes())
cy.layout({
name:"dagre"
}).run();
cy.elements().qtip({
content: function(){
d = this.data().data;
str = ""
for (var key in d) {
str += "<b>"+key+":</b></br>"
cont = [].concat(d[key]);
for(var i in cont){
str += cont[i] + "</br>"
}
}
return str
},
position: {
my: 'right center',
at: 'left center'
},
style: {
classes: 'qtip-bootstrap',
tip: {
width: 16,
height: 8
}
}
})
});
</script>
</body>
`
func startPipelineVisualization(p *pipeline.Pipeline, port string) error {
cy := &gotoscapejs.Cytoscape{}
for _, stage := range p.Stages {
cy.Add(gotoscapejs.Element{
Group: "nodes",
Data: gotoscapejs.Data{
Id: stage.Name,
Data: map[string]interface{}{
"Image": stage.Image,
"Cmd": stage.Cmd,
"Env": stage.Env,
"Volumes": stage.Volumes,
"Inputs": stage.Inputs,
"Comment": stage.Comment,
},
},
})
for _, input := range stage.Inputs {
cy.Add(gotoscapejs.Element{
Group: "edges",
Data: gotoscapejs.Data{
Id: stage.Name + input,
Source: input,
Target: stage.Name,
},
})
}
}
mux := http.NewServeMux()
mux.HandleFunc("/graph", func(w http.ResponseWriter, req *http.Request) {
cy.Write(w)
})
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte(vis))
})
fmt.Println("View pipeline visualization on http://localhost" + port)
return http.ListenAndServe(port, mux)
}