PiePlot.cs

Go to the documentation of this file.
00001 /*
00002 NPlot - A charting library for .NET
00003 
00004 PiePlot.cs
00005 Copyright (C) 2004
00006 Thierry Malo
00007 
00008 This library is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU Lesser General Public
00010 License as published by the Free Software Foundation; either
00011 version 2.1 of the License, or (at your option) any later version.
00012 
00013 This library is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 Lesser General Public License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General Public
00019 License along with this library; if not, write to the Free Software
00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022 $Id: PiePlot.cs,v 1.3 2004/10/23 07:08:35 mhowlett Exp $
00023 
00024 */
00025 
00026 /*
00027 using System;
00028 using System.Drawing;
00029 
00030 namespace scpl
00031 {
00035         public class PiePlot : BasePlot, IPlot
00036         {
00037                 public PiePlot(ISequenceAdapter datas)
00038                 {
00039                         //
00040                         // TODO : ajoutez ici la logique du constructeur
00041                         //
00042                         this.Data=datas;
00043 
00044                         _brushes=new Brush[_MaxBrush];
00045 
00046         _brushes[0] = Brushes.DarkBlue;
00047         _brushes[1] = Brushes.Yellow;
00048         _brushes[2] = Brushes.Green;
00049         _brushes[3] = Brushes.Brown;
00050         _brushes[4] = Brushes.Blue;
00051         _brushes[5] = Brushes.Red;
00052         _brushes[6] = Brushes.LightGreen;
00053         _brushes[7] = Brushes.Salmon;
00054 }
00055 
00056                 private ISequenceAdapter data_;
00057                 private double _Total;
00058                 const int _MaxBrush=8;
00059                 private Brush[] _brushes;
00060 
00061                 public ISequenceAdapter Data
00062                 {
00063                         get
00064                         {
00065                                 return data_;
00066                         }
00067                         set
00068                         {
00069                                 data_ = value;
00070 
00071                                 // calculate the sum of all value (this is related to 360°)
00072                                 _Total = 0;
00073                                 for ( int i=0; i<data_.Count; ++i )
00074                                 {
00075                                         _Total += data_[i].Y;
00076                                 }
00077                         }
00078                 }
00079 
00080                 #region SuggestXAxis
00081                 public virtual Axis SuggestXAxis()
00082                 {
00083                                 return data_.SuggestXAxis();
00084                 }
00085                 #endregion
00086 
00087                 #region SuggestXAxis
00088                 public virtual Axis SuggestYAxis()
00089                 {
00090                         return data_.SuggestYAxis();
00091                 }
00092                 #endregion
00093 
00094                 public virtual void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
00095                 {
00096                         int LastAngle=0,ReelAngle;
00097 
00098                         float rx=(xAxis.PhysicalMax.X - xAxis.PhysicalMin.X);
00099                         float ry=(yAxis.PhysicalMin.Y - yAxis.PhysicalMax.Y);
00100 
00101                         int h=(int) (ry * 0.8);
00102                         int w= (int) (rx * 0.8);
00103 
00104                         // This is to keep the pie based on a circle (i.e. inside a square)
00105                         int s=Math.Min(h,w);
00106 
00107                         // calculate boundary rectangle coordinate
00108                         int cy=(int) (yAxis.PhysicalMax.Y + (h * 1.2 - s) / 2);
00109                         int cx=(int) (xAxis.PhysicalMin.X + (w * 1.2 - s) / 2);
00110 
00111                         for (int i=0; i<this.Data.Count; ++i)
00112                         {
00113                                 ReelAngle = (int) (data_[i].Y * 360 / _Total);
00114                                 g.FillPie(_brushes[i % _MaxBrush], cx, cy, s, s, LastAngle, ReelAngle);
00115                                 LastAngle += ReelAngle;
00116                         }
00117                 }
00118         }
00119 }
00120 */

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