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
00055 namespace NPlot
00056 {
00057
00061 public class HorizontalLine : IPlot
00062 {
00063
00068 public HorizontalLine( double ordinateValue )
00069 {
00070 this.value_ = ordinateValue;
00071 }
00072
00073
00079 public HorizontalLine( double ordinateValue, Color color )
00080 {
00081 this.value_ = ordinateValue;
00082 this.pen_ = new Pen( color );
00083 }
00084
00090 public HorizontalLine( double ordinateValue, Pen pen )
00091 {
00092 this.value_ = ordinateValue;
00093 this.pen_ = pen;
00094 }
00095
00096
00102 public void DrawInLegend(System.Drawing.Graphics g, System.Drawing.Rectangle startEnd)
00103 {
00104 g.DrawLine( pen_, startEnd.Left, (startEnd.Top + startEnd.Bottom)/2,
00105 startEnd.Right, (startEnd.Top + startEnd.Bottom)/2 );
00106 }
00107
00108
00112 public string Label
00113 {
00114 get
00115 {
00116 return label_;
00117 }
00118 set
00119 {
00120 this.label_ = value;
00121 }
00122 }
00123
00124 private string label_ = "";
00125
00126
00130 public bool ShowInLegend
00131 {
00132 get
00133 {
00134 return showInLegend_;
00135 }
00136 set
00137 {
00138 this.showInLegend_ = value;
00139 }
00140 }
00141 private bool showInLegend_ = false;
00142
00143
00148 public Axis SuggestXAxis()
00149 {
00150 return null;
00151 }
00152
00153
00158 public Axis SuggestYAxis()
00159 {
00160 return new LinearAxis( this.value_, this.value_ );
00161 }
00162
00171 public void WriteData(System.Text.StringBuilder sb, RectangleD region, bool onlyInRegion)
00172 {
00173
00174
00175 if (value_ > region.Y+region.Height || value_ < region.Y)
00176 {
00177 if (onlyInRegion)
00178 {
00179 return;
00180 }
00181 }
00182
00183 sb.Append( "Label: " );
00184 sb.Append( this.Label );
00185 sb.Append( "\r\n" );
00186 sb.Append( value_.ToString() );
00187 sb.Append( "\r\n" );
00188
00189 }
00190
00197 public void Draw(System.Drawing.Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis)
00198 {
00199 int xMin = xAxis.PhysicalMin.X;
00200 int xMax = xAxis.PhysicalMax.X;
00201
00202 xMin += pixelIndent_;
00203 xMax -= pixelIndent_;
00204
00205 float length = Math.Abs(xMax - xMin);
00206 float lengthDiff = length - length*scale_;
00207 float indentAmount = lengthDiff/2;
00208
00209 xMin += (int)indentAmount;
00210 xMax -= (int)indentAmount;
00211
00212 int yPos = (int)yAxis.WorldToPhysical( value_, false ).Y;
00213
00214 g.DrawLine( pen_, new System.Drawing.Point( xMin, yPos ), new System.Drawing.Point( xMax, yPos ) );
00215
00216
00217 }
00218
00219 private double value_;
00223 public double OrdinateValue
00224 {
00225 get
00226 {
00227 return value_;
00228 }
00229 set
00230 {
00231 value_ = value;
00232 }
00233 }
00234
00235 private Pen pen_ = new Pen( Color.Black );
00239 public Pen Pen
00240 {
00241 get
00242 {
00243 return pen_;
00244 }
00245 set
00246 {
00247 pen_ = value;
00248 }
00249 }
00250
00251
00255 public int PixelIndent
00256 {
00257 get
00258 {
00259 return pixelIndent_;
00260 }
00261 set
00262 {
00263 pixelIndent_ = value;
00264 }
00265 }
00266 private int pixelIndent_ = 0;
00267
00268
00273 public float LengthScale
00274 {
00275 get
00276 {
00277 return scale_;
00278 }
00279 set
00280 {
00281 scale_ = value;
00282 }
00283 }
00284 private float scale_ = 1.0f;
00285
00286 }
00287 }