line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## @file |
2
|
|
|
|
|
|
|
# Implementation of Chart::Points |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# written by |
5
|
|
|
|
|
|
|
# @author david bonner (dbonner@cs.bu.edu) |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# maintained by the |
8
|
|
|
|
|
|
|
# @author Chart Group at Geodetic Fundamental Station Wettzell (Chart@fs.wettzell.de) |
9
|
|
|
|
|
|
|
# @date 2012-10-03 |
10
|
|
|
|
|
|
|
# @version 2.4.6 |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
## @class Chart::Points |
14
|
|
|
|
|
|
|
# Points class derived from class Base. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# This class provides all functions which are specific to |
17
|
|
|
|
|
|
|
# points |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
package Chart::Points; |
20
|
|
|
|
|
|
|
|
21
|
7
|
|
|
7
|
|
21332
|
use Chart::Base '2.4.6'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use GD; |
23
|
|
|
|
|
|
|
use Carp; |
24
|
|
|
|
|
|
|
use strict; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
@Chart::Points::ISA = qw(Chart::Base); |
27
|
|
|
|
|
|
|
$Chart::Points::VERSION = '2.4.6'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
#>>>>>>>>>>>>>>>>>>>>>>>>>># |
30
|
|
|
|
|
|
|
# public methods go here # |
31
|
|
|
|
|
|
|
#<<<<<<<<<<<<<<<<<<<<<<<<<<# |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#>>>>>>>>>>>>>>>>>>>>>>>>>>># |
34
|
|
|
|
|
|
|
# private methods go here # |
35
|
|
|
|
|
|
|
#<<<<<<<<<<<<<<<<<<<<<<<<<<<# |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
## @fn private _draw_data |
38
|
|
|
|
|
|
|
# finally get around to plotting the data |
39
|
|
|
|
|
|
|
sub _draw_data |
40
|
|
|
|
|
|
|
{ |
41
|
|
|
|
|
|
|
my $self = shift; |
42
|
|
|
|
|
|
|
my $data = $self->{'dataref'}; |
43
|
|
|
|
|
|
|
my $misccolor = $self->_color_role_to_index('misc'); |
44
|
|
|
|
|
|
|
my ( $x1, $x2, $x3, $y1, $y2, $y3, $mod ); |
45
|
|
|
|
|
|
|
my ( $width, $height, $delta, $map, $delta_num, $zero_offset ); |
46
|
|
|
|
|
|
|
my ( $i, $j, $color, $brush ); |
47
|
|
|
|
|
|
|
my $diff; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# init the imagemap data field if they want it |
50
|
|
|
|
|
|
|
if ( $self->true( $self->{'imagemap'} ) ) |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
$self->{'imagemap_data'} = []; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# find the delta value between data points, as well |
56
|
|
|
|
|
|
|
# as the mapping constant |
57
|
|
|
|
|
|
|
$width = $self->{'curr_x_max'} - $self->{'curr_x_min'}; |
58
|
|
|
|
|
|
|
$height = $self->{'curr_y_max'} - $self->{'curr_y_min'}; |
59
|
|
|
|
|
|
|
$delta = $width / ( $self->{'num_datapoints'} > 0 ? $self->{'num_datapoints'} : 1 ); |
60
|
|
|
|
|
|
|
$diff = ( $self->{'max_val'} - $self->{'min_val'} ); |
61
|
|
|
|
|
|
|
$diff = 1 if $diff == 0; |
62
|
|
|
|
|
|
|
$map = $height / $diff; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
#for a xy-plot, use this delta and maybe an offset for the zero-axes |
65
|
|
|
|
|
|
|
if ( $self->true( $self->{'xy_plot'} ) ) |
66
|
|
|
|
|
|
|
{ |
67
|
|
|
|
|
|
|
$diff = ( $self->{'x_max_val'} - $self->{'x_min_val'} ); |
68
|
|
|
|
|
|
|
$diff = 1 if $diff == 0; |
69
|
|
|
|
|
|
|
$delta_num = $width / $diff; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ( $self->{'x_min_val'} <= 0 && $self->{'x_max_val'} >= 0 ) |
72
|
|
|
|
|
|
|
{ |
73
|
|
|
|
|
|
|
$zero_offset = abs( $self->{'x_min_val'} ) * abs($delta_num); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
elsif ( $self->{'x_min_val'} > 0 || $self->{'x_max_val'} < 0 ) |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
$zero_offset = -$self->{'x_min_val'} * $delta_num; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else |
80
|
|
|
|
|
|
|
{ |
81
|
|
|
|
|
|
|
$zero_offset = 0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# get the base x-y values |
86
|
|
|
|
|
|
|
if ( $self->false( $self->{'xy_plot'} ) ) |
87
|
|
|
|
|
|
|
{ |
88
|
|
|
|
|
|
|
$x1 = $self->{'curr_x_min'} + ( $delta / 2 ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
else |
91
|
|
|
|
|
|
|
{ |
92
|
|
|
|
|
|
|
$x1 = $self->{'curr_x_min'}; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
if ( $self->{'min_val'} >= 0 ) |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
$y1 = $self->{'curr_y_max'}; |
97
|
|
|
|
|
|
|
$mod = $self->{'min_val'}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
elsif ( $self->{'max_val'} <= 0 ) |
100
|
|
|
|
|
|
|
{ |
101
|
|
|
|
|
|
|
$y1 = $self->{'curr_y_min'}; |
102
|
|
|
|
|
|
|
$mod = $self->{'max_val'}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else |
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
$y1 = $self->{'curr_y_min'} + ( $map * $self->{'max_val'} ); |
107
|
|
|
|
|
|
|
$mod = 0; |
108
|
|
|
|
|
|
|
$self->{'gd_obj'}->line( $self->{'curr_x_min'}, $y1, $self->{'curr_x_max'}, $y1, $misccolor ); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# draw the points |
112
|
|
|
|
|
|
|
for $i ( 1 .. $self->{'num_datasets'} ) |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# get the color for this dataset, and set the brush |
116
|
|
|
|
|
|
|
$color = $self->_color_role_to_index( 'dataset' . ( $i - 1 ) ); |
117
|
|
|
|
|
|
|
my $offset = 0; |
118
|
|
|
|
|
|
|
( $brush, $offset ) = $self->_prepare_brush( $color, 'point', 'dataset' . ( $i - 1 ) ); |
119
|
|
|
|
|
|
|
$self->{'gd_obj'}->setBrush($brush); |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# draw every point for this dataset |
122
|
|
|
|
|
|
|
for $j ( 0 .. $self->{'num_datapoints'} ) |
123
|
|
|
|
|
|
|
{ |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# don't try to draw anything if there's no data |
126
|
|
|
|
|
|
|
if ( defined( $data->[$i][$j] ) ) |
127
|
|
|
|
|
|
|
{ |
128
|
|
|
|
|
|
|
if ( $self->true( $self->{'xy_plot'} ) ) |
129
|
|
|
|
|
|
|
{ |
130
|
|
|
|
|
|
|
$x2 = $x1 + $delta_num * $data->[0][$j] + $zero_offset; |
131
|
|
|
|
|
|
|
$x3 = $x2; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
else |
134
|
|
|
|
|
|
|
{ |
135
|
|
|
|
|
|
|
$x2 = $x1 + ( $delta * $j ); |
136
|
|
|
|
|
|
|
$x3 = $x2; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
$y2 = $y1 - ( ( $data->[$i][$j] - $mod ) * $map ); |
139
|
|
|
|
|
|
|
$y3 = $y2; |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# draw the point only if it is within the chart borders |
142
|
|
|
|
|
|
|
if ( $data->[$i][$j] <= $self->{'max_val'} && $data->[$i][$j] >= $self->{'min_val'} ) |
143
|
|
|
|
|
|
|
{ |
144
|
|
|
|
|
|
|
$self->{'gd_obj'}->line( $x2, $y2, $x3, $y3, gdBrushed ); |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# store the imagemap data if they asked for it |
148
|
|
|
|
|
|
|
if ( $self->true( $self->{'imagemap'} ) ) |
149
|
|
|
|
|
|
|
{ |
150
|
|
|
|
|
|
|
$self->{'imagemap_data'}->[$i][$j] = [ $x2, $y2 ]; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# and finaly box it off |
157
|
|
|
|
|
|
|
$self->{'gd_obj'} |
158
|
|
|
|
|
|
|
->rectangle( $self->{'curr_x_min'}, $self->{'curr_y_min'}, $self->{'curr_x_max'}, $self->{'curr_y_max'}, $misccolor ); |
159
|
|
|
|
|
|
|
return; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
## be a good module and return 1 |
164
|
|
|
|
|
|
|
1; |