| 1 | package Chart::Clicker::Decoration::Legend; | ||||||||||
| 2 | 8 | $Chart::Clicker::Decoration::Legend::VERSION = '2.89'; | |||||||||
| 3 | 8 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 8 | extends 'Chart::Clicker::Container'; | |||||||||
| 6 | 8 | with 'Graphics::Primitive::Oriented'; | |||||||||
| 7 | |||||||||||
| 8 | # ABSTRACT: Series name, color key | ||||||||||
| 9 | |||||||||||
| 10 | 8 | ▶ | use Graphics::Primitive::Font; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 8 | ▶ | use Graphics::Primitive::Insets; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 8 | ▶ | use Graphics::Primitive::TextBox; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 8 | ▶ | use Layout::Manager::Flow; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | has '+border' => ( | ||||||||||
| 18 | default => sub { | ||||||||||
| 19 | 7 | ▶ | my $b = Graphics::Primitive::Border->new; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 7 | $b->color(Graphics::Color::RGB->new( red => 0, green => 0, blue => 0)); | |||||||||
| 21 | 7 | $b->width(1); | |||||||||
| 22 | 7 | return $b; | |||||||||
| 23 | } | ||||||||||
| 24 | 8 | ); | |||||||||
| 25 | |||||||||||
| 26 | |||||||||||
| 27 | has 'font' => ( | ||||||||||
| 28 | is => 'rw', | ||||||||||
| 29 | isa => 'Graphics::Primitive::Font', | ||||||||||
| 30 | default => sub { | ||||||||||
| 31 | 7 | ▶ | Graphics::Primitive::Font->new | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 32 | } | ||||||||||
| 33 | 8 | ); | |||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | has 'item_padding' => ( | ||||||||||
| 37 | is => 'rw', | ||||||||||
| 38 | isa => 'Graphics::Primitive::Insets', | ||||||||||
| 39 | default => sub { | ||||||||||
| 40 | 7 | ▶ | Graphics::Primitive::Insets->new({ | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | top => 3, left => 3, bottom => 3, right => 5 | ||||||||||
| 42 | }) | ||||||||||
| 43 | } | ||||||||||
| 44 | 8 | ); | |||||||||
| 45 | |||||||||||
| 46 | |||||||||||
| 47 | has '+layout_manager' => ( | ||||||||||
| 48 | 0 | ▶ | default => sub { Layout::Manager::Flow->new(anchor => 'west', wrap => 1) }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 49 | 8 | lazy => 1 | |||||||||
| 50 | ); | ||||||||||
| 51 | |||||||||||
| 52 | override('prepare', sub { | ||||||||||
| 53 | 0 | ▶ | my ($self, $driver) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | return if $self->component_count > 0; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | |||||||||||
| 57 | 0 | my $ca = $self->clicker->color_allocator; | |||||||||
| 58 | |||||||||||
| 59 | 0 | my $font = $self->font; | |||||||||
| 60 | |||||||||||
| 61 | 0 | my $ii = $self->item_padding; | |||||||||
| 62 | |||||||||||
| 63 | #this makes sure that wrapping works | ||||||||||
| 64 | 0 | $self->width($self->clicker->width); | |||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | if($self->is_vertical) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | # This assumes you aren't changing the layout manager... | ||||||||||
| 68 | 0 | $self->layout_manager->anchor('north'); | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | my $count = 0; | |||||||||
| 72 | 0 | foreach my $ds (@{ $self->clicker->datasets }) { | |||||||||
| 73 | 0 | foreach my $s (@{ $ds->series }) { | |||||||||
| 74 | |||||||||||
| 75 | 0 | ▶ | unless($s->has_name) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | $s->name("Series $count"); | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | my $tb = Graphics::Primitive::TextBox->new( | |||||||||
| 80 | color => $ca->next, | ||||||||||
| 81 | font => $font, | ||||||||||
| 82 | padding => $ii, | ||||||||||
| 83 | text => $s->name | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | 0 | $self->add_component($tb); | |||||||||
| 87 | |||||||||||
| 88 | 0 | $count++; | |||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | super; | |||||||||
| 93 | |||||||||||
| 94 | 0 | $ca->reset; | |||||||||
| 95 | 8 | }); | |||||||||
| 96 | |||||||||||
| 97 | 8 | __PACKAGE__->meta->make_immutable; | |||||||||
| 98 | |||||||||||
| 99 | 8 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 100 | |||||||||||
| 101 | 8 | 1; | |||||||||
| 102 | |||||||||||
| 103 | __END__ | ||||||||||
| 104 | |||||||||||
| 105 | =pod | ||||||||||
| 106 | |||||||||||
| 107 | =head1 NAME | ||||||||||
| 108 | |||||||||||
| 109 | Chart::Clicker::Decoration::Legend - Series name, color key | ||||||||||
| 110 | |||||||||||
| 111 | =head1 VERSION | ||||||||||
| 112 | |||||||||||
| 113 | version 2.89 | ||||||||||
| 114 | |||||||||||
| 115 | =head1 DESCRIPTION | ||||||||||
| 116 | |||||||||||
| 117 | Chart::Clicker::Decoration::Legend draws a legend on a Chart. | ||||||||||
| 118 | |||||||||||
| 119 | =head1 ATTRIBUTES | ||||||||||
| 120 | |||||||||||
| 121 | =head2 border | ||||||||||
| 122 | |||||||||||
| 123 | Set/Get this Legend's L<border|Graphics::Primitive::Border>. | ||||||||||
| 124 | |||||||||||
| 125 | =head2 font | ||||||||||
| 126 | |||||||||||
| 127 | Set/Get the L<font|Graphics::Primitive::Font> used for this legend's items. | ||||||||||
| 128 | |||||||||||
| 129 | =head2 insets | ||||||||||
| 130 | |||||||||||
| 131 | Set/Get this Legend's L<insets|Graphics::Primitive::Insets>. | ||||||||||
| 132 | |||||||||||
| 133 | =head2 item_padding | ||||||||||
| 134 | |||||||||||
| 135 | Set/Get the L<padding|Graphics::Primitive::Insets> for this legend's items. | ||||||||||
| 136 | |||||||||||
| 137 | =head2 layout_manager | ||||||||||
| 138 | |||||||||||
| 139 | Set/Get the layout manager for this lagend. Defaults to | ||||||||||
| 140 | L<Layout::Manager::Flow> with an anchor of C<west> and a C<wrap> of 1. | ||||||||||
| 141 | |||||||||||
| 142 | =head1 AUTHOR | ||||||||||
| 143 | |||||||||||
| 144 | Cory G Watson <gphat@cpan.org> | ||||||||||
| 145 | |||||||||||
| 146 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 147 | |||||||||||
| 148 | This software is copyright (c) 2016 by Cory G Watson. | ||||||||||
| 149 | |||||||||||
| 150 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 151 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 152 | |||||||||||
| 153 | =cut | ||||||||||