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

Spatial tab: user control of tree branch undef colour #936

Merged
merged 2 commits into from
Jun 1, 2024
Merged
Changes from all commits
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
50 changes: 49 additions & 1 deletion lib/Biodiverse/GUI/Tabs/Spatial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,13 @@ sub get_tree_menu_items {
},
active => 0,
},
{
type => 'Gtk2::MenuItem',
label => 'Set colour for undefined list values',
tooltip => 'Set the colour used to display list values that are undefined.',
event => 'activate',
callback => \&on_tree_undef_colour_changed,
},
{
type => 'submenu_radio_group',
label => 'Colour mode',
Expand Down Expand Up @@ -589,6 +596,7 @@ sub init_dendrogram {

# cannot colour more than one in a phylogeny
$self->{dendrogram}->set_num_clusters (1);
$self->set_dendrogram_colour_for_undef(COLOUR_GRAY); # default

$self->{no_dendro_legend_for} = {
map {$_ => 1, "<i>$_</i>" => 1}
Expand Down Expand Up @@ -821,6 +829,21 @@ sub init_dendrogram_legend {
return;
}

sub set_dendrogram_colour_for_undef {
my ($self, $colour) = @_;
my $dendrogram = $self->{dendrogram};
return if !$dendrogram;
$dendrogram->get_legend->set_colour_for_undef($colour // COLOUR_GRAY);
}

sub get_dendrogram_colour_for_undef {
my $self = shift;
my $dendrogram = $self->{dendrogram};
return if !$dendrogram;
$dendrogram->get_legend->get_colour_for_undef;
}


sub init_grid {
my $self = shift;
my $frame = $self->get_xmlpage_object('gridFrame');
Expand Down Expand Up @@ -1841,6 +1864,8 @@ sub colour_branches_on_dendrogram {

my %done;

my $colour_for_undef = $legend->get_colour_for_undef // COLOUR_BLACK;

LABEL:
foreach my $label (keys %$listref) {
next LABEL if $done{$label};
Expand All @@ -1864,7 +1889,7 @@ sub colour_branches_on_dendrogram {
$colour_ref
= defined $val
? $legend->$colour_method ($val, @minmax_args)
: COLOUR_BLACK;
: $colour_for_undef;

$dendrogram->highlight_node ($node_ref, $colour_ref);
$dendrogram->set_node_colour(
Expand Down Expand Up @@ -2623,6 +2648,29 @@ sub on_tree_colour_mode_changed {
return;
}

sub on_tree_undef_colour_changed {
my ($self, $menu_item) = @_;

return if !$menu_item;

# Pop up dialog for choosing the hue to use in saturation mode
my $colour_dialog = Gtk2::ColorSelectionDialog->new('Select colour');
my $colour_select = $colour_dialog->get_color_selection();
if (my $current_colour = $self->get_dendrogram_colour_for_undef) {
$colour_select->set_current_color ($current_colour);
}
$colour_dialog->show_all();
my $response = $colour_dialog->run;
if ($response eq 'ok') {
my $hue = $colour_select->get_current_color();
$self->set_dendrogram_colour_for_undef ($hue);
$self->{dendrogram}->update_legend;
}
$colour_dialog->destroy();

return;
}


# methods aren't inherited when called as GTK callbacks
# so we have to manually inherit them using SUPER::
Expand Down
Loading