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-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 154     154   5408 use 5.008002;
  154         515  
19 154     154   731 use strict;
  154         315  
  154         3107  
20 154     154   736 use warnings;
  154         283  
  154         3968  
21 154     154   708 use Carp;
  154         279  
  154         8604  
22 154     154   878 use Excel::Writer::XLSX::Chart;
  154         301  
  154         79079  
23              
24             our @ISA = qw(Excel::Writer::XLSX::Chart);
25             our $VERSION = '1.07';
26              
27              
28             ###############################################################################
29             #
30             # new()
31             #
32             #
33             sub new {
34              
35 156     156 0 1095 my $class = shift;
36 156         671 my $self = Excel::Writer::XLSX::Chart->new( @_ );
37              
38 156   100     903 $self->{_subtype} = $self->{_subtype} || 'clustered';
39 156         383 $self->{_horiz_val_axis} = 0;
40              
41             # Override and reset the default axis values.
42 156 100       640 if ( $self->{_subtype} eq 'percent_stacked' ) {
43 1         3 $self->{_y_axis}->{_defaults}->{num_format} = '0%';
44             }
45              
46 156         661 $self->set_y_axis();
47              
48             # Set the available data label positions for this chart type.
49 156         317 $self->{_label_position_default} = 'outside_end';
50             $self->{_label_positions} = {
51 156         680 center => 'ctr',
52             inside_base => 'inBase',
53             inside_end => 'inEnd',
54             outside_end => 'outEnd',
55             };
56              
57 156         362 bless $self, $class;
58              
59 156         557 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 308     308   602 my $self = shift;
72              
73             # Write the c:barChart element.
74 308         988 $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 308     308   551 my $self = shift;
87 308         1032 my %args = @_;
88              
89 308         564 my @series;
90 308 100       1028 if ( $args{primary_axes} ) {
91 154         1326 @series = $self->_get_primary_axes_series;
92             }
93             else {
94 154         1071 @series = $self->_get_secondary_axes_series;
95             }
96              
97 308 100       1081 return unless scalar @series;
98              
99 156         531 my $subtype = $self->{_subtype};
100 156 100       695 $subtype = 'percentStacked' if $subtype eq 'percent_stacked';
101              
102             # Set a default overlap for stacked charts.
103 156 100       855 if ($self->{_subtype} =~ /stacked/) {
104 3 50       21 if (!defined $self->{_series_overlap_1}) {
105 3         10 $self->{_series_overlap_1} = 100;
106             }
107             }
108              
109 156         755 $self->xml_start_tag( 'c:barChart' );
110              
111             # Write the c:barDir element.
112 156         682 $self->_write_bar_dir();
113              
114             # Write the c:grouping element.
115 156         1262 $self->_write_grouping( $subtype );
116              
117             # Write the c:ser elements.
118 156         1273 $self->_write_ser( $_ ) for @series;
119              
120 156 100       991 if ( $args{primary_axes} ) {
121             # Write the c:gapWidth element.
122 154         1630 $self->_write_gap_width( $self->{_series_gap_1} );
123              
124             # Write the c:overlap element.
125 154         1448 $self->_write_overlap( $self->{_series_overlap_1} );
126             }
127             else {
128             # Write the c:gapWidth element.
129 2         10 $self->_write_gap_width( $self->{_series_gap_2} );
130              
131             # Write the c:overlap element.
132 2         8 $self->_write_overlap( $self->{_series_overlap_2} );
133             }
134              
135             # Write the c:axId elements
136 156         1511 $self->_write_axis_ids( %args );
137              
138 156         576 $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 156     156   401 my $self = shift;
151 156         387 my $val = 'col';
152              
153 156         481 my @attributes = ( 'val' => $val );
154              
155 156         608 $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__