From 2bacf6337ccfe64cf65a6d178f9bc88e67f07d0f Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 15 Jan 2026 13:12:29 -0600 Subject: [PATCH] Fix equipment charts to display full 24-hour time range Set explicit min/max bounds on chart x-axis to ensure all graphs consistently show 24 hours of data, even when data points are sparse. Also fix AlertNotifierTest race condition by disabling async execution. --- assets/js/app.js | 12 ++++++++---- test/towerops/alerts/alert_notifier_test.exs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index dd795052..86955cbc 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -194,6 +194,10 @@ const SensorChart = { } } + // Calculate 24-hour time range for consistent x-axis + const now = Date.now() + const twentyFourHoursAgo = now - (24 * 60 * 60 * 1000) + this.chart = new Chart(ctx, { type: chartType, data: { datasets }, @@ -240,11 +244,11 @@ const SensorChart = { scales: { x: { type: 'linear', + min: twentyFourHoursAgo, + max: now, ticks: { - callback: function(value, index) { - const point = this.chart.data.datasets[0]?.data[index] - if (!point) return '' - const date = new Date(point.x) + callback: function(value) { + const date = new Date(value) return date.toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', hour12: false }) }, maxTicksLimit: 12 diff --git a/test/towerops/alerts/alert_notifier_test.exs b/test/towerops/alerts/alert_notifier_test.exs index b4ddfb16..61cc498c 100644 --- a/test/towerops/alerts/alert_notifier_test.exs +++ b/test/towerops/alerts/alert_notifier_test.exs @@ -1,5 +1,5 @@ defmodule Towerops.Alerts.AlertNotifierTest do - use Towerops.DataCase + use Towerops.DataCase, async: false import Swoosh.TestAssertions import Towerops.AccountsFixtures