| 1 | package GIFgraph::WithMap; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use vars qw (@ISA %fields $AUTOLOAD $VERSION); |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Carp; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 0 | ▶ | use CGI; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 7 | |||
| 8 | use MRP::BaseClass; | ||
| 9 | |||
| 10 | $VERSION = 1.0; | ||
| 11 | |||
| 12 | # use AUTOLOAD to pass everything that we can't do to _GIFgraph. | ||
| 13 | # don't know if this is kosha. AHHHH. | ||
| 14 | sub AUTOLOAD { | ||
| 15 | my $thing = shift; | ||
| 16 | my ($package, $function) = $AUTOLOAD =~ m/^(.*)::([^:]+)$/; | ||
| 17 | |||
| 18 | if(ref($thing)) { | ||
| 19 | my $delegate = $thing->_GIFgraph; | ||
| 20 | $function = join '::', $delegate, $function; | ||
| 21 | return $thing->$function(@_); | ||
| 22 | } | ||
| 23 | die "Could not find method $AUTOLOAD via $thing"; | ||
| 24 | } | ||
| 25 | |||
| 26 | sub isa { | ||
| 27 | my ($thing, $type) = @_; | ||
| 28 | return $thing->_GIFgraph->isa($type) || $thing->SUPER::isa($type); | ||
| 29 | } | ||
| 30 | |||
| 31 | sub new { | ||
| 32 | my $class = shift; | ||
| 33 | my $GIFgraph = shift; | ||
| 34 | my $baseClass = new MRP::BaseClass; | ||
| 35 | |||
| 36 | my $self = $class->rebless($GIFgraph, $baseClass); | ||
| 37 | |||
| 38 | $self->_GIFgraph(ref $GIFgraph); | ||
| 39 | |||
| 40 | return $self; | ||
| 41 | } | ||
| 42 | |||
| 43 | sub draw_data { | ||
| 44 | my ($self, $gd, $data) = @_; | ||
| 45 | my $fuzz = $self->fuzz; | ||
| 46 | my $map = ""; | ||
| 47 | my $mapname = $self->mapname || confess "You must set the name for this map before calling plot"; | ||
| 48 | my $seriesnames = $self->seriesnames; | ||
| 49 | my $links = $self->links; | ||
| 50 | |||
| 51 | my $delegateFunc = join '::', $self->_GIFgraph, 'draw_data'; | ||
| 52 | $self->$delegateFunc($gd, $data); | ||
| 53 | |||
| 54 | $map = '<MAP NAME="' . $mapname . '">'."\n"; | ||
| 55 | foreach my $series (1 .. $self->{numsets}) { | ||
| 56 | my (@up, @down); | ||
| 57 | foreach my $point (0 .. $self->{numpoints}) { | ||
| 58 | next unless defined($$data[$series][$point]); | ||
| 59 | my ($x, $y) = $self->val_to_pixel($point+1, $$data[$series][$point], $series); | ||
| 60 | push @up, $x, $y+$fuzz; | ||
| 61 | unshift @down, $x, $y-$fuzz; | ||
| 62 | } | ||
| 63 | my $seriesname = $seriesnames->[$series-1] || 'series '.$series; | ||
| 64 | my $link = $links->[$series-1] || "#$seriesname"; | ||
| 65 | $map .= join("\n\t", | ||
| 66 | '<AREA', | ||
| 67 | 'alt="' . $seriesname . '"', | ||
| 68 | 'href="' . $link . '"', | ||
| 69 | 'onMouseOver="self.status=' . "'$seriesname'" . '; return true"', | ||
| 70 | 'onMouseOut="self.status=' . "''" . '; return true"', | ||
| 71 | 'shape=polygon', | ||
| 72 | 'coords="' . join(', ', @up, @down) . '"', | ||
| 73 | ); | ||
| 74 | $map .= ">\n"; | ||
| 75 | } | ||
| 76 | $map .= "</MAP>\n"; | ||
| 77 | |||
| 78 | $self->map($map); | ||
| 79 | } | ||
| 80 | |||
| 81 | BEGIN { | ||
| 82 | @ISA = qw (MRP::BaseClass); | ||
| 83 | %fields = ( | ||
| 84 | 'fuzz' => 1, | ||
| 85 | 'map' => undef, | ||
| 86 | 'mapname' => undef, | ||
| 87 | 'seriesnames' => [], | ||
| 88 | 'links' => [], | ||
| 89 | '_GIFgraph' => undef, | ||
| 90 | ); | ||
| 91 | GIFgraph::WithMap->check4Clashes; | ||
| 92 | } | ||
| 93 | |||
| 94 | $VERSION; | ||
| 95 | |||
| 96 | __END__ | ||