$(function() {
function fmt_amount(a) {
a*=1000000;
if (a > 1000000000) a = Math.round(a/100000000)/10 + ' bio';
else if (a > 1000000) a = Math.round(a/100000)/10 + ' mio';
else if (a > 1000) a = Math.round(a/100)/10 + ' k';
else a = Math.round(a*10)/10;
return '€ '+a;
};
function fmt_percent(a) {
return Math.round(a*10)/10 + '%';
}
var indicators = {
'gdp_ppp': ['GDP in PPP', fmt_amount],
'empl': ['Employment', fmt_percent],
'youth_unempl': ['Youth Unemployment', fmt_percent],
'lt_unempl': ['Long-term unemployment', fmt_percent],
'ren_energy': ['Renewable Energy Share', fmt_percent]
},
colorscales = [
'Oranges','Reds','Blues','Greens','Purples','Greys',
'OrRd','PuBu','BuPu','BuGn','YlOrBr','GnBu','PuRd','PuBuGn'];
$.each(indicators, function(k,v) {
$('#indicator').append('');
});
$.each(colorscales, function(i,v) {
$('#colors').append('');
});
$.ajax({
url: 'data.json',
success: function(data) {
var map, colsc, tt, i, values, prop, prop_fmt;
// make sure the map fits inside browser window
$('#map').height(Math.max(500, $(window).height()-60));
/*
* updates the map after changing display properties
*/
function updateMap() {
prop = $('#indicator').val();
prop_fmt = indicators[prop][1]
map.clear(); // remove everything from the map
// first map layer for colored fills
map.addLayer({
id: 'regions',
key: 'nuts2'
});
// populate tooltip contents
tt = {};
$.each(data, function(i,d) {
d[prop] = Number(d[prop]);
tt[d.nuts] = [d.nuts, indicators[prop][0]+': '+prop_fmt(d[prop])];
});
// initialise color scale
colsc = new chroma.ColorScale({
colors: chroma.brewer[$('#colors').val()],
limits: chroma.limits(data, $('#scaletype').val(), 9, prop)
});
// update legend
var i,v,c,r,leg = $('#legend');
leg.html('');
if ($('#scaletype').val() != 'c') {
for (i=0;i