NAME
PostScript::GraphKey - a Key area for PostScript::GraphPaper
SYNOPSIS
use PostScript::File;
use PostScript::GraphKey;
use PostScript::GraphPaper;
my $ps = new PostScript::File;
my @bbox = $psf->get_page_bounding_box();
# Calculate variables from the graph data
# planned layout and available space ...
my $gk = new PostScript::GraphKey(
num_items => ... ,
max_height => ... ,
text_width => ... ,
icon_width => ... ,
icon_height => ... ,
);
# Need to pass this to GraphPaper
my $width = $pgk->width();
my $gp = new PostScript::GraphPaper(
file => $ps,
chart => {
key_width => $width,
},
);
# Now we can link the two
$gk->build_key( $gp );
foreach $line (@lines) {
... draw line on graph_paper ...
$gk->add_key_item( $title, <<END );
... postscript code
... drawing icon
END
}
DESCRIPTION
This is a companion object to PostScript::GraphPaper, used by any module that requies a Key for a graph. It automatically adjusts size and shape to accomodate the number of items in the space available, adding more columns if there is not enough vertical space.
The opportunity is provided to draw an icon with each key item. Ideally, this should use the same code and style as is used on the graph.
CONSTRUCTOR
new( [options] )
options
should be either a list of hash keys and values or a hash reference. Unlike other objects in this series, a couple of these (max_height
and num_items
) are required. Another difference is that all options occur within a flat space - there are no sub-groups. This is because it is expected that this module will only be used as part of another Chart object, with these options passed as a group through that constructor.
All values are in PostScript native units (1/72 inch).
file
If graph_paper
is not given, this probably should be. It is the PostScript::File object that holds the graph being constructed. It is possible to specify this later, when calling add_key_item. (No default)
background
Background colour for the key rectangle. (Default: 1)
graph_paper
If given, this should be a PostScript::GraphPaper object. A GraphKey needs to know which GraphPaper has allocated space for it. But the GraphPaper need the GraphKey to have already worked out how much space it needs. The best solution is to create the GraphKey before the GraphPaper, then pass the latter to build_chart. (No default)
horizontal_spacing
The gaps between edges, icon and text. (Defaults to spacing
)
icon_height
Vertical space for each icon. This will never be smaller than the height of the text. (Defaults to text_size
)
icon_width
Amount of horizontal space to allow for the icon to the left of each label. (Defaults to text_size
)
max_height
The vertical space available for the key rectangle. GraphKey tries to fit as many items as possible within this before adding another column.
num_items
The number of items that will be placed in the key.
outline_color
Colour of the box's outline. (Default: 0)
outline_width
Width of the box's outline. (Default: 0.75)
spacing
A larger value gives a less crowded feel, reduce it if you are short of space. Think printing leading. (Default: 4)
text_color
Colour of the text used in the body of the key. (Default: 0)
text_font
Font used for the key body text. (Default: "Helvetica")
text_size
Size of the font used for the key body text. (Default: 10)
text_width
Amount of room allowed for the text label on each key item. (Defaults to four times the font size)
title
The heading at the top of the key rectangle. (Default: "Key")
title_color
Colour of the key heading. (Default: 0)
title_font
The font used for the heading. (Default: "Helvetica-Bold")
title_size
Size of the font used for the heading. (Default: 12)
vertical_spacing
The gap between key items. (Defaults to spacing
)
OBJECT METHODS
height()
Return the height required for the key rectangle.
width()
Return the width required for the key rectangle.
build_key( [graph_paper] )
This is where the position of the key area is fixed and the outline and heading are drawn. It must be called before add_key_item.
add_key_item( label, code [, psfile] )
label
-
The text for this key item
code
-
Postscript code which draws the icon.
psfile
-
The PostScript::File object the code will be written to. If it was not given to new as either
file
orgraph_paper
, it must be given here.
A number of postscript variables are provided to help with the drawing.
kix0 left edge of icon area
kiy0 bottom edge
kix1 right edge
kiy1 top edge
Your code should use its own dictionary and can refer to dictionaries you have begun but not yet ended at this point. For example, here is the code used by PostScript::XYChart. It calculates the mid point of a diagonal line and draws it using the same functions used for the main chart. line_outer
etc. are provided by PostScript::GraphStyle to change style settings, draw1point
just expects 'x y' and drawxyline
expects an array of coordinates followed by the greatest index allowed.
$graphkey->add_key_item( $line->{ytitle},
<<END_KEY_ITEM );
2 dict begin
/kpx kix0 kix1 add 2 div def
/kpy kiy0 kiy1 add 2 div def
point_outer
kpx kpy draw1point
[ kix0 kiy0 kix1 kiy1 ] 3
2 copy
line_outer drawxyline
line_inner drawxyline
point_inner
kpx kpy draw1point
end
END_KEY_ITEM
BUGS
Very likely. This is still alpha software and has only been tested in very predictable conditions.
AUTHOR
Chris Willmot, chris@willmot.org.uk
SEE ALSO
PostScript::File, PostScript::GraphStyle, PostScript::GraphPaper.