Skip to content
New issue

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

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

Already on GitHub? # to your account

Update label_color_mapping and inherit palette from plot widget #49

Merged
merged 4 commits into from
Jan 16, 2024
Merged

Conversation

gc153671
Copy link
Contributor

Turn label_color_mapping into a partial map and have LabelEditorWidget inherit plot palette by default

Copy link
Collaborator

@hamelin hamelin left a comment

Choose a reason for hiding this comment

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

I'll word the changes I wish for a little differently, at the risk of repeating myself from the local comments. I understand the color and palette parameters as having a natural order:

  1. Colors for named labels in the label_color_mapping argument should be assigned as is.
  2. Further labels unnamed should be assigned colors from the palette provided through the palette argument. The order does not matter, but it must be stored so that it is sustained in any linked label editor widget.
  3. If there are more unique labels (aka label names) than the sum of the sizes of label_color_mapping and palette, or if palette_size is larger than that sum, then we should enlarge the palette obtained by this concatenation using glasbey.extend_palette, granting new colors determined to maximize the visual variance of the final palette.

If a label editor widget is, in turn, created with explicit factors and colors (to build its own view of the palette), then it must strictly match that of the plot. This would suggest that the user did their own palette homework and that no automatic palette extension occurred. Any palette incoherence between the plot and the editor should be punished with an exception. :-) No trying to fix a mess made by the user.

for label, color in label_color_mapping.items():
factors.append(label)
colors.append(color)
for factor, color in zip(factors, self._base_palette):
Copy link
Collaborator

Choose a reason for hiding this comment

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

So if the user provides a palette that is smaller than the cardinal of the label set, then the resulting plot will have less colours than there are unique labels. I believe this is a bad surprise to subject the user to: it looks like a bug.

factors.append(label)
colors.append(color)
for factor, color in zip(factors, self._base_palette):
if factor in label_color_mapping:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This approach makes it so the final palette is not composed in order to maximize the palette's visual variance, given the colors chosen by the user. I wish that if I provided parameters label_color_mapping={"my-special-label": "#abcdef"} and palette=None, then the plot would use glasbey.extend_palette to complete my choice. Same if a palette is provided by palette=[...], the the concatenation of the color mapping and the palette is too short given the number of unique labels.

If the user provides both a color map and a palette list, we should work out of the concatenation of the two. It's the user's responsibility to make these visually variant. Any further addition to the palette (to take into account a larger required palette size or number of unique labels) should be obtained by glasbey.extend_palette.

Copy link
Collaborator

@hamelin hamelin left a comment

Choose a reason for hiding this comment

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

Excellent implementation, looks great to me.

@hamelin hamelin merged commit 34f6e01 into TutteInstitute:main Jan 16, 2024
10 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants