lt.monarch.chart.models
Class ChartDataModel

java.lang.Object
  extended by lt.monarch.chart.models.AbstractDataModel
      extended by lt.monarch.chart.models.ChartDataModel
All Implemented Interfaces:
java.io.Serializable, ArrayDataModel, DataModel, MatrixDataModel

public class ChartDataModel
extends AbstractDataModel

If you add collections to the data model, be sure that it subclasses List. Otherwise set operation won't be performed, since there is no set() methods in a Collection class.
In the matrix case the data point is specified by row and column. Note that column in some cases are referred to the different type of values in the data model, such as x, y, z and etc. If data contains only one column, it may contain a matrix inside of it, which can be accessed through indexes row and column. Model can also contain multiple matrixes, for KEY and VALUES, e.i. multiple data cubes.

BE WARE! When passing arrays to the data model, the arrays are not copied but stored, so if you modify the array outside data model, the array in the data model also will change. The same is with the inner collections (not the ones specifying data column type).

See Also:
Serialized Form

Field Summary
Modifier and Type Field and Description
 
Fields inherited from class lt.monarch.chart.models.AbstractDataModel
columns, data, dataListeners, dimensions, suspended
 
Constructor Summary
Constructor and Description
ChartDataModel()
          Default chart data model constructor, which creates empty data model.
ChartDataModel(java.util.Collection<?> data)
          Chart data model constructor.
ChartDataModel(java.util.Collection<?>[] data)
          Chart data model constructor, which allows to add collection array to the model.
ChartDataModel(DataColumnType[] valType, java.util.Collection<?> data)
          Chart data model constructor.
ChartDataModel(DataColumnType[] valType, java.util.Collection<?>[] data)
          Chart data model constructor, which allows to add collection array to the model.
ChartDataModel(DataColumnType[] valType, java.lang.Object[][] data)
          Chart data model constructor, which adds data array to the model.
ChartDataModel(int size)
          Deprecated.  
ChartDataModel(java.lang.Object[][] data)
          Chart data model constructor, which adds data array to the model.
 
Method Summary
Modifier and Type Method and Description
 void add(DataColumnType[] valType, java.lang.Object[] values)
          Adds one data element to the data model.
 void add(java.lang.Object[] values)
          Adds one data element to the data model.
 void addKeyValues(java.lang.Object key, java.lang.Object[] values)
          Adds single key object with associated array of values to data model.
 boolean containsKey(java.lang.Object key)
          Checks if data model contains given key.
protected  void finalize()
           
 int getPointCount()
          Counts the data model size.
 int getPointCount(MatrixDimensions dimension)
          Gets the count of point in the specified dimension.
 java.lang.Object getValueAt(DataColumnType valType, int index)
          Gets the data value at the specified point.
 java.lang.Object getValueAt(DataColumnType valType, int row, int column)
          Get value at specified point.
 boolean hasColumn(DataColumnType columnType)
          Returns flag showing if this data model contains column of the given type.
 void remove(int index)
          Removes data point.
 void removeAll()
          Removes all data from the data model
 void setValueAt(DataColumnType valType, int row, int column, java.lang.Object value)
          Sets value at the specified point.
 void setValueAt(DataColumnType valType, int index, java.lang.Object value)
          Sets value at specified point.
 
Methods inherited from class lt.monarch.chart.models.AbstractDataModel
addColumn, addListener, castToArray, castToMatrix, dispose, fireDataChanged, getAddressDimensions, getColumns, getValuesInPoint, removeListener, resumeListeners, setColumns, suspendListeners
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartDataModel

public ChartDataModel()
Default chart data model constructor, which creates empty data model. Use this constructor if the data model is empty.


ChartDataModel

@Deprecated
public ChartDataModel(int size)
Deprecated. 

Use ChartDataModel() constructor instead


ChartDataModel

public ChartDataModel(DataColumnType[] valType,
                      java.lang.Object[][] data)
Chart data model constructor, which adds data array to the model. Data in the array is like this:
 data[0] = new Object[]{"1999", "2000"};
 data[1] = new Object[]{20d, 50d};
 array = new ChartDataModel(new DataValueType[] {DataValueType.KEY, DataValueType.VALUE}, data);
When adding matrix to data model you must add it in three dimensional array, like this:
 Double m[][][] = new Double[1][L][L];
 for (int i = 0; i < L; i++)
 {
   for (int j = 0; j < L; j++)
   {
     m[0][i][j] = new Double(Math.random());
   }
 }
 matrix = new ChartDataModel(new DataValueType[] { DataValueType.KEY }, m);

Parameters:
valType - value type array, which shows in what sequence the data from the array should be added to the model
data - data array which has to be added to the model

ChartDataModel

