-
Notifications
You must be signed in to change notification settings - Fork 12
/
mapb.html
124 lines (104 loc) · 3.78 KB
/
mapb.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<title>D3</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto+Slab" rel="stylesheet">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link href="css/fonts.css" rel="stylesheet">
<style>
.populacao, .demanda {
stroke: #fff;
stroke-width: 0.8px;
}
</style>
</head>
<body>
<div class="container">
<a href="index.html" class="sidebar-btn"><span class="icon-return"></span> Voltar</a>
<div class="header">
<div class="row">
<div class="col-xs-10">
<h2>Choropleth + dados externos</h2>
</div>
<div class="col-xs-2 text-right">
<a href="https://github.com/jeffersonrpn/d3/blob/master/map.html" target="_blank" class="btn btn-link"><span class="icon-code"></span></a>
<a href="https://bl.ocks.org/mbostock/4060606" target="_blank" class="btn btn-link"><span class="icon-link-external"></span></a>
</div>
</div>
</div>
<header>
<h1>População x PIB</h1>
</header>
<div id="chart"></div>
<div class="section">
<h3>Referências</h3>
<ul class="list-unstyled">
<li><a href="https://bl.ocks.org/mbostock/4060606" target="_blank">Exemplo base <span class="icon-link-external"></span></a></li>
</ul>
</div>
</div>
<footer></footer>
<!-- scripts -->
<script src="js/d3.v4.min.js"></script>
<script src="//d3js.org/d3-color.v1.min.js"></script>
<script src="//d3js.org/d3-scale-chromatic.v1.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var
width = 1000,
height = 500;
var svg = d3.select("#chart")
.append("svg")
.attr('version', '1.1')
.attr('viewBox', '0 0 '+width+' '+height)
.attr('width', '100%')
.attr('class', 'map-chart');
var projection = d3.geoAlbers()
.center([-36.820037, -7.195265])
.rotate([0, 0])
.parallels([0, 0])
.scale(12000);
var path = d3.geoPath().projection(projection);
var populacaoScale = d3.scaleThreshold();
var demandaScale = d3.scaleLinear();
d3.queue()
.defer(d3.json, "data/topo_pb.json")
.defer(d3.csv, "data/populacao_demanda.csv")
.await(draw);
function draw(error, pb, populacaoXdemanda) {
if (error) throw error;
var municipios = topojson.feature(pb, pb.objects.geo_pb);
populacaoScale
.domain([5000, 10000, 30000, 50000, 100000])
.range([d3.rgb(8, 48, 107, 0.2), d3.rgb(8, 48, 107, 0.4), d3.rgb(8, 48, 107, 0.6), d3.rgb(8, 48, 107, 0.8), d3.rgb(8, 48, 107, 1)]);
demandaScale
.domain([d3.min(populacaoXdemanda, function(d) { return +d.demanda }), d3.max(populacaoXdemanda, function(d) { return +d.demanda })])
.range(d3.schemeOranges[9]);
svg.selectAll(".municipios")
.data(municipios.features)
.enter().append("path")
.attr("id", function(d) { return "populacao-"+d.properties.codigo_ibg; })
.attr("d", path)
.style("opacity", 0.5);
svg.selectAll(".municipios")
.data(municipios.features)
.enter().append("path")
.attr("id", function(d) { return "demanda-"+d.properties.codigo_ibg; })
.attr("d", path)
.style("opacity", 0.5);
for (var i = 0; i < populacaoXdemanda.length; i++) {
svg.select("#populacao-"+populacaoXdemanda[i].id)
.attr("fill", populacaoScale(+populacaoXdemanda[i].populacao));
svg.select("#demanda-"+populacaoXdemanda[i].id)
.attr("fill", demandaScale(+populacaoXdemanda[i].demanda));
}
}
</script>
</body>
</html>