diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.cpp b/retroshare-gui/src/gui/common/RSGraphWidget.cpp index 527e13183..9190b38ba 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.cpp +++ b/retroshare-gui/src/gui/common/RSGraphWidget.cpp @@ -146,7 +146,6 @@ RSGraphWidget::RSGraphWidget(QWidget *parent) { _source =NULL; _painter = new QPainter(); - _graphStyle = AreaGraph; /* Initialize graph values */ _maxPoints = getNumPoints(); @@ -157,6 +156,7 @@ 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); } @@ -226,6 +226,14 @@ void RSGraphWidget::paintEvent(QPaintEvent *) _painter->end(); } +QColor RSGraphWidget::getColor(int i) +{ + // shuffle the colors a little bit + int h = (i*44497)%359 ; + + return QColor::fromHsv(h,128+127*(i&1),255) ; +} + /** Paints an integral and an outline of that integral for each data set (rsdht * and/or alldht) that is to be displayed. The integrals will be drawn first, * followed by the outlines, since we want the area of overlapping integrals @@ -249,12 +257,12 @@ void RSGraphWidget::paintData() pointsFromData(values,points) ; /* Plot the bandwidth data as area graphs */ - if (_graphStyle == AreaGraph) - paintIntegral(points, RSDHT_COLOR, 0.6); + if (_flags & RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) + paintIntegral(points, getColor(i), 0.6); /* Plot the bandwidth as solid lines. If the graph style is currently an * area graph, we end up outlining the integrals. */ - paintLine(points, RSDHT_COLOR); + paintLine(points, getColor(i)); } if(_maxValue > 0.0f) if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y) @@ -403,7 +411,6 @@ QString RSGraphWidget::totalToStr(qreal total) /** Paints the scale on the graph. */ void RSGraphWidget::paintScale() { - qreal markStep = valueToPixels(_maxValue) * .25; // in pixels int top = _rec.y(); int bottom = _rec.height(); qreal paintStep = (bottom - (bottom/10)) / 4; @@ -421,10 +428,10 @@ void RSGraphWidget::paintScale() { pos = bottom - (i * paintStep); - scale = pixelsToValue(i * markStep); + scale = pixelsToValue(i * paintStep); _painter->setPen(SCALE_COLOR); - _painter->drawText(QPointF(5, pos+FONT_SIZE), tr("%1 %2").arg(scale, 0, 'f', 0).arg(unit_name)); + _painter->drawText(QPointF(5, pos+0.5*FONT_SIZE), tr("%1 %2").arg(scale, 0, 'f', _precision_digits).arg(unit_name)); _painter->setPen(GRID_COLOR); _painter->drawLine(QPointF(SCALE_WIDTH, pos), QPointF(_rec.width(), pos)); } diff --git a/retroshare-gui/src/gui/common/RSGraphWidget.h b/retroshare-gui/src/gui/common/RSGraphWidget.h index cbc7e1981..2cab8690f 100644 --- a/retroshare-gui/src/gui/common/RSGraphWidget.h +++ b/retroshare-gui/src/gui/common/RSGraphWidget.h @@ -38,7 +38,7 @@ #define BACK_COLOR Qt::white #define SCALE_COLOR Qt::black -#define GRID_COLOR Qt::black +#define GRID_COLOR Qt::lightGray #define RSDHT_COLOR Qt::magenta #define ALLDHT_COLOR Qt::yellow @@ -98,9 +98,10 @@ class RSGraphWidget: public QFrame Q_OBJECT public: - static const uint32_t RSGRAPH_FLAGS_AUTO_SCALE_Y = 0x0001 ; // automatically adjust Y scale - static const uint32_t RSGRAPH_FLAGS_LOG_SCALE_Y = 0x0002 ; // log scale in Y - static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ; // keep collecting while not displayed + static const uint32_t RSGRAPH_FLAGS_AUTO_SCALE_Y = 0x0001 ;// automatically adjust Y scale + static const uint32_t RSGRAPH_FLAGS_LOG_SCALE_Y = 0x0002 ;// log scale in Y + static const uint32_t RSGRAPH_FLAGS_ALWAYS_COLLECT = 0x0004 ;// keep collecting while not displayed + static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style /** Bandwidth graph style. */ enum GraphStyle @@ -126,8 +127,8 @@ class RSGraphWidget: public QFrame void resetGraph(); /** Toggles display of data counters. */ //void setShowCounters(bool showRSDHT, bool showALLDHT); - /** Sets the graph style used to display bandwidth data. */ - void setGraphStyle(GraphStyle style) { _graphStyle = style; } + + void setScaleParams(int precision_digits) { _precision_digits = precision_digits ; } void setFlags(uint32_t flag) { _flags |= flag ; } void resetFlags(uint32_t flag) { _flags &= ~flag ; } @@ -148,7 +149,10 @@ class RSGraphWidget: public QFrame /** Paints the rsdht/alldht totals. */ void paintTotals(); /** Paints the scale in the graph. */ - void paintScale(); + void paintScale(); + + QColor getColor(int i) ; + /** Returns a formatted string representation of total. */ QString totalToStr(qreal total); /** Returns a list of points on the bandwidth graph based on the supplied set @@ -161,8 +165,6 @@ class RSGraphWidget: public QFrame /** Paints an integral using the supplied data. */ void paintIntegral(const QVector& points, QColor color, qreal alpha = 1.0); - /** Style with which the bandwidth data will be graphed. */ - GraphStyle _graphStyle; /** A QPainter object that handles drawing the various graph elements. */ QPainter* _painter; /** The current dimensions of the graph. */ @@ -175,6 +177,7 @@ 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 df5d6f52a..170077c87 100644 --- a/retroshare-gui/src/gui/statistics/RttStatistics.cpp +++ b/retroshare-gui/src/gui/statistics/RttStatistics.cpp @@ -173,7 +173,7 @@ RttStatistics::RttStatistics(QWidget *parent) m_bProcessSettings = false; - _tunnel_statistics_F->setWidget( _tst_CW = new RttStatisticsGraph() ) ; + _tunnel_statistics_F->setWidget( _tst_CW = new RttStatisticsGraph(this) ) ; _tunnel_statistics_F->setWidgetResizable(true); _tunnel_statistics_F->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); _tunnel_statistics_F->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); @@ -217,7 +217,11 @@ void RttStatistics::processSettings(bool bLoad) } -void RttGraphSource::getValues(std::map& vals) +QString RttGraphSource::unitName() const +{ + return QObject::tr("secs") ; +} +void RttGraphSource::getValues(std::map& vals) const { std::list idList; rsPeers->getOnlineList(idList); @@ -229,10 +233,28 @@ void RttGraphSource::getValues(std::map& vals) { rsRtt->getPongResults(*it, 1, results); - vals[(*it).toStdString()] = results.front().mRTT ; + vals[(*it).toStdString()] = results.back().mRTT ; } } +RttStatisticsGraph::RttStatisticsGraph(QWidget *parent) + : RSGraphWidget(parent) +{ + RttGraphSource *src = new RttGraphSource() ; + + src->setCollectionTimeLimit(10*60*1000) ; // 10 mins + src->setCollectionTimePeriod(1000) ; // collect every second + 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) ; +} + //void RttStatistics::updateDisplay() //{ // std::map > info; diff --git a/retroshare-gui/src/gui/statistics/RttStatistics.h b/retroshare-gui/src/gui/statistics/RttStatistics.h index 6bfdedf81..6a1552a86 100644 --- a/retroshare-gui/src/gui/statistics/RttStatistics.h +++ b/retroshare-gui/src/gui/statistics/RttStatistics.h @@ -32,17 +32,16 @@ class RttStatisticsWidget ; class RttGraphSource: public RSGraphSource { public: - RttGraphSource() ; + RttGraphSource() {} - virtual void getValues(std::map& vals) ; + virtual void getValues(std::map& vals) const ; + virtual QString unitName() const ; }; class RttStatisticsGraph: public RSGraphWidget { - public: - RttStatisticsGraph() - { - } +public: + RttStatisticsGraph(QWidget *parent); }; class RttStatistics: public MainPage, public Ui::RttStatistics diff --git a/retroshare-gui/src/gui/statistics/dhtgraph.cpp b/retroshare-gui/src/gui/statistics/dhtgraph.cpp index 56a11e499..1daa906d3 100644 --- a/retroshare-gui/src/gui/statistics/dhtgraph.cpp +++ b/retroshare-gui/src/gui/statistics/dhtgraph.cpp @@ -68,7 +68,10 @@ DhtGraph::DhtGraph(QWidget *parent) 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) ; }