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 13: Line 13:
}() );
}() );




Line 105: Line 106:
cur.totalcol = getColour(cur.totalidx);
cur.totalcol = getColour(cur.totalidx);
cur.pnperkm2col = getColour(cur.pnperkm2idx);
cur.pnperkm2col = getColour(cur.pnperkm2idx);
cur.pnperkm2popcol = getColour(cur.pnperkm2popidx);
cur.pnperkm2PopularCollection = getColour(cur.pnperkm2popidx);
}
}
}
}
Line 139: Line 140:
var PNs = res.query.results;
var PNs = res.query.results;
for (var key in PNs) {
for (var key in PNs) {
var admdiv = PNs[key].printouts.Pnadmdiv[0];
var admdiv = PNs[key].printouts.AdministrativeDivision[0];
var interest = PNs[key].printouts.Pninterest[0];
var interest = PNs[key].printouts.PlaceNamesInterest[0];
var admdivObj = d.counties[admdiv];
var admdivObj = d.counties[admdiv];
admdivObj.total++;
admdivObj.total++;
Line 157: Line 158:
if (!d.stats) {
if (!d.stats) {
w.map.addSpinner(get(w.map.curMap));
w.map.addSpinner(get(w.map.curMap));
var url = "https://www.irhb.org/wiki/api.php?action=ask&query=[[Category:English%20counties%20with%20place-names]]|?Area|?Population&format=json";
var url = "/w/api.php?action=ask&query=[[Category:English%20counties%20with%20place-names]]|?Area|?Population&format=json";
fetch(url).then(res => res.json()).then((jsnCty) => {
fetch(url).then(res => res.json()).then((jsnCty) => {
calcCounties(jsnCty);
calcCounties(jsnCty);
url = "https://www.irhb.org/wiki/api.php?action=ask&query=[[Category:English%20place-names]]|?Pninterest|?Pnadmdiv|sort=Pnadmdiv&format=json";
url = "/w/api.php?action=ask&query=[[Category:English%20place-names]]|?PlaceNamesInterest|?AdministrativeDivision|sort=AdministrativeDivision&format=json";
fetch(url).then(res => res.json()).then((jsnPN) => {
fetch(url).then(res => res.json()).then((jsnPN) => {
calcPlaceNames(jsnPN);
calcPlaceNames(jsnPN);
Line 231: Line 232:
'<tr><td>Miscellaneous</td><td colspan="2">' + d.Miscellaneous + '</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>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>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> 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>' +  
'<tr><td>PN/km<sup>2</sup>/pop. idx.</td><td>' + d.pnperkm2popidx + '</td><td style="background-color:' + d.pnperkm2PopularCollection + '; width:1.5em;"></td></tr>' +  
'</tbody>';
'</tbody>';
return txt;
return txt;
Line 239: Line 240:


}() );
}() );




Line 260: Line 262:
for (var key in d.counties) {
for (var key in d.counties) {
var cur = d.counties[key];
var cur = d.counties[key];
paths[cur.path].style.stroke = "#ffffff";
paths[cur.path].style.strokeWidth = "0px";
}
}
} else {
} else {
Line 267: Line 269:
var cur = d.counties[key];
var cur = d.counties[key];
paths[cur.path].style.fill = cur.totalcol;
paths[cur.path].style.fill = cur.totalcol;
paths[cur.path].style.stroke = "#ffffff";
paths[cur.path].style.strokeWidth = "0px";
}
}
} else if (w.nav.choroVar === "area") {
} else if (w.nav.choroVar === "area") {
Line 273: Line 275:
var cur = d.counties[key];
var cur = d.counties[key];
paths[cur.path].style.fill = cur.pnperkm2col;
paths[cur.path].style.fill = cur.pnperkm2col;
paths[cur.path].style.stroke = "#ffffff";
paths[cur.path].style.strokeWidth = "0px";
}
}
} else {
} else {
for (var key in d.counties) {
for (var key in d.counties) {
var cur = d.counties[key];
var cur = d.counties[key];
paths[cur.path].style.fill = cur.pnperkm2popcol;
paths[cur.path].style.fill = cur.pnperkm2PopularCollection;
paths[cur.path].style.stroke = "#ffffff";
paths[cur.path].style.strokeWidth = "0px";
}
}
}
}
Line 286: Line 288:


}() );
}() );




