aboutsummaryrefslogtreecommitdiffstats
path: root/app/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/main.js')
-rw-r--r--app/main.js46
1 files changed, 31 insertions, 15 deletions
diff --git a/app/main.js b/app/main.js
index 9abb300..da52152 100644
--- a/app/main.js
+++ b/app/main.js
@@ -50,23 +50,13 @@ export class App {
this.#filters,
this.#weights,
() => {
- this.#filtered = this.collection?.houses.filter((h) => h.matchesFilters(this.#filters));
- const filteredIds = this.#filtered.map((h) => h.id);
- this.#map.updateHouseVisibility(filteredIds);
-
- const stats = App.#getStats(this.#filtered);
- this.#stats.replaceWith(stats);
- this.#stats = stats;
+ this.#applyFiltersAndScoring();
},
(key, value) => {
if (key in this.#weights) {
this.#weights[/** @type {keyof Weights} */ (key)] = value;
}
- App.#recalculateScores(this.collection?.houses, this.#weights);
- this.#map.updateHousesColor(this.#houseParameter);
- const stats = App.#getStats(this.#filtered);
- this.#stats.replaceWith(stats);
- this.#stats = stats;
+ this.#applyFiltersAndScoring();
},
(param) => {
this.#houseParameter = param;
@@ -189,7 +179,9 @@ export class App {
async #initialize(loading) {
try {
this.collection = await Collection.get();
- this.#filtered = this.collection.houses.slice();
+
+ App.#recalculateScores(this.collection.houses, this.#weights);
+ this.#filtered = this.collection.houses.filter((h) => h.matchesFilters(this.#filters));
this.#map.initialize(this.collection, this.#houseParameter, this.#areaParameter);
this.#sidebar.updateDistricts(this.collection.houses);
@@ -211,10 +203,34 @@ export class App {
static #recalculateScores(houses, weights) {
for (const h of houses) {
h.scores.current = Math.round(ScoringEngine.calculate(h, weights));
+ h.value = h.scores.current;
}
}
/**
+ * Apply filters and recalculate scores
+ */
+ #applyFiltersAndScoring() {
+ if (!this.collection) return;
+
+ // First recalculate all scores with current weights
+ App.#recalculateScores(this.collection.houses, this.#weights);
+
+ // Then apply filters
+ this.#filtered = this.collection.houses.filter((h) => h.matchesFilters(this.#filters));
+
+ // Update map with filtered houses and new scores
+ const filteredIds = this.#filtered.map((h) => h.id);
+ this.#map.updateHouseVisibility(filteredIds);
+ this.#map.updateHousesColor(this.#houseParameter);
+
+ // Update statistics
+ const stats = App.#getStats(this.#filtered);
+ this.#stats.replaceWith(stats);
+ this.#stats = stats;
+ }
+
+ /**
* Update statistics display using DOM methods
* @param {House[]} filtered
*/
@@ -223,14 +239,14 @@ export class App {
new DomOptions({
children: [
Dom.strong(filtered.length.toString()),
- document.createTextNode(" houses shown • Average score: "),
+ Dom.span(" houses shown • Average score: "),
Dom.strong(
(filtered.length
? Math.round(filtered.reduce((s, h) => s + h.scores.current, 0) / filtered.length)
: 0
).toString(),
),
- document.createTextNode(" • Use weights sliders to adjust scoring"),
+ Dom.span(" • Use weights sliders to adjust scoring"),
],
id: "stats",
styles: {