Spaces:
Running
Running
Create App.js
Browse files
App.js
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useEffect, useState } from "react";
|
2 |
+
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
|
3 |
+
import 'leaflet/dist/leaflet.css';
|
4 |
+
import Chart from 'chart.js/auto';
|
5 |
+
|
6 |
+
function App() {
|
7 |
+
const [data, setData] = useState({
|
8 |
+
geoData: [{ latitude: 45.4, longitude: -71.9, name: "Position 1" }], // Sherbrooke, Québec par défaut
|
9 |
+
statsData: { labels: [], datasets: [] },
|
10 |
+
alerts: []
|
11 |
+
});
|
12 |
+
|
13 |
+
useEffect(() => {
|
14 |
+
// Simulation de données en temps réel (à remplacer par une connexion réelle)
|
15 |
+
const interval = setInterval(() => {
|
16 |
+
setData(prevData => ({
|
17 |
+
...prevData,
|
18 |
+
geoData: prevData.geoData.map(point => ({
|
19 |
+
...point,
|
20 |
+
latitude: point.latitude + (Math.random() - 0.5) * 0.1, // Mouvement aléatoire sur la carte
|
21 |
+
longitude: point.longitude + (Math.random() - 0.5) * 0.1
|
22 |
+
})),
|
23 |
+
statsData: {
|
24 |
+
labels: ["Red", "Blue", "Green"],
|
25 |
+
datasets: [{
|
26 |
+
label: 'Dataset 1',
|
27 |
+
data: [Math.random() * 100, Math.random() * 100, Math.random() * 100],
|
28 |
+
backgroundColor: [
|
29 |
+
'rgba(255, 99, 132, 0.2)',
|
30 |
+
'rgba(54, 162, 235, 0.2)',
|
31 |
+
'rgba(75, 192, 192, 0.2)'
|
32 |
+
],
|
33 |
+
borderColor: [
|
34 |
+
'rgba(255, 99, 132, 1)',
|
35 |
+
'rgba(54, 162, 235, 1)',
|
36 |
+
'rgba(75, 192, 192, 1)'
|
37 |
+
],
|
38 |
+
borderWidth: 1
|
39 |
+
}]
|
40 |
+
},
|
41 |
+
alerts: [...prevData.alerts, `Alerte ${Math.floor(Math.random() * 100)}`]
|
42 |
+
}));
|
43 |
+
}, 2000); // Mettre à jour les données toutes les 2 secondes
|
44 |
+
|
45 |
+
return () => clearInterval(interval);
|
46 |
+
}, []);
|
47 |
+
|
48 |
+
function updateMap(geoData) {
|
49 |
+
return (
|
50 |
+
<MapContainer center={[45.4, -71.9]} zoom={5} style={{ height: '400px' }}>
|
51 |
+
<TileLayer
|
52 |
+
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
53 |
+
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
54 |
+
/>
|
55 |
+
{geoData.map(point => (
|
56 |
+
<Marker key={point.name} position={[point.latitude, point.longitude]}>
|
57 |
+
<Popup>
|
58 |
+
{point.name}
|
59 |
+
</Popup>
|
60 |
+
</Marker>
|
61 |
+
))}
|
62 |
+
</MapContainer>
|
63 |
+
);
|
64 |
+
}
|
65 |
+
|
66 |
+
useEffect(() => {
|
67 |
+
if (data.statsData.datasets.length > 0) {
|
68 |
+
const ctx = document.getElementById('myChart').getContext('2d');
|
69 |
+
new Chart(ctx, {
|
70 |
+
type: 'bar',
|
71 |
+
data: data.statsData,
|
72 |
+
});
|
73 |
+
}
|
74 |
+
}, [data.statsData]);
|
75 |
+
|
76 |
+
function updateAlerts(alerts) {
|
77 |
+
return (
|
78 |
+
<div>
|
79 |
+
<h3>Alertes:</h3>
|
80 |
+
<ul>
|
81 |
+
{alerts.map((alert, index) => (
|
82 |
+
<li key={index}>{alert}</li>
|
83 |
+
))}
|
84 |
+
</ul>
|
85 |
+
</div>
|
86 |
+
);
|
87 |
+
}
|
88 |
+
|
89 |
+
return (
|
90 |
+
<div>
|
91 |
+
<h1>Tableau de Bord Démonstrateur</h1>
|
92 |
+
{updateMap(data.geoData)}
|
93 |
+
<canvas id="myChart"></canvas>
|
94 |
+
{updateAlerts(data.alerts)}
|
95 |
+
</div>
|
96 |
+
);
|
97 |
+
}
|
98 |
+
|
99 |
+
export default App;
|