com.approximatrix.charting
Class CoordSystemUtilities

java.lang.Object
  extended by com.approximatrix.charting.CoordSystemUtilities

public class CoordSystemUtilities
extends java.lang.Object

This class provides some utility functions for a CoordSystem. They were externalized to make the CoordSystem class clearer.

Version:
1.0
Author:
mueller, armstrong

Field Summary
protected  CoordSystem c
          The coordinate system associated with these utilities
protected  ChartDataModelConstraints constraints
          The primary axis constraints
protected  ChartDataModelConstraints constraints2
          The secondary axis contraints
private static int DEFAULT_MAX_ACTUAL_TICKS
          The default maximum number of ticks to allow the tick position calculator to generate on a single axis.
private static float[] DOT1
          Constant array of floats used to create the default grid line style.
private  int estimated_x_ticks
          Estimate of the number of x ticks to draw.
private  int estimated_y_ticks
          Estimates of the number of y ticks to draw.
private static java.awt.Color GRID_COLOR
          Color used for drawing gridlines
private static java.awt.BasicStroke GRID_LINE_STYLE
          Default and fixed grid line style to use
protected  int leftUnitBuffer
          Buffer to move the y axis label off the absolute bounds
protected  int marginOffset
          used for the offset on the y axis for the size of a "tick"
private static int MAX
          Internal constant refering to the max value index of a 2-element constraint array
private  int maximum_x_ticks
          The maximum number of x ticks to allow in the x direction
private  int maximum_y_ticks
          The maximum number of y ticks to allow in the x direction
private static int MIN
          Internal constant refering to the min value index of a 2-element constraint array
protected  ChartDataModel model
          The model associated with these utilities
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
          Used to limit the number of recursions into the tick mark auto-placement routine
 
Constructor Summary
CoordSystemUtilities(CoordSystem coord, ChartDataModelConstraints constraints, ChartDataModelConstraints constraints2, ChartDataModel model)
          Creates a new instance of CoordSystemUtilities
 
Method Summary
private  void checkMaxTickConsistency()
          Makes sure that the estimated tic mark count is always limited by the maximum tic mark count limit.
 int computeBottomMargin()
          Computes the bottom margin.
 int computeLeftMargin()
          Computes the left margin.
 int computeRightMargin()
          Computes the right margin.
private  double[] computeTicMarkLocations(double max, double min, int numTicsDesired, int maxTics)
          Simple wrapper that calls the other computeTicMarkLocations routine.
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.
 int computeTopMargin()
          Computes the top margin.
 int computeXAxisLabelHeight()
          Computes the maximum height of all x-axis labels.
 int computeYAxisLabelWidth()
          Computes the maximum width of all y-axis labels.
 void drawNumericalXAxisGrid(java.awt.Graphics2D g)
          Draws a grid based on values in the x-axis
 void drawNumericalXAxisTicks(java.awt.Graphics2D g)
          This method is called by paintDefault to paint the ticks on the x-axis for numerical x-axis values.
 void drawXAxisTicks(java.awt.Graphics2D g)
          This method is called by paintDefault to paint the ticks on the x-axis for non-numerical x-axis values..
 void drawYAxisGrid(java.awt.Graphics2D g)
          Draws a grid based on values in the y-axis
 void drawYAxisTicks(java.awt.Graphics2D g)
          This method is called by paintDefault to paint the ticks on the y-axis.
 int getEstimatedXTicks()
          Returns the number of estimated X ticks to draw on the graph (not the actual)
 int getEstimatedYTicks()
          Returns the number of estimated Y ticks to draw on the graph (not the actual)
 int getMaximumXTicks()
          Returns the maximum number of X ticks to draw on the X axis
 int getMaximumYTicks()
          Returns the maximum number of Y ticks to draw on the Y axis
 java.awt.geom.Line2D getSecondYAxisLine2D()
          Computes the Line2D object of the second y-axis using the DataConstraints.
 java.awt.geom.Line2D getXAxisLine2D()
          Computes the Line2D object of the x-axis using the DataConstraints.
