| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Excel::Writer::XLSX::Chart::Bar; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | ############################################################################### | 
| 4 |  |  |  |  |  |  | # | 
| 5 |  |  |  |  |  |  | # Bar - A class for writing Excel Bar 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 | 62 |  |  | 62 |  | 8989 | use 5.008002; | 
|  | 62 |  |  |  |  | 229 |  | 
| 19 | 62 |  |  | 62 |  | 380 | use strict; | 
|  | 62 |  |  |  |  | 117 |  | 
|  | 62 |  |  |  |  | 1275 |  | 
| 20 | 62 |  |  | 62 |  | 291 | use warnings; | 
|  | 62 |  |  |  |  | 122 |  | 
|  | 62 |  |  |  |  | 1640 |  | 
| 21 | 62 |  |  | 62 |  | 328 | use Carp; | 
|  | 62 |  |  |  |  | 136 |  | 
|  | 62 |  |  |  |  | 4092 |  | 
| 22 | 62 |  |  | 62 |  | 411 | use Excel::Writer::XLSX::Chart; | 
|  | 62 |  |  |  |  | 130 |  | 
|  | 62 |  |  |  |  | 42559 |  | 
| 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 | 68 |  |  | 68 | 0 | 2680 | my $class = shift; | 
| 36 | 68 |  |  |  |  | 293 | my $self  = Excel::Writer::XLSX::Chart->new( @_ ); | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 68 |  | 100 |  |  | 360 | $self->{_subtype}           = $self->{_subtype} || 'clustered'; | 
| 39 | 68 |  |  |  |  | 152 | $self->{_cat_axis_position} = 'l'; | 
| 40 | 68 |  |  |  |  | 128 | $self->{_val_axis_position} = 'b'; | 
| 41 | 68 |  |  |  |  | 121 | $self->{_horiz_val_axis}    = 0; | 
| 42 | 68 |  |  |  |  | 133 | $self->{_horiz_cat_axis}    = 1; | 
| 43 | 68 |  |  |  |  | 116 | $self->{_show_crosses}      = 0; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | # Override and reset the default axis values. | 
| 46 | 68 |  |  |  |  | 214 | $self->{_x_axis}->{_defaults}->{major_gridlines} = { visible => 1 }; | 
| 47 | 68 |  |  |  |  | 185 | $self->{_y_axis}->{_defaults}->{major_gridlines} = { visible => 0 }; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 68 | 100 |  |  |  | 228 | if ( $self->{_subtype} eq 'percent_stacked' ) { | 
| 50 | 1 |  |  |  |  | 2 | $self->{_x_axis}->{_defaults}->{num_format} = '0%'; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 | 68 |  |  |  |  | 260 | $self->set_x_axis(); | 
| 54 | 68 |  |  |  |  | 250 | $self->set_y_axis(); | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | # Set the available data label positions for this chart type. | 
| 57 | 68 |  |  |  |  | 174 | $self->{_label_position_default} = 'outside_end'; | 
| 58 |  |  |  |  |  |  | $self->{_label_positions} = { | 
| 59 | 68 |  |  |  |  | 297 | center      => 'ctr', | 
| 60 |  |  |  |  |  |  | inside_base => 'inBase', | 
| 61 |  |  |  |  |  |  | inside_end  => 'inEnd', | 
| 62 |  |  |  |  |  |  | outside_end => 'outEnd', | 
| 63 |  |  |  |  |  |  | }; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 68 |  |  |  |  | 181 | bless $self, $class; | 
| 66 | 68 |  |  |  |  | 248 | return $self; | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | ############################################################################### | 
| 71 |  |  |  |  |  |  | # | 
| 72 |  |  |  |  |  |  | # combine() | 
| 73 |  |  |  |  |  |  | # | 
| 74 |  |  |  |  |  |  | # Override parent method to add an extra check that is required for Bar | 
| 75 |  |  |  |  |  |  | # charts to ensure that their combined chart is on a secondary axis. | 
| 76 |  |  |  |  |  |  | # | 
| 77 |  |  |  |  |  |  | sub combine { | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 1 |  |  | 1 | 1 | 7 | my $self  = shift; | 
| 80 | 1 |  |  |  |  | 1 | my $chart = shift; | 
| 81 |  |  |  |  |  |  |  | 
| 82 | 1 | 50 |  |  |  | 4 | if (!$chart->{_is_secondary}) { | 
| 83 | 0 |  |  |  |  | 0 | carp 'Charts combined with Bar charts must be on a secondary axis'; | 
| 84 | 0 |  |  |  |  | 0 | return; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 | 1 |  |  |  |  | 3 | $self->{_combined} = $chart; | 
| 88 |  |  |  |  |  |  | } | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | ############################################################################## | 
| 92 |  |  |  |  |  |  | # | 
| 93 |  |  |  |  |  |  | # _write_chart_type() | 
| 94 |  |  |  |  |  |  | # | 
| 95 |  |  |  |  |  |  | # Override the virtual superclass method with a chart specific method. | 
| 96 |  |  |  |  |  |  | # | 
| 97 |  |  |  |  |  |  | sub _write_chart_type { | 
| 98 |  |  |  |  |  |  |  | 
| 99 | 130 |  |  | 130 |  | 273 | my $self = shift; | 
| 100 | 130 |  |  |  |  | 401 | my %args = @_; | 
| 101 |  |  |  |  |  |  |  | 
| 102 | 130 | 100 |  |  |  | 446 | if ( $args{primary_axes} ) { | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | # Reverse X and Y axes for Bar charts. | 
| 105 | 65 |  |  |  |  | 172 | my $tmp = $self->{_y_axis}; | 
| 106 | 65 |  |  |  |  | 177 | $self->{_y_axis} = $self->{_x_axis}; | 
| 107 | 65 |  |  |  |  | 145 | $self->{_x_axis} = $tmp; | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 65 | 50 |  |  |  | 348 | if ( $self->{_y2_axis}->{_position} eq 'r' ) { | 
| 110 | 65 |  |  |  |  | 191 | $self->{_y2_axis}->{_position} = 't'; | 
| 111 |  |  |  |  |  |  | } | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | # Write the c:barChart element. | 
| 115 | 130 |  |  |  |  | 408 | $self->_write_bar_chart( @_ ); | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | ############################################################################## | 
| 120 |  |  |  |  |  |  | # | 
| 121 |  |  |  |  |  |  | # _write_bar_chart() | 
| 122 |  |  |  |  |  |  | # | 
| 123 |  |  |  |  |  |  | # Write the  element. | 
| 124 |  |  |  |  |  |  | # | 
| 125 |  |  |  |  |  |  | sub _write_bar_chart { | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 130 |  |  | 130 |  | 219 | my $self = shift; | 
| 128 | 130 |  |  |  |  | 316 | my %args = @_; | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 130 |  |  |  |  | 220 | my @series; | 
| 131 | 130 | 100 |  |  |  | 390 | if ( $args{primary_axes} ) { | 
| 132 | 65 |  |  |  |  | 553 | @series = $self->_get_primary_axes_series; | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  | else { | 
| 135 | 65 |  |  |  |  | 507 | @series = $self->_get_secondary_axes_series; | 
| 136 |  |  |  |  |  |  | } | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 130 | 100 |  |  |  | 457 | return unless scalar @series; | 
| 139 |  |  |  |  |  |  |  | 
| 140 | 67 |  |  |  |  | 196 | my $subtype = $self->{_subtype}; | 
| 141 | 67 | 100 |  |  |  | 253 | $subtype = 'percentStacked' if $subtype eq 'percent_stacked'; | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | # Set a default overlap for stacked charts. | 
| 144 | 67 | 100 |  |  |  | 332 | if ($self->{_subtype} =~ /stacked/) { | 
| 145 | 2 | 50 |  |  |  | 6 | if (!defined $self->{_series_overlap_1}) { | 
| 146 | 2 |  |  |  |  | 4 | $self->{_series_overlap_1} = 100; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  | } | 
| 149 |  |  |  |  |  |  |  | 
| 150 | 67 |  |  |  |  | 296 | $self->xml_start_tag( 'c:barChart' ); | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | # Write the c:barDir element. | 
| 153 | 67 |  |  |  |  | 280 | $self->_write_bar_dir(); | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | # Write the c:grouping element. | 
| 156 | 67 |  |  |  |  | 492 | $self->_write_grouping( $subtype ); | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | # Write the c:ser elements. | 
| 159 | 67 |  |  |  |  | 502 | $self->_write_ser( $_ ) for @series; | 
| 160 |  |  |  |  |  |  |  | 
| 161 | 67 | 100 |  |  |  | 351 | if ( $args{primary_axes} ) { | 
| 162 |  |  |  |  |  |  | # Write the c:gapWidth element. | 
| 163 | 65 |  |  |  |  | 749 | $self->_write_gap_width( $self->{_series_gap_1} ); | 
| 164 |  |  |  |  |  |  |  | 
| 165 |  |  |  |  |  |  | # Write the c:overlap element. | 
| 166 | 65 |  |  |  |  | 538 | $self->_write_overlap( $self->{_series_overlap_1} ); | 
| 167 |  |  |  |  |  |  | } | 
| 168 |  |  |  |  |  |  | else { | 
| 169 |  |  |  |  |  |  | # Write the c:gapWidth element. | 
| 170 | 2 |  |  |  |  | 10 | $self->_write_gap_width( $self->{_series_gap_2} ); | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | # Write the c:overlap element. | 
| 173 | 2 |  |  |  |  | 9 | $self->_write_overlap( $self->{_series_overlap_2} ); | 
| 174 |  |  |  |  |  |  | } | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | # Write the c:axId elements | 
| 177 | 67 |  |  |  |  | 737 | $self->_write_axis_ids( %args ); | 
| 178 |  |  |  |  |  |  |  | 
| 179 | 67 |  |  |  |  | 242 | $self->xml_end_tag( 'c:barChart' ); | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  |  | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  | ############################################################################## | 
| 184 |  |  |  |  |  |  | # | 
| 185 |  |  |  |  |  |  | # _write_bar_dir() | 
| 186 |  |  |  |  |  |  | # | 
| 187 |  |  |  |  |  |  | # Write the  element. | 
| 188 |  |  |  |  |  |  | # | 
| 189 |  |  |  |  |  |  | sub _write_bar_dir { | 
| 190 |  |  |  |  |  |  |  | 
| 191 | 68 |  |  | 68 |  | 140 | my $self = shift; | 
| 192 | 68 |  |  |  |  | 200 | my $val  = 'bar'; | 
| 193 |  |  |  |  |  |  |  | 
| 194 | 68 |  |  |  |  | 196 | my @attributes = ( 'val' => $val ); | 
| 195 |  |  |  |  |  |  |  | 
| 196 | 68 |  |  |  |  | 247 | $self->xml_empty_tag( 'c:barDir', @attributes ); | 
| 197 |  |  |  |  |  |  | } | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | ############################################################################## | 
| 201 |  |  |  |  |  |  | # | 
| 202 |  |  |  |  |  |  | # _write_err_dir() | 
| 203 |  |  |  |  |  |  | # | 
| 204 |  |  |  |  |  |  | # Write the  element. Overridden from Chart class since it is not | 
| 205 |  |  |  |  |  |  | # used in Bar charts. | 
| 206 |  |  |  |  |  |  | # | 
| 207 |  |  |  | 1 |  |  | sub _write_err_dir {} | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | 1; | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  |  | 
| 212 |  |  |  |  |  |  | __END__ |