forked from julietKiloRomeo/visual-elephant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
363 lines (288 loc) · 8.18 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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body { font: 12px Arial;}
path {
stroke-width: 6;
fill: none;
}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
</style>
<body>
<script type="text/javascript" src="d3/d3.v3.min.js"></script>
<script>
var width = 1200
var height = 800
var sz = 30
var rects1, csvdata, ref_line, line;
var body = d3.select("body");
var svg_canvas = body
.append("svg")
.attr("y", 0)
.attr("x", 0)
.attr("width", width)
.attr("height", height);
var matrix = svg_canvas.append("g")
.attr("transform", "translate("+ sz*3 +", 0)")
var team_labels = svg_canvas.append("g")
.attr("transform", "translate("+ sz*3 +", 0)")
var round_indctr = svg_canvas.append("g")
.attr("transform", "translate("+ sz*3 +", 0)")
var bar_chart = svg_canvas.append("g")
.attr("transform", "translate("+ sz*25 +", 0)")
var bar_chart_ref = svg_canvas.append("g")
.attr("transform", "translate("+ sz*25 +", 0)")
var graph_ref = svg_canvas.append("g")
.attr("transform", "translate("+ sz*3 +","+ sz*15 +")")
var graph = svg_canvas.append("g")
.attr("transform", "translate("+ sz*3 +","+ sz*15 +")")
var pick_info = svg_canvas.append("g")
.attr("transform", "translate("+ sz*25 +","+ sz*15 +")")
pick_info.selectAll("rect")
.data([1])
.enter()
.append("rect")
.attr("y", 0)
.attr("x", 0)
.attr("fill", "white")
.attr("stroke", "black")
.attr("stroke-width", 2)
.attr("width", 10*sz)
.attr("height", 3*sz);
var dummy = [0,0,0]
var pick_text = pick_info.selectAll("text")
.data(dummy)
.enter()
.append("text")
.attr("y", function(d,i){return (i+1)*sz ;})
.attr("x", 1*sz)
.attr("font-size", 20)
.attr("font-family", "sans")
.attr("font-weight", "bold")
.text("");
var dummy = [0]
var pick_marker = graph.selectAll("circle")
.data(dummy)
.enter()
.append("circle")
.attr("fill", "black")
.attr("stroke", "gray")
.attr("stroke-width", 2)
.attr("r", 10)
.attr("cy", 100)
.attr("cx", 100000);
//Create the Scale we will use for the Axis
var x_axisScale = d3.scale.linear()
.domain([1, 16])
.range([0, 15*sz]);
var c_axisScale = d3.scale.linear()
.domain([0, 300])
.range([0, 300]);
var y_axisScale = d3.scale.linear()
.domain([0, 300])
.range([0, -300]);
//Create the Axis
var xAxis = d3.svg.axis()
.orient("bottom")
.scale(x_axisScale);
var yAxis = d3.svg.axis()
.orient("left")
.scale(y_axisScale);
var cAxis = d3.svg.axis()
.orient("bottom")
.scale(c_axisScale);
//Create an SVG group Element for the Axis elements and call the xAxis function
var xAxisGroup = graph.append("g")
.attr("class", "axis")
.attr("transform", "translate("+ sz*4.5 +","+ height/3 +")")
.call(xAxis);
var xAxisGroup_chart = bar_chart.append("g")
.attr("class", "axis")
.attr("transform", "translate("+ sz*0 +","+ sz*12 +")")
.call(cAxis);
var yAxisGroup = graph.append("g")
.attr("class", "axis")
.attr("transform", "translate("+ sz*4.5 +","+ height/3 +")")
.call(yAxis);
var c=d3.rgb("teal").brighter(10)
var color = d3.scale.linear()
.domain([-100, 0, 100])
.range(["tomato", "white", "deepskyblue"]);
var legend = svg_canvas.append("g")
.attr("class", "legend")
.attr("x", width - 200)
.attr("y", height - 300)
.attr("height", 100)
.attr("width", 100);
// -----------------------------------------------------------
// create a line function that can convert data[] into x and y points
var line_data = d3.svg.line()
// assign the X function to plot our line as we wish
.x(function(d,i) {
// return the X coordinate where we want to plot this datapoint
return i*sz + 4.5*sz;
})
.y(function(d) {
// return the Y coordinate where we want to plot this datapoint
return height/3 - d ; // use the 1st index of data (for example, get 20 from [20,13])
})
// -----------------------------------------------------------
function update_plots(org_d){
var round_scores = [];
var team_picks = [];
for (var i=0;i<csvdata.length;i++)
{
if(csvdata[i].pick == org_d.pick){
round_scores.push( {'score':csvdata[i].score, 'score_diff':csvdata[i].score_diff});
}
if(csvdata[i].ID == org_d.ID){
team_picks.push(csvdata[i].score);
}
}
rects1.data(round_scores)
.attr("fill", function(d,i) {return color(d.score_diff) })
.attr("width", function(d,i){return d.score} );
ref_line.attr("d", line_data(team_picks));
txt_dat = ["Player: "+org_d.name, "Value : "+String(org_d.score)]
pick_text.data(txt_dat)
.text(function(d,i){return d} );
console.log(org_d)
pick_marker.data([org_d])
.attr("cx", function(d,i){return parseFloat(d.pick)*sz + 4.5*sz;})
.attr("cy", function(d,i){return height/3 - parseFloat(d.score);})
};
// -----------------------------------------------------------
function update_ref_plots(org_d){
var round_scores = [];
var team_picks = [];
for (var i=0;i<csvdata.length;i++)
{
if(csvdata[i].pick == org_d.pick){
round_scores.push( {'score':csvdata[i].score, 'score_diff':csvdata[i].score_diff});
}
if(csvdata[i].ID == org_d.ID){
team_picks.push(csvdata[i].score);
}
}
rects_ref.data(round_scores)
.attr("x", function(d,i){return d.score} );
line.attr("d", line_data(team_picks));
};
// -----------------------------------------------------------
d3.csv("data/draft_2012_csv_list.csv", function(error, csv_data) {
csvdata = csv_data;
matrix.selectAll("rect")
.data(csv_data)
.enter()
.append("rect")
.attr("x", function(d, i) {
return d.pick*sz + 4*sz;
})
.attr("y", function(d,i){
return d.ID*sz + 2*sz;
})
.attr("width", sz)
.attr("height", sz)
.attr("stroke", "black")
.attr("stroke-width", 4)
.attr("fill", function(d,i) {return color(d.score_diff) })
.on("mouseover", function(d,i){
d3.select(this)
.attr("fill", "teal"),
update_plots(d);
})
.on("mousedown", function(d,i){
update_ref_plots(d);
})
.on("mouseout", function(){
d3.select(this)
.attr("fill", function(d,i) {return color(d.score_diff) });
});
var selected_data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
line = graph.selectAll("path")
.data(selected_data)
.enter()
.append("path")
.attr("data-legend", "team1")
.attr("stroke", "black")
.attr("stroke-opacity", 0.5)
.attr("d", line_data(selected_data));
ref_line = graph_ref.selectAll("path")
.data(selected_data)
.enter()
.append("path")
.attr("stroke", "green")
.attr("data-legend", "team2")
.attr("d", line_data(selected_data));
selected_data = [1,2,3,4,5,6,7,8,9,9]
rects1 = bar_chart.selectAll("rect")
.data(selected_data)
.enter()
.append("rect")
.attr("y", function(d, i) {
return i*sz + 2*sz + 1;
})
.attr("x", function(d,i){
return 0;
})
.attr("height", sz-2)
.attr("width", function(d,i){return d} )
.attr("fill", "gray");
rects_ref = bar_chart_ref.selectAll("rect")
.data(selected_data)
.enter()
.append("rect")
.attr("y", function(d, i) {
return i*sz + 2*sz + 1;
})
.attr("x", function(d,i){
return 0;
})
.attr("height", sz-2)
.attr("width", 2 )
.attr("fill", "black");
var team_names = [];
for (var i=0;i<11;i++)
{
team_names.push(csvdata[i].team);
}
texts = team_labels.selectAll("text")
.data(team_names)
.enter()
.append("text")
.attr("y", function(d, i) {
return i*sz + 2.6*sz ;
})
.attr("x", function(d,i){
return 3.5*sz;
})
.attr("text-anchor", "end")
.attr("font-size", 20)
.attr("font-family", "sans")
.attr("font-weight", "bold")
.text(function(d,i){return d;});
var rds = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
round_indctr.selectAll("text")
.data(rds)
.enter()
.append("text")
.attr("y", function(d, i) {
return 1.5*sz ;
})
.attr("x", function(d,i){
return i*sz + 4.5*sz;
})
.attr("text-anchor", "middle")
.attr("font-size", 20)
.attr("font-family", "sans")
.attr("font-weight", "bold")
.text(function(d,i){return d;});
});
</script>
</body>