michael@0: # michael@0: # This Source Code Form is subject to the terms of the Mozilla Public michael@0: # License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: # file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: package URLTimingGraph; michael@0: use strict; michael@0: use GD; michael@0: use GD::Graph::linespoints; michael@0: use GD::Graph::points; michael@0: use GD::Graph::lines; michael@0: use GD::Graph::mixed; michael@0: use GD::Graph::colour; michael@0: use GD::Graph::Data; michael@0: michael@0: sub new { michael@0: my $proto = shift; michael@0: my $class = ref($proto) || $proto; michael@0: my $self = {}; michael@0: bless ($self, $class); michael@0: $self->{data} = shift || die "No data."; michael@0: my $args = shift || {}; michael@0: $self->{cgimode} = $args->{cgimode} || 0; michael@0: $self->{title} = $args->{title} || ""; michael@0: $self->{types} = $args->{types} || ['lines', undef, undef, undef, undef, undef, undef]; michael@0: $self->{dclrs} = $args->{dclrs} || [qw(lred)]; michael@0: $self->{legend} = $args->{legend} || [qw(undef)]; michael@0: $self->{y_max_value} = $args->{y_max_value} || 10000; michael@0: $self->{width} = $args->{width} || 800; michael@0: $self->{height} = $args->{height} || 720; michael@0: return $self; michael@0: } michael@0: michael@0: sub _set_standard_options { michael@0: my $self = shift; michael@0: $self->{graph}->set( michael@0: x_label => '', michael@0: y_label => 'Page Load Time (msec)', michael@0: default_type => 'points', michael@0: x_labels_vertical => 1, michael@0: y_long_ticks => 1, michael@0: x_tick_length => 8, michael@0: x_long_ticks => 0, michael@0: line_width => 2, michael@0: marker_size => 3, michael@0: markers => [8], michael@0: show_values => 0, michael@0: transparent => 0, michael@0: interlaced => 1, michael@0: skip_undef => 1, michael@0: ) michael@0: || warn $self->{graph}->error; michael@0: $self->{graph}->set_title_font(GD::Font->Giant); michael@0: $self->{graph}->set_x_label_font(GD::Font->Large); michael@0: $self->{graph}->set_y_label_font(GD::Font->Large); michael@0: $self->{graph}->set_x_axis_font(GD::Font->Large); michael@0: $self->{graph}->set_y_axis_font(GD::Font->Large); michael@0: $self->{graph}->set_legend_font(GD::Font->Giant); michael@0: } michael@0: michael@0: sub plot { michael@0: my $self = shift; michael@0: $self->{graph} = new GD::Graph::mixed($self->{width}, michael@0: $self->{height}); michael@0: $self->_set_standard_options(); michael@0: michael@0: $self->{graph}->set(title => $self->{title}, michael@0: types => $self->{types}, michael@0: y_max_value => $self->{y_max_value}, michael@0: dclrs => $self->{dclrs}, michael@0: ) michael@0: || warn $self->{graph}->error; michael@0: michael@0: $self->{graph}->set_legend( @{$self->{legend}} ); michael@0: michael@0: # draw the graph image michael@0: $self->{graph}->plot($self->{data}) || michael@0: die $self->{graph}->error; michael@0: michael@0: # send it back to stdout (or browser) michael@0: print "Content-type: image/png\n\n" if $self->{cgimode}; michael@0: binmode STDOUT; michael@0: print $self->{graph}->gd->png(); michael@0: } michael@0: michael@0: michael@0: 1; #return true