PGgraphmacros.pl | topic started 5/22/2000; 9:54:01 PM last post 5/22/2000; 9:54:01 PM |
Michael Gage - PGgraphmacros.pl 5/22/2000; 9:54:01 PM (reads: 2665, responses: 0) |
||||||||
NAMEPGgraphmacros -- in courseScripts directory
SYNPOSIS
DESCRIPTIONThis collection of macros provides easy access to the facilities provided by the graph module WWPlot and the modules for objects which can be drawn on a graph: functions (Fun.pm) labels (Label.pm) and images. The only image implemented currently are open and closed circles (Circle) which can be used to mark graphs of functions defined on open and closed intervals. These macros provide an easy ability to graph simple functions. More complicated projects may require direct access to the underlying modules. If these complicated projects are common then it may be desirable to create additional macros. (See numericalmacros.pl for one example.)
Other constructsSee PGbasicmacros for definitions of
init_graph$graphObject = init_graph(xmin,ymin,xmax,ymax,'ticks'=>[4,4],'axes'=>[0,0]) Creates a graph object with the default size 200 by 200 pixels. If you want axes or grids you need to specify them in options. But the default values can be selected for you.
plot_functionsUsage: ($f1, $f2, $f3) = plot_functions($graph, $f1, $f2, $f3); Where $f1 is a string of the form $f1 = qq! x^2 - 3*x + 45 for x in [0, 45) using color:red and weight:2! The phrase translates as: formula for variable in interval using option-list. The option-list contains pairs of the form attribute:value. The default for color is "default_color" which is usually black. The default for the weight (pixel width) of the pen is 2 pixels. The string_to_sub subroutine is used to translate the formula into a subroutine. The functions in the list are installed in the graph object $graph and will appear when the graph object is next drawn.
insertGraph$filePath = insertGraph(graphObject); Note: Because insertGraph involves writing to the disk, it is actually defined in dangerousMacros.pl.
The permissions and ownership of the file are controlled by Returns: A string containing the full path to the temporary file containing the image. InsertGraph draws the object $graph, stores it in "${tempDirectory}gif/$imageName.gif (or .png)" where the $imageName is obtained from the graph object. ConvertPath and surePathToTmpFile are used to insure that the correct directory separators are used for the platform and that the necessary directories are created if they are not already present. The directory address to the file is the result. The most common use of C,insertGraph> is TEXT(image(insertGraph($graph)) ); where Another common usage is: TEXT(htmlLink( alias(insertGraph($graph), "picture" ) ) ); which inserts the URL pointing to the picture. alias converts the directory address to a URL when serving HTML pages and insures that an eps file is generated when creating TeX code for downloading. (Image, automatically applies alias to its input in order to obtain the URL.) See the documentation in dangerousMacros.pl for the latest details.
'Circle' lablesUsage: $circle_object = open_circle( $x_position, $y_position, $color ); Creates a small open (resp. filled in or closed) circle for use as a stamp in marking graphs. For example $graph -> stamps($circle_object2); # puts a filled dot at $x_position, $y_position
Auxiliary macros
string_to_sub and my_math_constantsThese are internal macros which govern the interpretation of equations. Usage: $string = my_math_constants($string)
File path = /ww/webwork/pg/macros/PGgraphmacros.pl |