/******************************************************************** gYAxis Implementation Copyright (c)2011 Mark Watkins License: GPL *********************************************************************/ #include #include #include "gYAxis.h" gYAxis::gYAxis(QColor col) :gLayer(NULL) { color.clear(); color.push_back(col); m_show_major_lines=true; m_show_minor_lines=true; m_yaxis_scale=1; } gYAxis::~gYAxis() { } void gYAxis::Plot(gGraphWindow &w,float scrx,float scry) { static QColor DARK_GREY(0xb8,0xb8,0xb8,0xa0); static QColor LIGHT_GREY(0xd8,0xd8,0xd8,0xa0); float x,y; int labelW=0; double miny=w.min_y; double maxy=w.max_y; if (maxy==miny) return; //if ((w.max_x-w.min_x)==0) // return; int start_px=w.GetLeftMargin(); int start_py=w.GetBottomMargin(); int width=scrx-(w.GetRightMargin()+start_px); int topm=w.GetTopMargin(); int height=scry-(topm+start_py); if (height<0) return; const QColor & linecol1=LIGHT_GREY; const QColor & linecol2=DARK_GREY; QString fd="0"; GetTextExtent(fd,x,y); double max_yticks=round(height / (y+15.0)); // plus spacing between lines double yt=1/max_yticks; double mxy=MAX(maxy,fabs(miny)); double mny=MIN(maxy,fabs(miny)); if (miny<0) mny=-mny; if (maxy<0) mxy=-mxy; double rxy=mxy-mny; double ymult=height/rxy; double min_ytick=rxy*yt; float ty,h; qint32 vertcnt=0; GLshort * vertarray=vertex_array[0]; if (vertarray==NULL) { qWarning() << "VertArray==NULL"; return; } glColor4ub(linecol1.red(),linecol1.green(),linecol1.blue(),linecol1.alpha()); glLineWidth(1); if (min_ytick<=0) { qDebug() << "min_ytick error in gYAxis::Plot()"; return; } if (min_ytick>=1000000) { min_ytick=100; } for (double i=miny+(min_ytick/2.0); i miny)) { glBegin(GL_LINES); glVertex2f(start_px+1, h); glVertex2f(start_px+width, h); glEnd(); } if (vertcnt>maxverts) { qWarning() << "vertarray bounds exceeded in gYAxis for " << w.Title() << "graph" << "MinY =" <>1); glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing }