-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheader.html
More file actions
170 lines (149 loc) · 4.61 KB
/
header.html
File metadata and controls
170 lines (149 loc) · 4.61 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Locales 2015 - Arroyomolinos de León</title>
<script src="jquery-2.1.4.min.js"></script>
<script src="Chart.js"></script>
<style type="text/css">
*{
font-family: sans-serif;
}
.legend{
float: left;
}
.legend ul{
list-style: none;
}
.legend ul li span{
width: 15px;
height: 15px;
display: block;
float: left;
border-radius: 2px;
}
@media screen and (min-width: 600px) {
.left{
float: left;
width: 50%;
}
.right{
float: right;
width: 50%;
}
}
</style>
</head>
<body>
<h1>Resultados Elecciones Municipales en Arroyomolinos de León</h1>
<h3>A partir de las 20h del 24 de mayo podrás seguir la evolución de los resultados provisionales en vivo.</h3>
<div class="left">
<h5>Votos por partidos</h5>
<div id="votos-legend" class="legend"></div>
<div id="canvas-holder">
<canvas id="votos-area" width="200" height="200"/>
</div>
</div>
<div class="right">
<h5>Composición ayuntamiento (7 concejales)</h5>
<div id="concejales-2011"></div>
<div id="concejales-legend" class="legend"></div>
<div id="canvas-holder">
<canvas id="concejales-area" width="200" height="200"/>
</div>
</div>
<script>
var PSOE = "#FF0000", PSOE_highlight = "#FF5A5E", PP = "#093EA6", PP_highlight = "#2D5DBB", Independientes = "#FDB45C", Independientes_highlight = "#FFC870", IU = "#086E08", IU_highlight = "#60A260";
var votosData = [
{
value: 1,
color:PSOE,
highlight: PSOE_highlight,
label: "PSOE"
},
{
value: 1,
color: PP,
highlight: PP_highlight,
label: "PP"
},
{
value: 1,
color: Independientes,
highlight: Independientes_highlight,
label: "Independientes"
},
{
value: 1,
color: IU,
highlight: IU_highlight,
label: "IU"
}
];
var concejalesData = [
{
value: 1,
color:PSOE,
highlight: PSOE_highlight,
label: "PSOE"
},
{
value: 1,
color: PP,
highlight: PP_highlight,
label: "PP"
},
{
value: 1,
color: Independientes,
highlight: Independientes_highlight,
label: "Independientes"
},
{
value: 1,
color: IU,
highlight: IU_highlight,
label: "IU"
}
];
window.onload = function(){
var ctx_votos = document.getElementById("votos-area").getContext("2d");
window.votosPie = new Chart(ctx_votos).Pie(votosData, {
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%> <%if(segments[i].value){%> (<%=segments[i].value%>) <%}%></li><%}%></ul>"
});
document.getElementById('votos-legend').innerHTML = window.votosPie.generateLegend();
var ctx_concejales = document.getElementById("concejales-area").getContext("2d");
window.concejalesPie = new Chart(ctx_concejales).Pie(concejalesData, {
legendTemplate : "<ul class=\"<%=name.toLowerCase()%>-legend\"><% for (var i=0; i<segments.length; i++){%><li><span style=\"background-color:<%=segments[i].fillColor%>\"></span><%if(segments[i].label){%><%=segments[i].label%><%}%> <%if(segments[i].value){%> (<%=segments[i].value%>) <%}%></li><%}%></ul>"
});
document.getElementById('concejales-legend').innerHTML = window.concejalesPie.generateLegend();
// get data server
setInterval(function(){
$.getJSON('get.php', function(data){
var votos=[], todoceros=true;
$.each( data, function( i, partido ) {
todoceros = todoceros && (partido.votos == 0);
window.votosPie.segments[i].value = partido.votos;
votos[i] = parseInt(partido.votos);
window.concejalesPie.segments[i].value = 0;
});
if (!todoceros) {
window.votosPie.update();
document.getElementById('votos-legend').innerHTML = window.votosPie.generateLegend();
var divisor=[1,1,1,1], votositerados=votos.slice(0);
for (var i = 0; i < 7; i++) {
var max = Math.max.apply(Math,votositerados);
var index = $.inArray(max, votositerados);//.indexOf(max);
window.concejalesPie.segments[index].value = window.concejalesPie.segments[index].value + 1;
divisor[index] = divisor[index] + 1;
votositerados[index] = votos[index] / divisor[index];
};
window.concejalesPie.update();
document.getElementById('concejales-legend').innerHTML = window.concejalesPie.generateLegend();
};
});
}, 3000);
};
</script>
</body>
</html>