00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 using System;
00053 using System.Drawing;
00054 using System.Diagnostics;
00055
00056 namespace NPlot
00057 {
00058
00062 public class LinePlot : BaseSequencePlot, IPlot, ISequencePlot
00063 {
00064
00068 public LinePlot()
00069 {
00070 }
00071
00072
00077 public LinePlot( object dataSource )
00078 {
00079 this.DataSource = dataSource;
00080 }
00081
00082
00088 public LinePlot( object ordinateData, object abscissaData )
00089 {
00090 this.OrdinateData = ordinateData;
00091 this.AbscissaData = abscissaData;
00092 }
00093
00094
00102 public void DrawLineOrShadow( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis, bool drawShadow )
00103 {
00104 Pen shadowPen = null;
00105 if (drawShadow)
00106 {
00107 shadowPen = (Pen)this.Pen.Clone();
00108 shadowPen.Color = this.ShadowColor;
00109 }
00110
00111 SequenceAdapter data =
00112 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );
00113
00114 ITransform2D t = Transform2D.GetTransformer( xAxis, yAxis );
00115
00116 int numberPoints = data.Count;
00117
00118 if (data.Count == 0)
00119 {
00120 return;
00121 }
00122
00123
00124
00125 if (numberPoints == 1)
00126 {
00127 PointF physical = t.Transform( data[0] );
00128
00129 if (drawShadow)
00130 {
00131 g.DrawLine( shadowPen,
00132 physical.X - 0.5f + this.ShadowOffset.X,
00133 physical.Y + this.ShadowOffset.Y,
00134 physical.X + 0.5f + this.ShadowOffset.X,
00135 physical.Y + this.ShadowOffset.Y );
00136 }
00137 else
00138 {
00139 g.DrawLine( Pen, physical.X-0.5f, physical.Y, physical.X+0.5f, physical.Y);
00140 }
00141 }
00142 else
00143 {
00144 for (int i = 1; i < numberPoints; ++i)
00145 {
00146
00147 double dx1 = data[i-1].X;
00148 double dx2 = data[i].X;
00149 double dy1 = data[i-1].Y;
00150 double dy2 = data[i].Y;
00151 if ( Double.IsNaN(dx1) || Double.IsNaN(dy1) ||
00152 Double.IsNaN(dx2) || Double.IsNaN(dy2) )
00153 {
00154 continue;
00155 }
00156
00157
00158 PointF p1 = t.Transform( data[i-1] );
00159 PointF p2 = t.Transform( data[i] );
00160
00161
00162
00163 if (p1.Equals(p2))
00164 continue;
00165
00166 if (drawShadow)
00167 {
00168 g.DrawLine( shadowPen,
00169 p1.X + ShadowOffset.X,
00170 p1.Y + ShadowOffset.Y,
00171 p2.X + ShadowOffset.X,
00172 p2.Y + ShadowOffset.Y );
00173 }
00174 else
00175 {
00176 g.DrawLine( Pen, p1.X, p1.Y, p2.X, p2.Y );
00177 }
00178 }
00179 }
00180
00181 }
00182
00183
00190 public void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
00191 {
00192 if (this.shadow_)
00193 {
00194 this.DrawLineOrShadow( g, xAxis, yAxis, true );
00195 }
00196
00197 this.DrawLineOrShadow( g, xAxis, yAxis, false );
00198 }
00199
00200
00205 public Axis SuggestXAxis()
00206 {
00207 SequenceAdapter data_ =
00208 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );
00209
00210 return data_.SuggestXAxis();
00211 }
00212
00213
00218 public Axis SuggestYAxis()
00219 {
00220 SequenceAdapter data_ =
00221 new SequenceAdapter( this.DataSource, this.DataMember, this.OrdinateData, this.AbscissaData );
00222
00223 return data_.SuggestYAxis();
00224 }
00225
00226
00230 public bool Shadow
00231 {
00232 get
00233 {
00234 return shadow_;
00235 }
00236 set
00237 {
00238 shadow_ = value;
00239 }
00240 }
00241 private bool shadow_ = false;
00242
00243
00247 public Color ShadowColor
00248 {
00249 get
00250 {
00251 return shadowColor_;
00252 }
00253 set
00254 {
00255 shadowColor_ = value;
00256 }
00257 }
00258 private Color shadowColor_ = Color.FromArgb(100,100,100);
00259
00260
00264 public Point ShadowOffset
00265 {
00266 get
00267 {
00268 return shadowOffset_;
00269 }
00270 set
00271 {
00272 shadowOffset_ = value;
00273 }
00274 }
00275 private Point shadowOffset_ = new Point( 1, 1 );
00276
00277
00283 public virtual void DrawInLegend(Graphics g, Rectangle startEnd)
00284 {
00285 g.DrawLine(pen_, startEnd.Left, (startEnd.Top + startEnd.Bottom) / 2,
00286 startEnd.Right, (startEnd.Top + startEnd.Bottom) / 2);
00287 }
00288
00289
00293 public System.Drawing.Pen Pen
00294 {
00295 get
00296 {
00297 return pen_;
00298 }
00299 set
00300 {
00301 pen_ = value;
00302 }
00303 }
00304 private System.Drawing.Pen pen_ = new Pen(Color.Black);
00305
00306
00310 public System.Drawing.Color Color
00311 {
00312 set
00313 {
00314 if (pen_ != null)
00315 {
00316 pen_.Color = value;
00317 }
00318 else
00319 {
00320 pen_ = new Pen(value);
00321 }
00322 }
00323 get
00324 {
00325 return pen_.Color;
00326 }
00327 }
00328
00329
00330 }
00331 }