com.objectplanet.chart
Class ChartData

java.lang.Object
  extended by com.objectplanet.chart.ChartData
All Implemented Interfaces:
java.io.Serializable

public class ChartData
extends java.lang.Object
implements java.io.Serializable

This class contains the data for one or more charts. A chart will render it's image using the data from this class. By letting several different charts share one data object, the data can be rendered in different styles.

Author:
Bjorn J. Kvande.
See Also:
Serialized Form

Constructor Summary
ChartData(int seriesCount, int sampleCount)
          Creates a new empty chart data with the specified number of series and samples.
 
Method Summary
 int appendSample(int serie, ChartSample sample, boolean makeSpace)
          Appends a sample to the given series.
 int appendSampleLabel(java.lang.String label, boolean makeSpace)
          Appends a sample labels If makeSpace is set to false, and all the sample labels are filled up, they will be scrolled to the left, with the left most label deleted.
 int appendSampleValue(int serie, double value, boolean makeSpace)
          Appends a value to the given series.
 double getMaxValue(int serie)
          Gets the largest value in the specified data series.
 double getMinValue(int serie)
          Gets the smallest value in the specified data series.
 ChartSample getSample(int serie, int index)
          Gets the specified sample.
 ChartSample getSample(java.lang.Object key)
          Gets the sample with the specified key.
 int getSampleCount()
          Gets the number of samples.
 java.lang.String getSampleLabel(int index)
          Gets the specified sample label.
 java.lang.String[] getSampleLabels()
          Gets the sample labels.
 ChartSample[] getSamples(int serie)
          Gets the samples for the specified serie.
 double getSampleValue(int serie, int index)
          Gets the specified sample value.
 double[] getSampleValues(int serie)
          Gets the sample values for the specified serie.
 int getSeriesCount()
          Gets the number of series.
 java.lang.String getSeriesLabel(int serie)
          Gets the specified series label.
 java.lang.String[] getSeriesLabels()
          Gets the series labels.
 boolean hasChangedSince(long time)
          Checks if the data has been changed since the specified time.
 boolean isSelected(int serie, int sample)
          Checks if a sample is selected.
 void setSample(int serie, int index, ChartSample sample)
          Sets the specified sample.
 void setSampleCount(int count)
          Sets the number of samples.
 void setSampleLabel(int index, java.lang.String label)
          Sets the specified sample label.
 void setSampleLabels(java.lang.String[] labels)
          Sets the sample labels.
 void setSamples(int serie, ChartSample[] samples)
          Sets the samples for the specified series.
 void setSampleValue(int serie, int index, double value)
          Sets the specified sample value.
 void setSampleValues(int serie, double[] values)
          Sets the sample values for the specified series.
 void setSelection(int serie, int sample, boolean selected)
          Marks a sample as selected or deselected.
 void setSeriesCount(int count)
          Sets the number of series.
 void setSeriesLabel(int serie, java.lang.String label)
          Sets the specified series label.
 void setSeriesLabels(java.lang.String[] labels)
          Sets the series labels.
 java.lang.String toString()
          Returns a string with the number of series and samples.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ChartData

public ChartData(int seriesCount,
                 int sampleCount)
Creates a new empty chart data with the specified number of series and samples.

Parameters:
seriesCount - The number of series to use.
sampleCount - The number of sampels to use.
Method Detail

appendSample

public int appendSample(int serie,
                        ChartSample sample,
                        boolean makeSpace)
Appends a sample to the given series. If the number of samples is less than the sample count, the new sample is added after the last sample. If the number of samples in the series is the same as the sample count (series is full), the addition will depend on the makeSpace parameter.

If the makeSpace parameter is set to false, all the current samples will shift to the left, and the new sample will be added at the end.

If the makeSpace parameter is set to true, the sample count will be increased by one, and the sample will be added at the end.

The sample labels are also moved to the left with the samples.

Parameters:
serie - The series to append the sample to.
sample - The sample to append.
makeSpace - True to make space for the new parameter.
Returns:
The index of the position where the sample was inserted.
Throws:
java.lang.IllegalArgumentException - If the serie is invalid.

appendSampleLabel

public int appendSampleLabel(java.lang.String label,
                             boolean makeSpace)
Appends a sample labels If makeSpace is set to false, and all the sample labels are filled up, they will be scrolled to the left, with the left most label deleted. If makeSpace is set to true, the number of sample labels will be incremented by one.

Parameters:
label - The label to append.
makeSpace - True to make space for the new parameter.
Returns:
The index of the position where the sample was inserted.

appendSampleValue

public int appendSampleValue(int serie,
                             double value,
                             boolean makeSpace)
Appends a value to the given series. If the number of samples is less than the sample count, a new sample is added after the last one. If the number of samples in the series is the same as the sample count (series is full), the addition will depend on the makeSpace parameter.

If the makeSpace parameter is set to false, all the current values will shift one sample to the left (the sample itself will not move, only the value) and the new value will be set in the last sample.

If the makeSpace parameter is set to true, the sample count will be increased by one, and a new sample will be added at the end.

Parameters:
serie - The series to append the sample to.
value - The value to append.
makeSpace - True to make space for the new parameter.
Returns:
The index of the position where the sample was inserted.
Throws:
java.lang.IllegalArgumentException - If the serie is invalid.

getMaxValue

public double getMaxValue(int serie)
Gets the largest value in the specified data series. If the specified series (i.e -1) does not exist, the value returned will be the maximum value of the whole chart.

Parameters:
serie - The index of the serie (0-based).

getMinValue

public double getMinValue(int serie)
Gets the smallest value in the specified data series. If the specified series (i.e -1) does not exist, the value returned will be the minimum value of the whole chart.

Parameters:
serie - The index of the serie (0-based).

getSample

public ChartSample getSample(int serie,
                             int index)
Gets the specified sample.

Parameters:
serie - The index of the serie (0-based).
index - The index of the sample (0-based).
Returns:
The sample, or null if no sample was found.
Throws:
java.lang.IllegalArgumentException - if the serie or index is invalid.

getSample

public ChartSample getSample(java.lang.Object key)
Gets the sample with the specified key. Every sample can have a key assosiated with them, so they can be gotten with this key instead of the index position. The default key is a string of type series.index, where series is the series number, and the index, is the sample index.

Parameters:
key - The key of the sample to find.
Returns:
The sample, or null if no sample was found.

getSampleCount

public int getSampleCount()
Gets the number of samples.


getSampleLabel

public java.lang.String getSampleLabel(int index)
Gets the specified sample label.

Parameters:
index - The index of the sample (0-based).
Returns:
The sample label, or null if no label was found.
Throws:
java.lang.IllegalArgumentException - if the index is invalid.

getSampleLabels

public java.lang.String[] getSampleLabels()
Gets the sample labels. The array returned is the original labels, so don't change anything in the array if you don't know what you are doing.

Returns:
The labels as an array of strings.

getSamples

public ChartSample[] getSamples(int serie)
Gets the samples for the specified serie.

Parameters:
serie - The index of the serie (0-based).
Returns:
The samples as an array of ChartSample objects.
Throws:
java.lang.IllegalArgumentException - if the serie is invalid.

getSampleValue

public double getSampleValue(int serie,
                             int index)
Gets the specified sample value.

Parameters:
serie - The index of the serie (0-based).
index - The index of the sample (0-based).
Returns:
The sample value, or Double.NaN if no sample is set.
Throws:
java.lang.IllegalArgumentException - if the serie or index is invalid.

getSampleValues

public double[] getSampleValues(int serie)
Gets the sample values for the specified serie.

Parameters:
serie - The index of the serie (0-based).
Returns:
The values as an array of floating point numbers.
Throws:
java.lang.IllegalArgumentException - if the serie is invalid.

