Package uk.ac.starlink.ttools.plot2
Class Axis
java.lang.Object
uk.ac.starlink.ttools.plot2.Axis
Does geometry and drawing for a straight line axis.
Linear and logarithmic scales are supported; obtain one using
the
createAxis
factory method.- Since:
- 12 Feb 2013
- Author:
- Mark Taylor
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Axis
(int glo, int ghi, double dlo, double dhi) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic Axis
createAxis
(int glo, int ghi, double dlo, double dhi, boolean log, boolean flip) Factory method to create a linear or logarithmic axis.abstract double[]
dataPan
(double d0, double d1) Returns the data bounds that result from performing an axis pan between two given data positions.abstract double
dataToGraphics
(double d) Converts a data coordinate to the graphics position on this axis.abstract double[]
dataZoom
(double d0, double factor) Returns the data bounds that result from performing an axis zoom about a given data position.void
drawLabels
(Tick[] ticks, String title, Captioner captioner, TickLook tickLook, Orientation orient, boolean invert, Graphics g) Draws an axis title and supplied tickmarks.double[]
Returns the axis data bounds.int[]
Returns the axis graphics bounds.getLabelBounds
(Tick[] ticks, String title, Captioner captioner, Orientation orient, boolean invert) Determines the bounds for axis and tickmark annotations.abstract double
graphicsToData
(double g) Converts a graphics position on this axis to a data coordinate.abstract boolean
isLinear()
Indicates whether the scaling on this axis is linear.static double[]
pan
(double dlo, double dhi, double d0, double d1, boolean isLog) Utility method for axis panning.static double[]
zoom
(double dlo, double dhi, double d0, double factor, boolean isLog) Utility method for axis zooming.
-
Constructor Details
-
Axis
protected Axis(int glo, int ghi, double dlo, double dhi) Constructor.- Parameters:
glo
- minimum graphics coordinateghi
- maximum graphics coordinatedlo
- minimum data coordinatedhi
- maximum data coordinate
-
-
Method Details
-
dataToGraphics
public abstract double dataToGraphics(double d) Converts a data coordinate to the graphics position on this axis.- Parameters:
d
- data coordinate- Returns:
- graphics coordinate
-
graphicsToData
public abstract double graphicsToData(double g) Converts a graphics position on this axis to a data coordinate.- Parameters:
g
- graphics coordinate- Returns:
- data coordinate
-
dataZoom
public abstract double[] dataZoom(double d0, double factor) Returns the data bounds that result from performing an axis zoom about a given data position.- Parameters:
d0
- data reference position for zoomfactor
- amount to zoom- Returns:
- 2-element array giving new new data min/max coordinates
-
dataPan
public abstract double[] dataPan(double d0, double d1) Returns the data bounds that result from performing an axis pan between two given data positions.- Parameters:
d0
- source data positiond1
- destination data position- Returns:
- 2-element array giving new new data min/max coordinates
-
getGraphicsLimits
public int[] getGraphicsLimits()Returns the axis graphics bounds. The first element of the result (glo
) is always strictly less than the second (ghi
).- Returns:
- 2-element array giving the graphics min/max coordinates
-
getDataLimits
public double[] getDataLimits()Returns the axis data bounds. The first element of the result (dlo
) is always strictly less than the second (dhi
).- Returns:
- 2-element array giving the data min/max coordinates
-
isLinear
public abstract boolean isLinear()Indicates whether the scaling on this axis is linear.- Returns:
- true iff this axis is linear
-
drawLabels
public void drawLabels(Tick[] ticks, String title, Captioner captioner, TickLook tickLook, Orientation orient, boolean invert, Graphics g) Draws an axis title and supplied tickmarks.- Parameters:
ticks
- tickmark arraytitle
- axis label text, may be nullcaptioner
- text positioning objecttickLook
- tick drawing styleorient
- axis orientation codeinvert
- whether to reverse sense of axisg
- graphics context
-
getLabelBounds
public Rectangle getLabelBounds(Tick[] ticks, String title, Captioner captioner, Orientation orient, boolean invert) Determines the bounds for axis and tickmark annotations. The returned value is a bounding box for everything that would be drawn by a corresponding call todrawLabels(uk.ac.starlink.ttools.plot2.Tick[], java.lang.String, uk.ac.starlink.ttools.plot2.Captioner, uk.ac.starlink.ttools.plot2.TickLook, uk.ac.starlink.ttools.plot2.Orientation, boolean, java.awt.Graphics)
.- Parameters:
ticks
- tickmark arraytitle
- axis label text, may be nullcaptioner
- text positioning objectorient
- axis orientation codeinvert
- whether to reverse sense of axis- Returns:
- bounding box for all annotations
-
createAxis
Factory method to create a linear or logarithmic axis.- Parameters:
glo
- minimum graphics coordinateghi
- maximum graphics coordinatedlo
- minimum data coordinatedhi
- maximum data coordinatelog
- true for logarithmic scaling, false for linearflip
- true if the data coordinates should run in the opposite sense to the graphics coordinates
-
pan
public static double[] pan(double dlo, double dhi, double d0, double d1, boolean isLog) Utility method for axis panning.- Parameters:
dlo
- initial axis lower bounddhi
- initial axis upper boundd0
- pan gesture start positiond1
- pan gesture end positionisLog
- false for linear axis, true for logarithmic- Returns:
- 2-element array giving final (panned) axis {lower,upper} bounds
-
zoom
public static double[] zoom(double dlo, double dhi, double d0, double factor, boolean isLog) Utility method for axis zooming.- Parameters:
dlo
- initial axis lower bounddhi
- initial axis upper boundd0
- zoom gesture reference positionfactor
- zoom factorisLog
- false for linear axis, true for logarithmic- Returns:
- 2-element array giving final (zoomed) axis {lower,upper} bounds
-