1package Chart::Clicker::Decoration::Annotation; 2 3$Chart::Clicker::Decoration::Annotation::VERSION = '2.88'; 4 5use strict; 6use warnings; 7use Moose; 8 9use Graphics::Color::RGB; 10use Geometry::Primitive::Point; 11use Layout::Manager::Absolute; 12 13extends 'Chart::Clicker::Container'; 14 15has '+background_color' => ( 16 default => sub { 17 Graphics::Color::RGB->new( 18 red => 1, 19 green => 1, 20 blue => 1, 21 alpha => 1 22 ); 23 }, 24); 25 26has 'color' => ( 27 is => 'rw', 28 isa => 'Graphics::Color::RGB', 29 default => sub { 30 Graphics::Color::RGB->new( 31 red => 0, 32 green => 0, 33 blue => 0, 34 alpha => 1 35 ); 36 }, 37); 38 39has 'key' => ( 40 is => 'rw', 41 isa => 'Num', 42 required => 1, 43); 44 45has 'value' => ( 46 is => 'rw', 47 isa => 'Num', 48 required => 1, 49); 50 51has 'offset' => ( 52 is => 'rw', 53 isa => 'Geometry::Primitive::Point', 54 default => sub { Geometry::Primitive::Point->new( x => 0, y => 0 ) } 55); 56 57has 'text' => ( 58 is => 'rw', 59 isa => 'Str', 60 required => 1 61); 62 63has 'context' => ( 64 is => 'rw', 65 isa => 'Str', 66 required => 1 67); 68 69has 'font' => ( 70 is => 'rw', 71 isa => 'Graphics::Primitive::Font', 72 default => sub { Graphics::Primitive::Font->new } 73); 74 75has '+layout_manager' => 76 ( ( default => sub { Layout::Manager::Absolute->new } ), ); 77 78override( 79 'prepare', 80 sub { 81 my ( $self, $driver ) = @_; 82 83 my $tb = Graphics::Primitive::TextBox->new( 84 text => $self->text, 85 color => $self->color, 86 font => $self->font, 87 ); 88 my $lay = $driver->get_textbox_layout($tb); 89 $tb->width( $lay->width ); 90 $tb->height( $lay->height ); 91 $tb->origin->x( $self->border->left->width + $self->padding->left ); 92 $tb->origin->y( $self->border->top->width + $self->padding->top ); 93 $self->add_component( $tb, 'c' ); 94 super; 95 } 96); 97 98override( 99 'finalize', 100 sub { 101 my ($self) = @_; 102 103 my $ctx = $self->clicker->get_context( $self->context ); 104 my $domain = $ctx->domain_axis; 105 my $range = $ctx->range_axis; 106 107 my $tb = $self->get_component(0); 108 my $width = 109 $tb->width + 110 $self->border->left->width + 111 $self->border->right->width + 112 $self->padding->left + 113 $self->padding->right; 114 my $height = 115 $tb->height + 116 $self->border->top->width + 117 $self->border->bottom->width + 118 $self->padding->top + 119 $self->padding->bottom; 120 $self->minimum_width($width); 121 $self->width($width); 122 $self->minimum_height($height); 123 $self->height($height); 124 125 my $plot = $self->clicker->plot; 126 my $render_area = $plot->render_area; 127 128 $self->origin->x( ( $self->key - $domain->range->lower ) / 129 ( $domain->range->upper - $domain->range->lower ) * 130 $render_area->width + $self->offset->x ); 131 $self->origin->y( ( $range->range->upper - $self->value ) / 132 ( $range->range->upper - $range->range->lower ) * 133 $render_area->height + $self->offset->y ); 134 } 135); 136 137__PACKAGE__->meta->make_immutable; 138 139no Moose; 140 1411; 142 143__END__ 144 145=pod 146 147=head1 NAME 148 149Chart::Clicker::Decoration::Annotation 150 151=head1 VERSION 152 153version 2.90 154 155=head1 DESCRIPTION 156 157A text annotation that can be put over a chart. You can find an example 158of an Annotation at L<http://gphat.github.com/chart-clicker/static/images/examples/annotation.png>. 159 160=head1 NAME 161 162Chart::Clicker::Decoration::Annotation - Text annotation over data 163 164=head1 VERSION 165 166version 2.88 167 168=head1 ATTRIBUTES 169 170=head2 axis_height 171 172Set/Get the height of the OverAxis that will be drawn. 173 174=head2 background_color 175 176Set/Get the background L<color|Graphics::Color::RGB> for this Annotation. 177 178=head2 color 179 180Set/Get the font L<color|Graphics::Color::RGB> for this Annotation. 181 182=head2 context 183 184Set/Get the context that this Annotation should use. 185 186=head2 key 187 188Set/Get the x-axis value for the position of the Annotation. 189 190=head2 layout_manager 191 192The layout manager to use for this overaxis. Defaults to a L<Layout::Manager::Absolute>. 193 194=head2 offset 195 196Set/Get the L<offset|Geometry::Primitive::Point> from (key,value) for the position of the Annotation. 197 198=head2 text 199 200Set/Get the Annotation text. 201 202=head2 value 203 204Set/Get the y-axis value for the position of the Annotation. 205 206=head1 AUTHOR 207 208Cory G Watson <gphat@cpan.org> 209 210=head1 COPYRIGHT AND LICENSE 211 212This software is copyright (c) 2014 by Cold Hard Code, LLC. 213 214This is free software; you can redistribute it and/or modify it under 215the same terms as the Perl 5 programming language system itself. 216 217=head1 AUTHOR 218 219Cory G Watson <gphat@cpan.org> 220 221=head1 COPYRIGHT AND LICENSE 222 223This software is copyright (c) 2016 by Cory G Watson. 224 225This is free software; you can redistribute it and/or modify it under 226the same terms as the Perl 5 programming language system itself. 227 228=cut 229