From fb9143ef8fa3d036ad0bcb69a9eb83188ce8c6d3 Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Sun, 18 Sep 2011 02:47:57 +1000 Subject: [PATCH] Graph Tweaks, Implementation of Min/Max Y cap code --- Graphs/gGraphView.cpp | 12 +++- Graphs/gGraphView.h | 8 ++- Graphs/gLineChart.cpp | 3 + Graphs/gSummaryChart.cpp | 150 +-------------------------------------- Graphs/gXAxis.cpp | 2 +- SleepLib/schema.cpp | 2 +- overview.cpp | 4 +- 7 files changed, 24 insertions(+), 157 deletions(-) diff --git a/Graphs/gGraphView.cpp b/Graphs/gGraphView.cpp index 80ef2ada..f1291358 100644 --- a/Graphs/gGraphView.cpp +++ b/Graphs/gGraphView.cpp @@ -19,14 +19,14 @@ void InitGraphs() { if (!_graph_init) { defaultfont=new QFont("Sans Serif",10); - defaultfont->setPixelSize(11); - mediumfont=new QFont("Sans Serif",12); + // defaultfont->setPixelSize(11); + mediumfont=new QFont("Serif",11); bigfont=new QFont("Serif",35); defaultfont->setStyleHint(QFont::SansSerif,QFont::OpenGLCompatible); mediumfont->setStyleHint(QFont::SansSerif,QFont::OpenGLCompatible); bigfont->setStyleHint(QFont::Serif ,QFont::OpenGLCompatible); - + mediumfont->setBold(true); _graph_init=true; } } @@ -550,6 +550,8 @@ gGraph::gGraph(gGraphView *graphview,QString title,int height,short group) : m_quad=new GLBuffer(QColor(128,128,255,128),64,GL_QUADS); m_quad->forceAntiAlias(true); + f_miny=f_maxy=0; + m_forceMinY=m_forceMaxY=false; } gGraph::~gGraph() { @@ -1133,6 +1135,7 @@ EventDataType gGraph::MinY() { bool first=true; EventDataType val=0,tmp; + if (m_forceMinY) return rmin_y=f_miny; for (QVector::iterator l=m_layers.begin();l!=m_layers.end();l++) { if ((*l)->isEmpty()) continue; tmp=(*l)->Miny(); @@ -1150,6 +1153,7 @@ EventDataType gGraph::MaxY() { bool first=true; EventDataType val=0,tmp; + if (m_forceMaxY) return rmax_y=f_maxy; for (QVector::iterator l=m_layers.begin();l!=m_layers.end();l++) { if ((*l)->isEmpty()) continue; tmp=(*l)->Maxy(); @@ -1262,6 +1266,8 @@ void gGraph::roundY(EventDataType &miny, EventDataType &maxy) miny/=4.0; } } + if (m_forceMinY && minyf_maxy) maxy=f_maxy; } gGraphView::gGraphView(QWidget *parent, gGraphView * shared) : diff --git a/Graphs/gGraphView.h b/Graphs/gGraphView.h index 18d30a64..701b89ef 100644 --- a/Graphs/gGraphView.h +++ b/Graphs/gGraphView.h @@ -262,12 +262,15 @@ public: virtual void SetMaxX(qint64 v); virtual void SetMinY(EventDataType v); virtual void SetMaxY(EventDataType v); + virtual void forceMinY(EventDataType v) { f_miny=v; m_forceMinY=true; } + virtual void forceMaxY(EventDataType v) { f_maxy=v; m_forceMaxY=true; } void resize(int width, int height); // margin recalcs.. qint64 max_x,min_x,rmax_x,rmin_x; - EventDataType max_y,min_y,rmax_y,rmin_y; - + EventDataType max_y,min_y,rmax_y,rmin_y, f_miny, f_maxy; + void unforceMinY() { m_forceMinY=false; } + void unforceMaxY() { m_forceMaxY=false; } bool blockZoom() { return m_blockzoom; } void setBlockZoom(bool b) { m_blockzoom=b; } int flipY(int y); // flip GL coordinates @@ -318,6 +321,7 @@ protected: short m_lastx23; Day * m_day; GLBuffer * m_quad; + bool m_forceMinY,m_forceMaxY; }; class gGraphView : public QGLWidget diff --git a/Graphs/gLineChart.cpp b/Graphs/gLineChart.cpp index 8b7b5206..197d960a 100644 --- a/Graphs/gLineChart.cpp +++ b/Graphs/gLineChart.cpp @@ -244,6 +244,9 @@ void gLineChart::paint(gGraph & w,int left, int top, int width, int height) done=false; first=true; + if (!accel) { + lines->setSize(1.5); + } else lines->setSize(1); bool firstpx=true; if (el.type()==EVL_Waveform) { // Waveform Plot if (idx>sam) idx-=sam; diff --git a/Graphs/gSummaryChart.cpp b/Graphs/gSummaryChart.cpp index 5827d29d..3cf78886 100644 --- a/Graphs/gSummaryChart.cpp +++ b/Graphs/gSummaryChart.cpp @@ -259,7 +259,7 @@ void SummaryChart::paint(gGraph & w,int left, int top, int width, int height) col=QColor("gold"); } - tmp=g.value(); + tmp=g.value()-miny; totalvalues[j]+=tmp; totalcounts[j]++; h=tmp*ymult; // height in pixels @@ -427,151 +427,3 @@ bool SummaryChart::mouseReleaseEvent(QMouseEvent * event) return false; } -/* -UsageChart::UsageChart(Profile *profile) - :gBarChart() -{ - m_profile=profile; - m_colors.push_back(Qt::green); - m_label="Hours"; -} - -void UsageChart::SetDay(Day * day) -{ - if (!m_profile) { - qWarning() << "Forgot to set profile for gBarChart dummy!"; - m_day=NULL; - return; - } - Layer::SetDay(day); - //m_empty=true; - // if (!day) return; - - m_values.clear(); - m_miny=9999999; - m_maxy=-9999999; - m_minx=0; - m_maxx=0; - - int dn; - EventDataType tmp,total; - ChannelID code; - - m_fday=0; - qint64 tt; - - int days=0; - for (QMap >::iterator d=m_profile->daylist.begin();d!=m_profile->daylist.end();d++) { - tt=QDateTime(d.key(),QTime(0,0,0),Qt::UTC).toTime_t(); - dn=tt/86400; - tt*=1000L; - // there could possibly may be a bug by doing this.. if charts don't match up.. come back here and enable the m_minx right down the bottom of this function. - if (!m_minx || ttm_maxx) m_maxx=tt; - - Day *day=m_profile->GetDay(d.key(),MT_CPAP); - if (day) { - total=day->hours(); - - m_values[dn][0]=total; - m_values[dn][1]=total; - if (totalm_maxy) m_maxy=total; - days++; - } - } - if (!days) m_empty=true; else m_empty=false; - //m_maxy=ceil(m_maxy); - //m_miny=floor(m_miny); - m_miny=0; - - // m_minx=qint64(QDateTime(m_profile->FirstDay(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L; - m_maxx=qint64(QDateTime(m_profile->LastDay().addDays(1),QTime(0,0,0),Qt::UTC).toTime_t())*1000L; -} - - -AHIChart::AHIChart(Profile *profile) - :gBarChart() -{ - m_label="AHI"; - m_profile=profile; -} - -void AHIChart::SetDay(Day * nullday) -{ -} - - - - -AvgChart::AvgChart(Profile *profile) - :gBarChart() -{ - m_label="Avg"; - m_profile=profile; -} - -void AvgChart::SetDay(Day * day) -{ - if (!m_profile) { - qWarning() << "Forgot to set profile for gBarChart dummy!"; - m_day=NULL; - return; - } - Layer::SetDay(day); - - m_values.clear(); - m_miny=9999999; - m_maxy=-9999999; - m_minx=0; - m_maxx=0; - - int dn; - EventDataType tmp,total; - ChannelID code; - - m_fday=0; - qint64 tt; - - for (QMap >::iterator d=m_profile->daylist.begin();d!=m_profile->daylist.end();d++) { - tt=QDateTime(d.key(),QTime(0,0,0),Qt::UTC).toTime_t(); - //tt=QDateTime(d.key(),QTime(12,0,0)).toTime_t(); - dn=tt/86400; - tt*=1000L; - if (!m_minx || ttm_maxx) m_maxx=tt; - - - total=0; - bool fnd=false; - for (int j=0;jchannelExists(code)) { // too many lookups happening here.. stop the crap.. - tmp=day->wavg(code); - if (tmp>0) { - fnd=true; - total+=tmp; - m_values[dn][j+1]=tmp; - break; - } - } - } - } - if (fnd) { - if (!m_fday) m_fday=dn; - m_values[dn][0]=total; - if (totalm_maxy) m_maxy=total; - } - } - m_miny=0; - - // m_minx=qint64(QDateTime(m_profile->FirstDay(),QTime(0,0,0),Qt::UTC).toTime_t())*1000L; - m_maxx=qint64(QDateTime(m_profile->LastDay().addDays(1),QTime(0,0,0),Qt::UTC).toTime_t())*1000L; - - m_empty=m_values.size()==0; -} - -*/ diff --git a/Graphs/gXAxis.cpp b/Graphs/gXAxis.cpp index 9f7f7914..d5410bb0 100644 --- a/Graphs/gXAxis.cpp +++ b/Graphs/gXAxis.cpp @@ -136,7 +136,7 @@ void gXAxis::paint(gGraph & w,int left,int top, int width, int height) GLBuffer *lines=w.backlines(); - int utcoff=m_utcfix ? -tz_hours : 0; + int utcoff=m_utcfix ? tz_hours : 0; //utcoff=0; int num_minor_ticks; diff --git a/SleepLib/schema.cpp b/SleepLib/schema.cpp index 71e6e489..10c3754b 100644 --- a/SleepLib/schema.cpp +++ b/SleepLib/schema.cpp @@ -23,7 +23,7 @@ void init() if (schema_initialized) return; schema_initialized=true; - EmptyChannel=Channel(0,DATA,DAY,"Empty","Empty Channel","Empty",""); + EmptyChannel=Channel(0,DATA,DAY,"Empty","Empty Channel","",""); ChanTypes["data"]=DATA; //Types["waveform"]=WAVEFORM; diff --git a/overview.cpp b/overview.cpp index 2d8b3017..7f72d6c8 100644 --- a/overview.cpp +++ b/overview.cpp @@ -80,10 +80,12 @@ Overview::Overview(QWidget *parent,Profile * _profile,gGraphView * shared) : pr=new SummaryChart(profile,"cmH2O",GT_LINE); - + PR->forceMinY(4.0); + //PR->forceMaxY(12.0); pr->addSlice(CPAP_Pressure,QColor("dark green"),ST_WAVG); pr->addSlice(CPAP_Pressure,QColor("orange"),ST_MIN); pr->addSlice(CPAP_Pressure,QColor("red"),ST_MAX); + //pr->addSlice(CPAP_Pressure,QColor("grey"),ST_90P); pr->addSlice(CPAP_EPAP,QColor("light green"),ST_MIN); pr->addSlice(CPAP_IPAP,QColor("light blue"),ST_MAX);