Skip to content

Commit ec5e1f3

Browse files
committed
GUI: plot label ranges as circumcircles
Off by default, same as for the convex hulls.
1 parent e135243 commit ec5e1f3

File tree

4 files changed

+110
-14
lines changed

4 files changed

+110
-14
lines changed

lib/Biodiverse/GUI/Canvas/Grid.pm

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,24 @@ sub new {
4242
$self->init_legend(%args, parent => $self);
4343

4444
$self->{callbacks} = {
45-
map => sub {shift->draw_cells_cb(@_)},
46-
highlights => sub {shift->plot_highlights(@_)},
47-
overlays => sub {shift->_bounding_box_page_units(@_)},
48-
underlays => sub {},
49-
legend => sub {shift->get_legend->draw(@_)},
50-
sel_rect => sub {shift->draw_selection_rect (@_)},
51-
range_outlines => undef,
45+
map => sub {shift->draw_cells_cb(@_)},
46+
highlights => sub {shift->plot_highlights(@_)},
47+
overlays => sub {shift->_bounding_box_page_units(@_)},
48+
underlays => sub {},
49+
legend => sub {shift->get_legend->draw(@_)},
50+
sel_rect => sub {shift->draw_selection_rect(@_)},
51+
range_convex_hulls => undef,
52+
range_circumcircles => undef,
5253
};
53-
$self->{callback_order} = [qw /underlays map overlays legend range_outlines highlights sel_rect/];
54+
$self->{callback_order} = [qw /
55+
underlays
56+
map
57+
overlays
58+
legend
59+
range_convex_hulls
60+
range_circumcircles
61+
highlights sel_rect
62+
/];
5463

5564
return $self;
5665
}
@@ -629,10 +638,19 @@ sub plot_highlights {
629638
return FALSE;
630639
}
631640

632-
sub clear_range_outlines {
641+
sub clear_range_convex_hulls {
633642
my $self = shift;
634643
$self->set_overlay(
635-
cb_target => 'range_outlines',
644+
cb_target => 'range_convex_hulls',
645+
plot_on_top => 1,
646+
data => undef,
647+
);
648+
}
649+
650+
sub clear_range_circumcircles {
651+
my $self = shift;
652+
$self->set_overlay(
653+
cb_target => 'range_circumcircles',
636654
plot_on_top => 1,
637655
data => undef,
638656
);
@@ -663,7 +681,19 @@ sub set_overlay {
663681
$linewidth ||= 1;
664682

665683
my $cb;
666-
if (is_blessed_ref ($data->[0])) {
684+
if (is_blessed_ref ($data) && $data->isa('Biodiverse::Geometry::Circle')) {
685+
$cb = sub {
686+
my ($self, $cx) = @_;
687+
$cx->set_matrix($self->{matrix});
688+
$cx->set_source_rgba(@rgba);
689+
# line width should be an option in the GUI
690+
$cx->set_line_width(max($cx->device_to_user_distance($linewidth, $linewidth)));
691+
$cx->arc(@{$data->centre}, $data->radius, 0, 2.0 * PI);
692+
$cx->close_path;
693+
$cx->$stroke_or_fill;
694+
}
695+
}
696+
elsif (is_blessed_ref ($data->[0])) {
667697
$cb = sub {
668698
my ($self, $cx) = @_;
669699
$cx->set_matrix($self->{matrix});

lib/Biodiverse/GUI/Tabs/Labels.pm

Lines changed: 52 additions & 3 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_circumcircle
402403
highlight_paths_on_tree
403404
separator
404405
background_colour
@@ -912,6 +913,25 @@ sub get_highlight_label_range_convex_hulls {
912913
$_[0]->{highlight_label_range_convex_hulls};
913914
}
914915

916+
sub set_highlight_label_range_circumcircles {
917+
my ($self, $value) = @_;
918+
919+
$self->{highlight_label_range_circumcircles} = !!$value;
920+
921+
return;
922+
}
923+
924+
sub toggle_highlight_label_range_circumcircles {
925+
my ($self, $value) = @_;
926+
927+
$self->{highlight_label_range_circumcircles}
928+
= !$self->{highlight_label_range_circumcircles};
929+
}
930+
931+
sub get_highlight_label_range_circumcircles {
932+
$_[0]->{highlight_label_range_circumcircles};
933+
}
934+
915935
sub highlight_label_range_convex_hulls {
916936
my ($self, $node) = @_;
917937

@@ -923,7 +943,7 @@ sub highlight_label_range_convex_hulls {
923943
my $label_hash = $bd->get_labels_ref->get_element_hash;
924944

925945
# clear existing
926-
$self->{grid}->clear_range_outlines;
946+
$self->{grid}->clear_range_convex_hulls;
927947

928948
my $cache = $bd->get_cached_value_dor_set_default_href('LABEL_RANGE_CONVEX_HULL_VERTICES');
929949

@@ -934,7 +954,34 @@ sub highlight_label_range_convex_hulls {
934954
//= $bd->get_label_range_convex_hull(label => $label)->GetPoints(0, 0);
935955
$self->{grid}->set_overlay(
936956
type => 'polyline',
937-
cb_target => 'range_outlines',
957+
cb_target => 'range_convex_hulls',
958+
plot_on_top => 1,
959+
data => $data,
960+
colour => COLOUR_BLACK,
961+
alpha => 0.5,
962+
);
963+
}
964+
}
965+
966+
sub highlight_label_range_circumcircles {
967+
my ($self, $node) = @_;
968+
969+
return if !$self->get_highlight_label_range_circumcircles;
970+
971+
my $terminal_elements = $node->get_terminal_elements;
972+
973+
my $bd = $self->get_base_ref;
974+
my $label_hash = $bd->get_labels_ref->get_element_hash;
975+
976+
# clear existing
977+
$self->{grid}->clear_range_circumcircles;
978+
979+
foreach my $label (keys %$terminal_elements) {
980+
next LABEL if !exists $label_hash->{$label};
981+
my $data = $bd->get_label_range_circumcircle(label => $label);
982+
$self->{grid}->set_overlay(
983+
type => 'polyline',
984+
cb_target => 'range_circumcircles',
938985
plot_on_top => 1,
939986
data => $data,
940987
colour => COLOUR_BLACK,
@@ -1520,7 +1567,8 @@ sub on_end_phylogeny_hover {
15201567

15211568
return if !$self->do_canvas_hover_flag;
15221569

1523-
$self->{grid}->clear_range_outlines;
1570+
$self->{grid}->clear_range_convex_hulls;
1571+
$self->{grid}->clear_range_circumcircles;
15241572
$self->{grid}->mark_with_circles;
15251573
}
15261574

@@ -1535,6 +1583,7 @@ sub on_phylogeny_highlight {
15351583

15361584
$self->highlight_label_range_marks($node);
15371585
$self->highlight_label_range_convex_hulls($node);
1586+
$self->highlight_label_range_circumcircles($node);
15381587

15391588
if (defined $node) {
15401589
my $text = 'Node: ' . $node->get_name;

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_circumcircle
421422
highlight_paths_on_tree
422423
separator
423424
plot_branches_by
@@ -1208,6 +1209,7 @@ sub on_phylogeny_highlight {
12081209

12091210
$self->highlight_label_range_marks($node);
12101211
$self->highlight_label_range_convex_hulls($node);
1212+
$self->highlight_label_range_circumcircles($node);
12111213

12121214
return;
12131215
}

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_circumcircle => {
1336+
type => 'Gtk3::CheckMenuItem',
1337+
label => 'Highlight groups on map with range circumcircles',
1338+
tooltip => 'When hovering the mouse over a tree branch, '
1339+
. 'plot a circumcircle containing the range of each subtending label.',
1340+
event => 'toggled',
1341+
callback => sub {
1342+
my ($self, $widget) = @_;
1343+
$self->set_highlight_label_range_circumcircles($widget->get_active);
1344+
},
1345+
active => sub {
1346+
my ($self) = @_;
1347+
$self->get_highlight_label_range_circumcircles;
1348+
},
1349+
},
13351350
highlight_paths_on_tree => {
13361351
type => 'Gtk3::CheckMenuItem',
13371352
label => 'Highlight paths on tree',

0 commit comments

Comments
 (0)