diff --git a/modules/ui/zones-editor.js b/modules/ui/zones-editor.js index 00ea9196..740b8797 100644 --- a/modules/ui/zones-editor.js +++ b/modules/ui/zones-editor.js @@ -18,7 +18,8 @@ function editZones() { }); // add listeners - document.getElementById("zonesEditorRefresh").addEventListener("click", zonesEditorAddLines); + document.getElementById("zonesFilterType").addEventListener("change", refreshZonesEditor); + document.getElementById("zonesEditorRefresh").addEventListener("click", refreshZonesEditor); document.getElementById("zonesEditStyle").addEventListener("click", () => editStyle("zones")); document.getElementById("zonesLegend").addEventListener("click", toggleLegend); document.getElementById("zonesPercentage").addEventListener("click", togglePercentageMode); @@ -61,6 +62,23 @@ function editZones() { zone = el.parentNode.dataset.id; if (el.classList.contains("religionName")) zones.select("#" + zone).attr("data-description", el.value); }); + + function refreshZonesEditor() { + updateSVG(); + zonesEditorAddLines(); + } + +function updateSVG() { + const value = document.getElementById("zonesFilterType").value; + +zones.selectAll("g").each(function () { + if (value == "All" || this.dataset.type == value) { + this.style.display = "block"; + } else { + this.style.display = "none"; + } + }); + } // add line for each zone function zonesEditorAddLines() { @@ -76,6 +94,7 @@ function editZones() { const urban = d3.sum(c.map(i => pack.cells.burg[i]).map(b => pack.burgs[b].population)) * populationRate * urbanization; const population = rural + urban; const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(urban)}. Click to change`; + const zonetype = this.dataset.type; const inactive = this.style.display === "none"; const focused = defs.select("#fog #focus" + this.id).size(); @@ -88,6 +107,7 @@ function editZones() {
${si(area) + unit}
${si(population)}
+