ohlc.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« candlesticks.pm ↑ Summary
1 #==========================================================================
2 # Copyright (c) 2008 Paul Miller
3 #==========================================================================
4  
5 package GD::Graph::ohlc;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶use GD::Graph::mixed; # NOTE: we pull this in so we can modify part of it.
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use GD::Graph::axestype;
12 use GD::Graph::utils qw(:all);
13 use GD::Graph::colour qw(:colours);
14  
15 use constant PI => 4 * atan2(1,1);
16  
17 our $VERSION = "0.9703";
18 our @ISA = qw(GD::Graph::axestype);
19  
20 push @GD::Graph::mixed::ISA, __PACKAGE__;
21  
22 # draw_data_set {{{
23 sub draw_data_set {
24 my $self = shift;
25 my $ds = shift;
26  
27 my @values = $self->{_data}->y_values($ds) or
28 return $self->_set_error("Impossible illegal data set: $ds", $self->{_data}->error);
29  
30 # Pick a colour
31 my $dsci = $self->set_clr($self->pick_data_clr($ds));
32  
33 my $GX;
34 my ($ox,$oy, $cx,$cy, $lx,$ly, $hx,$hy); # NOTE: all the x's are the same...
35 for (my $i = 0; $i < @values; $i++) {
36 my $value = $values[$i];
37 next unless ref($value) eq "ARRAY" and @$value==4;
38 my ($open, $high, $low, $close) = @$value;
39  
40 if (defined($self->{x_min_value}) && defined($self->{x_max_value})) {
41 $GX = $self->{_data}->get_x($i);
42  
43 ($ox, $oy) = $self->val_to_pixel($GX, $value->[0], $ds);
44 ($hx, $hy) = $self->val_to_pixel($GX, $value->[1], $ds);
45 ($lx, $ly) = $self->val_to_pixel($GX, $value->[2], $ds);
46 ($cx, $cy) = $self->val_to_pixel($GX, $value->[3], $ds);
47  
48 } else {
49 ($ox, $oy) = $self->val_to_pixel($i+1, $value->[0], $ds);
50 ($hx, $hy) = $self->val_to_pixel($i+1, $value->[1], $ds);
51 ($lx, $ly) = $self->val_to_pixel($i+1, $value->[2], $ds);
52 ($cx, $cy) = $self->val_to_pixel($i+1, $value->[3], $ds);
53 }
54  
55 $self->ohlc_marker($ox,$oy, $cx,$cy, $lx,$ly, $hx,$hy, $dsci );
56 $self->{_hotspots}[$ds][$i] = ['rect', $self->ohlc_marker_coordinates($ox,$oy, $cx,$cy, $lx,$ly, $hx,$hy)];
57 }
58  
59 return $ds;
60 }
61 # }}}
62 # ohlc_marker_coordinates {{{
63 sub ohlc_marker_coordinates {
64 my $self = shift;
65 my ($ox,$oy, $cx,$cy, $lx,$ly, $hx,$hy) = @_;
66  
67 my ($l,$t,$r,$b) = ( $ox-2, $hy, $ox+2, $ly );
68 return ($t <= $b) ? ( $l, $t, $r, $b ) : ( $l, $b, $r, $t );
69 }
70 # }}}
71 # ohlc_marker {{{
72 sub ohlc_marker {
73 my $self = shift;
74 my ($ox,$oy, $cx,$cy, $lx,$ly, $hx,$hy, $mclr) = @_;
75 return unless defined $mclr;
76  
77 $self->{graph}->line( ($ox,$oy) => ($ox-2,$oy), $mclr );
78 $self->{graph}->line( ($cx,$cy) => ($cx+2,$cy), $mclr );
79 $self->{graph}->line( ($lx,$ly) => ($hx,$hy), $mclr );
80  
81 return;
82 }
83 # }}}
84  
85 1;
« candlesticks.pm ↑ Summary