Line 328: Line 331:
features = svg.append("g").attr("class","features");
features = svg.append("g").attr("class","features");
tooltip = d3.select("body").append("div").attr("class","ttip");
tooltip = d3.select("body").append("div").attr("class","ttip");
d3.json("/wiki/geo/england/country/England.json",function(error,geodata) {
d3.json("/w/geo/england/country/England.json",function(error,geodata) {
if (!error) {
if (!error) {
features.selectAll("path").data(geodata.features).enter().append("path")
features.selectAll("path").data(geodata.features).enter().append("path")
Line 353: Line 356:
m.addSpinner = function (elem) {
m.addSpinner = function (elem) {
var svg = '<svg version="1.1" id="L9" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">';
var svg = '<svg version="1.1" id="spinner" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">';
svg += '<path fill="#fff" d="M73,50c0-12.7-10.3-23-23-23S27,37.3,27,50 M30.9,50c0-10.5,8.5-19.1,19.1-19.1S69.1,39.5,69.1,50">';
svg += '<path fill="#fff" d="M73,50c0-12.7-10.3-23-23-23S27,37.3,27,50 M30.9,50c0-10.5,8.5-19.1,19.1-19.1S69.1,39.5,69.1,50">';
svg += '<animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="2s" from="0 50 50" to="360 50 50" repeatCount="indefinite"/>';
svg += '<animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="2s" from="0 50 50" to="360 50 50" repeatCount="indefinite"/>';
svg += '</path></svg>';
svg += '</path></svg>';
elem.innerHTML = svg;
elem.innerHTML = svg;
elem.firstElementChild.firstElementChild.style.strokeWidth = "0px";
};
};


Line 381: Line 384:
tooltip.style("display","none");
tooltip.style("display","none");
}
}
}() );
//Navigation
( function() {
window.IRHB = window.IRHB || {};
var w = window.IRHB;
w.nav = {};
var n = w.nav;
var get = w.get;
var m = w.map;
var choroLegend = {
'count': { 's1': 'Count', 's2': 'Area', 's3': 'Area&ndash;Population'},
'area': { 's1': 'Area', 's2': 'Count', 's3': 'Area&ndash;Population'},
'areaPop': { 's1': 'Area&ndash;Population', 's2': 'Count', 's3': 'Area'}
}
n.choroVar = "count";
function selectChoroVar(event) {
var targId = event.target.id;
if (targId === "choroMapLegend2") {
if (n.choroVar !== "count") {
n.choroVar = "count";
} else {
n.choroVar = "area";
}
} else {
if (n.choroVar !== "areaPop") {
n.choroVar = "areaPop";
} else {
n.choroVar = "area";
}
}
get("choroMapLegend1").innerHTML = choroLegend[n.choroVar].s1;
get("choroMapLegend2").innerHTML = choroLegend[n.choroVar].s2;
get("choroMapLegend3").innerHTML = choroLegend[n.choroVar].s3;
w.choro.choropleth();
}
n.prepareNav = function() {
var d = get("choroMapLegend2");
d.onclick = selectChoroVar;
d.style.fontWeight = 600;
d.style.color = "#4d8375";
d.style.cursor = "pointer";
d = get("choroMapLegend3");
d.onclick = selectChoroVar;
d.style.fontWeight = 600;
d.style.color = "#4d8375";
d.style.cursor = "pointer";
get("choroMap").style.backgroundColor = "#f9fafa";
n.toggleNav();
};
n.toggleNav = function() {
get("choroMapLegend1").innerHTML = choroLegend[n.choroVar].s1;
get("choroMapLegend2").innerHTML = choroLegend[n.choroVar].s2;
get("choroMapLegend3").innerHTML = choroLegend[n.choroVar].s3;
get("choroMap").style.display = "block";
get("choroMapLegend").style.display = "block";
m.curMap = "choroMap";
m.initMap();
};
}() );
( function() {
    if (location.href.includes("Place-name_choropleths")) {
        document.getElementsByClassName("mw-selflink")[0].style.display = "none";
    }
    var w = window.IRHB;
    var gjson = "/w/geo/england/country/England.json";
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = "/w/js/d3js/d3.v3.min.js";
    script.onload = w.nav.prepareNav;
    document.head.appendChild(script);
}() );
}() );
</script></includeonly>
</script></includeonly>

Latest revision as of 15:47, 6 November 2022

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