Quick and dirty TAP yAxis labels

This commit is contained in:
Mark Watkins 2016-03-08 01:45:28 +10:00
parent 029795d7a6
commit 35138b1165
2 changed files with 25 additions and 5 deletions

View File

@ -179,7 +179,7 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
int tot = max - min; int tot = max - min;
float xstep = float(width) / float(tot); float xstep = float(width) / float(tot);
height -= 2; height -= 2;
float peak = float(qMax(ipap.peaktime, epap.peaktime)); float peak = ceil((float(qMax(ipap.peaktime, epap.peaktime))/600.0))*600.0;
m_miny = m_physminy = 0; m_miny = m_physminy = 0;
m_maxy = m_physmaxy = peak; m_maxy = m_physmaxy = peak;
@ -187,7 +187,7 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
float ystep = float(height) / peak; float ystep = float(height) / peak;
int p0, p1, p2, p3; int p0, p1, p2, p3;
QString label;
if (ipap.min_pressure > 0) { if (ipap.min_pressure > 0) {
float xp,yp; float xp,yp;
@ -196,15 +196,35 @@ void MinutesAtPressure::paint(QPainter &painter, gGraph &graph, const QRegion &r
xp = left;// /2.0; xp = left;// /2.0;
int w, h; int w, h;
for (int i = 0; i<=20; ++i) { for (int i = 0; i<=20; ++i) {
yp = bottom; yp = bottom+1;
painter.drawLine(xp, yp, xp, yp+6); painter.drawLine(xp, yp, xp, yp+6);
if (i>0) { // skip the first mid tick
painter.drawLine(xp-pstep/2, yp, xp-pstep/2, yp+4);
}
QString label = QString("%1").arg(i+4); label = QString("%1").arg(i+4);
GetTextExtent(label, w, h); GetTextExtent(label, w, h);
graph.renderText(label, xp-w/2, yp+h+4); graph.renderText(label, xp-w/2, yp+h+4);
xp+= pstep; xp+= pstep;
} }
double bot = bottom+1;
double r = double(height+3) / (peak/600.0);
yp = bot;
for (float f=0.0; f<=peak/60.0; f+=10.0) {
painter.setPen(Qt::black);
painter.drawLine(left, bot, left-4, bot);
painter.setPen(QColor(128,128,128,64));
painter.drawLine(left, bot, left+width, bot);
label = QString("%1").arg(f);
GetTextExtent(label, w, h);
graph.renderText(label, left-8-w, bot+h/2-2 );
bot -= r;
}
xstep /= 5.0; xstep /= 5.0;
painter.setPen(Qt::red); painter.setPen(Qt::red);

View File

@ -272,7 +272,7 @@ Daily::Daily(QWidget *parent,gGraphView * shared)
graphlist[STR_GRAPH_TAP] = TAP2 = new gGraph(STR_GRAPH_TAP, GraphView, QObject::tr("Time at Pressure"), QObject::tr("Time at Pressure"), default_height); graphlist[STR_GRAPH_TAP] = TAP2 = new gGraph(STR_GRAPH_TAP, GraphView, QObject::tr("Time at Pressure"), QObject::tr("Time at Pressure"), default_height);
MinutesAtPressure * map; MinutesAtPressure * map;
TAP2->AddLayer(map = new MinutesAtPressure()); TAP2->AddLayer(map = new MinutesAtPressure());
TAP2->AddLayer(new gYAxis(),LayerLeft,gYAxis::Margin); TAP2->AddLayer(new gLabelArea(map),LayerLeft,gYAxis::Margin);
TAP2->AddLayer(new gXAxisPressure(),LayerBottom,gXAxisPressure::Margin); TAP2->AddLayer(new gXAxisPressure(),LayerBottom,gXAxisPressure::Margin);
TAP2->setBlockSelect(true); TAP2->setBlockSelect(true);