Skip to content

Commit c9d63f3

Browse files
authored
fix: Some fixes (#12)
* fix: Doesn't show the flight curves for regions where its not available * fix: Fixes natural area selection not affecting the map * fix: Improves the month selecting slider * fix: Code review fixes
1 parent e1f488b commit c9d63f3

5 files changed

Lines changed: 60 additions & 4 deletions

File tree

src/components/ButterflyTransects.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,26 @@ function ButterflyTransects() {
330330
}
331331
}
332332

333+
// Protected Area filter
334+
if (protectedAreaFilters.length > 0) {
335+
const hasInside = protectedAreaFilters.includes("inside");
336+
const hasOutside = protectedAreaFilters.includes("outside");
337+
const specificAreas = protectedAreaFilters.filter(f => f !== "inside" && f !== "outside");
338+
339+
const isTransectInside = transect.protectedArea && transect.protectedArea !== "";
340+
341+
const matchesFilter =
342+
(hasInside && isTransectInside) ||
343+
(hasOutside && !isTransectInside) ||
344+
(isTransectInside &&
345+
transect.protectedArea &&
346+
specificAreas.includes(transect.protectedArea));
347+
348+
if (!matchesFilter) {
349+
return false;
350+
}
351+
}
352+
333353
return true;
334354
});
335355

src/components/MunicipalityPage.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ function MunicipalityPage() {
374374
min={MONITORING_MONTHS[0]}
375375
max={MONITORING_MONTHS[MONITORING_MONTHS.length - 1]}
376376
value={selectedMonth}
377+
trackStyle={{ display: "none" }}
377378
onChange={(value: number) => {
378379
// Find the closest monitoring month
379380
const closest = MONITORING_MONTHS.reduce((prev, curr) =>

src/components/charts/FlightCurveChart.tsx

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,42 @@ export const FlightCurvesDisplay: React.FC<FlightCurvesDisplayProps> = ({
200200
"Mediterrânico Sul": 4, // Southern Mediterranean Portugal
201201
};
202202

203-
const regions = Object.keys(phenologyData.regions).sort(
204-
(a, b) => (regionOrder[a] || 999) - (regionOrder[b] || 999)
205-
);
203+
// Filter out regions without valid phenology curves data
204+
const regions = Object.keys(phenologyData.regions)
205+
.filter(region => {
206+
const regionData = phenologyData.regions[region];
207+
if (!regionData.phenologyCurves || Object.keys(regionData.phenologyCurves).length === 0) {
208+
return false;
209+
}
210+
211+
// Check if at least one year has valid (non-NA) abundance data
212+
return Object.values(regionData.phenologyCurves).some(yearData => {
213+
if (!yearData.abundance || yearData.abundance.length === 0) return false;
214+
// Check if there's at least one valid numeric value (Number("NA") returns NaN)
215+
return yearData.abundance.some(val => val !== null && !isNaN(Number(val)));
216+
});
217+
})
218+
.sort((a, b) => (regionOrder[a] || 999) - (regionOrder[b] || 999));
219+
220+
// If no regions have data after filtering, show empty state
221+
if (regions.length === 0) {
222+
return (
223+
<Card>
224+
<Empty
225+
description={
226+
<>
227+
<p>
228+
Curvas de voo não disponíveis para <strong>{speciesName}</strong>
229+
</p>
230+
<p style={{ fontSize: "0.9em", color: "#666" }}>
231+
Dados insuficientes em todas as regiões climáticas
232+
</p>
233+
</>
234+
}
235+
/>
236+
</Card>
237+
);
238+
}
206239

207240
// Calculate maximum abundance across all regions and years for consistent y-axis
208241
const allAbundanceValues: number[] = [];

src/components/charts/MunicipalitySpeciesMap.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ const MunicipalitySpeciesMap: React.FC = () => {
359359
min={MONITORING_MONTHS[0]}
360360
max={MONITORING_MONTHS[MONITORING_MONTHS.length - 1]}
361361
value={selectedMonth}
362+
trackStyle={{ display: "none" }}
362363
onChange={(value: number) => {
363364
// Find the closest monitoring month
364365
const closest = MONITORING_MONTHS.reduce((prev, curr) =>

src/types/phenologyData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
/**
77
* Weekly abundance predictions for a single year
8+
* Note: abundance values can be numbers or "NA" strings when data is insufficient
89
*/
910
export interface YearlyPhenology {
1011
year: number;
1112
weeks: number[];
12-
abundance: number[];
13+
abundance: (number | string)[];
1314
}
1415

1516
/**

0 commit comments

Comments
 (0)