-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
58 lines (58 loc) · 1.61 KB
/
example.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
<!doctype html>
<html>
<head>
<title>Introducción a D3.js</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
d3.json('https://api.github.com/search/repositories?q=language:javascript&sort=stars&per_page=100', function (data) {
//Maximo de estrellas dadas a un repo
var maxStars = d3.max(data.items, function (item) {
return item.stargazers_count;
});
//Maximo de forks dados a un repo
var maxForks = d3.max(data.items, function (item) {
return item.forks;
});
//escala y dominio
var width = d3.scale.linear()
.domain([0, maxStars])
.range([0, 99]);
//coloreado en base al numero de forks
var background = d3.scale.linear()
.domain([0, maxForks])
.range(["#1f77b4", "#d62728"]);
d3.select('body')
.append('div')
.attr('class', 'chart')
.selectAll('div')
.data(data.items)
.enter()
.append('div')
.attr('class', 'bar')
.style('width', function (item) {
return width(item.stargazers_count) + '%';
})
.style('background-color', function (item) {
return background(item.forks);
})
.text(function (item) {
return item.name;
});
});
</script>
<style type="text/css">
.chart {
font-family: sans-serif;
}
.bar {
color: white;
height: 2em;
line-height: 2em;
padding-left: 1%;
margin-bottom: 1px;
}
</style>
</head>
<body>
</body>
</html>