Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reverse preset color order #2568

Merged
merged 4 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ def apply_RGB_presets(self):
self.swatches_palette[0][0],
]

preset_inds = {2: [1,4], 3: [1,2,4], 4: [1,2,3,4]}

# Switch back to this at the end
initial_layer = self.layer_selected

Expand All @@ -640,10 +642,8 @@ def apply_RGB_presets(self):
if n_visible > 2:
default_opacity = 1 / math.log2(n_visible)
# Sample along a colormap if we have too many layers
if n_visible == 2:
preset_colors = [preset_colors[1], preset_colors[4]]
elif n_visible == 3:
preset_colors = [preset_colors[1], preset_colors[2], preset_colors[4]]
if n_visible >= 2 and n_visible < len(preset_colors):
preset_colors = [preset_colors[i] for i in preset_inds[n_visible]]
elif n_visible > len(preset_colors):
cmap = matplotlib.colormaps['gist_rainbow'].resampled(n_visible)
preset_colors = [matplotlib.colors.to_hex(cmap(i), keep_alpha=True) for
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might now read better and be harder to break in the opposite order (if n_visible > len(preset_color): ... elif n_visible > 2: ...)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I wasn't thinking about the == case, so doesn't really make a difference I guess 🤷‍♂️

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I'm not changing it back!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def test_apply_presets(imviz_helper):
arr = np.arange(36).reshape(6, 6)
po = imviz_helper.plugins['Plot Options']

preset_colors = [po._obj.swatches_palette[4][1], "#0000FF", "#00FF00",
po._obj.swatches_palette[1][0], po._obj.swatches_palette[0][0],]
preset_colors_4 = ["#0000FF", "#00FF00", po._obj.swatches_palette[1][0],
po._obj.swatches_palette[0][0]]

# Test applying presets with < 6 layers

Expand All @@ -272,7 +272,7 @@ def test_apply_presets(imviz_helper):
po.layer = f"array_{i}"
assert po.stretch_function.value == "arcsinh"
assert po.stretch_preset.value == 99
assert po.image_color.value == preset_colors[i]
assert po.image_color.value == preset_colors_4[i]

# Test applying presets with > 5 layers

Expand Down
Loading