00001
00002
00003
00004
00005 #include <stdlib.h>
00006 #include <math.h>
00007 #include <stdio.h>
00008
00009 #include "xygridlog.h"
00010
00011 const char* xy_id_xygridlog_cpp="$Id: xygridlog.cpp,v 1.1 2002/01/23 16:09:37 clinio Exp $";
00012
00013 XYGridLog::XYGridLog (double mn, double mx, double p, long color,
00014 double rot, double step, xybool visible) :
00015 XYGrid(mn, mx, p, color, rot, step, visible)
00016 {
00017 }
00018
00019 XYGridLog::XYGridLog (double mn, double mx, double p, long color,
00020 int style, double rot, double step, xybool visible) :
00021 XYGrid(mn, mx, p, color, style, rot, step, visible )
00022 {
00023 }
00024
00025 void XYGridLog::draw (int xmin, int ymin, int xmax, int ymax) const
00026 {
00027 if (visible() == xyfalse) return;
00028 if (min() <= 0.00001) return;
00029
00030 int mode = cdClip(CD_CLIPON);
00031
00032
00033 int oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax;
00034 cdGetClipArea (&oldclip_xmin, &oldclip_xmax, &oldclip_ymin, &oldclip_ymax);
00035
00036
00037
00038
00039 double rot_rad = _rot * XY_PI / 180.0;
00040
00041
00042 double x1, y1;
00043 position (&x1, &y1);
00044
00045
00046 double x2 = x1 + _size * cos (rot_rad);
00047 double y2 = y1 + _size * sin (rot_rad);
00048
00049
00050 if (mtEqual(x1, x2)) x2 = x1;
00051 if (mtEqual(y1, y2)) y2 = y1;
00052
00053
00054
00055 cdLineWidth (1);
00056 cdLineStyle (_style);
00057 cdForeground (_color);
00058
00059
00060
00061 if (_step > 0.0)
00062 {
00063 double xorigin, yorigin;
00064 position(&xorigin, &yorigin);
00065
00066 double decade_step;
00067 for( double val = _mn; val <= _mx; val += decade_step*_step )
00068 {
00069 int current_decade = mtDecade(val);
00070 decade_step = pow( 10, current_decade );
00071 double dx, dy;
00072 mtRotate( (log10(val)-log10(_mn))*_size / (log10(_mx)-log10(_mn)),
00073 -1, rot_rad, &dx, &dy);
00074
00075 double other_dx, other_dy;
00076 mtRotate( (log10(val)-log10(_mn))*_size / (log10(_mx)-log10(_mn)),
00077 1, rot_rad, &other_dx, &other_dy);
00078
00079 double xtick = xorigin + dx;
00080 double ytick = yorigin + dy;
00081
00082 wdLine( xtick, ytick, xorigin+other_dx, yorigin+other_dy );
00083 }
00084
00085 }
00086
00087 cdClip(mode);
00088
00089 cdClipArea(oldclip_xmin, oldclip_xmax, oldclip_ymin, oldclip_ymax);
00090 }
00091
00092