Class ScatterPlot

java.lang.Object
edu.hws.jcm.draw.Drawable
edu.hws.jcm.draw.ScatterPlot
All Implemented Interfaces:
Computable, Serializable

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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
    static final int
    A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
    static final int
    A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
    static final int
    A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
    static final int
    A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.
    static final int
    A constant that can be used in the getValueObject() method to indicate which statistic the object should represent.

    Fields inherited from class edu.hws.jcm.draw.Drawable

    canvas, coords
  • Constructor Summary

    Constructors
    Constructor
    Description
    Default constructor.
    Create a scatter plot to plot data from the specified table.
    ScatterPlot(DataTableInput table, int column1, int column2)
    Create a scatter plot to plot data from two specified columns in a table.
    Create scatter plot to plot specified expressions using data from a table.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Recompute the data for the scatter plot.
    void
    draw(Graphics g, boolean coordsChanged)
    Draw the data points and regression line.
    boolean
    The return value indicates whether the limits on the CoordinateRect are automatically adjusted when the data is recomputed.
    Get the color that is used to draw the points in the data.
    Get the color that is used to draw the regression line.
    boolean
    The return value indicates whether missing data is considered to be an error.
    boolean
    The return value tells whether a regression line is drawn.
    Get the DataTableInput from which the plotted data is obtained.
    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
    Set the color that is used to draw the points in the data.
    void
    Specify the data for the the plot is to be obtained by evaluating the two expressions that are given as parameters.
    void
    Set the color that is used to draw the regression line.
    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
    Specify the table from which the plotted data is to be taken.

    Methods inherited from class edu.hws.jcm.draw.Drawable

    getVisible, needsRedraw, setOwnerData, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
  • Constructor Details

    • 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.
    • 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.
    • 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".
  • Method Details

    • 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().
    • getTable

      public DataTableInput getTable()
      Get the DataTableInput from which the plotted data is obtained.
    • 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.
    • 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.
    • 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.
    • getShowRegressionLine

      public boolean getShowRegressionLine()
      The return value tells whether a regression line is drawn.
    • 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.
    • getMissingValueIsError

      public boolean getMissingValueIsError()
      The return value indicates whether missing data is considered to be an error.
    • 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.
    • getAutoChangeLimits

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

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

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

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

      public void setLineColor(Color color)
      Set the color that is used to draw the regression line. The default value is black.
    • 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).
    • 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(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 - The graphics context in which the Drawble is to be drawn. (The drawing can change the color in g, but should not permanently change font, painting mode, etc. Thus, every drawable is responsible for setting the color it wants to use.)
      coordsChanged - Indicates whether the CoordinateRect has changed.