net.sourceforge.webcompmath.draw
Class ScatterPlot

java.lang.Object
  extended by java.awt.Component
      extended by net.sourceforge.webcompmath.draw.Drawable
          extended by net.sourceforge.webcompmath.draw.ScatterPlot
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, Computable
Direct Known Subclasses:
WCMScatterPlotBean

public class ScatterPlot
extends Drawable
implements Computable

A ScatterPlot graphs data taken from a DataTableInput. The data in the form of a small plus sign at each (x,y) in the data. The x and y values can be taken directly from two specified columns in the table. They can also be computed by expressions that can use column names from the table as well as the special variable rowNumber. For example, if column names are X and Y, then it could plot sqrt(X) versus rowNumber*(X+Y).

Optionally, a ScatterPlot will also draw a regression line for the data. Certain statistical values about the data points are available as Value objects by calling the getValueObject() method.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int CORRELATION
          A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
static int DATACT
          A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
static int INTERCEPT
          A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
static int MISSINGCT
          A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
static int SLOPE
          A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
static int STANDARDERROR
          A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
 
Fields inherited from class net.sourceforge.webcompmath.draw.Drawable
canvas, coords
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ScatterPlot()
          Default constructor.
ScatterPlot(DataTableInput table)
          Create a scatter plot to plot data from the specified table.
ScatterPlot(DataTableInput table, Expression exp1, Expression exp2)
          Create scatter plot to plot specified expressions using data from a table.
ScatterPlot(DataTableInput table, int column1, int column2)
          Create a scatter plot to plot data from two specified columns in a table.
 
Method Summary
 void compute()
          Recompute the data for the scatter plot.
 void draw(java.awt.Graphics g, boolean coordsChanged)
          Draw the data points and regression line.
 boolean getAutoChangeLimits()
          The return value indicates whether the limits on the CoordinateRect are automatically adjusted when the data is recomputed.
 int getCrossHalfSize()
          Get the width and height, in pixels, of crosses.
 int getCrossLineWidth()
          Get the width, in pixels, of lines that are drawn.
 java.awt.Color getDataColor()
          Get the color that is used to draw the points in the data.
 java.awt.Color getLineColor()
          Get the color that is used to draw the regression line.
 int getLineWidth()
          Get the width, in pixels, of lines for crosses.
 boolean getMissingValueIsError()
          The return value indicates whether missing data is considered to be an error.
 boolean getShowRegressionLine()
          The return value tells whether a regression line is drawn.
 DataTableInput getTable()
          Get the DataTableInput from which the plotted data is obtained.
 Value getValueObject(int valueCode)
          Get a Value that represents a statistic about the data that is shown in the scatter plot.
 void setAutoChangeLimits(boolean set)
          If the parameter is true, then the limits on the CoordinateRect that contains this ScatterPlot are automatically adjusted whenever the data is recomputed.
 void setColumns(int c1, int c2)
          Specify that the data to be plotted should be taken from the specified columns in the table.
 void setCrossHalfSize(int size)
          Set the width and height, in pixels, of crosses.
 void setCrossLineWidth(int width)
          Set the width, in pixels, of lines for crosses.
 void setDataColor(java.awt.Color color)
          Set the color that is used to draw the points in the data.
 void setExpressions(Expression exp1, Expression exp2)
          Specify the data for the the plot is to be obtained by evaluating the two expressions that are given as parameters.
 void setLineColor(java.awt.Color color)
          Set the color that is used to draw the regression line.
 void setLineWidth(int width)
          Set the width, in pixels, of lines that are drawn.
 void setMissingValueIsError(boolean isError)
          If the parameter is true, then a missing data value (an empty cell or an undefined value for one of the expressions) is considered to be an error, and a JCMError is thrown when it is encountered.
 void setShowRegressionLine(boolean line)
          If the parameter is true, then a regression line for the data is drawn.
 void setTable(DataTableInput table)
          Specify the table from which the plotted data is to be taken.
 
Methods inherited from class net.sourceforge.webcompmath.draw.Drawable
getVisible, needsRedraw, setOwnerData, setVisible
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INTERCEPT

public static final int INTERCEPT
A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

See Also:
Constant Field Values

SLOPE

public static final int SLOPE
A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

See Also:
Constant Field Values

DATACT

public static final int DATACT
A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

See Also:
Constant Field Values

MISSINGCT

public static final int MISSINGCT
A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

See Also:
Constant Field Values

STANDARDERROR

public static final int STANDARDERROR
A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

See Also:
Constant Field Values

CORRELATION

public static final int CORRELATION
A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

See Also:
Constant Field Values
Constructor Detail

ScatterPlot

public ScatterPlot()
Default constructor. A data table, at least, must be specified before anything can be drawn. The first two columns of the table will be plotted (once a table is specified).


ScatterPlot

public ScatterPlot(DataTableInput table)
Create a scatter plot to plot data from the specified table. Initially, it is configured to plot data from the first two columns in the table.

Parameters:
table - table to use

ScatterPlot

public ScatterPlot(DataTableInput table,
                   int column1,
                   int column2)
Create a scatter plot to plot data from two specified columns in a table. Columns are numbered starting from zero.

Parameters:
table - table to use
column1 - column to use
column2 - column to use

