com.approximatrix.charting.model
Class DefaultChartDataModel

java.lang.Object
  extended by com.approximatrix.charting.model.AbstractChartDataModel
      extended by com.approximatrix.charting.model.DefaultChartDataModel
All Implemented Interfaces:
ChartDataModel
Direct Known Subclasses:
EditableChartDataModel

public class DefaultChartDataModel
extends AbstractChartDataModel

Implements a default ChartModel. It uses a DataSet[] and the columns are numeric. It's purely read-only.

Version:
1.0
Author:
mueller

Field Summary
protected  java.util.TreeSet columnSet
          The sorted x-axis values used for calculating the constraints.
protected  ChartDataModelConstraints constraints1
          The constraints for the first and second y-axes.
protected  ChartDataModelConstraints constraints2
          The constraints for the first and second y-axes.
protected  java.util.ArrayList data
          The DataSet list.
protected  java.util.HashMap valuesbyaxis
          A HashMap containing the ordered data used for calculating the constraints.
 
Fields inherited from class com.approximatrix.charting.model.AbstractChartDataModel
autoscale, listener, manualscale, maxcolumn, maxvalue, mincolumn, minvalue
 
Constructor Summary
DefaultChartDataModel()
          Creates a new empty DefaultChartDataModel.
DefaultChartDataModel(DataSet[] ds)
          Creates a new DefaultChartDataModel using the given array of DataSets, effectively enabling the creation of DataModels with differently sized DataSets.
DefaultChartDataModel(double[][] data, double[] columns, java.lang.String[] rows)
          Creates new DefaultChartDataModel.
DefaultChartDataModel(int[][] data, double[] columns, java.lang.String[] rows)
          Creates new DefaultChartDataModel.
DefaultChartDataModel(java.lang.Number[][] data, double[] columns, java.lang.String[] rows)
          Creates new DefaultChartDataModel with the default axis binding.
 
Method Summary
 int getAxisBinding(int set)
          Returns the axis binding for a DataSet
 ChartDataModelConstraints getChartDataModelConstraints(int axis)
          Returns a ChartDataModelConstraints Object for a given axis.
 java.lang.Class getColumnClass()
          Returns the class of the column values.
 java.lang.Object getColumnValueAt(int col)
          Use getColumnValue(int set, int col) instead, because DefaultChartDataModel can contain DataSets with different lengths and column values.
 java.lang.Object getColumnValueAt(int set, int col)
          Returns a specific column value.
 int getDataSetLength(int set)
          Returns the length of a certain dataset.
 java.lang.String getDataSetName(int set)
          Returns the title of the DataSet.
 int getDataSetNumber()
          Returns the total amount of datasets.
protected  double getFirstColumnValue()
          Returns the first ordered column value for use by the ChartDataModelConstraints.
protected  double getLastColumnValue()
          Returns the last ordered column value for use by the ChartDataModelConstraints.
protected  java.util.TreeSet getOrderedValues(int axis)
          Returns an ordered set of all data values for the specified axis.
 java.lang.Number getValueAt(int set, int index)
          Returns the Value in a specific dataset at a certain index.
 boolean isColumnNumeric()
          Returns true if the columns are numeric.
 void setChartDataModelConstraints(int axis, ChartDataModelConstraints constraints)
          Sets the ChartDataModelConstraints object for the given axis binding.
protected  void trimSet(java.util.TreeSet s)
          Removes infinite and NaN values from a TreeSet.
 
Methods inherited from class com.approximatrix.charting.model.AbstractChartDataModel
addChartDataModelListener, equals, fireChartDataModelChangedEvent, getManualMaximumColumnValue, getManualMaximumValue, getManualMinimumColumnValue, getManualMinimumValue, isAutoScale, isManualScale, removeChartDataModelListener, setAutoScale, setAxisBinding, setManualScale, setMaximumColumnValue, setMaximumValue, setMinimumColumnValue, setMinimumValue, setValueAt
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

columnSet

protected java.util.TreeSet columnSet
The sorted x-axis values used for calculating the constraints.


data

protected java.util.ArrayList data
The DataSet list.


valuesbyaxis

protected java.util.HashMap valuesbyaxis
A HashMap containing the ordered data used for calculating the constraints.


constraints1

protected ChartDataModelConstraints constraints1
The constraints for the first and second y-axes.


constraints2

protected ChartDataModelConstraints constraints2
The constraints for the first and second y-axes.

Constructor Detail

DefaultChartDataModel

public DefaultChartDataModel()
Creates a new empty DefaultChartDataModel.


DefaultChartDataModel

public DefaultChartDataModel(java.lang.Number[][] data,
                             double[] columns,
                             java.lang.String[] rows)
Creates new DefaultChartDataModel with the default axis binding.

Parameters:
data - the array of values. The first index specifies the datasets, the last one is the value index.
columns - the array of x-axis values. The length of the datasets and the length of the column should be equal and the columns should be ordered.
rows - the array of DataSet titles. It has to have the same length as the number of DataSets.

DefaultChartDataModel

public DefaultChartDataModel(int[][] data,
                             double[] columns,
                             java.lang.String[] rows)
Creates new DefaultChartDataModel.

Parameters:
data - the array of values. The first index specifies the datasets, the last one is the value index.
columns - the array of x-axis values. The length of the datasets and the length of the column should be equal and the columns should be ordered.
rows - the array of DataSet titles. It has to have the same length as the number of DataSets.

DefaultChartDataModel

public DefaultChartDataModel(double[][] data,
                             double[] columns,
                             java.lang.String[] rows)
Creates new DefaultChartDataModel.

Parameters:
data - the array of values. The first index specifies the datasets, the last one is the value index.
columns - the array of x-axis values. The length of the datasets and the length of the column should be equal and the columns should be ordered.
rows - the array of DataSet titles. It has to have the same length as the number of DataSets.

DefaultChartDataModel

public DefaultChartDataModel(DataSet[] ds)
Creates a new DefaultChartDataModel using the given array of DataSets, effectively enabling the creation of DataModels with differently sized DataSets.

Parameters:
ds - the array of DataSets to be used.
Method Detail

getDataSetLength

public int getDataSetLength(int set)
Returns the length of a certain dataset.

Parameters:
set - the DataSet
Returns:
the length of the DataSet

getDataSetNumber

public int getDataSetNumber()
Returns the total amount of datasets.

Returns:
the amount of DataSets

getDataSetName

public java.lang.String getDataSetName(int set)
Returns the title of the DataSet. This is the number of the DataSet per default.

Specified by:
getDataSetName in interface ChartDataModel
Overrides:
getDataSetName in class AbstractChartDataModel
Parameters:
set - the DataSet index
Returns:
the String title

getAxisBinding

public int getAxisBinding(int set)
Returns the axis binding for a DataSet

Specified by:
getAxisBinding in interface ChartDataModel
Overrides:
getAxisBinding in class AbstractChartDataModel
Parameters:
set - the DataSet index
Returns:
an axis binding constant

isColumnNumeric

public boolean isColumnNumeric()
Returns true if the columns are numeric.

Specified by:
isColumnNumeric in interface ChartDataModel
Overrides:
isColumnNumeric in class AbstractChartDataModel
Returns:
true

getColumnClass

public java.lang.Class getColumnClass()
Returns the class of the column values.

Specified by:
getColumnClass in interface ChartDataModel
Overrides:
getColumnClass in class AbstractChartDataModel
Returns:
Double.class

getValueAt

public java.lang.Number getValueAt(int set,
                                   int index)
Returns the Value in a specific dataset at a certain index. *

Parameters:
set - the DataSet index
index - the value index
Returns:
the Number value at the specified position

getColumnValueAt

public java.lang.Object getColumnValueAt(int col)
Use getColumnValue(int set, int col) instead, because DefaultChartDataModel can contain DataSets with different lengths and column values.

Parameters:
col - the column index
Returns:
null

getColumnValueAt

public java.lang.Object getColumnValueAt(int set,
                                         int col)
Returns a specific column value.

Parameters:
col - the column index
set - the DataSet of which the column value is desired
Returns:
the column value or null if the column doesn't exist.

getChartDataModelConstraints

public ChartDataModelConstraints getChartDataModelConstraints(int axis)
Returns a ChartDataModelConstraints Object for a given axis. This way, there are different constraints for the first and for the second y-axis. If the model is empty, the maximum values are 1 and the minimum values are 0, thus enabling proper rendering.

Parameters:
axis - the axis constant.
Returns:
a ChartDataModelConstraints object with the constraints for the specified y-axis.

setChartDataModelConstraints

public void setChartDataModelConstraints(int axis,
                                         ChartDataModelConstraints constraints)
Sets the ChartDataModelConstraints object for the given axis binding.

Parameters:
axis - the Axis constant
constraints - the ChartDataModelConstraints object

trimSet

protected void trimSet(java.util.TreeSet s)
Removes infinite and NaN values from a TreeSet. Called with the TreeSet containing all values. If asymptotic functions are plotted, infinite values are the max / min values, resulting in bogus point-to-pixel rations. Therefore, these values are omitted from these calculations.


getOrderedValues

protected java.util.TreeSet getOrderedValues(int axis)
Returns an ordered set of all data values for the specified axis. This is called by the ChartDataModelConstraints classes.

Specified by:
getOrderedValues in class AbstractChartDataModel

getFirstColumnValue

protected double getFirstColumnValue()
Returns the first ordered column value for use by the ChartDataModelConstraints.

Specified by:
getFirstColumnValue in class AbstractChartDataModel

getLastColumnValue

protected double getLastColumnValue()
Returns the last ordered column value for use by the ChartDataModelConstraints.

Specified by:
getLastColumnValue in class AbstractChartDataModel