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

Issue 818 spatial tab: allow highlight of dendro paths for hovered cell only #914

Merged
merged 3 commits into from
Feb 5, 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
56 changes: 35 additions & 21 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,25 @@ 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);
},
);
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 +785,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 @@ -1124,7 +1128,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;
Expand Down Expand Up @@ -1724,7 +1728,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 +1749,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
Loading