Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/vicente'
Browse files Browse the repository at this point in the history
  • Loading branch information
Vhollow committed Jan 11, 2017
2 parents 41d681e + 3a7d216 commit a842d17
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
14 changes: 14 additions & 0 deletions SimuladorElecciones/web/simulacion/resources/grafico.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ function dibujaGraficoPequeño(circunscripcion, candidaturas, votosCircunscripci
var svg = divPequeño.append("svg")
.attr("width", dimensionesDivPequeño.width)
.attr("height", dimensionesDivPequeño.width/2);

svg.append("text")
.attr("transform", "translate(" + centro.x + ", " + centro.y + ")")
.attr("font-family", "sans-serif")
.attr("font-size", "30px")
.attr("fill", "black")
.text(circunscripcion.nombre);

var groupArcos = svg.append("g")
.attr("transform", "translate(" + centro.x + ", " + centro.y + ")");
Expand Down Expand Up @@ -102,6 +109,13 @@ function dibujaGraficoGrande(indice, circunscripciones, candidaturas, votosCircu
.attr("width", dimensionesDivGrande.width)
.attr("height", dimensionesDivGrande.width/2);

svg.append("text")
.attr("transform", "translate(" + centro.x + ", " + centro.y + ")")
.attr("font-family", "sans-serif")
.attr("font-size", "30px")
.attr("fill", "black")
.text("Total");

var groupArcos = svg.append("g")
.attr("transform", "translate(" + centro.x + ", " + centro.y + ")");

Expand Down
61 changes: 61 additions & 0 deletions SimuladorElecciones/web/simulacion/resources/paginaSimulacion.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function nuevaCandidatura() {
// Reset del texto por defecto en los botones para añadir una candidatura
formSimulacion.elements["input-candidatura-nombre"].value = "";
formSimulacion.elements["input-candidatura-color"].value = "FFFFFF";
formSimulacion.elements["input-candidatura-color"].style = "background-color: #FFFFFF";
}


Expand Down Expand Up @@ -304,6 +305,7 @@ function inicioSimulacion() {

dibujaGraficoPequeño(circunscripciones[0],candidaturas, votos[0], propMinRepresentacion);
dibujaGraficoGrande(0, circunscripciones, candidaturas, votos, propMinRepresentacion);
actualizarTablaResultados();
}

function avanzarSimulacion() {
Expand All @@ -317,24 +319,31 @@ function avanzarSimulacion() {

dibujaGraficoPequeño(circunscripciones[indiceSimulacion],candidaturas, votos[indiceSimulacion], propMinRepresentacion);
dibujaGraficoGrande(indiceSimulacion, circunscripciones, candidaturas, votos, propMinRepresentacion);
actualizarTablaResultados();
}

function retrocederSimulacion() {
indiceSimulacion--;
document.getElementById("boton-avance").disabled = false;
document.getElementById("boton-avance-fin").disabled = false;

if (indiceSimulacion === 0) {
document.getElementById("boton-retroceso").disabled = true;
}

dibujaGraficoPequeño(circunscripciones[indiceSimulacion], candidaturas, votos[indiceSimulacion], propMinRepresentacion);
dibujaGraficoGrande(indiceSimulacion, circunscripciones, candidaturas, votos, propMinRepresentacion);
actualizarTablaResultados();
}

function avanzarFinSimulacion() {
indiceSimulacion = circunscripciones.length - 1;
document.getElementById("boton-retroceso").disabled = false;
document.getElementById("boton-avance").disabled = true;
document.getElementById("boton-avance-fin").disabled = true;
dibujaGraficoPequeño(circunscripciones[indiceSimulacion],candidaturas, votos[indiceSimulacion], propMinRepresentacion);
dibujaGraficoGrande(indiceSimulacion, circunscripciones, candidaturas, votos, propMinRepresentacion);
actualizarTablaResultados();
}

function finalizarSimulacion() {
Expand All @@ -345,4 +354,56 @@ function finalizarSimulacion() {
document.getElementById("boton-detener").style.display = "none";
document.getElementById("charts1").style.display = "none";
document.getElementById("charts2").style.display = "none";
document.getElementById("tabla-resultados").style.display = "none";
}

function actualizarTablaResultados(){
var datos = new Array(candidaturas.length);
for (var i = 0; i < candidaturas.length; i++) {
datos[i] = { candidatura: candidaturas[i], numeroEscaños: 0 };
}

for(var i = 0 ; i <= indiceSimulacion; i++){
// Calculamos los escaños en la circunscripcion actual
var datosTemp = calculaEscaños(circunscripciones[i], candidaturas, votos[i], propMinRepresentacion);

// Añadimos los escaños de la circunscripcion a su respectiva candidatura
for (var j = 0; j < datos.length; j++) {
for (var k = 0; k < datosTemp.length; k++) {
if (datos[j].candidatura === datosTemp[k].candidatura) {
datos[j].numeroEscaños += datosTemp[k].numeroEscaños;
k = datos.length;
}
}
}
}

// Header
var head = document.createElement("thead");
var row = document.createElement("tr");
for (var j = 0 ; j < candidaturas.length ; j++){
var th = document.createElement("th");
th.innerHTML = candidaturas[j].nombreCorto;
th.style = "background-color: #" + candidaturas[j].color;
row.appendChild(th);
}
head.appendChild(row);

// Body
var body = document.createElement("tbody");
row = document.createElement("tr");
for(var j in datos){
var td = document.createElement("td");
td.innerHTML = datos[j].numeroEscaños;
row.appendChild(td);
}
body.appendChild(row);

// Table
var tabla = document.getElementById("tabla-resultados");
while(tabla.hasChildNodes()){
tabla.removeChild(tabla.firstChild);
}
tabla.appendChild(head);
tabla.appendChild(body);
}
6 changes: 5 additions & 1 deletion SimuladorElecciones/web/simulacion/simulacion.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<p class="titulo">Cargar archivo</p>
<div class="form-horizontal col-md-10">
<div class="form-group">
<select class="form-control">
<select class="form-control" disabled>
<option>-</option>
<option>Elecciones España junio 2016</option>
<option>2</option>
Expand Down Expand Up @@ -209,6 +209,10 @@
<div class="row">
<div class="col-md-8 col-md-offset-4" id="charts2"></div>
</div>
<div class="row" style="text-align: center">
<table class="table table-bordered table-responsive" id="tabla-resultados"></table>
</div>

<button class="btn btn-primary" id="boton-inicio" type="button" onclick="inicioSimulacion()"> Iniciar </button>
<button class="btn btn-primary" id="boton-retroceso" type="button" onclick="retrocederSimulacion()" style="display:none"> < Anterior </button>
<button class="btn btn-primary" id="boton-avance" type="button" onclick="avanzarSimulacion()" style="display:none"> Siguiente > </button>
Expand Down

0 comments on commit a842d17

Please sign in to comment.