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

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 91 CC 3 SCAR 11.7
CC
3
Cov
0%
draw
6.0
hrange
6.0
BEGIN
2.0
CRAP 3.2
1 # Copyright 2007, 2008, 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::Today;
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 use App::Chart::TZ;
27  
28 use constant TODAY_COLOUR => App::Chart::GREY_COLOUR;
29  
30 sub draw {
31 my ($class, $graph, $region) = @_;
32  
33 my $series_list = $graph->{'series_list'};
34 my $series = $series_list->[0] || return;
35 my $symbol = $series->symbol || return;
36  
37 my $timezone = App::Chart::TZ->for_symbol ($symbol);
38 my $timebase = $series->timebase;
39 my $today = $timebase->today ($timezone);
40 my $win = $graph->window;
41 my ($win_width, $win_height) = $win->get_size;
42  
43 # next column after today's, and 1 pixel gap
44 my $x = 1 + $graph->scale_x ($today + 1);
45 ### today t: $today
46 ### iso: $timebase->to_iso($today)
47 ### $x
48  
49 if ($x < 0 || $x >= $win_width
50 || $region->rect_in (Gtk2::Gdk::Rectangle->new ($x,0, 1,$win_height))
51 eq 'out') {
52 return;
53 }
54  
55 my $dash_gc = App::Chart::Gtk2::GUI::gc_for_colour_dashed ($graph, TODAY_COLOUR);
56 $win->draw_line ($dash_gc, $x,0, $x,$win_height-1);
57 }
58  
59 sub hrange {
60 my ($class, $graph, $series_list) = @_;
61 my $series = $series_list->[0] || return;
62 my $symbol = $series->symbol || return;
63  
64 my $timezone = App::Chart::TZ->for_symbol ($symbol);
65 my $timebase = $series->timebase;
66  
67 my $upper = max (map {$_->hi} @$series_list);
68 my $today = $timebase->today ($timezone);
69 if ($today - $upper >= 14) {
70 return;
71 }
72 return ($today, $today);
73 }
74  
75 1;
76 __END__