private  java.awt.geom.Point2D[] getXTickLocations()
          Returns the location of tick marks on the x-axis without any transform for plotting
 java.awt.geom.Line2D getYAxisLine2D()
          Computes the Line2D object of the y-axis using the DataConstraints.
private  java.awt.geom.Point2D[] getYTickLocations()
          Returns the location of tick marks on the y-axis without any transform for plotting
private  double[] performAutoScale(double max, double min, int numTicsDesired, int maxTics)
          Computes the tick mark locations on an axis
private  double[] safeMaxMin(double max, double min)
          Returns a safe estimate of min and max drawing values for an axis.
 void setEstimatedXTicks(int number)
          Sets the estimated number of X ticks (not the actual - handled by autoscaler)
 void setEstimatedYTicks(int number)
          Sets the estimated number of Y ticks (not the actual - handled by autoscaler)
 void setMaximumXTicks(int value)
           
 void setMaximumYTicks(int value)
          Sets the maximum number of ticks along the Y axis that will be allowed.
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

MAX

private static final int MAX
Internal constant refering to the max value index of a 2-element constraint array

See Also:
Constant Field Values

MIN

private static final int MIN
Internal constant refering to the min value index of a 2-element constraint array

See Also:
Constant Field Values

GRID_COLOR

private static final java.awt.Color GRID_COLOR
Color used for drawing gridlines


DOT1

private static final float[] DOT1
Constant array of floats used to create the default grid line style.


GRID_LINE_STYLE

private static final java.awt.BasicStroke GRID_LINE_STYLE
Default and fixed grid line style to use


marginOffset

protected final int marginOffset
used for the offset on the y axis for the size of a "tick"

See Also:
Constant Field Values

leftUnitBuffer

protected final int leftUnitBuffer
Buffer to move the y axis label off the absolute bounds

See Also:
Constant Field Values

c

protected CoordSystem c
The coordinate system associated with these utilities


constraints

protected ChartDataModelConstraints constraints
The primary axis constraints


constraints2

protected ChartDataModelConstraints constraints2
The secondary axis contraints


model

protected ChartDataModel model
The model associated with these utilities


estimated_x_ticks

private int estimated_x_ticks
Estimate of the number of x ticks to draw. Used for evaluating the automatically-generated tick locations.


estimated_y_ticks

private int estimated_y_ticks
Estimates of the number of y ticks to draw. Used for evaluating the automatically-generated tick locations.


DEFAULT_MAX_ACTUAL_TICKS

private static final int DEFAULT_MAX_ACTUAL_TICKS
The default maximum number of ticks to allow the tick position calculator to generate on a single axis.

See Also:
Constant Field Values

maximum_x_ticks

private int maximum_x_ticks
The maximum number of x ticks to allow in the x direction


maximum_y_ticks

private int maximum_y_ticks
The maximum number of y ticks to allow in the x direction


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

tick_recursions

private int tick_recursions
Used to limit the number of recursions into the tick mark auto-placement routine


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
Constructor Detail

CoordSystemUtilities

public CoordSystemUtilities(CoordSystem coord,
                            ChartDataModelConstraints constraints,
                            ChartDataModelConstraints constraints2,
                            ChartDataModel model)
Creates a new instance of CoordSystemUtilities

Method Detail

computeLeftMargin

public int computeLeftMargin()
Computes the left margin.


computeRightMargin

public int computeRightMargin()
Computes the right margin.


computeTopMargin

public int computeTopMargin()
Computes the top margin.


computeBottomMargin

public int computeBottomMargin()
Computes the bottom margin.


computeXAxisLabelHeight

public int computeXAxisLabelHeight()
Computes the maximum height of all x-axis labels.


computeYAxisLabelWidth

public int computeYAxisLabelWidth()
Computes the maximum width of all y-axis labels.


drawNumericalXAxisTicks

public void drawNumericalXAxisTicks(java.awt.Graphics2D g)
This method is called by paintDefault to paint the ticks on the x-axis for numerical x-axis values.

Parameters:
g - the Graphics2D context to paint in

drawXAxisTicks

public void drawXAxisTicks(java.awt.Graphics2D g)
This method is called by paintDefault to paint the ticks on the x-axis for non-numerical x-axis values..

Parameters:
g - the Graphics2D context to paint in

drawYAxisTicks

public void drawYAxisTicks(java.awt.Graphics2D g)
This method is called by paintDefault to paint the ticks on the y-axis.

Parameters:
g - the Graphics2D context in which to draw

drawYAxisGrid

public void drawYAxisGrid(java.awt.Graphics2D g)
Draws a grid based on values in the y-axis


drawNumericalXAxisGrid

public void drawNumericalXAxisGrid(java.awt.Graphics2D g)
Draws a grid based on values in the x-axis


getYTickLocations

private java.awt.geom.Point2D[] getYTickLocations()
Returns the location of tick marks on the y-axis without any transform for plotting


getXTickLocations

private java.awt.geom.Point2D[] getXTickLocations()
Returns the location of tick marks on the x-axis without any transform for plotting


getXAxisLine2D

public java.awt.geom.Line2D getXAxisLine2D()
Computes the Line2D object of the x-axis using the DataConstraints.


getYAxisLine2D

public java.awt.geom.Line2D getYAxisLine2D()
Computes the Line2D object of the y-axis using the DataConstraints.


getSecondYAxisLine2D

public java.awt.geom.Line2D getSecondYAxisLine2D()
Computes the Line2D object of the second y-axis using the DataConstraints.


computeTicMarkLocations

private double[] computeTicMarkLocations(double max,
                                         double min,
                                         int numTicsDesired,
                                         int maxTics)
Simple wrapper that calls the other computeTicMarkLocations routine. This wrapper does not require the specification of the force_simple flag. This routine may become deprecated in the future if the option to always force simple tic mark calculation is added.

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
Returns:
positions of tick marks along the axis

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

setEstimatedXTicks

public void setEstimatedXTicks(int number)
Sets the estimated number of X ticks (not the actual - handled by autoscaler)

Parameters:
number - the number of xticks to draw (estimated)

setEstimatedYTicks

public void setEstimatedYTicks(int number)
Sets the estimated number of Y ticks (not the actual - handled by autoscaler)

Parameters:
number - the number of yticks to draw (estimated)

getEstimatedXTicks

public int getEstimatedXTicks()
Returns the number of estimated X ticks to draw on the graph (not the actual)

Returns:
the estimated number of ticks to be drawn

getEstimatedYTicks

public int getEstimatedYTicks()
Returns the number of estimated Y ticks to draw on the graph (not the actual)

Returns:
the estimated number of ticks to be drawn

setMaximumXTicks

public void setMaximumXTicks(int value)
Parameters:
value -

setMaximumYTicks

public void setMaximumYTicks(int value)
Sets the maximum number of ticks along the Y axis that will be allowed.

Parameters:
value - the maximum number of Y ticks, or -1 to reset to default

getMaximumXTicks

public int getMaximumXTicks()
Returns the maximum number of X ticks to draw on the X axis

Returns:
the maximum number of X ticks to draw

getMaximumYTicks

public int getMaximumYTicks()
Returns the maximum number of Y ticks to draw on the Y axis

Returns:
the maximum number of Y ticks to draw

checkMaxTickConsistency

private void checkMaxTickConsistency()
Makes sure that the estimated tic mark count is always limited by the maximum tic mark count limit. Should be called every time the setEstimated?Ticks or setMaximum?Ticks methods are run.


safeMaxMin

private double[] safeMaxMin(double max,
                            double min)
Returns a safe estimate of min and max drawing values for an axis. Used to defend against special cases where max and min might be equal or reversed.

Parameters:
max - the original max value
min - the originial min value
Returns:
the new max and min values in an array, which can be indexed using the MAX and MIN constants in this class