Skip to content

Commit 347a486

Browse files
committed
GUI: Plot the union of label range convex hulls
This gives fewer lines and thus a less busy plot for large data sets.
1 parent 3138783 commit 347a486

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

lib/Biodiverse/GUI/Tabs/Labels.pm

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ sub get_tree_menu_items {
399399
qw /plot_branches_by
400400
highlight_groups_on_map
401401
highlight_groups_on_map_convex_hull
402+
highlight_groups_on_map_convex_hull_union
402403
highlight_groups_on_map_circumcircle
403404
highlight_paths_on_tree
404405
separator
@@ -913,6 +914,25 @@ sub get_highlight_label_range_convex_hulls {
913914
$_[0]->{highlight_label_range_convex_hulls};
914915
}
915916

917+
sub set_highlight_label_range_convex_hull_union {
918+
my ($self, $value) = @_;
919+
920+
$self->{highlight_label_range_convex_hull_union} = !!$value;
921+
922+
return;
923+
}
924+
925+
sub toggle_highlight_label_range_convex_hull_union {
926+
my ($self, $value) = @_;
927+
928+
$self->{highlight_label_range_convex_hull_union}
929+
= !$self->{highlight_label_range_convex_hull_union};
930+
}
931+
932+
sub get_highlight_label_range_convex_hull_union {
933+
$_[0]->{highlight_label_range_convex_hull_union};
934+
}
935+
916936
sub set_highlight_label_range_circumcircles {
917937
my ($self, $value) = @_;
918938

@@ -963,6 +983,45 @@ sub highlight_label_range_convex_hulls {
963983
}
964984
}
965985
986+
sub highlight_label_range_convex_hull_union {
987+
my ($self, $node) = @_;
988+
989+
return if !$self->get_highlight_label_range_convex_hull_union;
990+
991+
my $terminal_elements = $node->get_terminal_elements;
992+
993+
my $bd = $self->get_base_ref;
994+
my $label_hash = $bd->get_labels_ref->get_element_hash;
995+
996+
# clear existing
997+
$self->{grid}->clear_range_convex_hulls;
998+
999+
my $cache = $bd->get_cached_value_dor_set_default_href('LABEL_RANGE_CONVEX_HULL_VERTICES');
1000+
1001+
my $hull_union = $cache->{$node->get_name};
1002+
if (!$hull_union) {
1003+
# could climb up the tree if this takes too long
1004+
foreach my $label (keys %$terminal_elements) {
1005+
next LABEL if !exists $label_hash->{$label};
1006+
my $hull = $bd->get_label_range_convex_hull(label => $label);
1007+
$hull_union = $hull_union ? $hull_union->Union ($hull) : $hull;
1008+
}
1009+
$cache->{$node->get_name} = $hull_union;
1010+
}
1011+
1012+
# avoid plotting empties
1013+
if (defined $hull_union) {
1014+
$self->{grid}->set_overlay(
1015+
type => 'polyline',
1016+
cb_target => 'range_convex_hulls',
1017+
plot_on_top => 1,
1018+
data => scalar $hull_union->GetPoints(0, 0),
1019+
colour => COLOUR_BLACK,
1020+
alpha => 0.5,
1021+
);
1022+
}
1023+
}
1024+
9661025
sub highlight_label_range_circumcircles {
9671026
my ($self, $node) = @_;
9681027
@@ -1583,6 +1642,7 @@ sub on_phylogeny_highlight {
15831642

15841643
$self->highlight_label_range_marks($node);
15851644
$self->highlight_label_range_convex_hulls($node);
1645+
$self->highlight_label_range_convex_hull_union($node);
15861646
$self->highlight_label_range_circumcircles($node);
15871647

15881648
if (defined $node) {

lib/Biodiverse/GUI/Tabs/Spatial.pm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ sub get_tree_menu_items {
418418
separator
419419
highlight_groups_on_map
420420
highlight_groups_on_map_convex_hull
421+
highlight_groups_on_map_convex_hull_union
421422
highlight_groups_on_map_circumcircle
422423
highlight_paths_on_tree
423424
separator
@@ -1209,6 +1210,7 @@ sub on_phylogeny_highlight {
12091210

12101211
$self->highlight_label_range_marks($node);
12111212
$self->highlight_label_range_convex_hulls($node);
1213+
$self->highlight_label_range_convex_hull_union($node);
12121214
$self->highlight_label_range_circumcircles($node);
12131215

12141216
return;

lib/Biodiverse/GUI/Tabs/Tab.pm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,21 @@ EOT
13321332
$self->get_highlight_label_range_convex_hulls;
13331333
},
13341334
},
1335+
highlight_groups_on_map_convex_hull_union => {
1336+
type => 'Gtk3::CheckMenuItem',
1337+
label => 'Highlight groups on map with range convex hull union',
1338+
tooltip => 'When hovering the mouse over a tree branch, '
1339+
. 'plot the union of the convex hulls of the range of each subtending label.',
1340+
event => 'toggled',
1341+
callback => sub {
1342+
my ($self, $widget) = @_;
1343+
$self->set_highlight_label_range_convex_hull_union($widget->get_active);
1344+
},
1345+
active => sub {
1346+
my ($self) = @_;
1347+
$self->get_highlight_label_range_convex_hull_union;
1348+
},
1349+
},
13351350
highlight_groups_on_map_circumcircle => {
13361351
type => 'Gtk3::CheckMenuItem',
13371352
label => 'Highlight groups on map with range circumcircles',

0 commit comments

Comments
 (0)