com.approximatrix.charting.coordsystem.ticklocator
Class NumericTickLocator

java.lang.Object
  extended by com.approximatrix.charting.coordsystem.ticklocator.NumericTickLocator
Direct Known Subclasses:
NumericXTickLocator, NumericYTickLocator

public class NumericTickLocator
extends java.lang.Object

Class for locating tick marks along axes. Designed for axes with numeric values.

Author:
armstrong

Field Summary
private  int destics
           
private  double max
           
private  int maxtics
           
private  double min
           
private  boolean simple
           
private static int SIMPLE_TICK_THRESHOLD
          The threshhold of specified tic mark counts at which the routines default to simple tick mark calculator
private static int STOP_TICK_RECURSIONS
          Count of recursions into the tick mark auto-placement routine at which to give up calculating placement
private  int tick_recursions
           
 
Constructor Summary
NumericTickLocator(double max, double min, int numTicsDesired, int maxTics)
          Constructs a numeric tick locator based on maximum and minimum values.
NumericTickLocator(double max, double min, int numTicsDesired, int maxTics, boolean force_simple)
          Constructs a numeric tick locator based on maximum and minimum values.
 
Method Summary
private  double[] computeTicMarkLocations(double max, double min, int numTicsDesired, int maxTics, boolean force_simple)
          Simple wrapper routine that calls the appropriate tic mark locator routine.
 double[] getTickMarkLocations()
          Computes and returns the tick mark locations
private  double[] performAutoScale(double max, double min, int numTicsDesired, int maxTics)
          Computes the tick mark locations on an axis
private  double[] simpleTics(double max, double min, int numTicsDesired)
          Foolproof and simple method for determining Tic placement in cases where the tic count is low theoretically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SIMPLE_TICK_THRESHOLD

private static final int SIMPLE_TICK_THRESHOLD
The threshhold of specified tic mark counts at which the routines default to simple tick mark calculator

See Also:
Constant Field Values

STOP_TICK_RECURSIONS

private static final int STOP_TICK_RECURSIONS
Count of recursions into the tick mark auto-placement routine at which to give up calculating placement

See Also:
Constant Field Values

max

private double max

min

private double min

maxtics

private int maxtics

destics

private int destics

simple

private boolean simple

tick_recursions

private int tick_recursions
Constructor Detail

NumericTickLocator

public NumericTickLocator(double max,
                          double min,
                          int numTicsDesired,
                          int maxTics)
Constructs a numeric tick locator based on maximum and minimum values.

Parameters:
max - the largest value to be plotted
min - the smallest value to be plotted
numTicsDesired - the approximate desired number of tick marks
maxTics - the most allowed ticks

NumericTickLocator

public NumericTickLocator(double max,
                          double min,
                          int numTicsDesired,
                          int maxTics,
                          boolean force_simple)
Constructs a numeric tick locator based on maximum and minimum values. Allows one to specify using a simple locator, spacing ticks equally between max and min values.

Parameters:
max - the largest value to be plotted
min - the smallest value to be plotted
numTicsDesired - the approximate desired number of tick marks
maxTics - the most allowed ticks
force_simple - true to force the locator to create exactly numTicsDesired starting with min and ending with max
Method Detail

getTickMarkLocations

public double[] getTickMarkLocations()
Computes and returns the tick mark locations

Returns:
an array of doubles

computeTicMarkLocations

private double[] computeTicMarkLocations(double max,
                                         double min,
                                         int numTicsDesired,
                                         int maxTics,
                                         boolean force_simple)
Simple wrapper routine that calls the appropriate tic mark locator routine. The algorithm used depends on the desired number of tick marks to draw on the chart. If the requested number of tics than 5, the library will default to drawing using the simpleTic routine (which does not attempt to generate rounded numerical values). Any other values calls the elaborate tic calculator performAutoScale.

Parameters:
max - the largest value to be plotted
min - the smallest value to be plotted
numTicsDesired - the approximate desired number of tics (the result may not be this number of tics)
maxTics - the absolute maximum number of tics to draw
force_simple - force the use of the simple algorithm for drawing tic marks
Returns:
positions of tick marks along the axis

simpleTics

private double[] simpleTics(double max,
                            double min,
                            int numTicsDesired)
Foolproof and simple method for determining Tic placement in cases where the tic count is low theoretically. Simply creates equidistant tic marks based on the max, min and the number of tics desired inputs. No consideration is given to how nice the tic marks will look; the routine simply partitions the tic marks equally based on the span.

Parameters:
max - the largest value to be plotted
min - the smallest value to be plotted
numTicsDesired - the exact number of tics desired
Returns:
unrounded positions of tick marks along the axis

performAutoScale

private double[] performAutoScale(double max,
                                  double min,
                                  int numTicsDesired,
                                  int maxTics)
Computes the tick mark locations on an axis

Parameters:
max - the largest value in a data set
min - the smallest value in a data set
numTicsDesired - the first guess at the number of desired tick marks
Returns:
positions of tick marks along the axis