Repository: netbox-community/netbox
Pull request: Closes #8232: Add color show full 100% utilization
<!--
    Thank you for your interest in contributing to NetBox! Please note
    that our contribution policy requires that a feature request or bug
    report be opened for approval prior to filing a pull request. This
    helps avoid wasting time and effort on something that we might not
    be able to accept.

    Please indicate the relevant feature request or bug report below.
    IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR
    FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED.
-->
### Fixes: #8232 
<!--
    Please include a summary of the proposed changes below.
-->


Problem statement:
Show full 100% utilization bar in a different color from 99.9%
### NetBox version

v3.1.4

### Feature type

Change to existing functionality

### Proposed functionality

I propose when utilization is full, i.e. there is nothing free left, the utilization bar would not show the same red as it shows for 90% or 99.9%.  
Instead it could show a (slightly) different color, say brighter/darker red or purple.

### Use case

Make it easy for human operator to distinguish from the utilization bar whether utilization is totally full 100%, or not totally full <100%.

Currently the operator cannot just scan the list of utilization bars for whether something is 100% full or almost full because the bar has the same color and may display too similar bar length for 99%/99.9% and 100%.

100% is a slightly special case since there is nothing free left inside, so indicate that to the operator for spotting it easily.

### Database changes

None.

### External dependencies

None.

Hints from issue discussion:
The `utilization_graph` tag used to render these graphs currently supports warning (yellow) and danger (red) thresholds; these default to 75 and 90, respectively. It should be simple to extend this to include a special style/color for 100 values, although we might also need to look into rounding (e.g. 99.99% not being the same as 100%).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).

Commit message: Closes #8232: Add color show full 100% utilization

Patch to review:
diff --git a/netbox/utilities/templates/helpers/utilization_graph.html b/netbox/utilities/templates/helpers/utilization_graph.html
index fe1c0fc9a62..04b0391bf7b 100644
--- a/netbox/utilities/templates/helpers/utilization_graph.html
+++ b/netbox/utilities/templates/helpers/utilization_graph.html
@@ -9,8 +9,13 @@
       aria-valuemin="0"
       aria-valuemax="100"
       aria-valuenow="{{ utilization }}"
+      {% if is_full_danger %}
+      class="progress-bar"
+      style="width: {{ utilization }}%; background-color: #800080;"
+      {% else %}
       class="progress-bar {{ bar_class }}"
       style="width: {{ utilization }}%;"
+      {% endif %}
     >
       {% if utilization >= 25 %}{{ utilization }}%{% endif %}
     </div>
@@ -18,4 +23,4 @@
       <span class="ps-1">{{ utilization }}%</span>
     {% endif %}
   </div>
-{% endif %}
+{% endif %}
\ No newline at end of file
diff --git a/netbox/utilities/templatetags/helpers.py b/netbox/utilities/templatetags/helpers.py
index 0e45cb581c3..cfba03b8742 100644
--- a/netbox/utilities/templatetags/helpers.py
+++ b/netbox/utilities/templatetags/helpers.py
@@ -389,6 +389,9 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
     """
     Display a horizontal bar graph indicating a percentage of utilization.
     """
+    is_full_danger = False
+    if utilization == 100:
+        is_full_danger = True
     if danger_threshold and utilization >= danger_threshold:
         bar_class = 'bg-danger'
     elif warning_threshold and utilization >= warning_threshold:
@@ -397,9 +400,11 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
         bar_class = 'bg-success'
     else:
         bar_class = 'bg-gray'
+        is_full_danger = False
     return {
         'utilization': utilization,
         'bar_class': bar_class,
+        'is_full_danger': is_full_danger,
     }
 
 


Code review comments:
diff_hunk: @@ -389,6 +389,9 @@ def utilization_graph(utilization, warning_threshold=75, danger_threshold=90):
     """
     Display a horizontal bar graph indicating a percentage of utilization.
     """
+    is_full_danger = False
+    if utilization == 100:
+        is_full_danger = True
path: netbox/utilities/templatetags/helpers.py
text: @user1:
This logic can be cleaned up considerably. There should be no need to store a variable indicating whether the utilization value is 100: we can just reference utilization directly.

@author:
Oh sorry, I misunderstand something