index.html
<!DOCTYPE html>
<html>
<head>
<title>Slovak presidential election 2014 - 2nd round</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Slovak presidential election 2014 - 2nd round</a>
</div>
</div>
</div>
<div style="position:fixed;top:50px;z-index:1000;">
<div class="alert alert-info" >The <strong>size</strong> of bubbles represents number of voters, the <strong>color</strong> represents the winner and <strong>opacity</strong> margin of victory. <strong><span style="color:#00f">Kiska</span></strong> vs. <strong><span style="color:#f00">Fico</span></strong></div>
</div>
<div id="map" style="margin-top:40px;"></div>
<script type="text/javascript">
var map = L.map('map',{zoomControl: false}).setView([48.695493,19.467773], 8);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_fico_kiska_short.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.winner_class == 'kiska') color = "#00f";
else color = "#f00";
value.population = 0;
for (k=0;k<value.votes.length;k++)
value.population = value.population+parseFloat(value.votes[k]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp + "% (" + tuples[i][1].toLocaleString() +")<br>";
}
if (value.population > 20000) weight = 2;
else if (value.population > 3000) weight = 1;
else weight = 0.5;
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: color,
fillColor: color,
fillOpacity:
2.86*(Math.max(parseInt(value.votes[0]),parseInt(value.votes[1])) / value.population - 0.5),
weight: weight,
}).addTo(map);
circle.bindPopup(description);
});
});
</script>
</body>
</html>
index6.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
<div id="map"></div>
<script type="text/javascript">
var amax = Array(255,0,0);
var bmax = Array(0,0,255);
var map = L.map('map',{zoomControl: false}).setView([48.695493,19.467773], 7);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_fico_kiska_short.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.winner_class == 'kiska') color = "#00f";
else color = "#f00";
value.population = 0;
for (k=0;k<value.votes.length;k++)
value.population = value.population+parseFloat(value.votes[k]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp + "% (" + tuples[i][1].toLocaleString() +")<br>";
}
if (value.population > 20000) weight = 2;
else if (value.population > 3000) weight = 1;
else weight = 0.5;
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: data.colors[value.winner_class],
fillColor: values2color(parseInt(value.votes[0]),parseInt(value.votes[1])),
fillOpacity: 0.8,
weight: weight,
}).addTo(map);
circle.bindPopup(description);
});
});
function values2color(a,b) {
color = Array();
if (a >= b)
return val2col(1-(2*b/(a+b)),amax);
else
return val2col(1-(2*a/(a+b)),bmax);
}
function val2col(r,c) {
white = [255,255,255];
col = Array();
for (i=0;i<=2;i++) {
col[i] = Math.round(white[i] + r * (c[i] - white[i]));
}
return "rgb(" + col[0] + "," + col[1] + "," + col[2] + ")";
}
</script>
index6ba.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
<div id="map"></div>
<script type="text/javascript">
var amax = Array(255,0,0);
var bmax = Array(0,0,255);
var map = L.map('map',{zoomControl: false}).setView([48.123018,17.065659], 11);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_fico_kiska_ba_short.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.winner_class == 'kiska') color = "#00f";
else color = "#f00";
value.population = 0;
for (k=0;k<value.votes.length;k++)
value.population = value.population+parseFloat(value.votes[k]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp + "% (" + tuples[i][1].toLocaleString() +")<br>";
}
if (value.population > 2000) weight = 2;
else if (value.population > 300) weight = 1;
else weight = 0.5;
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*150), {
color: data.colors[value.winner_class],
fillColor: values2color(parseInt(value.votes[0]),parseInt(value.votes[1])),
fillOpacity: 0.8,
weight: weight,
}).addTo(map);
circle.bindPopup(description);
});
});
function values2color(a,b) {
color = Array();
if (a >= b)
return val2col(1-(2*b/(a+b)),amax);
else
return val2col(1-(2*a/(a+b)),bmax);
}
function val2col(r,c) {
white = [255,255,255];
col = Array();
for (i=0;i<=2;i++) {
col[i] = Math.round(white[i] + r * (c[i] - white[i]));
}
return "rgb(" + col[0] + "," + col[1] + "," + col[2] + ")";
}
</script>
index6fico.html
<!DOCTYPE html>
<html>
<head>
<title>Slovak presidential election 2014 - 2nd round gains against 1st round</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Slovak presidential election 2014 - 2nd round - "Tady je Ficovo"</a>
</div>
</div>
</div>
<div style="position:relative;top:50px;z-index:1000;">
<div class="alert alert-info" >The <strong>size</strong> of bubbles represents number of voters that a candidate gained against the other with respect to their results in the 1st round, the <strong>color</strong> represents the winner. Places, where <strong><span style="color:#f00">Fico</span> won</strong></div>
</div>
<div id="map"></div>
<script type="text/javascript">
var amax = Array(255,0,0);
var bmax = Array(0,0,255);
var map = L.map('map',{zoomControl: false}).setView([48.695493,19.467773], 7);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_fico_kiska_short.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.winner_class == 'kiska') color = "#00f";
else color = "#f00";
value.population = 0;
for (k=0;k<value.votes.length;k++)
value.population = value.population+parseFloat(value.votes[k]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp + "% (" + tuples[i][1].toLocaleString() +")<br>";
}
if (value.population > 20000) weight = 2;
else if (value.population > 3000) weight = 1;
else weight = 0.5;
if (parseInt(value.votes[0])>parseInt(value.votes[1])){
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: data.colors[value.winner_class],
fillColor: values2color(parseInt(value.votes[0]),parseInt(value.votes[1])),
fillOpacity: 0.8,
weight: weight,
}).addTo(map);
circle.bindPopup(description);
}
});
});
function values2color(a,b) {
color = Array();
if (a >= b)
return val2col(1-(2*b/(a+b)),amax);
else
return val2col(1-(2*a/(a+b)),bmax);
}
function val2col(r,c) {
white = [255,255,255];
col = Array();
for (i=0;i<=2;i++) {
col[i] = Math.round(white[i] + r * (c[i] - white[i]));
}
return "rgb(" + col[0] + "," + col[1] + "," + col[2] + ")";
}
</script>
</body>
</html>
index6ke.html
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
<div id="map"></div>
<script type="text/javascript">
var amax = Array(255,0,0);
var bmax = Array(0,0,255);
var map = L.map('map',{zoomControl: false}).setView([48.73989,21.262436], 11);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_fico_kiska_ke_short.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.winner_class == 'kiska') color = "#00f";
else color = "#f00";
value.population = 0;
for (k=0;k<value.votes.length;k++)
value.population = value.population+parseFloat(value.votes[k]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp + "% (" + tuples[i][1].toLocaleString() +")<br>";
}
if (value.population > 2000) weight = 2;
else if (value.population > 300) weight = 1;
else weight = 0.5;
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*150), {
color: data.colors[value.winner_class],
fillColor: values2color(parseInt(value.votes[0]),parseInt(value.votes[1])),
fillOpacity: 0.8,
weight: weight,
}).addTo(map);
circle.bindPopup(description);
});
});
function values2color(a,b) {
color = Array();
if (a >= b)
return val2col(1-(2*b/(a+b)),amax);
else
return val2col(1-(2*a/(a+b)),bmax);
}
function val2col(r,c) {
white = [255,255,255];
col = Array();
for (i=0;i<=2;i++) {
col[i] = Math.round(white[i] + r * (c[i] - white[i]));
}
return "rgb(" + col[0] + "," + col[1] + "," + col[2] + ")";
}
</script>
index6kiska.html
<!DOCTYPE html>
<html>
<head>
<title>Slovak presidential election 2014 - 2nd round gains against 1st round</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Slovak presidential election 2014 - 2nd round - "Tady je Kiskovo"</a>
</div>
</div>
</div>
<div style="position:relative;top:50px;z-index:1000;">
<div class="alert alert-info" >The <strong>size</strong> of bubbles represents number of voters that a candidate gained against the other with respect to their results in the 1st round, the <strong>color</strong> represents the winner. Places, where <strong><span style="color:#00f">Kiska</span> won</strong></div>
</div>
<div id="map"></div>
<script type="text/javascript">
var amax = Array(255,0,0);
var bmax = Array(0,0,255);
var map = L.map('map',{zoomControl: false}).setView([48.695493,19.467773], 7);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_fico_kiska_short.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.winner_class == 'kiska') color = "#00f";
else color = "#f00";
value.population = 0;
for (k=0;k<value.votes.length;k++)
value.population = value.population+parseFloat(value.votes[k]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([key,parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
tmp = Math.round(parseInt(tuples[i][1]) / parseInt(value.population) * 100);
description += data.people[tuples[i][0]] + ": " + tmp + "% (" + tuples[i][1].toLocaleString() +")<br>";
}
if (value.population > 20000) weight = 2;
else if (value.population > 3000) weight = 1;
else weight = 0.5;
if (parseInt(value.votes[0])<parseInt(value.votes[1])){
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: data.colors[value.winner_class],
fillColor: values2color(parseInt(value.votes[0]),parseInt(value.votes[1])),
fillOpacity: 0.8,
weight: weight,
}).addTo(map);
circle.bindPopup(description);
}
});
});
function values2color(a,b) {
color = Array();
if (a >= b)
return val2col(1-(2*b/(a+b)),amax);
else
return val2col(1-(2*a/(a+b)),bmax);
}
function val2col(r,c) {
white = [255,255,255];
col = Array();
for (i=0;i<=2;i++) {
col[i] = Math.round(white[i] + r * (c[i] - white[i]));
}
return "rgb(" + col[0] + "," + col[1] + "," + col[2] + ")";
}
</script>
</body>
</html>
index7.html
<!DOCTYPE html>
<html>
<head>
<title>Slovak presidential election 2014 - 2nd round - turnout</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Slovak presidential election 2014 - 2nd round - turnout</a>
</div>
</div>
</div>
<div style="position:fixed;top:50px;z-index:1000;">
<div class="alert alert-info" >The <strong>size</strong> of bubbles represents number of voters, the <strong>color</strong> and <strong>opacity</strong> represents the turnout. <strong><span style="color:#080">More than 50%</span></strong> vs. <strong><span style="color:#f00">less than 50%</span></strong></div>
</div>
<div id="map"></div>
<script type="text/javascript">
var amax = Array(255,0,0);
var bmax = Array(0,0,255);
var map = L.map('map',{zoomControl: false}).setView([48.695493,19.467773], 7);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_ucast.json", function (data) {
$.each(data.votes, function (index, value) {
rate = parseInt(value.votes[0])/parseInt(value.votes[1])
if (rate >= 0.5) { color = "#080"; colrgb = [0,128,0];}
else {color = "#f00"; colrgb = [255,0,0];}
value.population = value.votes[0];
description = "<strong>" + value.town + "</strong><br>";
tmp = Math.round(rate * 100);
description += "Turnout: " + tmp + "% (" + parseInt(value.votes[0]).toLocaleString() +" / " + parseInt(value.votes[1]).toLocaleString() + ")<br>";
if (value.population > 20000) weight = 2;
else if (value.population > 3000) weight = 1;
else weight = 0.5;
rateadj = Math.min((Math.abs(rate-0.5))*5,1);
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*2000), {
color: color,
fillColor: val2col(rateadj,colrgb),
fillOpacity: 0.8,
weight: weight,
}).addTo(map);
circle.bindPopup(description);
});
});
function values2color(a,b) {
color = Array();
if (a >= b)
return val2col(1-(2*b/(a+b)),amax);
else
return val2col(1-(2*a/(a+b)),bmax);
}
function val2col(r,c) {
white = [255,255,255];
col = Array();
for (i=0;i<=2;i++) {
col[i] = Math.round(white[i] + r * (c[i] - white[i]));
}
return "rgb(" + col[0] + "," + col[1] + "," + col[2] + ")";
}
</script>
</body>
</html>
index8.html
<!DOCTYPE html>
<html>
<head>
<title>Slovak presidential election 2014 - 2nd round gains against 1st round</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
L_PREFER_CANVAS = true;
</script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="//cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.leaflet-tile-pane {
opacity: .3
}
.leaflet-container {
background-color: #fff;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Slovak presidential election 2014 - 2nd round gains against 1st round</a>
</div>
</div>
</div>
<div style="position:fixed;top:50px;z-index:1000;">
<div class="alert alert-info" ><strong>"How the voters of the other candidates and the non-voters from the 1st round voted?" </strong><br/>The <strong>size</strong> of bubbles represents number of voters that a candidate gained against the other with respect to their results in the 1st round, the <strong>color</strong> represents the winner. <strong><span style="color:#00f">Kiska</span></strong> vs. <strong><span style="color:#f00">Fico</span></strong></div>
</div>
<div id="map" style="margin-top:40px;"></div>
<script type="text/javascript">
var map = L.map('map',{zoomControl: false}).setView([48.695493,19.467773], 8);
map.addControl( L.control.zoom({position: 'topright'}) );
L.tileLayer('//{s}.www.toolserver.org/tiles/bw-mapnik/{z}/{x}/{y}.png', {
attribution: '© <a href="//osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
$.getJSON( "sk_president_2014_2_transf.json", function (data) {
$.each(data.votes, function (index, value) {
if (value.votes[0] > value.votes[1]) color = data.colors[0];
else color = data.colors[1];
value.population = Math.abs(value.votes[0] - value.votes[1]);
description = "<strong>" + value.town + "</strong><br>";
tuples = [];
for (var key in value.votes) {
tuples.push([parseInt(key),parseInt(value.votes[key])]);
}
tuples.sort(function(a, b) {
a = a[1];
b = b[1];
return a < b ? 1 : (a > b ? -1 : 0);
});
for (i = 0; i <= 1; i++) {
description += data.people[tuples[i][0]] + ": +"+ tuples[i][1].toLocaleString() +"<br>";
}
circle = L.circle([value.lat, value.lng], Math.sqrt(parseInt(value.population)*3500), {
color: color,
fillColor: color,
fillOpacity: 0.8,
weight: 0.01,
}).addTo(map);
circle.bindPopup(description);
});
});
</script>
</body>
</html>
index9.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<script src="//code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="//maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="//mbostock.github.com/d3/d3.js?1.29.1"></script>
<style type="text/css">
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.stations, .stations svg {
position: absolute;
}
.stations svg {
width: 500px;
height: 500px;
padding-right: 100px;
font: 10px sans-serif;
}
.stations circle {
fill: #888;
fill-opacity: 0.01;
stroke-opacity: 0.75;
}
.kiska {
stroke: #00f;
color: #00f;
fill: #00f;
}
.fico {
stroke: #f00;
color: #f00;
fill: #f00;
}
div.tooltip
{
position: absolute;
text-align: center;
width: 140px;
height: 25px;
padding: 8px;
font: 10px sans-serif;
background: #ffff99;
border: solid 1px #aaa;
border-radius: 8px;
pointer-events: none;
}
img[draggable=false] {
opacity: 0.4;
}
</style>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">Slovak presidential election 2014 - 2nd round</a>
</div>
</div>
</div>
<div style="position:fixed;top:50px;z-index:1000;">
<div class="alert alert-info" >The <strong>size</strong> of bubbles represents number of voters, the <strong>color</strong> represents the winner and the <strong>ring width</strong> represents the margin of victory. <strong><span style="color:#00f">Kiska</span></strong> vs. <strong><span style="color:#f00">Fico</span></strong></div>
</div>
<div id="map"></div>
<script type="text/javascript">
var map = new google.maps.Map(d3.select("#map").node(), {
zoom: 8,
center: new google.maps.LatLng(48.695493,19.467773),
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var radiusScale = d3.scale.sqrt().domain([0, 250000]).range([0, 100]);
var div = d3.select("body").append("div")
.attr("class", "tooltip")
.style("opacity", 1e-6);
d3.json("sk_president_2014_2_fico_kiska.json", function(data) {
var overlay = new google.maps.OverlayView();
var marker;
overlay.onAdd = function() {
var layer = d3.select(this.getPanes().overlayLayer).append("div")
.attr("class", "stations");
overlay.draw = function() {
var projection = this.getProjection(),
padding = 200;
marker = layer.selectAll("svg")
.data(d3.entries(data.votes))
.each(transform)
.enter().append("svg:svg")
.each(transform);
marker.append("svg:circle")
.attr("r", function(d) {
return (radiusScale(parseInt(d.value.votes[0]))+radiusScale(parseInt(d.value.votes[1])))/2 * Math.pow(map.getZoom(),3) / 729;
})
.attr("stroke-width", function(d) {
return Math.abs(radiusScale(parseInt(d.value.votes[0]))-radiusScale(parseInt(d.value.votes[1]))) * Math.pow(map.getZoom(),3) / 729;
})
.attr("class", function(d) {return "marker" + ' ' + d.value.winner_class})
.attr("cx", padding)
.attr("cy", padding)
.attr("title", function(d) {d.value.town + ': ' + d.value.winner + ' vyhrál ' + Math.max(parseInt(d.value.votes[1]),parseInt(d.value.votes[0])) + ':' + Math.min(parseInt(d.value.votes[0]),parseInt(d.value.votes[1])) })
;
function transform(d) {
d = new google.maps.LatLng(d.value.lat, d.value.lng);
d = projection.fromLatLngToDivPixel(d);
return d3.select(this)
.style("left", (d.x - padding) + "px")
.style("top", (d.y - padding) + "px");
}
};
};
overlay.setMap(map);
google.maps.event.addListener(map, 'zoom_changed', function() {
zoomit();
function zoomit() {
d3.selectAll("circle").each(function(d,i) {
$(this)
.attr("r", function(d) {
return (radiusScale(parseInt(d.value.votes[0]))+radiusScale(parseInt(d.value.votes[1])))/2 * Math.pow(map.getZoom(),3) / 729;
})
.attr("stroke-width", function(d) {
return Math.abs(radiusScale(parseInt(d.value.votes[0]))-radiusScale(parseInt(d.value.votes[1]))) * Math.pow(map.getZoom(),3) / 729;
})
})
}
})
});
</script>
</body>
</html>
sk_president_2014_2_fico_kiska_ba_short.json
{"votes": [{"town": "Bratislava - Petr\u017ealka", "votes": ["14659", "40633"], "lat": 48.111, "lng": 17.112, "winner_class": "kiska", "id": "9"}, {"town": "Bratislava - Ru\u017einov", "votes": ["10645", "29797"], "lat": 48.158, "lng": 17.163, "winner_class": "kiska", "id": "13"}, {"town": "Bratislava - Star\u00e9 Mesto", "votes": ["5260", "19591"], "lat": 48.149, "lng": 17.108, "winner_class": "kiska", "id": "14"}, {"town": "Bratislava - Nov\u00e9 Mesto", "votes": ["5535", "16157"], "lat": 48.167, "lng": 17.137, "winner_class": "kiska", "id": "8"}, {"town": "Bratislava - Karlova Ves", "votes": ["4412", "14685"], "lat": 48.159, "lng": 17.052, "winner_class": "kiska", "id": "6"}, {"town": "Bratislava - D\u00fabravka", "votes": ["5204", "12177"], "lat": 48.189, "lng": 17.029, "winner_class": "kiska", "id": "4"}, {"town": "Bratislava - Ra\u010da", "votes": ["3520", "7363"], "lat": 48.212, "lng": 17.155, "winner_class": "kiska", "id": "11"}, {"town": "Bratislava - Podunajsk\u00e9 Biskupice", "votes": ["2708", "7727"], "lat": 48.125, "lng": 17.211, "winner_class": "kiska", "id": "10"}, {"town": "Bratislava - Vraku\u0148a", "votes": ["2370", "6557"], "lat": 48.142, "lng": 17.213, "winner_class": "kiska", "id": "16"}, {"town": "Bratislava - Dev\u00ednska Nov\u00e1 Ves", "votes": ["1957", "6422"], "lat": 48.211, "lng": 16.973, "winner_class": "kiska", "id": "3"}, {"town": "Bratislava - Lama\u010d", "votes": ["1201", "2792"], "lat": 48.194, "lng": 17.047, "winner_class": "kiska", "id": "7"}, {"town": "Bratislava - Vajnory", "votes": ["665", "1884"], "lat": 48.203, "lng": 17.205, "winner_class": "kiska", "id": "15"}, {"town": "Bratislava - Z\u00e1horsk\u00e1 Bystrica", "votes": ["551", "1589"], "lat": 48.242, "lng": 17.039, "winner_class": "kiska", "id": "17"}, {"town": "Bratislava - Rusovce", "votes": ["342", "1541"], "lat": 48.056, "lng": 17.145, "winner_class": "kiska", "id": "12"}, {"town": "Bratislava - Jarovce", "votes": ["208", "954"], "lat": 48.065, "lng": 17.114, "winner_class": "kiska", "id": "5"}, {"town": "Bratislava - Dev\u00edn", "votes": ["210", "545"], "lat": 48.174, "lng": 16.984, "winner_class": "kiska", "id": "2"}, {"town": "Bratislava - \u010cunovo", "votes": ["125", "587"], "lat": 48.031, "lng": 17.199, "winner_class": "kiska", "id": "1"}], "colors": {"kiska": "#00f", "fico": "#f00"}, "people": ["Fico", "Kiska"]}
sk_president_2014_2_fico_kiska_ke_short.json
{"votes": [{"town": "Ko\u0161ice - Z\u00e1pad", "votes": ["5556", "11377"], "lat": 48.714, "lng": 21.235, "winner_class": "kiska", "id": "2487"}, {"town": "Ko\u0161ice - Dargovsk\u00fdch hrdinov", "votes": ["3157", "6889"], "lat": 48.744, "lng": 21.277, "winner_class": "kiska", "id": "2467"}, {"town": "Ko\u0161ice - S\u00eddlisko KVP", "votes": ["2458", "7427"], "lat": 48.716, "lng": 21.215, "winner_class": "kiska", "id": "2480"}, {"town": "Ko\u0161ice - Juh", "votes": ["3109", "6728"], "lat": 48.709, "lng": 21.257, "winner_class": "kiska", "id": "2469"}, {"town": "Ko\u0161ice - Nad jazerom", "votes": ["3258", "6113"], "lat": 48.689, "lng": 21.284, "winner_class": "kiska", "id": "2476"}, {"town": "Ko\u0161ice - Star\u00e9 Mesto", "votes": ["2422", "6860"], "lat": 48.722, "lng": 21.257, "winner_class": "kiska", "id": "2482"}, {"town": "Ko\u0161ice - Sever", "votes": ["2305", "6494"], "lat": 48.737, "lng": 21.246, "winner_class": "kiska", "id": "2479"}, {"town": "Ko\u0161ice - S\u00eddlisko \u0164ahanovce", "votes": ["1903", "6530"], "lat": 48.754, "lng": 21.268, "winner_class": "kiska", "id": "2481"}, {"town": "Ko\u0161ice - \u0160aca", "votes": ["1032", "987"], "lat": 48.637, "lng": 21.171, "winner_class": "fico", "id": "2483"}, {"town": "Ko\u0161ice - Barca", "votes": ["505", "1109"], "lat": 48.663, "lng": 21.241, "winner_class": "kiska", "id": "2466"}, {"town": "Ko\u0161ice - Kr\u00e1sna", "votes": ["474", "1081"], "lat": 48.673, "lng": 21.319, "winner_class": "kiska", "id": "2472"}, {"town": "Ko\u0161ice - Ko\u0161ick\u00e1 Nov\u00e1 Ves", "votes": ["325", "711"], "lat": 48.733, "lng": 21.298, "winner_class": "kiska", "id": "2471"}, {"town": "Ko\u0161ice - Myslava", "votes": ["298", "691"], "lat": 48.709, "lng": 21.205, "winner_class": "kiska", "id": "2475"}, {"town": "Ko\u0161ice - Vy\u0161n\u00e9 Op\u00e1tske", "votes": ["221", "717"], "lat": 48.716, "lng": 21.28, "winner_class": "kiska", "id": "2486"}, {"town": "Ko\u0161ice - Pere\u0161", "votes": ["175", "607"], "lat": 48.689, "lng": 21.212, "winner_class": "kiska", "id": "2477"}, {"town": "Ko\u0161ice - \u0164ahanovce", "votes": ["193", "565"], "lat": 48.757, "lng": 21.255, "winner_class": "kiska", "id": "2485"}, {"town": "Ko\u0161ice - Kave\u010dany", "votes": ["154", "390"], "lat": 48.775, "lng": 21.206, "winner_class": "kiska", "id": "2470"}, {"town": "Ko\u0161ice - Po\u013eov", "votes": ["129", "344"], "lat": 48.665, "lng": 21.194, "winner_class": "kiska", "id": "2478"}, {"town": "Ko\u0161ice - \u0160ebastovce", "votes": ["100", "200"], "lat": 48.655, "lng": 21.27, "winner_class": "kiska", "id": "2484"}, {"town": "Ko\u0161ice - Lorin\u010d\u00edk", "votes": ["71", "188"], "lat": 48.688, "lng": 21.195, "winner_class": "kiska", "id": "2473"}, {"town": "Ko\u0161ice - Lun\u00edk IX", "votes": ["19", "203"], "lat": 48.697, "lng": 21.222, "winner_class": "kiska", "id": "2474"}, {"town": "Ko\u0161ice - D\u017eung\u013ea", "votes": ["87", "113"], "lat": 48.737, "lng": 21.268, "winner_class": "kiska", "id": "2468"}], "colors": {"kiska": "#00f", "fico": "#f00"}, "people": ["Fico", "Kiska"]}