mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2026-02-04 17:41:23 +01:00
feat: add search functionality to overview components
This commit is contained in:
parent
d0395624af
commit
3e339b78d4
5 changed files with 93 additions and 16 deletions
|
|
@ -25,13 +25,25 @@ function overviewRoutes() {
|
|||
byId("routesExport").on("click", downloadRoutesData);
|
||||
byId("routesLockAll").on("click", toggleLockAll);
|
||||
byId("routesRemoveAll").on("click", triggerAllRoutesRemove);
|
||||
byId("routesSearch").addEventListener("input", routesOverviewAddLines);
|
||||
|
||||
// add line for each route
|
||||
function routesOverviewAddLines() {
|
||||
body.innerHTML = "";
|
||||
let lines = "";
|
||||
const searchText = (byId("routesSearch").value || "").toLowerCase().trim();
|
||||
let filteredRoutes = pack.routes;
|
||||
|
||||
for (const route of pack.routes) {
|
||||
// filter by search text
|
||||
if (searchText) {
|
||||
filteredRoutes = filteredRoutes.filter(route => {
|
||||
const name = (route.name || "").toLowerCase();
|
||||
const group = (route.group || "").toLowerCase();
|
||||
return name.includes(searchText) || group.includes(searchText);
|
||||
});
|
||||
}
|
||||
|
||||
for (const route of filteredRoutes) {
|
||||
if (!route.points || route.points.length < 2) continue;
|
||||
route.name = route.name || Routes.generateName(route);
|
||||
route.length = route.length || Routes.getLength(route.i);
|
||||
|
|
@ -58,8 +70,8 @@ function overviewRoutes() {
|
|||
body.insertAdjacentHTML("beforeend", lines);
|
||||
|
||||
// update footer
|
||||
routesFooterNumber.innerHTML = pack.routes.length;
|
||||
const averageLength = rn(d3.mean(pack.routes.map(r => r.length)) || 0);
|
||||
routesFooterNumber.innerHTML = filteredRoutes.length;
|
||||
const averageLength = rn(d3.mean(filteredRoutes.map(r => r.length)) || 0);
|
||||
routesFooterLength.innerHTML = averageLength * distanceScale + " " + distanceUnitInput.value;
|
||||
|
||||
// add listeners
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue