Clicker/Decoration/OverAxis.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod n/a totaltotal 0.0% 0 / 74 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Chart::Clicker::Decoration::OverAxis;
2 $Chart::Clicker::Decoration::OverAxis::VERSION = '2.90';
3 use Moose;
4  
5 extends 'Chart::Clicker::Container';
6  
7 # ABSTRACT: An axis drawn over data
8  
9 use Graphics::Color::RGB;
10 use Graphics::Primitive::Operation::Fill;
11 use Graphics::Primitive::Paint::Solid;
12 use Layout::Manager::Flow;
13  
14  
15 has 'axis_height' => (
16 is => 'rw',
17 isa => 'Num',
18 default => 20
19 );
20  
21  
22 has '+background_color' => (
23 # is => 'rw',
24 # isa => 'Graphics::Color::RGB',
25 default => sub {
26 Graphics::Color::RGB->new(
27 red => .18, green => .17, blue => .17, alpha => 1
28 )
29 }
30 );
31  
32  
33 has 'border_color' => (
34 is => 'rw',
35 isa => 'Graphics::Color::RGB',
36 default => sub {
37 Graphics::Color::RGB->new(
38 red => 1, green => 1, blue => 1, alpha => 1
39 )
40 }
41 );
42  
43  
44 has 'border_width' => (
45 is => 'rw',
46 isa => 'Num',
47 default => 2
48 );
49  
50  
51 has 'context' => (
52 is => 'rw',
53 isa => 'Str',
54 required => 1
55 );
56  
57  
58 has 'font' => (
59 is => 'rw',
60 isa => 'Graphics::Primitive::Font',
61 default => sub { Graphics::Primitive::Font->new }
62 );
63  
64  
65 has '+layout_manager' => (
66 default => sub { Layout::Manager::Compass->new }
67 );
68  
69  
70 has 'text_color' => (
71 is => 'rw',
72 isa => 'Graphics::Color::RGB',
73 default => sub {
74 Graphics::Color::RGB->new(
75 red => 1, green => 1, blue => 1, alpha => 1
76 )
77 }
78 );
79  
80 override('prepare', sub {
81 my ($self) = @_;
82  
83 $self->height($self->axis_height);
84  
85 my $ctx = $self->clicker->get_context($self->context);
86  
87 my $ticks = $ctx->domain_axis->tick_values;
88 foreach my $tick (@{ $ticks }) {
89  
90 my $tb = Graphics::Primitive::TextBox->new(
91 text => $tick,
92 color => $self->text_color,
93 horizontal_alignment => 'center',
94 vertical_alignment => 'center',
95 font => $self->font
96 );
97  
98 $self->add_component($tb, 'w');
99 }
100 super;
101 });
102  
103 override('finalize', sub {
104 my ($self) = @_;
105  
106 my $ctx = $self->clicker->get_context($self->context);
107 my $domain = $ctx->domain_axis;
108 my $range = $ctx->range_axis;
109  
110 my $y = $range->mark($self->height, $range->baseline);
111  
112 my $axis_y = $y - ($self->axis_height / 2);
113  
114 $self->origin->x(0);
115 $self->origin->y($axis_y);
116 $self->border->top->width($self->border_width);
117 $self->border->bottom->width($self->border_width);
118 $self->border->color($self->border_color);
119 $self->minimum_height($self->axis_height);
120 $self->height($self->axis_height);
121  
122 my $ticks = $domain->tick_values;
123 for my $i (0 .. $#{ $ticks }) {
124 my $tick = $ticks->[$i];
125  
126 my $comp = $self->get_component($i);
127 $comp->width($self->width / scalar(@{ $ticks }));
128 $comp->origin->x(
129 $domain->mark($self->width, $tick) - $comp->width / 2
130 );
131 $comp->height($self->axis_height);
132 }
133 });
134  
135 __PACKAGE__->meta->make_immutable;
136  
137 no Moose;
138  
139 1;
140  
141 __END__