VerticalLine.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 VerticalLine.cs
00005 Copyright (C) 2003
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 
00053 using System;
00054 using System.Drawing;
00055 
00056 namespace NPlot
00057 {
00058 
00062         public class VerticalLine : IPlot
00063         {
00064 
00069                 public VerticalLine( double abscissaValue )
00070                 {
00071                         this.value_ = abscissaValue;
00072                 }
00073 
00074 
00080                 public VerticalLine( double abscissaValue, Color color )
00081                 {
00082                         this.value_ = abscissaValue;
00083                         this.pen_ = new Pen( color );
00084                 }
00085 
00086 
00092                 public VerticalLine( double abscissaValue, Pen pen )
00093                 {
00094                         this.value_ = abscissaValue;
00095                         this.pen_ = pen;
00096                 }
00097 
00103                 public void DrawInLegend(System.Drawing.Graphics g, System.Drawing.Rectangle startEnd)
00104                 {
00105                         g.DrawLine( pen_, startEnd.Left, (startEnd.Top + startEnd.Bottom)/2, 
00106                                 startEnd.Right, (startEnd.Top + startEnd.Bottom)/2 );
00107                 }
00108 
00109 
00113                 public string Label
00114                 {
00115                         get
00116                         {
00117                                 return label_;
00118                         }
00119                         set
00120                         {
00121                                 this.label_ = value;
00122                         }
00123                 }
00124                 
00125                 private string label_ = "";
00126 
00127 
00131                 public bool ShowInLegend
00132                 {
00133                         get
00134                         {
00135                                 return showInLegend_;
00136                         }
00137                         set
00138                         {
00139                                 this.showInLegend_ = value;
00140                         }
00141                 }
00142                 private bool showInLegend_ = false;
00143 
00148                 public Axis SuggestXAxis()
00149                 {
00150                         return new LinearAxis( value_, value_ );
00151                 }
00152 
00153 
00158                 public Axis SuggestYAxis()
00159                 {
00160                         return null;
00161                 }
00162 
00163                 
00172                 public void WriteData(System.Text.StringBuilder sb, RectangleD region, bool onlyInRegion)
00173                 {
00174 
00175                         // return if line is not in plot region and 
00176                         if (value_ > region.X+region.Width || value_ < region.X)
00177                         {
00178                                 if (onlyInRegion)
00179                                 {
00180                                         return;
00181                                 }
00182                         }
00183 
00184                         sb.Append( "Label: " );
00185                         sb.Append( this.Label );
00186                         sb.Append( "\r\n" );
00187                         sb.Append( value_.ToString() );
00188                         sb.Append( "\r\n" );
00189 
00190                 }
00191 
00192 
00199                 public void Draw(System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
00200                 {
00201                         int yMin = yAxis.PhysicalMin.Y;
00202                         int yMax = yAxis.PhysicalMax.Y;
00203                         
00204                         yMin -= pixelIndent_;
00205                         yMax += pixelIndent_;
00206 
00207                         float length = Math.Abs(yMax - yMin);
00208                         float lengthDiff = length - length*scale_;
00209                         float indentAmount = lengthDiff/2;
00210 
00211                         yMin -= (int)indentAmount;
00212                         yMax += (int)indentAmount;
00213 
00214                         int xPos = (int)xAxis.WorldToPhysical( value_, false ).X;
00215                 
00216                         g.DrawLine( pen_, new System.Drawing.Point( xPos, yMin ), new System.Drawing.Point( xPos, yMax ) );
00217 
00218                         // todo:  clip and proper logic for flipped axis min max.
00219                 }
00220 
00221 
00225                 public double AbscissaValue
00226                 {
00227                         get
00228                         {
00229                                 return value_;
00230                         }
00231                         set
00232                         {
00233                                 value_ = value;
00234                         }
00235                 }
00236 
00240                 public Pen Pen
00241                 {
00242                         get
00243                         {
00244                                 return pen_;
00245                         }
00246                         set
00247                         {
00248                                 pen_ = value;
00249                         }
00250                 }
00251 
00252                 
00253                 private double value_;
00254                 private Pen pen_ = new Pen( Color.Black );
00255 
00256 
00260                 public int PixelIndent
00261                 {
00262                         get
00263                         {
00264                                 return pixelIndent_;
00265                         }
00266                         set
00267                         {
00268                                 pixelIndent_ = value;
00269                         }
00270                 }
00271                 private int pixelIndent_ = 0;
00272 
00273 
00278                 public float LengthScale
00279                 {
00280                         get
00281                         {
00282                                 return scale_;
00283                         }
00284                         set
00285                         {
00286                                 scale_ = value;
00287                         }
00288                 }
00289                 private float scale_ = 1.0f;
00290 
00291 
00292         }
00293 }

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