GeniusTrader/Graphics/Object/Curve.pm untested

filter: Statementstmt 0.0% 0 / 66 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 95 CC 8 SCAR 35.0
CC
8
Cov
0%
display
72.0
init
2.0
set_antialiased
2.0
CRAP 33.1
1 package Finance::GeniusTrader::Graphics::Object::Curve;
2  
3 # Copyright 2000-2002 Raphaƫl Hertzog, Fabien Fulhaber
4 # This file is distributed under the terms of the General Public License
5 # version 2 or (at your option) any later version.
6  
7 use strict;
8 use vars qw(@ISA);
9 @ISA = qw(Finance::GeniusTrader::Graphics::Object);
10  
11 use Finance::GeniusTrader::Graphics::Graphic;
12 use Finance::GeniusTrader::Graphics::Object;
13 use Finance::GeniusTrader::Graphics::Driver;
14 use Finance::GeniusTrader::Graphics::Tools qw(:color);
15 use Finance::GeniusTrader::Conf;
16  
17 =head1 Finance::GeniusTrader::Graphics::Object::Curve
18  
19 This graphical object display a curve.
20  
21 =cut
22  
23 sub init {
24 my ($self) = @_;
25
26 # Default values ... maybe we should use Finance::GeniusTrader::Conf ?
27 $self->{'fg_color'} = get_color(Finance::GeniusTrader::Conf::get("Graphic::ForegroundColor"));
28 $self->{'aa'} = 1;
29 $self->{'linewidth'} = 1;
30 }
31  
32 sub set_antialiased {
33 my ($self, $aa) = @_;
34 $self->{'aa'} = $aa;
35 }
36  
37 sub set_linewidth {
38 my ($self, $lw) = @_;
39 $self->{'linewidth'} = $lw;
40 }
41  
42 sub display {
43 my ($self, $driver, $picture) = @_;
44 my $scale = $self->get_scale();
45 my $zone = $self->{'zone'};
46 my ($start, $end) = $self->{'source'}->get_selected_range();
47 my $space = $scale->convert_to_x_coordinate($start + 1) -
48 $scale->convert_to_x_coordinate($start);
49  
50 # only $y_min and $y_max are significant
51 my ($x_min, $y_min) = $scale->get_value_from_coordinate($start, 0);
52 my ($x_max, $y_max) = $scale->get_value_from_coordinate($end, $zone->height-1);
53  
54 # these are coordinate values of $y_min and $y_max
55 my $yc_min = $scale->convert_to_y_coordinate($y_min);
56 my $yc_max = $scale->convert_to_y_coordinate($y_max);
57  
58 my ($first_pt, $second_pt);
59 for(my $i = $start; $i <= $end; $i++)
60 {
61 # Find two available points
62 if ($self->{'source'}->is_available($i)) {
63 $second_pt = $i;
64 } else {
65 next;
66 }
67 if (! defined($first_pt)) {
68 $first_pt = $second_pt;
69 next;
70 }
71
72 # Now we have two points, let's display if possible
73 my $data1 = $self->{'source'}->get($first_pt);
74 my $data2 = $self->{'source'}->get($second_pt);
75 my ($x1, $y1) = $scale->convert_to_coordinate($first_pt, $data1);
76 my ($x2, $y2) = $scale->convert_to_coordinate($second_pt, $data2);
77 $x1 += int($space / 2);
78 $x2 += int($space / 2);
79  
80 # rather than skip plotting the curve that exceeds a zone boundary
81 # this change will plot to and along the zone boundary
82  
83 # clip at top of zone
84 $y1 = $yc_max if ($y1 > $yc_max);
85 $y2 = $yc_max if ($y2 > $yc_max);
86 # clip at bottom of zone
87 $y1 = $yc_min if ($y1 < $yc_min);
88 $y2 = $yc_min if ($y2 < $yc_min);
89  
90 my $oldlw = $driver->line_width($picture, $self->{'linewidth'});
91 if ($self->{'aa'}) {
92 $driver->antialiased_line($picture,
93 $zone->absolute_coordinate($x1, $y1),
94 $zone->absolute_coordinate($x2, $y2),
95 $self->{'fg_color'});
96 } else {
97 $driver->line($picture,
98 $zone->absolute_coordinate($x1, $y1),
99 $zone->absolute_coordinate($x2, $y2),
100 $self->{'fg_color'});
101 }
102 $driver->line_width($picture, $oldlw);
103  
104 # Shift the points
105 $first_pt = $second_pt;
106 }
107 }
108  
109 1;