Skip to content

Commit

Permalink
GUI Labels tab: Update the side menu to handle more cases
Browse files Browse the repository at this point in the history
And in the process, we now keep track of the plot mode
across trees.  So if a user wants depth based plotting
then this is consistent as the tree is changed.
  • Loading branch information
shawnlaffan committed Jan 4, 2024
1 parent a88fc21 commit eae7423
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 91 deletions.
71 changes: 0 additions & 71 deletions bin/ui/hboxLabelsPage.ui
Original file line number Diff line number Diff line change
Expand Up @@ -241,77 +241,6 @@
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem" id="separatormenuitem1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem_labels_tree">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Tree</property>
<property name="use_underline">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="phylogeny_plot_length">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Plot branches using their lengths. </property>
<property name="label" translatable="yes">Length</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_as_radio">True</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="phylogeny_plot_depth">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Plot branches as a function of depth from the root node.</property>
<property name="label" translatable="yes">Depth</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
<property name="group">phylogeny_plot_length</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="highlight_groups_on_map_labels_tab">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">When hovering on a branch,
highlight the groups on the grid
in which it is found.
</property>
<property name="label" translatable="yes">Highlight groups on map?</property>
<property name="use_underline">True</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkCheckMenuItem" id="use_highlight_path_changed1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">When hovering over a cell on the map,
highlight the paths from the tip to the root of the tree
for labels found in that group. </property>
<property name="label" translatable="yes">Highlight node paths for groups?</property>
<property name="use_underline">True</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem" id="menuitem_labels_set_tree_line_widths">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="tooltip_text" translatable="yes">Set the width of the tree branches.
Does not affect the vertical connectors.</property>
<property name="label" translatable="yes">Set tree branch line widths</property>
<property name="use_underline">True</property>
</object>
</child>
</object>
</child>
</object>
Expand Down
67 changes: 47 additions & 20 deletions lib/Biodiverse/GUI/Tabs/Labels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,11 @@ sub new {

$self->get_xmlpage_object("btnSelectToolVL")->set_active(1);

# CONVERT THIS TO A HASH BASED LOOP, as per Clustering.pm
# plot length triggers depth and vice versa
$xml->get_object('phylogeny_plot_length')->signal_connect_swapped(toggled => \&on_phylogeny_plot_mode_changed, $self);
$xml->get_object('highlight_groups_on_map_labels_tab')->signal_connect_swapped(activate => \&on_highlight_groups_on_map_changed, $self);
$xml->get_object('use_highlight_path_changed1')->signal_connect_swapped(activate => \&on_use_highlight_path_changed, $self);
$xml->get_object('menuitem_labels_show_legend')->signal_connect_swapped(toggled => \&on_show_hide_legend, $self);
$xml->get_object('menuitem_labels_set_tree_line_widths')->signal_connect_swapped(activate => \&on_set_tree_line_widths, $self);

$xml->get_object('menuitem_labels_show_legend')->signal_connect_swapped(
toggled => \&on_show_hide_legend,
$self
);

foreach my $type_option (qw /auto linear log/) {
my $radio_item = 'radiomenuitem_grid_colouring_' . $type_option;
$xml->get_object($radio_item)->signal_connect_swapped(
Expand Down Expand Up @@ -330,10 +327,22 @@ sub init_dendrogram {
sub get_tree_menu_items {
my $self = shift;

my $dendro_plot_mode_callback = sub {
my ($self, $mode_string) = @_;
$mode_string ||= 'length';
say "[Labels tab] Changing mode to $mode_string";
$self->{plot_mode} = $mode_string;
return if !$self->{project}->get_selected_phylogeny;
my $dendrogram = $self->{dendrogram};
if ($dendrogram) {
$self->{dendrogram}->set_plot_mode($mode_string)
};
};

my @menu_items = (
{
type => 'Gtk2::MenuItem',
label => 'Tree controls',
label => 'Tree options:',
tooltip => "Options to work with the displayed tree "
. "(this is the same as the one selected at "
. "the project level)",
Expand All @@ -347,27 +356,39 @@ sub get_tree_menu_items {
label => 'Length',
event => 'activate',
callback => sub {
my $self = shift;
state $mode_string = 'length';
say "[Labels tab] Changing mode to $mode_string";
$self->{plot_mode} = $mode_string;
$self->{dendrogram}->set_plot_mode($mode_string);
$dendro_plot_mode_callback->($self, 'length');
},
},
{
type => 'Gtk2::RadioMenuItem',
label => 'Depth',
event => 'activate',
callback => sub {
my $self = shift;
state $mode_string = 'depth';
say "[Labels tab] Changing mode to $mode_string";
$self->{plot_mode} = $mode_string;
$self->{dendrogram}->set_plot_mode($mode_string);
$dendro_plot_mode_callback->($self, 'depth');
},
},
],
},
{
type => 'Gtk2::CheckMenuItem',
label => 'Highlight groups on map?',
tooltip => 'When hovering the mouse over a tree branch, '
. 'highlight the groups on the map in which it is found.',
event => 'toggled',
callback => \&on_highlight_groups_on_map_changed,
active => 1,
self_key => 'checkbox_show_tree_legend',
},
{
type => 'Gtk2::CheckMenuItem',
label => 'Highlight paths on tree?',
tooltip => "When hovering over a group on the map, highlight the paths "
. "connecting the tips of the tree (that match labels in the group) "
. "to the root.",
event => 'toggled',
callback => \&on_use_highlight_path_changed,
active => 1,
},
{
type => 'Gtk2::SeparatorMenuItem',
},
Expand All @@ -389,6 +410,7 @@ sub get_tree_menu_items {
event => 'activate',
callback => sub {
my $tree_ref = $self->{project}->get_selected_phylogeny;
return if !$tree_ref;
return Biodiverse::GUI::Export::Run($tree_ref);
},
},
Expand Down Expand Up @@ -816,6 +838,10 @@ sub set_phylogeny_options_sensitive {
my $self = shift;
my $enabled = shift;

# These are handled differently now.
# Leaving code as a reminder, but returning early.
return;

my $page = $self->{xmlPage};

for my $widget (
Expand All @@ -837,7 +863,8 @@ sub on_selected_phylogeny_changed {

$self->{dendrogram}->clear;
if ($phylogeny) {
$self->{dendrogram}->set_cluster($phylogeny, 'length'); # now storing tree objects directly
# now storing tree objects directly
$self->{dendrogram}->set_cluster($phylogeny, $self->{plot_mode} //= 'length');
$self->set_phylogeny_options_sensitive(1);
}
else {
Expand Down

0 comments on commit eae7423

Please sign in to comment.