Files
smart-house---final-/dashboard.js
2026-03-24 10:04:24 +01:00

71 lines
2.2 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* global Chart */ // Permet à l'IDE de reconnaître Chart.js
// -------------------------------
// 1⃣ Sélection des widgets
// -------------------------------
const climat = document.querySelector('.widget.climat');
const securite = document.querySelector('.widget.securite');
const energie = document.querySelector('.widget.energie');
const lumiere = document.querySelector('.widget.lumiere');
const alertes = document.querySelector('.widget.alertes');
// -------------------------------
// 2⃣ Hover dynamique sur les widgets
// -------------------------------
function setupHover(widget, colorNormal, colorHover) {
widget.addEventListener('mouseenter', () => {
widget.style.backgroundColor = colorHover;
});
widget.addEventListener('mouseleave', () => {
widget.style.backgroundColor = colorNormal;
});
}
setupHover(climat, '#ADD8E6', '#87CEEB');
setupHover(securite, '#D3D3D3', '#C0C0C0');
setupHover(energie, '#FFFACD', '#FAFAD2');
setupHover(lumiere, '#F5F5DC', '#FFF8DC');
// -------------------------------
// 3⃣ Simulation d'alerte visuelle
// -------------------------------
function showAlert(widget) {
widget.classList.add('alert');
}
// Exemple : activer l'alerte sur climat
showAlert(climat);
// Le bloc alertes reste visible
alertes.style.display = 'block';
// -------------------------------
// 4⃣ Graphique Chart.js
// -------------------------------
const canvasTemp = document.getElementById('graph-temp');
if(canvasTemp) {
const ctx = canvasTemp.getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
datasets: [{
label: 'Température',
data: [20, 22, 19, 23, 21],
borderColor: 'blue',
backgroundColor: 'rgba(173,216,230,0.2)',
tension: 0.4
}]
},
options: {
responsive: true,
plugins: {
legend: { display: true }
},
scales: {
x: { display: true, title: { display: true, text: 'Mois' } },
y: { display: true, title: { display: true, text: '°C' } }
}
}
});
}