Built with blockbuilder.org
Last active
April 15, 2017 21:12
-
-
Save maelafifi/bcaf2d624c015bf113330a3187706c7c to your computer and use it in GitHub Desktop.
fresh block
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
license: mit |
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> | |
<head> | |
<meta charset="utf-8"> | |
<link href="style.css" rel="stylesheet" type="text/css"> | |
<title>SF Arrests</title> | |
</head> | |
<body> | |
<svg width="960" height="600"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="script.js"></script> | |
</body> |
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
// the geojson files are large, so loading them locally | |
var urls = { | |
basemap: "https://usf-cs360-2017.github.io/homework3-maelafifi/SVDistricts.geojson" | |
}; | |
var svg = d3.select("body").select("svg"); | |
var g = { | |
basemap: svg.append("g").attr("id", "basemap") | |
}; | |
// https://github.com/d3/d3-geo#conic-projections | |
var projection = d3.geoConicEqualArea(); | |
var path = d3.geoPath().projection(projection); | |
// http://mynasadata.larc.nasa.gov/latitudelongitude-finder/ | |
// center on san francisco [longitude, latitude] | |
// choose parallels on either side of center | |
projection.parallels([37.692514, 37.840699]); | |
// rotate to view we usually see of sf | |
projection.rotate([122, 0]); | |
// we want both basemap and streets to load before arrests | |
// https://github.com/d3/d3-queue | |
var q = d3.queue() | |
.defer(d3.json, urls.basemap) | |
.await(drawMap); | |
function drawMap(error, basemap) { | |
if (error) throw error; | |
console.log("basemap", basemap); | |
// make sure basemap fits in projection | |
projection.fitSize([960, 600], basemap); | |
// draw basemap | |
var land = g.basemap.selectAll("path.land") | |
.data(basemap.features) | |
.enter() | |
.append("path") | |
.attr("d", path) | |
.attr("class", "land"); | |
} | |
function translate(x, y) { | |
return "translate(" + String(x) + "," + String(y) + ")"; | |
} |
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
body { | |
background-color: white; | |
text-align: center; | |
font-family: sans-serif; | |
font-size: 9pt; | |
} | |
#tooltip { | |
font-weight: 600; | |
text-shadow: 0px 0px 2px white; | |
fill: black; | |
stroke: none; | |
} | |
path.land { | |
fill: #dddddd; | |
stroke: none; | |
} | |
path.neighborhood { | |
fill: none; | |
stroke: white; | |
stroke-width: 3.5px; | |
pointer-events: none; | |
} | |
path.street { | |
fill: none; | |
stroke: white; | |
stroke-width: 1px; | |
pointer-events: none; | |
} | |
.active { | |
stroke: red !important; | |
stroke-width: 1.5px !important; | |
} | |
circle.symbol { | |
fill-opacity: 0.6; | |
stroke: white; | |
stroke-width: 1px; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment