Skip to content

Commit

Permalink
Use a natural sort in the View Labels Tab
Browse files Browse the repository at this point in the history
Closes #614
  • Loading branch information
shawnlaffan committed Sep 22, 2016
1 parent c756b47 commit bb76e32
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/Biodiverse/GUI/Tabs/Labels.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use warnings;
use English ( -no_match_vars );

use Data::Dumper;
use Sort::Naturally qw /nsort ncmp/;

use List::MoreUtils qw /firstidx/;

Expand Down Expand Up @@ -387,7 +388,7 @@ sub sort_by_column {

return
$liststore->get($itera, $col_id) <=> $liststore->get($iterb, $col_id)
|| $label_order * ($liststore->get($itera, 0) cmp $liststore->get($iterb, 0));
|| $label_order * ncmp ($liststore->get($itera, 0), $liststore->get($iterb, 0));
}

sub sort_by_column_numeric_labels {
Expand Down Expand Up @@ -446,11 +447,15 @@ sub make_labels_model {
$self->{labels_model} = Gtk2::ListStore->new(@types);
my $model = $self->{labels_model};

my @labels = $base_ref->get_labels();
my $labels = $base_ref->get_labels();

my $sort_func = $base_ref->labels_are_numeric ? sub {$a <=> $b} : sub {$a cmp $b};
#my $sort_func = $base_ref->labels_are_numeric ? sub {$a <=> $b} : \&ncmp;
my @sorted_labels = $base_ref->labels_are_numeric
? sort {$a <=> $b} @$labels
: nsort @$labels;

foreach my $label (sort $sort_func @labels) {
#foreach my $label (sort $sort_func @labels) {
foreach my $label (@sorted_labels) {
my $iter = $model->append();
$model->set($iter, 0, $label);

Expand Down

0 comments on commit bb76e32

Please sign in to comment.