Update ApiDocs and HistoryCharts components; enhance PollutionMap with heat layer and toggle Voronoi visibility
This commit is contained in:
@@ -6,12 +6,12 @@ const ApiDocs = ({ json }) => {
|
|||||||
if (!json) return <p className="text-muted">No hay documentación disponible.</p>;
|
if (!json) return <p className="text-muted">No hay documentación disponible.</p>;
|
||||||
|
|
||||||
const renderEndpoints = (endpoints) => (
|
const renderEndpoints = (endpoints) => (
|
||||||
<Accordion>
|
<Accordion className='overflow-auto'>
|
||||||
{endpoints.map((ep, index) => (
|
{endpoints.map((ep, index) => (
|
||||||
<Accordion.Item eventKey={index.toString()} key={index}>
|
<Accordion.Item eventKey={index.toString()} key={index}>
|
||||||
<Accordion.Header>
|
<Accordion.Header className='d-flex align-items-center flex-wrap'>
|
||||||
<span className={`badge bg-${getMethodColor(ep.method)} me-2 text-uppercase`}>{ep.method}</span>
|
<span className={`badge bg-${getMethodColor(ep.method)} me-2 text-uppercase`}>{ep.method}</span>
|
||||||
<code>{ep.path}</code>
|
<code className='text-break flex-grow-1'>{ep.path}</code>
|
||||||
</Accordion.Header>
|
</Accordion.Header>
|
||||||
<Accordion.Body>
|
<Accordion.Body>
|
||||||
{ep.description && <p className="mb-2">{ep.description}</p>}
|
{ep.description && <p className="mb-2">{ep.description}</p>}
|
||||||
|
|||||||
@@ -108,22 +108,23 @@ const HistoryChartsContent = () => {
|
|||||||
cards={historyData.map(({ title, data, borderColor, backgroundColor }) => ({
|
cards={historyData.map(({ title, data, borderColor, backgroundColor }) => ({
|
||||||
title,
|
title,
|
||||||
content: (
|
content: (
|
||||||
<Line style={{ minHeight: "250px" }}
|
<Line
|
||||||
data={{
|
data={{
|
||||||
labels: timeLabels,
|
labels: timeLabels,
|
||||||
datasets: [{ data, borderColor, backgroundColor, fill: true, tension: 0.4 }]
|
datasets: [{ data, borderColor, backgroundColor, fill: true, tension: 0.4 }]
|
||||||
}}
|
}}
|
||||||
options={options}
|
options={options}
|
||||||
|
style={{ minHeight: "250px", width: '100%'}}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
styleMode: "override",
|
styleMode: "override",
|
||||||
className: "col-lg-6 col-xxs-12 d-flex flex-column align-items-center",
|
className: "col-lg-6 col-xxs-12 d-flex flex-column align-items-center",
|
||||||
style: { minHeight: "250px" }
|
style: { minHeight: "250px", width: '100%' }
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
<span className="m-0 p-0 d-flex align-items-center justify-content-center">
|
<span className="m-0 p-0 d-flex align-items-center justify-content-center">
|
||||||
<FontAwesomeIcon icon={faInfoCircle} className="me-2" />
|
<FontAwesomeIcon icon={faInfoCircle} className="me-2" />
|
||||||
<p className="m-0 p-0">El historial muestra datos de los últimos 3 días</p>
|
<p className="m-0 p-0">El historial muestra datos de los últimos 3 días, el mapa del día actual, y arriba del todo los datos son los últimos recogidos independientemente de la fecha</p>
|
||||||
</span>
|
</span>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ const PollutionMapContent = () => {
|
|||||||
const { config, configLoading, configError } = useConfig();
|
const { config, configLoading, configError } = useConfig();
|
||||||
const { data, dataLoading, dataError } = useDataContext();
|
const { data, dataLoading, dataError } = useDataContext();
|
||||||
|
|
||||||
const mapRef = useRef(null); // Referencia al mapa
|
const mapRef = useRef(null);
|
||||||
const voronoiLayerRef = useRef(null); // Referencia al layer de Voronoi
|
const voronoiLayerRef = useRef(null);
|
||||||
const [showVoronoi, setShowVoronoi] = useState(true);
|
const [showVoronoi, setShowVoronoi] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!data || !config) return;
|
if (!data || !config) return;
|
||||||
@@ -80,6 +80,12 @@ const PollutionMapContent = () => {
|
|||||||
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
|
const points = data
|
||||||
|
.filter(p => isToday(p.timestamp))
|
||||||
|
.map(p => [p.lat, p.lon, p.carbonMonoxide]);
|
||||||
|
|
||||||
|
L.heatLayer(points, { radius: 25 }).addTo(map);
|
||||||
|
|
||||||
fetch("/voronoi_sevilla_geovoronoi.geojson")
|
fetch("/voronoi_sevilla_geovoronoi.geojson")
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(geojson => {
|
.then(geojson => {
|
||||||
@@ -105,18 +111,11 @@ const PollutionMapContent = () => {
|
|||||||
console.error("Error cargando el GeoJSON:", err);
|
console.error("Error cargando el GeoJSON:", err);
|
||||||
});
|
});
|
||||||
|
|
||||||
const points = data
|
|
||||||
.filter(p => isToday(p.timestamp))
|
|
||||||
.map(p => [p.lat, p.lon, p.carbonMonoxide]);
|
|
||||||
|
|
||||||
L.heatLayer(points, { radius: 25 }).addTo(map);
|
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
map.remove();
|
map.remove();
|
||||||
};
|
};
|
||||||
}, [data, config]);
|
}, [data, config]);
|
||||||
|
|
||||||
// Esta parte gestiona el toggle del voronoi
|
|
||||||
const toggleVoronoi = () => {
|
const toggleVoronoi = () => {
|
||||||
const map = mapRef.current;
|
const map = mapRef.current;
|
||||||
const voronoiLayer = voronoiLayerRef.current;
|
const voronoiLayer = voronoiLayerRef.current;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import cleanPlugin from 'vite-plugin-clean'
|
|||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
server: {
|
server: {
|
||||||
host: "localhost",
|
host: "0.0.0.0",
|
||||||
port: 3000,
|
port: 3000,
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
Reference in New Issue
Block a user