Skip to content

Commit

Permalink
Fix ROI Colour Clash
Browse files Browse the repository at this point in the history
Rename random generator to be more descriptive as colours selected are not random, update tests to reflect method name change, move secon colour in pallet to another location in pallet to avoid colour clash of ROIs when one ROI is added after another
  • Loading branch information
JackEAllen committed Dec 7, 2023
1 parent 774a4e8 commit 0cce80d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions mantidimaging/gui/windows/spectrum_viewer/spectrum_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,16 @@ def get_tof_range(self) -> tuple[int, int]:
r_min, r_max = self.range_control.getRegion()
return int(r_min), int(r_max)

def random_colour_generator(self) -> tuple[int, int, int, int]:
def colour_generator(self) -> tuple[int, int, int, int]:
"""
A random colour generator to colour ROIs boarders.
Generates colours that are easy to see for colour blind people if colour_blind_friendly is True.
By default colour_blind_friendly is set to False
@return: A random colour in RGBA format. (0-255, 0-255, 0-255, 0-255)
"""
accessible_colours = [(255, 194, 10), (12, 123, 220), (153, 79, 0), (64, 176, 166), (230, 97, 0), (93, 58, 155),
(26, 255, 26), (254, 254, 98), (211, 95, 183), (220, 50, 43)]
accessible_colours = [(255, 194, 10), (153, 79, 0), (64, 176, 166), (230, 97, 0), (93, 58, 155), (26, 255, 26),
(12, 123, 220), (254, 254, 98), (211, 95, 183), (220, 50, 43)]
if self.colour_index == len(accessible_colours):
self.colour_index = 0
colour = accessible_colours[self.colour_index]
Expand Down Expand Up @@ -175,7 +175,7 @@ def add_roi(self, roi: SensibleROI, name: str) -> None:
@param name: The name of the ROI.
"""
roi_object = SpectrumROI(name, roi, pos=(0, 0), rotatable=False, scaleSnap=True, translateSnap=True)
roi_object.colour = self.random_colour_generator()
roi_object.colour = self.colour_generator()

self.roi_dict[name] = roi_object.roi
self.max_roi_size = roi_object.size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def tearDown(self):
del self.spectrum_widget

def test_WHEN_colour_generator_called_THEN_return_value_of_length_3(self):
colour = self.spectrum_widget.random_colour_generator()
colour = self.spectrum_widget.colour_generator()
self.assertEqual(len(colour), 4)

def test_WHEN_colour_generator_called_THEN_valid_rgb_tuple_returned(self):
colour = self.spectrum_widget.random_colour_generator()
colour = self.spectrum_widget.colour_generator()
self.assertTrue(all(0 <= c <= 255 for c in colour))

def test_WHEN_colour_generator_called_THEN_different_colours_returned(self):
colour_list = [self.spectrum_widget.random_colour_generator() for _ in range(10)]
colour_list = [self.spectrum_widget.colour_generator() for _ in range(10)]
self.assertEqual(len(colour_list), len({tuple(c) for c in colour_list}))

def test_WHEN_change_roi_colour_called_THEN_roi_colour_changed(self):
Expand Down

0 comments on commit 0cce80d

Please sign in to comment.