-
Notifications
You must be signed in to change notification settings - Fork 12
/
bubble2.html
122 lines (103 loc) · 3.71 KB
/
bubble2.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
<!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: 2em;
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/bubble2.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#sequential-scales" target="_blank">D3 API Reference: sequential scales <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.scaleLinear();
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.volume_percentual = +d.volume_percentual;
});
var root = d3.hierarchy({children: classes}).sum(function(d) { return d.value; });
color
.domain([0, d3.max(classes, function(d) { return d.volume_percentual; })])
.range(['#C9D4F6', '#4A70E2']);
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.volume_percentual); });
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) { console.log(d); return d.data.volume_percentual+"%"; })
.enter().append("tspan")
.text(function(d) { return d; });
d3.select("#count").text(classes.length);
});
</script>
</body>
</html>