| 1 | package Chart::Clicker::Decoration::Annotation; | ||
| 2 | |||
| 3 | $Chart::Clicker::Decoration::Annotation::VERSION = '2.88'; | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use Moose; | ||
| 8 | |||
| 9 | use Graphics::Color::RGB; | ||
| 10 | use Geometry::Primitive::Point; | ||
| 11 | use Layout::Manager::Absolute; | ||
| 12 | |||
| 13 | extends 'Chart::Clicker::Container'; | ||
| 14 | |||
| 15 | has '+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 | |||
| 26 | has '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 | |||
| 39 | has 'key' => ( | ||
| 40 | is => 'rw', | ||
| 41 | isa => 'Num', | ||
| 42 | required => 1, | ||
| 43 | ); | ||
| 44 | |||
| 45 | has 'value' => ( | ||
| 46 | is => 'rw', | ||
| 47 | isa => 'Num', | ||
| 48 | required => 1, | ||
| 49 | ); | ||
| 50 | |||
| 51 | has 'offset' => ( | ||
| 52 | is => 'rw', | ||
| 53 | isa => 'Geometry::Primitive::Point', | ||
| 54 | default => sub { Geometry::Primitive::Point->new( x => 0, y => 0 ) } | ||
| 55 | ); | ||
| 56 | |||
| 57 | has 'text' => ( | ||
| 58 | is => 'rw', | ||
| 59 | isa => 'Str', | ||
| 60 | required => 1 | ||
| 61 | ); | ||
| 62 | |||
| 63 | has 'context' => ( | ||
| 64 | is => 'rw', | ||
| 65 | isa => 'Str', | ||
| 66 | required => 1 | ||
| 67 | ); | ||
| 68 | |||
| 69 | has 'font' => ( | ||
| 70 | is => 'rw', | ||
| 71 | isa => 'Graphics::Primitive::Font', | ||
| 72 | default => sub { Graphics::Primitive::Font->new } | ||
| 73 | ); | ||
| 74 | |||
| 75 | has '+layout_manager' => | ||
| 76 | ( ( default => sub { Layout::Manager::Absolute->new } ), ); | ||
| 77 | |||
| 78 | override( | ||
| 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 | |||
| 98 | override( | ||
| 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 | |||
| 139 | no Moose; | ||
| 140 | |||
| 141 | 1; | ||
| 142 | |||
| 143 | __END__ | ||
| 144 | |||
| 145 | =pod | ||
| 146 | |||
| 147 | =head1 NAME | ||
| 148 | |||
| 149 | Chart::Clicker::Decoration::Annotation | ||
| 150 | |||
| 151 | =head1 VERSION | ||
| 152 | |||
| 153 | version 2.89 | ||
| 154 | |||
| 155 | =head1 DESCRIPTION | ||
| 156 | |||
| 157 | A text annotation that can be put over a chart. You can find an example | ||
| 158 | of an Annotation at L<http://gphat.github.com/chart-clicker/static/images/examples/annotation.png>. | ||
| 159 | |||
| 160 | =head1 NAME | ||
| 161 | |||
| 162 | Chart::Clicker::Decoration::Annotation - Text annotation over data | ||
| 163 | |||
| 164 | =head1 VERSION | ||
| 165 | |||
| 166 | version 2.88 | ||
| 167 | |||
| 168 | =head1 ATTRIBUTES | ||
| 169 | |||
| 170 | =head2 axis_height | ||
| 171 | |||
| 172 | Set/Get the height of the OverAxis that will be drawn. | ||
| 173 | |||
| 174 | =head2 background_color | ||
| 175 | |||
| 176 | Set/Get the background L<color|Graphics::Color::RGB> for this Annotation. | ||
| 177 | |||
| 178 | =head2 color | ||
| 179 | |||
| 180 | Set/Get the font L<color|Graphics::Color::RGB> for this Annotation. | ||
| 181 | |||
| 182 | =head2 context | ||
| 183 | |||
| 184 | Set/Get the context that this Annotation should use. | ||
| 185 | |||
| 186 | =head2 key | ||
| 187 | |||
| 188 | Set/Get the x-axis value for the position of the Annotation. | ||
| 189 | |||
| 190 | =head2 layout_manager | ||
| 191 | |||
| 192 | The layout manager to use for this overaxis. Defaults to a L<Layout::Manager::Absolute>. | ||
| 193 | |||
| 194 | =head2 offset | ||
| 195 | |||
| 196 | Set/Get the L<offset|Geometry::Primitive::Point> from (key,value) for the position of the Annotation. | ||
| 197 | |||
| 198 | =head2 text | ||
| 199 | |||
| 200 | Set/Get the Annotation text. | ||
| 201 | |||
| 202 | =head2 value | ||
| 203 | |||
| 204 | Set/Get the y-axis value for the position of the Annotation. | ||
| 205 | |||
| 206 | =head1 AUTHOR | ||
| 207 | |||
| 208 | Cory G Watson <gphat@cpan.org> | ||
| 209 | |||
| 210 | =head1 COPYRIGHT AND LICENSE | ||
| 211 | |||
| 212 | This software is copyright (c) 2014 by Cold Hard Code, LLC. | ||
| 213 | |||
| 214 | This is free software; you can redistribute it and/or modify it under | ||
| 215 | the same terms as the Perl 5 programming language system itself. | ||
| 216 | |||
| 217 | =head1 AUTHOR | ||
| 218 | |||
| 219 | Cory G Watson <gphat@cpan.org> | ||
| 220 | |||
| 221 | =head1 COPYRIGHT AND LICENSE | ||
| 222 | |||
| 223 | This software is copyright (c) 2016 by Cory G Watson. | ||
| 224 | |||
| 225 | This is free software; you can redistribute it and/or modify it under | ||
| 226 | the same terms as the Perl 5 programming language system itself. | ||
| 227 | |||
| 228 | =cut |