forked from bitlyscience/bitlyscience.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_old.html
142 lines (120 loc) · 3.64 KB
/
index_old.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
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=PT+Sans' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="./../static/js/d3.v2.js"></script>
<link rel="stylesheet" type="text/css" href="/obama_romney/data/colours.css">
<link href="./../static/css/bootstrap.css" rel="stylesheet">
<script>
function draw(data) {
var path = d3.geo.path();
d3.select(".science_graph")
.append("svg")
.selectAll("path")
.data(data.features)
.enter()
.append("path")
.attr("d", path)
.attr("id", function(d) { return d.properties.name })
.style("stroke", "white")
.style("stroke-width", 1)
.on("mouseover", function(d) {
d3.selectAll("path")
.style("opacity", 0.3)
d3.select("#"+d.properties.name)
.style("opacity", 0.5)
.style("stroke", "black")
// d3.selectAll(".graph_title")
// .text(d.properties.name)
})
// .on("click", function(d) {
// window.location="http://bitlyscience.github.com"//d.url
// })
.on("mouseout", function(d) {
d3.select("#"+d.properties.name)
.style("stroke", "white")
d3.selectAll("path")
.style("opacity", 1)
})
}
function title(data) {
key = {}
data.map(function(d) {
key[d.name]=d
})
console.log(key)
d3.selectAll("path")
.on("mouseover", function(d) {
console.log("name", d.properties.name)
d3.select(".graph_title")
.text(key[d.properties.name].title)
})
.on("mouseout", function(d) {
d3.select(".graph_title")
.text("")
})
.on("click", function(d) {
window.location=key[d.properties.name].url
})
}
function fill(data) {
d3.selectAll("path")
.attr("class", function(d) { return "state_" + data[d.properties.name]})
}
function legend(data) {
var margin = 105,
width = 920,
height = 30,
step = 100;
x_extent = d3.extent(data, function(d){ return d.num })
var x_scale = d3.scale.linear()
.range([margin, width-margin])
.domain(x_extent)
d3.select(".graph_legend")
.selectAll("div.legend")
.data(data)
.enter()
.append('div')
.attr("class", "legend")
.style("margin-right","0.8em")
.style("outline","black solid 1px")
.style("color","black")
.style("line-height","1.5em")
.style("text-align", "center")
.style('height', "1.5em")
.style("float", "left")
.style('width', 105)
.text(function(d) {return d.foodtype})
.style("background-color", function(d) {
return "rgb("+d.color+")"
})
}
</script>
<link href="../static/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div id="content">
<script>
d3.json('/obama_romney/data/us-states.json', draw);
d3.json('/obama_romney/data/index.json', fill);
d3.json('/obama_romney/data/title_link.json', title);
d3.json('/obama_romney/data/color_key.json', legend);
</script>
<div class="science_title">
<h1>Happy Independence Day, ZOMBIES!</h1>
</div>
<div class="blerb">
<p>Check out our <a href="http://bitly.com/bundles/annaksmith/i">bundle!</a> </p>
</div>
<div class="science_graph">
</div>
<div class="graph_title">
</div>
<div class="graph_legend">
</div>
<div class="blerb">
<p></p>
<p><a href="http://blog.bitly.com/post/26449494972/happy-independence-day-america">Back to the bitly blog</a> or to a <a href="http://bitlyscience.github.com">list of bitly science work.</a>
</div>
</div>
</body>
</html>