# Purpose : Generates an image map with the data available
# Usage : $map = $object->image_map;
sub image_map {
my ($self) = @_;
unless (ref $self) {
croak "Using Instance method &image_map() as Class method";
}
# Declare some variables
my $MAP_FORMAT = qq(
\n);
my $AREA_FORMAT = qq(\n);
my $action_file = basename($0); # default to current file
my $data_file = $self->get_data_file;
my $image_file = catfile($self->get_webroot, $self->get_image_file);
my $command_file = $self->get_command_file;
my $height = $self->get_gnuplot_height;
my $width = $self->get_gnuplot_width;
my $lmargin = $self->get_gnuplot_lmargin;
my $rmargin = $self->get_gnuplot_rmargin;
my $tmargin = $self->get_gnuplot_tmargin;
my $bmargin = $self->get_gnuplot_bmargin;
my $xmin = $self->get_xmin;
my $xmax = $self->get_xmax;
my $ymin = $self->get_ymin;
my $ymax = $self->get_ymax;
my $title = $self->get_title;
my $legend = $self->get_legend;
my $xaxis_label = $self->get_xaxis_label;
my $yaxis_label = $self->get_yaxis_label;
# Looping through the data ...
my $coordinates = "\n"; # for html formatting
for my $i ( 0 .. $#{$self->get_xcoords} ) {
# Get the x and y coordinates
my $xcoord = $self->get_xcoords->[$i];
my $ycoord = $self->get_ycoords->[$i];
my $xvalue = $self->get_xvalues->[$i];
my $yvalue = $self->get_yvalues->[$i];
# Create the image map ...
$coordinates .= sprintf $AREA_FORMAT, $xcoord, $ycoord, "$action_file?x=$xvalue&y=$yvalue", "Value: [$xvalue, $yvalue]", "Value: [$xvalue, $yvalue]";
# Save the x and y values to data file
print $data_file join("\t", $xvalue, $yvalue), "\n";
}
# Generate the gnuplot command
my $gnuplot_command = qq(
set terminal png
set output "$image_file"
set size $width, $height
set lmargin $lmargin
set rmargin $rmargin
set tmargin $tmargin
set bmargin $bmargin
set xrange [$xmin: $xmax]
set yrange [$ymin: $ymax]
set title "$title"
set xlabel "$xaxis_label"
set ylabel "$yaxis_label"
plot "$data_file" $legend
);
# Write gnuplot_command to command_file
print $command_file $gnuplot_command or die "Could not write to $command_file: $!";
# Run the gnuplot_command throwing any exceptions
system("gnuplot $command_file") and croak "Problem running Gnuplot command: $!";
# Return the image map
return sprintf $MAP_FORMAT, $self->get_image_file, "PLOT", "PLOT", $coordinates;
}