1 package Imager::Graph::Vertical;
5 Imager::Graph::Vertical- A super class for line/bar/column charts
12 @ISA = qw(Imager::Graph);
14 use constant STARTING_MIN_VALUE => 99999;
17 =item add_data_series(\@data, $series_name)
19 Add a data series to the graph, of the default type.
26 my $series_name = shift;
28 my $series_type = $self->_get_default_series_type();
29 $self->_add_data_series($series_type, $data_ref, $series_name);
34 =item add_column_data_series(\@data, $series_name)
36 Add a column data series to the graph.
40 sub add_column_data_series {
43 my $series_name = shift;
45 $self->_add_data_series('column', $data_ref, $series_name);
50 =item add_stacked_column_data_series(\@data, $series_name)
52 Add a stacked column data series to the graph.
56 sub add_stacked_column_data_series {
59 my $series_name = shift;
61 $self->_add_data_series('stacked_column', $data_ref, $series_name);
66 =item add_line_data_series(\@data, $series_name)
68 Add a line data series to the graph.
72 sub add_line_data_series {
75 my $series_name = shift;
77 $self->_add_data_series('line', $data_ref, $series_name);
82 =item set_y_max($value)
84 Sets the maximum y value to be displayed. This will be ignored if the y_max is lower than the highest value.
89 $_[0]->{'custom_style'}->{'y_max'} = $_[1];
92 =item set_y_min($value)
94 Sets the minimum y value to be displayed. This will be ignored if the y_min is higher than the lowest value.
99 $_[0]->{'custom_style'}->{'y_min'} = $_[1];
102 =item set_range_padding($percentage)
104 Sets the padding to be used, as a percentage. For example, if your data ranges from 0 to 10, and you have a 20 percent padding, the y axis will go to 12.
106 Defaults to 10. This attribute is ignored for positive numbers if set_y_max() has been called, and ignored for negative numbers if set_y_min() has been called.
110 sub set_range_padding {
111 $_[0]->{'custom_style'}->{'range_padding'} = $_[1];
114 =item set_negative_background($color)
116 Sets the background color used below the x axis.
120 sub set_negative_background {
121 $_[0]->{'custom_style'}->{'negative_bg'} = $_[1];
131 my ($self, %opts) = @_;
133 if (!$self->_valid_input()) {
137 $self->_style_setup(\%opts);
139 my $style = $self->{_style};
141 my $img = $self->_get_image()
144 my @image_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 );
145 $self->_set_image_box(\@image_box);
147 my @chart_box = ( 0, 0, $img->getwidth-1, $img->getheight-1 );
148 $self->_draw_legend(\@chart_box);
149 if ($style->{title}{text}) {
150 $self->_draw_title($img, \@chart_box)
154 # Scale the graph box down to the widest graph that can cleanly hold the # of columns.
155 $self->_get_data_range();
156 $self->_remove_tics_from_chart_box(\@chart_box);
157 my $column_count = $self->_get_column_count();
159 my $width = $self->_get_number('width');
160 my $height = $self->_get_number('height');
162 my $graph_width = $chart_box[2] - $chart_box[0];
163 my $graph_height = $chart_box[3] - $chart_box[1];
165 my $col_width = int(($graph_width - 1) / $column_count) -1;
166 $graph_width = $col_width * $column_count + 1;
168 my $tic_count = $self->_get_y_tics();
169 my $tic_distance = int(($graph_height-1) / ($tic_count - 1));
170 $graph_height = $tic_distance * ($tic_count - 1);
172 my $bottom = $chart_box[1];
173 my $left = $chart_box[0];
175 $self->{'_style'}{'graph_width'} = $graph_width;
176 $self->{'_style'}{'graph_height'} = $graph_height;
178 my @graph_box = ($left, $bottom, $left + $graph_width, $bottom + $graph_height);
179 $self->_set_graph_box(\@graph_box);
182 color => $self->_get_color('outline.line'),
184 xmax => $left+$graph_width,
186 ymax => $bottom+$graph_height,
190 color => $self->_get_color('bg'),
192 xmax => $left+$graph_width - 1,
194 ymax => $bottom+$graph_height-1 ,
198 my $min_value = $self->_get_min_value();
199 my $max_value = $self->_get_max_value();
200 my $value_range = $max_value - $min_value;
204 $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height-1);
207 if ($min_value < 0) {
209 color => $self->_get_color('negative_bg'),
211 xmax => $left+$graph_width- 1,
212 ymin => $zero_position,
213 ymax => $bottom+$graph_height - 1,
218 y1 => $zero_position,
219 x2 => $left + $graph_width,
220 y2 => $zero_position,
221 color => $self->_get_color('outline.line'),
225 if ($self->_get_data_series()->{'stacked_column'}) {
226 $self->_draw_stacked_columns();
228 if ($self->_get_data_series()->{'column'}) {
229 $self->_draw_columns();
231 if ($self->_get_data_series()->{'line'}) {
232 $self->_draw_lines();
235 if ($self->_get_y_tics()) {
236 $self->_draw_y_tics();
238 if ($self->_get_labels()) {
239 $self->_draw_x_tics();
242 return $self->_get_image();
245 sub _get_data_range {
250 my $column_count = 0;
252 my ($sc_min, $sc_max, $sc_cols) = $self->_get_stacked_column_range();
253 my ($c_min, $c_max, $c_cols) = $self->_get_column_range();
254 my ($l_min, $l_max, $l_cols) = $self->_get_line_range();
256 # These are side by side...
259 $min_value = $self->_min(STARTING_MIN_VALUE, $sc_min, $c_min, $l_min);
260 $max_value = $self->_max(0, $sc_max, $c_max, $l_max);
262 my $config_min = $self->_get_number('y_min');
263 my $config_max = $self->_get_number('y_max');
265 if (defined $config_max && $config_max < $max_value) {
268 if (defined $config_min && $config_min > $min_value) {
272 my $range_padding = $self->_get_number('range_padding');
273 if (defined $config_min) {
274 $min_value = $config_min;
277 if ($min_value > 0) {
280 if ($range_padding && $min_value < 0) {
281 my $difference = $min_value * $range_padding / 100;
282 if ($min_value < -1 && $difference > -1) {
285 $min_value += $difference;
288 if (defined $config_max) {
289 $max_value = $config_max;
292 if ($range_padding && $max_value > 0) {
293 my $difference = $max_value * $range_padding / 100;
294 if ($max_value > 1 && $difference < 1) {
297 $max_value += $difference;
300 $column_count = $self->_max(0, $sc_cols, $l_cols);
302 if ($self->_get_number('automatic_axis')) {
303 # In case this was set via a style, and not by the api method
304 eval { require "Chart/Math/Axis.pm"; };
306 die "Can't use automatic_axis - $@";
309 my $axis = Chart::Math::Axis->new();
310 $axis->add_data($min_value, $max_value);
311 $max_value = $axis->top;
312 $min_value = $axis->bottom;
313 my $ticks = $axis->ticks;
314 # The +1 is there because we have the bottom tick as well
315 $self->set_y_tics($ticks+1);
318 $self->_set_max_value($max_value);
319 $self->_set_min_value($min_value);
320 $self->_set_column_count($column_count);
327 foreach my $value (@_) {
328 next unless defined $value;
329 if ($value < $min) { $min = $value; }
338 foreach my $value (@_) {
339 next unless defined $value;
340 if ($value > $min) { $min = $value; }
345 sub _get_line_range {
347 my $series = $self->_get_data_series()->{'line'};
348 return (undef, undef, 0) unless $series;
351 my $min_value = STARTING_MIN_VALUE;
352 my $column_count = 0;
354 my @series = @{$series};
355 foreach my $series (@series) {
356 my @data = @{$series->{'data'}};
358 if (scalar @data > $column_count) {
359 $column_count = scalar @data;
362 foreach my $value (@data) {
363 if ($value > $max_value) { $max_value = $value; }
364 if ($value < $min_value) { $min_value = $value; }
368 return ($min_value, $max_value, $column_count);
371 sub _get_column_range {
374 my $series = $self->_get_data_series()->{'column'};
375 return (undef, undef, 0) unless $series;
378 my $min_value = STARTING_MIN_VALUE;
379 my $column_count = 0;
381 my @series = @{$series};
382 foreach my $series (@series) {
383 my @data = @{$series->{'data'}};
385 foreach my $value (@data) {
387 if ($value > $max_value) { $max_value = $value; }
388 if ($value < $min_value) { $min_value = $value; }
392 return ($min_value, $max_value, $column_count);
395 sub _get_stacked_column_range {
399 my $min_value = STARTING_MIN_VALUE;
400 my $column_count = 0;
402 return (undef, undef, 0) unless $self->_get_data_series()->{'stacked_column'};
403 my @series = @{$self->_get_data_series()->{'stacked_column'}};
407 for (my $i = scalar @series - 1; $i >= 0; $i--) {
408 my $series = $series[$i];
409 my $data = $series->{'data'};
411 for (my $i = 0; $i < scalar @$data; $i++) {
413 if ($data->[$i] > 0) {
414 $value = $data->[$i] + ($max_entries[$i] || 0);
415 $data->[$i] = $value;
416 $max_entries[$i] = $value;
418 elsif ($data->[$i] < 0) {
419 $value = $data->[$i] + ($min_entries[$i] || 0);
420 $data->[$i] = $value;
421 $min_entries[$i] = $value;
423 if ($value > $max_value) { $max_value = $value; }
424 if ($value < $min_value) { $min_value = $value; }
426 if (scalar @$data > $column_count) {
427 $column_count = scalar @$data;
431 return ($min_value, $max_value, $column_count);
436 my $chart_box = shift;
437 my $style = $self->{'_style'};
440 my $img = $self->_get_image();
441 if (my $series = $self->_get_data_series()->{'stacked_column'}) {
442 push @labels, map { $_->{'series_name'} } @$series;
444 if (my $series = $self->_get_data_series()->{'column'}) {
445 push @labels, map { $_->{'series_name'} } @$series;
447 if (my $series = $self->_get_data_series()->{'line'}) {
448 push @labels, map { $_->{'series_name'} } @$series;
451 if ($style->{features}{legend} && (scalar @labels)) {
452 $self->SUPER::_draw_legend($self->_get_image(), \@labels, $chart_box)
458 sub _draw_flat_legend {
464 my $style = $self->{'_style'};
466 my $img = $self->_get_image();
468 my $max_value = $self->_get_max_value();
469 my $min_value = $self->_get_min_value();
470 my $column_count = $self->_get_column_count();
472 my $value_range = $max_value - $min_value;
474 my $width = $self->_get_number('width');
475 my $height = $self->_get_number('height');
477 my $graph_width = $self->_get_number('graph_width');
478 my $graph_height = $self->_get_number('graph_height');
480 my $line_series = $self->_get_data_series()->{'line'};
481 my $series_counter = $self->_get_series_counter() || 0;
483 my $has_columns = (defined $self->_get_data_series()->{'column'} || $self->_get_data_series->{'stacked_column'}) ? 1 : 0;
485 my $col_width = int($graph_width / $column_count) -1;
487 my $graph_box = $self->_get_graph_box();
488 my $left = $graph_box->[0] + 1;
489 my $bottom = $graph_box->[1];
491 my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height - 1);
494 my $line_aa = $self->_get_number("lineaa");
495 foreach my $series (@$line_series) {
496 my @data = @{$series->{'data'}};
497 my $data_size = scalar @data;
501 $interval = $graph_width / ($data_size);
504 $interval = $graph_width / ($data_size - 1);
506 my $color = $self->_data_color($series_counter);
508 # We need to add these last, otherwise the next line segment will overwrite half of the marker
509 my @marker_positions;
510 for (my $i = 0; $i < $data_size - 1; $i++) {
511 my $x1 = $left + $i * $interval;
512 my $x2 = $left + ($i + 1) * $interval;
514 $x1 += $has_columns * $interval / 2;
515 $x2 += $has_columns * $interval / 2;
517 my $y1 = $bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height;
518 my $y2 = $bottom + ($value_range - $data[$i + 1] + $min_value)/$value_range * $graph_height;
520 push @marker_positions, [$x1, $y1];
521 $img->line(x1 => $x1, y1 => $y1, x2 => $x2, y2 => $y2, aa => $line_aa, color => $color) || die $img->errstr;
524 my $x2 = $left + ($data_size - 1) * $interval;
525 $x2 += $has_columns * $interval / 2;
527 my $y2 = $bottom + ($value_range - $data[$data_size - 1] + $min_value)/$value_range * $graph_height;
529 push @marker_positions, [$x2, $y2];
530 foreach my $position (@marker_positions) {
531 $self->_draw_line_marker($position->[0], $position->[1], $series_counter);
536 $self->_set_series_counter($series_counter);
541 my ($self, $index) = @_;
543 my $markers = $self->{'_style'}{'line_markers'};
547 my $marker = $markers->[$index % @$markers];
552 sub _draw_line_marker {
554 my ($x1, $y1, $series_counter) = @_;
556 my $img = $self->_get_image();
558 my $style = $self->_line_marker($series_counter);
559 return unless $style;
561 my $type = $style->{'shape'};
562 my $radius = $style->{'radius'};
564 my $line_aa = $self->_get_number("lineaa");
565 my $fill_aa = $self->_get_number("fill.aa");
566 if ($type eq 'circle') {
567 my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
568 $img->circle(x => $x1, y => $y1, r => $radius, aa => $fill_aa, filled => 1, @fill);
570 elsif ($type eq 'square') {
571 my @fill = $self->_data_fill($series_counter, [$x1 - $radius, $y1 - $radius, $x1 + $radius, $y1 + $radius]);
572 $img->box(xmin => $x1 - $radius, ymin => $y1 - $radius, xmax => $x1 + $radius, ymax => $y1 + $radius, @fill);
574 elsif ($type eq 'diamond') {
575 # The gradient really doesn't work for diamond
576 my $color = $self->_data_color($series_counter);
579 [$x1 - $radius, $y1],
580 [$x1, $y1 + $radius],
581 [$x1 + $radius, $y1],
582 [$x1, $y1 - $radius],
584 filled => 1, color => $color, aa => $fill_aa);
586 elsif ($type eq 'triangle') {
587 # The gradient really doesn't work for triangle
588 my $color = $self->_data_color($series_counter);
591 [$x1 - $radius, $y1 + $radius],
592 [$x1 + $radius, $y1 + $radius],
593 [$x1, $y1 - $radius],
595 filled => 1, color => $color, aa => $fill_aa);
598 elsif ($type eq 'x') {
599 my $color = $self->_data_color($series_counter);
600 $img->line(x1 => $x1 - $radius, y1 => $y1 -$radius, x2 => $x1 + $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
601 $img->line(x1 => $x1 + $radius, y1 => $y1 -$radius, x2 => $x1 - $radius, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
603 elsif ($type eq 'plus') {
604 my $color = $self->_data_color($series_counter);
605 $img->line(x1 => $x1, y1 => $y1 -$radius, x2 => $x1, y2 => $y1+$radius, aa => $line_aa, color => $color) || die $img->errstr;
606 $img->line(x1 => $x1 + $radius, y1 => $y1, x2 => $x1 - $radius, y2 => $y1, aa => $line_aa, color => $color) || die $img->errstr;
612 my $style = $self->{'_style'};
614 my $img = $self->_get_image();
616 my $max_value = $self->_get_max_value();
617 my $min_value = $self->_get_min_value();
618 my $column_count = $self->_get_column_count();
620 my $value_range = $max_value - $min_value;
622 my $width = $self->_get_number('width');
623 my $height = $self->_get_number('height');
625 my $graph_width = $self->_get_number('graph_width');
626 my $graph_height = $self->_get_number('graph_height');
629 my $graph_box = $self->_get_graph_box();
630 my $left = $graph_box->[0] + 1;
631 my $bottom = $graph_box->[1];
632 my $zero_position = int($bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1));
634 my $bar_width = int($graph_width / $column_count - 1);
637 if ($style->{'features'}{'outline'}) {
638 $outline_color = $self->_get_color('outline.line');
641 my $series_counter = $self->_get_series_counter() || 0;
642 my $col_series = $self->_get_data_series()->{'column'};
644 # 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.
645 my $column_series = 0;
647 # If there are stacked columns, non-stacked columns need to start one to the right of where they would otherwise
648 my $has_stacked_columns = (defined $self->_get_data_series()->{'stacked_column'} ? 1 : 0);
650 for (my $series_pos = 0; $series_pos < scalar @$col_series; $series_pos++) {
651 my $series = $col_series->[$series_pos];
652 my @data = @{$series->{'data'}};
653 my $data_size = scalar @data;
654 my $color = $self->_data_color($series_counter);
655 for (my $i = 0; $i < $data_size; $i++) {
656 my $x1 = int($left + $bar_width * (scalar @$col_series * $i + $series_pos)) + scalar @$col_series * $i + $series_pos;
657 if ($has_stacked_columns) {
658 $x1 += ($i + 1) * $bar_width + $i + 1;
660 my $x2 = $x1 + $bar_width;
662 my $y1 = int($bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height);
664 my $color = $self->_data_color($series_counter);
666 # my @fill = $self->_data_fill($series_counter, [$x1, $y1, $x2, $zero_position]);
668 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position-1, color => $color, filled => 1);
669 if ($style->{'features'}{'outline'}) {
670 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position, color => $outline_color);
674 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1, color => $color, filled => 1);
675 if ($style->{'features'}{'outline'}) {
676 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1+1, color => $outline_color);
684 $self->_set_series_counter($series_counter);
688 sub _draw_stacked_columns {
690 my $style = $self->{'_style'};
692 my $img = $self->_get_image();
694 my $max_value = $self->_get_max_value();
695 my $min_value = $self->_get_min_value();
696 my $column_count = $self->_get_column_count();
697 my $value_range = $max_value - $min_value;
699 my $graph_box = $self->_get_graph_box();
700 my $left = $graph_box->[0] + 1;
701 my $bottom = $graph_box->[1];
703 my $graph_width = $self->_get_number('graph_width');
704 my $graph_height = $self->_get_number('graph_height');
706 my $bar_width = int($graph_width / $column_count -1);
707 my $column_series = 0;
708 if (my $column_series_data = $self->_get_data_series()->{'column'}) {
709 $column_series = (scalar @$column_series_data);
714 if ($style->{'features'}{'outline'}) {
715 $outline_color = $self->_get_color('outline.line');
718 my $zero_position = $bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1);
719 my $col_series = $self->_get_data_series()->{'stacked_column'};
720 my $series_counter = $self->_get_series_counter() || 0;
721 foreach my $series (@$col_series) {
722 my @data = @{$series->{'data'}};
723 my $data_size = scalar @data;
724 my $color = $self->_data_color($series_counter);
725 for (my $i = 0; $i < $data_size; $i++) {
726 my $x1 = int($left + $bar_width * ($column_series * $i)) + $column_series * $i;
727 my $x2 = $x1 + $bar_width;
729 my $y1 = $bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height;
732 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position-1, color => $color, filled => 1);
733 if ($style->{'features'}{'outline'}) {
734 $img->box(xmin => $x1, xmax => $x2, ymin => $y1, ymax => $zero_position, color => $outline_color);
738 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1, color => $color, filled => 1);
739 if ($style->{'features'}{'outline'}) {
740 $img->box(xmin => $x1, xmax => $x2, ymin => $zero_position+1, ymax => $y1+1, color => $outline_color);
747 $self->_set_series_counter($series_counter);
751 sub _add_data_series {
753 my $series_type = shift;
754 my $data_ref = shift;
755 my $series_name = shift;
757 my $graph_data = $self->{'graph_data'} || {};
759 my $series = $graph_data->{$series_type} || [];
761 push @$series, { data => $data_ref, series_name => $series_name };
763 $graph_data->{$series_type} = $series;
765 $self->{'graph_data'} = $graph_data;
771 =item show_horizontal_gridlines()
773 Shows horizontal gridlines at the y-tics.
777 sub show_horizontal_gridlines {
778 $_[0]->{'custom_style'}->{'horizontal_gridlines'} = 1;
781 =item use_automatic_axis()
783 Automatically scale the Y axis, based on L<Chart::Math::Axis>
787 sub use_automatic_axis {
788 eval { require "Chart/Math/Axis.pm"; };
790 die "use_automatic_axis - $@\nCalled from ".join(' ', caller)."\n";
792 $_[0]->{'custom_style'}->{'automatic_axis'} = 1;
796 =item set_y_tics($count)
798 Set the number of Y tics to use. Their value and position will be determined by the data range.
803 $_[0]->{'y_tics'} = $_[1];
807 return $_[0]->{'y_tics'} || 0;
810 sub _remove_tics_from_chart_box {
812 my $chart_box = shift;
815 my $tic_width = $self->_get_y_tic_width() || 10;
816 my @y_tic_box = ($chart_box->[0], $chart_box->[1], $chart_box->[0] + $tic_width, $chart_box->[3]);
819 my $tic_height = $self->_get_x_tic_height() || 10;
820 my @x_tic_box = ($chart_box->[0], $chart_box->[3] - $tic_height, $chart_box->[2], $chart_box->[3]);
822 $self->_remove_box($chart_box, \@y_tic_box);
823 $self->_remove_box($chart_box, \@x_tic_box);
826 sub _get_y_tic_width{
828 my $min = $self->_get_min_value();
829 my $max = $self->_get_max_value();
830 my $tic_count = $self->_get_y_tics();
832 my $img = $self->_get_image();
833 my $graph_box = $self->_get_graph_box();
834 my $image_box = $self->_get_image_box();
836 my $interval = ($max - $min) / ($tic_count - 1);
838 my %text_info = $self->_text_style('legend')
842 for my $count (0 .. $tic_count - 1) {
843 my $value = sprintf("%.2f", ($count*$interval)+$min);
845 my @box = $self->_text_bbox($value, 'legend');
846 my $width = $box[2] - $box[0];
850 if ($width > $max_width) {
858 sub _get_x_tic_height {
861 my $labels = $self->_get_labels();
863 my $tic_count = (scalar @$labels) - 1;
865 my %text_info = $self->_text_style('legend')
869 for my $count (0 .. $tic_count) {
870 my $label = $labels->[$count];
872 my @box = $self->_text_bbox($label, 'legend');
874 my $height = $box[3] - $box[1];
878 if ($height > $max_height) {
879 $max_height = $height;
888 my $min = $self->_get_min_value();
889 my $max = $self->_get_max_value();
890 my $tic_count = $self->_get_y_tics();
892 my $img = $self->_get_image();
893 my $graph_box = $self->_get_graph_box();
894 my $image_box = $self->_get_image_box();
896 my $interval = ($max - $min) / ($tic_count - 1);
898 my %text_info = $self->_text_style('legend')
901 my $show_gridlines = $self->_get_number('horizontal_gridlines');
902 my $tic_distance = int(($graph_box->[3] - $graph_box->[1]) / ($tic_count - 1));
903 for my $count (0 .. $tic_count - 1) {
904 my $x1 = $graph_box->[0] - 5;
905 my $x2 = $graph_box->[0] + 5;
906 my $y1 = $graph_box->[3] - ($count * $tic_distance);
908 my $value = ($count*$interval)+$min;
909 if ($interval < 1 || ($value != int($value))) {
910 $value = sprintf("%.2f", $value);
913 my @box = $self->_text_bbox($value, 'legend')
916 $img->line(x1 => $x1, x2 => $x2, y1 => $y1, y2 => $y1, aa => 1, color => '000000');
919 my $height = $box[3];
921 $img->string(%text_info,
922 x => ($x1 - $width - 3),
923 y => ($y1 + ($height / 2)),
927 if ($show_gridlines) {
929 for (my $i = $graph_box->[0]; $i < $graph_box->[2]; $i += 6) {
932 if ($x2 > $graph_box->[2]) { $x2 = $graph_box->[2]; }
933 $img->line(x1 => $x1, x2 => $x2, y1 => $y1, y2 => $y1, aa => 1, color => '000000');
943 my $img = $self->_get_image();
944 my $graph_box = $self->_get_graph_box();
945 my $image_box = $self->_get_image_box();
947 my $labels = $self->_get_labels();
949 my $tic_count = (scalar @$labels) - 1;
951 my $has_columns = (defined $self->_get_data_series()->{'column'} || defined $self->_get_data_series()->{'stacked_column'});
953 # If we have columns, we want the x-ticks to show up in the middle of the column, not on the left edge
954 my $denominator = $tic_count;
958 my $tic_distance = ($graph_box->[2] - $graph_box->[0]) / ($denominator);
959 my %text_info = $self->_text_style('legend')
962 for my $count (0 .. $tic_count) {
963 my $label = $labels->[$count];
964 my $x1 = $graph_box->[0] + ($tic_distance * $count);
967 $x1 += $tic_distance / 2;
969 my $y1 = $graph_box->[3] + 5;
970 my $y2 = $graph_box->[3] - 5;
972 $img->line(x1 => $x1, x2 => $x1, y1 => $y1, y2 => $y2, aa => 1, color => '000000');
974 my @box = $self->_text_bbox($label, 'legend')
978 my $height = $box[3];
980 $img->string(%text_info,
981 x => ($x1 - ($width / 2)),
982 y => ($y1 + ($height + 5)),
992 if (!defined $self->_get_data_series() || !keys %{$self->_get_data_series()}) {
993 return $self->_error("No data supplied");
996 my $data = $self->_get_data_series();
997 if (defined $data->{'line'} && !scalar @{$data->{'line'}->[0]->{'data'}}) {
998 return $self->_error("No values in data series");
1000 if (defined $data->{'column'} && !scalar @{$data->{'column'}->[0]->{'data'}}) {
1001 return $self->_error("No values in data series");
1003 if (defined $data->{'stacked_column'} && !scalar @{$data->{'stacked_column'}->[0]->{'data'}}) {
1004 return $self->_error("No values in data series");
1010 sub _set_column_count { $_[0]->{'column_count'} = $_[1]; }
1011 sub _set_min_value { $_[0]->{'min_value'} = $_[1]; }
1012 sub _set_max_value { $_[0]->{'max_value'} = $_[1]; }
1013 sub _set_image_box { $_[0]->{'image_box'} = $_[1]; }
1014 sub _set_graph_box { $_[0]->{'graph_box'} = $_[1]; }
1015 sub _set_series_counter { $_[0]->{'series_counter'} = $_[1]; }
1016 sub _get_column_count { return $_[0]->{'column_count'} }
1017 sub _get_min_value { return $_[0]->{'min_value'} }
1018 sub _get_max_value { return $_[0]->{'max_value'} }
1019 sub _get_image_box { return $_[0]->{'image_box'} }
1020 sub _get_graph_box { return $_[0]->{'graph_box'} }
1021 sub _get_series_counter { return $_[0]->{'series_counter'} }