-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDistanceGraphTotal.html
289 lines (230 loc) · 8.42 KB
/
DistanceGraphTotal.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!DOCTYPE html>
<html>
<head>
<title>DistanceGraph</title>
<meta charset="utf-8">
<link href=css/bootstrap.min.css rel=stylesheet media="screen">
</head>
<!-- We define the css style information for the path. You can also have this information in a .css file -->
<!-- colors can be given as classes red - blue, but also as consecutive hexadecimal (0-f) numbers in the form of RGB (either 3 or 6 digits) so
For example: #00ff00 (green) , #f00 (red), #ff0 (yellow) #fff (white) #ccf (blue less saturated) etc -->
<!-- cursor allows you to define the form of the cursor when you are on top of the object -->
<style>
svg {
font: 10px sans-serif;
}
.background path {
fill: none;
stroke: #fff;
stroke-opacity: .4;
shape-rendering: crispEdges;
}
.foreground path {
fill: none;
stroke: steelblue;
stroke-width:1;
stroke-opacity: .7;
}
.brush .extent {
fill-opacity: .4;
shape-rendering: crispEdges;
}
.axis line,
.axis path {
fill: none;
stroke: #393b79;
shape-rendering: crispEdges;
}
.axis text {
text-shadow: 0 2px 0 #fff;
cursor: move;
}
.outer {
fill:none;
stroke: #000;
}
.legend rect {
fill:white;
stroke:black;
opacity:0.8;
}
.legend-box {
display: inline-block;
min-width: 1em;
min-height: 1em;
}
</style>
<script src="js/d3.min.js"></script>
<script src="js/jquery-1.11.1.min.js"></script>
<body>
<a class="btn btn-default" href="index.html"> Back </a>
<div class="container">
<h1>Distance Graph <small>Agregated Data from all games from dataset</small></h1>
<div class="row">
<div id="svgHere" class="col-lg-10"></div>
<div class="col-lg-2">
<h3><small>Tier Filter</small></h3>
<label><input type="checkbox" name="tiersFilter[]" value="Normal"> Normal</label></br>
<label><input type="checkbox" checked name="tiersFilter[]" value="High"> High</label></br>
<label><input type="checkbox" name="tiersFilter[]" value="VeryHigh"> Very High</label></br>
<label><input type="checkbox" name="tiersFilter[]" value="Pro"> Pro</label></br>
<h3><small>Win/Lose Filter</small></h3>
<label><input type="radio" name="winRadio" value="Win"> Win</label></br>
<label><input type="radio" name="winRadio" value="Lose"> Lose</label></br>
<label><input type="radio" checked name="winRadio" value="WinLose"> Both</label></br>
<h3><small>Legend</small></h3>
<div>
<div><span id="legend-radiant" class="legend-box"></span> Radiant (Won)</div>
<div><span id="legend-dire" class="legend-box"></span> Dire (Lost)</div>
</div>
</div>
</div>
<h1 id="loading">Loading...</h1>
</div>
<script>
var selectedWinLose = 'WinLose';
var checkedFilters = ['High'];
var margin = {top: 20, right: 20, bottom: 20, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// Defines your svg element and also as a "g" (graphic) element that you can translate for your visualization
var svg = d3.select("#svgHere").append("svg")// where are you placing your graphic (body) (div)
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); //
// We draw the outer rectangle based on the outer class
svg.append("rect")
.attr("class", "outer")
.attr("width", width)
.attr("height", height)
var color = d3.scale.category10();
//------------------------------------------------------------//
var dataRaw;
// We read the data
d3.csv("sample-data/master-distance.csv",function(error, data) {
data.forEach(function(d) {
d.match = d.match;
d.team = d.team;
d.tsync = +d.tsync;
d.DD = +d.DD;
d.Tier = d.Tier;
d.WinLose = d.WinLose;
});
dataRaw = data;
graphDraw(data);
});
var graphDraw = function(data){
var teamData = new Object();
var index = 0;
data.forEach(function(d){
/*
if(++index%250 > 0)
return;
*/
teamData[d.team] = teamData[d.team] || [];
teamData[d.team]["M"+d.match] = teamData[d.team]["M"+d.match] || [];
teamData[d.team]["M"+d.match].push(d);
});
vis = svg,
xRange = d3.scale.linear().range([margin.left, width - margin.right]).domain([d3.min(data, function(d) {
return d.tsync;
}), d3.max(data, function(d) {
return d.tsync;
})]),
yRange = d3.scale.linear().range([height - margin.top, margin.bottom]).domain([d3.min(data, function(d) {
return d.DD;
}), d3.max(data, function(d) {
return d.DD;
})]),
xAxis = d3.svg.axis()
.scale(xRange)
.tickSize(5)
.tickSubdivide(true),
yAxis = d3.svg.axis()
.scale(yRange)
.tickSize(5)
.orient('left')
.tickSubdivide(true);
vis.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(0,' + (height - margin.bottom) + ')')
.call(xAxis);
vis.append('g')
.attr('class', 'y axis')
.attr('transform', 'translate(' + (margin.left) + ',0)')
.call(yAxis);
var lineFunc = d3.svg.line()
.x(function(d) {
return (!isNaN(d.tsync))?xRange(d.tsync):0;
})
.y(function(d) {
return (!isNaN(d.DD))?yRange(d.DD):0;
})
.interpolate('linear');
for(key in teamData){
var tsync_agr = [];
for(game in teamData[key]){
var t;
teamData[key][game].forEach(function(player){
t = ''+player.tsync;
tsync_agr[t] = tsync_agr[t] || {tsync:0, DD:0, len:0, dd_sum:0};
tsync_agr[t].tsync = t;
tsync_agr[t].dd_sum += player.DD;
tsync_agr[t].len += 1;
tsync_agr[t].DD = tsync_agr[t].dd_sum / tsync_agr[t].len;
});
}
delete tsync_agr["NaN"];
console.log(tsync_agr);//{tsync: Object.keys(tsync_agr), DD: tsync_agr.map(function(me){return me.dd_avg;})});
vis.append('path')
.attr('class', 'linechart')
.attr('d', lineFunc(tsync_agr))
.attr('stroke',color(key))
.attr('stroke-width', 0.8)
.attr("data-legend", key)
.attr('fill', 'none');
$('#legend-'+key).css('background-color', color(key));
$('#loading').hide();
};
};
var graphReDraw = function(){
//matching rules from:
//var selectedWinLose = 'WinLose' || 'Win' || 'WinLose'
//var checkedFilters = ['Normal', 'High', 'VeryHigh', 'Pro']
//d.Tier = d.Tier;
//d.WinLose = d.WinLose;
//
$('.linechart').remove();
$('.axis').remove();
//$('.legend').remove();
graphDraw(dataRaw.filter(function(item){
var inTierCond = checkedFilters.indexOf(item.Tier) > -1;
var inWinLoseCond;
if(selectedWinLose == 'WinLose'){
inWinLoseCond = true;
} else {
inWinLoseCond = (selectedWinLose == item.WinLose);
}
return inTierCond && inWinLoseCond;
}));
}
//jquery bind buttons
$("input[name='winRadio'").click(function(){
var clicked = ($(this).val());
selectedWinLose = clicked;
graphReDraw();
});
$("input[name='tiersFilter[]'").click(function(){
var clicked = ($(this).val());
var index = checkedFilters.indexOf(clicked);
if(index>-1){
checkedFilters.splice(index,1);
} else {
checkedFilters.push(clicked);
}
graphReDraw();
});
</script>
</body>
</html>