From a57dfd2e263effd910be9ff8d919d2927e81e94f Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Mon, 5 Jan 2026 13:36:54 -0600 Subject: [PATCH] Move traffic graph below device info and add zero axis line --- assets/js/app.js | 17 ++++- .../live/equipment_live/show.html.heex | 62 +++++++++---------- lib/towerops_web/live/graph_live/show.ex | 2 + .../live/graph_live/show.html.heex | 1 + 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 47f01913..ec90a1de 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -52,6 +52,7 @@ const SensorChart = { const ctx = canvas.getContext('2d') const unit = this.el.dataset.unit || '%' const autoScale = this.el.dataset.autoScale === 'true' + const showZeroLine = this.el.dataset.showZeroLine === 'true' // Generate colors for each dataset const colors = [ @@ -77,13 +78,27 @@ const SensorChart = { // Y-axis configuration const yAxisConfig = autoScale ? { + beginAtZero: showZeroLine, ticks: { callback: function(value) { return value + unit } }, grid: { - color: 'rgba(0, 0, 0, 0.05)' + color: function(context) { + // Make the zero line more prominent + if (showZeroLine && context.tick.value === 0) { + return 'rgba(0, 0, 0, 0.3)' + } + return 'rgba(0, 0, 0, 0.05)' + }, + lineWidth: function(context) { + // Make the zero line thicker + if (showZeroLine && context.tick.value === 0) { + return 2 + } + return 1 + } } } : { min: 0, diff --git a/lib/towerops_web/live/equipment_live/show.html.heex b/lib/towerops_web/live/equipment_live/show.html.heex index ddf9bcbf..da4c2a1f 100644 --- a/lib/towerops_web/live/equipment_live/show.html.heex +++ b/lib/towerops_web/live/equipment_live/show.html.heex @@ -70,39 +70,6 @@
<%= case @active_tab do %> <% "overview" -> %> - - <%= if @traffic_chart_data do %> -
- <.link - navigate={ - ~p"/orgs/#{@current_organization.slug}/equipment/#{@equipment.id}/graph/traffic" - } - class="block px-4 py-3 border-b border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-750 transition-colors" - > -
-
-

- Overall Traffic (24 Hours) -

-

- Combined traffic across all interfaces -

-
- <.icon name="hero-arrow-right" class="h-4 w-4 text-zinc-400" /> -
- -
-
- -
-
-
- <% end %>
@@ -209,6 +176,35 @@
+ + <%= if @traffic_chart_data do %> +
+ <.link + navigate={ + ~p"/orgs/#{@current_organization.slug}/equipment/#{@equipment.id}/graph/traffic" + } + class="block px-4 py-3 border-b border-zinc-200 dark:border-zinc-700 hover:bg-zinc-50 dark:hover:bg-zinc-750 transition-colors" + > +
+

+ Overall Traffic (24 Hours) +

+ <.icon name="hero-arrow-right" class="h-4 w-4 text-zinc-400" /> +
+ +
+
+ +
+
+
+ <% end %>
diff --git a/lib/towerops_web/live/graph_live/show.ex b/lib/towerops_web/live/graph_live/show.ex index b9bd7d9f..f30819c3 100644 --- a/lib/towerops_web/live/graph_live/show.ex +++ b/lib/towerops_web/live/graph_live/show.ex @@ -55,6 +55,7 @@ defmodule ToweropsWeb.GraphLive.Show do end {title, unit, auto_scale} = get_chart_config(sensor_type) + show_zero_line = sensor_type == "traffic" socket |> assign(:equipment, equipment) @@ -63,6 +64,7 @@ defmodule ToweropsWeb.GraphLive.Show do |> assign(:chart_data, chart_data) |> assign(:unit, unit) |> assign(:auto_scale, auto_scale) + |> assign(:show_zero_line, show_zero_line) end defp get_sensor_types_for_chart("processors"), do: ["cpu_load"] diff --git a/lib/towerops_web/live/graph_live/show.html.heex b/lib/towerops_web/live/graph_live/show.html.heex index 4e715477..33a1295a 100644 --- a/lib/towerops_web/live/graph_live/show.html.heex +++ b/lib/towerops_web/live/graph_live/show.html.heex @@ -51,6 +51,7 @@ data-chart={@chart_data} data-unit={@unit} data-auto-scale={@auto_scale} + data-show-zero-line={@show_zero_line} style="height: 600px;" >