Skip to content

Instantly share code, notes, and snippets.

@ebendennis
Last active February 17, 2017 20:12
Show Gist options
  • Save ebendennis/bfa58a024e5079e0bb5e0bc1ad4877b0 to your computer and use it in GitHub Desktop.
Save ebendennis/bfa58a024e5079e0bb5e0bc1ad4877b0 to your computer and use it in GitHub Desktop.
LFC Seasons by Week - PPG
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v3.min.js"></script>
<style>
body {
margin:0;
position:fixed;
top:0;
right:0;
bottom:0;
left:0;
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: rgba(0,0,0,.25);
}
.tooltip {
position: absolute;
width: 75px;
height: 24px;
padding: 2px;
background: white;
pointer-events: none;
}
</style>
</head>
<body>
<script>
var margin = {top: 20, right: 20, bottom: 30, left: 40},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var color = d3.scale.category10();
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
// Define the div for the tooltip
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("seasonData.csv", function(error, data) {
if (error) throw error;
data.forEach(function(d) {
d.week = +d.week;
d.value = +d.value;
});
x.domain([1,42]);
y.domain([0,3]);
var nestData = d3.nest()
.key(function(d) { return +d.week; })
.rollup(function(values) { return {
first: d3.quantile(values.map(function(d) { return +d.value;}).sort(d3.ascending),.20),
avg: d3.mean(values, function(d) {return +d.value; }),
last: d3.quantile(values.map(function(d) { return +d.value;}).sort(d3.ascending),.80),
avgWeek: d3.mean(values, function(d) {return +d.week; })
};
})
.entries(data);
//Draw line
var subjectPath = d3.svg.line()
.interpolate("monotone")
.x(function(d) {
return x(d.values.avgWeek);
})
.y(function(d) {
return y(d.values.avg / d.values.avgWeek);
})
var area = d3.svg.area()
.interpolate("monotone")
.x(function(d) { return x(d.values.avgWeek); })
.y0(function(d) { return y(d.values.first / d.values.avgWeek); })
.y1(function(d) { return y(d.values.last / d.values.avgWeek); });
svg.append('path')
.style("fill", "#eaeaea")
// Pass the second level of the nested array to subjectPath to generate x/y co-ords
.attr("d", area(nestData));
svg.append('path')
.style("stroke", "#bababa")
.style("fill", "none")
// Pass the second level of the nested array to subjectPath to generate x/y co-ords
.attr("d", subjectPath(nestData));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Week");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Points")
svg.selectAll(".dot")
.data(data)
.enter().append("circle")
.attr("class", "dot")
.attr("r", 3.5)
.attr("cx", function(d) { return x(d.week); })
.attr("cy", function(d) { return y(d.value / d.week); })
.style("fill", function(d) {if (d.season == "16-17") {return "#ac0000";} else {return "rgba(0,0,0,0)";}; })
.on("mouseover", function(d) {
div.transition()
.duration(200)
.style("opacity", .9);
div.html("Week " + d.week + "<br/>" + d.season + ": " + d3.format(",.2f")(d.value / d.week) + " ppg")
.style("left", (d3.event.pageX + 10) + "px")
.style("top", (d3.event.pageY - 10) + "px");
})
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});;
});
</script>
</body>
season week value
92-93 1 0
93-94 1 3
94-95 1 3
95-96 1 3
96-97 1 1
97-98 1 1
98-99 1 3
99-00 1 3
00-01 1 3
01-02 1 3
02-03 1 3
03-04 1 0
04-05 1 1
05-06 1 1
06-07 1 1
07-08 1 3
08-09 1 3
09-10 1 0
10-11 1 1
11-12 1 1
12-13 1 0
13-14 1 3
14-15 1 3
15-16 1 3
16-17 1 3
92-93 2 3
93-94 2 6
94-95 2 6
95-96 2 3
96-97 2 4
97-98 2 1
98-99 2 4
99-00 2 3
00-01 2 3
01-02 2 0
02-03 2 6
03-04 2 1
04-05 2 4
05-06 2 4
06-07 2 4
07-08 2 4
08-09 2 6
09-10 2 3
10-11 2 1
11-12 2 4
12-13 2 1
13-14 2 6
14-15 2 0
15-16 2 6
16-17 2 3
92-93 3 3
93-94 3 9
94-95 3 9
95-96 3 6
96-97 3 5
97-98 3 2
98-99 3 7
99-00 3 3
00-01 3 4
01-02 3 0
02-03 3 7
03-04 3 2
04-05 3 4
05-06 3 5
06-07 3 4
07-08 3 7
08-09 3 7
09-10 3 3
10-11 3 4
11-12 3 7
12-13 3 1
13-14 3 9
14-15 3 6
15-16 3 7
16-17 3 4
92-93 4 4
93-94 4 9
94-95 4 10
95-96 4 9
96-97 4 8
97-98 4 5
98-99 4 10
99-00 4 6
00-01 4 7
01-02 4 6
02-03 4 8
03-04 4 5
04-05 4 7
05-06 4 6
06-07 4 4
07-08 4 10
08-09 4 10
09-10 4 6
10-11 4 5
11-12 4 7
12-13 4 2
13-14 4 10
14-15 4 6
15-16 4 7
16-17 4 7
92-93 5 5
93-94 5 12
94-95 5 10
95-96 5 9
96-97 5 11
97-98 5 8
98-99 5 10
99-00 5 9
00-01 5 10
01-02 5 9
02-03 5 9
03-04 5 8
04-05 5 7
05-06 5 7
06-07 5 7
07-08 5 11
08-09 5 11
09-10 5 9
10-11 5 5
11-12 5 7
12-13 5 2
13-14 5 10
14-15 5 6
15-16 5 7
16-17 5 10
92-93 6 6
93-94 6 12
94-95 6 11
95-96 6 12
96-97 6 14
97-98 6 9
98-99 6 11
99-00 6 9
00-01 6 11
01-02 6 12
02-03 6 12
03-04 6 11
04-05 6 10
05-06 6 7
06-07 6 10
07-08 6 12
08-09 6 14
09-10 6 12
10-11 6 6
11-12 6 10
12-13 6 5
13-14 6 13
14-15 6 7
15-16 6 8
16-17 6 13
92-93 7 9
93-94 7 12
94-95 7 14
95-96 7 15
96-97 7 17
97-98 7 12
98-99 7 11
99-00 7 10
00-01 7 12
01-02 7 13
02-03 7 15
03-04 7 11
04-05 7 10
05-06 7 10
06-07 7 10
07-08 7 15
08-09 7 17
09-10 7 15
10-11 7 6
11-12 7 13
12-13 7 6
13-14 7 16
14-15 7 10
15-16 7 11
16-17 7 16
92-93 8 9
93-94 8 12
94-95 8 17
95-96 8 16
96-97 8 20
97-98 8 12
98-99 8 12
99-00 8 10
00-01 8 12
01-02 8 16
02-03 8 18
03-04 8 11
04-05 8 13
05-06 8 10
06-07 8 11
07-08 8 16
08-09 8 20
09-10 8 15
10-11 8 6
11-12 8 14
12-13 8 9
13-14 8 17
14-15 8 13
15-16 8 12
16-17 8 17
92-93 9 9
93-94 9 12
94-95 9 17
95-96 9 17
96-97 9 20
97-98 9 15
98-99 9 13
99-00 9 11
00-01 9 15
01-02 9 19
02-03 9 21
03-04 9 11
04-05 9 16
05-06 9 13
06-07 9 11
07-08 9 19
08-09 9 23
09-10 9 15
10-11 9 9
11-12 9 15
12-13 9 10
13-14 9 20
14-15 9 14
15-16 9 13
16-17 9 20
92-93 10 9
93-94 10 13
94-95 10 20
95-96 10 20
96-97 10 23
97-98 10 15
98-99 10 16
99-00 10 14
00-01 10 18
01-02 10 22
02-03 10 24
03-04 10 14
04-05 10 17
05-06 10 16
06-07 10 14
07-08 10 20
08-09 10 26
09-10 10 18
10-11 10 12
11-12 10 18
12-13 10 11
13-14 10 20
14-15 10 14
15-16 10 14
16-17 10 23
92-93 11 12
93-94 11 16
94-95 11 23
95-96 11 23
96-97 11 23
97-98 11 18
98-99 11 16
99-00 11 15
00-01 11 21
01-02 11 23
02-03 11 27
03-04 11 17
04-05 11 17
05-06 11 19
06-07 11 17
07-08 11 21
08-09 11 26
09-10 11 18
10-11 11 15
11-12 11 19
12-13 11 12
13-14 11 23
14-15 11 14
15-16 11 17
16-17 11 26
92-93 12 13
93-94 12 17
94-95 12 23
95-96 12 23
96-97 12 26
97-98 12 19
98-99 12 16
99-00 12 18
00-01 12 21
01-02 12 26
02-03 12 30
03-04 12 17
04-05 12 20
05-06 12 22
06-07 12 17
07-08 12 24
08-09 12 29
09-10 12 19
10-11 12 16
11-12 12 22
12-13 12 15
13-14 12 24
14-15 12 14
15-16 12 17
16-17 12 27
92-93 13 16
93-94 13 20
94-95 13 26
95-96 13 23
96-97 13 27
97-98 13 22
98-99 13 16
99-00 13 21
00-01 13 24
01-02 13 29
02-03 13 30
03-04 13 18
04-05 13 20
05-06 13 25
06-07 13 18
07-08 13 27
08-09 13 32
09-10 13 20
10-11 13 16
11-12 13 23
12-13 13 16
13-14 13 24
14-15 13 17
15-16 13 20
16-17 13 30
92-93 14 16
93-94 14 23
94-95 14 29
95-96 14 24
96-97 14 28
97-98 14 22
98-99 14 19
99-00 14 24
00-01 14 24
01-02 14 32
02-03 14 31
03-04 14 21
04-05 14 23
05-06 14 28
06-07 14 21
07-08 14 30
08-09 14 33
09-10 14 23
10-11 14 19
11-12 14 23
12-13 14 16
13-14 14 27
14-15 14 20
15-16 14 23
16-17 14 30
92-93 15 19
93-94 15 23
94-95 15 29
95-96 15 24
96-97 15 31
97-98 15 25
98-99 15 22
99-00 15 27
00-01 15 24
01-02 15 33
02-03 15 31
03-04 15 22
04-05 15 24
05-06 15 31
06-07 15 22
07-08 15 30
08-09 15 34
09-10 15 24
10-11 15 19
11-12 15 26
12-13 15 19
13-14 15 30
14-15 15 21
15-16 15 23
16-17 15 31
92-93 16 22
93-94 16 26
94-95 16 30
95-96 16 25
96-97 16 31
97-98 16 25
98-99 16 22
99-00 16 27
00-01 16 27
01-02 16 33
02-03 16 31
03-04 16 22
04-05 16 24
05-06 16 34
06-07 16 25
07-08 16 30
08-09 16 37
09-10 16 24
10-11 16 22
11-12 16 29
12-13 16 22
13-14 16 33
14-15 16 21
15-16 16 24
16-17 16 34
92-93 17 25
93-94 17 26
94-95 17 31
95-96 17 28
96-97 17 34
97-98 17 28
98-99 17 22
99-00 17 30
00-01 17 27
01-02 17 33
02-03 17 31
03-04 17 25
04-05 17 25
05-06 17 37
06-07 17 28
07-08 17 33
08-09 17 38
09-10 17 27
10-11 17 22
11-12 17 30
12-13 17 22
13-14 17 36
14-15 17 22
15-16 17 24
16-17 17 37
92-93 18 25
93-94 18 29
94-95 18 32
95-96 18 31
96-97 18 37
97-98 18 31
98-99 18 25
99-00 18 33
00-01 18 30
01-02 18 36
02-03 18 31
03-04 18 26
04-05 18 28
05-06 18 40
06-07 18 31
07-08 18 36
08-09 18 39
09-10 18 27
10-11 18 22
11-12 18 31
12-13 18 25
13-14 18 36
14-15 18 25
15-16 18 27
16-17 18 40
92-93 19 28
93-94 19 30
94-95 19 33
95-96 19 34
96-97 19 38
97-98 19 34
98-99 19 28
99-00 19 34
00-01 19 33
01-02 19 37
02-03 19 32
03-04 19 29
04-05 19 31
05-06 19 41
06-07 19 34
07-08 19 37
08-09 19 42
09-10 19 30
10-11 19 25
11-12 19 34
12-13 19 25
13-14 19 36
14-15 19 28
15-16 19 30
16-17 19 43
92-93 20 28
93-94 20 31
94-95 20 36
95-96 20 35
96-97 20 39
97-98 20 37
98-99 20 31
99-00 20 37
00-01 20 33
01-02 20 38
02-03 20 33
03-04 20 32
04-05 20 34
05-06 20 44
06-07 20 34
07-08 20 38
08-09 20 45
09-10 20 33
10-11 20 25
11-12 20 34
12-13 20 28
13-14 20 39
14-15 20 29
15-16 20 30
16-17 20 44
92-93 21 29
93-94 21 32
94-95 21 39
95-96 21 38
96-97 21 42
97-98 21 40
98-99 21 32
99-00 21 37
00-01 21 36
01-02 21 38
02-03 21 34
03-04 21 32
04-05 21 34
05-06 21 44
06-07 21 37
07-08 21 39
08-09 21 46
09-10 21 34
10-11 21 25
11-12 21 35
12-13 21 31
13-14 21 42
14-15 21 32
15-16 21 31
16-17 21 45
92-93 22 29
93-94 22 33
94-95 22 42
95-96 22 39
96-97 22 42
97-98 22 41
98-99 22 35
99-00 22 40
00-01 22 39
01-02 22 39
02-03 22 34
03-04 22 33
04-05 22 37
05-06 22 45
06-07 22 40
07-08 22 40
08-09 22 47
09-10 22 37
10-11 22 26
11-12 22 35
12-13 22 31
13-14 22 43
14-15 22 35
15-16 22 31
16-17 22 45
92-93 23 29
93-94 23 36
94-95 23 45
95-96 23 42
96-97 23 43
97-98 23 44
98-99 23 35
99-00 23 41
00-01 23 40
01-02 23 40
02-03 23 35
03-04 23 34
04-05 23 37
05-06 23 45
06-07 23 43
07-08 23 40
08-09 23 48
09-10 23 38
10-11 23 29
11-12 23 38
12-13 23 34
13-14 23 46
14-15 23 38
15-16 23 34
16-17 23 46
92-93 24 32
93-94 24 37
94-95 24 45
95-96 24 45
96-97 24 46
97-98 24 45
98-99 24 38
99-00 24 44
00-01 24 41
01-02 24 43
02-03 24 38
03-04 24 35
04-05 24 37
05-06 24 45
06-07 24 46
07-08 24 43
08-09 24 51
09-10 24 41
10-11 24 32
11-12 24 39
12-13 24 35
13-14 24 47
14-15 24 39
15-16 24 34
16-17 24 46
92-93 25 33
93-94 25 40
94-95 25 46
95-96 25 46
96-97 25 49
97-98 25 45
98-99 25 38
99-00 25 47
00-01 25 44
01-02 25 46
02-03 25 39
03-04 25 38
04-05 25 40
05-06 25 48
06-07 25 49
07-08 25 44
08-09 25 54
09-10 25 44
10-11 25 35
11-12 25 39
12-13 25 36
13-14 25 50
14-15 25 42
15-16 25 35
16-17 25 49
92-93 26 34
93-94 26 43
94-95 26 47
95-96 26 49
96-97 26 52
97-98 26 46
98-99 26 39
99-00 26 48
00-01 26 45
01-02 26 49
02-03 26 42
03-04 26 39
04-05 26 43
05-06 26 51
06-07 26 50
07-08 26 47
08-09 26 55
09-10 26 44
10-11 26 38
11-12 26 39
12-13 26 36
13-14 26 53
14-15 26 45
15-16 26 38
92-93 27 34
93-94 27 44
94-95 27 48
95-96 27 52
96-97 27 53
97-98 27 47
98-99 27 39
99-00 27 49
00-01 27 45
01-02 27 52
02-03 27 43
03-04 27 39
04-05 27 43
05-06 27 54
06-07 27 50
07-08 27 50
08-09 27 55
09-10 27 45
10-11 27 39
11-12 27 39
12-13 27 39
13-14 27 56
14-15 27 48
15-16 27 41
92-93 28 35
93-94 28 44
94-95 28 51
95-96 28 55
96-97 28 53
97-98 28 47
98-99 28 39
99-00 28 50
00-01 28 46
01-02 28 53
02-03 28 43
03-04 28 42
04-05 28 43
05-06 28 55
06-07 28 53
07-08 28 53
08-09 28 58
09-10 28 48
10-11 28 39
11-12 28 42
12-13 28 42
13-14 28 59
14-15 28 51
15-16 28 44
92-93 29 36
93-94 29 44
94-95 29 54
95-96 29 56
96-97 29 56
97-98 29 50
98-99 29 42
99-00 29 53
00-01 29 49
01-02 29 56
02-03 29 46
03-04 29 45
04-05 29 44
05-06 29 55
06-07 29 53
07-08 29 56
08-09 29 61
09-10 29 48
10-11 29 42
11-12 29 42
12-13 29 45
13-14 29 62
14-15 29 54
15-16 29 44
92-93 30 36
93-94 30 47
94-95 30 54
95-96 30 59
96-97 30 57
97-98 30 51
98-99 30 43
99-00 30 56
00-01 30 50
01-02 30 59
02-03 30 49
03-04 30 46
04-05 30 47
05-06 30 58
06-07 30 54
07-08 30 59
08-09 30 64
09-10 30 51
10-11 30 45
11-12 30 42
12-13 30 45
13-14 30 65
14-15 30 54
15-16 30 45
92-93 31 39
93-94 31 47
94-95 31 57
95-96 31 59
96-97 31 60
97-98 31 54
98-99 31 44
99-00 31 59
00-01 31 50
01-02 31 62
02-03 31 52
03-04 31 49
04-05 31 50
05-06 31 61
06-07 31 57
07-08 31 59
08-09 31 67
09-10 31 51
10-11 31 45
11-12 31 42
12-13 31 48
13-14 31 68
14-15 31 54
15-16 31 48
92-93 32 42
93-94 32 50
94-95 32 58
95-96 32 62
96-97 32 60
97-98 32 55
98-99 32 44
99-00 32 62
00-01 32 53
01-02 32 65
02-03 32 52
03-04 32 49
04-05 32 50
05-06 32 64
06-07 32 60
07-08 32 62
08-09 32 70
09-10 32 54
10-11 32 48
11-12 32 43
12-13 32 49
13-14 32 71
14-15 32 57
15-16 32 51
92-93 33 45
93-94 33 53
94-95 33 61
95-96 33 62
96-97 33 63
97-98 33 58
98-99 33 44
99-00 33 65
00-01 33 56
01-02 33 68
02-03 33 55
03-04 33 49
04-05 33 51
05-06 33 67
06-07 33 61
07-08 33 63
08-09 33 71
09-10 33 55
10-11 33 49
11-12 33 46
12-13 33 50
13-14 33 74
14-15 33 58
15-16 33 54
92-93 34 46
93-94 34 53
94-95 34 61
95-96 34 65
96-97 34 64
97-98 34 59
98-99 34 47
99-00 34 66
00-01 34 59
01-02 34 71
02-03 34 58
03-04 34 50
04-05 34 54
05-06 34 70
06-07 34 64
07-08 34 66
08-09 34 74
09-10 34 56
10-11 34 52
11-12 34 46
12-13 34 51
13-14 34 77
14-15 34 58
15-16 34 55
92-93 35 46
93-94 35 53
94-95 35 64
95-96 35 66
96-97 35 64
97-98 35 59
98-99 35 50
99-00 35 66
00-01 35 62
01-02 35 74
02-03 35 61
03-04 35 53
04-05 35 54
05-06 35 73
06-07 35 67
07-08 35 69
08-09 35 77
09-10 35 59
10-11 35 55
11-12 35 49
12-13 35 54
13-14 35 80
14-15 35 61
15-16 35 55
92-93 36 49
93-94 36 53
94-95 36 64
95-96 36 69
96-97 36 67
97-98 36 62
98-99 36 51
99-00 36 66
00-01 36 65
01-02 36 77
02-03 36 64
03-04 36 56
04-05 36 55
05-06 36 76
06-07 36 67
07-08 36 70
08-09 36 80
09-10 36 62
10-11 36 58
11-12 36 49
12-13 36 55
13-14 36 80
14-15 36 62
15-16 36 58
92-93 37 50
93-94 37 54
94-95 37 67
95-96 37 70
96-97 37 67
97-98 37 65
98-99 37 51
99-00 37 67
00-01 37 66
01-02 37 77
02-03 37 64
03-04 37 59
04-05 37 55
05-06 37 79
06-07 37 67
07-08 37 73
08-09 37 83
09-10 37 62
10-11 37 58
11-12 37 52
12-13 37 58
13-14 37 81
14-15 37 62
15-16 37 59
92-93 38 53
93-94 38 57
94-95 38 70
95-96 38 71
96-97 38 68
97-98 38 65
98-99 38 54
99-00 38 67
00-01 38 69
01-02 38 80
02-03 38 64
03-04 38 60
04-05 38 58
05-06 38 82
06-07 38 68
07-08 38 76
08-09 38 86
09-10 38 63
10-11 38 58
11-12 38 52
12-13 38 61
13-14 38 84
14-15 38 62
15-16 38 60
92-93 39 56
93-94 39 57
94-95 39 71
92-93 40 56
93-94 40 60
94-95 40 71
92-93 41 56
93-94 41 60
94-95 41 71
92-93 42 59
93-94 42 60
94-95 42 74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment