From b51c34d23b56b4d411f238af55dfdfc16f44b6d1 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 16 Oct 2014 19:17:17 +0000 Subject: [PATCH] improved display of graphs git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7614 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/common/RSGraphWidget.cpp | 11 +++-- retroshare-gui/src/gui/common/RSGraphWidget.h | 9 ++-- .../src/gui/statistics/RttStatistics.cpp | 14 +++++- .../src/gui/statistics/RttStatistics.h | 1 + retroshare-gui/src/gui/statistics/bwgraph.h | 44 +++++++++++++++++-- retroshare-gui/src/gui/statistics/dhtgraph.h | 8 +--- .../src/gui/statistics/turtlegraph.h | 7 +-- 7 files changed, 74 insertions(+), 20 deletions(-) diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.cpp b/retroshare-gui/src/gui/common/RSGraphWidget.cpp index 9d2fe6212..b90b0f7e8 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.cpp +++ b/retroshare-gui/src/gui/common/RSGraphWidget.cpp @@ -40,6 +40,7 @@ RSGraphSource::RSGraphSource() _update_period_msecs = 1*1000 ; _time_orig_msecs = QDateTime::currentMSecsSinceEpoch() ; _timer = new QTimer ; + _digits = 2 ; QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ; } @@ -80,7 +81,7 @@ QString RSGraphSource::displayName(int i) const QString RSGraphSource::displayValue(float v) const { - return QString::number(v,'f',2) + " " + unitName() ; + return QString::number(v,'f',_digits) + " " + unitName() ; } void RSGraphSource::getCurrentValues(std::vector& vals) const @@ -91,6 +92,11 @@ void RSGraphSource::getCurrentValues(std::vector& vals) const vals.push_back(it->second.back().second) ; } +QString RSGraphSource::legend(int i,float v) const +{ + return displayName(i) + " (" + displayValue(v) + " )"; +} + void RSGraphSource::getDataPoints(int index,std::vector& pts) const { pts.clear() ; @@ -182,7 +188,6 @@ RSGraphWidget::RSGraphWidget(QWidget *parent) _timer = new QTimer ; QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ; - _precision_digits = 1 ; _y_scale = 1.0f ; _timer->start(1000); } @@ -482,7 +487,7 @@ void RSGraphWidget::paintLegend() { qreal paintStep = 4+FONT_SIZE; qreal pos = 20+i*paintStep; - QString text = _source->displayName(i) + " (" + _source->displayValue(vals[i]) + " )"; + QString text = _source->legend(i,vals[i]) ; QPen oldPen = _painter->pen(); _painter->setPen(QPen(getColor(i), Qt::SolidLine)); diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.h b/retroshare-gui/src/gui/common/RSGraphWidget.h index aedec2663..9dda5d3a4 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.h +++ b/retroshare-gui/src/gui/common/RSGraphWidget.h @@ -70,6 +70,9 @@ public: // return the vector of last values up to date virtual void getCurrentValues(std::vector& vals) const ; + // returns what to display in the legend. Derive this to show additional info. + virtual QString legend(int i,float v) const ; + // Returns the n^th interpolated value at the given time in floating point seconds backward. virtual void getDataPoints(int index, std::vector& pts) const ; @@ -82,6 +85,8 @@ public: // Sets the time period for collecting new values. Units=milliseconds. void setCollectionTimePeriod(qint64 msecs) ; + void setDigits(int d) { _digits = d ;} + protected slots: // Calls the internal source for a new data points; called by the timer. You might want to overload this // if the collection system needs it. Otherwise, the default method will call getValues() @@ -101,6 +106,7 @@ protected: qint64 _time_limit_msecs ; qint64 _update_period_msecs ; qint64 _time_orig_msecs ; + int _digits ; }; class RSGraphWidget: public QFrame @@ -139,8 +145,6 @@ class RSGraphWidget: public QFrame /** Toggles display of data counters. */ //void setShowCounters(bool showRSDHT, bool showALLDHT); - void setScaleParams(int precision_digits) { _precision_digits = precision_digits ; } - void setFlags(uint32_t flag) { _flags |= flag ; } void resetFlags(uint32_t flag) { _flags &= ~flag ; } protected: @@ -190,7 +194,6 @@ class RSGraphWidget: public QFrame qreal pixelsToValue(qreal) ; qreal valueToPixels(qreal) ; int _maxPoints; - int _precision_digits ; qreal _time_scale ; // horizontal scale in pixels per sec. diff --git a/retroshare-gui/src/gui/statistics/RttStatistics.cpp b/retroshare-gui/src/gui/statistics/RttStatistics.cpp index 296dd9bf5..2e05285ba 100644 --- a/retroshare-gui/src/gui/statistics/RttStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/RttStatistics.cpp @@ -88,6 +88,17 @@ QString RttGraphSource::unitName() const { return QObject::tr("secs") ; } + +QString RttGraphSource::displayName(int i) const +{ + int n=0 ; + for(std::map > >::const_iterator it=_points.begin();it!=_points.end();++it,++n) + if(n==i) + return QString::fromUtf8(rsPeers->getPeerName(RsPeerId(it->first)).c_str()) ; + + return QString() ; +} + void RttGraphSource::getValues(std::map& vals) const { std::list idList; @@ -111,13 +122,14 @@ RttStatisticsGraph::RttStatisticsGraph(QWidget *parent) src->setCollectionTimeLimit(10*60*1000) ; // 10 mins src->setCollectionTimePeriod(1000) ; // collect every second + src->setDigits(1) ; src->start() ; addSource(src) ; setTimeScale(2.0f) ; // 1 pixels per second of time. - setScaleParams(2) ; resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; + setFlags(RSGRAPH_FLAGS_SHOW_LEGEND) ; } diff --git a/retroshare-gui/src/gui/statistics/RttStatistics.h b/retroshare-gui/src/gui/statistics/RttStatistics.h index 4525abd2f..24f1092ed 100644 --- a/retroshare-gui/src/gui/statistics/RttStatistics.h +++ b/retroshare-gui/src/gui/statistics/RttStatistics.h @@ -36,6 +36,7 @@ public: virtual void getValues(std::map& vals) const ; virtual QString unitName() const ; + virtual QString displayName(int i) const ; }; class RttStatisticsGraph: public RSGraphWidget diff --git a/retroshare-gui/src/gui/statistics/bwgraph.h b/retroshare-gui/src/gui/statistics/bwgraph.h index d49c4685d..5ef4026a4 100644 --- a/retroshare-gui/src/gui/statistics/bwgraph.h +++ b/retroshare-gui/src/gui/statistics/bwgraph.h @@ -11,11 +11,47 @@ public: RsConfigDataRates totalRates; rsConfig->getTotalBandwidthRates(totalRates); - values.insert(std::make_pair(std::string("Bytes in"),(float)totalRates.mRateIn)) ; - values.insert(std::make_pair(std::string("Bytes out"),(float)totalRates.mRateOut)) ; + values.insert(std::make_pair(std::string("Bytes in"),1024 * (float)totalRates.mRateIn)) ; + values.insert(std::make_pair(std::string("Bytes out"),1024 * (float)totalRates.mRateOut)) ; + + _total_sent += 1024 * totalRates.mRateOut * _update_period_msecs/1000.0f ; + _total_recv += 1024 * totalRates.mRateIn * _update_period_msecs/1000.0f ; } virtual QString unitName() const { return tr("KB/s"); } + + virtual QString displayValue(float v) const + { + if(v < 1000) + return QString::number(v,'f',2) + " B/s" ; + else if(v < 1000*1024) + return QString::number(v/1024.0,'f',2) + " KB/s" ; + else + return QString::number(v/(1024.0*1024),'f',2) + " MB/s" ; + } + + virtual QString legend(int i,float v) const + { + if(i==0) + return RSGraphSource::legend(i,v) + " Total: " + niceNumber(_total_recv) ; + else + return RSGraphSource::legend(i,v) + " Total: " + niceNumber(_total_sent) ; + } + private: + QString niceNumber(float v) const + { + if(v < 1000) + return QString::number(v,'f',2) + " B" ; + else if(v < 1000*1024) + return QString::number(v/1024.0,'f',2) + " KB" ; + else if(v < 1000*1024*1024) + return QString::number(v/(1024*1024.0),'f',2) + " MB" ; + else + return QString::number(v/(1024*1024.0*1024),'f',2) + " GB"; + } + + mutable float _total_sent ; + mutable float _total_recv ; }; class BWGraph: public RSGraphWidget @@ -27,13 +63,13 @@ class BWGraph: public RSGraphWidget BWGraphSource *src = new BWGraphSource() ; src->setCollectionTimeLimit(30*60*1000) ; // 30 mins - src->setCollectionTimePeriod(1000) ; // collect every second + src->setCollectionTimePeriod(1000) ; // collect every second + src->setDigits(2) ; src->start() ; addSource(src) ; setTimeScale(1.0f) ; // 1 pixels per second of time. - setScaleParams(2) ; resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; diff --git a/retroshare-gui/src/gui/statistics/dhtgraph.h b/retroshare-gui/src/gui/statistics/dhtgraph.h index 337513c5c..2f9e0be34 100644 --- a/retroshare-gui/src/gui/statistics/dhtgraph.h +++ b/retroshare-gui/src/gui/statistics/dhtgraph.h @@ -33,10 +33,6 @@ class DHTGraphSource: public RSGraphSource { public: - virtual int n_values() const - { - return 1 ; - } virtual void getValues(std::map& values) const { RsConfigNetStatus config; @@ -67,13 +63,13 @@ class DhtGraph : public RSGraphWidget DHTGraphSource *src = new DHTGraphSource() ; src->setCollectionTimeLimit(30*60*1000) ; // 30 mins - src->setCollectionTimePeriod(1000) ; // collect every second + src->setCollectionTimePeriod(1000) ; // collect every second + src->setDigits(0) ; src->start() ; addSource(src) ; setTimeScale(1.0f) ; // 1 pixels per second of time. - setScaleParams(0) ; resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; setFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; diff --git a/retroshare-gui/src/gui/statistics/turtlegraph.h b/retroshare-gui/src/gui/statistics/turtlegraph.h index 474b0d8df..f9271ee9d 100644 --- a/retroshare-gui/src/gui/statistics/turtlegraph.h +++ b/retroshare-gui/src/gui/statistics/turtlegraph.h @@ -38,17 +38,18 @@ class TurtleGraph: public RSGraphWidget TurtleGraphSource *src = new TurtleGraphSource() ; src->setCollectionTimeLimit(30*60*1000) ; // 30 mins - src->setCollectionTimePeriod(1000) ; // collect every second + src->setCollectionTimePeriod(1000) ; // collect every second + src->setDigits(2) ; src->start() ; addSource(src) ; setTimeScale(1.0f) ; // 1 pixels per second of time. - setScaleParams(2) ; resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ; resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ; - } + setFlags(RSGRAPH_FLAGS_SHOW_LEGEND) ; + } };