OFC2/Pie.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/Line.pm ↑ Summary OFC2/PieValues.pm »
1 package Chart::OFC2::Pie;
2  
3 =head1 NAME
4  
5 Chart::OFC2::Pie - OFC2 Pie chart
6  
7 =head1 SYNOPSIS
8  
9 use Chart::OFC2::Pie;
10
11 my $pie = Chart::OFC2::Pie->new(
12 tip => '#val# of #total#<br>#percent# of 100%',
13 );
14 $pie->values([ (1 .. 5) ]);
15 $pie->values->labels([qw( IE Firefox Opera Wii Other)]);
16 $pie->values->colours([ '#d01f3c', '#356aa0', '#C79810', '#73880A', '#D15600' ]);
17  
18 my $pie2 = Chart::OFC2::Pie->new(
19 values => [
20 { 'value' => 1, 'label' => 'IE', },
21 { 'value' => 2, 'label' => 'Firefox', },
22 ],
23 );
24  
25 my $pie2 = Chart::OFC2::Pie->new(
26 values => [
27 { 'value' => 1, 'label' => 'IE', 'colour' => '#d01f3c' },
28 { 'value' => 2, 'label' => 'Firefox', 'colour' => '#356aa0' },
29 { 'value' => 3, 'label' => 'Opera', 'colour' => '#C79810' },
30 { 'value' => 4, 'label' => 'Wii', 'colour' => '#000000' },
31 { 'value' => 5, 'label' => 'Other', 'colour' => '#D15600' },
32 ],
33 );
34  
35 =head1 DESCRIPTION
36  
37 extends 'Chart::OFC2::Element';
38  
39 =cut
40  
41 0 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=2.6
42 use MooseX::StrictConstructor;
43  
44 our $VERSION = '0.07';
45  
46 extends 'Chart::OFC2::Element';
47  
48 use Chart::OFC2::PieValues;
49  
50 =head1 PROPERTIES
51  
52 =cut
53  
54 has '+type_name' => (default => 'pie');
55 has 'label-colour' => (is => 'rw', isa => 'ArrayRef',);
56 has 'border' => (is => 'rw', isa => 'Str',);
57 has 'animate' => (is => 'rw', isa => 'Bool',);
58 has 'start-angle' => (is => 'rw', isa => 'Int',);
59 has 'gradient-fill' => (is => 'rw', isa => 'Bool',);
60 has 'values' => (is => 'rw', isa => 'Chart::OFC2::PieValues', 'coerce' => 1,);
61  
62 override 'TO_JSON' => sub {
63 my $self = shift;
64
65 my $pie_element = super();
66
67 # get the colours from values attribute if defined
68 # if one of the colour is undef set to #aaaaaa (OFC2 will not show the graph otherwise)
69 $pie_element->{'colours'} = [ map { defined $_ ? $_ : '#aaaaaa' } @{$self->values->colours} ]
70 if (defined $self->values->colours);
71
72 return $pie_element;
73 };
74  
75 1;
76  
77  
78 __END__
« OFC2/Line.pm ↑ Summary OFC2/PieValues.pm »