Skip to content

Instantly share code, notes, and snippets.

@chule
Last active August 29, 2015 14:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save chule/9ee62bceb245a567ed89 to your computer and use it in GitHub Desktop.
Counties of Croatia (from '92. to '97.)
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<!DOCTYPE html>
<meta charset="utf-8">
<style>
/*path {
fill: none;
stroke: #000;
stroke-linejoin: round;
stroke-linecap: round;
}
*/
.subunit {
fill: #777;
}
.country {
stroke: #fff;
fill: none;
}
/*
*/
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 600;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("croatiatopo.json", function(error, cro) {
if (error) return console.error(error);
var subunits = topojson.feature(cro, cro.objects.croatia);
var projection = d3.geo.mercator()
.center([15, 37.5]) // x to left, y to bottom
.scale(5400)
.translate([width / 3, height * 2]);
var path = d3.geo.path()
.projection(projection);
zupanije = svg.selectAll(".subunit")
.data(topojson.feature(cro, cro.objects.croatia).features)
.enter().append("path")
.attr("class", function(d) { /* console.log(d);*/ return "subunit " + d.properties.HASC_1.substr(3,2); }) //str.substr(start[, length])
.attr("d", path);
zupanije.append("title")
.text(function(d, i) { return d.properties.NAME_1; });
zupanije.on("mouseover", function (d, i) {
d3.select(this).style("fill", "steelblue"); // .attr("transform", "translate(5,5)");
//console.log(d.properties.NAME_1);
});
zupanije.on("mouseout", function (d, i) {
d3.select(this).style("fill", "#777");
});
svg.append("path")
.datum(subunits)
.attr("d", path)
.attr("class", "country");
});
d3.select(self.frameElement).style("height", height + 80 + "px");
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment