aboutsummaryrefslogtreecommitdiffstats
path: root/app/models.js
diff options
context:
space:
mode:
authorPetri Hienonen <petri.hienonen@gmail.com>2025-11-14 16:25:45 +0200
committerPetri Hienonen <petri.hienonen@gmail.com>2025-11-14 16:25:45 +0200
commit55085dae685305d24c29b60b1c16fc7dc76831af (patch)
tree4833cb2974bf8922c804bbb463113f0fe568f7a3 /app/models.js
parenta92ad2b817b2c28b26e869897e03c14d30d0f991 (diff)
downloadhousing-55085dae685305d24c29b60b1c16fc7dc76831af.tar.zst
Add slider filters and initialisation screen that handles data loading before application starts
Diffstat (limited to 'app/models.js')
-rw-r--r--app/models.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/models.js b/app/models.js
index b4584f7..e3f6381 100644
--- a/app/models.js
+++ b/app/models.js
@@ -712,10 +712,52 @@ export class Filters {
this.minPrice = 0;
this.maxPrice = Number.POSITIVE_INFINITY;
this.minYear = 1800;
+ this.maxYear = Number.POSITIVE_INFINITY;
this.minArea = 0;
+ this.maxArea = Number.POSITIVE_INFINITY;
+ this.minLot = 0;
+ this.maxLot = Number.POSITIVE_INFINITY;
/** @type {string[]} */
this.districts = [];
}
+
+ /**
+ * Update filter ranges based on house data
+ * @param {House[]} houses
+ */
+ updateRanges(houses) {
+ if (!houses || houses.length === 0) return;
+
+ const prices = houses.map((h) => h.price).filter((p) => p > 0);
+ const years = houses.map((h) => h.constructionYear).filter((y) => y && y > 0);
+ const areas = houses.map((h) => h.livingArea).filter((a) => a && a > 0);
+ const lots = houses.map((h) => h.totalArea).filter((l) => l && l > 0);
+
+ // Set reasonable defaults if no data
+ const defaultPrice = 500000;
+ const defaultYear = new Date().getFullYear();
+ const defaultArea = 200;
+ const defaultLot = 1000;
+
+ // Update min/max values, ensuring they're reasonable
+ this.minPrice = Math.min(...prices) || 0;
+ this.maxPrice = Math.max(...prices) || defaultPrice;
+
+ this.minYear = Math.min(...years) || 1800;
+ this.maxYear = Math.max(...years) || defaultYear;
+
+ this.minArea = Math.min(...areas) || 0;
+ this.maxArea = Math.max(...areas) || defaultArea;
+
+ this.minLot = Math.min(...lots) || 0;
+ this.maxLot = Math.max(...lots) || defaultLot;
+
+ // Ensure min doesn't exceed max
+ this.minPrice = Math.min(this.minPrice, this.maxPrice);
+ this.minYear = Math.min(this.minYear, this.maxYear);
+ this.minArea = Math.min(this.minArea, this.maxArea);
+ this.minLot = Math.min(this.minLot, this.maxLot);
+ }
}
export class Collection {