From 664d6215e0a4a0ba7f5ec0f1fc164366d62b9d7d Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Mon, 5 Feb 2024 13:24:54 +1100 Subject: [PATCH 1/3] Spatial tab: Add menu option to highlight only paths in the hovered cell As opposed to across both neighbour sets. --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 69 +++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 03da4d5fd..c628ea1ea 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -591,10 +591,8 @@ sub init_dendrogram { $self->{dendrogram}->set_num_clusters (1); $self->{no_dendro_legend_for} = { - 'Turnover' => 1, - 'Branches in nbr set 1' => 1, - 'Turnover' => 1, - 'Branches in nbr set 1' => 1, + map {$_ => 1, "$_" => 1} + ('Turnover', 'Branches in nbr set 1', 'Branches in hovered cell only') }; $self->init_branch_colouring_menu; @@ -651,23 +649,40 @@ sub init_branch_colouring_menu { ? 'Turnover' : 'Branches in nbr set 1'; $label->set_markup ($default_text); - my $default_text_sans_markup = $default_text =~ s/<.?i>//gr; my $sel_group = []; - my $menu_item_label = Gtk2::Label->new($default_text); - my $menu_item - = Gtk2::RadioMenuItem->new_with_label($sel_group, $default_text_sans_markup); - push @$sel_group, $menu_item; - $menu_item->set_use_underline(0); - # $menu_item->set_label($menu_item_label); - $menu->append($menu_item); - $menu_item->signal_connect_swapped( - activate => sub { - $self->{dendrogram}->get_legend->hide; - $self->{current_branch_colouring_source} = undef; - $label->set_markup ($default_text); - }, - ); + # my $menu_item_label = Gtk2::Label->new($default_text); + # my $menu_item + # = Gtk2::RadioMenuItem->new_with_label($sel_group, $default_text_sans_markup); + # push @$sel_group, $menu_item; + # $menu_item->set_use_underline(0); + # # $menu_item->set_label($menu_item_label); + # $menu->append($menu_item); + # $menu_item->signal_connect_swapped( + # activate => sub { + # $self->{dendrogram}->get_legend->hide; + # $self->{current_branch_colouring_source} = undef; + # $label->set_markup ($default_text); + # }, + # ); + + foreach my $text ($default_text, 'Branches in hovered cell only') { + my $text_sans_markup = $text =~ s/<.?i>//gr; + my $menu_item_label = Gtk2::Label->new($text); + my $menu_item + = Gtk2::RadioMenuItem->new_with_label($sel_group, $text_sans_markup); + push @$sel_group, $menu_item; + $menu_item->set_use_underline(0); + # $menu_item->set_label($menu_item_label); + $menu->append($menu_item); + $menu_item->signal_connect_swapped( + activate => sub { + $self->{dendrogram}->get_legend->hide; + $self->{current_branch_colouring_source} = $text_sans_markup; + $label->set_markup($text); + }, + ); + } $menu->append(Gtk2::SeparatorMenuItem->new); $menu->append(Gtk2::MenuItem->new_with_label('Lists in this output:')); @@ -785,6 +800,10 @@ and black denotes those in both. From these one can see the turnover of branches between the groups (cells) in each neighbour set. +The 'Branches in hovered cell only' option will only +highlight paths found in the group (cell) being hovered over, +regardless of how many groups are in the neighbour sets. + The next set of menu options are list indices in the spatial output that belongs to this tab. The remainder are lists across other spatial outputs in the project, organised by their @@ -1724,7 +1743,8 @@ my @dendro_highlight_branch_colours sub highlight_paths_on_dendrogram { my ($self, $hashrefs, $group) = @_; - if (my $sources = $self->{current_branch_colouring_source}) { + my $sources = $self->{current_branch_colouring_source}; + if (is_ref $sources) { my ($ref, $listname) = @$sources; $self->colour_branches_on_dendrogram ( list_name => $listname, @@ -1744,6 +1764,15 @@ sub highlight_paths_on_dendrogram { my %done; my $dendrogram = $self->{dendrogram}; + # user only wants the hovered cell contents + if (($sources // '') eq 'Branches in hovered cell only') { + my $bd = $self->{output_ref}->get_basedata_ref; + $hashrefs = [ + scalar $bd->get_labels_in_group_as_hash_aa($group), + {}, + ]; + } + foreach my $idx (0, 1) { my $alt_idx = $idx ? 0 : 1; my $href = $hashrefs->[$idx]; From 41359af1172d110fcf8d9986eeade6bf4e599b13 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Mon, 5 Feb 2024 13:34:22 +1100 Subject: [PATCH 2/3] avoid an undef comparison warning --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index c628ea1ea..35101aa28 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -1143,7 +1143,7 @@ sub on_selected_phylogeny_changed { my $dendro_tree = $self->{dendrogram}->get_cluster; # don't trigger needless redraws - return if refaddr ($phylogeny) == refaddr ($dendro_tree); + return if ($dendro_tree && $phylogeny) && refaddr ($phylogeny) == refaddr ($dendro_tree); if ($self->{dendrogram}) { $self->{dendrogram}->clear; From e42cf721b75f53af60e6fb8056d4307dea7111d9 Mon Sep 17 00:00:00 2001 From: shawnlaffan Date: Mon, 5 Feb 2024 13:57:08 +1100 Subject: [PATCH 3/3] delete some commented code --- lib/Biodiverse/GUI/Tabs/Spatial.pm | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/lib/Biodiverse/GUI/Tabs/Spatial.pm b/lib/Biodiverse/GUI/Tabs/Spatial.pm index 35101aa28..260ac2f78 100644 --- a/lib/Biodiverse/GUI/Tabs/Spatial.pm +++ b/lib/Biodiverse/GUI/Tabs/Spatial.pm @@ -651,21 +651,6 @@ sub init_branch_colouring_menu { $label->set_markup ($default_text); my $sel_group = []; - # my $menu_item_label = Gtk2::Label->new($default_text); - # my $menu_item - # = Gtk2::RadioMenuItem->new_with_label($sel_group, $default_text_sans_markup); - # push @$sel_group, $menu_item; - # $menu_item->set_use_underline(0); - # # $menu_item->set_label($menu_item_label); - # $menu->append($menu_item); - # $menu_item->signal_connect_swapped( - # activate => sub { - # $self->{dendrogram}->get_legend->hide; - # $self->{current_branch_colouring_source} = undef; - # $label->set_markup ($default_text); - # }, - # ); - foreach my $text ($default_text, 'Branches in hovered cell only') { my $text_sans_markup = $text =~ s/<.?i>//gr; my $menu_item_label = Gtk2::Label->new($text);