uk.ac.starlink.ttools.plot
Class AxisLabeller

java.lang.Object
  extended by uk.ac.starlink.ttools.plot.AxisLabeller

public class AxisLabeller
extends Object

Assigns and draws axis labels.

Since:
13 Mar 2006
Author:
Mark Taylor

Nested Class Summary
static class AxisLabeller.TickStyle
          Defines tick mark annotation styles.
 
Field Summary
static AxisLabeller.TickStyle ANTI_Y
          Tick style suitable for right-hand-side Y axis labels.
static AxisLabeller.TickStyle X
          Tick style suitable for X axis labels.
static AxisLabeller.TickStyle Y
          Tick style suitable for Y axis labels.
 
Constructor Summary
AxisLabeller(String axisLabel, double lo, double hi, int npix, boolean log, boolean flip, FontMetrics fm, AxisLabeller.TickStyle tickStyle, int reqTick, int loPad, int hiPad)
          Constructs a new labeller giving enough information to determine where the tickmarks will appear.
 
Method Summary
 void annotateAxis(Graphics g)
          Draw the axis labels on a given graphics context.
 void drawGridLine(Graphics g, int y0, int y1, double value)
          Draws a single grid line on a given graphics context.
 void drawGridLines(Graphics g, int y0, int y1)
          Draws grid lines on a given graphics context.
 int getAnnotationHeight()
          Returns the height in pixels of the annotation text.
 int getNpix()
          Returns the number of pixels along this axis.
 void setDrawText(boolean drawText)
          Sets whether textual labels should be drawn on the axis.
 void setNpix(int npix)
          Sets the number of pixels along this axis.
 void setTickStyle(AxisLabeller.TickStyle tickStyle)
          Sets the tick mark style to one of the predefined settings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

X

public static final AxisLabeller.TickStyle X
Tick style suitable for X axis labels.


Y

public static final AxisLabeller.TickStyle Y
Tick style suitable for Y axis labels.


ANTI_Y

public static final AxisLabeller.TickStyle ANTI_Y
Tick style suitable for right-hand-side Y axis labels.

Constructor Detail

AxisLabeller

public AxisLabeller(String axisLabel,
                    double lo,
                    double hi,
                    int npix,
                    boolean log,
                    boolean flip,
                    FontMetrics fm,
                    AxisLabeller.TickStyle tickStyle,
                    int reqTick,
                    int loPad,
                    int hiPad)
Constructs a new labeller giving enough information to determine where the tickmarks will appear.

Parameters:
axisLabel - text annotation for the axis
lo - lower bound of the data range
hi - upper bound of the data range
npix - number of pixels along the length of the axis
log - true iff the scale is to be logarithmic
flip - true iff the scale is reversed (low to high is right to left instead of left to right)
fm - font metrics used for the text
tickStyle - determines positioning of ticks
reqTick - suggested number of tick marks on the axis; the actual number may be greater or smaller according to axis length, font size etc
loPad - number of pixels below 0 available for drawing on
hiPad - number of pixels above npix available for drawing on
Method Detail

getAnnotationHeight

public int getAnnotationHeight()
Returns the height in pixels of the annotation text. This is a distance perpendicular to the axis itself.

Returns:
size of annotation box

getNpix

public int getNpix()
Returns the number of pixels along this axis.

Returns:
npix

setNpix

public void setNpix(int npix)
Sets the number of pixels along this axis.

Parameters:
npix - axis length in pixels

annotateAxis

public void annotateAxis(Graphics g)
Draw the axis labels on a given graphics context. The axis will be drawn along the horizontal direction of the context, starting at the origin.

Parameters:
g - graphics context

drawGridLines

public void drawGridLines(Graphics g,
                          int y0,
                          int y1)
Draws grid lines on a given graphics context. The lines will be drawn vertically, the axis being considered horizontal and starting at the origin. The vertical extent of the grid lines is given by two values y0 and y1. It is the caller's responsibility to set colours and so on.

Parameters:
g - graphics context
y0 - y coordinate of one end of the lines
y1 - y coordinate of the other end of the lines

drawGridLine

public void drawGridLine(Graphics g,
                         int y0,
                         int y1,
                         double value)
Draws a single grid line on a given graphics context. The line will be drawn vertically, the axis being considered horizontal and starting at the origin. The vertical extent of the grid line is given by two values y0 and y1. The horizontal position is given by the value. If the line is out of range, no action is taken. It is the caller's responsibility to set colours and so on.

Parameters:
g - graphics context
y0 - y coordinate of one end of the lines
y1 - y coordinate of the other end of the lines
value - x position of the line in data coordinates

setTickStyle

public void setTickStyle(AxisLabeller.TickStyle tickStyle)
Sets the tick mark style to one of the predefined settings. Currently the values X and Y are available.

Parameters:
tickStyle - style

setDrawText

public void setDrawText(boolean drawText)
Sets whether textual labels should be drawn on the axis. If false, only tickmarks will be drawn. True by default.

Parameters:
drawText - true iff you want textual labelling


Copyright © 2009 Central Laboratory of the Research Councils. All Rights Reserved.