mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-23 04:21:24 +01:00
filtering types
This commit is contained in:
parent
7873f8fb80
commit
6468859f5e
2 changed files with 46 additions and 25 deletions
|
|
@ -2916,7 +2916,7 @@
|
||||||
<div id="zonesFilters">
|
<div id="zonesFilters">
|
||||||
<span>Filter by type: </span>
|
<span>Filter by type: </span>
|
||||||
<select id="zonesFilterType" data-tip="Only zones of this type appear on the map"></select>
|
<select id="zonesFilterType" data-tip="Only zones of this type appear on the map"></select>
|
||||||
<button id="zonesFilterTable" data-tip="Click to toggle the filtering of elements on the list" class="icon-eye"></button>
|
<button id="zonesFilterButton" data-tip="Click to toggle the filtering of elements on the list" class="icon-eye"></button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="zonesFooter" class="totalLine">
|
<div id="zonesFooter" class="totalLine">
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ function editZones() {
|
||||||
|
|
||||||
// add listeners
|
// add listeners
|
||||||
document.getElementById("zonesFilterType").addEventListener("change", refreshZonesEditor);
|
document.getElementById("zonesFilterType").addEventListener("change", refreshZonesEditor);
|
||||||
document.getElementById("zonesFilterTable").addEventListener("click", toggleFilterTable);
|
document.getElementById("zonesFilterButton").addEventListener("click", toggleFilterTable);
|
||||||
document.getElementById("zonesEditorRefresh").addEventListener("click", refreshZonesEditor);
|
document.getElementById("zonesEditorRefresh").addEventListener("click", refreshZonesEditor);
|
||||||
document.getElementById("zonesEditStyle").addEventListener("click", () => editStyle("zones"));
|
document.getElementById("zonesEditStyle").addEventListener("click", () => editStyle("zones"));
|
||||||
document.getElementById("zonesLegend").addEventListener("click", toggleLegend);
|
document.getElementById("zonesLegend").addEventListener("click", toggleLegend);
|
||||||
|
|
@ -28,7 +28,7 @@ function editZones() {
|
||||||
document.getElementById("zonesManuallyApply").addEventListener("click", applyZonesManualAssignent);
|
document.getElementById("zonesManuallyApply").addEventListener("click", applyZonesManualAssignent);
|
||||||
document.getElementById("zonesManuallyCancel").addEventListener("click", cancelZonesManualAssignent);
|
document.getElementById("zonesManuallyCancel").addEventListener("click", cancelZonesManualAssignent);
|
||||||
document.getElementById("zonesAdd").addEventListener("click", addZonesDialog);
|
document.getElementById("zonesAdd").addEventListener("click", addZonesDialog);
|
||||||
document.getElementById("typeTrash").addEventListener("click", removeType);
|
//document.getElementById("typeTrash").addEventListener("click", removeZoneType);
|
||||||
document.getElementById("zonesNewBlank").addEventListener("click", addZonesLayer);
|
document.getElementById("zonesNewBlank").addEventListener("click", addZonesLayer);
|
||||||
document.getElementById("zonesNewRandom").addEventListener("click", addZonesLayer);
|
document.getElementById("zonesNewRandom").addEventListener("click", addZonesLayer);
|
||||||
document.getElementById("zonesNewTypeButton").addEventListener("click", addZonesType);
|
document.getElementById("zonesNewTypeButton").addEventListener("click", addZonesType);
|
||||||
|
|
@ -99,7 +99,8 @@ function editZones() {
|
||||||
|
|
||||||
// add line for each zone
|
// add line for each zone
|
||||||
function zonesEditorAddLines() {
|
function zonesEditorAddLines() {
|
||||||
const unit = areaUnit.value === "square" ? " " + distanceUnitInput.value + "²" : " " + areaUnit.value;
|
const unit = areaUnit.value === "square" ? " " + distanceUnitInput.value + "²" : " " + areaUnit.value;
|
||||||
|
let lines = "";
|
||||||
|
|
||||||
const selectedType = zonesFilterType.value || "All";
|
const selectedType = zonesFilterType.value || "All";
|
||||||
zonesFilterType.options.length=0;
|
zonesFilterType.options.length=0;
|
||||||
|
|
@ -108,8 +109,10 @@ function editZones() {
|
||||||
zonesFilterType.options.add(new Option(z, z, false, selectedType==z));
|
zonesFilterType.options.add(new Option(z, z, false, selectedType==z));
|
||||||
});
|
});
|
||||||
|
|
||||||
let lines = "";
|
|
||||||
zones.selectAll("g").each(function () {
|
zones.selectAll("g").each(function () {
|
||||||
|
const zoneType = this.dataset.type;
|
||||||
|
if (zonesFilterButton.classList.contains("pressed") && zoneType !== selectedType) return;
|
||||||
|
|
||||||
const c = this.dataset.cells ? this.dataset.cells.split(",").map(c => +c) : [];
|
const c = this.dataset.cells ? this.dataset.cells.split(",").map(c => +c) : [];
|
||||||
const description = this.dataset.description;
|
const description = this.dataset.description;
|
||||||
const fill = this.getAttribute("fill");
|
const fill = this.getAttribute("fill");
|
||||||
|
|
@ -117,7 +120,6 @@ function editZones() {
|
||||||
const rural = d3.sum(c.map(i => pack.cells.pop[i])) * populationRate;
|
const rural = d3.sum(c.map(i => pack.cells.pop[i])) * populationRate;
|
||||||
const urban = d3.sum(c.map(i => pack.cells.burg[i]).map(b => pack.burgs[b].population)) * populationRate * urbanization;
|
const urban = d3.sum(c.map(i => pack.cells.burg[i]).map(b => pack.burgs[b].population)) * populationRate * urbanization;
|
||||||
const population = rural + urban;
|
const population = rural + urban;
|
||||||
const zoneType = this.dataset.type;
|
|
||||||
const zoneTypeList = getZoneTypesList(this.id, this.dataset.type);
|
const zoneTypeList = getZoneTypesList(this.id, this.dataset.type);
|
||||||
const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(urban)}. Click to change`;
|
const populationTip = `Total population: ${si(population)}; Rural population: ${si(rural)}; Urban population: ${si(urban)}. Click to change`;
|
||||||
const inactive = this.style.display === "none";
|
const inactive = this.style.display === "none";
|
||||||
|
|
@ -386,15 +388,12 @@ function editZones() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function toggleFilterTable() {
|
function toggleFilterTable() {
|
||||||
this.classList.toggle("pressed");
|
this.classList.toggle("pressed");
|
||||||
const selectedType = zonesFilterType.value || "All";
|
const selectedType = zonesFilterType.value || "All";
|
||||||
//zoneTypes.forEach(function(z, i) {
|
const FilterTable = document.getElementById("zonesFilterButton").classList.contains("pressed");
|
||||||
//});
|
/*if (FilterTable) {
|
||||||
// if zone != selected type , hide the zones not selected from the list.
|
|
||||||
//zonesFilterType.options.length=0;
|
|
||||||
const FilterTable = document.getElementById("zonesFilterTable").classList.contains("pressed");
|
|
||||||
if (FilterTable) {
|
|
||||||
// hide the elements from the list
|
// hide the elements from the list
|
||||||
selection.forEach(i => {
|
selection.forEach(i => {
|
||||||
const index = zones.id(i);
|
const index = zones.id(i);
|
||||||
|
|
@ -409,7 +408,7 @@ function editZones() {
|
||||||
zone
|
zone
|
||||||
.attr("id", base + i);
|
.attr("id", base + i);
|
||||||
});
|
});
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
function addZonesLayer() {
|
function addZonesLayer() {
|
||||||
|
|
@ -540,7 +539,8 @@ function editZones() {
|
||||||
zoneTypes.forEach(function(z, i) {
|
zoneTypes.forEach(function(z, i) {
|
||||||
lines += `<div class="states"><span class="religionname">${z}</span>`;
|
lines += `<div class="states"><span class="religionname">${z}</span>`;
|
||||||
if (i > 5) {
|
if (i > 5) {
|
||||||
lines += '<span id="typeTrash" data-tip="Remove zone type" class="icon-trash-empty"></span>';
|
let id="removeZoneType" + i;
|
||||||
|
lines += `<span data-tip="Remove zone type" class="icon-trash-empty" id="${id}"></span>`;
|
||||||
}
|
}
|
||||||
lines += '</div>';
|
lines += '</div>';
|
||||||
});
|
});
|
||||||
|
|
@ -549,25 +549,46 @@ function editZones() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addZonesDialog() {
|
function addZonesDialog() {
|
||||||
//const body = document.getElementById("zonesTypesBodySection");
|
|
||||||
$("#zonesTypes").dialog({
|
$("#zonesTypes").dialog({
|
||||||
title: "Add zones and types",
|
title: "Add zones and types",
|
||||||
width: fitContent(),
|
width: fitContent(),
|
||||||
|
close: closeZoneTypesEditor,
|
||||||
position: {my: "center", at: "center", of: "svg"},
|
position: {my: "center", at: "center", of: "svg"},
|
||||||
});
|
});
|
||||||
zonesTypesAddLines();
|
zonesTypesAddLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeZoneTypesEditor() {
|
||||||
|
zonesEditorAddLines();
|
||||||
|
}
|
||||||
|
|
||||||
function addZonesType() {
|
function addZonesType() {
|
||||||
let zoneType = zonesNewTypeInput.value;
|
let zoneType = zonesNewTypeInput.value;
|
||||||
if (!zoneTypes.includes(zoneType)) { zoneTypes.push(zoneType); }
|
if (!zoneTypes.includes(zoneType)) { zoneTypes.push(zoneType); }
|
||||||
zonesTypesAddLines();
|
zonesTypesAddLines();
|
||||||
//body.insertAdjacentHTML("beforeend", line);
|
|
||||||
zonesTypesFooterNumber.innerHTML = zoneTypes.length;
|
zonesTypesFooterNumber.innerHTML = zoneTypes.length;
|
||||||
|
for (let i=0; i<zoneTypes.length; i++) {
|
||||||
|
let d = document.getElementById("removeZoneType" + i);
|
||||||
|
if (d) {
|
||||||
|
d.addEventListener("click", function() { removeZoneType(zoneTypes[i]); });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeType () {
|
function removeZoneType(zoneType) {
|
||||||
zoneType = this.dataset.type
|
zones.selectAll("g").each(function () {
|
||||||
|
if (this.dataset.type === zoneType) {
|
||||||
|
this.dataset.type = "Unassigned";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let i=0; i<zoneTypes.length; i++) {
|
||||||
|
if (zoneTypes[i] === zoneType) {
|
||||||
|
zoneTypes.splice(i, 1);
|
||||||
|
zonesTypesAddLines();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function zoneRemove(zone) {
|
function zoneRemove(zone) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue