Dear Monks

I am trying to do something that I believe is possible but may be slightly above my station :(

I have a method in a class which generates image maps from Gnuplot graphs where each data point on the graph is clickable. Trouble is, at present its default behaviour is to just pass the x and y values for the data point back to the script that calls it (the current file).

I would like a situation where I can let the user specify the action (s)he would like to take (such as CSS or Javascript mouseOver action).

My current thinking is to have some sort of "action" attribute which expects a CODE reference detailing the action to take. However I am not quite sure how to implement this.

Does anyone have any ideas ... or am I making things too complicated here?

Here is the method that generates the image map:

# 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(<img src="%s" usemap="#%s">\n<map name=" +%s">%s</map>); my $AREA_FORMAT = qq(<area shape=circle coords="%.3f, %.3f, 2 +" href="%s" alt="%s" title="%s">\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_imag +e_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 t +o $command_file: $!"; # Run the gnuplot_command throwing any exceptions system("gnuplot $command_file") and croak "Problem running Gnu +plot command: $!"; # Return the image map return sprintf $MAP_FORMAT, $self->get_image_file, "PLOT", "PL +OT", $coordinates; }

Whilst creating the image map, the action: "$action_file?x=$xvalue&y=$yvalue" is currently hard coded. I think this is where I need to provide an action method: "$self->action" that will allow the user to specify his desires.

Any help is appreciated :)


In reply to 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.