Skip to content

Instantly share code, notes, and snippets.

@yoon-gu
Forked from mbostock/.block
Last active July 29, 2016 15:53
Show Gist options
  • Save yoon-gu/292357d88f07092f8759238a10cddd2f to your computer and use it in GitHub Desktop.
Save yoon-gu/292357d88f07092f8759238a10cddd2f to your computer and use it in GitHub Desktop.
연습 02 : Korea Area Choropleth
license: gpl-3.0
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This choropleth encodes the area of each county using color on a log scale from red to blue.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
.states {
fill: none;
stroke: #fff;
stroke-linejoin: round;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var fill = d3.scale.log()
.domain([10, 500])
.range(["brown", "steelblue"]);
var projection = d3.geo.mercator()
.center([126.9895, 37.5551])
.scale(70000)
.translate([width/2, height/2]);
var path = d3.geo.path().projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json(".seoul_submunicipalities_topo.json", function(error, kor) {
if (error) throw error;
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(kor, kor.objects.seoul_submunicipalities_geo).features)
.enter().append("path")
.attr("d", path)
.style("fill", function(d) { return fill(path.area(d)); });
svg.append("path")
.datum(topojson.mesh(kor, kor.objects.seoul_submunicipalities_geo, function(a, b) { return a.id !== b.id; }))
.attr("class", "states")
.attr("d", path);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment