Skip to content

Instantly share code, notes, and snippets.

@danielepalumbo89
Created June 5, 2016 09:54
Show Gist options
  • Save danielepalumbo89/9032780a168d27465d60e0474e62d0d5 to your computer and use it in GitHub Desktop.
Save danielepalumbo89/9032780a168d27465d60e0474e62d0d5 to your computer and use it in GitHub Desktop.
var width = 960,
height = 1160;
var formatNumber = d3.format(",.0f");
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("uk.json", function(error, uk) {
if (error) return console.error(error);
var subunits = topojson.feature(uk, uk.objects.subunits);
var projection = d3.geo.albers()
.center([0, 55.4])
.rotate([4.4, 0])
.parallels([50, 60])
.scale(6000)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
svg.selectAll(".subunit")
.data(topojson.feature(uk, uk.objects.subunits).features)
.enter().append("path")
.attr("class", function(d) { return "subunit " + d.id; })
.attr("d", path);
svg.append("path")
.datum(topojson.feature(uk, uk.objects.subunits))
.attr("class", "land")
.attr("d", path);
svg.append("path")
.datum(topojson.mesh(uk, uk.objects.subunits, function(a, b) { return a !== b; }))
.attr("class", "border border--state")
.attr("d", path);
d3.csv
svg.append("g")
.attr("class", "bubble")
.selectAll("circle")
.data(topojson.feature(uk, uk.objects.places).features
.sort(function(a, b) { return b.properties.population - a.properties.population; }))
.enter().append("circle")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.attr("r", 2);
var radius = d3.scale.sqrt()
.domain([0, 1e6])
.range([0, 15]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment