Last active
March 4, 2019 23:21
-
-
Save arkut/13b6fa6b67a7e320194bec44c544d894 to your computer and use it in GitHub Desktop.
Mapping Nebraska school districts with D3 v4
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> | |
<style> | |
.districts { | |
fill: steelblue; | |
} | |
.districts :hover { | |
fill: red; | |
} | |
.district-borders { | |
fill: none; | |
stroke: #fff; | |
stroke-width: 0.5px; | |
stroke-linejoin: round; | |
stroke-linecap: round; | |
pointer-events: none; | |
} | |
</style> | |
<svg width="960" height="600"></svg> | |
<script src="https://d3js.org/d3.v4.min.js"></script> | |
<script src="https://d3js.org/topojson.v2.min.js"></script> | |
<script src="https://d3js.org/d3-queue.v3.min.js"></script> | |
<script> | |
var svg = d3.select('svg'); | |
var projection = d3.geoConicConformal() | |
.parallels([40, 43]) | |
.rotate([100, 0]); | |
var path = d3.geoPath() | |
.projection(projection); | |
d3.json("ne-district-id-topo.json", function(error, ne) { | |
if (error) throw error; | |
var featureCollection = topojson.feature(ne, ne.objects.districts); | |
projection.fitSize([960,580],featureCollection); | |
svg.append("g") | |
.attr("class", "districts") | |
.selectAll("path") | |
.data(featureCollection.features) | |
.enter().append("path") | |
.attr("d", path); | |
svg.append("path") | |
.attr("class", "district-borders") | |
.attr("d", path(topojson.mesh(ne, ne.objects.districts, function(a, b) { return a !== b; }))); | |
}); | |
function round(value, precision) { | |
var multiplier = Math.pow(10, precision || 0); | |
return Math.round(value * multiplier) / multiplier; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment