diff -r 95311e220eb6 -r 1357dfbfa29c QTfrontend/ui/page/pagegamestats.cpp --- a/QTfrontend/ui/page/pagegamestats.cpp Thu Mar 15 04:33:11 2018 +0100 +++ b/QTfrontend/ui/page/pagegamestats.cpp Thu Mar 15 14:51:07 2018 +0100 @@ -161,8 +161,6 @@ void PageGameStats::renderStats() { - graphic->show(); - labelGraphTitle-> show(); if(defaultGraphTitle) { labelGraphTitle->setText("

" + PageGameStats::tr("Health graph") + "

"); } else { @@ -177,31 +175,35 @@ m_scene.reset(new QGraphicsScene(this)); quint32 maxValue = 0; - int maxSize = 0; + int maxDataPoints = 0; for(QMap >::const_iterator i = healthPoints.constBegin(); i != healthPoints.constEnd(); ++i) { - maxSize = qMax(maxSize, i.value().size()); - - foreach (quint32 v, i.value()) - maxValue = qMax(maxValue, v); + maxDataPoints = qMax(maxDataPoints, i.value().size()); } - if(maxSize < 2) - return; + /* There must be at least 2 data points for any clan, + otherwise there's not much to look at. ;-) */ + if(maxDataPoints < 2) { + labelGraphTitle->hide(); + graphic->hide(); + return; + } QMap >::const_iterator i = healthPoints.constBegin(); while (i != healthPoints.constEnd()) { quint32 c = i.key(); - //QColor clanColor = QColor(qRgb((c >> 16) & 255, (c >> 8) & 255, c & 255)); const QVector& hps = i.value(); QPainterPath path; + if (hps.size()) path.moveTo(0, hps[0]); - for(int t = 1; t < hps.size(); ++t) - path.lineTo(t * maxValue / (maxSize - 1), hps[t]); + for(int t = 0; t < hps.size(); ++t) { + path.lineTo(t, hps[t]); + maxValue = qMax(maxValue, hps[t]); + } QPen pen(c); pen.setWidth(2); @@ -212,7 +214,11 @@ } graphic->setScene(m_scene.data()); + graphic->setSceneRect(0, 0, maxDataPoints-1, qMax(maxValue, (quint32) 1)); graphic->fitInView(graphic->sceneRect()); + + graphic->show(); + labelGraphTitle->show(); } }