-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex3.html
221 lines (181 loc) · 7.29 KB
/
index3.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
<html>
<head>
<title>Harry Potter Dialogues</title>
<!--Scripts-->
<script src="scripts/d3.v4.js"></script>
<script src="scripts/queue.js"></script>
<script src="https://unpkg.com/d3-sankey@0"></script>
<script src="js/sankey.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<link href="css/main.css" rel="stylesheet">
</head>
<body>
<h1 align=center style="margin-bottom: 0px font: Roboto Condensed, Helvetica, Arial, sans-serif">Harry Potter Series: Who said What?</h1>
<div align="left">
<table align="center" border=1>
<div id="sankey_diagram"></div></table>
</div>
<div id="controls" style="text-align:center;font-size:100%;color:#444444;margin-top: 10px;margin-bottom: 10px;">
<span>
<label style="margin-right: 10px;"><input id="allcharacters" type="radio" name="grouping" value="1" checked>All Characters</label>
<label style="margin-right: 10px;"><input id="harry" type="radio" name="grouping" value="2">Harry Potter</label>
<label style="margin-right: 10px;"><input id="ron" type="radio" name="grouping" value="3" >Ron Weasley</label>
<label style="margin-right: 10px;"><input id="hermoine" type="radio" name="grouping" value="4" >Hermione Granger</label>
</span>
</div>
<script src="js/chord.js"> </script>
<script>
var full_data = [];
var bp;
var g;
var slider_value = 1;
var playing = 0;
var width = 1400;
var height = 650;
var sankey_dimension = {
width: 750,
height: 575
}
var svg = d3.select("#sankey_diagram").append("svg").attr("width", width).attr("height", height);
function isChecked(elementID) {
return d3.select(elementID).property("checked");
}
addFillListener();
//var opt = 1;
var file="sankey_agg.csv";
function addFillListener() {
d3.selectAll('input[name="grouping"]')
.on("change", function() {
if(isChecked("#allcharacters"))
file="sankey_agg.csv";
else if(isChecked("#harry"))
file="harry_colour.csv";
else if(isChecked("#ron"))
file="ron_colour.csv";
else file="hermoine_colour.csv";
full_data = [];
d3.csv(file, function(data) {
data.forEach(function(d) {
full_data.push([d['source'], d['target'], d['value']])
});
svg.selectAll("groups").remove();
svg.selectAll("foreignObject").remove();
svg.selectAll(".edges").remove();
svg.selectAll(".mainBars").remove();
svg.selectAll(".subBars").remove();
svg.selectAll(".chord").remove();
svg.selectAll(".groups").remove();
svg.selectAll(".label").remove();
svg.selectAll(".face").remove();
svg.selectAll(".majorTicks").remove();
svg.selectAll(".minorTicks").remove();
console.log(svg);
draw(full_data);
});
});
}
d3.csv(file, function(data) {
data.forEach(function(d) {
full_data.push([d['source'], d['target'], d['value']])
});
draw(full_data);
});
function draw(data) {
var color = {
//orange
"m1": "#cc7722",
"m2": "#b3672b",
"m3": "#b1560f",
"m4": "#8b4000",
"m5": "#813f0b",
"m6": "#883000",
"m7": "#793802",
"m8": '#613613',
//blue
"m1_harry": "#1388be",
"m2_harry": "#0f52ba",
"m3_harry": "#1034a6",
"m4_harry": "#2832c2",
"m5_harry": "#000080",
"m6_harry": "#111e6c",
"m7_harry": "#1d2951",
"m8_harry": '#003152',
//green
"m1_ron": "#50c878",
"m2_ron": "#5dbb63",
"m3_ron": "#00a86b",
"m4_ron": "#028a0f",
"m5_ron": "#2e8857",
"m6_ron": "#4f7942",
"m7_ron": "#086623",
"m8_ron": '#026623',
//red
"m1_hermoine": "#d21f3c",
"m2_hermoine": "#c25863",
"m3_hermoine": "#b2292c",
"m4_hermoine": "#a24345",
"m5_hermoine": "#921f3c",
"m6_hermoine": "#953835",
"m7_hermoine": "#8c1208",
"m8_hermoine": '#7e191b'
};
svg.append("foreignObject")
.attr("width", 200)
.attr("height", 30)
.attr('x', width / 2 - 100)
.attr('y', 10)
.append("xhtml:body")
.style("font", "14px 'Roboto Condensed', 'Helvetica', 'Arial', sans-serif")
//.html('<h4>Total Deaths - <span id="year-number">2001</span></h4>')
bp = viz.bP()
.data(data)
.min(12)
.pad(1)
.height(sankey_dimension.height)
.width(sankey_dimension.width)
.barSize(35)
.fill(d => color[d.primary]);
g = svg.append("g").attr("transform", "translate(400,50)").call(bp);
g.append("text").attr("x", -70).attr("y", -8).style("text-anchor", "middle").text("Movies").style("font-weight", 'normal').style('fill', '#808080').style("font", "'Roboto Condensed', 'Helvetica', 'Arial', sans-serif");
g.append("text").attr("x", sankey_dimension.width + 78).attr("y", -8).style("text-anchor", "middle").text("Dialogues").style("font-weight", 'normal').style('fill', '#808080').style("font", "'Roboto Condensed', 'Helvetica', 'Arial', sans-serif");
g.selectAll(".mainBars")
.on("mouseover", mouseover);
g.selectAll(".mainBars").append("text").attr("class", "label")
.attr("x", d => (d.part == "primary" ? -60 : 60))
.attr("y", d => +6)
.style('fill', function(d){
return '#6a6a6a'
}) // '#6a6a6a')
.text(function(d) {
if(d.key=="nAnswer") return "'N'Answer";
else if(d.key=="whQuestion") return "'Wh'Question";
else if(d.key=="yAnswer") return "'Y'Answer";
else if(d.key=="ynQuestion") return "'Y/N'Question";
else if(d.key=="m1" || d.key=="m1_harry" || d.key=="m1_ron" || d.key=="m1_hermoine") return "Philosopher's Stone";
else if(d.key=="m2" || d.key=="m2_harry" || d.key=="m2_ron" || d.key=="m2_hermoine") return "Chamber of Secrets";
else if(d.key=="m3" || d.key=="m3_harry" || d.key=="m3_ron" || d.key=="m3_hermoine") return "Prisoner of Azkaban";
else if(d.key=="m4" || d.key=="m4_harry" || d.key=="m4_ron" || d.key=="m4_hermoine") return "Goblet of Fire";
else if(d.key=="m5" || d.key=="m5_harry" || d.key=="m5_ron" || d.key=="m5_hermoine") return "Order of the Phoenix";
else if(d.key=="m6" || d.key=="m6_harry" || d.key=="m6_ron" || d.key=="m6_hermoine") return "Half-Blood Prince";
else if(d.key=="m7" || d.key=="m7_harry" || d.key=="m7_ron" || d.key=="m7_hermoine") return "Deathly Hallows 1";
else if(d.key=="m8" || d.key=="m8_harry" || d.key=="m8_ron" || d.key=="m8_hermoine") return "Deathly Hallows 2";
else if(d.key=="all") return "All Movies";
else return d.key;})
.style("font", "14px 'Roboto Condensed', 'Helvetica', 'Arial', sans-serif")
.style('font-size', '16')
.style('font-weight', 'normal')
.attr("text-anchor", d => (d.part == "primary" ? "end" : "start"));
function mouseover(d) {
g.selectAll(".mainBars").select(".perc")
.text(function(d) {
return parseInt((d.percent) * 100);
});
g.selectAll(".mainBars").select(".val")
.text(function(d) {
return d3.format("100")(d.value)
});
}
}
</script>
</body>
</html>