App/Chart/Gtk2/LineStyle/Points.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 105 CC 6 SCAR 29.5
CC
6
Cov
0%
draw
42.0
widget_x_pixels_to_y_pixels
2.0
BEGIN
2.0
CRAP 19.1
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::LineStyle::Points;
18 use 5.010;
19 use strict;
20 use warnings;
21 use Carp;
22 use Gtk2;
23 use List::Util qw(min max);
24  
25 use App::Chart::Series;
26  
27 sub draw {
28 my ($class, $graph, $series) = @_;
29  
30 my $win = $graph->window;
31 my ($win_width, $win_height) = $win->get_size();
32 my $style = $graph->style;
33 my $gc = $style->fg_gc ($graph->state);
34 my $ret = 0;
35  
36 my $scale_x_step = $graph->scale_x_step;
37 # print "x step $scale_x_step\n";
38 # points 1/2 of step wide, but at least 1 pixel
39 my $x_diameter = max (1, int ($scale_x_step * 0.5));
40 my $y_diameter = max (1, int (widget_x_pixels_to_y_pixels
41 ($graph, $x_diameter)));
42 $x_diameter = 1;
43 $y_diameter= 1;
44  
45 my $y_lo = -$y_diameter;
46 my $y_hi = $win_height;
47 my ($t_lo, $t_hi) = $graph->draw_t_range();
48 my $scale_y = $graph->scale_y_proc;
49 my $scale_x = $graph->scale_x_proc;
50  
51 $series->fill ($t_lo, $t_hi);
52 my $values = $series->values_array;
53  
54 if ($x_diameter > 1 || $y_diameter > 1) {
55 foreach my $t ($t_lo .. $t_hi) {
56 my $value = $values->[$t];
57 if (! defined $value) { next; }
58  
59 my $x = $scale_x->($t);
60 my $y = $scale_y->($value);
61 if ($y <= $y_lo || $y >= $y_hi) { next; }
62 # print "$t $value $x $y\n";
63  
64 $win->draw_arc ($gc, 1, $x, $y, $x_diameter, $y_diameter,
65 0, 360*64); # full 360 degree circle
66 }
67  
68 } else {
69 my @array;
70 foreach my $t ($t_lo .. $t_hi) {
71 my $value = $values->[$t];
72 if (! defined $value) { next; }
73 $ret = 1;
74  
75 my $x = $scale_x->($t);
76 my $y = $scale_y->($value);
77 if ($y <= $y_lo || $y >= $y_hi) { next; }
78  
79 # print "$t $value $x $y\n";
80 push @array, $x, $y;
81 }
82 $win->draw_points ($gc, @array);
83 }
84 return $ret;
85 }
86  
87  
88 # =item C<< widget_x_pixels_to_y_pixels ($widget, $x) >>
89 #
90 # Return a pixel count in the y direction which is the same distance as C<$x>
91 # horizontally. This uses the aspect ratio of the screen of C<$widget>. The
92 # return is a floating point value; you can round it to an integer as desired.
93 #
94 # =cut
95  
96 sub widget_x_pixels_to_y_pixels {
97 my ($widget, $x) = @_;
98 my $screen = $widget->get_screen
99 or croak 'widget_x_pixels_to_y_pixels(): widget not on a screen yet';
100 return $x
101 * ($screen->get_width_mm / $screen->get_width) # x->mm
102 * ($screen->get_height_mm / $screen->get_height); # mm->y
103 }
104  
105 1;
106 __END__