FilledRegion.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 FilledRegion.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 
00055 namespace NPlot
00056 {
00057 
00061         public class FilledRegion : IDrawable
00062         {
00063 
00070                 public FilledRegion( LinePlot lp1, LinePlot lp2 )
00071                 {
00072                         lp1_ = lp1;
00073                         lp2_ = lp2;
00074                 }
00075 
00076 
00082         public FilledRegion(VerticalLine l1, VerticalLine l2)
00083         {
00084             vl1_ = l1;
00085             vl2_ = l2;
00086         }
00087 
00088 
00094         public FilledRegion(HorizontalLine l1, HorizontalLine l2)
00095         {
00096             hl1_ = l1;
00097             hl2_ = l2;
00098         }
00099 
00100 
00107                 public void Draw( System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
00108                 {
00109             ITransform2D t = Transform2D.GetTransformer(xAxis, yAxis);
00110 
00111             Brush b = brush_;
00112             if (b == null)
00113             {
00114                 b = areaBrush_.Get(new Rectangle(xAxis.PhysicalMin.X, yAxis.PhysicalMax.Y, xAxis.PhysicalLength, yAxis.PhysicalLength));
00115             }
00116 
00117             if (hl1_ != null && hl2_ != null)
00118             {
00119                 PointF[] points = new PointF[4];
00120                 points[0] = t.Transform(xAxis.Axis.WorldMin, hl1_.OrdinateValue);
00121                 points[1] = t.Transform(xAxis.Axis.WorldMax, hl1_.OrdinateValue);
00122                 points[2] = t.Transform(xAxis.Axis.WorldMax, hl2_.OrdinateValue);
00123                 points[3] = t.Transform(xAxis.Axis.WorldMin, hl2_.OrdinateValue);
00124 
00125                 g.FillPolygon(b, points);
00126             }   
00127             else if (vl1_ != null && vl2_ != null)
00128             {
00129                 PointF[] points = new PointF[4];
00130                 points[0] = t.Transform(vl1_.AbscissaValue, yAxis.Axis.WorldMin);
00131                 points[1] = t.Transform(vl1_.AbscissaValue, yAxis.Axis.WorldMax);
00132                 points[2] = t.Transform(vl2_.AbscissaValue, yAxis.Axis.WorldMax);
00133                 points[3] = t.Transform(vl2_.AbscissaValue, yAxis.Axis.WorldMin);
00134 
00135                 g.FillPolygon(b, points);
00136             }
00137             else if (lp1_ != null && lp2_ != null)
00138             {
00139 
00140                 SequenceAdapter a1 = new SequenceAdapter(lp1_.DataSource, lp1_.DataMember, lp1_.OrdinateData, lp1_.AbscissaData);
00141                 SequenceAdapter a2 = new SequenceAdapter(lp2_.DataSource, lp2_.DataMember, lp2_.OrdinateData, lp2_.AbscissaData);
00142 
00143 
00144                 int count = a1.Count + a2.Count;
00145                 PointF[] points = new PointF[count];
00146                 for (int i = 0; i < a1.Count; ++i)
00147                 {
00148                     points[i] = t.Transform(a1[i]);
00149                 }
00150                 for (int i = 0; i < a2.Count; ++i)
00151                 {
00152                     points[i + a1.Count] = t.Transform(a2[a2.Count - i - 1]);
00153                 }
00154 
00155                 g.FillPolygon(b, points);
00156             }
00157             else
00158             {
00159                 throw new NPlotException("One of bounds was set to null");
00160             }
00161         }
00162 
00163 
00167                 public Brush Brush
00168                 {
00169                         set
00170                         {
00171                                 brush_ = value;
00172                                 areaBrush_ = null;
00173                         }
00174                 }
00175 
00176 
00180                 public IRectangleBrush RectangleBrush
00181                 {
00182                         set
00183                         {
00184                                 brush_ = null;
00185                                 areaBrush_ = value;
00186                         }
00187                 }
00188 
00189 
00190         private VerticalLine vl1_;
00191         private VerticalLine vl2_;
00192 
00193         private HorizontalLine hl1_;
00194         private HorizontalLine hl2_;
00195 
00196         private LinePlot lp1_;
00197                 private LinePlot lp2_;
00198 
00199                 private Brush brush_ = new SolidBrush( Color.GhostWhite );
00200                 private IRectangleBrush areaBrush_ = null;
00201         }
00202 
00203 }

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