ScatterPlot

public ScatterPlot(DataTableInput table,
                   Expression exp1,
                   Expression exp2)
Create scatter plot to plot specified expressions using data from a table. The expressions should include references to the column names from the table and can also refer to the special variable "rowNumber".

Parameters:
table - table to use
exp1 - expression to plot
exp2 - expression to plot
Method Detail

setTable

public void setTable(DataTableInput table)
Specify the table from which the plotted data is to be taken. The data from the first two columns of the table will be plotted, unless this is changed by calling setColumns() or setExpressions().

Parameters:
table - table to use

getTable

public DataTableInput getTable()
Get the DataTableInput from which the plotted data is obtained.

Returns:
table being used

setColumns

public void setColumns(int c1,
                       int c2)
Specify that the data to be plotted should be taken from the specified columns in the table. Note that columns are numbered starting from zero. The parameters must be within the range of column numbers in the table.

Parameters:
c1 - column to use
c2 - column to use

setExpressions

public void setExpressions(Expression exp1,
                           Expression exp2)
Specify the data for the the plot is to be obtained by evaluating the two expressions that are given as parameters. Both expressions should be non-null. The expressions can only be created by a Parser to which the variables from the table have been added by calling the method DataTableInput.addVariablesToParser(). The expressions are evaluated once for each row in the table to obtain the data to be ploted. They can include references to the column names from the table and to the special variable "rowNumber", which represents the number of the current row.

Parameters:
exp1 - expression to plot
exp2 - expression to plot

setShowRegressionLine

public void setShowRegressionLine(boolean line)
If the parameter is true, then a regression line for the data is drawn. The default value is true.

Parameters:
line - true or false

getShowRegressionLine

public boolean getShowRegressionLine()
The return value tells whether a regression line is drawn.

Returns:
true or false

setMissingValueIsError

public void setMissingValueIsError(boolean isError)
If the parameter is true, then a missing data value (an empty cell or an undefined value for one of the expressions) is considered to be an error, and a JCMError is thrown when it is encountered. If the value is false, missing data are ignored, and the value of MISSINGCT gives the number of points for which the data was missing. Note that invalid data (a cell that contains text that does not represent a number) is always considered to be an error. Also note that completely empty rows at the bottom of a DataTableInput are always ignored and are never considered to be an error. The default value of missingValueIsError is true, so that missing data is considered to be an error unless you turn off this option.

Parameters:
isError - true or false

getMissingValueIsError

public boolean getMissingValueIsError()
The return value indicates whether missing data is considered to be an error.

Returns:
true or false

setAutoChangeLimits

public void setAutoChangeLimits(boolean set)
If the parameter is true, then the limits on the CoordinateRect that contains this ScatterPlot are automatically adjusted whenever the data is recomputed. The default value is true.

Parameters:
set - true or false

getAutoChangeLimits

public boolean getAutoChangeLimits()
The return value indicates whether the limits on the CoordinateRect are automatically adjusted when the data is recomputed.

Returns:
true or false

getDataColor

public java.awt.Color getDataColor()
Get the color that is used to draw the points in the data.

Returns:
point color

setDataColor

public void setDataColor(java.awt.Color color)
Set the color that is used to draw the points in the data. The default value is red.

Parameters:
color - point color

getLineColor

public java.awt.Color getLineColor()
Get the color that is used to draw the regression line.

Returns:
line color

setLineColor

public void setLineColor(java.awt.Color color)
Set the color that is used to draw the regression line. The default value is black.

Parameters:
color - line color

setLineWidth

public void setLineWidth(int width)
Set the width, in pixels, of lines that are drawn. If set to 0, the thinnest possible line is drawn.

Parameters:
width - line width

getCrossLineWidth

public int getCrossLineWidth()
Get the width, in pixels, of lines that are drawn.

Returns:
line width

setCrossLineWidth

public void setCrossLineWidth(int width)
Set the width, in pixels, of lines for crosses.

Parameters:
width - line width

getLineWidth

public int getLineWidth()
Get the width, in pixels, of lines for crosses.

Returns:
line width

setCrossHalfSize

public void setCrossHalfSize(int size)
Set the width and height, in pixels, of crosses.

Parameters:
size - the size

getCrossHalfSize

public int getCrossHalfSize()
Get the width and height, in pixels, of crosses.

Returns:
the size

getValueObject

public Value getValueObject(int valueCode)
Get a Value that represents a statistic about the data that is shown in the scatter plot. The parameter specifies which statistic is represented. It can be one of the constants defined in this class: SLOPE (of regression line), INTERCEPT (y-intercept of regression line), DATACT (number of data points), MISSINGCT (number of missing data; alwasy zero if the missingValueIsError property is true), STANDARDERROR (standard error of regression line), and CORRELATION (correlation coefficient between first and second coordintes of data points).

Parameters:
valueCode - code for statistic to get
Returns:
statistic value

compute

public void compute()
Recompute the data for the scatter plot. This is generally not called directly.

Specified by:
compute in interface Computable

draw

public void draw(java.awt.Graphics g,
                 boolean coordsChanged)
Draw the data points and regression line. Not meant to be called directly.

Specified by:
draw in class Drawable
Parameters:
g - graphics context
coordsChanged - true or false