1// One answer to what the reader is looking at.2//3// Three surfaces used to work this out for themselves. The canvas drew what4// survived every filter; the footer counted what the legend allowed; the dock5// listed what the search left. So highlighting one district could cull sixty6// features off the map while the panel beside it went on offering all sixty,7// and the two numbers on screen disagreed by a factor of four with nothing to8// say which was the map's. Every surface asks here now, and a filter that9// lands on one of them lands on all of them.1011import { isCollectionHidden } from "./collections.js";12import { pinIsHidden } from "./features.js";13import { state } from "./state.js";1415// Every point feature the chart is drawing: its collection shown, the search16// satisfied, and standing inside whatever ground or cell is holding the view.17export function visiblePins() {18 return state.features.filter((pin) => !pinIsHidden(pin));19}2021// Every shape feature the chart is drawing: its collection shown, and on the22// lens's own shard, which is all the registry holds. Highlighting narrows23// which points stand rather than which ground is drawn, so it asks nothing24// here.25export function visibleZones() {26 return [...state.zoneRecords.values()]27 .filter((record) => !isCollectionHidden(record.zone.collectionId));28}2930// What the map is drawing, counted: features of every kind, one number.31export function drawnFeatureCount() {32 return visiblePins().length + visibleZones().length;33}3435// The part of it a list can name, alphabetically. Shape features answer the36// search here rather than on the canvas -- searching for a place has never37// taken the ground out from under it -- and one the archive left untitled is38// on the map without being in any index of it.39export function listableFeatures() {40 return [41 ...visiblePins().map((pin) => ({ title: pin.location.title, pin })),42 ...visibleZones()43 .filter((record) => record.zone.title &&44 (!state.search || record.zone.title.toLocaleLowerCase().includes(state.search)))45 .map((record) => ({ title: record.zone.title, record })),46 ].sort((a, b) => a.title.localeCompare(b.title));47}4849// Whether anything but the reader's own search is narrowing the list: a50// collection put away, ground highlighted, a cell holding the view. The dock51// flags itself with this, so the count dropping always has a reason on screen52// beside it.53export function filtersApply() {54 return state.hiddenCollections.size > 0 || state.highlightedZones.size > 0 ||55 Boolean(state.gridEnabled && state.gridCell);56}