//============================================================================ //ZedGraph Class Library - A Flexible Line Graph/Bar Graph Library in C# //Copyright ?2007 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; namespace DrawGraph { /// /// inherits from , and defines the /// special characteristics of a horizontal axis, specifically located at /// the top of the of the /// object /// /// /// John Champion /// $Revision: 3.1 $ $Date: 2007/04/16 00:03:07 $ [Serializable] public class X2Axis : Axis, ICloneable, ISerializable { #region Defaults /// /// A simple struct that defines the /// default property values for the class. /// public new struct Default { // Default X2 Axis properties /// /// The default display mode for the /// ( property). true to display the scale /// values, title, tic marks, false to hide the axis entirely. /// public static bool IsVisible = false; /// /// Determines if a line will be drawn at the zero value for the /// , that is, a line that /// divides the negative values from positive values. /// . /// public static bool IsZeroLine = false; } #endregion #region Constructors /// /// Default constructor that sets all properties to /// default values as defined in the class /// public X2Axis() : this( "X2 Axis" ) { } /// /// Default constructor that sets all properties to /// default values as defined in the class, except /// for the axis title /// /// The for this axis public X2Axis( string title ) : base( title ) { _isVisible = Default.IsVisible; _majorGrid._isZeroLine = Default.IsZeroLine; _scale._fontSpec.Angle = 180F; _title._fontSpec.Angle = 180F; } /// /// The Copy Constructor /// /// The X2Axis object from which to copy public X2Axis( X2Axis rhs ) : base( rhs ) { } /// /// 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 X2Axis Clone() { return new X2Axis( this ); } #endregion #region Serialization /// /// Current schema value that defines the version of the serialized file /// public const int schema2 = 11; /// /// Constructor for deserializing objects /// /// A instance that defines the serialized data /// /// A instance that contains the serialized data /// protected X2Axis( 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( "schema2" ); } /// /// 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( "schema2", schema2 ); } #endregion #region Methods /// /// Setup the Transform Matrix to handle drawing of this /// /// /// A graphic device object to be drawn into. This is normally e.Graphics from the /// PaintEventArgs argument to the Paint() method. /// /// /// A reference to the object that is the parent or /// owner of this object. /// /// /// The scaling factor to be used for rendering objects. This is calculated and /// passed down by the parent object using the /// method, and is used to proportionally adjust /// font sizes, etc. according to the actual size of the graph. /// override public void SetTransformMatrix( Graphics g, GraphPane pane, float scaleFactor ) { // Move the origin to the TopLeft of the ChartRect, which is the left // side of the X2 axis (facing from the label side) g.TranslateTransform( pane.Chart._rect.Right, pane.Chart._rect.Top ); //g.ScaleTransform( 1.0f, -1.0f ); // rotate so this axis is in the right-left direction g.RotateTransform( 180 ); } /// /// Determines if this object is a "primary" one. /// /// /// The primary axes are the (always), /// the (always), the first /// in the /// ( = 0), and the first /// in the /// ( = 0). Note that /// and /// always reference the primary axes. /// /// /// A reference to the object that is the parent or /// owner of this object. /// /// true for a primary (for the , /// this is always true), false otherwise override internal bool IsPrimary( GraphPane pane ) { return this == pane.X2Axis; } /// /// Calculate the "shift" size, in pixels, in order to shift the axis from its default /// location to the value specified by . /// /// /// A reference to the object that is the parent or /// owner of this object. /// /// The shift amount measured in pixels internal override float CalcCrossShift( GraphPane pane ) { double effCross = EffectiveCrossValue( pane ); if ( !_crossAuto ) return pane.YAxis.Scale.Transform( effCross ) - pane.YAxis.Scale._maxPix; else return 0; } /* override internal bool IsCrossed( GraphPane pane ) { return !this.crossAuto && this.cross > pane.YAxis.Min && this.cross < pane.YAxis.Max; } */ /// /// Gets the "Cross" axis that corresponds to this axis. /// /// /// The cross axis is the axis which determines the of this Axis when the /// Axis.Cross property is used. The /// cross axis for any or /// is always the primary , and /// the cross axis for any or is /// always the primary . /// /// /// A reference to the object that is the parent or /// owner of this object. /// override public Axis GetCrossAxis( GraphPane pane ) { return pane.YAxis; } // override internal float GetMinPix( GraphPane pane ) // { // return pane.Chart._rect.Left; // } #endregion } }