BarPlot.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 BarPlot.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 using System;
00053 using System.Drawing;
00054 
00055 namespace NPlot
00056 {
00057 
00061         public class BarPlot : BasePlot, IPlot, IDrawable
00062         {
00063 
00067                 public BarPlot()
00068                 {
00069                 }
00070 
00071 
00075                 public object OrdinateDataTop
00076                 {
00077                         get
00078                         {
00079                                 return this.ordinateDataTop_;
00080                         }
00081                         set
00082                         {
00083                                 this.ordinateDataTop_ = value;
00084                         }
00085                 }
00086                 private object ordinateDataTop_ = null;
00087 
00088                 
00092                 public object OrdinateDataBottom
00093                 {
00094                         get
00095                         {
00096                                 return this.ordinateDataBottom_;
00097                         }
00098                         set
00099                         {
00100                                 this.ordinateDataBottom_ = value;
00101                         }
00102                 }
00103                 private object ordinateDataBottom_ = null;
00104 
00105 
00109                 public object AbscissaData
00110                 {
00111                         get
00112                         {
00113                                 return this.abscissaData_;
00114                         }
00115                         set
00116                         {
00117                                 this.abscissaData_ = value;
00118                         }
00119                 }
00120                 private object abscissaData_ = null;
00121 
00122 
00129                 public void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
00130                 {
00131                         SequenceAdapter dataTop = 
00132                                 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateDataTop, this.AbscissaData );
00133 
00134                         SequenceAdapter dataBottom = 
00135                                 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateDataBottom, this.AbscissaData );
00136 
00137                         ITransform2D t = Transform2D.GetTransformer( xAxis, yAxis );
00138                         
00139                         for (int i=0; i<dataTop.Count; ++i)
00140                         {
00141                                 PointF physicalBottom = t.Transform( dataBottom[i] );
00142                                 PointF physicalTop = t.Transform( dataTop[i] );
00143 
00144                                 Rectangle r = new Rectangle( (int)physicalBottom.X - 4, (int)physicalTop.Y,
00145                                         8, (int)(physicalBottom.Y - physicalTop.Y) );
00146 
00147                                 g.FillRectangle( this.rectangleBrush_.Get(r), r );
00148                                 g.DrawRectangle( borderPen_, r );
00149 
00150                         }
00151 
00152                 }
00153 
00158                 public Axis SuggestXAxis()
00159                 {
00160                         SequenceAdapter dataBottom_ = 
00161                                 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateDataBottom, this.AbscissaData );
00162 
00163                         SequenceAdapter dataTop_ = 
00164                                 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateDataTop, this.AbscissaData );
00165 
00166                         return dataBottom_.SuggestXAxis();
00167                 }
00168 
00169 
00174                 public Axis SuggestYAxis()
00175                 {
00176                         SequenceAdapter dataBottom_ = 
00177                                 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateDataBottom, this.AbscissaData );
00178 
00179                         SequenceAdapter dataTop_ = 
00180                                 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateDataTop, this.AbscissaData );
00181 
00182                         return dataTop_.SuggestYAxis();
00183                 }
00184 
00185 
00191                 public virtual void DrawInLegend(Graphics g, Rectangle startEnd)
00192                 {
00193                         int smallerHeight = (int)(startEnd.Height * 0.5f);
00194                         int heightToRemove = (int)(startEnd.Height * 0.5f);
00195                         Rectangle newRectangle = new Rectangle( startEnd.Left, startEnd.Top + smallerHeight / 2, startEnd.Width, smallerHeight );
00196                         g.FillRectangle( rectangleBrush_.Get( newRectangle ), newRectangle );
00197                         g.DrawRectangle( borderPen_, newRectangle );
00198                 }
00199 
00203                 public System.Drawing.Pen BorderPen
00204                 {
00205                         get
00206                         {
00207                                 return borderPen_;
00208                         }
00209                         set
00210                         {
00211                                 borderPen_ = value;
00212                         }
00213                 }
00214                 private System.Drawing.Pen borderPen_ = new Pen(Color.Black);
00215 
00216 
00220                 public System.Drawing.Color BorderColor
00221                 {
00222                         set
00223                         {
00224                                 if (borderPen_ != null)
00225                                 {
00226                                         borderPen_.Color = value;
00227                                 }
00228                                 else
00229                                 {
00230                                         borderPen_ = new Pen(value);
00231                                 }
00232                         }
00233                         get
00234                         {
00235                                 return borderPen_.Color;
00236                         }
00237                 }
00238 
00239 
00243                 public IRectangleBrush FillBrush
00244                 {
00245                         get
00246                         {
00247                                 return rectangleBrush_;
00248                         }
00249                         set
00250                         {
00251                                 rectangleBrush_ = value;
00252                         }
00253 
00254                 }
00255                 private IRectangleBrush rectangleBrush_ = new RectangleBrushes.Solid( Color.LightGray );
00256 
00257 
00258 
00266                 public void WriteData( System.Text.StringBuilder sb, RectangleD region, bool onlyInRegion )
00267                 {
00268                         sb.Append( "Write data not implemented yet for BarPlot\r\n" );
00269                 }
00270 
00271 
00272         }
00273 
00274 }

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