Widget:PlaceNamesChoropleths: Difference between revisions

From International Robin Hood Bibliography
mNo edit summary
mNo edit summary
(27 intermediate revisions by the same user not shown)
Line 85: Line 85:
var cur = d.colours[i];
var cur = d.colours[i];
if (val <= cur.limit) {
if (val <= cur.limit) {
colour = cur.rgb;
colour = "#" + cur.rgb;
break;
break;
}
}
Line 166: Line 166:
d.stats = true;
d.stats = true;
w.map.prepareMap();
w.map.prepareMap();
prepareDataTable();
}).catch(err => { throw err });
}).catch(err => { throw err });
}).catch(err => { throw err });
}).catch(err => { throw err });
Line 171: Line 172:
w.map.prepareMap();
w.map.prepareMap();
}
}
};
function prepareDataTable() {
var e = window.IRHB.data.England;
var c = window.IRHB.data.counties;
var tables = '<table class="bordertable expando" id="choropleth1" style="margin-bottom:-1px;">' +
'<tbody id="england">' +
'<tr class="header"><th colspan="2">England</th><th><span class="expando-c">&#x2014;&#xa0;</span><span class="expando-o">&#x25a2;&#xa0;</span></th></tr>' +
'<tr><td>Artifact</td><td colspan="2">' + e.Artifacts + '</td></tr>' +
'<tr><td>Literary locale</td><td colspan="2">' + e["Literary locale"] + '</td></tr>' +
'<tr><td>Local tradition</td><td colspan="2">' + e["Local tradition"] + '</td></tr>' +
'<tr><td>Miscellaneous</td><td colspan="2">' + e.Miscellaneous + '</td></tr>' +
'<tr><td>Robin Hood name</td><td colspan="2">' + e["Robin Hood name"] + '</td></tr>' +
'<tr><td>Area (km<sup>2</sup>)</td><td colspan="2">' + e.area + '</td></tr>' +
'<tr><td>Population</td><td colspan="2">' + e.population + '</td></tr>' +
'<tr><td>Pop. density/km<sup>2</sup></td><td colspan="2">' + e.popdensity + '</td></tr>' +
'<tr><td>Place-names (PN)</td><td colspan="2">' + e.total + '</td></tr>' +
'<tr><td>Counties</td><td colspan="2">' + e.counties + '</td></tr>' +
'<tr><td>Km<sup>2</sup>/person</td><td colspan="2">' + e.km2perperson + '</td></tr>' +
'<tr><td>Km<sup>2</sup>/PN</td><td colspan="2">' + e.km2perpn + '</td></tr>' +
'<tr><td>PN/km<sup>2</sup></td><td colspan="2">' + e.pnperkm2 + '</td></tr>' +
'<tr><td>PN/km<sup>2</sup> idx</td><td colspan="2">' + e.pnperkm2idx + '</td></tr>' +
'<tr><td>PN/county avg.</td><td colspan="2">' + e.pnpercounty + '</td></tr>' +
'</tbody>';
var counties = Object.keys(c);
var nCounties = counties.length;
var idxLeics = 19;
for (var i = 0; i < idxLeics; i++) {
var cty = counties[i];
tables += getCountyData(cty, c[cty]);
}
tables += '</table>';
tables += '<table class="bordertable expando" id="choropleth2">';
for (var i = idxLeics; i < nCounties; i++) {
var cty = counties[i];
tables += getCountyData(cty, c[cty]);
}
tables += '</table>';
get("dSet").innerHTML = tables;
window.IRHB.expando.init();
};
function getCountyData(cty, d) {
var txt = '<tbody id="' + cty + '"><tr class="header"><th colspan="2">' + cty + '</th>' +
'<th><span class="expando-c">—&nbsp;</span><span class="expando-o">▢&nbsp;</span></th></tr>' +
'<tr><td style="width:129px;">Area (km<sup>2</sup>)</td><td colspan="2">' + d.area + '</td></tr>' +
'<tr><td>Population</td><td colspan="2">' + d.population + '</td></tr>' +
'<tr><td>Pop. density/km<sup>2</sup></td><td colspan="2">' + d.popdensity + '</td></tr>' +
'<tr><td>Km<sup>2</sup>/PN</td><td colspan="2">' + d.km2perpn + '</td></tr>' +
'<tr><td>PN/km<sup>2</sup></td><td colspan="2">' + d.pnperkm2 + '</td></tr>' +
'<tr><td>RH names</td><td colspan="2">' + d["Robin Hood name"] + '</td></tr>' +
'<tr><td>Local traditions</td><td colspan="2">' + d["Local tradition"] + '</td></tr>' +
'<tr><td>Literary locales</td><td colspan="2">' + d["Literary locale"] + '</td></tr>' +
'<tr><td>Artifacts</td><td colspan="2">' + d.Artifacts+ '</td></tr>' +
'<tr><td>Miscellaneous</td><td colspan="2">' + d.Miscellaneous + '</td></tr>' +
'<tr><td>Total count</td><td colspan="2">' + d.total + '</td></tr>' +
'<tr><td>Count idx.</td><td>' + d.totalidx + '</td><td style="background-color:' + d.totalcol + '; width:1.5em;"></td></tr>' +
'<tr><td>PN/km<sup>2</sup> idx.</td><td>' + d.pnperkm2idx + '</td><td style="background-color:' + d.pnperkm2col + '; width:1.5em;"></td></tr>' +
'<tr><td>PN/km<sup>2</sup>/pop. idx.</td><td>' + d.pnperkm2popidx + '</td><td style="background-color:' + d.pnperkm2popcol + '; width:1.5em;"></td></tr>' +
'</tbody>';
return txt;
}
}


}() );
}() );
Line 258: Line 323:
var mp = get(m.curMap);
var mp = get(m.curMap);
var width = 496, height = 550;
var width = 496, height = 550;
var projection = d3.geo.conicEqualArea()
var projection = d3.geo.conicEqualArea().scale(5165.269352442655).center([-1.4602454263940616,52.55675714793008]).parallels([49.95898294542323,55.81107189358492]).rotate([1.4602454263940616]).translate([202.798519176517,306.70813464248357]);
.scale(5165.269352442655).center([-1.4602454263940616,52.55675714793008])
.parallels([49.95898294542323,55.81107189358492]).rotate([1.4602454263940616])
.translate([202.798519176517,306.70813464248357]);
var path = d3.geo.path().projection(projection);
var path = d3.geo.path().projection(projection);
var svg = d3.select("div#" + m.curMap).append("svg").attr("width", width).attr("height", height);
var svg = d3.select("div#" + m.curMap).append("svg").attr("width", width).attr("height", height);
Line 274: Line 336:
.attr("d",path).on("mouseover",showTooltip).on("mousemove",moveTooltip)
.attr("d",path).on("mouseover",showTooltip).on("mousemove",moveTooltip)
.on("mouseout",hideTooltip).on("click",clicked);
.on("mouseout",hideTooltip).on("click",clicked);
if (m.curMap === "navMap" || m.curMap === "choroMap") {
w.choro.choropleth();
w.choro.choropleth();
}
if (mp.childNodes.length > 1) {
if (mp.childNodes.length > 1) {
mp.removeChild(mp.childNodes[0]);
mp.removeChild(mp.childNodes[0]);
Line 301: Line 361:
svg += '</path></svg>';
svg += '</path></svg>';
elem.innerHTML = svg;
elem.innerHTML = svg;
elem.firstElementChild.firstElementChild.style.strokeWidth = "0px";
};
};
Line 380: Line 441:
d.style.cursor = "pointer";
d.style.cursor = "pointer";
get("choroMap").style.backgroundColor = "#f9fafa";
get("choroMap").style.backgroundColor = "#f9fafa";
console.log("OK");
n.toggleNav();
};
};


n.toggleNav = function() {
n.toggleNav = function() {
var t = event.target.id;
get("choroMapLegend1").innerHTML = choroLegend[n.choroVar].s1;
if (t === "nmnChoro") {
get("choroMapLegend2").innerHTML = choroLegend[n.choroVar].s2;
get("choroMapLegend1").innerHTML = choroLegend[n.choroVar].s1;
get("choroMapLegend3").innerHTML = choroLegend[n.choroVar].s3;
get("choroMapLegend2").innerHTML = choroLegend[n.choroVar].s2;
get("choroMap").style.display = "block";
get("choroMapLegend3").innerHTML = choroLegend[n.choroVar].s3;
get("choroMapLegend").style.display = "block";
get("choroMap").style.display = "block";
m.curMap = "choroMap";
get("choroMapLegend").style.display = "block";
m.initMap();
}
if (t === "nmnChoro") {
m.curMap = "choroMap";
}
m.initMap();
};
};



Revision as of 19:09, 7 June 2019

This widget displays the navigation map on country and administrative division landing pages in the place-names section of IRHB. It takes no parameters.