File Coverage

blib/lib/Excel/Writer/XLSX/Chart/Column.pm
Criterion Covered Total %
statement 54 54 100.0
branch 13 14 92.8
condition 2 2 100.0
subroutine 10 10 100.0
pod 0 1 0.0
total 79 81 97.5


line stmt bran cond sub pod time code
1             package Excel::Writer::XLSX::Chart::Column;
2              
3             ###############################################################################
4             #
5             # Column - A class for writing Excel Column 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-2019, 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 133     133   4824 use 5.008002;
  133         499  
19 133     133   704 use strict;
  133         280  
  133         2741  
20 133     133   640 use warnings;
  133         263  
  133         3585  
21 133     133   732 use Carp;
  133         319  
  133         8706  
22 133     133   960 use Excel::Writer::XLSX::Chart;
  133         315  
  133         70974  
23              
24             our @ISA = qw(Excel::Writer::XLSX::Chart);
25             our $VERSION = '1.03';
26              
27              
28             ###############################################################################
29             #
30             # new()
31             #
32             #
33             sub new {
34              
35 135     135 0 1054 my $class = shift;
36 135         731 my $self = Excel::Writer::XLSX::Chart->new( @_ );
37              
38 135   100     761 $self->{_subtype} = $self->{_subtype} || 'clustered';
39 135         309 $self->{_horiz_val_axis} = 0;
40              
41             # Override and reset the default axis values.
42 135 100       491 if ( $self->{_subtype} eq 'percent_stacked' ) {
43 1         2 $self->{_y_axis}->{_defaults}->{num_format} = '0%';
44             }
45              
46 135         572 $self->set_y_axis();
47              
48             # Set the available data label positions for this chart type.
49 135         306 $self->{_label_position_default} = 'outside_end';
50             $self->{_label_positions} = {
51 135         658 center => 'ctr',
52             inside_base => 'inBase',
53             inside_end => 'inEnd',
54             outside_end => 'outEnd',
55             };
56              
57 135         354 bless $self, $class;
58              
59 135         563 return $self;
60             }
61              
62              
63             ##############################################################################
64             #
65             # _write_chart_type()
66             #
67             # Override the virtual superclass method with a chart specific method.
68             #
69             sub _write_chart_type {
70              
71 266     266   566 my $self = shift;
72              
73             # Write the c:barChart element.
74 266         835 $self->_write_bar_chart( @_ );
75             }
76              
77              
78             ##############################################################################
79             #
80             # _write_bar_chart()
81             #
82             # Write the element.
83             #
84             sub _write_bar_chart {
85              
86 266     266   476 my $self = shift;
87 266         823 my %args = @_;
88              
89 266         609 my @series;
90 266 100       878 if ( $args{primary_axes} ) {
91 133         1229 @series = $self->_get_primary_axes_series;
92             }
93             else {
94 133         1141 @series = $self->_get_secondary_axes_series;
95             }
96              
97 266 100       960 return unless scalar @series;
98              
99 135         421 my $subtype = $self->{_subtype};
100 135 100       636 $subtype = 'percentStacked' if $subtype eq 'percent_stacked';
101              
102             # Set a default overlap for stacked charts.
103 135 100       688 if ($self->{_subtype} =~ /stacked/) {
104 3 50       17 if (!defined $self->{_series_overlap_1}) {
105 3         15 $self->{_series_overlap_1} = 100;
106             }
107             }
108              
109 135         659 $self->xml_start_tag( 'c:barChart' );
110              
111             # Write the c:barDir element.
112 135         579 $self->_write_bar_dir();
113              
114             # Write the c:grouping element.
115 135         1168 $self->_write_grouping( $subtype );
116              
117             # Write the c:ser elements.
118 135         1026 $self->_write_ser( $_ ) for @series;
119              
120 135 100       703 if ( $args{primary_axes} ) {
121             # Write the c:gapWidth element.
122 133         1494 $self->_write_gap_width( $self->{_series_gap_1} );
123              
124             # Write the c:overlap element.
125 133         1253 $self->_write_overlap( $self->{_series_overlap_1} );
126             }
127             else {
128             # Write the c:gapWidth element.
129 2         23 $self->_write_gap_width( $self->{_series_gap_2} );
130              
131             # Write the c:overlap element.
132 2         10 $self->_write_overlap( $self->{_series_overlap_2} );
133             }
134              
135             # Write the c:axId elements
136 135         1314 $self->_write_axis_ids( %args );
137              
138 135         513 $self->xml_end_tag( 'c:barChart' );
139             }
140              
141              
142             ##############################################################################
143             #
144             # _write_bar_dir()
145             #
146             # Write the element.
147             #
148             sub _write_bar_dir {
149              
150 135     135   335 my $self = shift;
151 135         315 my $val = 'col';
152              
153 135         394 my @attributes = ( 'val' => $val );
154              
155 135         574 $self->xml_empty_tag( 'c:barDir', @attributes );
156             }
157              
158              
159             ##############################################################################
160             #
161             # _write_err_dir()
162             #
163             # Write the element. Overridden from Chart class since it is not
164             # used in Bar charts.
165             #
166       1     sub _write_err_dir {}
167              
168              
169             1;
170              
171              
172             __END__