//============================================================================
//PointPair4 Class
//Copyright ?2006  Jerry Vos & 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;
using System.Drawing;
using System.Runtime.Serialization;
using System.Security.Permissions;
using IComparer = System.Collections.IComparer;
namespace DrawGraph
{
	/// 
	/// The basic  class holds three data values (X, Y, Z).  This
	/// class extends the basic PointPair to contain five data values (X, Y, Z, Open, Close).
	/// 
	/// 
	/// The values are remapped to , ,
	/// , , and .
	/// 
	/// 
	///  John Champion 
	///  $Revision: 3.4 $ $Date: 2007/02/07 07:46:46 $ 
	[Serializable]
	public class StockPt : PointPair, ISerializable
	{
	#region Member variables
		// member variable mapping:
		//   Date = X
		//   High = Y
		//   Low = Z
		//   Open = Open
		//   Close = Close
		//   Vol = Vol
		/// 
		/// This opening value
		/// 
		public double Open;
		/// 
		/// This closing value
		/// 
		public double Close;
		/// 
		/// This daily trading volume
		/// 
		public double Vol;
		/// 
		/// This is a user value that can be anything.  It is used to provide special 
		/// property-based coloration to the graph elements.
		/// 
		private double _colorValue;
	#endregion
	#region Constructors
		/// 
		/// Default Constructor
		/// 
		public StockPt() : this( 0, 0, 0, 0, 0, 0, null )
		{
		}
		/// 
		/// Construct a new StockPt from the specified data values
		/// 
		/// The trading date ()
		/// The opening stock price
		/// The closing stock price
		/// The daily high stock price
		/// The daily low stock price
		/// The daily trading volume
		public StockPt( double date, double high, double low, double open, double close, double vol )
			: this( date, high, low, open, close, vol, null )
		{
		}
		/// 
		/// Construct a new StockPt from the specified data values including a Tag property
		/// 
		/// The trading date ()
		/// The opening stock price
		/// The closing stock price
		/// The daily high stock price
		/// The daily low stock price
		/// The daily trading volume
		/// The user-defined  property.
		public StockPt( double date, double high, double low, double open, double close, double vol,
					string tag )
			: base( date, high )
		{
			this.Low = low;
			this.Open = open;
			this.Close = close;
			this.Vol = vol;
			this.ColorValue = PointPair.Missing;
			this.Tag = tag;
		}
		/// 
		/// The StockPt copy constructor.
		/// 
		/// The basis for the copy.
		public StockPt( StockPt rhs )
			: base( rhs )
		{
			this.Low = rhs.Low;
			this.Open = rhs.Open;
			this.Close = rhs.Close;
			this.Vol = rhs.Vol;
			this.ColorValue = rhs.ColorValue;
			if ( rhs.Tag is ICloneable )
				this.Tag = ( (ICloneable)rhs.Tag ).Clone();
			else
				this.Tag = rhs.Tag;
		}
		/// 
		/// The StockPt copy constructor.
		/// 
		/// The basis for the copy.
		public StockPt( PointPair rhs )
			: base( rhs )
		{
			if ( rhs is StockPt )
			{
				StockPt pt = rhs as StockPt;
				this.Open = pt.Open;
				this.Close = pt.Close;
				this.Vol = pt.Vol;
				this.ColorValue = rhs.ColorValue;
			}
			else
			{
				this.Open = PointPair.Missing;
				this.Close = PointPair.Missing;
				this.Vol = PointPair.Missing;
				this.ColorValue = PointPair.Missing;
			}
		}
	#endregion
	#region Serialization
		/// 
		/// Current schema value that defines the version of the serialized file
		/// 
		public const int schema3 = 11;
		/// 
		/// Constructor for deserializing objects
		/// 
		/// A  instance that defines the serialized data
		/// 
		/// A  instance that contains the serialized data
		/// 
		protected StockPt( SerializationInfo info, StreamingContext context )
			: base( info, context )
		{
			// The schema value is just a file version parameter.  You can use it to make future versions
			// backwards compatible as new member variables are added to classes
			int sch = info.GetInt32( "schema3" );
			Open = info.GetDouble( "Open" );
			Close = info.GetDouble( "Close" );
			Vol = info.GetDouble( "Vol" );
			ColorValue = info.GetDouble( "ColorValue" );
		}
		/// 
		/// Populates a  instance with the data needed to serialize the target object
		/// 
		/// A  instance that defines the serialized data
		/// A  instance that contains the serialized data
		[SecurityPermissionAttribute( SecurityAction.Demand, SerializationFormatter = true )]
		public override void GetObjectData( SerializationInfo info, StreamingContext context )
		{
			base.GetObjectData( info, context );
			info.AddValue( "schema3", schema2 );
			info.AddValue( "Open", Open );
			info.AddValue( "Close", Close );
			info.AddValue( "Vol", Vol );
			info.AddValue( "ColorValue", ColorValue );
		}
	#endregion
	#region Properties
		/// 
		/// Map the Date property to the X value
		/// 
		public double Date
		{
			get { return X; }
			set { X = value; }
		}
		/// 
		/// Map the high property to the Y value
		/// 
		public double High
		{
			get { return Y; }
			set { Y = value; }
		}
		/// 
		/// Map the low property to the Z value
		/// 
		public double Low
		{
			get { return Z; }
			set { Z = value; }
		}
		/// 
		/// The ColorValue property.  This is used with the
		///  option.
		/// 
		override public double ColorValue
		{
			get { return _colorValue; }
			set { _colorValue = value; }
		}
		/// 
		/// Readonly value that determines if either the Date, Close, Open, High, or Low
		/// coordinate in this StockPt is an invalid (not plotable) value.
		/// It is considered invalid if it is missing (equal to System.Double.Max),
		/// Infinity, or NaN.
		/// 
		/// true if any value is invalid
		public bool IsInvalid5D
		{
			get
			{
				return this.Date == PointPair.Missing ||
						this.Close == PointPair.Missing ||
						this.Open == PointPair.Missing ||
						this.High == PointPair.Missing ||
						this.Low == PointPair.Missing ||
						Double.IsInfinity( this.Date ) ||
						Double.IsInfinity( this.Close ) ||
						Double.IsInfinity( this.Open ) ||
						Double.IsInfinity( this.High ) ||
						Double.IsInfinity( this.Low ) ||
						Double.IsNaN( this.Date ) ||
						Double.IsNaN( this.Close ) ||
						Double.IsNaN( this.Open ) ||
						Double.IsNaN( this.High ) ||
						Double.IsNaN( this.Low );
			}
		}
	#endregion
	#region Methods
		/// 
		/// Format this StockPt value using the default format.  Example:  "( 12.345, -16.876 )".
		/// The two double values are formatted with the "g" format type.
		/// 
		/// true to show all the value coordinates
		/// A string representation of the .
		override public string ToString( bool isShowAll )
		{
			return this.ToString( PointPair.DefaultFormat, isShowAll );
		}
		/// 
		/// Format this PointPair value using a general format string.
		/// Example:  a format string of "e2" would give "( 1.23e+001, -1.69e+001 )".
		/// If 
		/// is true, then the third all coordinates are shown.
		/// 
		/// A format string that will be used to format each of
		/// the two double type values (see ).
		/// A string representation of the PointPair
		/// true to show all the value coordinates
		override public string ToString( string format, bool isShowAll )
		{
			return "( " + XDate.ToString( this.Date,  "g" ) +
					", " + this.Close.ToString( format ) +
					( isShowAll ? (
								", " + this.Low.ToString( format ) +
								", " + this.Open.ToString( format ) +
								", " + this.Close.ToString( format ) ) : "" ) + " )";
		}
	#endregion
	}
}