GeniusTrader/Graphics/Object.pm untested

filter: Statementstmt 0.0% 0 / 79 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 27 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 123 CC 2 SCAR 8.3
CC
2
Cov
0%
get_scale
6.0
new
2.0
set_z_level
2.0
CRAP 2.3
1 package Finance::GeniusTrader::Graphics::Object;
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 Finance::GeniusTrader::Graphics::Graphic;
9 use Finance::GeniusTrader::Graphics::Tools qw(:color);
10 use Finance::GeniusTrader::Conf;
11  
12 require Finance::GeniusTrader::Graphics::Object::Candle;
13 require Finance::GeniusTrader::Graphics::Object::CandleVolume;
14 require Finance::GeniusTrader::Graphics::Object::CandleVolumePlace;
15 require Finance::GeniusTrader::Graphics::Object::BarChart;
16 require Finance::GeniusTrader::Graphics::Object::Histogram;
17 require Finance::GeniusTrader::Graphics::Object::Marks;
18 #require Finance::GeniusTrader::Graphics::Object::PointAndFigure;
19 require Finance::GeniusTrader::Graphics::Object::Curve;
20 require Finance::GeniusTrader::Graphics::Object::Mountain;
21 require Finance::GeniusTrader::Graphics::Object::MountainBand;
22 require Finance::GeniusTrader::Graphics::Object::Text;
23 require Finance::GeniusTrader::Graphics::Object::Polygon;
24 require Finance::GeniusTrader::Graphics::Object::BuySellArrows;
25 require Finance::GeniusTrader::Graphics::Object::VotingLine;
26  
27 =head1 Finance::GeniusTrader::Graphics::Object
28  
29 A graphical object is a part of a graphic. It can display itself
30 on a picture.
31  
32 =head1 FUNCTIONS TO IMPLEMENT
33  
34 Each object will have to implement those functions.
35  
36 =head2 $o->display($driver, $picture)
37  
38 Display the object on the picture using the given driver. It may
39 use $o->{'zone'} and $o->{'source'} to get the data and display
40 itself in the good zone.
41  
42 =head2 $o->init(...)
43  
44 This function is called with the trailing arguments given to
45 the constructor.
46  
47 =head1 GENERIC FUNCTIONS
48  
49 =head2 Finance::GeniusTrader::Graphics::Object::<Something>->new($datasource, $zone, ...)
50  
51 The constructor.
52  
53 =cut
54 sub new {
55 my $type = shift;
56 my $class = ref($type) || $type;
57 my $source = shift;
58 my $zone = shift;
59  
60 my $self = { "source" => $source, "zone" => $zone,
61 "bg_color" =>
62 get_color(Finance::GeniusTrader::Conf::get("Graphic::BackgroundColor")),
63 "fg_color" =>
64 get_color(Finance::GeniusTrader::Conf::get("Graphic::ForegroundColor"))
65 };
66 bless $self, $class;
67  
68 $self->init(@_);
69
70 return $self;
71 }
72  
73 =head2 $o->get_z_level()
74  
75 =head2 $o->set_z_level($z)
76  
77 Those two functions are used to manage the order in which the orders
78 are displayed. An object with a low Z level is drawn first.
79  
80 =cut
81 sub set_z_level {
82 my ($self, $z) = @_;
83 $self->{'z'} = $z;
84 }
85  
86 sub get_z_level {
87 my ($self) = @_;
88 return $self->{'z'};
89 }
90  
91 =head2 $o->set_source($source)
92  
93 =head2 $o->get_source()
94  
95 Set/get the datasource associated to this object.
96  
97 =cut
98 sub set_source {
99 my ($self, $source) = @_;
100 $self->{'source'} = $source;
101 }
102 sub get_source { $_[0]->{'source'} }
103  
104 =head2 $o->set_zone($zone)
105  
106 Set the zone in which the object will be displayed.
107  
108 =cut
109 sub set_zone {
110 my ($self, $zone) = @_;
111 $self->{'zone'} = $zone;
112 }
113  
114 =head2 $o->set_special_scale($scale)
115  
116 Use a special scale to draw this object.
117  
118 =cut
119 sub set_special_scale {
120 my ($self, $scale) = @_;
121 $self->{'special_scale'} = $scale;
122 }
123  
124 =head2 $o->get_scale()
125  
126 Return the associated scale. If it exists, it uses the special scale,
127 otherwise returns the default scale associated to the zone.
128  
129 =cut
130 sub get_scale {
131 my ($self) = @_;
132 if (defined($self->{'special_scale'})) {
133 return $self->{'special_scale'};
134 }
135 return $self->{'zone'}->get_default_scale();
136 }
137  
138 =head2 $o->set_background_color($color)
139  
140 Use this color as background color.
141  
142 =cut
143 sub set_background_color {
144 my ($self, $color) = @_;
145 $self->{'bg_color'} = get_color($color);
146 }
147  
148 =head2 $o->set_foreground_color($color)
149  
150 Use this color as foreground color.
151  
152 =cut
153 sub set_foreground_color {
154 my ($self, $color) = @_;
155 $self->{'fg_color'} = get_color($color);
156 }
157  
158 1;