Skip to content

Commit

Permalink
Spatial tab: Add menu option to highlight only paths in the hovered cell
Browse files Browse the repository at this point in the history
As opposed to across both neighbour sets.
  • Loading branch information
shawnlaffan committed Feb 5, 2024
1 parent b56b8da commit 664d621
Showing 1 changed file with 49 additions and 20 deletions.
69 changes: 49 additions & 20 deletions lib/Biodiverse/GUI/Tabs/Spatial.pm
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,8 @@ sub init_dendrogram {
$self->{dendrogram}->set_num_clusters (1);

$self->{no_dendro_legend_for} = {
'<i>Turnover</i>' => 1,
'<i>Branches in nbr set 1</i>' => 1,
'Turnover' => 1,
'Branches in nbr set 1' => 1,
map {$_ => 1, "<i>$_</i>" => 1}
('Turnover', 'Branches in nbr set 1', 'Branches in hovered cell only')
};

$self->init_branch_colouring_menu;
Expand Down Expand Up @@ -651,23 +649,40 @@ sub init_branch_colouring_menu {
? '<i>Turnover</i>'
: '<i>Branches in nbr set 1</i>';
$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, '<i>Branches in hovered cell only</i>') {
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:'));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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];
Expand Down

0 comments on commit 664d621

Please sign in to comment.