-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·279 lines (242 loc) · 8.88 KB
/
index.html
File metadata and controls
executable file
·279 lines (242 loc) · 8.88 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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<html>
<head>
<title>Pet Detective</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
var transitioned = 0;
$(document).ready(function(){
$("#night").click(function(){
if (!transitioned) {
$("#night").css("transition", "0.7s");
$("#day").css("transition", "0.7s");
$("#night").css("width", "98%");
$("#night").css("background", "transparent");
$("#night").css("z-index", "-1");
$("#day").css("z-index", "-1");
$("#day, .gap60").css("background", "transparent");
$("#day, .gap60").hover(function(){
$(this).css("cursor", "pointer");
});
$("#night").css("cursor", "auto");
$("#night").hover(function(){
$(this).css("cursor", "auto");
});
$("#arrow1").css("transition", "0.7s");
$("#arrow1").css("background-color", "#e7e7e2");
$("#arrow1").css("margin-left", "-35px");
$(".title").css("opacity", 0);
$("#night .title").css("opacity", 1);
$("#night .title").css("color", "#222");
transitioned = 1;
};
});
});
$(document).ready(function(){
$("#day, .gap60").click(function(){
if (transitioned) {
$("#day").css("transition", "0.7s");
$("#night").css("transition", "0.7s");
$("#night").css("width", "40%");
$("#night").css("background", "#222");
$("#night").css("cursor", "pointer");
$("#night").css("z-index", "");
$("#day").css("z-index", "");
$("#day").css("background", "#e7e7e2");
$("#night").hover(function(){
$(this).css("cursor", "pointer");
});
$("#day, .gap60").css("cursor", "auto");
$("#day, .gap60").hover(function(){
$(this).css("cursor", "auto");
});
$("#arrow1").css("transition", "0.7s");
$("#arrow1").css("background-color", "#222");
$("#arrow1").css("margin-left", "0px");
$(".title").css("opacity", 1);
$("#night .title").css("color", "#e7e7e2");
transitioned = 0;
};
});
});
$(document).ready(function(){
$(".popup").click(function(){
$(".popup").css("margin-left", "-100%");
});
});
// var x = 0
// $(document).ready(function(){
// setTimeout(function(){ $("#count").attr("content", x); x += 1; }, 1000);
// });
</script>
</head>
<body>
<div class="gap60"></div>
<div class="popup">
<div class="imgContainer"><img id="img1" src=""><img id="img2" src=""></div>
<!-- <div class="imgContainer"><img id="img2" src=""></div> -->
</div>
<div id="day" class="panel">
<div class="container">
<div class="title" id="text">Pet</div>
<div class="title" id="text2">Detective</div>
<img id="logo" src="./img/logo.png">
</div>
</div>
<div id="night" class="panel">
<div class="title">Pets Rescued</div>
<div class="separator"></div>
<div class="title" id="count">94224</div>
<div class="arrow" id="arrow"></div>
<div class="arrow" id="arrow1"></div>
<div class="container" id="map_container">
<script src="https://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript" id="jscr">
/* This visualization was made possible by modifying code provided by:
Scott Murray, Choropleth example from "Interactive Data Visualization for the Web"
https://github.com/alignedleft/d3-book/blob/master/chapter_12/05_choropleth.html
Malcolm Maclean, tooltips example tutorial
http://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html
Mike Bostock, Pie Chart Legend
http://bl.ocks.org/mbostock/3888852 */
//Width and height of map
var width = 1536;
var height = 800;
// D3 Projection
var projection = d3.geo.albersUsa()
.translate([width/2, height/2]) // translate to center of screen
.scale([1200]); // scale things down so see entire US
// Define path generator
var path = d3.geo.path() // path generator that will convert GeoJSON to SVG paths
.projection(projection); // tell path generator to use albersUsa projection
// Define linear scale for output
var color = d3.scale.linear()
.range(["rgb(69,173,168)", "rgb(69,173,168)"]);
// "rgb(213,222,217)","rgb(84,36,55)","rgb(217,91,67)"
// var legendText = ["Cities Lived", "States Lived", "States Visited", "Nada"];
//Create SVG element and append map to the SVG
var svg = d3.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
// Append Div for tooltip to SVG
var div = d3.select("body")
.append("div")
.attr("class", "tooltip")
.style("opacity", 0);
// Load in my states data!
d3.csv("statesCount.csv", function(data) {
color.domain([0,1,2,3]); // setting the range of the input data
// Load GeoJSON data and merge with states data
d3.json("us-states.json", function(json) {
// Loop through each state data value in the .csv file
for (var i = 0; i < data.length; i++) {
// Grab State Name
var dataState = data[i].state;
// Grab data value
var dataValue = data[i].lostCount;
// Find the corresponding state inside the GeoJSON
for (var j = 0; j < json.features.length; j++) {
var jsonState = json.features[j].properties.name;
if (dataState == jsonState) {
// Copy the data value into the JSON
json.features[j].properties.lostCount = dataValue;
// Stop looking through the JSON
break;
}
}
}
// Bind the data to the SVG and create one path per GeoJSON feature
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("stroke", "#fff")
.style("stroke-width", "1")
.style("fill", function(d) {
// Get data value
var value = d.properties.lostCount;
if (value) {
//If value exists…
return color(value);
} else {
//If value is undefined…
return "rgb(213,222,217)";
}
})
.on("click", function(d) {
$(document).ready(function(){
$("#img1").attr("src","");
$("#img2").attr("src","");
$(".popup").css("margin-left", "0%");
if (d.properties.name == "California") {
$("#img1").attr("src","./img/CityReports.jpg");
$("#img2").attr("src","./img/TimeReports.jpg");
};
});
});
// Map the cities I have lived in!
d3.csv("citiesCount.csv", function(data) {
svg.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", function(d) {
return projection([d.lon, d.lat])[0];
})
.attr("cy", function(d) {
return projection([d.lon, d.lat])[1];
})
.attr("r", function(d) {
return Math.sqrt(d.dogs+d.cats)/3;
})
.style("fill", "rgb(217,91,67)")
.style("opacity", 0.85)
// Modification of custom tooltip code provided by Malcolm Maclean, "D3 Tips and Tricks"
// http://www.d3noob.org/2013/01/adding-tooltips-to-d3js-graph.html
.on("mouseover", function(d) {
div.transition()
.duration(200)
.style("opacity", .9);
div.text(d.place+"\n "+"Dogs:"+d.dogs+"\n "+"Cats:"+d.cats)
.style("width", 70)
.style("height", 50)
.style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
})
// fade out tooltip on mouse out
.on("mouseout", function(d) {
div.transition()
.duration(500)
.style("opacity", 0);
});
});
// Modified Legend Code from Mike Bostock: http://bl.ocks.org/mbostock/3888852
// var legend = d3.select("body").append("svg")
// .attr("class", "legend")
// .attr("width", 140)
// .attr("height", 200)
// .selectAll("g")
// .data(color.domain().slice().reverse())
// .enter()
// .append("g")
// .attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
// legend.append("rect")
// .attr("width", 18)
// .attr("height", 18)
// .style("fill", color);
// legend.append("text")
// .data(legendText)
// .attr("x", 24)
// .attr("y", 9)
// .attr("dy", ".35em")
// .text(function(d) { return d; });
});
});
</script>
</div>
</div>
</div>
</body>
</html>