org.gicentre.utils.stat
Class AbstractChart

java.lang.Object
  extended by org.gicentre.utils.stat.AbstractChart
Direct Known Subclasses:
BarChart, XYChart

public abstract class AbstractChart
extends java.lang.Object

Abstract class for representing a statistical chart. This class provides the core functionality common to all charts. A chart will contain a set of axes each corresponding to a set of data. The way in which each axis/data set is displayed will depend on the nature of the chart represented by the subclass.

Version:
3.0.1, 13th August, 2010.
Author:
Jo Wood, giCentre, City University London.

Nested Class Summary
protected static class AbstractChart.Side
          Indicates a side of the chart
 
Field Summary
protected  java.text.DecimalFormat[] axisFormatter
          For numerical formatting of axis labels.
protected  float[][] data
          The datasets to be charted.
protected  float[][] logTics
          Tic mark values for optional axis display.
protected  processing.core.PApplet parent
          Parent sketch in which this chart is to be drawn.
protected  float[][] tics
          Tic mark values for optional axis display.
protected  boolean transposeAxes
          Determines if the two primary axes should be transposed.
 
Constructor Summary
protected AbstractChart(processing.core.PApplet parent)
          Initialises the chart settings.
 
Method Summary
protected static float convertToLog(double dataItem, double minLogValue, double maxLogValue)
          Converts the given value assumed to be positive to a log value scaled between 0 and 1
protected abstract  void draw(float xOrigin, float yOrigin, float width, float height)
          Should draw the chart within the given bounds.
protected  float getBorder(AbstractChart.Side side)
          Reports the internal border between the given edge of the chart and the drawing area.
protected  boolean getIsLogScale(int dimension)
          Reports whether or not the data in the given dimension are to be represented on the log10 scale.
protected  float getMax(int dimension)
          Reports the maximum value of the data to be charted on the axis of the given dimension.
protected  float getMaxLog(int dimension)
          Reports the maximum value of the log10 of the data to be charted on the axis of the given dimension.
protected  float getMin(int dimension)
          Reports the minimum value of the data to be charted on the axis of the given dimension.
protected  float getMinBorder()
          Reports the minimum internal border between the chart and the drawing area.
protected  float getMinLog(int dimension)
          Reports the minimum value of the log10 of the data to be charted on the axis of the given dimension.
protected  boolean getShowAxis(int dimension)
          Reports whether or not the axis representing the given dimension is drawn.
protected  void setBorder(float border, AbstractChart.Side side)
          Sets the internal border between the given edge of the chart and the drawing area.
protected  void setData(int dimension, float[] data)
          Sets the data to be displayed along the given axis of the chart.
protected  void setFormat(int dimension, java.lang.String format)
          Sets the numerical format for numbers shown on the axis of the given dimension.
protected  void setIsLogScale(int dimension, boolean isLog)
          Determines whether or not the data in the given dimension are to be represented on the log10 scale.
protected  void setMax(int dimension, float max)
          Sets the maximum value of the data to be charted on the axis of the given dimension.
protected  void setMin(int dimension, float min)
          Sets the minimum value of the data to be charted on the axis of the given dimension.
protected  void setMinBorder(float border)
          Sets the minimum internal border between the edge of the graph and the drawing area.
protected  void setMinBorder(float border, AbstractChart.Side side)
          Sets the minimum internal border between the given edge of the chart and the drawing area.
protected  void setRange(int dimension, float min, float max)
          Sets the minimum and maximum values of the data to be charted on the axis of the given dimension.
protected  void showAxis(int dimension, boolean showAxis, AbstractChart.Side side)
          Determines whether or not the axis representing the given dimension is drawn.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parent

protected processing.core.PApplet parent
Parent sketch in which this chart is to be drawn.


data

protected float[][] data
The datasets to be charted.


tics

protected float[][] tics
Tic mark values for optional axis display.


logTics

protected float[][] logTics
Tic mark values for optional axis display.


transposeAxes

protected boolean transposeAxes
Determines if the two primary axes should be transposed.


axisFormatter

protected java.text.DecimalFormat[] axisFormatter
For numerical formatting of axis labels.

Constructor Detail

AbstractChart

protected AbstractChart(processing.core.PApplet parent)
Initialises the chart settings. Subclasses should normally call this constructor as a convenience to initialise properties common to all charts.

Parameters:
parent - Sketch in which this chart is to appear.
Method Detail

draw

protected abstract void draw(float xOrigin,
                             float yOrigin,
                             float width,
                             float height)
Should draw the chart within the given bounds. All implementing classes must include this method do do the drawing.

Parameters:
xOrigin - left-hand pixel coordinate of the area in which to draw the chart.
yOrigin - top pixel coordinate of the area in which to draw the chart.
width - Width in pixels of the area in which to draw the chart.
height - Height in pixels of the area in which to draw the chart.

