File Coverage

blib/lib/Excel/Writer/XLSX/Chart/Doughnut.pm
Criterion Covered Total %
statement 40 41 97.5
branch 2 4 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 1 2 50.0
total 54 60 90.0


line stmt bran cond sub pod time code
1             package Excel::Writer::XLSX::Chart::Doughnut;
2              
3             ###############################################################################
4             #
5             # Doughnut - A class for writing Excel Doughnut charts.
6             #
7             # Used in conjunction with Excel::Writer::XLSX::Chart.
8             #
9             # See formatting note in Excel::Writer::XLSX::Chart.
10             #
11             # Copyright 2000-2020, John McNamara, jmcnamara@cpan.org
12             #
13             # Documentation after __END__
14             #
15              
16             # perltidy with the following options: -mbl=2 -pt=0 -nola
17              
18 11     11   218 use 5.008002;
  11         37  
19 11     11   53 use strict;
  11         20  
  11         216  
20 11     11   48 use warnings;
  11         21  
  11         260  
21 11     11   50 use Carp;
  11         17  
  11         629  
22 11     11   4964 use Excel::Writer::XLSX::Chart::Pie;
  11         28  
  11         3694  
23              
24             our @ISA = qw(Excel::Writer::XLSX::Chart::Pie);
25             our $VERSION = '1.07';
26              
27              
28             ###############################################################################
29             #
30             # new()
31             #
32             #
33             sub new {
34              
35 11     11 0 27 my $class = shift;
36 11         40 my $self = Excel::Writer::XLSX::Chart::Pie->new( @_ );
37              
38 11         72 $self->{_vary_data_color} = 1;
39 11         21 $self->{_hole_size} = 50;
40 11         20 $self->{_rotation} = 0;
41              
42 11         37 bless $self, $class;
43 11         57 return $self;
44             }
45              
46              
47             ###############################################################################
48             #
49             # set_hole_size()
50             #
51             # Set the Doughnut chart hole size.
52             #
53             sub set_hole_size {
54              
55 2     2 1 10 my $self = shift;
56 2         4 my $size = shift;
57              
58 2 50       4 return if !defined $size;
59              
60 2 50 33     10 if ( $size >= 10 && $size <= 90 ) {
61 2         5 $self->{_hole_size} = $size;
62             }
63             else {
64 0         0 carp "Hole size $size outside Excel range: 10 <= size <= 90";
65             }
66             }
67              
68              
69             ##############################################################################
70             #
71             # _write_chart_type()
72             #
73             # Override the virtual superclass method with a chart specific method.
74             #
75             sub _write_chart_type {
76              
77 11     11   37 my $self = shift;
78              
79             # Write the c:doughnutChart element.
80 11         47 $self->_write_doughnut_chart( @_ );
81             }
82              
83              
84             ##############################################################################
85             #
86             # _write_doughnut_chart()
87             #
88             # Write the element. Over-ridden method to remove axis_id code
89             # since Doughnut charts don't require val and cat axes.
90             #
91             sub _write_doughnut_chart {
92              
93 11     11   35 my $self = shift;
94              
95 11         69 $self->xml_start_tag( 'c:doughnutChart' );
96              
97             # Write the c:varyColors element.
98 11         85 $self->_write_vary_colors();
99              
100             # Write the series elements.
101 11         19 $self->_write_ser( $_ ) for @{ $self->{_series} };
  11         112  
102              
103             # Write the c:firstSliceAng element.
104 11         124 $self->_write_first_slice_ang();
105              
106             # Write the c:holeSize element.
107 11         49 $self->_write_hole_size();
108              
109 11         36 $self->xml_end_tag( 'c:doughnutChart' );
110             }
111              
112              
113             ##############################################################################
114             #
115             # _write_hole_size()
116             #
117             # Write the element.
118             #
119             sub _write_hole_size {
120              
121 11     11   22 my $self = shift;
122 11         34 my $val = $self->{_hole_size};
123              
124 11         65 my @attributes = ( 'val' => $val );
125              
126 11         38 $self->xml_empty_tag( 'c:holeSize', @attributes );
127             }
128              
129             1;
130              
131              
132             __END__