Skip to content

Commit

Permalink
Cluster tab: Update index legend correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnlaffan committed Jan 1, 2024
1 parent 5bd7af4 commit 98fb9f3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
18 changes: 11 additions & 7 deletions lib/Biodiverse/GUI/Dendrogram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1627,24 +1627,28 @@ sub on_map_index_combo_changed {
my $iter = $combo->get_active_iter;

if ($iter) {

$index = $combo->get_model->get($iter, 0);
$self->{analysis_list_index} = $index;

my @minmax = $self->get_plot_min_max_values;
$self->{analysis_min} = $minmax[0];
$self->{analysis_max} = $minmax[1];
my $map = $self->{map};

my @minmax = $self->get_parent_tab->set_plot_min_max_values;

# say "[Dendrogram] Setting grid to use index $index";
$self->{map}->set_legend_min_max(@minmax);
# must set this before legend min max
$map->set_legend_colour_mode_from_list_and_index (
list => $self->{analysis_list_name},
index => $self->{analysis_list_index},
);
$map->set_legend_min_max(@minmax);
$self->get_parent_tab->on_colour_mode_changed;

$self->set_cluster_colour_mode(value => "list-values");
$self->recolour_cluster_elements();

$self->recolour_cluster_lines($self->get_processed_nodes);

$self->{map}->update_legend;
$map->update_legend;
}
else {
$self->{analysis_list_index} = undef;
Expand Down Expand Up @@ -1688,7 +1692,7 @@ sub set_plot_min_max_values {
$self->{analysis_min} = $min;
$self->{analysis_max} = $max;

return;
return wantarray ? ($min, $max) : [$min, $max];
}

sub get_plot_min_max_values {
Expand Down
5 changes: 5 additions & 0 deletions lib/Biodiverse/GUI/Grid.pm
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ sub update_legend {
return;
}

sub set_legend_colour_mode_from_list_and_index {
my $self = shift;
return $self->get_legend->set_colour_mode_from_list_and_index(@_);
}

sub set_legend_mode {
my $self = shift;
my $mode = shift;
Expand Down
3 changes: 3 additions & 0 deletions lib/Biodiverse/GUI/Legend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,9 @@ sub get_colour_ratio {

state $centre_colour = Gtk2::Gdk::Color->parse('#ffffbf');

# Perhaps should handle cases where min or max are zero,
# but those should not be passed anyway so an error is
# appropriate.
my $extreme = exp (max (abs log $min, log $max));

return $centre_colour
Expand Down
12 changes: 5 additions & 7 deletions lib/Biodiverse/GUI/Tabs/Clustering.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1899,6 +1899,8 @@ sub recolour {
# need to update the grid before the tree else the grid is not changed properly
$self->set_plot_min_max_values;
$self->{grid}->set_legend_mode($self->{colour_mode});
# $self->{grid}->set_legend_min_max($self->get_plot_min_max_values);
# $self->{grid}->update_legend();

$self->{dendrogram}->recolour();
if ($args{all_elements}) {
Expand All @@ -1915,22 +1917,18 @@ sub set_plot_min_max_values {

return if ! defined $list || ! defined $index;

my $stats = $self->{stats}{$list}{$index};
if (not $stats) {
$stats = $self->{output_ref}->get_list_stats (
my $stats = $self->{stats}{$list}{$index}
//= $self->{output_ref}->get_list_stats (
list => $list,
index => $index,
);
}
$self->{plot_min_value} = $stats->{$self->{PLOT_STAT_MIN} || 'MIN'};
$self->{plot_max_value} = $stats->{$self->{PLOT_STAT_MAX} || 'MAX'};
$self->set_legend_ltgt_flags ($stats);
$self->{dendrogram}->set_plot_min_max_values ($self->get_plot_min_max_values);

return;
return $self->{dendrogram}->set_plot_min_max_values ($self->get_plot_min_max_values);
}
# Same as the version in Spatial.pm except it calls
Expand Down

0 comments on commit 98fb9f3

Please sign in to comment.