GeniusTrader/Graphics/Object/VotingLine.pm untested

filter: Statementstmt 0.0% 0 / 75 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 103 CC 9 SCAR 35.1
CC
9
Cov
0%
display
72.0
init
6.0
BEGIN
2.0
CRAP 33.6
1 package Finance::GeniusTrader::Graphics::Object::VotingLine;
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::Prices;
12 use Finance::GeniusTrader::Graphics::Object;
13 use Finance::GeniusTrader::Graphics::Driver;
14 use Finance::GeniusTrader::Graphics::Tools qw(:color);
15 use Finance::GeniusTrader::Tools qw(:math);
16 use Finance::GeniusTrader::Conf;
17  
18 Finance::GeniusTrader::Conf::default("Graphic::VotingLine::BuyColor", "green");
19 Finance::GeniusTrader::Conf::default("Graphic::VotingLine::SellColor", "red");
20 Finance::GeniusTrader::Conf::default("Graphic::VotingLine::Height", 4);
21 Finance::GeniusTrader::Conf::default("Graphic::VotingLine::Width", 4);
22  
23 =head1 Finance::GeniusTrader::Graphics::Object::VotingLine
24  
25 This graphical object display buy and sell arrows.
26  
27 The Voting Line contains the results of a System Manager, which is an entity
28 interacting between a Portfolio Manager, a Trading System, an Order Factory,
29 Trade Filters and Close Strategies.
30  
31 =cut
32  
33 sub init {
34 my ($self, $y) = @_;
35
36 # Default values ...
37 $self->{'buy_color'} = get_color(
38 Finance::GeniusTrader::Conf::get("Graphic::VotingLine::BuyColor")
39 );
40 $self->{'sell_color'} = get_color(
41 Finance::GeniusTrader::Conf::get("Graphic::VotingLine::SellColor")
42 );
43 $self->{'height'} = Finance::GeniusTrader::Conf::get("Graphic::VotingLine::Height");
44 $self->{'width'} = Finance::GeniusTrader::Conf::get("Graphic::VotingLine::Width");
45 $self->{'y'} = 0;
46 $self->{'y'} = $y if (defined($y));
47 }
48  
49 sub display {
50 my ($self, $driver, $picture) = @_;
51 my $scale = $self->get_scale();
52 my $zone = $self->{'zone'};
53 my ($start, $end) = $self->{'source'}->get_selected_range();
54 my $space = $scale->convert_to_x_coordinate($start + 1) -
55 $scale->convert_to_x_coordinate($start);
56 my $width = max($space - 2, $self->{'width'});
57 my $y = $self->{'y'};
58 my ($position, $last_position) = (0, 0);
59
60 for(my $i = $start; $i <= $end; $i++)
61 {
62 my $x = $scale->convert_to_x_coordinate($i);
63 my $value = $self->{'source'}->get($i);
64
65 # Draw an Up and Green Arrow if value = 1
66 if ($value == 1) {
67 my @points = (
68 [$zone->absolute_coordinate($x + int($width/2),
69 $y + $self->{'height'})],
70 [$zone->absolute_coordinate($x, $y)],
71 [$zone->absolute_coordinate($x + $width, $y)]
72 );
73 $driver->filled_polygon($picture, $self->{'buy_color'}, @points);
74 $position = 1;
75 }
76
77 # Draw a Down and Red Arrow if value = -1
78 if ($value == -1) {
79 my @points = (
80 [$zone->absolute_coordinate($x + int($width / 2), $y)],
81 [$zone->absolute_coordinate($x, $y + $self->{'height'})],
82 [$zone->absolute_coordinate($x + $width,
83 $y + $self->{'height'})]
84 );
85 $driver->filled_polygon($picture, $self->{'sell_color'}, @points);
86 $position = -1;
87 }
88
89 next if (! $position);
90
91 # The line is made of two parts, the part before, and the part
92 # after, each can be drawed on the top or on the bottom
93 my ($left_part, $right_part, $left_top, $right_top) = (0, 0);
94
95 $left_top = ($last_position == 1); # Drawed on top if system was buying
96 $right_top = ($position == 1); # Drawed on top if system is buying
97  
98 $left_part = ($position == $last_position); # If position changed only
99 $right_part = 1; # Always
100
101 $driver->line($picture,
102 $zone->absolute_coordinate($x + int($width / 2) - 1,
103 $y + $self->{'height'} * $left_top),
104 $zone->absolute_coordinate($x, $y + $self->{'height'} * $left_top),
105 $left_top ? $self->{'buy_color'} : $self->{'sell_color'})
106 if ($left_part);
107  
108 $driver->line($picture,
109 $zone->absolute_coordinate($x + int($width / 2),
110 $y + $self->{'height'} * $right_top),
111 $zone->absolute_coordinate($x + $space - 1,
112 $y + $self->{'height'} * $right_top),
113 $right_top ? $self->{'buy_color'} : $self->{'sell_color'})
114 if ($right_part);
115
116 $last_position = $position;
117 }
118 }
119  
120 1;