Created
January 26, 2014 16:17
-
-
Save glassira/8635149 to your computer and use it in GitHub Desktop.
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"> | |
<head> | |
</head> | |
<body> | |
<script src='http://d3js.org/d3.v3.js'></script> | |
<script src='http://d3js.org/topojson.v1.js'></script> | |
<script src='http://d3js.org/queue.v1.js'></script> | |
<script src='http://d3js.org/colorbrewer.v1.js'></script> | |
<script> | |
var width = 960, height = 500 | |
var ext_color_domain = [0, 50, 150, 350, 750, 1500] | |
var color_domain = ext_color_domain.slice(1) | |
var color = d3.scale.threshold() | |
.range(colorbrewer['Reds'][6]) | |
.domain(color_domain) | |
queue() | |
.defer(d3.json, 'http://nemetz.devg.ru/d3/russia_1e-7sr.json') | |
.defer(d3.csv, 'http://nemetz.devg.ru/d3/Accidents.csv') | |
.await(ready) | |
function drawMap(svg, map, rateById, projection) { | |
var path = d3.geo.path().projection(projection) | |
svg.append('g') | |
.attr('class', 'region') | |
.selectAll('path') | |
.data(topojson.feature(map, map.objects.russia).features) | |
.enter().append('path') | |
.attr('d', path) | |
.style('fill', function (d) { return color(rateById[d.properties.region]) }) | |
.style('stroke', 'red') | |
.style('stroke-width', function(d) { | |
var quant=+d.CarAccidents | |
return (quant/400) | |
}) | |
.style('opacity', 0.7) | |
.on('mouseover', function(d,i){ | |
d3.select(this) | |
.transition() | |
.style('opacity', 1) | |
}) | |
.on('mouseout', function(d,i){ | |
d3.select(this) | |
.transition() | |
.style('opacity', 0.7) | |
}) | |
} | |
function ready(error, map, data) { | |
var svg = d3.select('body').append('svg') | |
.attr('width', width) | |
.attr('height', height) | |
.style('margin', '10px auto') | |
var projection = d3.geo.conicEqualArea() | |
.rotate([-105, 0]) | |
.center([-10, 65]) | |
.parallels([52, 64]) | |
.scale(700) | |
.translate([width * 0.5, height * 0.5]) | |
var rateById = {} | |
data.forEach(function (d) { rateById[d.RegionCode] = +d.Deaths }) | |
drawMap(svg, map, rateById, projection) | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment