Package uk.ac.starlink.ttools.plot2
Class Axis
- java.lang.Object
-
- uk.ac.starlink.ttools.plot2.Axis
-
@Equality public abstract class Axis extends java.lang.Object
Does geometry and drawing for a straight line axis. Linear and logarithmic scales are supported; obtain one using thecreateAxis
factory method.- Since:
- 12 Feb 2013
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Axis(int glo, int ghi, double dlo, double dhi)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static 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, java.lang.String title, Captioner captioner, Orientation orient, boolean invert, java.awt.Graphics g)
Draws an axis title and supplied tickmarks.double[]
getDataLimits()
Returns the axis data bounds.int[]
getGraphicsLimits()
Returns the axis graphics bounds.java.awt.Rectangle
getLabelBounds(Tick[] ticks, java.lang.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.
-
-
-
Method Detail
-
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, java.lang.String title, Captioner captioner, Orientation orient, boolean invert, java.awt.Graphics g)
Draws an axis title and supplied tickmarks.- Parameters:
ticks
- tickmark arraytitle
- axis label text, may be nullcaptioner
- text positioning objectorient
- axis orientation codeinvert
- whether to reverse sense of axisg
- graphics context
-
getLabelBounds
public java.awt.Rectangle getLabelBounds(Tick[] ticks, java.lang.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.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
public static Axis createAxis(int glo, int ghi, double dlo, double dhi, boolean log, boolean flip)
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
-
-