-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbook_map.html
148 lines (128 loc) · 4.54 KB
/
book_map.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
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<!-- I recommend you host this file on your own, since this will change without warning -->
<script src="http://datamaps.github.io/scripts/datamaps.world.min.js?v=1"></script>
<a href = "index.html" style = "font-size: 200%;">Home</a>
<div id="container1" style="position: relative; width: 80%; height: 600px;"></div>
<br><br><br>
<div id = "my_div" style = "width: 1000px; height: 300px; margin-left:auto; margin-right:auto;">
<table style="width:100%">
<tbody>
<tr>
<td colspan = "30" style = "text-align: center; font-size:40px;">Novels</td>
<td colspan = "60" style = "text-align: center; font-size:40px;">Essays</td>
</tr>
<br>
<br>
<tr>
<td colspan = "25" style = "text-align: center; font-size:20px;">Fantasy</td>
<td colspan = "25" style = "text-align: left; font-size:20px;">Real</td>
</tr>
</tbody>
</table>
</div>
<script>
//basic map config with custom fills, mercator projection
var map = new Datamap({
scope: 'world',
element: document.getElementById('container1'),
projection: 'mercator',
fills: {
defaultFill: '#f0af0a',
lt50: 'rgba(0,244,244,0.9)',
gt50: 'red'
},
data: {
}
})
function parse_data(){
var longitude = new Array();
longitude = make_array();
return longitude;
}
$(document).ready(function make_bubbles() {
longitude = [];
latitude = [];
names = [];
size = [];
var fantasy = 0;
var real = 0;
var nosetting = 0;
d3.json("data/parsed_book_data.json",function(error,data){
if (error) return console.warn(error);
for(var i = 0; i < data.length; i++)
{
if(data[i]["lng"] && data[i]["lat"]) {
longitude[i] = data[i]["lng"];
latitude[i] = data[i]["lat"];
real += 1;
}
else if(data[i]["fiction"] == "1")
{
fantasy += 1;
}
else
{
nosetting+=1;
}
if(data[i]["title"])
{
names[i] = data[i]["title"];
}
if(data[i]["my_rating"])
{
size[i] = data[i]["my_rating"];
}
else
{
size[i] = data[i]["average_rating"];
}
}
bubbles = new Array();
for(var i = 0; i < longitude.length; i++)
{
if(longitude[i])
{
if(latitude[i])
{
bubbles.push({'name' : names[i], 'latitude' : latitude[i],
'longitude' : longitude[i], 'radius': size[i]*2, 'fillKey' : 'gt50'});
}
}
}
var m_div = d3.select("#my_div");
var m_svg = m_div.append("svg")
.attr("height", 1000)
.attr("width", 1000);
var g = m_svg.append("g");
g.append("circle")
.attr("name", "Fictional")
.attr("cx", 200)
.attr("cy", 100)
.attr("r", function(d) { return 2*fantasy; })
.attr("style", "fill: steelblue");
g.append("circle")
.attr("name", "Non-Fictional")
.attr("cx", 500)
.attr("cy", 100)
.attr("r", function(d) { return 2*real; })
.attr("style", "fill: orangered");
g.append("circle")
.attr("name", "No Setting")
.attr("cx", 800)
.attr("cy", 100)
.attr("r", function(d) { return 2*nosetting; })
.attr("style", "fill: green");
map.bubbles(bubbles, {
popupTemplate: function (geo, data) {
return "<div class='hoverinfo'>It is " + data.name + "</div>";
}
});
})
})
</script>
</body>