-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
234 lines (204 loc) · 9.7 KB
/
index.html
File metadata and controls
234 lines (204 loc) · 9.7 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
<!DOCTYPE html>
<html>
<head>
<title>Crime in New York City</title>
<link href="https://fonts.googleapis.com/css?family=PT+Sans" rel="stylesheet">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/styles/default.min.css">
<meta charset="utf-8"/>
<script type="text/javascript" src="js/geojson.min.js"></script>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="http://d3js.org/topojson.v2.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.9.0/highlight.min.js"></script>
<style>
/* Because this project was labelled as a "display as if it were
a poster" sort of endeavor, we decided to go for a fixed page width
to make sure the experience would be standardized and not subject to
individual screen sizes (much like actual posters). */
body{ font-family: "PT Sans",sans-serif;
margin: 0;
background-color: #1f211c;
width: 1600px;
display: inline-block;}
div {
display: block;
}
svg { margin: 0 0 0 0;
float:left; }
svg#border
{ background: url(images/banner.png);
background-repeat: no-repeat;
background-size: 660px;
display: block;
width: 1600px;
height: 140px;
padding-bottom: 100px; }
svg#borough_map
{}
svg#borough_plot
{}
path.borough_map
{ stroke: 4px; }
.axisB line
{ stroke: #aaaaaa; }
.axisB path
{ stroke: #aaaaaa; }
.axisB text
{ fill: #aaaaaa; }
</style>
</head>
<body>
<svg id="border" width="100%" height="100px">
<text
fill= "#ffffff" text-anchor="middle" x="750" y="100" font-size="70px">2015 NYPD Complaint Data Analysis</text>
<text
fill= "#aaaaaa" text-anchor="middle" x="765" y="145" font-size="27px" font-style="italic">Categorized criminal complaints in NYC by borough and selected crimes -- “data.cityofnewyork.us” </text>
<image x="60" y="25" width="140" height="110" xlink:href="images/badge.png"></image>
</svg>
<svg id ="borough_map1" width="800" height="700"></svg>
<svg id ="borough_plot1" width="800" height="700"></svg>
<svg id ="borough_map2" width="800" height="700"></svg>
<svg id ="borough_plot2" width="800" height="700"></svg>
<svg id ="borough_map3" width="800" height="700"></svg>
<svg id ="borough_plot3" width="800" height="700"></svg>
<script>
var geo;
var tsv;
var projection = d3.geoMercator();
d3.tsv("data/NYPD_Complaint_Map.tsv", function(error, data) {
tsv = data;
});
//Geojson data taken from https://github.com/dwillis/nyc-maps
d3.json("data/boroughs.geojson", function (error, data) {
geo = data;
showMap(1); showMap(2); showMap(3);
plotPoints(1,"LARCENY");
showConcentration(1, "LARCENY");
plotPoints(2,"AGGRAVATED HARASSMENT");
showConcentration(2,"AGGRAVATED HARASSMENT");
plotPoints(3,"CRIMINAL MIS");
showConcentration(3,"CRIMINAL MIS");
});
function showMap(num) {
var map_id = "#borough_map"+num;
var svg1 = d3.select(map_id);
projection.fitExtent([[100,100], [600, 600]], geo);
pathGenerator = d3.geoPath().projection(projection);
var paths = svg1.selectAll("path.borough_map").data(geo.features);
paths.enter()
.append("path")
.attr("class", "borough_map")
.attr("stroke","#bbbbbb")
.attr("stroke-width",1)
.attr("opacity",1)
.attr("fill", function () { return "#222233"; })
.merge(paths)
.attr("d", function (borough_map) { return pathGenerator(borough_map); });
}
function plotPoints(num, crime) {
var map_id = "#borough_map"+num;
var svg1 = d3.select(map_id);
//scale domains and ranges calculated by searching through the geojson file.
var scaleLati = d3.scaleLinear().domain([40.50110098,40.91027045]).range([600,100]);
var scaleLongi = d3.scaleLinear().domain([-74.24930373,-73.70138638]).range([100,600]);
//Pins
svg1.append("text").html("Manhattan").attr("font-size",17).attr("x",240).attr("y",260).attr("fill", "#aaaaaa");
svg1.append("text").html("Bronx").attr("font-size",17).attr("x",550).attr("y",160).attr("fill", "#aaaaaa");
svg1.append("text").html("Brooklyn").attr("font-size",17).attr("x",300).attr("y",540).attr("fill", "#aaaaaa");
svg1.append("text").html("Queens").attr("font-size",17).attr("x",590).attr("y",350).attr("fill", "#aaaaaa");
svg1.append("text").html("Staten Island").attr("font-size",17).attr("x",110).attr("y",410).attr("fill", "#aaaaaa");
//Title
svg1.append("text").attr("transform", "translate(400, 50)").attr("text-anchor","middle")
.attr("font-size","25").attr("fill", "#dddddd")
.html( function() {
if (crime=="LARCENY") return "Larceny Complaints";
else if (crime=="AGGRAVATED HARASSMENT") return "Aggravated Harassment Complaints";
else if (crime=="CRIMINAL MIS") return "Criminal Mischief Complaints";
})
//Subtitle
svg1.append("text").attr("transform", "translate(400, 72)").attr("text-anchor","middle")
.attr("font-size","15").attr("fill", "#aaaaaa")
.html( function() {
if (crime=="LARCENY") return "(Petit Larceny, Grand Larceny, & Felony Theft)";
else if (crime=="AGGRAVATED HARASSMENT") return "(First Degree, Second Degree)";
else if (crime=="CRIMINAL MIS") return "(Damage, defacement, alteration, or destruction of property) ";
})
//Data
tsv.forEach( function(d) {
if ((d.Latitude != (undefined || "")) && (d.Longitude != (undefined || "")) && d.PD_DESC.includes(crime)){
var lati = parseFloat(d.Latitude);
var longi = parseFloat(d.Longitude);
svg1.append("circle")
.attr("cx", scaleLongi(longi))
.attr("cy", scaleLati(lati))
.attr("r", 2)
.attr("opacity", function() {
if (crime=="LARCENY") return 0.3;
else if (crime=="AGGRAVATED HARASSMENT") return 0.5;
else return 0.5;
})
.attr("stroke", function() {
if (crime=="LARCENY") return "blue";
else if (crime=="AGGRAVATED HARASSMENT") return "red";
else return "#ff00ff"
})
.attr("stroke-width",1)
.style("fill", "#ffffff");
}
});
}
function showConcentration(num, crime) {
var map_id = "#borough_plot"+num;
var svg0 = d3.select(map_id);
//Axis
var scaleB = d3.scaleLinear().domain([0,24]).range([0,600]);
var axB = d3.axisBottom(scaleB).tickFormat(function(d) {
var ampm; var hour;
if (d==24 || d-12<0) ampm = "AM"; else ampm = "PM";
if (d%12 == 0) hour = 12; else hour = d%12;
return hour+ampm;
});
svg0.append("g").attr("transform", "translate(150, 450)").attr("class", "axisB").call(axB);
//Text
svg0.append("text").html("Bronx").attr("transform", "translate(125, 405)").attr("text-anchor","end").attr("fill", "#aaaaaa");
svg0.append("text").html("Brooklyn").attr("transform", "translate(125, 345)").attr("text-anchor","end").attr("fill", "#aaaaaa");
svg0.append("text").html("Manhattan").attr("transform", "translate(125, 285)").attr("text-anchor","end").attr("fill", "#aaaaaa");
svg0.append("text").html("Queens").attr("transform", "translate(125, 225)").attr("text-anchor","end").attr("fill", "#aaaaaa");
svg0.append("text").html("Staten Island").attr("transform", "translate(125, 165)").attr("text-anchor","end").attr("fill", "#aaaaaa");
svg0.append("text").attr("transform", "translate(400, 50)").attr("text-anchor","middle").attr("font-size","25").attr("fill", "#dddddd").attr("font-weight","900")
.html(function() {
if (crime=="LARCENY") return "Larceny Complaints by Time of Day";
else if (crime=="AGGRAVATED HARASSMENT") return "Aggravated Harassment Complaints by Time of Day";
else if (crime=="CRIMINAL MIS") return "Criminal Mischief Complaints by Time of Day";
});
//Data
tsv.forEach( function(d) {
var dtime = d.CMPLNT_FR_TM
if (dtime != undefined && d.PD_DESC.includes(crime)){
var hour = dtime.split(":")[0];
var minute = dtime.split(":")[1];
var inthour = parseFloat(hour);
var intminute = parseFloat(minute);
svg0.append("rect")
.attr("x", inthour*25+intminute*25/60+150)
.attr("y", function () {
var name = d.BORO_NM;
if (name == "STATEN ISLAND") return 150;
else if (name == "QUEENS") return 210;
else if (name == "MANHATTAN") return 270;
else if (name == "BROOKLYN") return 330;
else return 390; //Bronx
})
.attr("height",20)
.attr("width",6)
.attr("opacity",0.15)
.attr("fill", function(){
if (crime=="LARCENY") return "#5555ff";
else if (crime=="AGGRAVATED HARASSMENT") return "red";
else return "#ff00ff";
});
}
});
}
</script>
</body>
</html>