OFC2/Axis.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« OFC2.pm ↑ Summary OFC2/Bar.pm »
1 package Chart::OFC2::Axis;
2  
3 =head1 NAME
4  
5 Chart::OFC2::Axis - OFC2 axis base module
6  
7 =head1 SYNOPSIS
8  
9 use Chart::OFC2::Axis;
10 my $x_axis = Chart::OFC2::XAxis->new(
11 labels => {
12 labels => [ 'Jan', 'Feb', 'Mar', 'Apr', 'May' ]
13 }
14 );
15  
16 =head1 DESCRIPTION
17  
18 X or Y axis for OFC2.
19  
20 =cut
21  
22 0 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=2.6
23 use Moose::Util::TypeConstraints;
24 use MooseX::StrictConstructor;
25 use MooseX::Aliases;
26  
27 our $VERSION = '0.07';
28  
29 use Chart::OFC2;
30 use Chart::OFC2::Labels;
31 use Chart::OFC2::Types qw( PositiveInt ChartOFC2Labels );
32  
33  
34 =head1 PROPERTIES
35  
36 has 'name' => ( is => 'rw', isa => enum(['x_axis', 'y_axis', 'y_axis_right']), required => 1 );
37 has 'labels' => ( is => 'rw', isa => ChartOFC2Labels, coerce => 1);
38 has 'stroke' => ( is => 'rw', isa => 'Int', );
39 has 'colour' => ( is => 'rw', isa => 'Str', alias => 'color' );
40 has 'offset' => ( is => 'rw', isa => 'Bool', );
41 has 'grid_colour' => ( is => 'rw', isa => 'Str', alias => 'grid_color');
42 has 'is3d' => ( is => 'rw', isa => 'Bool', );
43 has 'steps' => ( is => 'rw', isa => PositiveInt, );
44 has 'visible' => ( is => 'rw', isa => 'Bool', );
45 has 'min' => ( is => 'rw', isa => 'Num|Str|Undef', ); # can be 'a' for auto too
46 has 'max' => ( is => 'rw', isa => 'Num|Str|Undef', ); # can be 'a' for auto too
47  
48 =cut
49  
50 coerce 'Chart::OFC2::XAxis'
51 => from 'HashRef'
52 => via { Chart::OFC2::XAxis->new($_) };
53 coerce 'Chart::OFC2::YAxis'
54 => from 'HashRef'
55 => via { Chart::OFC2::YAxis->new($_) };
56  
57 has 'name' => ( is => 'rw', isa => enum(['x_axis', 'y_axis', 'y_axis_right']), required => 1 );
58 has 'labels' => ( is => 'rw', isa => ChartOFC2Labels, coerce => 1);
59 has 'stroke' => ( is => 'rw', isa => 'Int', );
60 has 'colour' => ( is => 'rw', isa => 'Str', alias => 'color' );
61 has 'offset' => ( is => 'rw', isa => 'Bool', );
62 has 'grid_colour' => ( is => 'rw', isa => 'Str', alias => 'grid_color');
63 has 'is3d' => ( is => 'rw', isa => 'Bool', );
64 has 'steps' => ( is => 'rw', isa => PositiveInt, );
65 has 'visible' => ( is => 'rw', isa => 'Bool', );
66 has 'min' => ( is => 'rw', isa => 'Num|Str|Undef', ); # can be 'a' for auto too
67 has 'max' => ( is => 'rw', isa => 'Num|Str|Undef', ); # can be 'a' for auto too
68  
69 =head1 METHODS
70  
71 =head2 TO_JSON()
72  
73 Returns HashRef that is possible to give to C<encode_json()> function.
74  
75 =cut
76  
77 sub TO_JSON {
78 my ($self) = @_;
79
80 my %json = (
81 map { my $v = $self->$_; (defined $v ? ($_ => $v) : ()) }
82 grep { $_ ne 'name' }
83 map { $_->name } $self->meta->get_all_attributes
84 );
85 $json{'3d'} = delete $json{'is3d'}
86 if (exists $json{'is3d'});
87  
88 return \%json;
89 }
90  
91 =head2 color()
92  
93 Same as colour().
94  
95 =cut
96  
97 sub color {
98 &colour;
99 }
100  
101 =head2 grid_color()
102  
103 Same as grid_colour().
104  
105 =cut
106  
107 sub grid_color {
108 &grid_colour;
109 }
110  
111 __PACKAGE__->meta->make_immutable;
112  
113 1;
114  
115  
116 =head1 Chart::OFC2::XAxis
117  
118 X axis object.
119  
120 extends 'Chart::OFC2::Axis';
121  
122 =cut
123  
124 package Chart::OFC2::XAxis;
125 use Moose;
126 use MooseX::StrictConstructor;
127  
128 extends 'Chart::OFC2::Axis';
129  
130 =head1 PROPERTIES
131  
132 has '+name' => ( default => 'x_axis', );
133 has 'tick_height' => ( is => 'rw', isa => 'Int', );
134  
135 =cut
136  
137 has '+name' => ( default => 'x_axis', );
138 has 'tick_height' => ( is => 'rw', isa => 'Int', );
139  
140 1;
141  
142  
143 =head1 Chart::OFC2::YAxis
144  
145 y axis object.
146  
147 extends 'Chart::OFC2::Axis';
148  
149 =cut
150  
151 package Chart::OFC2::YAxis;
152 use Moose;
153 use MooseX::StrictConstructor;
154  
155 extends 'Chart::OFC2::Axis';
156  
157 =head1 PROPERTIES
158  
159 has '+name' => ( default => 'y_axis' );
160 has 'tick_length' => ( is => 'rw', isa => 'Int', );
161  
162 =cut
163  
164 has '+name' => ( default => 'y_axis' );
165 has 'tick_length' => ( is => 'rw', isa => 'Int', );
166  
167 1;
168  
169  
170 =head1 Chart::OFC2::YAxisRight
171  
172 y axis on the right side object.
173  
174 extends 'Chart::OFC2::YAxis';
175  
176 =cut
177  
178 package Chart::OFC2::YAxisRight;
179  
180 use Moose;
181 use MooseX::StrictConstructor;
182  
183 extends 'Chart::OFC2::YAxis';
184  
185 =head1 PROPERTIES
186  
187 has '+name' => ( default => 'y_axis_right' );
188  
189 =cut
190  
191 has '+name' => ( default => 'y_axis_right' );
192  
193 1;
194  
195  
196 __END__
« OFC2.pm ↑ Summary OFC2/Bar.pm »