in reply to Re: Mouse action using SVG
in thread Mouse action using SVG

Here is the perl script to draw rectangle using SVG module. In which, I would like to have mouse interactivity. The module supports mouse actions but I am not clear about how to use it.

$svg->rectangle( x =>$x1, y =>$y1, width => $x2, height => $y2, style => { 'fill' => 'rgb(0, 0, 128)', 'stroke' => 'black', 'stroke-width' => 1, 'stroke-opacity' => 1, 'fill-opacity' => 1, }, );

Replies are listed 'Best First'.
Re^3: Mouse action using SVG
by LanX (Saint) on Jul 29, 2016 at 21:53 UTC
    >  The module supports mouse actions but I am not clear about how to use it.

    Would you mind to specify "the module" or maybe even link to it?

    There are several SVG modules on cpan,   but I am not clear about it.

    See How (Not) To Ask A Question for further ideas.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

Re^3: Mouse action using SVG
by Anonymous Monk on Jul 29, 2016 at 22:06 UTC
      It doesn't seem to work for me. I want to show the message which is stored in $message when I click the rectangle. I modified the code this way.
      $svg->rectangle( x =>$x1, y =>$y1, width => $x2, height => $y2, style => { 'fill' => 'rgb(0, 0, 128)', 'stroke' => 'black', 'stroke-width' => 1, 'stroke-opacity' => 1, 'fill-opacity' => 1, }, ); $rectangle->attrib(onclick=>q{alert($message);});
      Please correct me if I am wrong

        Of course that doesn't work. Did you look at the debug "console" of your browser to check for javascript errors? Why not? Did you look at the HTML that was produced/sent? Why not?

        After you've done that, you might also want to read the subtread at Re^7: perl dancer route template hashref pass complex json file to server issue (escape/filter).

        I'm not going to post code that I think will work for this case yet, as I think it is important for you to think more about this aspect of the problem before being handed code.

        - tye