-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
87 lines (80 loc) · 2.05 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Electores por Circuito en la Provincia de Córdoba</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
width: calc(100vw - (100vw - 100%));
}
nav {
display: flex;
box-sizing: border-box;
}
nav button {
border: 1px solid #038854;
background-color: #00a665;
box-sizing: border-box;
color: #FFFFFF;
cursor: pointer;
flex: 1 1 auto;
padding: 10px;
}
nav button:focus {
outline: none;
}
.activo {
border-color: transparent;
background-color: #00d984;
}
#viz {
width: 100%;
}
</style>
</head>
<body>
<nav>
<button onClick="cargar(this,2007)">2007</button>
<button onClick="cargar(this,2011)">2011</button>
<button onClick="cargar(this,2013)">2013</button>
<button onClick="cargar(this,2015)">2015</button>
<button onClick="cargar(this,2017)">2017</button>
<button class="activo" onClick="cargar(this,2019)">2019</button>
</nav>
<div id="viz"></div>
<script src="https://d3plus.org/js/d3.js"></script>
<script src="https://d3plus.org/js/d3plus.js"></script>
<script>
const viz = document.getElementById('viz');
const botones = document.getElementsByTagName('button');
const formatoNumeros = (numero, key) => {
return Math.round(numero) !== numero ? numero.toFixed(2) + "%" : numero.toLocaleString('es-AR');
};
const visualization = d3plus.viz()
.container("#viz")
.data("electores.tsv")
.type("tree_map")
.id(["Nombre Seccion", "Nombre Circuito"])
.size("Electores 2019")
.format("es_ES")
.format({ "number" : formatoNumeros})
.draw();
const limpiarClases = () => {
for (let i = 0; i < botones.length; i++) {
botones[i].classList.remove('activo');
}
}
const cargar = (boton, anio) => {
limpiarClases();
boton.classList.add('activo');
visualization
.size(`Electores ${anio}`)
.format({ "number" : formatoNumeros})
.draw();
}
</script>
</body>
</html>