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.
 Rectangle getAnnotationBounds()
          Returns the bounding box that contains the axis and annotations drawn that this labeller would like to draw.
 int getHiPad()
          Returns the number of pixels above npix available for drawing on.
 int getLoPad()
          Returns the number of pixels below 0 available for drawing on.
 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

getAnnotationBounds

public Rectangle getAnnotationBounds()
Returns the bounding box that contains the axis and annotations drawn that this labeller would like to draw. In the horizontal direction this covers at least the range 0-npix, and may be larger if some numeric labels extend beyond the axis itself. In the vertical direction it includes space for the height of numeric labels and possibly a text label.

Returns:
annotation bounding 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

getLoPad

public int getLoPad()
Returns the number of pixels below 0 available for drawing on.

Returns:
left padding pixel count

getHiPad

public int getHiPad()
Returns the number of pixels above npix available for drawing on.

Returns:
right padding pixel count

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. The current font of the supplied graphics context should have font metrics as supplied in this object's constructor.

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 © 2017 Central Laboratory of the Research Councils. All Rights Reserved.