App/Chart/Gtk2/Heading.pm

filter: Statementstmt 81.8% 9 / 11 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 86.6% 13 / 15 CC 1 SCAR 0.7
CC
1
Cov
82%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« App/Chart/Gtk2/HScale.pm ↑ Summary App/Chart/Gtk2/IndicatorModel.pm »
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 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 0 ▶use Gtk2;
Subroutine BEGIN: called CC=1 SCAR=2.6
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__
« App/Chart/Gtk2/HScale.pm ↑ Summary App/Chart/Gtk2/IndicatorModel.pm »