org.opensha.commons.gui.plot.jfreechart
Class DiscretizedFunctionXYDataSet

java.lang.Object
  extended by org.jfree.data.general.AbstractDataset
      extended by org.jfree.data.general.AbstractSeriesDataset
          extended by org.jfree.data.xy.AbstractXYDataset
              extended by org.opensha.commons.gui.plot.jfreechart.DiscretizedFunctionXYDataSet
All Implemented Interfaces:
ObjectInputValidation, Serializable, Cloneable, EventListener, org.jfree.data.general.Dataset, org.jfree.data.general.SeriesChangeListener, org.jfree.data.general.SeriesDataset, org.jfree.data.xy.IntervalXYDataset, org.jfree.data.xy.TableXYDataset, org.jfree.data.xy.XYDataset, Named

public class DiscretizedFunctionXYDataSet
extends org.jfree.data.xy.AbstractXYDataset
implements Named, org.jfree.data.xy.IntervalXYDataset, org.jfree.data.xy.TableXYDataset

Title: DiscretizedFunctionXYDataSet

Description: Wrapper for a DiscretizedFuncList. Implements XYDataSet so that it can be passed into the JRefinery Graphing Package

This class contains a pointer to a DiscretizedFuncList. It also implements an XYDataset which is JFreChart's interface that all datasets must implement so they can be passed to the graphing routines. This class transforms the DiscretizedFuncList data into the format as required by this interface. This also implements IntervalXYDataset to allow for Histograms plotting

Please consult the JFreeChart documentation for further information on XYDataSets.

Note: The FaultTraceXYDataSet and GriddedSurfaceXYDataSet are handled in exactly the same manner as for DiscretizedFunction.

Modified 7/21/2002 SWR: I mede this list more generic to handle any type of DiscretizedFunc that implements DiscretizedFuncAPI. Previously it only handled ArbDiscrFunctWithParams.

Modified 7/21/2002 SWR: (Still need to do) Made this list handle log-log plots by hiding zero values in x and y axis when choosen. If not JFreeeChart will throw an arithmatic exception.

Modified Gupta Brothers: Expanded the log-log capabilities.

Version:
1.2
Author:
Steven W. Rock, Gupta Brothers
See Also:
FaultTraceXYDataSet, DiscretizedFunctionXYDataSet, XY_DataSetList, Serialized Form

Field Summary
protected static String C
          Class name used for debug statements
protected static boolean D
          If true prints out debug statements
protected  XY_DataSetList functions
          Internal list of 2D Functions - indexed by name.
protected  ArrayList<org.jfree.data.general.DatasetChangeListener> listeners
          list of listeners for data changes
protected  boolean xLog
           
protected  boolean yLog
           
 
Constructor Summary
DiscretizedFunctionXYDataSet()
          no arg constructor -
 
Method Summary
 void addChangeListener(org.jfree.data.general.DatasetChangeListener listener)
          XYDatasetAPI- Registers an object for notification of changes to the dataset.
 void clear()
          Removes all DiscretizedFunction2Ds from the list, making it an empty list.
 DiscretizedFunctionXYDataSet deepClone()
          Returns a copy of this list, therefore any changes to the copy cannot affect this original list.
 boolean equals(Object list)
          Returns true if all the Functions in this list are equal.
 Number getEndX(int series, int item)
          Returns the ending X value for the specified series and item.
 double getEndXValue(int series, int item)
          Returns the ending X value for the specified series and item.
 Number getEndY(int series, int item)
          Returns the ending Y value for the specified series and item.
 double getEndYValue(int series, int item)
          Returns the ending Y value for the specified series and item.
 XY_DataSetList getFunctions()
          Returns the "wrapped" dataset, i.e.
 org.jfree.data.general.DatasetGroup getGroup()
          Returns the dataset group for the dataset.
 int getItemCount()
          TableXYDataset - Returns the number of items in the series.
 int getItemCount(int series)
          XYDataSetAPI - Returns the number of items in a series.
 String getName()
          Gets the name of the functions list
 int getSeriesCount()
          XYDataSetAPI - Returns the number of series in the dataset.
 Comparable getSeriesKey(int series)
          Returns the key for a series (this being the info String of the Series, which is unique for each series)
 String getSeriesName(int series)
          XYDataSetAPI - Returns the name of a series.
 Number getStartX(int series, int item)
          Returns the starting X value for the specified series and item.
 double getStartXValue(int series, int item)
          Returns the starting X value for the specified series and item.
 Number getStartY(int series, int item)
          Returns the starting Y value for the specified series and item.
 double getStartYValue(int series, int item)
          Returns the starting Y value for the specified series and item.
 Number getX(int series, int item)
          XYDatasetAPI - Returns the x-value for an item within a series.
 double getXValue(int series, int item)
          XYDatasetAPI - Returns the x-value for an item within a series.
 XY_DataSet getXYDataset(int series)
           
 Number getY(int series, int item)
          XYDatasetAPI - Returns the y-value for an item within a series.
 double getYValue(int series, int item)
          XYDatasetAPI - Returns the y-value for an item within a series.
protected static boolean isAdjustedIndexIfFirstXZero(XY_DataSet func, boolean xLog, boolean yLog)
          Very important function to handle log plotting.
 boolean isXLog()
           
 boolean isYLog()
           
 ListIterator<XY_DataSet> listIterator()
          Returns an iterator of all DiscretizedFunction2Ds in the list
 void removeChangeListener(org.jfree.data.general.DatasetChangeListener listener)
          XYDatasetAPI- Deregisters an object for notification of changes to the dataset.
 void setConvertZeroToMin(boolean zeroToMin)
          In case of Y-log, set' swhether you want to convert 0 value to minValue.
 void setConvertZeroToMin(boolean zeroMin, double minVal)
          In case of Y-log, you can specify the minValue so that 0 values on y - axis will be converted to this value.
 void setFunctions(XY_DataSetList functions)
          Sets the "wrapped" dataset, i.e.
 void setGroup(org.jfree.data.general.DatasetGroup group)
          Sets the dataset group for the dataset.
 void setName(String name)
          Sets the name of the functions list
 void setXLog(boolean xLog)
           
 void setYLog(boolean yLog)
           
 int size()
          Returns number of DiscretizedFunction2Ds in the list.
 
Methods inherited from class org.jfree.data.xy.AbstractXYDataset
getDomainOrder
 
Methods inherited from class org.jfree.data.general.AbstractSeriesDataset
indexOf, seriesChanged
 
Methods inherited from class org.jfree.data.general.AbstractDataset
clone, fireDatasetChanged, getNotify, hasListener, notifyListeners, setNotify, validateObject
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jfree.data.xy.XYDataset
getDomainOrder
 
Methods inherited from interface org.jfree.data.general.SeriesDataset
indexOf
 

Field Detail

C

protected static final String C
Class name used for debug statements

See Also:
Constant Field Values

D

protected static final boolean D
If true prints out debug statements

See Also:
Constant Field Values

yLog

protected boolean yLog

xLog

protected boolean xLog

functions

protected XY_DataSetList functions
Internal list of 2D Functions - indexed by name. This is the real data that is "wrapped" by this class.


listeners

protected ArrayList<org.jfree.data.general.DatasetChangeListener> listeners
list of listeners for data changes

Constructor Detail

DiscretizedFunctionXYDataSet

public DiscretizedFunctionXYDataSet()
no arg constructor -

Method Detail

isYLog

public boolean isYLog()

setYLog

public void setYLog(boolean yLog)

isXLog

public boolean isXLog()

setXLog

public void setXLog(boolean xLog)

setName

public void setName(String name)
Sets the name of the functions list


getName

public String getName()
Gets the name of the functions list

Specified by:
getName in interface Named

listIterator

public ListIterator<XY_DataSet> listIterator()
Returns an iterator of all DiscretizedFunction2Ds in the list


getSeriesCount

public int getSeriesCount()
XYDataSetAPI - Returns the number of series in the dataset. For a DiscretizedFuncList returns the number of functions in the list.

Specified by:
getSeriesCount in interface org.jfree.data.general.SeriesDataset
Specified by:
getSeriesCount in class org.jfree.data.general.AbstractSeriesDataset