getSeriesCount

public int getSeriesCount()
Gets the number of series.


getSeriesLabel

public java.lang.String getSeriesLabel(int serie)
Gets the specified series label.

Parameters:
serie - The index of the serie (0-based).
Returns:
The sample label, or null if no label was found.
Throws:
java.lang.IllegalArgumentException - if the index is invalid.

getSeriesLabels

public java.lang.String[] getSeriesLabels()
Gets the series labels.

Returns:
The labels as an array of strings, or null if no labels are found.

hasChangedSince

public boolean hasChangedSince(long time)
Checks if the data has been changed since the specified time.

Parameters:
time - The time to check for.
Returns:
True if the data has changed, false otherwise.

isSelected

public boolean isSelected(int serie,
                          int sample)
Checks if a sample is selected.

Parameters:
serie - The series index (-1 is whole series).
sample - The sample index (-1 is all samples in series).
Returns:
True if the specified sample is selected, false otherwise.
Throws:
java.lang.IllegalArgumentException - If the serie or sample is invalid.

setSample

public void setSample(int serie,
                      int index,
                      ChartSample sample)
Sets the specified sample. If a null sample is given, the sample is cleared.

Parameters:
serie - The index of the serie (0-based).
index - The index of the sample (0-based).
sample - The sample to use.
Throws:
java.lang.IllegalArgumentException - if the serie or index is invalid.

setSampleCount

public void setSampleCount(int count)
Sets the number of samples.

Parameters:
count - The number of samples.

setSampleLabel

public void setSampleLabel(int index,
                           java.lang.String label)
Sets the specified sample label.

Parameters:
index - The index of the sample (0-based).
label - The label of the sample.

setSampleLabels

public void setSampleLabels(java.lang.String[] labels)
Sets the sample labels.

Parameters:
labels - The labels to use.

setSamples

public void setSamples(int serie,
                       ChartSample[] samples)
Sets the samples for the specified series. If the number of samples is less than the current sample count, the rest of the samples will be set to null. If the number of samples is larger than the current sample count, the rest of the samples will be discarded.

Parameters:
serie - The index of the serie (0-based).
samples - The samples to set.
Throws:
java.lang.IllegalArgumentException - if the serie is invalid.

setSampleValue

public void setSampleValue(int serie,
                           int index,
                           double value)
Sets the specified sample value.

Parameters:
serie - The index of the serie (0-based).
index - The index of the sample (0-based).
value - The value to use for the sample.
Throws:
java.lang.IllegalArgumentException - if the serie or index is invalid.

setSampleValues

public void setSampleValues(int serie,
                            double[] values)
Sets the sample values for the specified series. If the number of values is less than the current sample count, the rest of the samples will be set to null. If the number of values is larger than the current sample count, the rest of the values will be discarded.

Parameters:
serie - The index of the serie (0-based).
values - The values to use for the series.
Throws:
java.lang.IllegalArgumentException - if the serie is invalid.

setSelection

public void setSelection(int serie,
                         int sample,
                         boolean selected)
Marks a sample as selected or deselected. If serie is -1, the specified sample in all series are marked. If sample is -1, all the samples in the specified series is marked. No listeners are notified by calling this method.

Parameters:
serie - The series index.
sample - The sample index.
selected - True for selected, false for deselected.

setSeriesCount

public void setSeriesCount(int count)
Sets the number of series.

Parameters:
count - The number of series.

setSeriesLabel

public void setSeriesLabel(int serie,
                           java.lang.String label)
Sets the specified series label.

Parameters:
serie - The index of the serie (0-based).
label - The label of the sample.
Throws:
java.lang.IllegalArgumentException - if the index is invalid.

setSeriesLabels

public void setSeriesLabels(java.lang.String[] labels)
Sets the series labels.

Parameters:
labels - The labels to use.

toString

public java.lang.String toString()
Returns a string with the number of series and samples.

Overrides:
toString in class java.lang.Object