GeniusTrader/Graphics/Object/Mountain.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 84 CC 7 SCAR 33.7
CC
7
Cov
0%
display
56.0
init
2.0
BEGIN
2.0
CRAP 29.0
1 package Finance::GeniusTrader::Graphics::Object::Mountain;
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 # ras version -- includes gmargo@pacbell.net patch 12dec06
8 # $Id$
9  
10 use strict;
11 use vars qw(@ISA);
12 @ISA = qw(Finance::GeniusTrader::Graphics::Object);
13  
14 use Finance::GeniusTrader::Graphics::Object;
15 use Finance::GeniusTrader::Graphics::Driver;
16 use Finance::GeniusTrader::Graphics::Tools qw(:color);
17 use Finance::GeniusTrader::Conf;
18  
19 Finance::GeniusTrader::Conf::default("Graphic::Mountain::Color", "black");
20  
21 =head1 Finance::GeniusTrader::Graphics::Object::Mountain
22  
23 =cut
24  
25 sub init {
26 my ($self) = @_;
27
28 # Default values ...
29 $self->{'fg_color'} = get_color(Finance::GeniusTrader::Conf::get("Graphic::Mountain::Color"));
30 }
31  
32 sub display {
33 my ($self, $driver, $picture) = @_;
34 my $scale = $self->get_scale();
35 my $zone = $self->{'zone'};
36 my ($start, $end) = $self->{'source'}->get_selected_range();
37 my $space = $scale->convert_to_x_coordinate($start + 1) -
38 $scale->convert_to_x_coordinate($start);
39 my $y_zero = $scale->convert_to_y_coordinate(0);
40  
41 # only $y_min and $y_max are significant
42 my ($x_min, $y_min) = $scale->get_value_from_coordinate($start, 0);
43 my ($x_max, $y_max) = $scale->get_value_from_coordinate($end, $zone->height-1);
44  
45 # these are coordinate values of $y_min and $y_max
46 my $yc_min = $scale->convert_to_y_coordinate($y_min);
47 my $yc_max = $scale->convert_to_y_coordinate($y_max);
48  
49 my ($first_pt, $second_pt);
50 for(my $i = $start; $i <= $end; $i++)
51 {
52 # Find two available points
53 if ($self->{'source'}->is_available($i)) {
54 $second_pt = $i;
55 } else {
56 next;
57 }
58 if (! defined($first_pt)) {
59 $first_pt = $second_pt;
60 next;
61 }
62
63 # Draw
64 my $data1 = $self->{'source'}->get($first_pt);
65 my $data2 = $self->{'source'}->get($second_pt);
66 my ($x1, $y1) = $scale->convert_to_coordinate($first_pt, $data1);
67 my ($x2, $y2) = $scale->convert_to_coordinate($second_pt, $data2);
68 $x1 += int($space / 2);
69 $x2 += int(($space-0.5) / 2);
70  
71 # clip at top of zone
72 $y1 = $yc_max if ($y1 > $yc_max);
73 $y2 = $yc_max if ($y2 > $yc_max);
74 # clip at bottom of zone
75 $y1 = $yc_min if ($y1 < $yc_min);
76 $y2 = $yc_min if ($y2 < $yc_min);
77  
78 my @points = (
79 [$zone->absolute_coordinate($x1, $y1)],
80 [$zone->absolute_coordinate($x2, $y2)],
81 [$zone->absolute_coordinate($x2, $y_zero)],
82 [$zone->absolute_coordinate($x1, $y_zero)]
83 );
84
85 $driver->filled_polygon($picture, $self->{'fg_color'}, @points);
86  
87 # Shift the points
88 $first_pt = $second_pt;
89 }
90 }
91  
92 1;