-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
200 lines (173 loc) · 6.61 KB
/
index.html
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<meta charset="utf-8">
<title>Gode</title>
</head>
<body>
<script type="text/javascript" src="media/jquery-1.8.3.min.js"></script>
<script src="media/d3.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<link rel="stylesheet" type="text/css" href="media/gode.css">
<script>
var socket = io.connect('http://localhost:3000');
var domJustLoaded = true;
var svgcanvas = d3.select("body").append("svg:svg").attr("width", 1000).attr("height", 1000).attr("x","100");
function renderTooltip(d){
var text = "Comment: " + d.comment ;
tooltip.text(text).
style("visibility", "visible");
}
var tooltip = d3.select("body")
.append("div")
.style("position", "absolute")
.style("z-index", "10")
.style("visibility", "hidden")
.attr("class","tip");
socket.on('current-branch', function (input) {
svgcanvas.append("rect")
.attr("x",350)
.attr("y",130)
.attr("width", 100)
.attr("height",30)
.style("fill","steelblue")
.style("opacity",0.5)
.on('mouseover', function() {
d3.select(this)
.style('opacity', 1);
})
.on('mouseout', function() {
d3.select(this)
.style('opacity', 0.5)
});
// Branch name
// Text
svgcanvas.append("svg:text")
.attr("x", 400)
.attr("y", 145)
.attr("text-anchor","middle")
.attr("dy",".35em")
.text( input );
// Triangle
svgcanvas.append('path')
.attr('d', function(d) {
var x = 350, y = 130;
return 'M ' + x +' '+ y + ' l -20 15 l 20 15 z';
}).style("fill","steelblue").style("opacity",0.5);
});
socket.on('full-git-log', function (full_git_log) {
var dataset = full_git_log;
var node_radius = 30;
var group = svgcanvas.append("svg:g");
// Binding & Adding the circles
group.selectAll("circle").data(dataset)
.enter().append("circle")
.attr("r", node_radius)
.attr("cy", function(d){ return (dataset.length-d.index) * 100 + 150;})
.attr("cx", 300).style("fill", "steelblue")
// Tooltip events
.on("click", function(d){ renderTooltip(d); })
.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px")})
.on("mouseout", function(){return tooltip.style("visibility", "hidden");});
// Binding & Adding the rectangles (lines)
group.selectAll("rect").data(dataset)
.enter().append("rect")
.attr("x",300)
.attr("y",function(d){ return (dataset.length-d.index) * 100 + 185;})
.attr("width", 3)
.attr("height",30);
});
socket.on('update-git-log', function (dataset) {
var svg = d3.select("body svg") ;
// Starting point for the canvas group. Every time that a commit is added/removed this canvas will be moved down/up
var yValue = 0;
// get the last y position of the group after last transform and increase it
if (svgcanvas.select("g").attr("transform")!=null){
//todo: find a clean way to get the past transform data, without using the split method
yValue = parseInt(svgcanvas.select("g").attr("transform").split(",")[1].split(")")[0]) + 100 ;
}
// Did we remove data from the dataset?
var toRemove = false;
if (svgcanvas.select("g").selectAll("circle")[0].length > dataset.length){
toRemove = true;
}
// Update the dataset for both circles and rectangles
var circle = svgcanvas.select("g").selectAll("circle").data(dataset);
var rect = svgcanvas.select("g").selectAll("rect").data(dataset);
if (toRemove){
// Fade out circle & remove it
circle.exit()
.transition()
.duration(1000) // this is 1s
.delay(500) // this is 0.1s
.style("opacity","0").each("end", function() { circle.exit().remove(); });
// Fade out rectangle & remove it
rect.exit()
.transition()
.duration(1000) // this is 1s
.delay(500) // this is 0.1s
.style("opacity","0").each("end", function() { rect.exit().remove(); });
// Move the canvas to the original position calculating the correct offset
var yTransform = 0;
if (yValue > 0){
yTransform = yValue - 200;
} else if (yValue == 0 && domJustLoaded) {
yTransform = yValue - 100;
}
// Move up the group
svgcanvas.select("g").transition()
.duration(1000) // this is 1s
.delay(500) // this is 0.1s
.attr("transform", "translate(0,"+yTransform+")");
} else {
// Move the canvas to the new position calculating the correct offset
var yTransform = 0;
if (yValue == 0 && domJustLoaded){
yTransform = 100;
} else{
yTransform = yValue;
}
// Move down all the group
svgcanvas.select("g").transition()
.duration(1000) // this is 1s
.delay(500) // this is 0.1s
.attr("transform", "translate(0,"+ yTransform +")");
// Add new circle
circle.enter()
.append("circle")
.transition()
.duration(1000) // this is 1s
.delay(500) // this is 0.1s
.attr("cy", 150 - yTransform)
.attr("cx", 300)
.attr("r", 30)
.style("fill", "steelblue")
// .style("fill", "green")
// .each("end", function() {
// d3.select(this)
// .transition()
// .duration(1000) // this is 1s
// .delay(500) // this is 0.1s
// .style("fill","steelblue"); })
.each("end", function() {
// Tooltip events
d3.select(this)
.on("click", function(d){ renderTooltip(d) })
.on("mousemove", function(){return tooltip.style("top", (event.pageY-10)+"px").style("left",(event.pageX+10)+"px")})
.on("mouseout", function(){return tooltip.style("visibility", "hidden");})});
// Add new rectangle
rect.enter()
.append("rect")
.transition()
.duration(1000) // this is 1s
.delay(500) // this is 0.1s
.attr("x",300)
.attr("y",function(d){ return (dataset.length-d.index) * 100 + 270 - yTransform - 85;})
.attr("width", 3)
.attr("height",30);
}
domJustLoaded = false;
});
</script>
</body>
</html>