From fd09eb4307d19ba3d77569c6a23b4b400a538601 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sat, 26 Oct 2013 09:11:37 +1000 Subject: [PATCH] Fix some physmin/max yaxis scaling issues --- sleepyhead/Graphs/gGraphView.cpp | 2 +- sleepyhead/Graphs/gLineChart.cpp | 12 +++++++---- sleepyhead/Graphs/gSummaryChart.cpp | 32 +++++++++++++++++++++++------ sleepyhead/Graphs/gYAxis.cpp | 18 ++++++++++------ 4 files changed, 47 insertions(+), 17 deletions(-) diff --git a/sleepyhead/Graphs/gGraphView.cpp b/sleepyhead/Graphs/gGraphView.cpp index 15c95e91..e5fbae5c 100644 --- a/sleepyhead/Graphs/gGraphView.cpp +++ b/sleepyhead/Graphs/gGraphView.cpp @@ -838,7 +838,7 @@ void gToolTip::paint() //actually paints it. lines_drawn_this_frame+=4; quads_drawn_this_frame+=1; - QBrush brush(QColor(255,255,128,255)); + QBrush brush(QColor(255,255,128,200)); brush.setStyle(Qt::SolidPattern); painter.setBrush(brush); painter.setPen(QColor(0,0,0,255)); diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp index 60115e85..d48e58a3 100644 --- a/sleepyhead/Graphs/gLineChart.cpp +++ b/sleepyhead/Graphs/gLineChart.cpp @@ -160,12 +160,11 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height) }*/ if (w.zoomY()==0) { - miny=m_physminy; - maxy=m_physmaxy; + miny=m_physminy, maxy=m_physmaxy; } else { miny=w.min_y, maxy=w.max_y; - w.roundY(miny,maxy); } + w.roundY(miny,maxy); double xx=maxx-minx; double xmult=double(width)/xx; @@ -698,12 +697,17 @@ void AHIChart::paint(gGraph & w,int left, int top, int width, int height) EventDataType miny,maxy; double minx,maxx; - miny=w.min_y, maxy=w.max_y; maxx=w.max_x, minx=w.min_x; // hmmm.. subtract_offset.. + if (w.zoomY()==0) { + miny=w.physMinY(); + maxy=w.physMaxY(); + } else { + miny=w.min_y, maxy=w.max_y; + } w.roundY(miny,maxy); double xx=maxx-minx; diff --git a/sleepyhead/Graphs/gSummaryChart.cpp b/sleepyhead/Graphs/gSummaryChart.cpp index c5e865db..9d82011b 100644 --- a/sleepyhead/Graphs/gSummaryChart.cpp +++ b/sleepyhead/Graphs/gSummaryChart.cpp @@ -48,6 +48,8 @@ void SummaryChart::SetDay(Day * nullday) m_goodcodes.clear(); m_miny=999999999; m_maxy=-999999999; + m_physmaxy=0; + m_physminy=0; m_minx=0; m_maxx=0; @@ -107,6 +109,7 @@ void SummaryChart::SetDay(Day * nullday) } int suboffset; SummaryType type; + bool first=true; for (QMap >::iterator d=PROFILE.daylist.begin();d!=PROFILE.daylist.end();d++) { tt=QDateTime(d.key(),QTime(0,0,0),Qt::UTC).toTime_t(); @@ -144,10 +147,16 @@ void SummaryChart::SetDay(Day * nullday) m_times[dn][s]=tmp2; - if (tmp2 < m_miny) + if (first) { m_miny=tmp2; - if (tmp2+tmp > m_maxy) m_maxy=tmp2+tmp; + first=false; + } else { + if (tmp2 < m_miny) + m_miny=tmp2; + if (tmp2+tmp > m_maxy) + m_maxy=tmp2+tmp; + } } if (total>0) { m_days[dn]=day; @@ -248,7 +257,8 @@ void SummaryChart::SetDay(Day * nullday) } // m_minx=qint64(QDateTime(PROFILE.FirstDay(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L; m_maxx=qint64(QDateTime(PROFILE.LastDay(),QTime(23,59,0),Qt::UTC).toTime_t())*1000L; - + m_physmaxy=m_maxy; + m_physminy=m_miny; } QColor brighten(QColor color) @@ -290,9 +300,19 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height) qint64 xx=maxx - minx; float days=double(xx)/86400000.0; - EventDataType maxy=m_maxy; - EventDataType miny=m_miny; - w.roundY(miny,maxy); + + EventDataType maxy; + EventDataType miny; + + if (w.zoomY()==0) { + maxy=m_physmaxy; + miny=m_physminy; + w.roundY(miny,maxy); + } else { + maxy=m_maxy; + miny=m_miny; + w.roundY(miny,maxy); + } EventDataType yy=maxy-miny; EventDataType ymult=float(height-2)/yy; diff --git a/sleepyhead/Graphs/gYAxis.cpp b/sleepyhead/Graphs/gYAxis.cpp index 30be462d..840df2e2 100644 --- a/sleepyhead/Graphs/gYAxis.cpp +++ b/sleepyhead/Graphs/gYAxis.cpp @@ -29,11 +29,18 @@ void gXGrid::paint(gGraph & w,int left,int top, int width, int height) gVertexBuffer * stippled, * lines; - EventDataType miny=w.min_y; - EventDataType maxy=w.max_y; + EventDataType miny,maxy; - if (miny<0) { // even it up if it's starts negative - miny=-MAX(fabs(miny),fabs(maxy)); + if (w.zoomY()==0) { + miny=w.physMinY(); + maxy=w.physMaxY(); + } else { + miny=w.min_y; + maxy=w.max_y; + + if (miny<0) { // even it up if it's starts negative + miny=-MAX(fabs(miny),fabs(maxy)); + } } w.roundY(miny,maxy); @@ -277,9 +284,8 @@ void gYAxis::paint(gGraph & w,int left,int top, int width, int height) if (miny<0) { // even it up if it's starts negative miny=-MAX(fabs(miny),fabs(maxy)); } - - w.roundY(miny,maxy); } + w.roundY(miny,maxy); EventDataType dy=maxy-miny;