public ChartDataModel(java.lang.Object[][] data)
Chart data model constructor, which adds data array to the model. Value types are in ascending order as the columns of the data.

The count of data columns is determined from the length of the data array. Data in the array is like this:

 data[0] = new Object[]{"1999", "2000"};
 data[1] = new Object[]{20d, 50d};
 array = new ChartDataModel(data);
When adding matrix to data model you must add it in three dimensional array, like this:
 Double m[][][] = new Double[1][L][L];
 for (int i = 0; i < L; i++)
 {
   for (int j = 0; j < L; j++)
   {
     m[0][i][j] = new Double(Math.random());
   }
 }
 matrix = new ChartDataModel(m);

Parameters:
data - data array which has to be added to the model

ChartDataModel

public ChartDataModel(java.util.Collection<?>[] data)
Chart data model constructor, which allows to add collection array to the model. Each collection in the array corresponds to a different column in the data model. Data in the collection array is like this:
 ArrayList list1 = new ArrayList();
 list1.add("1999");
 list1.add("2000");
 data[0] = list1;
 ArrayList list2 = new ArrayList();
 list2.add(59d);
 list2.add(89d);
 data[1] = list2;
 array = new ChartDataModel(data);
or
 ArrayList[] list = new ArrayList[2];
 Double[] x = new Double[]{ 5d, 15d, 30d };
 Double[] y = new Double[]{ 10d, 20d, 0d };
 
 ArrayList xValues = new ArrayList();
 Collections.addAll(xValues, x);

 ArrayList yValues = new ArrayList();
 Collections.addAll(yValues, y);
 list[0] = xValues;
 list[1] = yValues;
 array = new ChartDataModel(list);
For matrix data model it should look like this:
 int L = 3;
 ArrayList> m[] = new ArrayList[1];
 m[0] = new ArrayList>();
 for (int i = 0; i < L; i++)
 {
   m[0].add(new ArrayList());
   for (int j = 0; j < L; j++)
   {
     m[0].get(i).add(new Double((i + 1) * 10 + j + 1));
   }
 }
 matrix = new ChartDataModel(m);

Parameters:
data - data collection array which has to be added to the model

ChartDataModel

public ChartDataModel(DataColumnType[] valType,
                      java.util.Collection<?>[] data)
Chart data model constructor, which allows to add collection array to the model. Each collection in the array corresponds to a different column in the data model. Since the order of column types are not specified in this constructor, so it will be placed in the same order as it is provided.

Data in the collection array is like this:

 ArrayList list1 = new ArrayList();
 list1.add("1999");
 list1.add("2000");
 data[0] = list1;
 ArrayList list2 = new ArrayList();
 list2.add(59d);
 list2.add(89d);
 data[1] = list2;
 array = new ChartDataModel(new DataValueType[] { DataValueType.KEY, DataValueType.VALUE }, data);
or
 ArrayList[] list = new ArrayList[2];
 Double[] x = new Double[]{ 5d, 15d, 30d };
 Double[] y = new Double[]{ 10d, 20d, 0d };
        
 ArrayList xValues = new  ArrayList();
 Collections.addAll(xValues, x);
        
 ArrayList yValues = new  ArrayList();
 Collections.addAll(yValues, y);
 list[0] = xValues;
 list[1] = yValues;

 array = new ChartDataModel(new DataValueType[] { DataValueType.KEY, DataValueType.VALUE },list);
For the matrix the sample code looks like this:
 int L = 3;
 ArrayList> m[] = new ArrayList[1];
 m[0] = new ArrayList>();
 for (int i = 0; i < L; i++)
 {
  m[0].add(new ArrayList());
  for (int j = 0; j < L; j++)
  {
   m[0].get(i).add(new Double((i + 1) * 10 + j + 1));
  }
 }
 matrix = new ChartDataModel(new DataValueType[] {DataValueType.KEY },m);

Parameters:
valType - value type array, which shows in what sequence the data from the collection array should be added to the model.
data - data collection array which has to be added to the model.

ChartDataModel

public ChartDataModel(DataColumnType[] valType,
                      java.util.Collection<?> data)
Chart data model constructor. It allows to add Collection of collections or arrays. Each sub-array or sub-collection of the primary collection is the row from the data model (not the column of one data type), for example:
 ArrayList list = new ArrayList();
 Double[] x = new Double[] { 5d, 15d, 30d };
 Double[] y = new Double[] { 10d, 20d, 0d };

 list.add(x);
 list.add(y);

 array = new ChartDataModel(new DataValueType[] { DataValueType.KEY, DataValueType.VALUE }, list);
