diff --git a/src/src/components/weatherChart/WeatherChart.js b/src/src/components/weatherChart/WeatherChart.js index 001c4aa..dbdea7d 100644 --- a/src/src/components/weatherChart/WeatherChart.js +++ b/src/src/components/weatherChart/WeatherChart.js @@ -27,6 +27,7 @@ Chart.register( const WeatherChart = ({ title, data, + dataSpatial, unit, color, isChartLoading, @@ -71,7 +72,7 @@ const WeatherChart = ({ document.body.removeChild(link); }; - const chartConfig = (label, data, color) => ({ + const chartConfig = (label, data, color, dataSpatial, spatialColor) => ({ labels: data.map((item) => item.label), datasets: [ { @@ -81,6 +82,17 @@ const WeatherChart = ({ borderColor: color, tension: 0.1, }, + ...(dataSpatial + ? [ + { + label: `Datos satelitales`, + data: dataSpatial.map((item) => item.value), + fill: false, + borderColor: spatialColor, + tension: 0.1, + }, + ] + : []), ], }); @@ -91,7 +103,7 @@ const WeatherChart = ({ y: { title: { display: true, text: unit }, beginAtZero: false }, }, }), - [] + [unit] ); const ChartOptionsStartedAtZero = useMemo( @@ -177,7 +189,13 @@ const WeatherChart = ({ identificar patrones climáticos recientes en la región.

{ precipitation: [], solRad: [], }); + const [dataSpacial, setDataSpacial] = useState({ + tempMax: [], + tempMin: [], + precipitation: [], + solRad: [], + }); const [stations, setStations] = useState([]); const [currentStation, setCurrentStation] = useState(null); const [currentStationSpacial, setCurrentStationSpacial] = useState(null); @@ -27,6 +41,7 @@ const Dashboard = () => { const [endDataDate, setEndDataDate] = useState(); const [endDataSpacialDate, setEndDataSpacialDate] = useState(); const [isFavorite, setIsFavorite] = useState(false); + const [showToast, setShowToast] = useState(false); const { idWS } = useParams(); const navigate = useNavigate(); @@ -81,11 +96,11 @@ const Dashboard = () => { const lastDataSpacialAvailable = await Services.getLastDailyWeather( currentStationSpacial.id ); - const formattedSpacialEndDate = new Date( - lastDataSpacialAvailable[0].date - ) - .toISOString() - .split("T")[0]; + const formattedSpacialEndDate = lastDataSpacialAvailable.length + ? new Date(lastDataSpacialAvailable[0].date) + .toISOString() + .split("T")[0] + : "N/A"; setEndDataSpacialDate(formattedSpacialEndDate); const startDate = new Date(lastDataAvailable[0].date); @@ -223,10 +238,50 @@ const Dashboard = () => { setIsFavorite(true); }; - const compareData = () => {}; + const compareData = () => { + const fetchData = async () => { + if (!currentStationSpacial) return; + try { + const response = await Services.getDailyWeather( + startDate, + endDate, + currentStationSpacial.id + ); + const parsedData = parseWeatherData(response.daily_data); + setDataSpacial(parsedData); + console.log(parsedData); + } catch (error) { + console.error("Error fetching daily weather data:", error); + } finally { + if (dataSpacial.tempMax.length === 0) { + setShowToast(true); + } + } + }; + fetchData(); + }; return (
+ + setShowToast(false)} + show={showToast} + delay={3000} + autohide + bg="warning" + > + + + La estacion no tiene datos espaciales para este periodo de tiempo! + + + + { { { {