00001 #pragma ident "$Id: Axis.hpp 2091 2009-08-21 14:24:47Z afarris $"
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef VPLOT_AXIS_H
00028 #define VPLOT_AXIS_H
00029
00030 #include <cmath>
00031 #include <cstdio>
00032 #include "AxisStyle.hpp"
00033 #include "GraphicsConstants.hpp"
00034 #include "Frame.hpp"
00035
00039 namespace vplot
00040 {
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00056 class Axis
00057 {
00058 public:
00059 static const double RIGHT;
00060 static const double UP ;
00061 static const double LEFT ;
00062 static const double DOWN ;
00063 static const double N ;
00064 static const double E ;
00065 static const double S ;
00066 static const double W ;
00067 static const double NORTH;
00068 static const double EAST ;
00069 static const double SOUTH;
00070 static const double WEST ;
00071
00072
00073
00074
00075
00087 Axis(double ix, double iy, double ex, double ey, double length, double imin, double imax, const AxisStyle &style=AxisStyle())
00088 {
00089
00090
00091
00092
00093
00094
00095
00096 double direction;
00097 if(ex==ix)
00098 {
00099 if(ey < iy) direction=vdraw::PI;
00100 else direction=0;
00101 }
00102 else if(ey==iy)
00103 {
00104 if(ex < ix) direction=vdraw::PI+vdraw::HALF_PI;
00105 else direction=vdraw::HALF_PI;
00106 }
00107 else
00108 {
00109 direction=atan((ey-iy)/(ex-ix));
00110 if(direction < 0) direction=vdraw::TWO_PI+direction;
00111 }
00112 init(ix,iy,direction,length,imin,imax,style);
00113 }
00114
00125 Axis(double ix, double iy, double direction, double length, double imin, double imax, const AxisStyle &style=AxisStyle())
00126 {
00127 init(ix,iy,direction,length,imin,imax,style);
00128 }
00129
00133 ~Axis()
00134 {
00135 }
00136
00137
00138
00139
00141 inline void setPosition(double ix, double iy) { x=ix; y=iy; }
00142
00144 inline void setLength(double length) { line_length=length; }
00145
00147 inline void setRange(double imin, double imax) { min=imin; max=imax; axesMin=min; axesMax=max; }
00148
00150 inline void setGap(double igap) { gap=igap; }
00151
00153 void setAngle(double angle);
00154
00155
00156
00157
00158
00163 void drawToFrame(const vdraw::Frame &ff);
00164
00172 bool pointFromValue(double &x, double &y, double value);
00173
00182 inline bool labelPointAbove(double &x, double &y, double &rotation, double value)
00183 {
00184 return labelPoint(x,y,rotation,value,AxisStyle::ABOVE);
00185 }
00186
00195 inline bool labelPointBelow(double &x, double &y, double &rotation, double value)
00196 {
00197 return labelPoint(x,y,rotation,value,AxisStyle::BELOW);
00198 }
00199
00201 AxisStyle axis_style;
00202
00203 protected:
00204
00205
00206
00207
00218 void init(double ix, double iy, double direction, double length, double imin, double imax, const AxisStyle &style);
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00244 inline void fromRatio(double &x, double &y, double ratio)
00245 {
00246 x = this->x+cosdir*line_length*ratio;
00247 y = this->y+sindir*line_length*ratio;
00248 }
00249
00255 inline void axisTick(double ratio, double dist)
00256 {
00257 axisTickRecursive(
00258 true,
00259 axis_style.tick_recursion_depth,
00260 ratio,
00261 dist,
00262 axis_style.major_tick_length);
00263 }
00264
00273 void axisTickRecursive(bool draw, int depth, double ratio, double dist, double length);
00274
00280 void drawTick(double ratio, double length);
00281
00291 void fromTic(double &x1, double &y1, double &x2, double &y2,
00292 double distratio, double length);
00293
00308 void guessTickInfo(double &startpos, double &startval, double &distpos, double &distval);
00309
00316 bool label(double value, int direction, const vdraw::TextStyle &style);
00317
00325 bool label(const char *str, double value, int direction, const vdraw::TextStyle &style);
00326
00334 bool label(vdraw::Text &t, double value, int direction, const vdraw::TextStyle &style);
00335
00340 bool labelPoint(double &x, double &y, double &rotation, double value, int direction);
00341
00342
00343
00344
00347 vdraw::Frame f;
00348
00350 double x;
00351
00353 double y;
00354
00356 double line_length;
00357
00359 double line_direction;
00361 double sindir;
00363 double cosdir;
00365 double sintic;
00367 double costic;
00368
00369
00370
00371
00373 double max;
00376 double axesMax;
00377
00378
00380 double min;
00383 double axesMin;
00384
00385
00388 double gap;
00389 };
00390 }
00391
00392 #endif //VPLOT_AXIS_H
00393