File Coverage

blib/lib/App/Chart/Gtk2/Heading.pm
Criterion Covered Total %
statement 9 11 81.8
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 13 15 86.6


line stmt bran cond sub pod time code
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::Heading;
18 1     1   497 use 5.010;
  1         3  
19 1     1   4 use strict;
  1         2  
  1         18  
20 1     1   4 use warnings;
  1         2  
  1         24  
21 1     1   141 use Gtk2;
  0            
  0            
22             use Locale::TextDomain ('App-Chart');
23              
24             use App::Chart;
25             use App::Chart::Gtk2::GUI;
26              
27             # uncomment this to run the ### lines
28             #use Devel::Comments;
29              
30              
31             use Glib::Object::Subclass
32             'Gtk2::EventBox',
33             properties => [Glib::ParamSpec->scalar
34             ('series-list',
35             'series-list',
36             'Arrayref of App::Chart::Gtk2::Symlist objects',
37             Glib::G_PARAM_READWRITE)
38             ];
39             App::Chart::Gtk2::GUI::chart_style_class (__PACKAGE__);
40             Gtk2::Rc->parse_string (<<'HERE');
41             widget_class "*.<App__Chart__Gtk2__Heading>.*.GtkLabel" style:application "Chart_style"
42             HERE
43              
44             sub INIT_INSTANCE {
45             my ($self) = @_;
46             my $hbox = Gtk2::HBox->new (0,0);
47             $self->add ($hbox);
48              
49             my $left = $self->{'left'} = Gtk2::Label->new ('left');
50             $left->set (xalign => 0);
51             $hbox->pack_start ($left, 0,0,0);
52              
53             my $right = $self->{'right'} = Gtk2::Label->new ('right');
54             $right->set (xalign => 1);
55             $hbox->pack_end ($right, 0,0,0);
56              
57             $hbox->show_all;
58             }
59              
60             sub SET_PROPERTY {
61             my ($self, $pspec, $newval) = @_;
62             my $pname = $pspec->get_name;
63             $self->{$pname} = $newval; # per default GET_PROPERTY
64             ### Heading SET_PROPERTY(): "$self $pname $newval"
65              
66             if ($pname eq 'series_list') {
67             my $series_list = $newval;
68             ### series_list length: scalar(@$series_list)
69             my $series = $series_list->[0];
70             my $left = '';
71             my $right = '';
72             if ($series) {
73             ### series for text: "$series"
74             $left = ($series_list->[1] || $series)->name;
75             # FIXME: Show "- Log" for logarithmic?
76              
77             if ($series->can('symbol_name')) {
78             $right = $series->symbol_name // '';
79             }
80              
81             # FIXME: do something in the Timebase classes for an strftime format
82             # string, maybe make it configurable
83             my $timebase = $series->timebase;
84             my $to_date;
85             # FIXME: use download-done date here
86             my $hi = $series->hi;
87             if ($timebase->isa('App::Chart::Timebase::Weeks')) {
88             # ENHANCE-ME: the date shown is the start of the week, is that ok?
89             $to_date = $timebase->strftime ($App::Chart::option{'d_fmt'},
90             $hi);
91             $to_date = __x('to week {date}', date => $to_date);
92             } elsif ($timebase->isa('App::Chart::Timebase::Months')
93             || $timebase->isa('App::Chart::Timebase::Quarters')) {
94             $to_date = $timebase->strftime (__('to %b %Y'), $hi);
95             } elsif ($timebase->isa('App::Chart::Timebase::Years')) {
96             $to_date = $timebase->strftime (__('to %Y'), $hi);
97             } elsif ($timebase->isa('App::Chart::Timebase::Decades')) {
98             $to_date = $timebase->strftime (__('to decade %Y'), $hi);
99             } else {
100             $to_date = $timebase->strftime ($App::Chart::option{'wd_fmt'},
101             $hi);
102             $to_date = __x('to {date}', date => $to_date);
103             }
104             $right = join (' ', $right//'', $to_date . ' ');
105             }
106             ### $left
107             ### $right
108             $self->{'left'}->set_text ($left);
109             $self->{'right'}->set_text ($right);
110             }
111             }
112              
113             1;
114             __END__
115              
116             =for stopwords superclass arrayref undef
117              
118             =head1 NAME
119              
120             App::Chart::Gtk2::Heading -- view heading display widget
121              
122             =head1 SYNOPSIS
123              
124             use App::Chart::Gtk2::Heading;
125             my $hscale = App::Chart::Gtk2::Heading->new();
126              
127             =head1 WIDGET HIERARCHY
128              
129             C<App::Chart::Gtk2::Heading> is a subclass of C<Gtk2::EventBox>.
130              
131             Gtk2::Widget
132             Gtk2::Container
133             Gtk2::Bin
134             Gtk2::EventBox
135             App::Chart::Gtk2::Heading
136              
137             The superclass is only C<Gtk2::EventBox> to get a container with its own
138             window, and that might change.
139              
140             =head1 DESCRIPTION
141              
142             A C<App::Chart::Gtk2::Heading> widget displays ...
143              
144             =head1 PROPERTIES
145              
146             =over 4
147              
148             =item C<series-list> (arrayref of C<App::Chart::Series> objects, default undef)
149              
150             =back
151              
152             =head1 SEE ALSO
153              
154             L<App::Chart::Gtk2::View>, L<App::Chart::Series>
155              
156             =cut