-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathview.html
More file actions
132 lines (119 loc) · 4.17 KB
/
view.html
File metadata and controls
132 lines (119 loc) · 4.17 KB
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
<!DOCTYPE html>
<html>
<head>
<title>TVplot - {{.Title}}</title>
</head>
<body>
<h3><a href="/">TVplot</a></h3>
<h2>{{.Title}} ({{.Year}})</h2>
<style type="text/css">
body {
font-size: 1.25em;
line-height: 1.4em;
text-align: center;
font-family: Helvetica;
color: #515151;
}
a {
color: #588d69;
text-decoration: none;
}
a:hover {
color: #d43728;
}
.d3-tip {
line-height: 1;
font: 14px sans-serif;
padding: 12px;
background: rgba(0, 0, 0, 0.8);
color: rgb(185, 185, 185);
border-radius: 2px;
}
.d3-tip:after {
box-sizing: border-box;
display: inline;
font-size: 10px;
width: 100%;
line-height: 1;
color: rgba(0, 0, 0, 0.8);
content: "\25BC";
position: absolute;
text-align: center;
}
.d3-tip.n:after {
margin: -1px 0 0 0;
top: 100%;
left: 0;
}
</style>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdn.rawgit.com/VACLab/d3-tip/master/d3-tip.js"></script>
<script>
var data = [
{{range $i, $e := .Episodes}}
{{range $j, $x := $e}}
[{{$x.EpisodeNum}}, {{$x.Rating}}, {{$x.Season}}, {{$x.Formatted}}, {{$x.Title}}],
{{end}}
{{end}}
];
var margin = { top: 30, right: 50, bottom: 40, left: 50 };
var width = window.innerWidth - margin.left - margin.right;
var height = 600 + margin.top + margin.bottom;
var xscale = d3.scaleLinear()
.domain([0,data.length])
.range([0,width]);
var yscale = d3.scaleLinear()
.domain([0, 10])
.range([height,0]);
var xAxis = d3.axisBottom().scale(xscale) ;
var yAxis = d3.axisLeft().scale(yscale).tickSize(-width);
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 + ")");
var cValue = function(d) {return d[2]}, color = d3.scaleOrdinal(d3.schemeCategory10);
var tip = d3.tip()
.attr('class', 'd3-tip')
.offset([-10, 0])
.html(function(d) {
return "<div><span>Rating:</span> <span style='color:white'>" + d[1] + "</span></div>" + "<div><span>Title:</span> <span style='color:white'>" + d[3] + " - " + d[4] + "</span></div>";
})
svg.call(tip);
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.attr("class", "x axis")
.call(xAxis);
svg.append("text")
.attr("transform", "translate(" + (width/2) + " ," + (height + margin.top + 5) + ")")
.style("text-anchor", "middle")
.text("Episode Number");
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left + 5)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("Rating");
svg.append("g")
.attr("transform", "translate(0,0)")
.attr("class", "y axis")
.call(yAxis)
.append("text").attr("transform", "rotate(-90)").text("IMDb Rating");
svg.selectAll("circle")
.data(data)
.enter()
.append("g")
.append("circle")
.attr("x", function(d) { return xscale(d[0]);})
.attr("y", function(d) { return yscale(d[1]);})
.style("fill", function(d) { return color(cValue(d));})
.attr("r", 6)
.attr("cx", function(d) { return xscale(d[0]);})
.attr("cy", function(d) { return yscale(d[1]);})
.on("mouseover", tip.show)
.on("mouseout", tip.hide);
</script>
</body>
</html>