Chart-GGPlot

 view release on metacpan or  search on metacpan

lib/Chart/GGPlot/Position/Stack.pm  view on Meta::CPAN

    my $var = $params->at('var');
    unless ($var) {
        return $data;
    }

    my $negative = $data->at($var) < 0;
    my $neg      = $data->select_rows( which($negative) );
    my $pos      = $data->select_rows( which( !$negative ) );

    if ( $neg->nrow ) {
        $neg = collide( $neg, undef, 'position_stack', \&pos_stack,
            map { $_ => $params->at($_) } qw(vjust fill reverse) );
    }
    if ( $pos->nrow ) {
        $pos = collide( $pos, undef, 'position_stack', \&pos_stack,
            map { $_ => $params->at($_) } qw(vjust fill reverse) );
    }

    return $neg->rbind($pos);
}

classmethod stack_var ($data) {
    if ( $data->exists('ymax') ) {
        return 'ymax';
    }
    elsif ( $data->exists('y') ) {
        return 'y';
    }

    warn "Stacking requires either ymin & ymax or y aesthetics";
    return undef;
}

__PACKAGE__->meta->make_immutable;

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Chart::GGPlot::Position::Stack - Position for "stack"

=head1 VERSION

version 0.002003

=head1 DESCRIPTION

This stacks bars on top of each other.

=head1 ATTRIBUTES

=head2 reverse

If true, will reverse the default stacking order.
This is useful if you're rotating both the plot and legend.
Default is false.

=head1 SEE ALSO

L<Chart::GGPlot::Position>

=head1 AUTHOR

Stephan Loyd <sloyd@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2019-2023 by Stephan Loyd.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 0.802 second using v1.01-cache-2.11-cpan-39bf76dae61 )