| 1 | package Imager::Graph::Vertical; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Imager::Graph::Vertical- A super class for line/bar/column/area charts | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | use Imager::Graph::Vertical; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | my $vert = Imager::Graph::Vertical->new; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | $vert->add_column_data_series(\@data, "My data"); | ||||||||||||||||||||||||||||||||||||||||||
| 13 | $vert->add_area_data_series(\@data2, "Area data"); | ||||||||||||||||||||||||||||||||||||||||||
| 14 | $vert->add_stacked_column_data_series(\@data3, "stacked data"); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | $vert->add_line_data_series(\@data4, "line data"); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | my $img = $vert->draw(); | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | use Imager::Graph::Column; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | my $column = Imager::Graph::Column->new; | ||||||||||||||||||||||||||||||||||||||||||
| 20 | $column->add_data_series(\@data, "my data"); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | my $img = $column->draw(); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | This is a base class that implements the functionality for column, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | stacked column, line and area charts where the dependent variable is | ||||||||||||||||||||||||||||||||||||||||||
| 27 | represented in changes in the vertical position. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | The subclasses, L<Imager::Graph::Column>, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | L<Imager::Graph::StackedColumn>, L<Imager::Graph::Line> and | ||||||||||||||||||||||||||||||||||||||||||
| 31 | L<Imager::Graph::Area> simply provide default data series types. | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | use Imager::Graph; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 9 | @ISA = qw(Imager::Graph); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | ▶ | use Imager::Fill; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | our $VERSION = "0.11"; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 9 | ▶ | use constant STARTING_MIN_VALUE => 99999; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | =item add_data_series(\@data, $series_name) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | Add a data series to the graph, of the default type. This requires | ||||||||||||||||||||||||||||||||||||||||||
| 52 | that the graph object be one of the derived graph classes. | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | sub add_data_series { | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_data_series: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 16 | my $data_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 16 | my $series_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 16 | my $series_type = $self->_get_default_series_type(); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 16 | $self->_add_data_series($series_type, $data_ref, $series_name); | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | =item add_column_data_series(\@data, $series_name) | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | Add a column data series to the graph. | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | sub add_column_data_series { | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_column_data_series: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $data_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $series_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | $self->_add_data_series('column', $data_ref, $series_name); | |||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | =item add_stacked_column_data_series(\@data, $series_name) | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | Add a stacked column data series to the graph. | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | sub add_stacked_column_data_series { | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_stacked_column_data_series: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my $data_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $series_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $self->_add_data_series('stacked_column', $data_ref, $series_name); | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | =item add_line_data_series(\@data, $series_name) | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | Add a line data series to the graph. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | sub add_line_data_series { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_line_data_series: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | my $data_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $series_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $self->_add_data_series('line', $data_ref, $series_name); | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =item add_area_data_series(\@data, $series_name) | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | Add a area data series to the graph. | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | sub add_area_data_series { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_area_data_series: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $data_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $series_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $self->_add_data_series('area', $data_ref, $series_name); | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =item set_y_max($value) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | Sets the maximum y value to be displayed. This will be ignored if the | ||||||||||||||||||||||||||||||||||||||||||
| 134 | y_max is lower than the highest value. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | sub set_y_max { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | $_[0]->{'custom_style'}->{'y_max'} = $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_y_max: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | =item set_y_min($value) | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | Sets the minimum y value to be displayed. This will be ignored if the | ||||||||||||||||||||||||||||||||||||||||||
| 145 | y_min is higher than the lowest value. | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub set_y_min { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $_[0]->{'custom_style'}->{'y_min'} = $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_y_min: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | =item set_column_padding($int) | ||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | Sets the padding between columns. This is a percentage of the column | ||||||||||||||||||||||||||||||||||||||||||
| 156 | width. Defaults to 0. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | sub set_column_padding { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | $_[0]->{'custom_style'}->{'column_padding'} = $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_column_padding: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =item set_range_padding($percentage) | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | Sets the padding to be used, as a percentage. For example, if your | ||||||||||||||||||||||||||||||||||||||||||
| 167 | data ranges from 0 to 10, and you have a 20 percent padding, the y | ||||||||||||||||||||||||||||||||||||||||||
| 168 | axis will go to 12. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | Defaults to 10. This attribute is ignored for positive numbers if | ||||||||||||||||||||||||||||||||||||||||||
| 171 | set_y_max() has been called, and ignored for negative numbers if | ||||||||||||||||||||||||||||||||||||||||||
| 172 | set_y_min() has been called. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | sub set_range_padding { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | $_[0]->{'custom_style'}->{'range_padding'} = $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_range_padding: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | =item set_negative_background($color) | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | Sets the background color or fill used below the x axis. | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | sub set_negative_background { | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | $_[0]->{'custom_style'}->{'negative_bg'} = $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_negative_background: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | =item draw() | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | Draw the graph | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | sub draw { | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
draw: called CC=23 SCAR=31.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | 12 | ▶ | if (!$self->_valid_input()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 12 | $self->_style_setup(\%opts); | |||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 12 | my $style = $self->{_style}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 12 | ▶ | $self->_make_img | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | 12 | ▶ | my $img = $self->_get_image() | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 12 | my @image_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 ); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 12 | $self->_set_image_box(\@image_box); | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 12 | my @chart_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 ); | |||||||||||||||||||||||||||||||||||||||||
| 217 | 12 | $self->_draw_legend(\@chart_box); | |||||||||||||||||||||||||||||||||||||||||
| 218 | 12 | ▶ | if ($style->{title}{text}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | $self->_draw_title($img, \@chart_box) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | # Scale the graph box down to the widest graph that can cleanly hold the # of columns. | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 12 | ▶ | return unless $self->_get_data_range(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 12 | $self->_remove_tics_from_chart_box(\@chart_box, \%opts); | |||||||||||||||||||||||||||||||||||||||||
| 226 | 12 | my $column_count = $self->_get_column_count(); | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 12 | my $width = $self->_get_number('width'); | |||||||||||||||||||||||||||||||||||||||||
| 229 | 12 | my $height = $self->_get_number('height'); | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 12 | my $graph_width = $chart_box[2] - $chart_box[0]; | |||||||||||||||||||||||||||||||||||||||||
| 232 | 12 | my $graph_height = $chart_box[3] - $chart_box[1]; | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 12 | my $col_width = ($graph_width - 1) / $column_count; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 12 | ▶ | if ($col_width > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 10 | $graph_width = int($col_width) * $column_count + 1; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 2 | $graph_width = $col_width * $column_count + 1; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 12 | my $tic_count = $self->_get_y_tics(); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 12 | my $tic_distance = ($graph_height-1) / ($tic_count - 1); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 12 | $graph_height = int($tic_distance * ($tic_count - 1)); | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 12 | my $top = $chart_box[1]; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 12 | my $left = $chart_box[0]; | |||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 12 | $self->{'_style'}{'graph_width'} = $graph_width; | |||||||||||||||||||||||||||||||||||||||||
| 250 | 12 | $self->{'_style'}{'graph_height'} = $graph_height; | |||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 12 | my @graph_box = ($left, $top, $left + $graph_width, $top + $graph_height); | |||||||||||||||||||||||||||||||||||||||||
| 253 | 12 | $self->_set_graph_box(\@graph_box); | |||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 12 | my @fill_box = ( $left, $top, $left+$graph_width, $top+$graph_height ); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 12 | ▶ | if ($self->_feature_enabled("graph_outline")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 12 | ▶ | my @line = $self->_get_line("graph.outline") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 12 | $self->_box( | |||||||||||||||||||||||||||||||||||||||||
| 261 | @line, | ||||||||||||||||||||||||||||||||||||||||||
| 262 | box => \@fill_box, | ||||||||||||||||||||||||||||||||||||||||||
| 263 | img => $img, | ||||||||||||||||||||||||||||||||||||||||||
| 264 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 12 | ++$fill_box[0]; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 12 | ++$fill_box[1]; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 12 | --$fill_box[2]; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 12 | --$fill_box[3]; | |||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | $img->box( | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 12 | $self->_get_fill('graph.fill'), | |||||||||||||||||||||||||||||||||||||||||
| 273 | box => \@fill_box, | ||||||||||||||||||||||||||||||||||||||||||
| 274 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 12 | my $min_value = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 12 | my $max_value = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 278 | 12 | my $value_range = $max_value - $min_value; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 12 | my $zero_position; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 12 | ▶ | if ($value_range) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | 12 | $zero_position = $top + $graph_height - (-1*$min_value / $value_range) * ($graph_height-1); | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 12 | ▶ | if ($min_value < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | my @neg_box = ( $left + 1, $zero_position, $left+$graph_width- 1, $top+$graph_height - 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 3 | ▶ | my @neg_fill = $self->_get_fill('negative_bg', \@neg_box) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 3 | $img->box( | |||||||||||||||||||||||||||||||||||||||||
| 290 | @neg_fill, | ||||||||||||||||||||||||||||||||||||||||||
| 291 | box => \@neg_box, | ||||||||||||||||||||||||||||||||||||||||||
| 292 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 3 | $img->line( | |||||||||||||||||||||||||||||||||||||||||
| 294 | x1 => $left+1, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | y1 => $zero_position, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | x2 => $left + $graph_width, | ||||||||||||||||||||||||||||||||||||||||||
| 297 | y2 => $zero_position, | ||||||||||||||||||||||||||||||||||||||||||
| 298 | color => $self->_get_color('outline.line'), | ||||||||||||||||||||||||||||||||||||||||||
| 299 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 12 | $self->_reset_series_counter(); | |||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 12 | ▶ | if ($self->_get_data_series()->{'stacked_column'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | ▶ | return unless $self->_draw_stacked_columns(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 12 | ▶ | if ($self->_get_data_series()->{'column'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 3 | ▶ | return unless $self->_draw_columns(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | 12 | ▶ | if ($self->_get_data_series()->{'line'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | 5 | ▶ | return unless $self->_draw_lines(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 12 | ▶ | if ($self->_get_data_series()->{'area'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | ▶ | return unless $self->_draw_area(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 12 | ▶ | if ($self->_get_y_tics()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 2 | $self->_draw_y_tics(); | |||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | 12 | ▶ | if ($self->_get_labels(\%opts)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 12 | $self->_draw_x_tics(\%opts); | |||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 12 | return $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | sub _get_data_range { | ||||||||||||||||||||||||||||||||||||||||||
| 328 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_data_range: called CC=18 SCAR=42.7
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 12 | my $max_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 12 | my $min_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 12 | my $column_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 12 | my ($sc_min, $sc_max, $sc_cols) = $self->_get_stacked_column_range(); | |||||||||||||||||||||||||||||||||||||||||
| 335 | 12 | my ($c_min, $c_max, $c_cols) = $self->_get_column_range(); | |||||||||||||||||||||||||||||||||||||||||
| 336 | 12 | my ($l_min, $l_max, $l_cols) = $self->_get_line_range(); | |||||||||||||||||||||||||||||||||||||||||
| 337 | 12 | my ($a_min, $a_max, $a_cols) = $self->_get_area_range(); | |||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | # These are side by side... | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 12 | $sc_cols += $c_cols; | |||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 12 | $min_value = $self->_min(STARTING_MIN_VALUE, $sc_min, $c_min, $l_min, $a_min); | |||||||||||||||||||||||||||||||||||||||||
| 343 | 12 | $max_value = $self->_max(0, $sc_max, $c_max, $l_max, $a_max); | |||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 12 | my $config_min = $self->_get_number('y_min'); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 12 | my $config_max = $self->_get_number('y_max'); | |||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | 12 | ▶ | if (defined $config_max && $config_max < $max_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $config_max and $config_max < $max_value
MC/DC0%0/2
defined $config_max and $config_max < $max_value
defined $config_max
$config_max < $max_value
Truth table33%1/3
A and B
A= defined $config_maxB= $config_max < $max_value
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | $config_max = undef; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 12 | ▶ | if (defined $config_min && $config_min > $min_value) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $config_min and $config_min > $min_value
MC/DC0%0/2
defined $config_min and $config_min > $min_value
defined $config_min
$config_min > $min_value
Truth table33%1/3
A and B
A= defined $config_minB= $config_min > $min_value
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $config_min = undef; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 12 | my $range_padding = $self->_get_number('range_padding'); | |||||||||||||||||||||||||||||||||||||||||
| 356 | 12 | ▶ | if (defined $config_min) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $min_value = $config_min; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 12 | ▶ | if ($min_value > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 9 | $min_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 12 | ▶ | if ($range_padding && $min_value < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$range_padding and $min_value < 0
MC/DC0%0/2
$range_padding and $min_value < 0
$range_padding
$min_value < 0
Truth table33%1/3
A and B
A= $range_paddingB= $min_value < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $difference = $min_value * $range_padding / 100; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if ($min_value < -1 && $difference > -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$min_value < -1 and $difference > -1
MC/DC0%0/2
$min_value < -1 and $difference > -1
$min_value < -1
$difference > -1
Truth table0%0/3
A and B
A= $min_value < -1B= $difference > -1
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $difference = -1; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $min_value += $difference; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 12 | ▶ | if (defined $config_max) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $max_value = $config_max; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 12 | ▶ | if ($range_padding && $max_value > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$range_padding and $max_value > 0
MC/DC0%0/2
$range_padding and $max_value > 0
$range_padding
$max_value > 0
Truth table33%1/3
A and B
A= $range_paddingB= $max_value > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | my $difference = $max_value * $range_padding / 100; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | if ($max_value > 1 && $difference < 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$max_value > 1 and $difference < 1
MC/DC0%0/2
$max_value > 1 and $difference < 1
$max_value > 1
$difference < 1
Truth table0%0/3
A and B
A= $max_value > 1B= $difference < 1
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $difference = 1; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $max_value += $difference; | |||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 12 | $column_count = $self->_max(0, $sc_cols, $l_cols, $a_cols); | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 12 | ▶ | if ($self->_get_number('automatic_axis')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | # In case this was set via a style, and not by the api method | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | eval { require Chart::Math::Axis; }; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | return $self->_error("Can't use automatic_axis - $@"); | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $axis = Chart::Math::Axis->new(); | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $axis->include_zero(); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | $axis->add_data($min_value, $max_value); | |||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $max_value = $axis->top; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | $min_value = $axis->bottom; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $ticks = $axis->ticks; | |||||||||||||||||||||||||||||||||||||||||
| 398 | # The +1 is there because we have the bottom tick as well | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $self->set_y_tics($ticks+1); | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 12 | $self->_set_max_value($max_value); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 12 | $self->_set_min_value($min_value); | |||||||||||||||||||||||||||||||||||||||||
| 404 | 12 | $self->_set_column_count($column_count); | |||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 12 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | sub _min { | ||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_min: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 12 | my $min = shift; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 12 | foreach my $value (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 414 | 48 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 12 | ▶ | if ($value < $min) { $min = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | 12 | return $min; | |||||||||||||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | sub _max { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 24 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_max: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 422 | 24 | my $min = shift; | |||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 24 | foreach my $value (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 425 | 84 | ▶ | next unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 426 | 48 | ▶ | if ($value > $min) { $min = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 24 | return $min; | |||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||
| 431 | sub _get_line_range { | ||||||||||||||||||||||||||||||||||||||||||
| 432 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_line_range: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 12 | my $series = $self->_get_data_series()->{'line'}; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 12 | ▶ | return (undef, undef, 0) unless $series; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 5 | my $max_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 437 | 5 | my $min_value = STARTING_MIN_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 5 | my $column_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 5 | my @series = @{$series}; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 5 | foreach my $series (@series) { | |||||||||||||||||||||||||||||||||||||||||
| 442 | 5 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | ▶ | if (scalar @data > $column_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | 5 | $column_count = scalar @data; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 5 | foreach my $value (@data) { | |||||||||||||||||||||||||||||||||||||||||
| 449 | 2016 | ▶ | if ($value > $max_value) { $max_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 2016 | ▶ | if ($value < $min_value) { $min_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||
| 454 | 5 | return ($min_value, $max_value, $column_count); | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | sub _get_area_range { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_area_range: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | 12 | my $series = $self->_get_data_series()->{'area'}; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 12 | ▶ | return (undef, undef, 0) unless $series; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 2 | my $max_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | my $min_value = STARTING_MIN_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 464 | 2 | my $column_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | my @series = @{$series}; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 2 | foreach my $series (@series) { | |||||||||||||||||||||||||||||||||||||||||
| 468 | 3 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | 3 | ▶ | if (scalar @data > $column_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | $column_count = scalar @data; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | 3 | foreach my $value (@data) { | |||||||||||||||||||||||||||||||||||||||||
| 475 | 21 | ▶ | if ($value > $max_value) { $max_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 21 | ▶ | if ($value < $min_value) { $min_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 2 | return ($min_value, $max_value, $column_count); | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | sub _get_column_range { | ||||||||||||||||||||||||||||||||||||||||||
| 485 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_column_range: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 12 | my $series = $self->_get_data_series()->{'column'}; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 12 | ▶ | return (undef, undef, 0) unless $series; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | 3 | my $max_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 491 | 3 | my $min_value = STARTING_MIN_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 3 | my $column_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | 3 | my @series = @{$series}; | |||||||||||||||||||||||||||||||||||||||||
| 495 | 3 | foreach my $series (@series) { | |||||||||||||||||||||||||||||||||||||||||
| 496 | 5 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 5 | foreach my $value (@data) { | |||||||||||||||||||||||||||||||||||||||||
| 499 | 35 | $column_count++; | |||||||||||||||||||||||||||||||||||||||||
| 500 | 35 | ▶ | if ($value > $max_value) { $max_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 501 | 35 | ▶ | if ($value < $min_value) { $min_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | 3 | return ($min_value, $max_value, $column_count); | |||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | sub _get_stacked_column_range { | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_stacked_column_range: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 12 | my $max_value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 512 | 12 | my $min_value = STARTING_MIN_VALUE; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 12 | my $column_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | 12 | ▶ | return (undef, undef, 0) unless $self->_get_data_series()->{'stacked_column'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 516 | 2 | my @series = @{$self->_get_data_series()->{'stacked_column'}}; | |||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||
| 518 | 2 | my @max_entries; | |||||||||||||||||||||||||||||||||||||||||
| 519 | my @min_entries; | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 2 | ▶ | for (my $i = scalar @series - 1; $i >= 0; $i--) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | 3 | my $series = $series[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 3 | my $data = $series->{'data'}; | |||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||
| 524 | 3 | ▶ | for (my $i = 0; $i < scalar @$data; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 525 | 21 | my $value = 0; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 21 | ▶ | if ($data->[$i] > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 527 | 18 | ▶ | $value = $data->[$i] + ($max_entries[$i] || 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$max_entries[$i] || 0
MC/DC100%1/1
$max_entries[$i] || 0
$max_entries[$i]
Truth table100%2/2
A
A= $max_entries[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 18 | $data->[$i] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 18 | $max_entries[$i] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||
| 531 | elsif ($data->[$i] < 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 3 | ▶ | $value = $data->[$i] + ($min_entries[$i] || 0); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$min_entries[$i] || 0
MC/DC0%0/1
$min_entries[$i] || 0
$min_entries[$i]
Truth table50%1/2
A
A= $min_entries[$i]
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 3 | $data->[$i] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 534 | 3 | $min_entries[$i] = $value; | |||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 21 | ▶ | if ($value > $max_value) { $max_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 21 | ▶ | if ($value < $min_value) { $min_value = $value; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 3 | ▶ | if (scalar @$data > $column_count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | 2 | $column_count = scalar @$data; | |||||||||||||||||||||||||||||||||||||||||
| 541 | } | ||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | 2 | return ($min_value, $max_value, $column_count); | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | sub _draw_legend { | ||||||||||||||||||||||||||||||||||||||||||
| 548 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_legend: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 12 | my $chart_box = shift; | |||||||||||||||||||||||||||||||||||||||||
| 550 | 12 | my $style = $self->{'_style'}; | |||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | 12 | my @labels; | |||||||||||||||||||||||||||||||||||||||||
| 553 | 12 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 554 | 12 | ▶ | if (my $series = $self->_get_data_series()->{'stacked_column'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | 2 | push @labels, map { $_->{'series_name'} } @$series; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 12 | ▶ | if (my $series = $self->_get_data_series()->{'column'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | 3 | push @labels, map { $_->{'series_name'} } @$series; | |||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 12 | ▶ | if (my $series = $self->_get_data_series()->{'line'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 561 | 5 | push @labels, map { $_->{'series_name'} } @$series; | |||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||
| 563 | 12 | ▶ | if (my $series = $self->_get_data_series()->{'area'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 564 | 2 | push @labels, map { $_->{'series_name'} } @$series; | |||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | 12 | ▶ | if ($style->{features}{legend} && (scalar @labels)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$style->{"features"}{"legend"} and scalar @labels
MC/DC100%1/1
$style->{"features"}{"legend"} and scalar @labels
$style->{"features"}{"legend"}
Truth table100%2/2
A
A= $style->{"features"}{"legend"}
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 2 | ▶ | $self->SUPER::_draw_legend($self->_get_image(), \@labels, $chart_box) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 12 | return; | |||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | sub _draw_flat_legend { | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 1 | ▶ | return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_flat_legend: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||
| 578 | sub _draw_lines { | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_lines: called CC=10 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | 5 | my $style = $self->{'_style'}; | |||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | 5 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | 5 | my $max_value = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 585 | 5 | my $min_value = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 586 | 5 | my $column_count = $self->_get_column_count(); | |||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | 5 | my $value_range = $max_value - $min_value; | |||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 5 | my $width = $self->_get_number('width'); | |||||||||||||||||||||||||||||||||||||||||
| 591 | 5 | my $height = $self->_get_number('height'); | |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 5 | my $graph_width = $self->_get_number('graph_width'); | |||||||||||||||||||||||||||||||||||||||||
| 594 | 5 | my $graph_height = $self->_get_number('graph_height'); | |||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | 5 | my $line_series = $self->_get_data_series()->{'line'}; | |||||||||||||||||||||||||||||||||||||||||
| 597 | 5 | ▶ | my $series_counter = $self->_get_series_counter() || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_get_series_counter || 0
MC/DC0%0/1
$self->_get_series_counter || 0
$self->_get_series_counter
Truth table50%1/2
A
A= $self->_get_series_counter
| |||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | 5 | ▶ | my $has_columns = (defined $self->_get_data_series()->{'column'} || $self->_get_data_series->{'stacked_column'}) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->_get_data_series->{"column"} or $self->_get_data_series->{"stacked_column"}
MC/DC0%0/2
defined $self->_get_data_series->{"column"} or $self->_get_data_series->{"stacked_column"}
defined $self->_get_data_series->{"column"}
$self->_get_data_series->{"stacked_column"}
Truth table33%1/3
A or B
A= defined $self->_get_data_series->{"column"}B= $self->_get_data_series->{"stacked_column"}
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 5 | my $col_width = int($graph_width / $column_count) -1; | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 5 | my $graph_box = $self->_get_graph_box(); | |||||||||||||||||||||||||||||||||||||||||
| 604 | 5 | my $left = $graph_box->[0] + 1; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 5 | my $bottom = $graph_box->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||
| 607 | 5 | my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height - 1); | |||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||
| 609 | 5 | my $line_aa = $self->_get_number("lineaa"); | |||||||||||||||||||||||||||||||||||||||||
| 610 | 5 | foreach my $series (@$line_series) { | |||||||||||||||||||||||||||||||||||||||||
| 611 | 5 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 612 | 5 | my $data_size = scalar @data; | |||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||
| 614 | 5 | my $interval; | |||||||||||||||||||||||||||||||||||||||||
| 615 | 5 | ▶ | if ($has_columns) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | $interval = $graph_width / ($data_size); | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 5 | $interval = $graph_width / ($data_size - 1); | |||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||
| 621 | 5 | my $color = $self->_data_color($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||
| 623 | # We need to add these last, otherwise the next line segment will overwrite half of the marker | ||||||||||||||||||||||||||||||||||||||||||
| 624 | 5 | my @marker_positions; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 5 | ▶ | for (my $i = 0; $i < $data_size - 1; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 626 | 2011 | my $x1 = $left + $i * $interval; | |||||||||||||||||||||||||||||||||||||||||
| 627 | 2011 | my $x2 = $left + ($i + 1) * $interval; | |||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 2011 | $x1 += $has_columns * $interval / 2; | |||||||||||||||||||||||||||||||||||||||||
| 630 | 2011 | $x2 += $has_columns * $interval / 2; | |||||||||||||||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||||||||||||||||
| 632 | 2011 | my $y1 = $bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height; | |||||||||||||||||||||||||||||||||||||||||
| 633 | 2011 | my $y2 = $bottom + ($value_range - $data[$i + 1] + $min_value)/$value_range * $graph_height; | |||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||
| 635 | 2011 | push @marker_positions, [$x1, $y1]; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 2011 | ▶ | $img->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2, aa => $line_aa, color => $color) || die $img->errstr; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | } | ||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||
| 639 | 5 | my $x2 = $left + ($data_size - 1) * $interval; | |||||||||||||||||||||||||||||||||||||||||
| 640 | 5 | $x2 += $has_columns * $interval / 2; | |||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||
| 642 | 5 | my $y2 = $bottom + ($value_range - $data[$data_size - 1] + $min_value)/$value_range * $graph_height; | |||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | 5 | ▶ | if ($self->_feature_enabled("linemarkers")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | 5 | push @marker_positions, [$x2, $y2]; | |||||||||||||||||||||||||||||||||||||||||
| 646 | 5 | foreach my $position (@marker_positions) { | |||||||||||||||||||||||||||||||||||||||||
| 647 | 2016 | $self->_draw_line_marker($position->[0], $position->[1], $series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||
| 650 | 5 | $series_counter++; | |||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||
| 653 | 5 | $self->_set_series_counter($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 654 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | sub _area_data_fill { | ||||||||||||||||||||||||||||||||||||||||||
| 658 | 3 | ▶ | my ($self, $index, $box) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_area_data_fill: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||
| 660 | 3 | my %fill = $self->_data_fill($index, $box); | |||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||
| 662 | 3 | my $opacity = $self->_get_number("area.opacity"); | |||||||||||||||||||||||||||||||||||||||||
| 663 | 3 | ▶ | $opacity == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | and return %fill; | ||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||
| 666 | 3 | my $orig_fill = $fill{fill}; | |||||||||||||||||||||||||||||||||||||||||
| 667 | 3 | ▶ | unless ($orig_fill) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | $orig_fill = Imager::Fill->new | ||||||||||||||||||||||||||||||||||||||||||
| 669 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 670 | solid => $fill{color}, | ||||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | combine => "normal", | |||||||||||||||||||||||||||||||||||||||||
| 672 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||
| 674 | return | ||||||||||||||||||||||||||||||||||||||||||
| 675 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 3 | fill => Imager::Fill->new | |||||||||||||||||||||||||||||||||||||||||
| 677 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 678 | type => "opacity", | ||||||||||||||||||||||||||||||||||||||||||
| 679 | other => $orig_fill, | ||||||||||||||||||||||||||||||||||||||||||
| 680 | opacity => $opacity, | ||||||||||||||||||||||||||||||||||||||||||
| 681 | ), | ||||||||||||||||||||||||||||||||||||||||||
| 682 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||
| 685 | sub _draw_area { | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_area: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 2 | my $style = $self->{'_style'}; | |||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||
| 689 | 2 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||
| 691 | 2 | my $max_value = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 692 | 2 | my $min_value = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 693 | 2 | my $column_count = $self->_get_column_count(); | |||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||
| 695 | 2 | my $value_range = $max_value - $min_value; | |||||||||||||||||||||||||||||||||||||||||
| 696 | |||||||||||||||||||||||||||||||||||||||||||
| 697 | 2 | my $width = $self->_get_number('width'); | |||||||||||||||||||||||||||||||||||||||||
| 698 | 2 | my $height = $self->_get_number('height'); | |||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | my $graph_width = $self->_get_number('graph_width'); | |||||||||||||||||||||||||||||||||||||||||
| 701 | 2 | my $graph_height = $self->_get_number('graph_height'); | |||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||
| 703 | 2 | my $area_series = $self->_get_data_series()->{'area'}; | |||||||||||||||||||||||||||||||||||||||||
| 704 | 2 | ▶ | my $series_counter = $self->_get_series_counter() || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_get_series_counter || 0
MC/DC0%0/1
$self->_get_series_counter || 0
$self->_get_series_counter
Truth table50%1/2
A
A= $self->_get_series_counter
| |||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 2 | my $col_width = int($graph_width / $column_count) -1; | |||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||
| 708 | 2 | my $graph_box = $self->_get_graph_box(); | |||||||||||||||||||||||||||||||||||||||||
| 709 | 2 | my $left = $graph_box->[0] + 1; | |||||||||||||||||||||||||||||||||||||||||
| 710 | 2 | my $bottom = $graph_box->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | my $right = $graph_box->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 2 | my $top = $graph_box->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||
| 714 | 2 | my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height - 1); | |||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||
| 716 | 2 | my $line_aa = $self->_get_number("lineaa"); | |||||||||||||||||||||||||||||||||||||||||
| 717 | 2 | foreach my $series (@$area_series) { | |||||||||||||||||||||||||||||||||||||||||
| 718 | 3 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 719 | 3 | my $data_size = scalar @data; | |||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||
| 721 | 3 | my $interval = $graph_width / ($data_size - 1); | |||||||||||||||||||||||||||||||||||||||||
| 722 | |||||||||||||||||||||||||||||||||||||||||||
| 723 | 3 | my $color = $self->_data_color($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 724 | |||||||||||||||||||||||||||||||||||||||||||
| 725 | # We need to add these last, otherwise the next line segment will overwrite half of the marker | ||||||||||||||||||||||||||||||||||||||||||
| 726 | 3 | my @marker_positions; | |||||||||||||||||||||||||||||||||||||||||
| 727 | my @polygon_points; | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 3 | ▶ | for (my $i = 0; $i < $data_size - 1; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 729 | 18 | my $x1 = $left + $i * $interval; | |||||||||||||||||||||||||||||||||||||||||
| 730 | |||||||||||||||||||||||||||||||||||||||||||
| 731 | 18 | my $y1 = $bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height; | |||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||
| 733 | 18 | ▶ | if ($i == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 734 | 3 | push @polygon_points, [$x1, $top]; | |||||||||||||||||||||||||||||||||||||||||
| 735 | } | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 18 | push @polygon_points, [$x1, $y1]; | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | 18 | push @marker_positions, [$x1, $y1]; | |||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 3 | my $x2 = $left + ($data_size - 1) * $interval; | |||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 3 | my $y2 = $bottom + ($value_range - $data[$data_size - 1] + $min_value)/$value_range * $graph_height; | |||||||||||||||||||||||||||||||||||||||||
| 744 | 3 | push @polygon_points, [$x2, $y2]; | |||||||||||||||||||||||||||||||||||||||||
| 745 | 3 | push @polygon_points, [$x2, $top]; | |||||||||||||||||||||||||||||||||||||||||
| 746 | 3 | push @polygon_points, $polygon_points[0]; | |||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||
| 748 | 3 | my @fill = $self->_area_data_fill($series_counter, [$left, $bottom, $right, $top]); | |||||||||||||||||||||||||||||||||||||||||
| 749 | 3 | $img->polygon(points => [@polygon_points], @fill); | |||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | 3 | ▶ | if ($self->_feature_enabled("areamarkers")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 1 | push @marker_positions, [$x2, $y2]; | |||||||||||||||||||||||||||||||||||||||||
| 753 | 1 | foreach my $position (@marker_positions) { | |||||||||||||||||||||||||||||||||||||||||
| 754 | 7 | $self->_draw_line_marker($position->[0], $position->[1], $series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 755 | } | ||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||
| 757 | 3 | $series_counter++; | |||||||||||||||||||||||||||||||||||||||||
| 758 | } | ||||||||||||||||||||||||||||||||||||||||||
| 759 | |||||||||||||||||||||||||||||||||||||||||||
| 760 | 2 | $self->_set_series_counter($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 761 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||
| 764 | sub _draw_columns { | ||||||||||||||||||||||||||||||||||||||||||
| 765 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_columns: called CC=12 SCAR=25.0
| |||||||||||||||||||||||||||||||||||||||||||
| 766 | 3 | my $style = $self->{'_style'}; | |||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||
| 768 | 3 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||
| 770 | 3 | my $max_value = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 771 | 3 | my $min_value = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 772 | 3 | my $column_count = $self->_get_column_count(); | |||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 3 | my $value_range = $max_value - $min_value; | |||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | 3 | my $width = $self->_get_number('width'); | |||||||||||||||||||||||||||||||||||||||||
| 777 | 3 | my $height = $self->_get_number('height'); | |||||||||||||||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||||||||||||||||
| 779 | 3 | my $graph_width = $self->_get_number('graph_width'); | |||||||||||||||||||||||||||||||||||||||||
| 780 | 3 | my $graph_height = $self->_get_number('graph_height'); | |||||||||||||||||||||||||||||||||||||||||
| 781 | |||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||
| 783 | 3 | my $graph_box = $self->_get_graph_box(); | |||||||||||||||||||||||||||||||||||||||||
| 784 | 3 | my $left = $graph_box->[0] + 1; | |||||||||||||||||||||||||||||||||||||||||
| 785 | 3 | my $bottom = $graph_box->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 786 | 3 | my $zero_position = int($bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1)); | |||||||||||||||||||||||||||||||||||||||||
| 787 | |||||||||||||||||||||||||||||||||||||||||||
| 788 | 3 | my $bar_width = $graph_width / $column_count; | |||||||||||||||||||||||||||||||||||||||||
| 789 | |||||||||||||||||||||||||||||||||||||||||||
| 790 | 3 | my $outline_color; | |||||||||||||||||||||||||||||||||||||||||
| 791 | 3 | ▶ | if ($style->{'features'}{'outline'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 792 | 2 | $outline_color = $self->_get_color('outline.line'); | |||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||
| 794 | |||||||||||||||||||||||||||||||||||||||||||
| 795 | 3 | ▶ | my $series_counter = $self->_get_series_counter() || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_get_series_counter || 0
MC/DC0%0/1
$self->_get_series_counter || 0
$self->_get_series_counter
Truth table50%1/2
A
A= $self->_get_series_counter
| |||||||||||||||||||||||||||||||||||||||||||
| 796 | 3 | my $col_series = $self->_get_data_series()->{'column'}; | |||||||||||||||||||||||||||||||||||||||||
| 797 | 3 | ▶ | my $column_padding_percent = $self->_get_number('column_padding') || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_get_number('column_padding') || 0
MC/DC0%0/1
$self->_get_number('column_padding') || 0
$self->_get_number('column_padding')
Truth table50%1/2
A
A= $self->_get_number('column_padding')
| |||||||||||||||||||||||||||||||||||||||||||
| 798 | 3 | my $column_padding = int($column_padding_percent * $bar_width / 100); | |||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||
| 800 | # This tracks the series we're in relative to the starting series - this way colors stay accurate, but the columns don't start out too far to the right. | ||||||||||||||||||||||||||||||||||||||||||
| 801 | 3 | my $column_series = 0; | |||||||||||||||||||||||||||||||||||||||||
| 802 | |||||||||||||||||||||||||||||||||||||||||||
| 803 | # If there are stacked columns, non-stacked columns need to start one to the right of where they would otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 804 | 3 | ▶ | my $has_stacked_columns = (defined $self->_get_data_series()->{'stacked_column'} ? 1 : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | |||||||||||||||||||||||||||||||||||||||||||
| 806 | 3 | ▶ | for (my $series_pos = 0; $series_pos < scalar @$col_series; $series_pos++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 807 | 5 | my $series = $col_series->[$series_pos]; | |||||||||||||||||||||||||||||||||||||||||
| 808 | 5 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 809 | 5 | my $data_size = scalar @data; | |||||||||||||||||||||||||||||||||||||||||
| 810 | 5 | ▶ | for (my $i = 0; $i < $data_size; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 35 | my $part1 = $bar_width * (scalar @$col_series * $i); | |||||||||||||||||||||||||||||||||||||||||
| 812 | 35 | my $part2 = ($series_pos) * $bar_width; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 35 | my $x1 = $left + $part1 + $part2; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 35 | ▶ | if ($has_stacked_columns) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | 0 | $x1 += ($bar_width * ($i+1)); | |||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||
| 817 | 35 | $x1 = int($x1); | |||||||||||||||||||||||||||||||||||||||||
| 818 | |||||||||||||||||||||||||||||||||||||||||||
| 819 | 35 | my $x2 = int($x1 + $bar_width - $column_padding)-1; | |||||||||||||||||||||||||||||||||||||||||
| 820 | # Special case for when bar_width is less than 1. | ||||||||||||||||||||||||||||||||||||||||||
| 821 | 35 | ▶ | if ($x2 < $x1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 822 | 0 | $x2 = $x1; | |||||||||||||||||||||||||||||||||||||||||
| 823 | } | ||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||
| 825 | 35 | my $y1 = int($bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height); | |||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||
| 827 | 35 | my $color = $self->_data_color($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 828 | |||||||||||||||||||||||||||||||||||||||||||
| 829 | 35 | ▶ | if ($data[$i] > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 830 | 29 | my @fill = $self->_data_fill($series_counter, [$x1, $y1, $x2, $zero_position-1]); | |||||||||||||||||||||||||||||||||||||||||
| 831 | 29 | $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position-1, @fill); | |||||||||||||||||||||||||||||||||||||||||
| 832 | 29 | ▶ | if ($style->{'features'}{'outline'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 22 | $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position, color => $outline_color); | |||||||||||||||||||||||||||||||||||||||||
| 834 | } | ||||||||||||||||||||||||||||||||||||||||||
| 835 | } | ||||||||||||||||||||||||||||||||||||||||||
| 836 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 837 | 6 | my @fill = $self->_data_fill($series_counter, [$x1, $zero_position+1, $x2, $y1]); | |||||||||||||||||||||||||||||||||||||||||
| 838 | 6 | $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1, @fill); | |||||||||||||||||||||||||||||||||||||||||
| 839 | 6 | ▶ | if ($style->{'features'}{'outline'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | 6 | $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1+1, color => $outline_color); | |||||||||||||||||||||||||||||||||||||||||
| 841 | } | ||||||||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | |||||||||||||||||||||||||||||||||||||||||||
| 845 | 5 | $series_counter++; | |||||||||||||||||||||||||||||||||||||||||
| 846 | 5 | $column_series++; | |||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 848 | 3 | $self->_set_series_counter($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 849 | 3 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||
| 852 | sub _draw_stacked_columns { | ||||||||||||||||||||||||||||||||||||||||||
| 853 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_stacked_columns: called CC=13 SCAR=26.0
| |||||||||||||||||||||||||||||||||||||||||||
| 854 | 2 | my $style = $self->{'_style'}; | |||||||||||||||||||||||||||||||||||||||||
| 855 | |||||||||||||||||||||||||||||||||||||||||||
| 856 | 2 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||
| 858 | 2 | my $max_value = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 859 | 2 | my $min_value = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 860 | 2 | my $column_count = $self->_get_column_count(); | |||||||||||||||||||||||||||||||||||||||||
| 861 | 2 | my $value_range = $max_value - $min_value; | |||||||||||||||||||||||||||||||||||||||||
| 862 | |||||||||||||||||||||||||||||||||||||||||||
| 863 | 2 | my $graph_box = $self->_get_graph_box(); | |||||||||||||||||||||||||||||||||||||||||
| 864 | 2 | my $left = $graph_box->[0] + 1; | |||||||||||||||||||||||||||||||||||||||||
| 865 | 2 | my $bottom = $graph_box->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||
| 867 | 2 | my $graph_width = $self->_get_number('graph_width'); | |||||||||||||||||||||||||||||||||||||||||
| 868 | 2 | my $graph_height = $self->_get_number('graph_height'); | |||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||
| 870 | 2 | my $bar_width = $graph_width / $column_count; | |||||||||||||||||||||||||||||||||||||||||
| 871 | 2 | my $column_series = 0; | |||||||||||||||||||||||||||||||||||||||||
| 872 | 2 | ▶ | if (my $column_series_data = $self->_get_data_series()->{'column'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | 0 | $column_series = (scalar @$column_series_data); | |||||||||||||||||||||||||||||||||||||||||
| 874 | } | ||||||||||||||||||||||||||||||||||||||||||
| 875 | 2 | $column_series++; | |||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | 2 | ▶ | my $column_padding_percent = $self->_get_number('column_padding') || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_get_number('column_padding') || 0
MC/DC100%1/1
$self->_get_number('column_padding') || 0
$self->_get_number('column_padding')
Truth table100%2/2
A
A= $self->_get_number('column_padding')
| |||||||||||||||||||||||||||||||||||||||||||
| 878 | 2 | ▶ | if ($column_padding_percent < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 879 | 0 | return $self->_error("Column padding less than 0"); | |||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 2 | ▶ | if ($column_padding_percent > 100) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | 0 | return $self->_error("Column padding greater than 0"); | |||||||||||||||||||||||||||||||||||||||||
| 883 | } | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 2 | my $column_padding = int($column_padding_percent * $bar_width / 100); | |||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||
| 886 | 2 | my $outline_color; | |||||||||||||||||||||||||||||||||||||||||
| 887 | 2 | ▶ | if ($style->{'features'}{'outline'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 888 | 1 | $outline_color = $self->_get_color('outline.line'); | |||||||||||||||||||||||||||||||||||||||||
| 889 | } | ||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||
| 891 | 2 | my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1); | |||||||||||||||||||||||||||||||||||||||||
| 892 | 2 | my $col_series = $self->_get_data_series()->{'stacked_column'}; | |||||||||||||||||||||||||||||||||||||||||
| 893 | 2 | ▶ | my $series_counter = $self->_get_series_counter() || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_get_series_counter || 0
MC/DC0%0/1
$self->_get_series_counter || 0
$self->_get_series_counter
Truth table50%1/2
A
A= $self->_get_series_counter
| |||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||
| 895 | 2 | foreach my $series (@$col_series) { | |||||||||||||||||||||||||||||||||||||||||
| 896 | 3 | my @data = @{$series->{'data'}}; | |||||||||||||||||||||||||||||||||||||||||
| 897 | 3 | my $data_size = scalar @data; | |||||||||||||||||||||||||||||||||||||||||
| 898 | 3 | ▶ | for (my $i = 0; $i < $data_size; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 899 | 21 | my $part1 = $bar_width * $i * $column_series; | |||||||||||||||||||||||||||||||||||||||||
| 900 | 21 | my $part2 = 0; | |||||||||||||||||||||||||||||||||||||||||
| 901 | 21 | my $x1 = int($left + $part1 + $part2); | |||||||||||||||||||||||||||||||||||||||||
| 902 | 21 | my $x2 = int($x1 + $bar_width - $column_padding) - 1; | |||||||||||||||||||||||||||||||||||||||||
| 903 | # Special case for when bar_width is less than 1. | ||||||||||||||||||||||||||||||||||||||||||
| 904 | 21 | ▶ | if ($x2 < $x1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | 0 | $x2 = $x1; | |||||||||||||||||||||||||||||||||||||||||
| 906 | } | ||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||
| 908 | 21 | my $y1 = int($bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height); | |||||||||||||||||||||||||||||||||||||||||
| 909 | |||||||||||||||||||||||||||||||||||||||||||
| 910 | 21 | ▶ | if ($data[$i] > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | 18 | my @fill = $self->_data_fill($series_counter, [$x1, $y1, $x2, $zero_position-1]); | |||||||||||||||||||||||||||||||||||||||||
| 912 | 18 | $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position-1, @fill); | |||||||||||||||||||||||||||||||||||||||||
| 913 | 18 | ▶ | if ($style->{'features'}{'outline'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | 11 | $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position, color => $outline_color); | |||||||||||||||||||||||||||||||||||||||||
| 915 | } | ||||||||||||||||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||||||||||||||
| 917 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 918 | 3 | my @fill = $self->_data_fill($series_counter, [$x1, $zero_position+1, $x2, $y1]); | |||||||||||||||||||||||||||||||||||||||||
| 919 | 3 | $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1, @fill); | |||||||||||||||||||||||||||||||||||||||||
| 920 | 3 | ▶ | if ($style->{'features'}{'outline'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 921 | 3 | $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1+1, color => $outline_color); | |||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||
| 923 | } | ||||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||
| 925 | |||||||||||||||||||||||||||||||||||||||||||
| 926 | 3 | $series_counter++; | |||||||||||||||||||||||||||||||||||||||||
| 927 | } | ||||||||||||||||||||||||||||||||||||||||||
| 928 | 2 | $self->_set_series_counter($series_counter); | |||||||||||||||||||||||||||||||||||||||||
| 929 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 930 | } | ||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||
| 932 | sub _add_data_series { | ||||||||||||||||||||||||||||||||||||||||||
| 933 | 16 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_data_series: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 934 | 16 | my $series_type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 935 | 16 | my $data_ref = shift; | |||||||||||||||||||||||||||||||||||||||||
| 936 | 16 | my $series_name = shift; | |||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||
| 938 | 16 | ▶ | my $graph_data = $self->{'graph_data'} || {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'graph_data'} || {}
MC/DC100%1/1
$self->{'graph_data'} || {}
$self->{'graph_data'}
Truth table100%2/2
A
A= $self->{'graph_data'}
| |||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||
| 940 | 16 | ▶ | my $series = $graph_data->{$series_type} || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$graph_data->{$series_type} || []
MC/DC100%1/1
$graph_data->{$series_type} || []
$graph_data->{$series_type}
Truth table100%2/2
A
A= $graph_data->{$series_type}
| |||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||
| 942 | 16 | push @$series, { data => $data_ref, series_name => $series_name }; | |||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||
| 944 | 16 | $graph_data->{$series_type} = $series; | |||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||
| 946 | 16 | $self->{'graph_data'} = $graph_data; | |||||||||||||||||||||||||||||||||||||||||
| 947 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||
| 948 | } | ||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||
| 950 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||||||||||||||||
| 952 | =head1 FEATURES | ||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||
| 954 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||
| 956 | =item show_horizontal_gridlines() | ||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||
| 958 | Feature: horizontal_gridlines | ||||||||||||||||||||||||||||||||||||||||||
| 959 | X<horizontal_gridlines>X<features, horizontal_gridlines> | ||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||
| 961 | Enables the C<horizontal_gridlines> feature, which shows horizontal | ||||||||||||||||||||||||||||||||||||||||||
| 962 | gridlines at the y-tics. | ||||||||||||||||||||||||||||||||||||||||||
| 963 | |||||||||||||||||||||||||||||||||||||||||||
| 964 | The style of the gridlines can be controlled with the | ||||||||||||||||||||||||||||||||||||||||||
| 965 | set_horizontal_gridline_style() method (or by setting the hgrid | ||||||||||||||||||||||||||||||||||||||||||
| 966 | style). | ||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||
| 968 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||
| 970 | sub show_horizontal_gridlines { | ||||||||||||||||||||||||||||||||||||||||||
| 971 | 1 | ▶ | $_[0]->{'custom_style'}{features}{'horizontal_gridlines'} = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_horizontal_gridlines: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 972 | } | ||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||
| 974 | =item set_horizontal_gridline_style(style => $style, color => $color) | ||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||
| 976 | Style: hgrid. | ||||||||||||||||||||||||||||||||||||||||||
| 977 | X<hgrid>X<style parameters, hgrid> | ||||||||||||||||||||||||||||||||||||||||||
| 978 | |||||||||||||||||||||||||||||||||||||||||||
| 979 | Set the style and color of horizonal gridlines. | ||||||||||||||||||||||||||||||||||||||||||
| 980 | |||||||||||||||||||||||||||||||||||||||||||
| 981 | See: L<Imager::Graph/"Line styles"> | ||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||
| 983 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | sub set_horizontal_gridline_style { | ||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_horizontal_gridline_style: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | ▶ | $self->{custom_style}{hgrid} ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"custom_style"}{"hgrid"} ||= {}
MC/DC0%0/1
$self->{"custom_style"}{"hgrid"} ||= {}
$self->{"custom_style"}{"hgrid"}
Truth table0%0/2
A
A= $self->{"custom_style"}{"hgrid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 989 | 0 | @{$self->{custom_style}{hgrid}}{keys %opts} = values %opts; | |||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||
| 991 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 992 | } | ||||||||||||||||||||||||||||||||||||||||||
| 993 | |||||||||||||||||||||||||||||||||||||||||||
| 994 | =item show_graph_outline($flag) | ||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||
| 996 | Feature: graph_outline | ||||||||||||||||||||||||||||||||||||||||||
| 997 | X<graph_outline>X<features, graph_outline> | ||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | If no flag is supplied, unconditionally enable the graph outline. | ||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||
| 1001 | If $flag is supplied, enable/disable the graph_outline feature based | ||||||||||||||||||||||||||||||||||||||||||
| 1002 | on that. | ||||||||||||||||||||||||||||||||||||||||||
| 1003 | |||||||||||||||||||||||||||||||||||||||||||
| 1004 | Enabled by default. | ||||||||||||||||||||||||||||||||||||||||||
| 1005 | |||||||||||||||||||||||||||||||||||||||||||
| 1006 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||
| 1008 | sub show_graph_outline { | ||||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | ▶ | my ($self, $flag) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_graph_outline: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1010 | |||||||||||||||||||||||||||||||||||||||||||
| 1011 | 0 | ▶ | @_ == 1 and $flag = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1012 | |||||||||||||||||||||||||||||||||||||||||||
| 1013 | 0 | $self->{custom_style}{features}{graph_outline} = $flag; | |||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||
| 1015 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1016 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||
| 1018 | =item set_graph_outline_style(color => ...) | ||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||
| 1020 | =item set_graph_outline_style(style => ..., color => ...) | ||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||
| 1022 | Style: graph.outline | ||||||||||||||||||||||||||||||||||||||||||
| 1023 | X<graph.outline>X<style parameters, graph.outline> | ||||||||||||||||||||||||||||||||||||||||||
| 1024 | |||||||||||||||||||||||||||||||||||||||||||
| 1025 | Sets the style of the graph outline. | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||
| 1027 | Default: the style C<fg>. | ||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||
| 1029 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||
| 1031 | sub set_graph_outline_style { | ||||||||||||||||||||||||||||||||||||||||||
| 1032 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_graph_outline_style: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1033 | |||||||||||||||||||||||||||||||||||||||||||
| 1034 | 0 | $self->{custom_style}{graph}{outline} = \%opts; | |||||||||||||||||||||||||||||||||||||||||
| 1035 | |||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1037 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||
| 1039 | =item set_graph_fill_style(I<fill parameters>) | ||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||
| 1041 | Style: graph.fill | ||||||||||||||||||||||||||||||||||||||||||
| 1042 | X<graph.fill>X<style parameters, graph.fill> | ||||||||||||||||||||||||||||||||||||||||||
| 1043 | |||||||||||||||||||||||||||||||||||||||||||
| 1044 | Set the fill used to fill the graph data area. | ||||||||||||||||||||||||||||||||||||||||||
| 1045 | |||||||||||||||||||||||||||||||||||||||||||
| 1046 | Default: the style C<bg>. | ||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||
| 1048 | eg. | ||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||
| 1050 | $graph->set_graph_fill_style(solid => "FF000020", combine => "normal"); | ||||||||||||||||||||||||||||||||||||||||||
| 1051 | |||||||||||||||||||||||||||||||||||||||||||
| 1052 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||||||
| 1054 | sub set_graph_fill_style { | ||||||||||||||||||||||||||||||||||||||||||
| 1055 | 0 | ▶ | my ($self, %opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_graph_fill_style: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1056 | |||||||||||||||||||||||||||||||||||||||||||
| 1057 | 0 | $self->{custom_style}{graph}{fill} = \%opts; | |||||||||||||||||||||||||||||||||||||||||
| 1058 | |||||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1060 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1061 | |||||||||||||||||||||||||||||||||||||||||||
| 1062 | =item show_area_markers() | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | |||||||||||||||||||||||||||||||||||||||||||
| 1064 | =item show_area_markers($value) | ||||||||||||||||||||||||||||||||||||||||||
| 1065 | |||||||||||||||||||||||||||||||||||||||||||
| 1066 | Feature: areamarkers. | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | |||||||||||||||||||||||||||||||||||||||||||
| 1068 | If $value is missing or true, draw markers along the top of area data | ||||||||||||||||||||||||||||||||||||||||||
| 1069 | series. | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||
| 1071 | eg. | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||
| 1073 | $chart->show_area_markers(); | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | |||||||||||||||||||||||||||||||||||||||||||
| 1075 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | sub show_area_markers { | ||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_area_markers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||||||
| 1080 | 0 | ▶ | @_ > 1 or $value = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | $self->{custom_style}{features}{areamarkers} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||
| 1084 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1085 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | |||||||||||||||||||||||||||||||||||||||||||
| 1087 | =item show_line_markers() | ||||||||||||||||||||||||||||||||||||||||||
| 1088 | |||||||||||||||||||||||||||||||||||||||||||
| 1089 | =item show_line_markers($value) | ||||||||||||||||||||||||||||||||||||||||||
| 1090 | |||||||||||||||||||||||||||||||||||||||||||
| 1091 | Feature: linemarkers. | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | |||||||||||||||||||||||||||||||||||||||||||
| 1093 | If $value is missing or true, draw markers on a line data series. | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | |||||||||||||||||||||||||||||||||||||||||||
| 1095 | Note: line markers are drawn by default. | ||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||
| 1097 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | sub show_line_markers { | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | 0 | ▶ | my ($self, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
show_line_markers: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||
| 1102 | 0 | ▶ | @_ > 1 or $value = 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1103 | |||||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | $self->{custom_style}{features}{linemarkers} = $value; | |||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||
| 1106 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||
| 1109 | =item use_automatic_axis() | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | |||||||||||||||||||||||||||||||||||||||||||
| 1111 | Automatically scale the Y axis, based on L<Chart::Math::Axis>. If | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | Chart::Math::Axis isn't installed, this sets an error and returns | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | undef. Returns 1 if it is installed. | ||||||||||||||||||||||||||||||||||||||||||
| 1114 | |||||||||||||||||||||||||||||||||||||||||||
| 1115 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1116 | |||||||||||||||||||||||||||||||||||||||||||
| 1117 | sub use_automatic_axis { | ||||||||||||||||||||||||||||||||||||||||||
| 1118 | 1 | ▶ | eval { require Chart::Math::Axis; }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
use_automatic_axis: called CC=2 SCAR=7.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1119 | 1 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1120 | 1 | return $_[0]->_error("use_automatic_axis - $@\nCalled from ".join(' ', caller)."\n"); | |||||||||||||||||||||||||||||||||||||||||
| 1121 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | $_[0]->{'custom_style'}->{'automatic_axis'} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 1123 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||
| 1126 | =item set_y_tics($count) | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||
| 1128 | Set the number of Y tics to use. Their value and position will be | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | determined by the data range. | ||||||||||||||||||||||||||||||||||||||||||
| 1130 | |||||||||||||||||||||||||||||||||||||||||||
| 1131 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||
| 1133 | sub set_y_tics { | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | 2 | ▶ | $_[0]->{'y_tics'} = $_[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_y_tics: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||
| 1137 | sub _get_y_tics { | ||||||||||||||||||||||||||||||||||||||||||
| 1138 | 38 | ▶ | return $_[0]->{'y_tics'} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_y_tics: called CC=2 SCAR=6.9
Condition100%2/2
$_[0]{'y_tics'} || 0
MC/DC100%1/1
$_[0]{'y_tics'} || 0
$_[0]{'y_tics'}
Truth table100%2/2
A
A= $_[0]{'y_tics'}
| |||||||||||||||||||||||||||||||||||||||||||
| 1139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||
| 1141 | sub _remove_tics_from_chart_box { | ||||||||||||||||||||||||||||||||||||||||||
| 1142 | 12 | ▶ | my ($self, $chart_box, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_remove_tics_from_chart_box: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||
| 1144 | # XXX - bad default | ||||||||||||||||||||||||||||||||||||||||||
| 1145 | 12 | ▶ | my $tic_width = $self->_get_y_tic_width() || 10; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_get_y_tic_width || 10
MC/DC100%1/1
$self->_get_y_tic_width || 10
$self->_get_y_tic_width
Truth table100%2/2
A
A= $self->_get_y_tic_width
| |||||||||||||||||||||||||||||||||||||||||||
| 1146 | 12 | my @y_tic_box = ($chart_box->[0], $chart_box->[1], $chart_box->[0] + $tic_width, $chart_box->[3]); | |||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||
| 1148 | # XXX - bad default | ||||||||||||||||||||||||||||||||||||||||||
| 1149 | 12 | ▶ | my $tic_height = $self->_get_x_tic_height($opts) || 10; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->_get_x_tic_height($opts) || 10
MC/DC100%1/1
$self->_get_x_tic_height($opts) || 10
$self->_get_x_tic_height($opts)
Truth table100%2/2
A
A= $self->_get_x_tic_height($opts)
| |||||||||||||||||||||||||||||||||||||||||||
| 1150 | 12 | my @x_tic_box = ($chart_box->[0], $chart_box->[3] - $tic_height, $chart_box->[2], $chart_box->[3]); | |||||||||||||||||||||||||||||||||||||||||
| 1151 | |||||||||||||||||||||||||||||||||||||||||||
| 1152 | 12 | $self->_remove_box($chart_box, \@y_tic_box); | |||||||||||||||||||||||||||||||||||||||||
| 1153 | 12 | $self->_remove_box($chart_box, \@x_tic_box); | |||||||||||||||||||||||||||||||||||||||||
| 1154 | |||||||||||||||||||||||||||||||||||||||||||
| 1155 | # If there's no title, the y-tics will be part off-screen. Half of the x-tic height should be more than sufficient. | ||||||||||||||||||||||||||||||||||||||||||
| 1156 | 12 | my @y_tic_tops = ($chart_box->[0], $chart_box->[1], $chart_box->[2], $chart_box->[1] + int($tic_height / 2)); | |||||||||||||||||||||||||||||||||||||||||
| 1157 | 12 | $self->_remove_box($chart_box, \@y_tic_tops); | |||||||||||||||||||||||||||||||||||||||||
| 1158 | |||||||||||||||||||||||||||||||||||||||||||
| 1159 | # Make sure that the first and last label fit | ||||||||||||||||||||||||||||||||||||||||||
| 1160 | 12 | ▶ | if (my $labels = $self->_get_labels($opts)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1161 | 12 | ▶ | if (my @box = $self->_text_bbox($labels->[0], 'legend')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1162 | 5 | my @remove_box = ($chart_box->[0], | |||||||||||||||||||||||||||||||||||||||||
| 1163 | $chart_box->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 1164 | $chart_box->[0] + int($box[2] / 2) + 1, | ||||||||||||||||||||||||||||||||||||||||||
| 1165 | $chart_box->[3] | ||||||||||||||||||||||||||||||||||||||||||
| 1166 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1167 | |||||||||||||||||||||||||||||||||||||||||||
| 1168 | 5 | $self->_remove_box($chart_box, \@remove_box); | |||||||||||||||||||||||||||||||||||||||||
| 1169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1170 | 12 | ▶ | if (my @box = $self->_text_bbox($labels->[-1], 'legend')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1171 | 5 | my @remove_box = ($chart_box->[2] - int($box[2] / 2) - 1, | |||||||||||||||||||||||||||||||||||||||||
| 1172 | $chart_box->[1], | ||||||||||||||||||||||||||||||||||||||||||
| 1173 | $chart_box->[2], | ||||||||||||||||||||||||||||||||||||||||||
| 1174 | $chart_box->[3] | ||||||||||||||||||||||||||||||||||||||||||
| 1175 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||
| 1177 | 5 | $self->_remove_box($chart_box, \@remove_box); | |||||||||||||||||||||||||||||||||||||||||
| 1178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1181 | |||||||||||||||||||||||||||||||||||||||||||
| 1182 | sub _get_y_tic_width { | ||||||||||||||||||||||||||||||||||||||||||
| 1183 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_y_tic_width: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1184 | 12 | my $min = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 1185 | 12 | my $max = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 1186 | 12 | my $tic_count = $self->_get_y_tics(); | |||||||||||||||||||||||||||||||||||||||||
| 1187 | |||||||||||||||||||||||||||||||||||||||||||
| 1188 | 12 | my $interval = ($max - $min) / ($tic_count - 1); | |||||||||||||||||||||||||||||||||||||||||
| 1189 | |||||||||||||||||||||||||||||||||||||||||||
| 1190 | 12 | ▶ | my %text_info = $self->_text_style('legend') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1191 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1192 | |||||||||||||||||||||||||||||||||||||||||||
| 1193 | 5 | my $max_width = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1194 | 5 | for my $count (0 .. $tic_count - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 1195 | 15 | my $value = ($count*$interval)+$min; | |||||||||||||||||||||||||||||||||||||||||
| 1196 | |||||||||||||||||||||||||||||||||||||||||||
| 1197 | 15 | ▶ | if ($interval < 1 || ($value != int($value))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$interval < 1 or $value != int $value
MC/DC50%1/2
$interval < 1 or $value != int $value
$interval < 1
$value != int $value
Truth table66%2/3
A or B
A= $interval < 1B= $value != int $value
| |||||||||||||||||||||||||||||||||||||||||||
| 1198 | 3 | $value = sprintf("%.2f", $value); | |||||||||||||||||||||||||||||||||||||||||
| 1199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | 15 | my @box = $self->_text_bbox($value, 'legend'); | |||||||||||||||||||||||||||||||||||||||||
| 1201 | 15 | my $width = $box[2] - $box[0]; | |||||||||||||||||||||||||||||||||||||||||
| 1202 | |||||||||||||||||||||||||||||||||||||||||||
| 1203 | # For the tic width | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | 15 | $width += 10; | |||||||||||||||||||||||||||||||||||||||||
| 1205 | 15 | ▶ | if ($width > $max_width) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1206 | 5 | $max_width = $width; | |||||||||||||||||||||||||||||||||||||||||
| 1207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1209 | |||||||||||||||||||||||||||||||||||||||||||
| 1210 | 5 | return $max_width; | |||||||||||||||||||||||||||||||||||||||||
| 1211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1212 | |||||||||||||||||||||||||||||||||||||||||||
| 1213 | sub _get_x_tic_height { | ||||||||||||||||||||||||||||||||||||||||||
| 1214 | 12 | ▶ | my ($self, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_x_tic_height: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 1215 | |||||||||||||||||||||||||||||||||||||||||||
| 1216 | 12 | my $labels = $self->_get_labels($opts); | |||||||||||||||||||||||||||||||||||||||||
| 1217 | |||||||||||||||||||||||||||||||||||||||||||
| 1218 | 12 | ▶ | if (!$labels) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | 12 | my $tic_count = (scalar @$labels) - 1; | |||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||
| 1224 | 12 | ▶ | my %text_info = $self->_text_style('legend') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1225 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||
| 1227 | 5 | my $max_height = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1228 | 5 | for my $count (0 .. $tic_count) { | |||||||||||||||||||||||||||||||||||||||||
| 1229 | 30 | my $label = $labels->[$count]; | |||||||||||||||||||||||||||||||||||||||||
| 1230 | |||||||||||||||||||||||||||||||||||||||||||
| 1231 | 30 | my @box = $self->_text_bbox($label, 'legend'); | |||||||||||||||||||||||||||||||||||||||||
| 1232 | |||||||||||||||||||||||||||||||||||||||||||
| 1233 | 30 | my $height = $box[3] - $box[1]; | |||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||
| 1235 | # Padding + the tic | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | 30 | $height += 10; | |||||||||||||||||||||||||||||||||||||||||
| 1237 | 30 | ▶ | if ($height > $max_height) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1238 | 5 | $max_height = $height; | |||||||||||||||||||||||||||||||||||||||||
| 1239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1241 | |||||||||||||||||||||||||||||||||||||||||||
| 1242 | 5 | return $max_height; | |||||||||||||||||||||||||||||||||||||||||
| 1243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1244 | |||||||||||||||||||||||||||||||||||||||||||
| 1245 | sub _draw_y_tics { | ||||||||||||||||||||||||||||||||||||||||||
| 1246 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_y_tics: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1247 | 2 | my $min = $self->_get_min_value(); | |||||||||||||||||||||||||||||||||||||||||
| 1248 | 2 | my $max = $self->_get_max_value(); | |||||||||||||||||||||||||||||||||||||||||
| 1249 | 2 | my $tic_count = $self->_get_y_tics(); | |||||||||||||||||||||||||||||||||||||||||
| 1250 | |||||||||||||||||||||||||||||||||||||||||||
| 1251 | 2 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 1252 | 2 | my $graph_box = $self->_get_graph_box(); | |||||||||||||||||||||||||||||||||||||||||
| 1253 | 2 | my $image_box = $self->_get_image_box(); | |||||||||||||||||||||||||||||||||||||||||
| 1254 | |||||||||||||||||||||||||||||||||||||||||||
| 1255 | 2 | my $interval = ($max - $min) / ($tic_count - 1); | |||||||||||||||||||||||||||||||||||||||||
| 1256 | |||||||||||||||||||||||||||||||||||||||||||
| 1257 | 2 | ▶ | my %text_info = $self->_text_style('legend') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1258 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1259 | |||||||||||||||||||||||||||||||||||||||||||
| 1260 | 2 | my $line_style = $self->_get_color('outline.line'); | |||||||||||||||||||||||||||||||||||||||||
| 1261 | 2 | my $show_gridlines = $self->{_style}{features}{'horizontal_gridlines'}; | |||||||||||||||||||||||||||||||||||||||||
| 1262 | 2 | my @grid_line = $self->_get_line("hgrid"); | |||||||||||||||||||||||||||||||||||||||||
| 1263 | 2 | my $tic_distance = ($graph_box->[3] - $graph_box->[1]) / ($tic_count - 1); | |||||||||||||||||||||||||||||||||||||||||
| 1264 | 2 | for my $count (0 .. $tic_count - 1) { | |||||||||||||||||||||||||||||||||||||||||
| 1265 | 15 | my $x1 = $graph_box->[0] - 5; | |||||||||||||||||||||||||||||||||||||||||
| 1266 | 15 | my $x2 = $graph_box->[0] + 5; | |||||||||||||||||||||||||||||||||||||||||
| 1267 | 15 | my $y1 = int($graph_box->[3] - ($count * $tic_distance)); | |||||||||||||||||||||||||||||||||||||||||
| 1268 | |||||||||||||||||||||||||||||||||||||||||||
| 1269 | 15 | my $value = ($count*$interval)+$min; | |||||||||||||||||||||||||||||||||||||||||
| 1270 | 15 | ▶ | if ($interval < 1 || ($value != int($value))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$interval < 1 or $value != int $value
MC/DC50%1/2
$interval < 1 or $value != int $value
$interval < 1
$value != int $value
Truth table66%2/3
A or B
A= $interval < 1B= $value != int $value
| |||||||||||||||||||||||||||||||||||||||||||
| 1271 | 3 | $value = sprintf("%.2f", $value); | |||||||||||||||||||||||||||||||||||||||||
| 1272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1273 | |||||||||||||||||||||||||||||||||||||||||||
| 1274 | 15 | ▶ | my @box = $self->_text_bbox($value, 'legend') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1275 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1276 | |||||||||||||||||||||||||||||||||||||||||||
| 1277 | 15 | $img->line(x1 => $x1, x2 => $x2, y1 => $y1, y2 => $y1, aa => 1, color => $line_style); | |||||||||||||||||||||||||||||||||||||||||
| 1278 | |||||||||||||||||||||||||||||||||||||||||||
| 1279 | 15 | my $width = $box[2]; | |||||||||||||||||||||||||||||||||||||||||
| 1280 | 15 | my $height = $box[3]; | |||||||||||||||||||||||||||||||||||||||||
| 1281 | |||||||||||||||||||||||||||||||||||||||||||
| 1282 | 15 | $img->string(%text_info, | |||||||||||||||||||||||||||||||||||||||||
| 1283 | x => ($x1 - $width - 3), | ||||||||||||||||||||||||||||||||||||||||||
| 1284 | y => ($y1 + ($height / 2)), | ||||||||||||||||||||||||||||||||||||||||||
| 1285 | text => $value | ||||||||||||||||||||||||||||||||||||||||||
| 1286 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1287 | |||||||||||||||||||||||||||||||||||||||||||
| 1288 | 15 | ▶ | if ($show_gridlines && $y1 != $graph_box->[1] && $y1 != $graph_box->[3]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$show_gridlines and $y1 != $graph_box->[1] and $y1 != $graph_box->[3]
$show_gridlines and $y1 != $graph_box->[1]
MC/DC100%3/3
$show_gridlines and $y1 != $graph_box->[1] and $y1 != $graph_box->[3]
$show_gridlines
$y1 != $graph_box->[1]
$y1 != $graph_box->[3]
Truth table100%4/4
A and B and C
A= $show_gridlinesB= $y1 != $graph_box->[1]C= $y1 != $graph_box->[3]
| |||||||||||||||||||||||||||||||||||||||||||
| 1289 | 8 | $self->_line(x1 => $graph_box->[0], y1 => $y1, | |||||||||||||||||||||||||||||||||||||||||
| 1290 | x2 => $graph_box->[2], y2 => $y1, | ||||||||||||||||||||||||||||||||||||||||||
| 1291 | img => $img, | ||||||||||||||||||||||||||||||||||||||||||
| 1292 | @grid_line); | ||||||||||||||||||||||||||||||||||||||||||
| 1293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1295 | |||||||||||||||||||||||||||||||||||||||||||
| 1296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1297 | |||||||||||||||||||||||||||||||||||||||||||
| 1298 | sub _draw_x_tics { | ||||||||||||||||||||||||||||||||||||||||||
| 1299 | 12 | ▶ | my ($self, $opts) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_draw_x_tics: called CC=11 SCAR=25.5
| |||||||||||||||||||||||||||||||||||||||||||
| 1300 | |||||||||||||||||||||||||||||||||||||||||||
| 1301 | 12 | my $img = $self->_get_image(); | |||||||||||||||||||||||||||||||||||||||||
| 1302 | 12 | my $graph_box = $self->_get_graph_box(); | |||||||||||||||||||||||||||||||||||||||||
| 1303 | 12 | my $image_box = $self->_get_image_box(); | |||||||||||||||||||||||||||||||||||||||||
| 1304 | |||||||||||||||||||||||||||||||||||||||||||
| 1305 | 12 | my $labels = $self->_get_labels($opts); | |||||||||||||||||||||||||||||||||||||||||
| 1306 | |||||||||||||||||||||||||||||||||||||||||||
| 1307 | 12 | my $tic_count = (scalar @$labels) - 1; | |||||||||||||||||||||||||||||||||||||||||
| 1308 | |||||||||||||||||||||||||||||||||||||||||||
| 1309 | 12 | ▶ | my $has_columns = (defined $self->_get_data_series()->{'column'} || defined $self->_get_data_series()->{'stacked_column'}); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
defined $self->_get_data_series->{'column'} || defined $self->_get_data_series->{'stacked_column'}
MC/DC100%2/2
defined $self->_get_data_series->{'column'} || defined $self->_get_data_series->{'stacked_column'}
defined $self->_get_data_series->{'column'}
defined $self->_get_data_series->{'stacked_column'}
Truth table100%3/3
A || B
A= defined $self->_get_data_series->{'column'}B= defined $self->_get_data_series->{'stacked_column'}
| |||||||||||||||||||||||||||||||||||||||||||
| 1310 | |||||||||||||||||||||||||||||||||||||||||||
| 1311 | # If we have columns, we want the x-ticks to show up in the middle of the column, not on the left edge | ||||||||||||||||||||||||||||||||||||||||||
| 1312 | 12 | my $denominator = $tic_count; | |||||||||||||||||||||||||||||||||||||||||
| 1313 | 12 | ▶ | if ($has_columns) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1314 | 5 | $denominator ++; | |||||||||||||||||||||||||||||||||||||||||
| 1315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1316 | 12 | my $tic_distance = ($graph_box->[2] - $graph_box->[0]) / ($denominator); | |||||||||||||||||||||||||||||||||||||||||
| 1317 | 12 | ▶ | my %text_info = $self->_text_style('legend') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1318 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1319 | |||||||||||||||||||||||||||||||||||||||||||
| 1320 | # If automatic axis is turned on, let's be selective about what labels we draw. | ||||||||||||||||||||||||||||||||||||||||||
| 1321 | 5 | my $max_size = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1322 | 5 | my $tic_skip = 0; | |||||||||||||||||||||||||||||||||||||||||
| 1323 | 5 | ▶ | if ($self->_get_number('automatic_axis')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1324 | 0 | foreach my $label (@$labels) { | |||||||||||||||||||||||||||||||||||||||||
| 1325 | 0 | my @box = $self->_text_bbox($label, 'legend'); | |||||||||||||||||||||||||||||||||||||||||
| 1326 | 0 | ▶ | if ($box[2] > $max_size) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1327 | 0 | $max_size = $box[2]; | |||||||||||||||||||||||||||||||||||||||||
| 1328 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1329 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1330 | |||||||||||||||||||||||||||||||||||||||||||
| 1331 | # Give the max_size some padding... | ||||||||||||||||||||||||||||||||||||||||||
| 1332 | 0 | $max_size *= 1.2; | |||||||||||||||||||||||||||||||||||||||||
| 1333 | |||||||||||||||||||||||||||||||||||||||||||
| 1334 | 0 | $tic_skip = int($max_size / $tic_distance) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 1335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1336 | |||||||||||||||||||||||||||||||||||||||||||
| 1337 | 5 | my $line_style = $self->_get_color('outline.line'); | |||||||||||||||||||||||||||||||||||||||||
| 1338 | |||||||||||||||||||||||||||||||||||||||||||
| 1339 | 5 | for my $count (0 .. $tic_count) { | |||||||||||||||||||||||||||||||||||||||||
| 1340 | 30 | ▶ | next if ($count % ($tic_skip + 1)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1341 | 30 | my $label = $labels->[$count]; | |||||||||||||||||||||||||||||||||||||||||
| 1342 | 30 | my $x1 = $graph_box->[0] + ($tic_distance * $count); | |||||||||||||||||||||||||||||||||||||||||
| 1343 | |||||||||||||||||||||||||||||||||||||||||||
| 1344 | 30 | ▶ | if ($has_columns) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1345 | 0 | $x1 += $tic_distance / 2; | |||||||||||||||||||||||||||||||||||||||||
| 1346 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1347 | |||||||||||||||||||||||||||||||||||||||||||
| 1348 | 30 | $x1 = int($x1); | |||||||||||||||||||||||||||||||||||||||||
| 1349 | |||||||||||||||||||||||||||||||||||||||||||
| 1350 | 30 | my $y1 = $graph_box->[3] + 5; | |||||||||||||||||||||||||||||||||||||||||
| 1351 | 30 | my $y2 = $graph_box->[3] - 5; | |||||||||||||||||||||||||||||||||||||||||
| 1352 | |||||||||||||||||||||||||||||||||||||||||||
| 1353 | 30 | $img->line(x1 => $x1, x2 => $x1, y1 => $y1, y2 => $y2, aa => 1, color => $line_style); | |||||||||||||||||||||||||||||||||||||||||
| 1354 | |||||||||||||||||||||||||||||||||||||||||||
| 1355 | 30 | ▶ | my @box = $self->_text_bbox($label, 'legend') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1356 | or return; | ||||||||||||||||||||||||||||||||||||||||||
| 1357 | |||||||||||||||||||||||||||||||||||||||||||
| 1358 | 30 | my $width = $box[2]; | |||||||||||||||||||||||||||||||||||||||||
| 1359 | 30 | my $height = $box[3]; | |||||||||||||||||||||||||||||||||||||||||
| 1360 | |||||||||||||||||||||||||||||||||||||||||||
| 1361 | 30 | $img->string(%text_info, | |||||||||||||||||||||||||||||||||||||||||
| 1362 | x => ($x1 - ($width / 2)), | ||||||||||||||||||||||||||||||||||||||||||
| 1363 | y => ($y1 + ($height + 5)), | ||||||||||||||||||||||||||||||||||||||||||
| 1364 | text => $label | ||||||||||||||||||||||||||||||||||||||||||
| 1365 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 1366 | |||||||||||||||||||||||||||||||||||||||||||
| 1367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1369 | |||||||||||||||||||||||||||||||||||||||||||
| 1370 | sub _valid_input { | ||||||||||||||||||||||||||||||||||||||||||
| 1371 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_valid_input: called CC=9 SCAR=25.8
| |||||||||||||||||||||||||||||||||||||||||||
| 1372 | |||||||||||||||||||||||||||||||||||||||||||
| 1373 | 12 | ▶ | if (!defined $self->_get_data_series() || !keys %{$self->_get_data_series()}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->_get_data_series and keys %{$self->_get_data_series;}
MC/DC0%0/2
defined $self->_get_data_series and keys %{$self->_get_data_series;}
defined $self->_get_data_series
keys %{$self->_get_data_series;}
Truth table33%1/3
A and B
A= defined $self->_get_data_seriesB= keys %{$self->_get_data_series;}
| |||||||||||||||||||||||||||||||||||||||||||
| 1374 | 0 | return $self->_error("No data supplied"); | |||||||||||||||||||||||||||||||||||||||||
| 1375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1376 | |||||||||||||||||||||||||||||||||||||||||||
| 1377 | 12 | my $data = $self->_get_data_series(); | |||||||||||||||||||||||||||||||||||||||||
| 1378 | 12 | ▶ | if (defined $data->{'line'} && !scalar @{$data->{'line'}->[0]->{'data'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $data->{"line"} and not scalar @{$data->{"line"}[0]{"data"};}
MC/DC0%0/2
defined $data->{"line"} and not scalar @{$data->{"line"}[0]{"data"};}
defined $data->{"line"}
not scalar @{$data->{"line"}[0]{"data"};}
Truth table66%2/3
A and not(B)
A= defined $data->{"line"}B= not scalar @{$data->{"line"}[0]{"data"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 1379 | 0 | return $self->_error("No values in data series"); | |||||||||||||||||||||||||||||||||||||||||
| 1380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1381 | 12 | ▶ | if (defined $data->{'column'} && !scalar @{$data->{'column'}->[0]->{'data'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $data->{"column"} and not scalar @{$data->{"column"}[0]{"data"};}
MC/DC0%0/2
defined $data->{"column"} and not scalar @{$data->{"column"}[0]{"data"};}
defined $data->{"column"}
not scalar @{$data->{"column"}[0]{"data"};}
Truth table66%2/3
A and not(B)
A= defined $data->{"column"}B= not scalar @{$data->{"column"}[0]{"data"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 1382 | 0 | return $self->_error("No values in data series"); | |||||||||||||||||||||||||||||||||||||||||
| 1383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1384 | 12 | ▶ | if (defined $data->{'stacked_column'} && !scalar @{$data->{'stacked_column'}->[0]->{'data'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $data->{"stacked_column"} and not scalar @{$data->{"stacked_column"}[0]{"data"};}
MC/DC0%0/2
defined $data->{"stacked_column"} and not scalar @{$data->{"stacked_column"}[0]{"data"};}
defined $data->{"stacked_column"}
not scalar @{$data->{"stacked_column"}[0]{"data"};}
Truth table66%2/3
A and not(B)
A= defined $data->{"stacked_column"}B= not scalar @{$data->{"stacked_column"}[0]{"data"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 1385 | 0 | return $self->_error("No values in data series"); | |||||||||||||||||||||||||||||||||||||||||
| 1386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1387 | |||||||||||||||||||||||||||||||||||||||||||
| 1388 | 12 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 1389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1390 | |||||||||||||||||||||||||||||||||||||||||||
| 1391 | 12 | ▶ | sub _set_column_count { $_[0]->{'column_count'} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_column_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1392 | 12 | ▶ | sub _set_min_value { $_[0]->{'min_value'} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_min_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1393 | 12 | ▶ | sub _set_max_value { $_[0]->{'max_value'} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_max_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1394 | 12 | ▶ | sub _set_image_box { $_[0]->{'image_box'} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_image_box: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1395 | 12 | ▶ | sub _set_graph_box { $_[0]->{'graph_box'} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_graph_box: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1396 | 12 | ▶ | sub _set_series_counter { $_[0]->{'series_counter'} = $_[1]; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_series_counter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1397 | 24 | ▶ | sub _get_column_count { return $_[0]->{'column_count'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_column_count: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1398 | 38 | ▶ | sub _get_min_value { return $_[0]->{'min_value'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_min_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1399 | 38 | ▶ | sub _get_max_value { return $_[0]->{'max_value'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_max_value: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1400 | 14 | ▶ | sub _get_image_box { return $_[0]->{'image_box'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_image_box: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1401 | 26 | ▶ | sub _get_graph_box { return $_[0]->{'graph_box'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_graph_box: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1402 | 12 | ▶ | sub _reset_series_counter { $_[0]->{series_counter} = 0 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_reset_series_counter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1403 | 12 | ▶ | sub _get_series_counter { return $_[0]->{'series_counter'} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_series_counter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1404 | |||||||||||||||||||||||||||||||||||||||||||
| 1405 | sub _style_defs { | ||||||||||||||||||||||||||||||||||||||||||
| 1406 | 12 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_style_defs: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1407 | |||||||||||||||||||||||||||||||||||||||||||
| 1408 | 12 | my %work = %{$self->SUPER::_style_defs()}; | |||||||||||||||||||||||||||||||||||||||||
| 1409 | $work{area} = | ||||||||||||||||||||||||||||||||||||||||||
| 1410 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1411 | 12 | opacity => 0.5, | |||||||||||||||||||||||||||||||||||||||||
| 1412 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1413 | 12 | push @{$work{features}}, qw/graph_outline graph_fill linemarkers/; | |||||||||||||||||||||||||||||||||||||||||
| 1414 | $work{hgrid} = | ||||||||||||||||||||||||||||||||||||||||||
| 1415 | { | ||||||||||||||||||||||||||||||||||||||||||
| 1416 | 12 | color => "lookup(fg)", | |||||||||||||||||||||||||||||||||||||||||
| 1417 | style => "solid", | ||||||||||||||||||||||||||||||||||||||||||
| 1418 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1419 | |||||||||||||||||||||||||||||||||||||||||||
| 1420 | 12 | return \%work; | |||||||||||||||||||||||||||||||||||||||||
| 1421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1422 | |||||||||||||||||||||||||||||||||||||||||||
| 1423 | sub _composite { | ||||||||||||||||||||||||||||||||||||||||||
| 1424 | 12 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_composite: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1425 | 12 | return ( $self->SUPER::_composite(), "graph", "hgrid" ); | |||||||||||||||||||||||||||||||||||||||||
| 1426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1427 | |||||||||||||||||||||||||||||||||||||||||||
| 1428 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 1429 | |||||||||||||||||||||||||||||||||||||||||||
| 1430 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 1431 | |||||||||||||||||||||||||||||||||||||||||||
| 1432 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 1433 | |||||||||||||||||||||||||||||||||||||||||||
| 1434 | Patrick Michaud, Tony Cook. | ||||||||||||||||||||||||||||||||||||||||||
| 1435 | |||||||||||||||||||||||||||||||||||||||||||
| 1436 | =cut | ||||||||||||||||||||||||||||||||||||||||||