| 1 | # Copyright 2007, 2008, 2009, 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::Heading; | ||
| 18 | use 5.010; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Gtk2; | ||
| 22 | |||
| 23 | use base 'App::Chart::Gtk2::Graph::Plugin'; | ||
| 24 | use App::Chart; | ||
| 25 | # use Locale::TextDomain ('App-Chart'); | ||
| 26 | |||
| 27 | # uncomment this to run the ### lines | ||
| 28 | #use Devel::Comments; | ||
| 29 | |||
| 30 | |||
| 31 | use constant { | ||
| 32 | X_MARGIN_SPACES => 1, | ||
| 33 | Y_MARGIN_LINES => 0.3, | ||
| 34 | }; | ||
| 35 | |||
| 36 | sub draw { | ||
| 37 | my ($class, $graph, $region) = @_; | ||
| 38 | ### Graph Heading draw() ... | ||
| 39 | |||
| 40 | $graph->{'heading_in_graph'} or return; | ||
| 41 | |||
| 42 | my $series_list = $graph->{'series_list'}; | ||
| 43 | my $series = $series_list->[0] || return; | ||
| 44 | ### series: "$series" | ||
| 45 | my $str = $series->name // return; | ||
| 46 | ### $str | ||
| 47 | |||
| 48 | my $win = $graph->window; | ||
| 49 | my $style = $graph->style; | ||
| 50 | my $cliprect = $region->get_clipbox; | ||
| 51 | |||
| 52 | my $layout = ($graph->{'layout'} ||= $graph->create_pango_layout('')); | ||
| 53 | my $line_height = Gtk2::Ex::Units::line_height($layout); | ||
| 54 | my $y = $line_height * Y_MARGIN_LINES; | ||
| 55 | $layout->set_text ((' ' x X_MARGIN_SPACES).$str); | ||
| 56 | |||
| 57 | $style->paint_layout ($win, # window | ||
| 58 | $graph->state, | ||
| 59 | 1, # use_text, for the text gc instead of the fg one | ||
| 60 | $cliprect, | ||
| 61 | $graph, # widget | ||
| 62 | __PACKAGE__, # style detail string | ||
| 63 | 0, $y, # x,y | ||
| 64 | $layout); | ||
| 65 | } | ||
| 66 | |||
| 67 | 1; | ||
| 68 | __END__ |