edu.rit.numeric.plot
Class Axis

java.lang.Object
  extended by edu.rit.numeric.plot.Axis
Direct Known Subclasses:
NumericalAxis

public abstract class Axis
extends Object

Class Axis is the abstract base class for an axis on a plot. It also provides static methods to help determine the scale for an axis.


Field Summary
static Paint DEFAULT_PAINT
          The default axis paint (black).
static Stroke DEFAULT_STROKE
          The default axis stroke (solid, width=1).
protected  double myLength
          Length of this axis on the display.
protected  Paint myPaint
          Paint for drawing this axis on the display.
protected  Stroke myStroke
          Stroke for drawing this axis on the display.
 
Constructor Summary
protected Axis(double theLength, Stroke theStroke, Paint thePaint)
          Construct a new axis.
 
Method Summary
static double autoscale(double max)
          Determine a pleasing scale for an axis.
abstract  void drawHorizontal(Graphics2D g2d)
          Draw this axis in the given graphics context starting at coordinates (0, 0) and moving horizontally to the right.
abstract  void drawVertical(Graphics2D g2d)
          Draw this axis in the given graphics context starting at coordinates (0, 0) and moving vertically up.
 double getLength()
          Returns the length of this axis on the display.
 Paint getPaint()
          Returns the paint for drawing this axis on the display.
 Stroke getStroke()
          Returns the stroke for drawing this axis on the display.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_STROKE

public static final Stroke DEFAULT_STROKE
The default axis stroke (solid, width=1).


DEFAULT_PAINT

public static final Paint DEFAULT_PAINT
The default axis paint (black).


myLength

protected double myLength
Length of this axis on the display.


myStroke

protected Stroke myStroke
Stroke for drawing this axis on the display.


myPaint

protected Paint myPaint
Paint for drawing this axis on the display.

Constructor Detail

Axis

protected Axis(double theLength,
               Stroke theStroke,
               Paint thePaint)
Construct a new axis. The axis is drawn with the given length, stroke, and paint.

Parameters:
theLength - Length of this axis on the display.
theStroke - Stroke for drawing this axis on the display.
thePaint - Paint for drawing this axis on the display.
Throws:
NullPointerException - (unchecked exception) Thrown if theStroke is null or thePaint is null.
IllegalArgumentException - (unchecked exception) Thrown if theLength is less than or equal to 0.
Method Detail

getLength

public double getLength()
Returns the length of this axis on the display.


getStroke

public Stroke getStroke()
Returns the stroke for drawing this axis on the display.


getPaint

public Paint getPaint()
Returns the paint for drawing this axis on the display.


drawHorizontal

public abstract void drawHorizontal(Graphics2D g2d)
Draw this axis in the given graphics context starting at coordinates (0, 0) and moving horizontally to the right.

Parameters:
g2d - 2-D graphics context.

drawVertical

public abstract void drawVertical(Graphics2D g2d)
Draw this axis in the given graphics context starting at coordinates (0, 0) and moving vertically up.

Parameters:
g2d - 2-D graphics context.

autoscale

public static double autoscale(double max)
Determine a pleasing scale for an axis. The input, max, is the largest value to be displayed along the axis. The output is the smallest number of the form 1x10k, 2x10k, or 5x10k, k an integer, that is greater than or equal to max. This can then be used as the maximum value for the axis.

Note: The autoscale() method works for negative inputs. If max < 0, then autoscale(max) = -autoscale(-max).

Note: autoscale(0) = 0.

Parameters:
max - Maximum value to be displayed along the axis.
Returns:
Maximum value for the axis.


Copyright © 2005 by Alan Kaminsky. All rights reserved. Send comments to ark­@­cs.rit.edu.