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 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 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 static int MAX_ACTUAL_TICKS
          The maximum number of ticks to allow the tick position calculator to generate on a single axis.
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
 
Constructor Summary
CoordSystemUtilities(CoordSystem coord, ChartDataModelConstraints constraints, ChartDataModelConstraints constraints2, ChartDataModel model)
          Creates a new instance of CoordSystemUtilities
 
Method Summary
 int computeBottomMargin()
          Computes the bottom margin.
 int computeLeftMargin()
          Computes the left margin.
 int computeRightMargin()
          Computes the right margin.
 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)
 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)
          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)
 
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

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.


MAX_ACTUAL_TICKS

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

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. Updated for use in Phi by Jeff Armstrong


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.


performAutoScale

private double[] performAutoScale(double max,
                                  double min,
                                  int numTicsDesired)
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

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