1package CVSMonitor::Graph::Lines;
2
3# This package implements a Graph that calculate statistics on the quantity
4# of lines over time.
5
6use strict;
7use UNIVERSAL 'isa';
8use base 'CVSMonitor::Graph::Range';
9use Class::Autouse 'GD::Graph::lines',
10                   'Chart::Math::Axis';
11
12
13
14
15
16# What sort of Range do we need?
17sub rangeClass { 'CVSMonitor::Range::Basics' }
18
19# Returns the GD::Image object for the graph
20sub gd {
21	my $self = shift;
22
23	# Build the datasets
24	my $dates = $self->{Range}->slice( 'date' ) or return undef;
25	my $up = $self->addSlices(
26		$self->{Range}->slice( 'add' ),
27		$self->{Range}->slice( 'increase' ),
28		) or return undef;
29	my $down = $self->addSlices(
30		$self->{Range}->slice( 'remove' ),
31		$self->{Range}->slice( 'decrease' ),
32		) or return undef;
33	$down = $self->negateSlice( $down ) or return undef;
34	my $size = $self->addSlices( $up, $down ) or return undef;
35	my $accum = $self->accumulateSlice( $size );
36
37	# Add the start data if needed
38	if ( $self->getShowStart ) {
39		unshift @$dates, 'Start';
40		unshift @$up, 0; unshift @$down, 0;
41		unshift @$size, 0; unshift @$accum, 0;
42	}
43
44	# Create the graph object
45	my $graph = GD::Graph::lines->new( $self->getWidth, $self->getHeight ) or return undef;
46
47	# Set the legend
48	$graph->set_legend( 'Added', 'Removed', 'Difference', 'Total Size' );
49
50	# Since the axis provided by GD::Graph sucks, we will generate our own
51	# Use the oh-so-nifty Chart::Math::Axis to acomplish this.
52	my $y_max_value = $self->sliceMax( $up, $down, $size, $accum );
53	my $y_min_value = $self->sliceMin( $up, $down, $size, $accum );
54	my $Axis = Chart::Math::Axis->new( $y_max_value, $y_min_value ) or return undef;
55	$Axis->include_zero() or return undef;
56	if ( $self->{maximum_intervals} ) {
57		$Axis->set_maximum_intervals( $self->{maximum_intervals} );
58	}
59	$Axis->apply_to( $graph );
60
61	# Set the calculated graph properties
62	$graph->set(
63		title             => $self->getTitle,
64		x_labels_vertical => 1,
65		y_label           => 'File Lines',
66		dclrs             => [ qw{green red blue black} ],
67		legend_placement  => 'BC',
68		zero_axis         => 1,
69		skip_undef        => 1,
70		);
71
72	# Plot and return
73	$graph->plot( [ $dates, $up, $down, $size, $accum ] );
74}
75
761;
77
78__END__
79
80# Copyright (C) 2002-2004 Adam Kennedy
81#
82# This program is free software; you can redistribute it and/or modify
83# it under the terms of the GNU General Public License as published by
84# the Free Software Foundation; either version 2 of the License, or
85# (at your option) any later version.
86#
87# This program is distributed in the hope that it will be useful,
88# but WITHOUT ANY WARRANTY; without even the implied warranty of
89# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
90# GNU General Public License for more details.
91#
92# You should have received a copy of the GNU General Public License
93# along with this program; if not, write to the Free Software
94# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
95#
96# Should you wish to utilise this software under a different licence,
97# please contact the author.
98