diff --git a/assets/js/app.js b/assets/js/app.js index ec90a1de..653f4308 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -76,11 +76,27 @@ const SensorChart = { pointHoverRadius: 4, })) + // Format bits per second into human-readable units + const formatBps = (bps) => { + if (bps >= 1_000_000_000) { + return (bps / 1_000_000_000).toFixed(2) + ' Gbps' + } else if (bps >= 1_000_000) { + return (bps / 1_000_000).toFixed(2) + ' Mbps' + } else if (bps >= 1_000) { + return (bps / 1_000).toFixed(2) + ' Kbps' + } else { + return bps.toFixed(2) + ' bps' + } + } + // Y-axis configuration const yAxisConfig = autoScale ? { beginAtZero: showZeroLine, ticks: { callback: function(value) { + if (unit === 'bps') { + return formatBps(value) + } return value + unit } }, @@ -105,6 +121,9 @@ const SensorChart = { max: 100, ticks: { callback: function(value) { + if (unit === 'bps') { + return formatBps(value) + } return value + unit } }, @@ -145,6 +164,9 @@ const SensorChart = { }) }, label: function(context) { + if (unit === 'bps') { + return context.dataset.label + ': ' + formatBps(context.parsed.y) + } return context.dataset.label + ': ' + context.parsed.y.toFixed(1) + unit } } diff --git a/lib/towerops_web/live/equipment_live/show.html.heex b/lib/towerops_web/live/equipment_live/show.html.heex index da4c2a1f..1630717d 100644 --- a/lib/towerops_web/live/equipment_live/show.html.heex +++ b/lib/towerops_web/live/equipment_live/show.html.heex @@ -71,141 +71,146 @@ <%= case @active_tab do %> <% "overview" -> %>