in reply to User defined action(s)

Solved this one.

What I needed was another attribute to allow the user specify his/her wishes. The default is the same as above (ie. pass the x and y values to current file as parameters).

Within the image_map() method I have changed the line:

$coordinates .= sprintf $AREA_FORMAT, $xcoord, $ycoord, "$action_file? +x=$xvalue&y=$yvalue", "Value: [$xvalue, $yvalue]", "Value: [$xvalue, +$yvalue]";

To:

$coordinates .= sprintf $AREA_FORMAT, $xcoord, $ycoord, $self->get_act +ion->($i);

I have also changed $AREA_FORMAT accordingly:

my $AREA_FORMAT = qq(<area shape=circle coords="%.3f, %.3f, 2" %s>\n) +;

The user has to ensure his/her subroutine takes one integer as an argument ($i - the current index) and returns a string. That way (s)he can iterate over a number of arrays, hard coded into his subroutine and associate the values correctly.

As an example, the following code:

#!/usr/bin/perl -w use strict; use GnuplotImageMap; # generate some values to plot my @xvalues = map { sprintf "%.3f", rand } 1 .. 10; my @yvalues = map { sprintf "%.3f", rand } 1 .. 10; # this is to test the "action" my $alphabets = [ 'a' .. 'z' ]; # generate the image map my $object = GnuplotImageMap->new( xvalues => [@xvalues], yvalues => [@yvalues], # this is where you specify what you want to do ... the default is + as before! action => sub { my ($i) = @_; return $alphabets->[$i] || "out + of bounds here"; }, ); # print out the image map print "\n\nThe image map:\n\n", $object->image_map(), "\n"; exit 0;

Gives the following output:

The image map: <img src="C:\DOCUME~1\ionyia\LOCALS~1\Temp\LSPVfXDptt.png" usemap="#PL +OT"> <map name="PLOT"> <area shape=circle coords="605.000, 172.167, 2" a > <area shape=circle coords="308.779, 207.111, 2" b > <area shape=circle coords="588.668, 264.256, 2" c > <area shape=circle coords="70.000, 310.300, 2" d > <area shape=circle coords="397.195, 82.133, 2" e > <area shape=circle coords="249.647, 370.322, 2" f > <area shape=circle coords="273.863, 425.000, 2" g > <area shape=circle coords="544.179, 162.300, 2" h > <area shape=circle coords="598.805, 55.000, 2" i > <area shape=circle coords="332.432, 269.189, 2" j > </map>

Note the alphabets: increasing from 'a' to 'j' in the image map string :)

UPDATE:
Tried to clarify the changes made and their effect on the output.