Package uk.ac.starlink.ttools.plot
Class AxisLabeller
java.lang.Object
uk.ac.starlink.ttools.plot.AxisLabeller
Assigns and draws axis labels.
- Since:
- 13 Mar 2006
- Author:
- Mark Taylor
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Defines tick mark annotation styles. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AxisLabeller.TickStyle
Tick style suitable for right-hand-side Y axis labels.static final AxisLabeller.TickStyle
Tick style suitable for X axis labels.static final AxisLabeller.TickStyle
Tick style suitable for Y axis labels. -
Constructor Summary
ConstructorsConstructorDescriptionAxisLabeller
(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
Modifier and TypeMethodDescriptionvoid
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.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 Details
-
X
Tick style suitable for X axis labels. -
Y
Tick style suitable for Y axis labels. -
ANTI_Y
Tick style suitable for right-hand-side Y axis labels.
-
-
Constructor Details
-
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 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 Details
-
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
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
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
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
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
-