For the matrix sample code is this:
 int L = 3;
 ArrayList>> m = new ArrayList>>();
 m.add(new ArrayList>());
 for (int i = 0; i < L; i++)
 {
  m.get(0).add(new ArrayList());
  for (int j = 0; j < L; j++)
  {
   m.get(0).get(i).add(new Double((i + 1) * 10 + j + 1));
  }
 }
 matrix = new ChartDataModel(new DataValueType[] { DataValueType.KEY }, m);

Parameters:
valType - value type array, which shows in what sequence the data from the collection should be added to the model.
data - data collection which has to be added to the model.

ChartDataModel

public ChartDataModel(java.util.Collection<?> data)
Chart data model constructor. It allows to add Collection of collections or arrays. Each sub array or sub-collection of the primary collection is the row from the data model (not the column of one data type), for example:
 ArrayList list = new ArrayList();
 Double[] x = new Double[] { 5d, 15d, 30d };
 Double[] y = new Double[] { 10d, 20d, 0d };

 list.add(x);
 list.add(y);
 array = new ChartDataModel(list);
Matrix is created like this:
 int L = 3;
 ArrayList>> m = new ArrayList>>();
 m.add(new ArrayList>());
 for (int i = 0; i < L; i++)
 {
  m.get(0).add(new ArrayList());
  for (int j = 0; j < L; j++)
  {
   m.get(0).get(i).add(new Double((i + 1) * 10 + j + 1));
  }
 }
 matrix = new ChartDataModel(m);
Since the order of the data columns is not specified in this constructor the data will be placed in columns in ascending order.

The length of sub-arrays or size of sub-collections must be the same, since the count of columns is determined from the sub-array or sub-collection size.

Use DataSetConverter to convert table-like arrays and collections to the model representation

Parameters:
data - data collection which has to be added to the model
Method Detail

getPointCount

public int getPointCount(MatrixDimensions dimension)
Description copied from interface: MatrixDataModel
Gets the count of point in the specified dimension. If dimension is ROWS then it returns the count of rows, if COLUMNS then count of columns.

Parameters:
dimension - dimension of the matrix
Returns:
count of either rows or columns

getValueAt

public java.lang.Object getValueAt(DataColumnType valType,
                                   int row,
                                   int column)
Description copied from interface: MatrixDataModel
Get value at specified point.

Parameters:
valType - data column type
row - row of the matrix
column - column of the matrix
Returns:
matrix element value

getValueAt

public java.lang.Object getValueAt(DataColumnType valType,
                                   int index)
Description copied from interface: ArrayDataModel
Gets the data value at the specified point.

Parameters:
valType - data column type (KEY, VALUE and etc.)
index - data value index in the data model
Returns:
requested data value

getPointCount

public int getPointCount()
Description copied from interface: ArrayDataModel
Counts the data model size.

Returns:
data model size.

setValueAt

public void setValueAt(DataColumnType valType,
                       int index,
                       java.lang.Object value)
Description copied from interface: ArrayDataModel
Sets value at specified point.

Parameters:
valType - data column type (KEY, VALUE and etc.)
index - data value index in the data model
value - value to set

setValueAt

public void setValueAt(DataColumnType valType,
                       int row,
                       int column,
                       java.lang.Object value)
Description copied from interface: MatrixDataModel
Sets value at the specified point.

Parameters:
valType - data column type
row - row number of the matrix
column - column number of the matrix
value - value to set to the specified point

add

public void add(java.lang.Object[] values)
Adds one data element to the data model. Adding is performed only in array dimension. If you wish to add a matrix, you will have to add whole 2D matrix here. Of course, you can add the row to the matrix as well.

Parameters:
values - data values in

addKeyValues

public void addKeyValues(java.lang.Object key,
                         java.lang.Object[] values)
Adds single key object with associated array of values to data model. Array of values will be added as a list.

Parameters:
key - key
values - array of values

containsKey

public boolean containsKey(java.lang.Object key)
Checks if data model contains given key.

Parameters:
key -
Returns:
true if data model contains given key

add

public void add(DataColumnType[] valType,
                java.lang.Object[] values)
Adds one data element to the data model. Adding is performed only in array dimension. If you wish to add an matrix, you will have to add whole 2D matrix here indicating KEY column. Of course, you can add the row to the matrix as well.

Parameters:
values - data values in
valType - array specifying order of values in the values array.

remove

public void remove(int index)
Removes data point. If you use remove on matrix, the row of the matrix will be removed.

Parameters:
index - index of data point to remove

removeAll

public void removeAll()
Removes all data from the data model


finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

hasColumn

public boolean hasColumn(DataColumnType columnType)
Description copied from interface: DataModel
Returns flag showing if this data model contains column of the given type.

Parameters:
columnType - data column type
Returns:
true if column with the given type exists.