# fine_likert.pl # Original by Kieran Mathieson # Perl port by Andrew Perrin # See original idea, ASP code, license, and documentation at: # http://www.sba.oakland.edu/faculty/mathieson/research/slider_sim/implementation_paper/fgl_implmentation.htm # Perl implementation copyright (c) 2003 Andrew J. Perrin. # All rights reserved. # # You may use and redistribute the Perl code under the terms of your # choice of the Perl Artistic License: # http://www.perl.com/pub/a/language/misc/Artistic.html # or the Gnu Public License: # http://www.gnu.org/licenses/gpl.html # # You'll need the collection of gifs to make this work. You can find them # from http://www.unc.edu/~aperrin/tips/src/likert_gifs.zip or # http://www.unc.edu/~aperrin/tips/src/likert_gifs.tgz # # Usage: (assumes this file saved in @INC path as fine_likert.pl) # (options are passed via hashref [preferred] or assumed @_) # (all options are optional; see defaults below) # # require 'fine_likert.pl'; # ... # print fine_likert({-tickwidthpixels => .., # -cellheightpixels => .., # -minvalue => .., #beginning of range # -maxvalue => .., #end of range # -ticksperunitvalue => .., #possible options between values # -labels => [..], #arrayref of unit labels # -showvalue => .., #include a text box with selection? # -name => .., #CGI variable name for value # -gifserver => .., #Where to find the GIFs needed # -formname => ..}); #Name (from
) # #of form scale is on sub fine_likert { my $param = {-tickwidthpixels => 3, -cellheightpixels => 21, -minvalue => 1, -maxvalue => 5, -ticksperunitvalue => 30, -labels => [], -showvalue => 0, -name => 'val', -gifserver => "", -formname => "f" }; my $p; unless (ref($_[0]) eq 'HASH') { # make @_ into hash $p = {@_}; } else { $p = shift; } $param->{$_} = $p->{$_} for keys %$p; $param->{-valuerange} = $param->{-maxvalue} - $param->{-minvalue}; for my $i (0..$param->{-valuerange}) { $param->{-labels}->[$i] = $i unless defined $param->{-labels}->[$i]; } if ($param->{-gifserver} and substr($param->{-gifserver}, -1, 1) ne "/") { $param->{-gifserver} = "$param->{-gifserver}/"; } my @out; push @out, < var oldImage; var oldTickNumber; var bFirstTimeThru = true; function makeTick(tickNumber) { var tickName; document.$param->{-formname}.$param->{-name}.value = tickNumber / 30 + 1; tickName = 'tick' + tickNumber; if (!bFirstTimeThru) eval('document.$param->{-formname}.tick' + oldTickNumber + '.src = oldImage'); oldImage = eval('document.$param->{-formname}.' + tickName + '.src'); oldTickNumber = tickNumber; bFirstTimeThru = false; eval('document.$param->{-formname}.'+tickName+'.src="$param->{-gifserver}1x1_red.gif"'); } ESCRIPT push(@out, ('', '') ); #Write out the first table - the scale #Write out a cell that is half a scale unit value push(@out, ""); #Write out each scale interval for my $i (0..$param->{-valuerange} - 1) { #Black tick to start it push(@out, ""); #Now regular ticks for the rest of the scale interval for my $j (1 .. $param->{-ticksperunitvalue} - 1) { push(@out, ""); } # $j } # $i # Write out final tick push(@out, ""); #Write out a cell that is half a unit value push(@out, ""); push(@out,("", '
{-cellheightpixels}>{-cellheightpixels} width=" . "$param->{-tickwidthpixels} border=0 onclick='makeTick(" . $i * $param->{-ticksperunitvalue} . ")'>{-cellheightpixels} width=" . "$param->{-tickwidthpixels} border=0 onclick='" . "makeTick(" . ($i * $param->{-ticksperunitvalue} + $j) . ")'>{-cellheightpixels} " . "width=$param->{-tickwidthpixels} border=0 onclick=makeTick(" . $param->{-valuerange} * $param->{-ticksperunitvalue} . ")'>
', '', '')); #Write out the label table for my $i (0 .. $param->{-valuerange}) { push(@out, ""); } push(@out,('', '
$param->{-labels}->[$i]
')); if ($param->{-showvalue}) { push(@out, "{-name}>"); } else { push(@out, "{-name}>"); } return join("\n",@out); } 1;