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