-
Notifications
You must be signed in to change notification settings - Fork 12
/
bubble.html
123 lines (104 loc) · 4.01 KB
/
bubble.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
<!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>
text {
font: 10px sans-serif;
text-anchor: middle;
}
</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>Bubble chart</h2>
</div>
<div class="col-xs-2 text-right">
<a href="https://github.com/jeffersonrpn/d3/blob/master/bubble.html" target="_blank" class="btn btn-link"><span class="icon-code"></span></a>
<a href="http://bl.ocks.org/mbostock/4063269" target="_blank" class="btn btn-link"><span class="icon-link-external"></span></a>
</div>
</div>
</div>
<header>
<h1>Reservatórios do semiárido brasileiro</h1>
<p><span id="count">0</span> reservatórios</p>
</header>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div id="chart"></div>
</div>
</div>
<div class="section">
<h3>Referências</h3>
<ul class="list-unstyled">
<li><a href="http://bl.ocks.org/mbostock/4063269" target="_blank">Exemplo base <span class="icon-link-external"></span></a></li>
<li><a href="https://github.com/d3/d3-scale/blob/master/README.md#schemeCategory10" target="_blank">D3 API Reference: color schemes <span class="icon-link-external"></span></a></li>
<li><a href="https://github.com/d3/d3-scale/blob/master/README.md#ordinal-scales" target="_blank">D3 API Reference: ordinal scales <span class="icon-link-external"></span></a></li>
<li><a href="https://www.stockjo.com/stocks/colours/" target="_blank">Color pallets <span class="icon-link-external"></span></a></li>
</ul>
</div>
</div>
<footer></footer>
<!-- scripts -->
<script src="js/d3.v4.min.js"></script>
<script>
var width = 1000;
var svg = d3.select("#chart")
.append("svg")
.attr('version', '1.1')
.attr('viewBox', '0 0 '+width+' '+width)
.attr('width', '100%')
.attr('class', 'bubble-chart');
var format = d3.format(",d");
// var color = d3.scaleOrdinal(['#1f77b4', '#ff7f0e', '#2ca02c', '#e377c2', '#9467bd', '#8c564b', '#d62728', '#7f7f7f', '#bcbd22', '#17becf']);
var color = d3.scaleOrdinal(d3.schemeCategory10);
var pack = d3.pack()
.size([width, width])
.padding(1.5);
d3.json("reservatorios.json", function(error, classes) {
if (error) throw error;
// Altera o tipo de dado
classes.forEach(function(d) {
d.id = +d.id;
d.value = +d.capacidade;
d.class = d.estado;
});
var root = d3.hierarchy({children: classes})
.sum(function(d) { return d.value; });
var node = svg.selectAll(".node")
.data(pack(root).leaves())
.enter().append("g")
.attr("class", "node")
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
node.append("circle")
.attr("id", function(d) { return d.data.id; })
.attr("r", function(d) { return d.r; })
.style("fill", function(d) { return color(d.data.class); });
node.append("clipPath")
.attr("id", function(d) { return "clip-" + d.data.id; })
.append("use")
.attr("xlink:href", function(d) { return "#" + d.data.id; });
node.append("text")
.attr("clip-path", function(d) { return "url(#clip-" + d.data.id + ")"; })
.selectAll("tspan")
.data(function(d) { return d.data.class; })
.enter().append("tspan")
.text(function(d) { return d; });
d3.select("#count").text(classes.length);
});
</script>
</body>
</html>