The idea of using a Plot's attributes to control the appearance of the
graphical output it produces ( and
) can easily be extended to allow the user
of a program complete control over such matters.
For instance, if the file ``plot.config'' contains a series of plotting options in the form of Plot attribute assignments (see below for an example), then we could create a Plot and implement these assignments before producing the graphical output as follows:
#include <stdio.h> #define MAXCHARS 120 FILE *stream; char line[ MAXCHARS + 2 ]; int base; ... /* Create a Plot and define the default appearance of the graphical output it will produce. */ plot = astPlot( wcsinfo, gbox, pbox, "Grid=1, Colour(grid)=2, Font(textlab)=3" ); /* Obtain the value of any Plot attributes we want to preserve. */ base = astGetI( plot, "Base" ); /* Open the plot configuration file, if it exists. Read each line of text and use it to set new Plot attribute values. Close the file when done. */ if ( stream = fopen( "plot.config", "r" ) ) { while ( fgets( line, MAXCHARS + 2, stream ) ) astSet( plot, "%s", line ); close( stream ); } /* Restore any attribute values we are preserving. */ astSetI( plot, "Base", base ); /* Produce the graphical output (e.g.). */ astGrid( plot );
Notice that we take care that the Plot's Base attribute is preserved so that the user cannot change it. This is because graphical output will not be produced successfully if the base Frame does not describe the plotting surface to which we attached the Plot when we created it.
The arrangement shown above allows the contents of the ``plot.config'' file to control most aspects of the graphical output produced (including the coordinate system used; the colour, line style, thickness and font used for each component; the positioning of axes and tick marks; the precision, format and positioning of labels; etc.) via assignments of the form:
System=Galactic, Equinox = 2001 Border = 1, Colour( border ) = 1 Colour( grid ) = 2 DrawAxes = 1 Colour( axes ) = 3 Digits = 8 Labelling = Interior
For a more sophisticated interface, you could obviously perform pre-processing on this input--for example, to translate words like ``red'', ``green'' and ``blue'' into colour indices, to permit comments and blank lines, etc.
For a full list of the attributes that may be used to control the
appearance of graphical output, see the description of the Plot class
in . For a complete description of each
individual attribute (e.g. those above), see the attribute's
entry in
.
AST A Library for Handling World Coordinate Systems in Astronomy