PiAxis.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 PiAxis.cs
00005 Copyright (C) 2004
00006 Matt Howlett
00007 
00008 Redistribution and use of NPlot or parts there-of in source and
00009 binary forms, with or without modification, are permitted provided
00010 that the following conditions are met:
00011 
00012 1. Re-distributions in source form must retain at the head of each
00013    source file the above copyright notice, this list of conditions
00014    and the following disclaimer.
00015 
00016 2. Any product ("the product") that makes use NPlot or parts 
00017    there-of must either:
00018   
00019     (a) allow any user of the product to obtain a complete machine-
00020         readable copy of the corresponding source code for the 
00021         product and the version of NPlot used for a charge no more
00022         than your cost of physically performing source distribution,
00023         on a medium customarily used for software interchange, or:
00024 
00025     (b) reproduce the following text in the documentation, about 
00026         box or other materials intended to be read by human users
00027         of the product that is provided to every human user of the
00028         product: 
00029    
00030               "This product includes software developed as 
00031               part of the NPlot library project available 
00032               from: http://www.nplot.com/" 
00033 
00034         The words "This product" may optionally be replace with 
00035         the actual name of the product.
00036 
00037 ------------------------------------------------------------------------
00038 
00039 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00040 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00041 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00042 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00043 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00044 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00045 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00046 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00047 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00048 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00049 
00050 */
00051 
00052 using System;
00053 using System.Drawing;
00054 using System.Collections;
00055 
00056 namespace NPlot
00057 {
00058 
00066         public class PiAxis : Axis
00067         {
00068 
00073                 public override object Clone()
00074                 {
00075                         PiAxis a = new PiAxis();
00076                         // ensure that this isn't being called on a derived type. If it is, then oh no!
00077                         if (this.GetType() != a.GetType())
00078                         {
00079                                 throw new NPlotException( "Error. Clone method is not defined in derived type." );
00080                         }
00081                         DoClone( this, a );
00082                         return a;
00083                 }
00084 
00085 
00091                 protected static void DoClone( PiAxis b, PiAxis a )
00092                 {
00093                         Axis.DoClone( b, a );
00094                 }
00095 
00096 
00100                 private void Init()
00101                 {
00102                 }
00103 
00104 
00110                 public PiAxis( Axis a )
00111                         : base( a )
00112                 {
00113                         Init();
00114                 }
00115 
00116 
00120                 public PiAxis()
00121                         : base()
00122                 {
00123                         Init();
00124                 }
00125 
00126 
00132                 public PiAxis( double worldMin, double worldMax )
00133                         : base( worldMin, worldMax )
00134                 {
00135                         Init();
00136                 }
00137 
00138 
00148                 protected override void DrawTicks( 
00149                         Graphics g, 
00150                         Point physicalMin, 
00151                         Point physicalMax, 
00152                         out object labelOffset,
00153                         out object boundingBox )
00154                 {
00155                         Point tLabelOffset;
00156                         Rectangle tBoundingBox;
00157 
00158                         labelOffset = this.getDefaultLabelOffset( physicalMin, physicalMax );
00159                         boundingBox = null;
00160 
00161                         int start = (int)Math.Ceiling( this.WorldMin / Math.PI );
00162                         int end = (int)Math.Floor( this.WorldMax / Math.PI );
00163                         
00164                         // sanity checking.
00165                         if ( end - start < 0 || end - start > 30 )
00166                         {
00167                                 return;
00168                         }
00169 
00170                         for (int i=start; i<=end; ++i)
00171                         {
00172                                 string label = i.ToString() + "Pi";
00173 
00174                                 if (i == 0)
00175                                         label = "0";
00176                                 else if (i == 1)
00177                                         label = "Pi";
00178 
00179                                 this.DrawTick( g, i*Math.PI, this.LargeTickSize, 
00180                                         label,
00181                                         new Point(0,0), 
00182                                         physicalMin, physicalMax,
00183                                         out tLabelOffset, out tBoundingBox );
00184 
00185                                 Axis.UpdateOffsetAndBounds( 
00186                                         ref labelOffset, ref boundingBox, 
00187                                         tLabelOffset, tBoundingBox );
00188                         }
00189 
00190                 }
00191 
00192 
00202                 internal override void WorldTickPositions_FirstPass(
00203                         Point physicalMin, 
00204                         Point physicalMax,
00205                         out ArrayList largeTickPositions,
00206                         out ArrayList smallTickPositions
00207                         )
00208                 {
00209                         smallTickPositions = null;
00210                         largeTickPositions = new ArrayList();
00211         
00212                         int start = (int)Math.Ceiling( this.WorldMin / Math.PI );
00213                         int end = (int)Math.Floor( this.WorldMax / Math.PI );
00214 
00215                         // sanity checking.
00216                         if ( end - start < 0 || end - start > 30 )
00217                         {
00218                                 return;
00219                         }
00220 
00221                         for (int i=start; i<end; ++i)
00222                         {
00223                                 largeTickPositions.Add( i*Math.PI ); 
00224                         }
00225 
00226                 }
00227 
00228 
00229         }
00230 }

Generated on Sat Nov 5 01:04:06 2005 for NPlot by  doxygen 1.4.5