/******************************************************************** gYAxis Implementation Copyright (c)2011 Mark Watkins License: GPL *********************************************************************/ #include #include #include "gYAxis.h" gYAxis::gYAxis(QColor col) :gLayer(EmptyChannel) { m_line_color=col; m_text_color=col; m_major_color=QColor(190,190,190,64); m_minor_color=QColor(220,220,220,64); 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) { float x,y; int labelW=0; double miny=w.min_y; double maxy=w.max_y; double dy=maxy-miny; if (dy<=0) { if (miny==0) return; else { miny+=1; maxy-=1; dy=2; } } int m; if (maxy>500) { m=ceil(maxy/100.0); maxy=m*100; m=floor(miny/100.0); miny=m*100; } else if (maxy>150) { m=ceil(maxy/50.0); maxy=m*50; m=floor(miny/50.0); miny=m*50; } else if (maxy>80) { m=ceil(maxy/20.0); maxy=m*20; m=floor(miny/20.0); miny=m*20; } else if (maxy>30) { m=ceil(maxy/10.0); maxy=m*10; m=floor(miny/10.0); miny=m*10; } else if (maxy>5) { m=ceil(maxy/5.0); maxy=m*5; m=floor(miny/5.0); miny=m*5; } else { maxy=ceil(maxy); if (maxy<1) maxy=1; miny=floor(miny); //if (miny<1) miny=0; } //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; 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=(GLshort *)vertex_array[0]; qint32 minorvertcnt=0; GLshort * minorvertarray=(GLshort *)vertex_array[1]; qint32 majorvertcnt=0; GLshort * majorvertarray=(GLshort *)vertex_array[2]; if ((vertarray==NULL) || (minorvertarray==NULL) || (majorvertarray==NULL)) { qWarning() << "gYAxis::Plot() VertArray==NULL"; return; } if (min_ytick<=0) { qDebug() << "min_ytick error in gYAxis::Plot()"; return; } if (min_ytick>=1000000) { min_ytick=100; } double q=((maxy-(miny+(min_ytick/2.0)))/min_ytick)*4; if (q>=maxverts) { qDebug() << "Would exeed maxverts. Should be another two bounds exceeded messages after this. (I can do a minor optimisation by disabling the other checks if this turns out to be consistent)" << q << maxverts; } for (double i=miny+(min_ytick/2.0); i miny)) { minorvertarray[minorvertcnt++]=start_px+1; minorvertarray[minorvertcnt++]=h; minorvertarray[minorvertcnt++]=start_px+width; minorvertarray[minorvertcnt++]=h; } if (vertcnt>=maxverts) { // Should only need to check one.. The above check should be enough. qWarning() << "vertarray bounds exceeded in gYAxis for " << w.Title() << "graph" << "MinY =" <>1); w.qglColor(m_minor_color); glVertexPointer(2, GL_SHORT, 0, minorvertarray); glDrawArrays(GL_LINES, 0, minorvertcnt>>1); w.qglColor(m_major_color); glVertexPointer(2, GL_SHORT, 0, majorvertarray); glDrawArrays(GL_LINES, 0, majorvertcnt>>1); glDisableClientState(GL_VERTEX_ARRAY); // deactivate vertex arrays after drawing }