getSeriesName

public String getSeriesName(int series)
XYDataSetAPI - Returns the name of a series. To make this name unique, info string of the particulare discretized function is returned at the name of that series. Typically the info string represents the key-value input paramters.


getItemCount

public int getItemCount(int series)
XYDataSetAPI - Returns the number of items in a series. The particular DiscretizedFuncAPI at the specified index ( series ), is obtained, then getNum() is called on that function. This number is reduced by one if the first x point is zero and xLog is choosen.

Specified by:
getItemCount in interface org.jfree.data.xy.XYDataset

getItemCount

public int getItemCount()
TableXYDataset - Returns the number of items in the series. This is needed to draw stacked bars. All the functions in the function list should have same number of X values and X-Values should also be same to draw bar charts. So, it returns the number of X-Values in first series of this list. It assumes that all other

Specified by:
getItemCount in interface org.jfree.data.xy.TableXYDataset

getXValue

public double getXValue(int series,
                        int item)
XYDatasetAPI - Returns the x-value for an item within a series.

The implementation is responsible for ensuring that the x-values are presented in ascending order. Note: If xlog is choosen, and first x point is zero the index is incresed to return the second point.

Specified by:
getXValue in interface org.jfree.data.xy.XYDataset
Overrides:
getXValue in class org.jfree.data.xy.AbstractXYDataset
Parameters:
series - The series (zero-based index).
item - The item (zero-based index).
Returns:
The x-value for an item within a series.

getXYDataset

public XY_DataSet getXYDataset(int series)

getYValue

public double getYValue(int series,
                        int item)
XYDatasetAPI - Returns the y-value for an item within a series.

Note: If xlog is choosen, and first x point is zero the index is incresed to return the second point.

Specified by:
getYValue in interface org.jfree.data.xy.XYDataset
Overrides:
getYValue in class org.jfree.data.xy.AbstractXYDataset
Parameters:
series - The series (zero-based index).
item - The item (zero-based index).
Returns:
The y-value for an item within a series.

isAdjustedIndexIfFirstXZero

protected static final boolean isAdjustedIndexIfFirstXZero(XY_DataSet func,
                                                           boolean xLog,
                                                           boolean yLog)
Very important function to handle log plotting. That is why this function is made final, so subclasses can't overide this functionality. This is an internal helper function used when getX() or getY()m numberPoints(), etc. are called.

This returns truw if the first point should be skipped. The criteria is based on if xLog and yLog are true, and the first point x or y values are zero. If these conditions are met, true is returned, false otherwise.


clear

public void clear()
Removes all DiscretizedFunction2Ds from the list, making it an empty list.


size

public int size()
Returns number of DiscretizedFunction2Ds in the list.


equals

public boolean equals(Object list)
Returns true if all the Functions in this list are equal. See DiscretizedFunctList.equals() for further details.

Overrides:
equals in class Object

deepClone

public DiscretizedFunctionXYDataSet deepClone()
Returns a copy of this list, therefore any changes to the copy cannot affect this original list. A deep clone() indicates that all the list fields are cloned, as well as all the fucntions in the list, and each point in each function. This is a very expensive operations if there are a large numbe of functions and/or points.


addChangeListener

public void addChangeListener(org.jfree.data.general.DatasetChangeListener listener)
XYDatasetAPI- Registers an object for notification of changes to the dataset.

Specified by:
addChangeListener in interface org.jfree.data.general.Dataset
Overrides:
addChangeListener in class org.jfree.data.general.AbstractDataset

removeChangeListener

public void removeChangeListener(org.jfree.data.general.DatasetChangeListener listener)
XYDatasetAPI- Deregisters an object for notification of changes to the dataset.

Specified by:
removeChangeListener in interface org.jfree.data.general.Dataset
Overrides:
removeChangeListener in class org.jfree.data.general.AbstractDataset

getFunctions

public XY_DataSetList getFunctions()
Returns the "wrapped" dataset, i.e. the DiscretizedFunctionList


setFunctions

public void setFunctions(XY_DataSetList functions)
Sets the "wrapped" dataset, i.e. the DiscretizedFunctionList


setConvertZeroToMin

