| 1 | #========================================================================== | ||
| 2 | # Copyright (c) 1995-2000 Martien Verbruggen | ||
| 3 | #-------------------------------------------------------------------------- | ||
| 4 | # | ||
| 5 | # Name: | ||
| 6 | # GD::Graph::area.pm | ||
| 7 | # | ||
| 8 | # $Id: area.pm,v 1.19 2007/06/05 04:49:27 ben Exp $ | ||
| 9 | # | ||
| 10 | #========================================================================== | ||
| 11 | |||
| 12 | package GD::Graph::area; | ||
| 13 | |||
| 14 | ($GD::Graph::area::VERSION) = '$Revision: 1.19 $' =~ /\s([\d.]+)/; | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | |||
| 18 | use GD::Graph::axestype; | ||
| 19 | use GD; | ||
| 20 | |||
| 21 | @GD::Graph::area::ISA = qw( GD::Graph::axestype ); | ||
| 22 | |||
| 23 | # PRIVATE | ||
| 24 | sub draw_data_set | ||
| 25 | { | ||
| 26 | my $self = shift; # object reference | ||
| 27 | my $ds = shift; # number of the data set | ||
| 28 | |||
| 29 | my @values = $self->{_data}->y_values($ds) or | ||
| 30 | return $self->_set_error("Impossible illegal data set: $ds", | ||
| 31 | $self->{_data}->error); | ||
| 32 | |||
| 33 | # Select a data colour | ||
| 34 | my $dsci = $self->set_clr($self->pick_data_clr($ds),$self->{alpha}); | ||
| 35 | my $brci; | ||
| 36 | my @rgb = $self->pick_border_clr($ds); | ||
| 37 | if (@rgb > 0){ | ||
| 38 | $brci = $self->set_clr(@rgb,$self->{alpha}); | ||
| 39 | } else { | ||
| 40 | $brci = undef; | ||
| 41 | } | ||
| 42 | |||
| 43 | # Create a new polygon | ||
| 44 | my $poly = GD::Polygon->new(); | ||
| 45 | |||
| 46 | my (@top,@bottom); | ||
| 47 | |||
| 48 | # Add the data points | ||
| 49 | for (my $i = 0; $i < @values; $i++) | ||
| 50 | { | ||
| 51 | my $value = $values[$i]; | ||
| 52 | next unless defined $value; | ||
| 53 | |||
| 54 | my $bottom = $self->_get_bottom($ds, $i); | ||
| 55 | $value = $self->{_data}->get_y_cumulative($ds, $i) | ||
| 56 | if $self->{cumulate}; | ||
| 57 | |||
| 58 | my ($x, $y) = $self->val_to_pixel($i + 1, $value, $ds); | ||
| 59 | push @top, [$x, $y]; | ||
| 60 | # Need to keep track of this stuff for hotspots, and because | ||
| 61 | # it's the only reliable way of closing the polygon, without | ||
| 62 | # making odd assumptions. | ||
| 63 | push @bottom, [$x, $bottom]; | ||
| 64 | |||
| 65 | # Hotspot stuff | ||
| 66 | # XXX needs fixing. Not used at the moment. | ||
| 67 | next unless defined $self->{_hotspots}->[$ds]->[$i]; | ||
| 68 | if ($i == 0) | ||
| 69 | { | ||
| 70 | $self->{_hotspots}->[$ds]->[$i] = ["poly", | ||
| 71 | $x, $y, | ||
| 72 | $x , $bottom, | ||
| 73 | $x - 1, $bottom, | ||
| 74 | $x - 1, $y, | ||
| 75 | $x, $y]; | ||
| 76 | } | ||
| 77 | else | ||
| 78 | { | ||
| 79 | $self->{_hotspots}->[$ds]->[$i] = ["poly", | ||
| 80 | $poly->getPt($i), | ||
| 81 | @{$bottom[$i]}, | ||
| 82 | @{$bottom[$i-1]}, | ||
| 83 | $poly->getPt($i-1), | ||
| 84 | $poly->getPt($i)]; | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | foreach my $pair (@top, reverse @bottom) | ||
| 89 | { | ||
| 90 | $poly->addPt( @$pair ); | ||
| 91 | } | ||
| 92 | |||
| 93 | # Draw a filled and a line polygon | ||
| 94 | if ($self->{aa}){ | ||
| 95 | $self->{graph}->setAntiAliased($dsci); | ||
| 96 | $self->{graph}->filledPolygon($poly, GD->gdAntiAliased) | ||
| 97 | if defined $dsci; | ||
| 98 | $self->{graph}->setAntiAliased($brci); | ||
| 99 | $self->{graph}->polygon($poly, GD->gdAntiAliased) | ||
| 100 | if defined $brci; | ||
| 101 | } else { | ||
| 102 | $self->{graph}->filledPolygon($poly, $dsci) | ||
| 103 | if defined $dsci; | ||
| 104 | $self->{graph}->polygon($poly, $brci) | ||
| 105 | if defined $brci; | ||
| 106 | } | ||
| 107 | |||
| 108 | # Draw the accent lines | ||
| 109 | if (defined $brci && | ||
| 110 | ($self->{right} - $self->{left})/@values > $self->{accent_treshold}) | ||
| 111 | { | ||
| 112 | for my $i ( 0 .. $#top ) | ||
| 113 | { | ||
| 114 | my ($x, $y) = @{$top[$i]}; | ||
| 115 | my $bottom = $bottom[$i]->[1]; | ||
| 116 | $self->{graph}->dashedLine($x, $y, $x, $bottom, $brci); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 120 | return $ds | ||
| 121 | } | ||
| 122 | |||
| 123 | "Just another true value"; |