Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miscellaneous legend fixes #904

Merged
merged 8 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions lib/Biodiverse/GUI/Dendrogram.pm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ sub new {
# Process changes for the map
if ($map_index_combo) {
$map_index_combo->signal_connect_swapped(
changed => \&on_combo_map_index_changed,
changed => \&on_map_index_combo_changed,
$self,
);
}
Expand Down Expand Up @@ -662,6 +662,9 @@ sub do_slider_move {
$self->recolour_cluster_elements();
$self->recolour_cluster_lines(\@intersecting_nodes);
$self->set_processed_nodes(\@intersecting_nodes);
if ($self->{map}) {
$self->{map}->update_legend;
}

#$self->{last_slide_time} = time;
return;
Expand Down Expand Up @@ -758,6 +761,9 @@ sub do_colour_nodes_below {
$self->recolour_cluster_elements($terminal_element_hash_ref);
$self->recolour_cluster_lines(\@colour_nodes);
$self->set_processed_nodes(\@colour_nodes);
if ($self->{map}) {
$self->{map}->update_legend;
}

return;
}
Expand Down Expand Up @@ -952,10 +958,11 @@ sub recolour_cluster_elements {

$map->colour ($colour_callback);

if ($cluster_colour_mode eq 'list-values') {
$map->set_legend_min_max($analysis_min, $analysis_max);
}
$map->update_legend;
# now called elsewhere
# if ($cluster_colour_mode eq 'list-values') {
# $map->set_legend_min_max($analysis_min, $analysis_max);
# $map->update_legend;
# }

return;
}
Expand Down Expand Up @@ -1605,37 +1612,43 @@ sub on_map_list_combo_changed {
$self->{analysis_list_name} = $list;

$self->setup_map_index_model($self->{tree_node}->get_list_ref(list => $list));
$self->on_combo_map_index_changed;
$self->on_map_index_combo_changed;
}

return;
}

# this should be controlled by the parent tab, not the dendrogram
sub on_combo_map_index_changed {
sub on_map_index_combo_changed {
my $self = shift;
my $combo = shift || $self->{map_index_combo};

my $index = undef;
my $iter = $combo->get_active_iter;

if ($iter) {

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

$self->get_parent_tab->on_colour_mode_changed;
my $map = $self->{map};

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

#print "[Dendrogram] Setting grid to use (spatial) analysis $analysis\n";
# say "[Dendrogram] Setting grid to use index $index";
# 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);

$map->update_legend;
}
else {
$self->{analysis_list_index} = undef;
Expand Down Expand Up @@ -1679,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
13 changes: 7 additions & 6 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 Expand Up @@ -813,12 +818,8 @@ sub hide_some_cells {
CELL:
foreach my $cell (values %{$self->{cells}}) {
# sometimes we are called before all cells have contents
if ($callback->($cell->[INDEX_ELEMENT])) {
$cell->[INDEX_RECT]->hide;
}
else {
$cell->[INDEX_RECT]->show;
}
my $bool = !!$callback->($cell->[INDEX_ELEMENT]);
$cell->[INDEX_RECT]->set_visible($bool);
}

return;
Expand Down
26 changes: 21 additions & 5 deletions lib/Biodiverse/GUI/Legend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ sub hide_current_marks {
return;
}

sub show_current_marks {
my $self = shift;
my $marks = $self->{marks}{current} // [];
foreach my $mark (@$marks) {
$mark->raise_to_top;
$mark->show;
}
return;
}

sub set_gt_flag {
my $self = shift;
my $flag = shift;
Expand Down Expand Up @@ -447,7 +457,7 @@ sub reposition {
$self->{legend_colours_group}->affine_absolute($matrix);

# Reposition the "mark" textboxes
my @mark_arr = @{$self->{marks}{current} // []};
my @mark_arr = @{$self->{marks}{current} //= $self->{marks}{default}};
foreach my $i (0..$#mark_arr) {
my $mark = $mark_arr[$#mark_arr - $i];
# move the mark to right align with the legend
Expand All @@ -472,8 +482,9 @@ sub reposition {

$mark->raise_to_top;
$mark->show;
# say STDERR "Mark $i is " . $mark->get( 'text' );
}

# Reposition value box
if ($self->{value_group}) {
my ($value_x, $value_y) = $self->{value_group}->get('x', 'y');
Expand All @@ -498,7 +509,7 @@ sub reposition {
# Set colouring mode - 'Hue' or 'Sat'
sub set_mode {
my $self = shift;
my $mode = shift;
my $mode = shift // $self->get_mode;

$mode = ucfirst lc $mode;

Expand Down Expand Up @@ -742,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 Expand Up @@ -1016,7 +1030,9 @@ sub set_min_max {
else {
$mark->move ($offset - length ($text) - 0.5, 0);
}
# say STDERR "Mark text $i is $text";
$mark->raise_to_top;
$mark->show;
}

return;
Expand Down Expand Up @@ -1151,7 +1167,7 @@ sub set_text_marks_for_labels {
foreach my $i (0 .. $#strings) {
my $mark = $mark_arr->[$#strings - $i];
$mark->set( text => $strings[$i] );
# $mark->show;
$mark->show;
$mark->raise_to_top;
}

Expand Down Expand Up @@ -1278,7 +1294,7 @@ sub get_colour_method {
sub _make_nonbasic_methods {
my ($pkg) = shift || __PACKAGE__;
my @methods = _get_nonbasic_plot_modes();
print "Calling _make_access_methods for $pkg";
# print "Calling _make_access_methods for $pkg";
no strict 'refs';
foreach my $key (@methods) {
my $method = "get_${key}_mode";
Expand Down
Loading
Loading