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.Drawing.Drawing2D;
00055 using System.Collections;
00056
00057 namespace NPlot
00058 {
00059
00064 public class Grid : IDrawable
00065 {
00066
00070 public enum GridType
00071 {
00075 None = 0,
00079 Coarse = 1,
00083 Fine = 2
00084 }
00085
00086
00090 public Grid()
00091 {
00092 minorGridPen_ = new Pen( Color.LightGray );
00093 float[] pattern = {1.0f, 2.0f};
00094 minorGridPen_.DashPattern = pattern;
00095
00096 majorGridPen_ = new Pen( Color.LightGray );
00097
00098 horizontalGridType_ = GridType.Coarse;
00099
00100 verticalGridType_ = GridType.Coarse;
00101 }
00102
00103
00107 public GridType HorizontalGridType
00108 {
00109 get
00110 {
00111 return horizontalGridType_;
00112 }
00113 set
00114 {
00115 horizontalGridType_ = value;
00116 }
00117 }
00118 GridType horizontalGridType_;
00119
00120
00124 public GridType VerticalGridType
00125 {
00126 get
00127 {
00128 return verticalGridType_;
00129 }
00130 set
00131 {
00132 verticalGridType_ = value;
00133 }
00134 }
00135 GridType verticalGridType_;
00136
00137
00141 public System.Drawing.Pen MajorGridPen
00142 {
00143 get
00144 {
00145 return majorGridPen_;
00146 }
00147 set
00148 {
00149 majorGridPen_ = value;
00150 }
00151 }
00152 private Pen majorGridPen_;
00153
00154
00158 public System.Drawing.Pen MinorGridPen
00159 {
00160 get
00161 {
00162 return minorGridPen_;
00163 }
00164 set
00165 {
00166 minorGridPen_ = value;
00167 }
00168 }
00169 private Pen minorGridPen_;
00170
00171
00181 private void DrawGridLines(
00182 Graphics g, PhysicalAxis axis, PhysicalAxis orthogonalAxis,
00183 System.Collections.ArrayList a, bool horizontal, Pen p )
00184 {
00185 for (int i=0; i<a.Count; ++i)
00186 {
00187 PointF p1 = axis.WorldToPhysical((double)a[i], true);
00188 PointF p2 = p1;
00189 PointF p3 = orthogonalAxis.PhysicalMax;
00190 PointF p4 = orthogonalAxis.PhysicalMin;
00191 if (horizontal)
00192 {
00193 p1.Y = p4.Y;
00194 p2.Y = p3.Y;
00195 }
00196 else
00197 {
00198 p1.X = p4.X;
00199 p2.X = p3.X;
00200 }
00201
00202 g.DrawLine( p, (int)p1.X, (int)p1.Y, (int)p2.X, (int)p2.Y );
00203 }
00204 }
00205
00212 public void Draw( Graphics g, PhysicalAxis xAxis, PhysicalAxis yAxis )
00213 {
00214
00215 ArrayList xLargePositions = null;
00216 ArrayList yLargePositions = null;
00217 ArrayList xSmallPositions = null;
00218 ArrayList ySmallPositions = null;
00219
00220 if (this.horizontalGridType_ != GridType.None)
00221 {
00222 xAxis.Axis.WorldTickPositions_FirstPass( xAxis.PhysicalMin, xAxis.PhysicalMax, out xLargePositions, out xSmallPositions );
00223 DrawGridLines( g, xAxis, yAxis, xLargePositions, true, this.MajorGridPen );
00224 }
00225
00226 if (this.verticalGridType_ != GridType.None)
00227 {
00228 yAxis.Axis.WorldTickPositions_FirstPass( yAxis.PhysicalMin, yAxis.PhysicalMax, out yLargePositions, out ySmallPositions );
00229 DrawGridLines( g, yAxis, xAxis, yLargePositions, false, this.MajorGridPen );
00230 }
00231
00232
00233 if (this.horizontalGridType_ == GridType.Fine)
00234 {
00235 xAxis.Axis.WorldTickPositions_SecondPass( xAxis.PhysicalMin, xAxis.PhysicalMax, xLargePositions, ref xSmallPositions );
00236 DrawGridLines( g, xAxis, yAxis, xSmallPositions, true, this.MinorGridPen );
00237 }
00238
00239 if (this.verticalGridType_ == GridType.Fine)
00240 {
00241 yAxis.Axis.WorldTickPositions_SecondPass( yAxis.PhysicalMin, yAxis.PhysicalMax, yLargePositions, ref ySmallPositions );
00242 DrawGridLines( g, yAxis, xAxis, ySmallPositions, false, this.MinorGridPen );
00243 }
00244
00245 }
00246
00247 }
00248 }