import { initialiseGraphControls } from "./dashboard/graph-controls.js"; import { createProbeCharts } from "./dashboard/charts.js"; import { createInsightsCharts } from "./dashboard/insights.js"; import { createWeatherCharts } from "./dashboard/weather-page.js"; import { loadWeatherForecast } from "./dashboard/weather-forecast.js"; import { DASHBOARD_REFRESH_MS } from "./dashboard/constants.js"; import { loadQuickReadings } from "./dashboard/quick-readings.js"; import { createStatusLoader } from "./dashboard/status.js"; import { createTimeframeState } from "./dashboard/timeframe.js"; // Global chart defaults: incline x-axis labels for better mobile readability Chart.defaults.scales.category.ticks.maxRotation = 45; Chart.defaults.scales.category.ticks.minRotation = 45; const timeframe = createTimeframeState(); const probes = createProbeCharts(timeframe); const insights = createInsightsCharts(); const weatherPage = createWeatherCharts(); const loadStatuses = createStatusLoader(); document.querySelectorAll(".tab-button").forEach(button => { button.addEventListener("click", () => probes.activateTab(button.dataset.probe)); }); initialiseGraphControls(timeframe, () => { probes.reloadDisplayed(); }); window.addEventListener("hashchange", () => { const probe = probes.probeFromLocation(); if (probe) probes.activateTab(probe); }); const initialHashProbe = probes.probeFromHash(); const initialProbe = probes.probeFromLocation(); if (initialProbe) { probes.activateTab(initialProbe); if (initialHashProbe) { document.getElementById(`probe-${initialHashProbe}`)?.scrollIntoView(); } } else if (probes.activeProbe()) { probes.loadDisplayed(); } let refreshInFlight = null; function refreshDashboard() { if (refreshInFlight) return refreshInFlight; refreshInFlight = Promise.allSettled([ probes.loadDisplayed(), insights.reload(), weatherPage.reload(), loadWeatherForecast(), loadQuickReadings(), loadStatuses() ]).finally(() => { refreshInFlight = null; }); return refreshInFlight; } function refreshVisibleDashboard() { return document.hidden ? null : refreshDashboard(); } document.addEventListener("visibilitychange", () => { if (!document.hidden) refreshDashboard(); }); refreshVisibleDashboard(); setInterval(refreshVisibleDashboard, DASHBOARD_REFRESH_MS);