|
1 # |
|
2 # This Source Code Form is subject to the terms of the Mozilla Public |
|
3 # License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
5 package URLTimingGraph; |
|
6 use strict; |
|
7 use GD; |
|
8 use GD::Graph::linespoints; |
|
9 use GD::Graph::points; |
|
10 use GD::Graph::lines; |
|
11 use GD::Graph::mixed; |
|
12 use GD::Graph::colour; |
|
13 use GD::Graph::Data; |
|
14 |
|
15 sub new { |
|
16 my $proto = shift; |
|
17 my $class = ref($proto) || $proto; |
|
18 my $self = {}; |
|
19 bless ($self, $class); |
|
20 $self->{data} = shift || die "No data."; |
|
21 my $args = shift || {}; |
|
22 $self->{cgimode} = $args->{cgimode} || 0; |
|
23 $self->{title} = $args->{title} || ""; |
|
24 $self->{types} = $args->{types} || ['lines', undef, undef, undef, undef, undef, undef]; |
|
25 $self->{dclrs} = $args->{dclrs} || [qw(lred)]; |
|
26 $self->{legend} = $args->{legend} || [qw(undef)]; |
|
27 $self->{y_max_value} = $args->{y_max_value} || 10000; |
|
28 $self->{width} = $args->{width} || 800; |
|
29 $self->{height} = $args->{height} || 720; |
|
30 return $self; |
|
31 } |
|
32 |
|
33 sub _set_standard_options { |
|
34 my $self = shift; |
|
35 $self->{graph}->set( |
|
36 x_label => '', |
|
37 y_label => 'Page Load Time (msec)', |
|
38 default_type => 'points', |
|
39 x_labels_vertical => 1, |
|
40 y_long_ticks => 1, |
|
41 x_tick_length => 8, |
|
42 x_long_ticks => 0, |
|
43 line_width => 2, |
|
44 marker_size => 3, |
|
45 markers => [8], |
|
46 show_values => 0, |
|
47 transparent => 0, |
|
48 interlaced => 1, |
|
49 skip_undef => 1, |
|
50 ) |
|
51 || warn $self->{graph}->error; |
|
52 $self->{graph}->set_title_font(GD::Font->Giant); |
|
53 $self->{graph}->set_x_label_font(GD::Font->Large); |
|
54 $self->{graph}->set_y_label_font(GD::Font->Large); |
|
55 $self->{graph}->set_x_axis_font(GD::Font->Large); |
|
56 $self->{graph}->set_y_axis_font(GD::Font->Large); |
|
57 $self->{graph}->set_legend_font(GD::Font->Giant); |
|
58 } |
|
59 |
|
60 sub plot { |
|
61 my $self = shift; |
|
62 $self->{graph} = new GD::Graph::mixed($self->{width}, |
|
63 $self->{height}); |
|
64 $self->_set_standard_options(); |
|
65 |
|
66 $self->{graph}->set(title => $self->{title}, |
|
67 types => $self->{types}, |
|
68 y_max_value => $self->{y_max_value}, |
|
69 dclrs => $self->{dclrs}, |
|
70 ) |
|
71 || warn $self->{graph}->error; |
|
72 |
|
73 $self->{graph}->set_legend( @{$self->{legend}} ); |
|
74 |
|
75 # draw the graph image |
|
76 $self->{graph}->plot($self->{data}) || |
|
77 die $self->{graph}->error; |
|
78 |
|
79 # send it back to stdout (or browser) |
|
80 print "Content-type: image/png\n\n" if $self->{cgimode}; |
|
81 binmode STDOUT; |
|
82 print $self->{graph}->gd->png(); |
|
83 } |
|
84 |
|
85 |
|
86 1; #return true |