mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-13 16:39:43 -05:00
fixed RTT graph. Added colors, and new options to RSGraphWidget. Still needs to draw names for different colors
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7610 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1757a85e57
commit
3d49af2b2b
@ -146,7 +146,6 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
|
|||||||
{
|
{
|
||||||
_source =NULL;
|
_source =NULL;
|
||||||
_painter = new QPainter();
|
_painter = new QPainter();
|
||||||
_graphStyle = AreaGraph;
|
|
||||||
|
|
||||||
/* Initialize graph values */
|
/* Initialize graph values */
|
||||||
_maxPoints = getNumPoints();
|
_maxPoints = getNumPoints();
|
||||||
@ -157,6 +156,7 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
|
|||||||
_timer = new QTimer ;
|
_timer = new QTimer ;
|
||||||
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ;
|
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(update())) ;
|
||||||
|
|
||||||
|
_precision_digits = 1 ;
|
||||||
_y_scale = 1.0f ;
|
_y_scale = 1.0f ;
|
||||||
_timer->start(1000);
|
_timer->start(1000);
|
||||||
}
|
}
|
||||||
@ -226,6 +226,14 @@ void RSGraphWidget::paintEvent(QPaintEvent *)
|
|||||||
_painter->end();
|
_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
|
/** 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,
|
* 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
|
* followed by the outlines, since we want the area of overlapping integrals
|
||||||
@ -249,12 +257,12 @@ void RSGraphWidget::paintData()
|
|||||||
pointsFromData(values,points) ;
|
pointsFromData(values,points) ;
|
||||||
|
|
||||||
/* Plot the bandwidth data as area graphs */
|
/* Plot the bandwidth data as area graphs */
|
||||||
if (_graphStyle == AreaGraph)
|
if (_flags & RSGRAPH_FLAGS_PAINT_STYLE_PLAIN)
|
||||||
paintIntegral(points, RSDHT_COLOR, 0.6);
|
paintIntegral(points, getColor(i), 0.6);
|
||||||
|
|
||||||
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
/* Plot the bandwidth as solid lines. If the graph style is currently an
|
||||||
* area graph, we end up outlining the integrals. */
|
* area graph, we end up outlining the integrals. */
|
||||||
paintLine(points, RSDHT_COLOR);
|
paintLine(points, getColor(i));
|
||||||
}
|
}
|
||||||
if(_maxValue > 0.0f)
|
if(_maxValue > 0.0f)
|
||||||
if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y)
|
if(_flags & RSGRAPH_FLAGS_LOG_SCALE_Y)
|
||||||
@ -403,7 +411,6 @@ QString RSGraphWidget::totalToStr(qreal total)
|
|||||||
/** Paints the scale on the graph. */
|
/** Paints the scale on the graph. */
|
||||||
void RSGraphWidget::paintScale()
|
void RSGraphWidget::paintScale()
|
||||||
{
|
{
|
||||||
qreal markStep = valueToPixels(_maxValue) * .25; // in pixels
|
|
||||||
int top = _rec.y();
|
int top = _rec.y();
|
||||||
int bottom = _rec.height();
|
int bottom = _rec.height();
|
||||||
qreal paintStep = (bottom - (bottom/10)) / 4;
|
qreal paintStep = (bottom - (bottom/10)) / 4;
|
||||||
@ -421,10 +428,10 @@ void RSGraphWidget::paintScale()
|
|||||||
{
|
{
|
||||||
pos = bottom - (i * paintStep);
|
pos = bottom - (i * paintStep);
|
||||||
|
|
||||||
scale = pixelsToValue(i * markStep);
|
scale = pixelsToValue(i * paintStep);
|
||||||
|
|
||||||
_painter->setPen(SCALE_COLOR);
|
_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->setPen(GRID_COLOR);
|
||||||
_painter->drawLine(QPointF(SCALE_WIDTH, pos), QPointF(_rec.width(), pos));
|
_painter->drawLine(QPointF(SCALE_WIDTH, pos), QPointF(_rec.width(), pos));
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
#define BACK_COLOR Qt::white
|
#define BACK_COLOR Qt::white
|
||||||
#define SCALE_COLOR Qt::black
|
#define SCALE_COLOR Qt::black
|
||||||
#define GRID_COLOR Qt::black
|
#define GRID_COLOR Qt::lightGray
|
||||||
#define RSDHT_COLOR Qt::magenta
|
#define RSDHT_COLOR Qt::magenta
|
||||||
#define ALLDHT_COLOR Qt::yellow
|
#define ALLDHT_COLOR Qt::yellow
|
||||||
|
|
||||||
@ -98,9 +98,10 @@ class RSGraphWidget: public QFrame
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const uint32_t RSGRAPH_FLAGS_AUTO_SCALE_Y = 0x0001 ; // automatically adjust Y scale
|
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_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_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. */
|
/** Bandwidth graph style. */
|
||||||
enum GraphStyle
|
enum GraphStyle
|
||||||
@ -126,8 +127,8 @@ class RSGraphWidget: public QFrame
|
|||||||
void resetGraph();
|
void resetGraph();
|
||||||
/** Toggles display of data counters. */
|
/** Toggles display of data counters. */
|
||||||
//void setShowCounters(bool showRSDHT, bool showALLDHT);
|
//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 setFlags(uint32_t flag) { _flags |= flag ; }
|
||||||
void resetFlags(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. */
|
/** Paints the rsdht/alldht totals. */
|
||||||
void paintTotals();
|
void paintTotals();
|
||||||
/** Paints the scale in the graph. */
|
/** Paints the scale in the graph. */
|
||||||
void paintScale();
|
void paintScale();
|
||||||
|
|
||||||
|
QColor getColor(int i) ;
|
||||||
|
|
||||||
/** Returns a formatted string representation of total. */
|
/** Returns a formatted string representation of total. */
|
||||||
QString totalToStr(qreal total);
|
QString totalToStr(qreal total);
|
||||||
/** Returns a list of points on the bandwidth graph based on the supplied set
|
/** 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. */
|
/** Paints an integral using the supplied data. */
|
||||||
void paintIntegral(const QVector<QPointF>& points, QColor color, qreal alpha = 1.0);
|
void paintIntegral(const QVector<QPointF>& 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. */
|
/** A QPainter object that handles drawing the various graph elements. */
|
||||||
QPainter* _painter;
|
QPainter* _painter;
|
||||||
/** The current dimensions of the graph. */
|
/** The current dimensions of the graph. */
|
||||||
@ -175,6 +177,7 @@ class RSGraphWidget: public QFrame
|
|||||||
qreal pixelsToValue(qreal) ;
|
qreal pixelsToValue(qreal) ;
|
||||||
qreal valueToPixels(qreal) ;
|
qreal valueToPixels(qreal) ;
|
||||||
int _maxPoints;
|
int _maxPoints;
|
||||||
|
int _precision_digits ;
|
||||||
|
|
||||||
qreal _time_scale ; // horizontal scale in pixels per sec.
|
qreal _time_scale ; // horizontal scale in pixels per sec.
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ RttStatistics::RttStatistics(QWidget *parent)
|
|||||||
|
|
||||||
m_bProcessSettings = false;
|
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->setWidgetResizable(true);
|
||||||
_tunnel_statistics_F->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
_tunnel_statistics_F->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
_tunnel_statistics_F->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
_tunnel_statistics_F->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
@ -217,7 +217,11 @@ void RttStatistics::processSettings(bool bLoad)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RttGraphSource::getValues(std::map<std::string,float>& vals)
|
QString RttGraphSource::unitName() const
|
||||||
|
{
|
||||||
|
return QObject::tr("secs") ;
|
||||||
|
}
|
||||||
|
void RttGraphSource::getValues(std::map<std::string,float>& vals) const
|
||||||
{
|
{
|
||||||
std::list<RsPeerId> idList;
|
std::list<RsPeerId> idList;
|
||||||
rsPeers->getOnlineList(idList);
|
rsPeers->getOnlineList(idList);
|
||||||
@ -229,10 +233,28 @@ void RttGraphSource::getValues(std::map<std::string,float>& vals)
|
|||||||
{
|
{
|
||||||
rsRtt->getPongResults(*it, 1, results);
|
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()
|
//void RttStatistics::updateDisplay()
|
||||||
//{
|
//{
|
||||||
// std::map<RsPeerId, std::list<RsRttPongResult> > info;
|
// std::map<RsPeerId, std::list<RsRttPongResult> > info;
|
||||||
|
@ -32,17 +32,16 @@ class RttStatisticsWidget ;
|
|||||||
class RttGraphSource: public RSGraphSource
|
class RttGraphSource: public RSGraphSource
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RttGraphSource() ;
|
RttGraphSource() {}
|
||||||
|
|
||||||
virtual void getValues(std::map<std::string,float>& vals) ;
|
virtual void getValues(std::map<std::string,float>& vals) const ;
|
||||||
|
virtual QString unitName() const ;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RttStatisticsGraph: public RSGraphWidget
|
class RttStatisticsGraph: public RSGraphWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
RttStatisticsGraph()
|
RttStatisticsGraph(QWidget *parent);
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RttStatistics: public MainPage, public Ui::RttStatistics
|
class RttStatistics: public MainPage, public Ui::RttStatistics
|
||||||
|
@ -68,7 +68,10 @@ DhtGraph::DhtGraph(QWidget *parent)
|
|||||||
addSource(src) ;
|
addSource(src) ;
|
||||||
|
|
||||||
setTimeScale(1.0f) ; // 1 pixels per second of time.
|
setTimeScale(1.0f) ; // 1 pixels per second of time.
|
||||||
|
setScaleParams(0) ;
|
||||||
|
|
||||||
resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
||||||
|
setFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user