diff --git a/lib/Biodiverse/GUI/Dendrogram.pm b/lib/Biodiverse/GUI/Dendrogram.pm index ed2be02ae..0cd9c3087 100644 --- a/lib/Biodiverse/GUI/Dendrogram.pm +++ b/lib/Biodiverse/GUI/Dendrogram.pm @@ -1627,16 +1627,20 @@ 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"); @@ -1644,7 +1648,7 @@ sub on_map_index_combo_changed { $self->recolour_cluster_lines($self->get_processed_nodes); - $self->{map}->update_legend; + $map->update_legend; } else { $self->{analysis_list_index} = undef; @@ -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 { diff --git a/lib/Biodiverse/GUI/Grid.pm b/lib/Biodiverse/GUI/Grid.pm index f3a7183cf..6dfad79ec 100644 --- a/lib/Biodiverse/GUI/Grid.pm +++ b/lib/Biodiverse/GUI/Grid.pm @@ -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; diff --git a/lib/Biodiverse/GUI/Legend.pm b/lib/Biodiverse/GUI/Legend.pm index 83ea2e307..1e213e451 100644 --- a/lib/Biodiverse/GUI/Legend.pm +++ b/lib/Biodiverse/GUI/Legend.pm @@ -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 diff --git a/lib/Biodiverse/GUI/Tabs/Clustering.pm b/lib/Biodiverse/GUI/Tabs/Clustering.pm index 573904d26..b4a8d7b19 100644 --- a/lib/Biodiverse/GUI/Tabs/Clustering.pm +++ b/lib/Biodiverse/GUI/Tabs/Clustering.pm @@ -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}) { @@ -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