Carte chômage Canada
This file contains hidden or 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
nom | rate | id | |
---|---|---|---|
Terre-Neuve-et-Labrador | 11.0 | TNL | |
Île-du-Prince-Édouard | 8.5 | IPE | |
Nouvelle-Écosse | 8.5 | NE | |
Nouveau-B | 9.8 | NB | |
Québec | 8.2 | QC | |
Ontario | 7.6 | ON | |
Manitoba | 7.1 | MB | |
Saskatchewan | 6.0 | SK | |
Alberta | 6.6 | AB | |
Colombie-Britannique | 6.3 | CB |
This file contains hidden or 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"> | |
<style> | |
/*.counties { | |
fill: none; | |
}*/ | |
.provinces { | |
fill: none; | |
stroke: #bebebe; | |
/* stroke-linejoin: round; | |
*/} | |
.d3-tip { | |
line-height: 1; | |
font-weight: normal; | |
font-family: Arial; | |
padding: 5px; | |
background-color: rgba(255,255,255,0.5); | |
color: black; | |
border-radius: 4px; | |
font-size: 11px; | |
margin-left: 10px; | |
margin-top: 10px; | |
width:200px; | |
border: 1px solid #ccc; | |
} | |
.q0-9 { fill:rgb(247,251,255); } | |
.q1-9 { fill:rgb(222,235,247); } | |
.q2-9 { fill:rgb(198,219,239); } | |
.q3-9 { fill:rgb(158,202,225); } | |
.q4-9 { fill:rgb(107,174,214); } | |
.q5-9 { fill:rgb(66,146,198); } | |
.q6-9 { fill:rgb(33,113,181); } | |
.q7-9 { fill:rgb(8,81,156); } | |
.q8-9 { fill:rgb(8,48,107); } | |
</style> | |
<body> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-legend/1.3.0/d3-legend.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3-tip/0.6.7/d3-tip.min.js"></script> | |
<script src="http://d3js.org/queue.v1.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/1.6.19/topojson.min.js"></script> | |
<script> | |
var width = 635, | |
height = 357; | |
var rateById = d3.map(); | |
var quantize = d3.scale.quantize() | |
.domain([0, 11]) | |
.range(d3.range(9).map(function(i) { return "q" + i + "-9"; })); | |
// var projection = d3.geo.albers() | |
// .scale(600) | |
// .center([7, 55.4]) | |
// .translate([width / 2, height / 2]); | |
var projection = d3.geo.conicConformal() | |
.scale(700) | |
.center([7, 57.4]) | |
.rotate([100, 0]) | |
// .parallels([50, 60]) | |
.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); | |
queue() | |
.defer(d3.json, "provincesCanada.json") | |
.defer(d3.csv, "data.csv", function(d) { rateById.set(d.id, +d.rate); | |
console.log(d.rate) }) | |
.await(ready); | |
var tip = d3.tip() | |
.attr('class', 'd3-tip') | |
.offset([-10, 0]) | |
.html(function(d) { | |
return "<strong>Province</strong> : " + d.properties.nom + "<br/><strong>Taux de chômage</strong> : " + rateById.get(d.id); | |
// + "\t" | |
// + year.values + "</strong><br/><span style='color:#fff'>" + value.values + " députés élus" | |
}) | |
svg.call(tip) | |
function ready(error, canada) //définir nom de fonction qui va conditionner l'Appel geojson canada.objects....) | |
{ | |
if (error) throw error; | |
svg.append("g") | |
.attr("class", "counties") | |
.selectAll("path") | |
.data(topojson.feature(canada, canada.objects.provincesCanada).features) | |
.enter().append("path") | |
.attr("class", function(d) { return quantize(rateById.get(d.id)); }) // faudrait mettre un if else pour ne pas afficher territoires... | |
.attr("d", path) | |
.on('mouseover', tip.show) | |
.on('mouseout', tip.hide) | |
// .on('mouseover', function(d, i) { | |
// tip.show(d,i) | |
// .style("top", (50)+"px").style("left",(0)+"px") | |
// }) | |
// .on('mouseout', function(d, i) { | |
// tip.hide(d,i); | |
// }) | |
; | |
svg.append("path") | |
.datum(topojson.mesh(canada, canada.objects.provincesCanada, function(a, b) { return a !== b; })) | |
.attr("class", "provinces") | |
.attr("d", path); | |
} | |
d3.select(self.frameElement).style("height", height + "px"); | |
</script> | |
</body> | |
</html> |
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