setData

protected void setData(int dimension,
                       float[] data)
Sets the data to be displayed along the given axis of the chart. Updates the min and max ranges in response to the new data.

Parameters:
dimension - Dimension of the data to add.
data - Collection of data items to represent in the chart.

setRange

protected void setRange(int dimension,
                        float min,
                        float max)
Sets the minimum and maximum values of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose minimum value is to be set.
min - Minimum value to be represented on the axis.
max - Maximum value to be represented on the axis.

setMin

protected void setMin(int dimension,
                      float min)
Sets the minimum value of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose minimum value is to be set.
min - Minimum value to be represented on the axis.

getMin

protected float getMin(int dimension)
Reports the minimum value of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose minimum value is to be retrieved.
Returns:
Minimum value to be represented on the axis.

getMax

protected float getMax(int dimension)
Reports the maximum value of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose maximum value is to be retrieved.
Returns:
Maximum value to be represented on the axis.

getMinLog

protected float getMinLog(int dimension)
Reports the minimum value of the log10 of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose minimum value is to be retrieved.
Returns:
Minimum value to be represented on the axis assuming log scaling.

getMaxLog

protected float getMaxLog(int dimension)
Reports the maximum value of the log10 of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose maximum value is to be retrieved.
Returns:
Maximum value to be represented on the axis assuming log scaling.

setMax

protected void setMax(int dimension,
                      float max)
Sets the maximum value of the data to be charted on the axis of the given dimension.

Parameters:
dimension - Dimension of the data whose maximum value is to be set.
max - Maximum value to be represented on the axis.

setMinBorder

protected void setMinBorder(float border)
Sets the minimum internal border between the edge of the graph and the drawing area.

Parameters:
border - Minimum internal border size in pixel units.

setMinBorder

protected void setMinBorder(float border,
                            AbstractChart.Side side)
Sets the minimum internal border between the given edge of the chart and the drawing area. If the given value is less than that given to the no-arguments method setMinBorder(), then this method has no effect.

Parameters:
border - Border at the given side in pixel units.
side - Side of the chart to set the minimum border size.

setBorder

protected void setBorder(float border,
                         AbstractChart.Side side)
Sets the internal border between the given edge of the chart and the drawing area. This method is used for explicit setting of border dimensions and will also reset the minimum border to the given dimension.

Parameters:
border - Border at the given side in pixel units.
side - Side of the chart to set the border size.

getMinBorder

protected float getMinBorder()
Reports the minimum internal border between the chart and the drawing area.

Returns:
Minimum border between chart and drawing area in pixel units.

getBorder

protected float getBorder(AbstractChart.Side side)
Reports the internal border between the given edge of the chart and the drawing area. This value is at least getMinBorder() and large enough to accommodate any axis labelling.

Parameters:
side - Side of the chart to query.
Returns:
Border at the given side in pixel units.

showAxis

protected void showAxis(int dimension,
                        boolean showAxis,
                        AbstractChart.Side side)
Determines whether or not the axis representing the given dimension is drawn.

Parameters:
dimension - Dimension of the data to have axis displayed or hidden.
showAxis - Axis is drawn if true.
side - Side of chart along which axis is drawn.

getShowAxis

protected boolean getShowAxis(int dimension)
Reports whether or not the axis representing the given dimension is drawn.

Parameters:
dimension - Dimension of the data to query.
Returns:
True if given axis dimension is drawn.

getIsLogScale

protected boolean getIsLogScale(int dimension)
Reports whether or not the data in the given dimension are to be represented on the log10 scale.

Parameters:
dimension - Dimension of the data to query.
Returns:
True if the data in the given dimension are to be log-scaled.

setIsLogScale

protected void setIsLogScale(int dimension,
                             boolean isLog)
Determines whether or not the data in the given dimension are to be represented on the log10 scale.

Parameters:
dimension - Dimension of the data to set.
isLog - True if the data in the given dimension are to be log-scaled or false if linear.

setFormat

protected void setFormat(int dimension,
                         java.lang.String format)
Sets the numerical format for numbers shown on the axis of the given dimension.

Parameters:
dimension - Dimension of the data axis to format.
format - Format for numbers on the given data axis.

convertToLog

protected static float convertToLog(double dataItem,
                                    double minLogValue,
                                    double maxLogValue)
Converts the given value assumed to be positive to a log value scaled between 0 and 1

Parameters:
dataItem - Item from which to find log value.
minLogValue - Minimum value of the log10 of dataItem (used to scale result between 0-1)
maxLogValue - Maximum value of the log10 of dataItem (used to scale result between 0-1)
Returns:
Log-scaled equivalent of the given value.


gicentreUtils V.3.0, API documentation generated 13th August, 2010