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 {
00078 public class PhysicalAxis
00079 {
00080
00084 private PhysicalAxis()
00085 {
00086 }
00087
00088
00095 public PhysicalAxis( Axis a, Point physicalMin, Point physicalMax )
00096 {
00097 this.Axis = a;
00098 this.PhysicalMin = physicalMin;
00099 this.PhysicalMax = physicalMax;
00100 }
00101
00102
00107 public virtual Rectangle GetBoundingBox()
00108 {
00109 System.Drawing.Bitmap scratchArea_ = new System.Drawing.Bitmap( 1, 1 );
00110 Graphics g = Graphics.FromImage( scratchArea_ );
00111 Rectangle bounds;
00112 this.Draw( g, out bounds );
00113 return bounds;
00114 }
00115
00116
00123 public virtual void Draw( System.Drawing.Graphics g, out Rectangle boundingBox )
00124 {
00125 this.Axis.Draw( g, PhysicalMin, PhysicalMax, out boundingBox );
00126 }
00127
00128
00136 public PointF WorldToPhysical( double coord, bool clip )
00137 {
00138 return Axis.WorldToPhysical( coord, PhysicalMin, PhysicalMax, clip );
00139 }
00140
00141
00152 public double PhysicalToWorld( Point p, bool clip )
00153 {
00154 return Axis.PhysicalToWorld( p, PhysicalMin, PhysicalMax, clip );
00155 }
00156
00157
00164 public void SetWorldLimitsFromPhysical( Point min, Point max )
00165 {
00166 double minc;
00167 double maxc;
00168 if (Axis != null)
00169 {
00170 minc = Axis.WorldMin;
00171 maxc = Axis.WorldMax;
00172 if ( !Axis.Reversed )
00173 {
00174 double tmp = this.PhysicalToWorld(min,true);
00175 Axis.WorldMax = this.PhysicalToWorld(max,true);
00176 Axis.WorldMin = tmp;
00177 }
00178 else
00179 {
00180 double tmp = this.PhysicalToWorld(min,true);
00181 Axis.WorldMin = this.PhysicalToWorld(max,true);
00182 Axis.WorldMax = tmp;
00183 }
00184
00185
00186
00187
00188
00189
00190
00191 double half = (Axis.WorldMin + Axis.WorldMax)/2;
00192 double width = Axis.WorldMax - Axis.WorldMin;
00193 if (Math.Abs(half/width) > 1.0e12)
00194 {
00195 Axis.WorldMin = minc;
00196 Axis.WorldMax = maxc;
00197 }
00198 }
00199 }
00200
00201
00205 public Point PhysicalMin
00206 {
00207 get
00208 {
00209 return physicalMin_;
00210 }
00211 set
00212 {
00213 physicalMin_ = value;
00214 }
00215 }
00216 private Point physicalMin_;
00217
00218
00222 public Point PhysicalMax
00223 {
00224 get
00225 {
00226 return physicalMax_;
00227 }
00228 set
00229 {
00230 physicalMax_ = value;
00231 }
00232 }
00233 private Point physicalMax_;
00234
00235
00239 public Axis Axis
00240 {
00241 get
00242 {
00243 return axis_;
00244 }
00245 set
00246 {
00247 axis_ = value;
00248 }
00249 }
00250 private Axis axis_;
00251
00252
00256 public int PhysicalLength
00257 {
00258 get
00259 {
00260 return Utils.Distance( PhysicalMin, PhysicalMax );
00261 }
00262 }
00263
00267 public double PixelWorldLength
00268 {
00269 get
00270 {
00271 return this.Axis.WorldLength / this.PhysicalLength;
00272 }
00273 }
00274
00275 }
00276 }