The TopoJson of Guatemala used in this project was created by Wsvekla http://bl.ocks.org/wsvekla/4348435
Last active
August 29, 2015 13:56
-
-
Save jdonis/9093948 to your computer and use it in GitHub Desktop.
Indicadores de económicos de Guatemala, d3 and TopoJSON
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"> | |
<title>Indicadores de econónmicos de Guatemala</title> | |
<style> | |
.departamentos { | |
fill: none; | |
stroke-width: 2px; | |
} | |
.pais { | |
stroke: #fff; | |
stroke-width: 2px; | |
} | |
h1 { | |
font-size: 42px; | |
font-weight: 300; | |
letter-spacing: -2px; | |
margin: .3em 0 .1em 0; | |
line-height: 0.2em; | |
} | |
h2 { | |
font-size: 32px; | |
font-weight: 300; | |
letter-spacing: -2px; | |
margin: .3em 0 .1em 0; | |
line-height: 1.2em; | |
} | |
a { | |
color:#000; | |
cursor:pointer; | |
text-decoration:underline; | |
} | |
a:hover { | |
color:#000; | |
font-weight:bold; | |
} | |
p { | |
font-size: 12px; | |
font-weight: 300; | |
letter-spacing: -1px; | |
margin: .3em 0 .1em 0; | |
line-height: 1.2em; | |
font-family: Consolas, courier; | |
} | |
.label { | |
font-size: 10px; | |
font-family: Consolas, courier; | |
} | |
.descripcion{ | |
width: 200px; | |
height: 130px; | |
position: absolute; | |
color: #000; | |
font-size:16px; | |
border: 1px solid rgba(155, 158, 155, 0.36); | |
top: 80px; | |
left: 550px; | |
box-shadow: 6px 5px 5px rgba(136, 136, 136, 0.23); | |
padding:5px; | |
} | |
body{padding-left:30px;} | |
.q0-9 { fill:rgb(247,251,255); stroke: #fff;} | |
.q1-9 { fill:rgb(222,235,247); stroke: #fff; } | |
.q2-9 { fill:rgb(198,219,239); stroke: #fff; } | |
.q3-9 { fill:rgb(158,202,225); stroke: #fff;} | |
.q4-9 { fill:rgb(107,174,214); stroke: #fff;} | |
.q5-9 { fill:rgb(66,146,198); stroke: #fff;} | |
.q6-9 { fill:rgb(33,113,181); stroke: #fff;} | |
.q7-9 { fill:rgb(8,81,156); stroke: #fff;} | |
.q8-9 { fill:rgb(8,48,107); stroke: #fff;} | |
</style> | |
<body> | |
<h2>Indicadores económicos por departamento: <span id='actual'>Pobreza</span></h2> | |
<p> | |
<a onclick='pintar(0,0,0.99,this.innerText)'>Pobreza</a> | |
<a onclick='pintar(1,0.40,0.95,this.innerText)'>Empleo Informal</a> | |
<a onclick='pintar(2,400,2100,this.innerText)'>Mediana Ingreso</a> | |
<a onclick='pintar(3,0.10,0.25,this.innerText)'>Emprendimiento</a> | |
</p><br> | |
<p class='descripcion'></p> | |
<script src="http://alejandrodonis.com/cien/economicas/js/d3.v3.min.js"></script> | |
<script src="http://alejandrodonis.com/cien/economicas/js/queue.v1.min.js"></script> | |
<script src="http://alejandrodonis.com/cien/economicas/js/topojson.v1.min.js"></script> | |
<script> | |
var width = 500, | |
height = 500; | |
var rateById = d3.map(); | |
var quantize = d3.scale.quantize() | |
.domain([0, 0.99]) | |
.range(d3.range(9).map(function(i) { return "q" + i + "-9"; })); | |
var projection = d3.geo.mercator() | |
.center([-90.22, 15.78]) | |
.scale(6400); | |
var path = d3.geo.path() | |
.projection(projection); | |
var svg = d3.select("body").append("svg") | |
.attr("width", width) | |
.attr("height", height) | |
.attr("transform", "translate(-100,10)"); | |
queue() | |
.defer(d3.json, "guatemala.json") | |
.defer(d3.csv, "indicadores.csv", function(d) { rateById.set(d.id, [+d.Pobreza,+d.EmpleoInformal,+d.MedianaIngresos,+d.Emprendimiento,d.Departamento]); }) | |
.await(ready); | |
function ready(error, gt) { | |
svg.append("path") | |
.data(topojson.feature(gt, gt.objects.guatemala0).features) | |
.attr("d", path) | |
.attr("transform", "translate(-220,1)") | |
.attr("class", "pais"); | |
svg.append("g") | |
.attr("transform", "translate(-220,1)") | |
.attr("class", "depatamentos") | |
.selectAll("path") | |
.data(topojson.feature(gt, gt.objects.guatemala1).features) | |
.enter().append("path") | |
.attr("id",function(d) { return d.id; }) | |
.attr("title",function(d) { return rateById.get(d.id)[4]; }) | |
.attr("class", function(d) { return quantize(rateById.get(d.id)[0]); }) | |
.attr("d", path) | |
.on("mouseover",function(d){ | |
panel(d,0); | |
}); | |
svg.selectAll(".subunit-label") | |
.data(topojson.feature(gt, gt.objects.guatemala1).features) | |
.enter().append("text") | |
.attr("class","label") | |
.attr("transform", function(d) { centroide = eval("[" + path.centroid(d) + "]"); x = parseInt(centroide[0])-230; return "translate(" + x + "," + centroide[1] + ")"; }) | |
.attr("dy", ".35em") | |
.text(function(d) { return d3.round(rateById.get(d.id)[0],2) + (rateById.get(d.id)[0] < 1? "%":"");}); | |
// draw legend | |
var legend = svg.selectAll(".legend") | |
.data([0,1,2,3,4,5,6]) | |
.enter().append("g") | |
.attr("class", "legend") | |
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; }); | |
// draw legend colored rectangles | |
legend.append("rect") | |
.attr("x", width - 18) | |
.attr("width", 18) | |
.attr("height", 18) | |
.attr("class", function(d,i) { return quantize(rateById.get(i)[0]); }); | |
} | |
function panel(d,n){ | |
d3.select(".descripcion").html("<div align='center' style='padding:10px;'><b>" + rateById.get(d.id)[4] +"</b><br><br><h2>" + d3.round(rateById.get(d.id)[n],2) + (rateById.get(d.id)[n] < 1? "%":"") + "</h2></div>"); | |
} | |
function pintar(n,ini,fin,name){ | |
quantize.domain([+ini,+fin]); | |
d3.selectAll("path[id]") | |
.attr("class",function(d) { return quantize(rateById.get(d.id)[n]); }) | |
.on("mouseover",function(d){ panel(d,n)}); | |
d3.selectAll(".label") | |
.text(function(d) { return d3.round(rateById.get(d.id)[n],2) + (rateById.get(d.id)[n] < 1? "%":""); }); | |
d3.select("#actual").text(name); | |
} | |
</script> | |
<p>Ayuda: seleccione cualquiera de los diferentes indicadores para visualizar la información o pase el mouse sobre el departamento. <br>Fuente: ENCOVI, 2011 | Programación y diagramación: Alejandro Donis</p><br> |
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
id | Departamento | Pobreza | EmpleoInformal | MedianaIngresos | Emprendimiento | |
---|---|---|---|---|---|---|
7 | Huehuetenango | 0.605 | 0.9169346 | 800 | 0.15488215 | |
20 | Totonicapán | 0.7329 | 0.90657199 | 840 | 0.21513944 | |
18 | Sololá | 0.7747 | 0.89884728 | 900 | 0.17721519 | |
13 | Quiché | 0.7185 | 0.89089098 | 720 | 0.22072072 | |
0 | Alta Verapaz | 0.7824 | 0.88826643 | 800 | 0.16563659 | |
16 | San Marcos | 0.6854 | 0.88031308 | 1000 | 0.16885007 | |
12 | Quetzaltenango | 0.5373 | 0.87484873 | 1000 | 0.20742534 | |
2 | Chimaltenango | 0.6557 | 0.86052677 | 886 | 0.21467391 | |
9 | Jalapa | 0.6993 | 0.85858976 | 1050 | 0.16164818 | |
17 | Santa Rosa | 0.5777 | 0.83570483 | 1100 | 0.18855219 | |
14 | Retalhuleu | 0.5924 | 0.82564456 | 1200 | 0.18156809 | |
11 | Petén | 0.6567 | 0.82350371 | 1200 | 0.24587706 | |
3 | Chiquimula | 0.6268 | 0.81777495 | 1040 | 0.19559902 | |
1 | Baja Verapaz | 0.6401 | 0.80311918 | 840 | 0.20588235 | |
19 | Suchitepéquez | 0.7065 | 0.80220695 | 1200 | 0.16872428 | |
4 | El Progreso | 0.4105 | 0.78172445 | 1250 | 0.22863568 | |
21 | Zacapa | 0.55 | 0.77538851 | 1400 | 0.22261799 | |
10 | Jutiapa | 0.5154 | 0.77060588 | 1200 | 0.19054054 | |
15 | Sacatepéquez | 0.4127 | 0.74764313 | 1500 | 0.20806916 | |
8 | Izabal | 0.5866 | 0.74243359 | 1500 | 0.21928328 | |
5 | Escuintla | 0.3964 | 0.63350943 | 1960 | 0.18104366 | |
6 | Guatemala | 0.1864 | 0.61303811 | 2000 | 0.19648924 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment