Skip to content

Instantly share code, notes, and snippets.

@ddonatien
Created January 31, 2020 16:30
Show Gist options
  • Select an option

  • Save ddonatien/95e36231fb45b350847073fb528c13e9 to your computer and use it in GitHub Desktop.

Select an option

Save ddonatien/95e36231fb45b350847073fb528c13e9 to your computer and use it in GitHub Desktop.
TD Grippe
license: mit
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="https://d3js.org/d3-scale-chromatic.v1.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
var width = 700,
height = 580;
var dataCsv = "https://lyondataviz.github.io/teaching/lyon1-m2/2017/data/GrippeFrance2014.csv";
var svg = d3.select( "body" )
.append( "svg" )
.attr( "width", width )
.attr( "height", height );
var projection = d3.geoConicConformal()
.center([2.454071, 46.279229])
.scale(2800);
var path = d3.geoPath() // d3.geo.path avec d3 version 3
.projection(projection);
d3.csv(dataCsv, function(data) {
let color = d3.scaleOrdinal(d3.schemeGreens[7])
.domain([0, 2000]);
maxValue = 0
d3.json("regions.json", function(json) {
//On fusionne les donnees avec le GeoJSON des regions
let geoGrippe = {};
for (var i = 0; i < data.length; i++) {
let dataValue= parseFloat(data[i].somme2014);
if (dataValue > maxValue) maxValue = dataValue;
geoGrippe[data[i].region] = dataValue;
}
color.domain([0, maxValue]);
svg.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("fill", function(d) {
var value = geoGrippe[d.properties.nom];
return color(value)
});
});
});
</script>
</body>
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment