App/Chart/Gtk2/Graph/Plugin/HLines.pm untested

filter: Statementstmt 0.0% 0 / 57 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 90 CC 5 SCAR 19.9
CC
5
Cov
0%
hrange
20.0
draw
6.0
BEGIN
2.0
CRAP 7.3
1 # Copyright 2009, 2010, 2011 Kevin Ryde
2  
3 # This file is part of Chart.
4 #
5 # Chart is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3, or (at your option) any later version.
8 #
9 # Chart is distributed in the hope that it will be useful, but WITHOUT ANY
10 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12 # details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with Chart. If not, see <http://www.gnu.org/licenses/>.
16  
17 package App::Chart::Gtk2::Graph::Plugin::HLines;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Gtk2;
22 use List::Util qw(min max);
23  
24 use base 'App::Chart::Gtk2::Graph::Plugin';
25 use App::Chart::Gtk2::GUI;
26  
27 use constant HLINE_COLOUR => App::Chart::GREY_COLOUR;
28  
29 sub draw {
30 my ($class, $graph, $region) = @_;
31  
32 my @hlines = map { @{$_->hlines} } @{$graph->{'series_list'}}
33 or return;
34  
35 my $scale_y_proc = $graph->scale_y_proc;
36 my $win = $graph->window;
37 my ($win_width, $win_height) = $win->get_size;
38 my $gc = App::Chart::Gtk2::GUI::gc_for_colour_dashed ($graph, HLINE_COLOUR);
39  
40 foreach my $p (@hlines) {
41 my $y = $scale_y_proc->($p);
42 ### hline
43 ### $p
44 ### $y
45  
46 if ($y < 0 || $y >= $win_height
47 || $region->rect_in (Gtk2::Gdk::Rectangle->new (0,$y, $win_width,1))
48 eq 'out') {
49 next;
50 }
51 $win->draw_line ($gc, 0,$y, $win_width-1,$y);
52 }
53 }
54  
55 sub hrange {
56 my ($class, $graph, $series_list) = @_;
57 my $series = $series_list->[0];
58 if (! $series) { return; }
59 my $symbol = $series->symbol;
60 if (! $symbol) { return; }
61  
62 require App::Chart::TZ;
63 my $timezone = App::Chart::TZ->for_symbol ($symbol);
64 my $timebase = $series->timebase;
65  
66 my $upper = max (map {$_->hi} @$series_list);
67 my $today = $timebase->today ($timezone);
68 if ($today - $upper >= 14) {
69 return;
70 }
71 return ($today, $today);
72 }
73  
74 1;
75 __END__