public void setConvertZeroToMin(boolean zeroToMin)
In case of Y-log, set' swhether you want to convert 0 value to minValue.


setConvertZeroToMin

public void setConvertZeroToMin(boolean zeroMin,
                                double minVal)
In case of Y-log, you can specify the minValue so that 0 values on y - axis will be converted to this value.

Parameters:
zeroMin - true if you want to convert 0 values in Y-log to small value
minVal - value which will be returned if we have 0 on Y-axis in case of log

getGroup

public org.jfree.data.general.DatasetGroup getGroup()
Returns the dataset group for the dataset.

Specified by:
getGroup in interface org.jfree.data.general.Dataset
Overrides:
getGroup in class org.jfree.data.general.AbstractDataset
Returns:
the dataset group.

setGroup

public void setGroup(org.jfree.data.general.DatasetGroup group)
Sets the dataset group for the dataset.

Specified by:
setGroup in interface org.jfree.data.general.Dataset
Overrides:
setGroup in class org.jfree.data.general.AbstractDataset
Parameters:
group - the dataset group.

getStartXValue

public double getStartXValue(int series,
                             int item)
Returns the starting X value for the specified series and item. This is needed for drawing histograms

Specified by:
getStartXValue in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the starting X value for the specified series and item.

getEndXValue

public double getEndXValue(int series,
                           int item)
Returns the ending X value for the specified series and item. This is needed for drawing histograms

Specified by:
getEndXValue in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the ending X value for the specified series and item.

getStartYValue

public double getStartYValue(int series,
                             int item)
Returns the starting Y value for the specified series and item. This is needed for drawing histograms

Specified by:
getStartYValue in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
starting Y value for the specified series and item.

getEndYValue

public double getEndYValue(int series,
                           int item)
Returns the ending Y value for the specified series and item. This is needed for drawing histograms

Specified by:
getEndYValue in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the ending Y value for the specified series and item.

getEndX

public Number getEndX(int series,
                      int item)
Returns the ending X value for the specified series and item. This is needed for drawing histograms

Specified by:
getEndX in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the ending X value for the specified series and item.

getEndY

public Number getEndY(int series,
                      int item)
Returns the ending Y value for the specified series and item. This is needed for drawing histograms

Specified by:
getEndY in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the ending Y value for the specified series and item.

getStartX

public Number getStartX(int series,
                        int item)
Returns the starting X value for the specified series and item. This is needed for drawing histograms

Specified by:
getStartX in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the starting X value for the specified series and item.

getStartY

public Number getStartY(int series,
                        int item)
Returns the starting Y value for the specified series and item. This is needed for drawing histograms

Specified by:
getStartY in interface org.jfree.data.xy.IntervalXYDataset
Parameters:
series - the series (zero-based index).
item - the item within a series (zero-based index).
Returns:
the starting Y value for the specified series and item.

getX

public Number getX(int series,
                   int item)
XYDatasetAPI - Returns the x-value for an item within a series.

The implementation is responsible for ensuring that the x-values are presented in ascending order. Note: If xlog is choosen, and first x point is zero the index is incresed to return the second point.

Specified by:
getX in interface org.jfree.data.xy.XYDataset
Parameters:
series - The series (zero-based index).
item - The item (zero-based index).
Returns:
The x-value for an item within a series.

getY

public Number getY(int series,
                   int item)
XYDatasetAPI - Returns the y-value for an item within a series.

The implementation is responsible for ensuring that the x-values are presented in ascending order. Note: If ylog is choosen, and first y point is zero the index is incresed to return the second point.

Specified by:
getY in interface org.jfree.data.xy.XYDataset
Parameters:
series - The series (zero-based index).
item - The item (zero-based index).
Returns:
The y-value for an item within a series.

getSeriesKey

public Comparable getSeriesKey(int series)
Returns the key for a series (this being the info String of the Series, which is unique for each series)

Specified by:
getSeriesKey in interface org.jfree.data.general.SeriesDataset
Specified by:
getSeriesKey in class org.jfree.data.general.AbstractSeriesDataset
Parameters:
series - the series index (in the range 0 to getSeriesCount() - 1).
Returns:
The key for the series.