Built with blockbuilder.org
Last active
November 8, 2015 18:28
-
-
Save brettvalle/fd04d558124b336f473b to your computer and use it in GitHub Desktop.
california_wildfires_simple
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> | |
.graticule { | |
fill: none; | |
stroke: #777; | |
stroke-width: .5px; | |
stroke-opacity: .5 | |
} | |
.land { | |
fill: #d3d3d3; | |
} | |
.fire1 { | |
fill: #0000ff; | |
} | |
.fire2 { | |
fill: #ff0000; | |
} | |
.boundary { | |
fill: none; | |
stroke: #fff; | |
stroke-width: .5px; | |
} | |
.legend { | |
font-size: 12px; | |
} | |
</style> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script> | |
<script src="http://d3js.org/topojson.v1.min.js"></script> | |
<script> | |
var width = 650, | |
height = 745; | |
var color_domain = [750, 1500] | |
var ext_color_domain = [750, 1500, 0] | |
var legend_labels = ["2000-2013", "1878-1999", "Fire size > 50,000 acres"] | |
var color = d3.scale.threshold() | |
.domain(color_domain) | |
.range(["#ffffff", "#ff0000", "#0000ff"]); | |
var projection = d3.geo.conicEqualArea() | |
.scale(1400*2.25) | |
.rotate([114, 0]) | |
.center([0, 39.5]) | |
.parallels([34, 40.5]) | |
.clipExtent([[-1, -1], [width + 1, height + 1]]); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height); | |
var graticule = d3.geo.graticule() | |
.step([1, 1]); | |
svg.append("path") | |
.datum(graticule) | |
.attr("class", "graticule") | |
.attr("d", path); | |
//id == 6 for ca | |
d3.json("us.json", function(error, us) { | |
var californiaState = us.objects.states.geometries.filter(function(d) { return d.id === 6; })[0], | |
californiaCounties = us.objects.counties.geometries.filter(function(d) { return d.id / 1000 | 0 === 6; }); | |
svg.insert("path", ".graticule") | |
.datum(topojson.feature(us, californiaState)) | |
.attr("class", "land") | |
.attr("d", path); | |
svg.insert("path", ".graticule") | |
.datum(topojson.mesh(us, {type: "GeometryCollection", geometries: californiaCounties})) | |
.attr("class", "boundary") | |
.attr("d", path); | |
}); | |
d3.json("pre2000r1.json", function(error, pre2000r1) { | |
svg.append("path") | |
.datum(topojson.feature(pre2000r1, pre2000r1.objects.pre2000)) | |
.attr("class", function(d) { return "fire1"; }) | |
.attr("d", path); | |
}); | |
d3.json("post2000r1.json", function(error, post2000r1) { | |
svg.append("path") | |
.datum(topojson.feature(post2000r1, post2000r1.objects.post2000)) | |
.attr("class", function(d) { return "fire2"; }) | |
.attr("d", path); | |
}); | |
//Addlegend | |
var legend = svg.selectAll("g.legend") | |
.data(ext_color_domain) | |
.enter().append("g") | |
.attr("class", "legend"); | |
var ls_w = 20, ls_h = 20; | |
var pos_h = 85; | |
var pos_v = 105; | |
legend.append("rect") | |
.attr("x", pos_h) | |
.attr("y", function(d, i){ return height - (i*ls_h) - 2*ls_h-pos_v;}) | |
.attr("width", ls_w) | |
.attr("height", ls_h) | |
.style("fill", function(d, i) { return color(d); }) | |
.style("opacity", 0.8); | |
legend.append("text") | |
.attr("x", pos_h+30) | |
.attr("y", function(d, i){ return height - (i*ls_h) - ls_h - 4-pos_v;}) | |
.text(function(d, i){ return legend_labels[i]; }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment