Repository: napari/napari

Issue:
Layer.bounding_box.line_color sets default to red color if ```ndisplay = 3``` is not set in advance
### 🐛 Bug Report

It was first posted in image.sc forum. The layer bounding box shows the required effect in 2D viewing mode. However, as soon as we switch to 3D mode, the bounding box goes to the default color [red] and default thickness.

Furthermore, if we specify `n_display=3` either when initializing viewer  as ```viewer = napari.Viewer(ndisplay=3)``` or later by keeping  ```viewer.dims.ndisplay = 3```  line before `img_layer.bounding_box.line_color = 'magenta'` line, we can see the desired effect at the first time. But if we switch to 2D mode and then to 3D mode, the bounding_box will regain its default color and thickness. 

### 💡 Steps to Reproduce

Please run the aboA simple code to generate this effect is shown below.
```
import numpy as np
import napari
# Create a simple 4D image (axis0 = time, axis1=Z, axis2=Y, axis3=X )
img = np.random.random((5, 25, 100, 100)) 
viewer = napari.Viewer()
img_layer = viewer.add_image(img)
img_layer.bounding_box.visible = True
img_layer.bounding_box.points = False
img_layer.bounding_box.line_color = 'magenta'  # Set bbox line_color to magenta
img_layer.bounding_box.line_thickness = 2   # Adjust bbox line_thickness
napari.run()
```
# Expected behavior in 2D viewing mode 
![2d_view](https://github.com/napari/napari/assets/107076601/2a62ee98-e5c9-4266-b2a0-3c8d123683e2)

# Unexpected behavior in 2D viewing mode 
![3d_view](https://github.com/napari/napari/assets/107076601/013ea016-4c90-4c68-81c3-4588a4dff735)


### 💡 Expected Behavior

_No response_

### 🌎 Environment

napari: 0.4.19.post1
Platform: Windows-10-10.0.22631-SP0
Python: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr 5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Qt: 5.15.2
PyQt5: 5.15.10
NumPy: 1.24.3
SciPy: 1.10.1
Dask: 2024.3.1
VisPy: 0.14.2
magicgui: 0.8.2
superqt: 0.6.2
in-n-out: 0.2.0
app-model: 0.2.5
npe2: 0.7.4

OpenGL:
- GL version: 4.6.0 - Build 27.20.100.9664
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 960x540, scale 2.0

Settings path:
- C:\Users\ganes\AppData\Local\napari\Spille-env_37971cbecf9a2e8d7253a2dbc0abe906acec97a0\settings.yaml

### 💡 Additional Context

_No response_


Discussion:
This issue has been mentioned on **Image.sc Forum**. There might be relevant details there:

https://forum.image.sc/t/napari-layer-bounding-box-line-color-does-not-change-in-3d-viewing-mode/95005/3

@pganes check out #6855, it should fix your issue :)

Resolving patch:
diff --git a/napari/_vispy/overlays/bounding_box.py b/napari/_vispy/overlays/bounding_box.py
--- a/napari/_vispy/overlays/bounding_box.py
+++ b/napari/_vispy/overlays/bounding_box.py
@@ -31,7 +31,6 @@ def _on_bounds_change(self):
             bounds = np.pad(bounds, ((1, 0), (0, 0)))
 
         self.node.set_bounds(bounds[::-1])  # invert for vispy
-        self._on_lines_change()
 
     def _on_lines_change(self):
         self.node.lines.visible = self.overlay.lines
@@ -40,10 +39,12 @@ def _on_points_change(self):
         self.node.markers.visible = self.overlay.points
 
     def _on_line_thickness_change(self):
-        self.node.lines.set_data(width=self.overlay.line_thickness)
+        self.node._line_thickness = self.overlay.line_thickness
+        self._on_bounds_change()
 
     def _on_line_color_change(self):
-        self.node.lines.set_data(color=self.overlay.line_color)
+        self.node._line_color = self.overlay.line_color
+        self._on_bounds_change()
 
     def _on_point_size_change(self):
         self.node._marker_size = self.overlay.point_size
diff --git a/napari/_vispy/visuals/bounding_box.py b/napari/_vispy/visuals/bounding_box.py
--- a/napari/_vispy/visuals/bounding_box.py
+++ b/napari/_vispy/visuals/bounding_box.py
@@ -33,6 +33,8 @@ class BoundingBox(Compound):
     )
 
     def __init__(self, *args, **kwargs):
+        self._line_color = 'red'
+        self._line_thickness = 2
         self._marker_color = (1, 1, 1, 1)
         self._marker_size = 1
 
@@ -54,7 +56,10 @@ def set_bounds(self, bounds):
         vertices = np.array(list(product(*bounds)))
 
         self.lines.set_data(
-            pos=vertices, connect=self._edges.copy(), color='red', width=2
+            pos=vertices,
+            connect=self._edges.copy(),
+            color=self._line_color,
+            width=self._line_thickness,
         )
         self.lines.visible = True
 


Test patch: