uk.ac.starlink.ttools.plot2
Class Axis

java.lang.Object
  extended by uk.ac.starlink.ttools.plot2.Axis

@Equality
public abstract class Axis
extends Object

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
protected Axis(int glo, int ghi, double dlo, double dhi)
          Constructor.
 
Method Summary
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, String title, Captioner captioner, Orientation orient, boolean invert, Graphics g)
          Draws an axis title and supplied tickmarks.
 double[] getDataLimits()
          Returns the axis data bounds.
 int[] getGraphicsLimits()
          Returns the axis graphics bounds.
 Rectangle 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Axis

protected Axis(int glo,
               int ghi,
               double dlo,
               double dhi)
Constructor.

Parameters:
glo - minimum graphics coordinate
ghi - maximum graphics coordinate
dlo - minimum data coordinate
dhi - maximum data coordinate
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 zoom
factor - 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 position
d1 - 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,
                       Orientation orient,
                       boolean invert,
                       Graphics g)
Draws an axis title and supplied tickmarks.

Parameters:
ticks - tickmark array
title - axis label text, may be null
captioner - text positioning object
orient - axis orientation code
invert - whether to reverse sense of axis
g - 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 to drawLabels(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 array
title - axis label text, may be null
captioner - text positioning object
orient - axis orientation code
invert - 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 coordinate
ghi - maximum graphics coordinate
dlo - minimum data coordinate
dhi - maximum data coordinate
log - true for logarithmic scaling, false for linear
flip - 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 bound
dhi - initial axis upper bound
d0 - pan gesture start position
d1 - pan gesture end position
isLog - 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 bound
dhi - initial axis upper bound
d0 - zoom gesture reference position
factor - zoom factor
isLog - false for linear axis, true for logarithmic
Returns:
2-element array giving final (zoomed) axis {lower,upper} bounds


Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.