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.


In reply to Re: User defined action(s) by j1n3l0
in thread User defined action(s) by j1n3l0

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.