//============================================================================
//BasicArrayPointList Class
//Copyright ?2005 John Champion
//
//This library is free software; you can redistribute it and/or
//modify it under the terms of the GNU Lesser General Public
//License as published by the Free Software Foundation; either
//version 2.1 of the License, or (at your option) any later version.
//
//This library is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
//Lesser General Public License for more details.
//
//You should have received a copy of the GNU Lesser General Public
//License along with this library; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//=============================================================================
using System;
namespace DrawGraph
{
///
/// A data collection class for ZedGraph, provided as an alternative to .
///
///
/// The data storage class for ZedGraph can be any type, so long as it uses the
/// interface. This class, albeit simple, is a demonstration of implementing the
/// interface to provide a simple data collection using only two arrays. The
/// interface can also be used as a layer between ZedGraph and a database, for example.
///
///
///
///
/// John Champion
/// $Revision: 3.4 $ $Date: 2007/02/18 05:51:53 $
[Serializable]
public class BasicArrayPointList : IPointList
{
#region Fields
///
/// Instance of an array of x values
///
public double[] x;
///
/// Instance of an array of x values
///
public double[] y;
#endregion
#region Properties
///
/// Indexer to access the specified object by
/// its ordinal position in the list.
///
///
/// Returns for any value of
/// that is outside of its corresponding array bounds.
///
/// The ordinal position (zero-based) of the
/// object to be accessed.
/// A object reference.
public PointPair this[ int index ]
{
get
{
double xVal, yVal;
if ( index >= 0 && index < x.Length )
xVal = x[index];
else
xVal = PointPair.Missing;
if ( index >= 0 && index < y.Length )
yVal = y[index];
else
yVal = PointPair.Missing;
return new PointPair( xVal, yVal, PointPair.Missing, null );
}
set
{
if ( index >= 0 && index < x.Length )
x[index] = value.X;
if ( index >= 0 && index < y.Length )
y[index] = value.Y;
}
}
///
/// Returns the number of points available in the arrays. Count will be the greater
/// of the lengths of the X and Y arrays.
///
public int Count
{
get { return x.Length > y.Length ? x.Length : y.Length; }
}
#endregion
#region Constructors
///
/// Constructor to initialize the PointPairList from two arrays of
/// type double.
///
public BasicArrayPointList( double[] x, double[] y )
{
this.x = x;
this.y = y;
}
///
/// The Copy Constructor
///
/// The PointPairList from which to copy
public BasicArrayPointList( BasicArrayPointList rhs )
{
x = (double[]) rhs.x.Clone();
y = (double[]) rhs.y.Clone();
}
///
/// Implement the interface in a typesafe manner by just
/// calling the typed version of
///
/// A deep copy of this object
object ICloneable.Clone()
{
return this.Clone();
}
///
/// Typesafe, deep-copy clone method.
///
/// A new, independent copy of this class
public BasicArrayPointList Clone()
{
return new BasicArrayPointList( this );
}
#endregion
}
}