org.mbari.siam.moos.utils.chart.graph
Class DataSet

java.lang.Object
  extended by org.mbari.siam.moos.utils.chart.graph.DataSet
Direct Known Subclasses:
VectorSet

public class DataSet
extends java.lang.Object

This class is designed to hold the data to be plotted. It is to be used in conjunction with the Graph2D class and Axis class for plotting 2D graphs.

Version:
$Revision: 1.2 $, $Date: 2011/08/17 19:09:20 $
Author:
Leigh Brookshaw

Field Summary
 boolean clipping
          Boolean to control clipping of the data window.
protected  double[] data
          The array containing the actual data
protected  double dxmax
          The data X maximum.
protected  double dxmin
          The data X minimum.
protected  double dymax
          The data Y maximum.
protected  double dymin
          The data Y minimum.
 Graph2D g2d
          The Graphics canvas that is driving the whole show.
protected  int increment
          The amount to increment the data array when the append method is being used.
protected  double legend_dx
          The X data position of the data legend
protected  double legend_dy
          The Y data position of the data legend
protected  int legend_ix
          The X pixel position of the data legend
protected  int legend_iy
          The Y pixel position of the data legend
protected  int legend_length
          The length of the example line in the data legend.
protected  TextLine legend_text
          The legend text
protected  int length
          The number of data points stored in the data array
static int LINE
          A constant value flag used to specify that a straight line segment is to join the data points.
 java.awt.Color linecolor
          The color of the straight line segments
 int linestyle
          The linestyle to employ when joining the data points with straight line segments.
 int marker
          The index of the marker to use at the data points.
 java.awt.Color markercolor
          The marker color
 double markerscale
          The scaling factor for the marker.
static int NOLINE
          A constant value flag used to specify no straight line segment is to join the data points
protected  int stride
          The stride of the data.
 Axis xaxis
          The Axis object the X data is attached to.
 double xmax
          The current plottable X maximum of the data.
 double xmin
          The current plottable X minimum of the data.
protected  double xrange
          The X range of the clipped data
 Axis yaxis
          The Axis object the Y data is attached to.
 double ymax
          The current plottable Y maximum of the data.
 double ymin
          The current plottable Y minimum of the data.
protected  double yrange
          The Y range of the clipped data
 
Constructor Summary
DataSet()
          Instantiate an empty data set.
DataSet(double[] d, int n)
          Instantiate a DataSet with the parsed data.
DataSet(double[] d, int n, int s)
          Instantiate a DataSet with the parsed data.
DataSet(int stride)
          Instantiate an empty data set.
 
Method Summary
 void append(double[] d, int n)
          Append data to the data set.
 int dataPoints()
          Return the number of data points in the DataSet
 void delete(int start, int end)
          Delete data from the data set (start and end are inclusive).
 void deleteData()
          Delete all the data from the data set.
 void draw_data(java.awt.Graphics g, java.awt.Rectangle bounds)
          Draw the straight line segments and/or the markers at the data points.
protected  void draw_legend(java.awt.Graphics g, java.awt.Rectangle w)
          Draw a legend for this data set
protected  void draw_lines(java.awt.Graphics g, java.awt.Rectangle w)
          Draw into the data window the straight line segments joining the data points.
protected  void draw_markers(java.awt.Graphics g, java.awt.Rectangle w)
          Draw the markers.
 double[] getClosestPoint(double x, double y)
          Return the data point that is closest to the parsed (x,y) position
 double[] getPoint(int index)
          get the data point at the parsed index.
 double getXmax()
          return the data X maximum.
 double getXmin()
          return the data X minimum.
 double getYmax()
          return the data Y maximum.
 double getYmin()
          return the data Y minimum.
protected  boolean inside(double x, double y)
          Return true if the point (x,y) is inside the allowed data range.
 void legend(double x, double y, java.lang.String text)
          Define a data legend in the graph window
 void legend(int x, int y, java.lang.String text)
          Define a data legend in the graph window
 void legendColor(java.awt.Color c)
          Set the color for the legend text
 void legendFont(java.awt.Font f)
          Set the font to be used in the legend
protected  void range(int stride)
          Calculate the range of the data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOLINE

public static final int NOLINE
A constant value flag used to specify no straight line segment is to join the data points

See Also:
Constant Field Values

LINE

public static final int LINE
A constant value flag used to specify that a straight line segment is to join the data points.

See Also:
Constant Field Values

g2d

public Graph2D g2d
The Graphics canvas that is driving the whole show.

See Also:
Graph2D

linestyle

public int linestyle
The linestyle to employ when joining the data points with straight line segments. Currently only solid and no line are supported.


linecolor

public java.awt.Color linecolor
The color of the straight line segments


marker

public int marker
The index of the marker to use at the data points.

See Also:
Markers

markercolor

public java.awt.Color markercolor
The marker color


markerscale

public double markerscale
The scaling factor for the marker. Default value is 1.


xaxis

public Axis xaxis
The Axis object the X data is attached to. From the Axis object the scaling for the data can be derived.

See Also:
Axis

yaxis

public Axis yaxis
The Axis object the Y data is attached to.

See Also:
Axis

xmax

public double xmax
The current plottable X maximum of the data. This can be very different from true data X maximum. The data is clipped when plotted.


xmin

public double xmin
The current plottable X minimum of the data. This can be very different from true data X minimum. The data is clipped when plotted.


ymax

public double ymax
The current plottable Y maximum of the data. This can be very different from true data Y maximum. The data is clipped when plotted.


ymin

public double ymin
The current plottable Y minimum of the data. This can be very different from true data Y minimum. The data is clipped when plotted.


clipping

public boolean clipping
Boolean to control clipping of the data window. Default value is true, clip the data window.


dxmax

protected double dxmax
The data X maximum. Once the data is loaded this will never change.


dxmin

protected double dxmin
The data X minimum. Once the data is loaded this will never change.


dymax

protected double dymax
The data Y maximum. Once the data is loaded this will never change.


dymin

protected double dymin
The data Y minimum. Once the data is loaded this will never change.


data

protected double[] data
The array containing the actual data


length

protected int length
The number of data points stored in the data array


xrange

protected double xrange
The X range of the clipped data


yrange

protected double yrange
The Y range of the clipped data


legend_length

protected int legend_length
The length of the example line in the data legend.


legend_text

protected TextLine legend_text
The legend text


legend_ix

protected int legend_ix
The X pixel position of the data legend


legend_iy

protected int legend_iy
The Y pixel position of the data legend


legend_dx

protected double legend_dx
The X data position of the data legend


legend_dy

protected double legend_dy
The Y data position of the data legend


increment

protected int increment
The amount to increment the data array when the append method is being used.


stride

protected int stride
The stride of the data. For data pairs (x,y) the stride is 2

Constructor Detail

DataSet

public DataSet()
Instantiate an empty data set.


DataSet

public DataSet(int stride)
        throws java.lang.Exception
Instantiate an empty data set.

Parameters:
stride - the stride of the data set. The default stride is 2.
Throws:
java.lang.Exception

DataSet

public DataSet(double[] d,
               int n)
        throws java.lang.Exception
Instantiate a DataSet with the parsed data. Default stride is 2. The double array contains the data. The X data is expected in the even indices, the y data in the odd. The integer n is the number of data Points. This means that the length of the data array is 2*n.

Parameters:
d - Array containing the (x,y) data pairs.
n - Number of (x,y) data pairs in the array.
Throws:
java.lang.Exception - A Generic exception if it fails to load the parsed array into the class.

DataSet

public DataSet(double[] d,
               int n,
               int s)
        throws java.lang.Exception
Instantiate a DataSet with the parsed data. The double array contains the data. The X data is expected to be in indices i*stride where i=0,1,... The Y data is expected to be found in indices i*stride+1 where i=0,1,2... The integer n is the number of data Points. This means that the length of the data array is 2*stride.

Parameters:
d - Array containing the (x,y) data pairs.
n - Number of (x,y) data pairs in the array.
s - The stride of the data.
Throws:
java.lang.Exception - A Generic exception if it fails to load the parsed array into the class.
Method Detail

append

public void append(double[] d,
                   int n)
            throws java.lang.Exception
Append data to the data set.

Parameters:
d - Array containing (x,y) pairs to append
n - Number of (x,y) data pairs in the array.
Throws:
java.lang.Exception - A generic exception if it fails to load the parsed array into the class.

delete

public void delete(int start,
                   int end)
Delete data from the data set (start and end are inclusive). The first (x,y) pair in the data set start at index 0.

Parameters:
start - The start (x,y) pair index.
end - The end (x,y) pair index.

deleteData

public void deleteData()
Delete all the data from the data set.


draw_data

public void draw_data(java.awt.Graphics g,
                      java.awt.Rectangle bounds)
Draw the straight line segments and/or the markers at the data points. If this data has been attached to an Axis then scale the data based on the axis maximum/minimum otherwise scale using the data's maximum/minimum

Parameters:
g - Graphics state
bounds - The data window to draw into

getXmax

public double getXmax()
return the data X maximum.


getXmin

public double getXmin()
return the data X minimum.


getYmax

public double getYmax()
return the data Y maximum.


getYmin

public double getYmin()
return the data Y minimum.


legend

public void legend(int x,
                   int y,
                   java.lang.String text)
Define a data legend in the graph window

Parameters:
x - pixel position of the legend.
y - pixel position of the legend.
text - text to display in the legend

legend

public void legend(double x,
                   double y,
                   java.lang.String text)
Define a data legend in the graph window

Parameters:
x - data position of the legend.
y - data position of the legend.
text - text to display in the legend

legendFont

public void legendFont(java.awt.Font f)
Set the font to be used in the legend

Parameters:
f - font

legendColor

public void legendColor(java.awt.Color c)
Set the color for the legend text

Parameters:
c - color

dataPoints

public int dataPoints()
Return the number of data points in the DataSet

Returns:
number of (x,y0 points.

getPoint

public double[] getPoint(int index)
get the data point at the parsed index. The first (x,y) pair is at index 0.

Parameters:
index - Data point index
Returns:
array containing the (x,y) pair.

getClosestPoint

public double[] getClosestPoint(double x,
                                double y)
Return the data point that is closest to the parsed (x,y) position

Parameters:
x -
y - (x,y) position in data space.
Returns:
array containing the closest data point.

draw_lines

protected void draw_lines(java.awt.Graphics g,
                          java.awt.Rectangle w)
Draw into the data window the straight line segments joining the data points.

Parameters:
g - Graphics context
w - Data window

inside

protected boolean inside(double x,
                         double y)
Return true if the point (x,y) is inside the allowed data range.


draw_markers

protected void draw_markers(java.awt.Graphics g,
                            java.awt.Rectangle w)
Draw the markers. Only markers inside the specified range will be drawn. Also markers close the edge of the clipping region will be clipped.

Parameters:
g - Graphics context
w - data window
See Also:
Markers

draw_legend

protected void draw_legend(java.awt.Graphics g,
                           java.awt.Rectangle w)
Draw a legend for this data set

Parameters:
g - Graphics context
w - Data Window

range

protected void range(int stride)
Calculate the range of the data. This modifies dxmin,dxmax,dymin,dymax and xmin,xmax,ymin,ymax



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.