Last active
January 25, 2016 18:29
-
-
Save jadiehm/2f33d3565e9a8b6bee6a to your computer and use it in GitHub Desktop.
Us dot map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<meta charset="utf-8"> | |
<style> | |
body { | |
font-family: 'Proxima Nova', sans-serif; | |
} | |
.g-hed { | |
text-align: left; | |
text-transform: uppercase; | |
font-weight: bold; | |
font-size:22px; | |
margin: 3px 0; | |
} | |
.g-source-bold { | |
text-align: left; | |
font-size:10px; | |
font-weight: bold; | |
} | |
.g-source-reg { | |
text-align: left; | |
font-size:10px; | |
} | |
.g-source { | |
margin: 10px 0; | |
} | |
.g-intro { | |
font-size: 16px; | |
margin: 0px 0px 10px 0px; | |
} | |
.states { | |
fill: #d3d3d3; | |
stroke: #ffffff; | |
stroke-linejoin: round; | |
} | |
div.tooltip { | |
position: absolute; | |
left: 75px; | |
text-align: center; | |
height: 12px; | |
padding: 8px; | |
font-size: 13px; | |
font-family: 'Proxima-Nova', sans-serif; | |
background: #FFFFFF; | |
border: 1px solid #989898; | |
pointer-events: none; | |
} | |
.block { | |
width:18%; | |
height: 15px; | |
display:inline-block; | |
} | |
</style> | |
<body> | |
<h5 class="g-hed"></h5> | |
<p class="g-intro"></p> | |
<div class="g-chart"></div> | |
<div class="g-source"><span class="g-source-bold"></span><span class="g-source-reg"></span></div> | |
</body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script> | |
<script> | |
//Creates tooltip and makes it invisiblae | |
var div = d3.select("body").append("div") | |
.attr("class", "tooltip") | |
.style("opacity", 0); | |
//Sets dimensions | |
var margin = {top: 10, left: 10, bottom: 10, right: 10}, | |
width = window.outerWidth, | |
width = width - margin.left - margin.right, | |
mapRatio = .5, | |
height = width * mapRatio; | |
//Tells the nap what projection to use | |
var projection = d3.geo.albersUsa() | |
.scale(width) | |
.translate([width / 2, height / 2]); | |
//Tells the map how to draw the paths from the projection | |
var path = d3.geo.path() | |
.projection(projection); | |
//Appened svg to page | |
var map = d3.select(".g-chart").append("svg") | |
.style('height', height + 'px') | |
.style('width', width + 'px'); | |
//Load the files | |
queue() | |
.defer(d3.json, "us.json") | |
.defer(d3.csv, "massshootings.csv") | |
.await(ready); | |
//Moves selection to front | |
d3.selection.prototype.moveToFront = function() { | |
return this.each(function(){ | |
this.parentNode.appendChild(this); | |
}); | |
}; | |
//Moves selection to back | |
d3.selection.prototype.moveToBack = function() { | |
return this.each(function() { | |
var firstChild = this.parentNode.firstChild; | |
if (firstChild) { | |
this.parentNode.insertBefore(this, firstChild); | |
} | |
}); | |
}; | |
function ready(error, us, massshootings) { | |
if (error) throw error; | |
console.log(us, massshootings); | |
//Appends chart headline | |
d3.select(".g-hed").text("Map headline goes here"); | |
//Appends chart intro text | |
d3.select(".g-intro").text("Map intro text goes here. Write a short sentence describing the map here."); | |
//Append states | |
map.append("g") | |
.attr("class", "states") | |
.selectAll("path") | |
.data(topojson.feature(us, us.objects.states).features) | |
.enter().append("path") | |
.attr("d", path); | |
//Add cities | |
map.selectAll("circle") | |
.data(massshootings) | |
.enter() | |
.append("circle") | |
.attr("cx", function(d) { | |
return projection([d.longitude, d.latitude])[0]; | |
}) | |
.attr("cy", function(d) { | |
return projection([d.longitude, d.latitude])[1]; | |
}) | |
.attr("r", function(d){ | |
return Math.sqrt(d.dead)*7; | |
}) | |
.style("fill", "#5e8dc9") | |
.style("stroke", "#305491") | |
.style("stroke-width", 1) | |
.style("opacity", 0.75) | |
//Hovers | |
.on("mouseover", function(d) { | |
var sel = d3.select(this); | |
sel.moveToFront(); | |
d3.select(this).transition().duration(300).style("opacity", 0.8); | |
div.transition().duration(300) | |
.style("opacity", 1) | |
div.text(d.location + ": " + d.dead) | |
.style("left", (d3.event.pageX) + "px") | |
.style("top", (d3.event.pageY -30) + "px"); | |
}) | |
.on("mouseout", function() { | |
var sel = d3.select(this); | |
d3.select(this) | |
.transition().duration(300) | |
.style("opacity", 0.75); | |
div.transition().duration(300) | |
.style("opacity", 0); | |
}); | |
//Appends chart source | |
d3.select(".g-source-bold") | |
.text("SOURCE: ") | |
.attr("class", "g-source-bold"); | |
d3.select(".g-source-reg") | |
.text("Chart source info goes here") | |
.attr("class", "g-source-reg"); | |
//RESPONSIVENESS | |
d3.select(window).on('resize', resize); | |
function resize() { | |
var w = d3.select(".g-chart").node().clientWidth; | |
console.log("resized", w); | |
// adjust things when the window size changes | |
width = w - margin.left - margin.right; | |
height = width * mapRatio; | |
console.log(width) | |
// update projection | |
var newProjection = d3.geo.albersUsa() | |
.scale(width) | |
.translate([width / 2, height / 2]); | |
//Update path | |
path = d3.geo.path() | |
.projection(newProjection); | |
//Update circles | |
map.selectAll("circle") | |
.attr("cx", function(d) { | |
return newProjection([d.longitude, d.latitude])[0]; | |
}) | |
.attr("cy", function(d) { | |
return newProjection([d.longitude, d.latitude])[1]; | |
}) | |
.attr("r", function(d){ | |
return Math.sqrt(d.dead)*3; | |
}) | |
// resize the map container | |
map | |
.style('width', width + 'px') | |
.style('height', height + 'px'); | |
// resize the map | |
map.selectAll("path").attr('d', path); | |
} | |
} | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date | shooter | dead | injured | location | latitude | longitude | article | |
---|---|---|---|---|---|---|---|---|
1/4/15 | Unknown | 3 | 1 | Dallas, TX | 32.776664 | -96.796988 | http://dfw.cbslocal.com/2015/01/04/police-3-dead-1-in-surgery-after-dallas-shooting/ | |
1/9/15 | Unknown | 4 | 0 | San Francisco, CA | 37.774929 | -122.419416 | http://abc7news.com/news/sfpd-confirm-4-dead-following-shooting-in-hayes-valley/469681/ | |
1/10/15 | John Lee | 3 | 1 | Moscow, ID | 46.732387 | -117.000165 | http://www.kxly.com/news/north-idaho-news/moscow-police-investigating-shooting/30634900 | |
1/24/15 | Unknown | 3 | 5 | Omaha, NE | 41.252363 | -95.997988 | http://www.usatoday.com/story/news/nation/2015/01/24/omaha-party-shooting/22297565/ | |
1/24/15 | Jonathon Walker | 4 | 1 | Queens, NY | 40.728224 | -73.794852 | http://www.nbcnewyork.com/news/local/2-Kids-and-1-Adult-Dead-in-Queens-Shooting-3rd-Child-Being-Treated-Brookville-148th-Avenue-289669211.html | |
1/29/15 | Thomas Jessee Lee | 5 | 0 | Troup County, GA | 33.069857 | -85.023346 | http://www.wsbtv.com/news/news/local/five-bodies-found-inside-lagrange-home/nj2rK/ | |
2/4/15 | Unknown | 4 | 0 | King, NC | 36.280694 | -80.35922 | http://www.journalnow.com/news/crime/four-dead-in-stokes-county-shooting/article_eed92570-aca5-11e4-91e7-0f002c38c9b8.html | |
2/5/15 | Unknown | 3 | 3 | Warrensville Heights, OH | 41.432307 | -81.510266 | http://www.wkyc.com/story/news/local/cuyahoga-county/2015/02/05/warrensville-heights-barbershop/22956675/ | |
2/7/15 | Cedric G. Prather | 5 | 2 | Douglasville, GA | 33.751497 | -84.747714 | http://www.csmonitor.com/USA/Latest-News-Wires/2015/0208/Children-among-five-dead-in-Georgia-shooting-video | |
2/9/15 | Christopher Lee Duncan and Dora Delgado | 3 | 1 | New Port Richey, FL | 28.244177 | -82.719267 | http://www.tampabay.com/news/publicsafety/crime/pasco-sheriff-identifies-third-victim-in-moon-lake-shooting/2217118 | |
2/22/15 | Anthony Giaquinta | 3 | 2 | Habersham County, GA | 34.647889 | -83.549657 | http://www.wsbtv.com/news/news/local/2-deputies-shot-habersham-county/nkGwC/ | |
2/22/15 | Atase Giffa | 4 | 1 | Killeen, TX | 31.117119 | -97.727796 | http://www.wfaa.com/story/news/nation/2015/02/23/four-dead-killeen-texas-shooting/23873731/ | |
2/25/15 | Unknown | 3 | 2 | Houston, TX | 29.760427 | -95.369803 | http://www.khou.com/story/news/2015/02/26/3-dead-2-injured-in-south-houston-shooting/24040425/ | |
2/27/15 | Joseph Jesse Aldridge | 8 | 1 | Tyrone, MO | 37.203383 | -91.87654 | http://www.nbcnews.com/news/crime-courts/nine-found-dead-including-gunman-after-missouri-shooting-spree-police-n314071 | |
2/28/15 | Ian Sherrod | 4 | 0 | Tarboro, NC | 35.896824 | -77.535805 | http://www.wncn.com/story/28228144/at-least-2-shot-at-tarboro-barber-shop | |
2/28/15 | Unknown | 3 | 1 | Columbia, MO | 38.951705 | -92.334072 | http://www.wmur.com/national/three-dead-one-wounded-in-missouri-shootings/31551946 | |
3/3/15 | Unknown | 3 | 1 | Las Vegas, NV | 36.169941 | -115.13983 | http://www.jrn.com/ktnv/news/2-dead-2-hospitalized-after-shooting-near-Fort-Apache-and-Sahara-294993961.html | |
3/15/15 | Christopher Lance Joyner | 3 | 1 | Houston County, AL | 31.131869 | -85.313622 | http://www.wsfa.com/story/28529911/3-dead-1-injured-in-houston-county-murder-suicide | |
3/17/15 | Unknown | 3 | 4 | Stockton, CA | 37.957702 | -121.29078 | http://www.kcra.com/news/police-multiple-people-reportedly-injured-in-stockton-shooting/31860188 | |
3/24/15 | Unknown | 4 | 0 | Indianapolis, IN | 39.768403 | -86.158068 | http://www.usatoday.com/story/news/nation/2015/03/24/4-dead-indianapolis-home/70374450/ | |
3/30/15 | Sudheer Khamitkar | 4 | 0 | Tulsa, OK | 36.153982 | -95.992775 | http://www.tulsaworld.com/news/crimewatch/four-people-found-dead-in-east-tulsa-home-police-say/article_9c246e78-57b2-5d84-8257-5a5d23e37a14.html | |
4/16/15 | Unknown | 5 | 0 | Phoenix, AZ | 33.448377 | -112.074037 | http://www.washingtonpost.com/news/morning-mix/wp/2015/04/17/five-dead-in-family-dispute-after-hours-long-standoff-at-phoenix-home/ | |
5/3/15 | Unknown | 4 | 1 | Menasha, WI | 44.202208 | -88.446497 | http://news.yahoo.com/four-killed-shooting-wisconsin-foot-bridge-including-suspect-041118959.html | |
5/13/15 | Unknown | 4 | 0 | Anchorage, AK | 61.218056 | -149.900278 | http://www.adn.com/article/20150514/domestic-violence-blame-4-deaths-south-anchorage-police-say | |
5/17/15 | Unknown | 9 | 18 | Waco, TX | 31.549333 | -97.14667 | http://www.cnn.com/2015/05/17/us/texas-shooting/index.html | |
5/31/15 | Unknown | 3 | 1 | Cleveland, OH | 41.49932 | -81.694361 | http://www.wkyc.com/story/news/local/cleveland/2015/05/31/lavern-ave-shooting/28285919/ | |
6/3/15 | Unknown | 3 | 1 | Wyandanch, NY | 40.753988 | -73.360398 | http://www.nbcnewyork.com/news/local/3-Dead-Wyandanch-Long-Island-Shooting-Police-306096381.html | |
6/17/15 | Dylan Roof | 9 | 0 | Charleston, SC | 32.776475 | -79.931051 | http://www.usatoday.com/story/news/nation/2015/06/17/charleston-south-carolina-shooting/28902017/ | |
6/21/15 | Russell Smith | 4 | 0 | Roy, UT | 41.161611 | -112.026331 | http://www.wkyt.com/home/headlines/Several-people-injured-in-shooting-at-Douglass-Park-in-Lexington.html | |
6/23/15 | Unknown | 3 | 1 | Breaux Bridge, LA | 30.273532 | -91.899284 | http://www.katc.com/story/29392606/3-dead-1-injured-in-breaux-bridge-shooting | |
6/27/15 | Unknown | 4 | 0 | Greenacres, FL | 26.627628 | -80.13539 | http://www.palmbeachpost.com/news/news/crime-law/greenacres-police-probe-report-of-shooting/nmm6y/ | |
7/5/15 | Unknown | 4 | 0 | Rock Hill, SC | 34.924867 | -81.025078 | http://www.charlotteobserver.com/news/local/crime/article26552740.html | |
7/7/15 | Unknown | 3 | 1 | Baltimore, MD | 39.290385 | -76.612189 | http://www.wbal.com/article/116967/40/4-shot-3-dead-just-blocks-from-umb-campus | |
7/12/15 | Marquiles Whaley | 3 | 1 | Baton Rouge, LA | 30.458283 | -91.14032 | http://theadvocate.com/news/12895241-171/three-dead-one-wounded-in | |
7/15/15 | Unknown | 4 | 1 | Holly Hill, SC | 33.322662 | -80.413704 | http://abcnews.go.com/US/wireStory/sheriffs-office-people-killed-home-south-carolina-32464912 | |
7/16/15 | Muhammad Youssef Abdulazeez | 5 | 3 | Chattanooga, TN | 35.04563 | -85.30968 | http://www.cbsnews.com/news/report-police-officer-shot-near-tennessee-army-recruiting-center/ | |
7/23/15 | John Russell Houser | 3 | 9 | Lafayette, LA | 30.22409 | -92.019843 | http://www.latimes.com/nation/la-na-louisiana-movie-theater-shooting-20150724-story.html | |
8/7/15 | Jody Herring | 4 | 0 | Barre, VT | 44.197006 | -72.502049 | http://www.wcax.com/story/29740309/3-women-found-dead-in-berlin-related-to-barre-shooting-suspect | |
8/8/15 | David Conley | 8 | 0 | Houston, TX | 29.760427 | -95.369803 | http://www.usatoday.com/story/news/nation/2015/08/10/victims-shooting-mourned/31398681/ | |
8/19/15 | Unknown | 3 | 4 | Rochester, NY | 43.16103 | -77.610922 | http://abcnews.go.com/US/wireStory/killed-wounded-shooting-western-york-33194354 | |
8/26/15 | Vester Flanagan (aka Bryce Williams) | 3 | 1 | Moneta, VA | 37.181254 | -79.617254 | http://www.nytimes.com/2015/08/27/us/wdbj7-virginia-journalists-shot-during-live-broadcast.html?emc=edit_na_20150826&nlid=54192941&ref=headline&_r=0 | |
8/29/15 | Robert Seth Denton | 3 | 2 | Bristol, TN | 36.595106 | -82.188744 | http://abcnews.go.com/US/wireStory/dead-injured-shooting-spree-tennessee-33417102 | |
9/1/15 | Lyndon Beharry | 4 | 0 | Long Branch, NJ | 40.304278 | -73.99236 | http://6abc.com/news/family-shot-in-murder-suicide-before-nj-fire-prosecutors-say/969948/ | |
9/8/15 | Brian Short | 5 | 0 | Minneapolis, MN | 44.977753 | -93.265011 | http://www.chron.com/news/crime/article/Authorities-Minnesota-family-died-in-6500498.php | |
9/8/15 | Unknown | 4 | 0 | Manson, WA | 47.884745 | -120.156701 | http://www.yakimaherald.com/news/crime_and_courts/dead-in-shooting-in-chelan-county/article_9ff488b6-5707-11e5-a337-a77b679c27c1.html | |
9/13/15 | Rodney Chemin | 4 | 0 | Baker, LA | 30.588243 | -91.168163 | http://theadvocate.com/news/13436293-100/four-found-dead-in-apparent | |
9/17/15 | Scott Westerhuis | 6 | 0 | Platte, SD | 43.38694 | -98.84453 | http://www.nbcnews.com/news/us-news/father-killed-wife-kids-suicide-prelim-autopsy-reveals-n431401?cid=sm_tw&hootPostID=1cbcc7d6cf3ec13f4bb8ee5651e7de1f | |
10/1/15 | Chris Harper-Mercer | 10 | 7 | Roseburg, OR | 43.216505 | -123.341738 | http://www.oregonlive.com/pacific-northwest-news/index.ssf/2015/10/horror_in_roseburg_10_minutes.html#incart_maj-story-1 | |
10/31/15 | Undisclosed | 4 | 0 | Colorado Springs, CO | 38.833882 | -104.821363 | http://www.denverpost.com/news/ci_29052366/shooting-reported-near-downtown-colorado-springs | |
11/1/15 | Unknown | 4 | 0 | Pendleton, SC | 34.651773 | -82.783751 | http://www.foxcarolina.com/story/30411911/anderson-county-deputies-investigate-pendleton-shooting | |
11/4/15 | Herman Derico | 4 | 0 | Oakland, ME | 44.540222 | -69.721995 | http://www.wcsh6.com/story/news/2015/11/04/police-from-five-agencies-are-at-the-scene-of-a-reported-shooting-on-belgrade-road-in-oakland/75189082/ | |
11/13/15 | Gawain Rushane Wilson | 4 | 1 | Jacksonville, FL | 30.332184 | -81.655651 | http://www.wftv.com/news/ap/florida/infant-twins-among-4-killed-in-florida-domestic-sh/npNKJ/ | |
11/15/15 | William Hudson | 6 | 0 | Anderson County, TX | 31.776932 | -95.645795 | http://crimeblog.dallasnews.com/2015/11/suspect-in-anderson-county-campsite-slayings-charged-with-six-counts-of-capital-murder.html/ | |
11/16/15 | Donnie Lee Abernathy | 3 | 1 | Round Mountain, AL | 34.58037 | -87.33641 | http://wiat.com/2015/11/16/3-dead-1-injured-after-cherokee-county-shooting/ | |
11/17/15 | Pascasio Arellano | 4 | 0 | Murray, KY | 36.610333 | -88.314761 | http://bnonews.com/news/index.php/news/id2716 | |
12/2/15 | Syed Rizwan Farook and Tashfeen Malik | 14 | 17 | San Bernardino, CA | 34.108345 | -117.289765 | http://www.cnn.com/2015/12/03/us/what-we-know-san-bernardino-mass-shooting/index.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment