Package uk.ac.starlink.ttools.plot
Class AxisLabeller
- java.lang.Object
-
- uk.ac.starlink.ttools.plot.AxisLabeller
-
public class AxisLabeller extends java.lang.Object
Assigns and draws axis labels.- Since:
- 13 Mar 2006
- Author:
- Mark Taylor
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AxisLabeller.TickStyle
Defines tick mark annotation styles.
-
Field Summary
Fields Modifier and Type Field Description 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
Constructors Constructor Description AxisLabeller(java.lang.String axisLabel, double lo, double hi, int npix, boolean log, boolean flip, java.awt.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
annotateAxis(java.awt.Graphics g)
Draw the axis labels on a given graphics context.void
drawGridLine(java.awt.Graphics g, int y0, int y1, double value)
Draws a single grid line on a given graphics context.void
drawGridLines(java.awt.Graphics g, int y0, int y1)
Draws grid lines on a given graphics context.java.awt.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.
-
-
-
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(java.lang.String axisLabel, double lo, double hi, int npix, boolean log, boolean flip, java.awt.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 axislo
- lower bound of the data rangehi
- upper bound of the data rangenpix
- number of pixels along the length of the axislog
- true iff the scale is to be logarithmicflip
- true iff the scale is reversed (low to high is right to left instead of left to right)fm
- font metrics used for the texttickStyle
- determines positioning of ticksreqTick
- suggested number of tick marks on the axis; the actual number may be greater or smaller according to axis length, font size etcloPad
- number of pixels below 0 available for drawing onhiPad
- number of pixels above npix available for drawing on
-
-
Method Detail
-
getAnnotationBounds
public java.awt.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(java.awt.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(java.awt.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 valuesy0
andy1
. It is the caller's responsibility to set colours and so on.- Parameters:
g
- graphics contexty0
- y coordinate of one end of the linesy1
- y coordinate of the other end of the lines
-
drawGridLine
public void drawGridLine(java.awt.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 valuesy0
andy1
. The horizontal position is given by thevalue
. 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 contexty0
- y coordinate of one end of the linesy1
- y coordinate of the other end of the linesvalue
- 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 valuesX
andY
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
-
-