mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-08-05 21:04:14 -04:00
added temporal filtering to RSGraphWidget to clear up the display. Auto-changes with scale. Can be changed manually with shift+wheel
This commit is contained in:
parent
140205108a
commit
b32eb6e0c8
2 changed files with 157 additions and 141 deletions
|
@ -113,7 +113,7 @@ QString RSGraphSource::legend(int i,float v) const
|
||||||
return displayName(i) + " (" + displayValue(v) + " )";
|
return displayName(i) + " (" + displayValue(v) + " )";
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts) const
|
void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts,float filter_factor) const
|
||||||
{
|
{
|
||||||
pts.clear() ;
|
pts.clear() ;
|
||||||
qint64 now = getTime() ;
|
qint64 now = getTime() ;
|
||||||
|
@ -126,8 +126,15 @@ void RSGraphSource::getDataPoints(int index,std::vector<QPointF>& pts) const
|
||||||
if(n != index)
|
if(n != index)
|
||||||
return ;
|
return ;
|
||||||
|
|
||||||
|
float last_value = it->second.empty()?0.0f:(it->second.begin()->second) ;
|
||||||
|
|
||||||
for(std::list<std::pair<qint64,float> >::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
|
for(std::list<std::pair<qint64,float> >::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
|
||||||
pts.push_back(QPointF( (now - (*it2).first)/1000.0f,(*it2).second)) ;
|
{
|
||||||
|
float val = (1-filter_factor)*(*it2).second + filter_factor*last_value;
|
||||||
|
last_value = val ;
|
||||||
|
|
||||||
|
pts.push_back(QPointF( (now - (*it2).first)/1000.0f, val)) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSGraphWidget::setShowEntry(uint32_t entry,bool b)
|
void RSGraphWidget::setShowEntry(uint32_t entry,bool b)
|
||||||
|
@ -231,6 +238,7 @@ RSGraphWidget::RSGraphWidget(QWidget *parent)
|
||||||
_opacity = 0.6 ;
|
_opacity = 0.6 ;
|
||||||
_flags = 0;
|
_flags = 0;
|
||||||
_time_scale = 5.0f ; // in pixels per second.
|
_time_scale = 5.0f ; // in pixels per second.
|
||||||
|
_time_filter = 1.0f ;
|
||||||
_timer = new QTimer ;
|
_timer = new QTimer ;
|
||||||
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(updateIfPossible())) ;
|
QObject::connect(_timer,SIGNAL(timeout()),this,SLOT(updateIfPossible())) ;
|
||||||
|
|
||||||
|
@ -370,7 +378,8 @@ void RSGraphWidget::paintData()
|
||||||
if( _masked_entries.find(source.displayName(i).toStdString()) == _masked_entries.end() )
|
if( _masked_entries.find(source.displayName(i).toStdString()) == _masked_entries.end() )
|
||||||
{
|
{
|
||||||
std::vector<QPointF> values ;
|
std::vector<QPointF> values ;
|
||||||
source.getDataPoints(i,values) ;
|
//std::cerr << "time filter = " << _time_filter << ", factor=" << 1./_time_scale*_time_filter/(1+_time_filter/_time_scale) << std::endl;
|
||||||
|
source.getDataPoints(i,values,1./_time_scale*_time_filter/(1.0f+_time_filter/_time_scale)) ;
|
||||||
|
|
||||||
QVector<QPointF> points ;
|
QVector<QPointF> points ;
|
||||||
pointsFromData(values,points) ;
|
pointsFromData(values,points) ;
|
||||||
|
@ -394,79 +403,79 @@ void RSGraphWidget::paintData()
|
||||||
* of rsdht or alldht values. */
|
* of rsdht or alldht values. */
|
||||||
void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QPointF>& points)
|
void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QPointF>& points)
|
||||||
{
|
{
|
||||||
points.clear();
|
points.clear();
|
||||||
|
|
||||||
int x = _rec.width();
|
int x = _rec.width();
|
||||||
int y = _rec.height();
|
int y = _rec.height();
|
||||||
|
|
||||||
float time_step = 1.0f ; // number of seconds per pixel
|
float time_step = 1.0f ; // number of seconds per pixel
|
||||||
|
|
||||||
/* Translate all data points to points on the graph frame */
|
/* Translate all data points to points on the graph frame */
|
||||||
|
|
||||||
// take 0 as the origin, otherwise the different curves are not aligned properly
|
// take 0 as the origin, otherwise the different curves are not aligned properly
|
||||||
float last = 0;//values.back().x();
|
float last = 0;//values.back().x();
|
||||||
|
|
||||||
//std::cerr << "Got " << values.size() << " values for index 0" << std::endl;
|
//std::cerr << "Got " << values.size() << " values for index 0" << std::endl;
|
||||||
|
|
||||||
float FS = QFontMetricsF(font()).height();
|
float FS = QFontMetricsF(font()).height();
|
||||||
float fact = FS/14.0 ;
|
float fact = FS/14.0 ;
|
||||||
|
|
||||||
float last_px = SCALE_WIDTH*fact ;
|
float last_px = SCALE_WIDTH*fact ;
|
||||||
float last_py = 0.0f ;
|
float last_py = 0.0f ;
|
||||||
|
|
||||||
// float min_x_no_data_threshold = 1.5 ; // 1.5 sec.
|
// float min_x_no_data_threshold = 1.5 ; // 1.5 sec.
|
||||||
|
|
||||||
for (uint i = 0; i < values.size(); ++i)
|
for (uint i = 0; i < values.size(); ++i)
|
||||||
{
|
{
|
||||||
//std::cerr << "Value: (" << values[i].x() << " , " << values[i].y() << ")" << std::endl;
|
//std::cerr << "Value: (" << values[i].x() << " , " << values[i].y() << ")" << std::endl;
|
||||||
|
|
||||||
// compute point in pixels
|
// compute point in pixels
|
||||||
|
|
||||||
qreal px = x - (values[i].x()-last)*_time_scale ;
|
qreal px = x - (values[i].x()-last)*_time_scale ;
|
||||||
qreal py = y - valueToPixels(values[i].y()) ;
|
qreal py = y - valueToPixels(values[i].y()) ;
|
||||||
|
|
||||||
if(px >= SCALE_WIDTH*fact && last_px < SCALE_WIDTH*fact)
|
if(px >= SCALE_WIDTH*fact && last_px < SCALE_WIDTH*fact)
|
||||||
{
|
{
|
||||||
float alpha = (SCALE_WIDTH*fact - last_px)/(px - last_px) ;
|
float alpha = (SCALE_WIDTH*fact - last_px)/(px - last_px) ;
|
||||||
float ipx = SCALE_WIDTH*fact ;
|
float ipx = SCALE_WIDTH*fact ;
|
||||||
float ipy = (1-alpha)*last_py + alpha*py ;
|
float ipy = (1-alpha)*last_py + alpha*py ;
|
||||||
|
|
||||||
points << QPointF(ipx,y) ;
|
points << QPointF(ipx,y) ;
|
||||||
points << QPointF(ipx,ipy) ;
|
points << QPointF(ipx,ipy) ;
|
||||||
}
|
}
|
||||||
else if(i==0)
|
else if(i==0)
|
||||||
{
|
{
|
||||||
if(px < SCALE_WIDTH*fact)
|
if(px < SCALE_WIDTH*fact)
|
||||||
points << QPointF(SCALE_WIDTH*fact,py) ;
|
points << QPointF(SCALE_WIDTH*fact,py) ;
|
||||||
else
|
else
|
||||||
points << QPointF(px,y) ;
|
points << QPointF(px,y) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(px < SCALE_WIDTH*fact)
|
if(px < SCALE_WIDTH*fact)
|
||||||
continue ;
|
continue ;
|
||||||
|
|
||||||
_maxValue = std::max(_maxValue,values[i].y()) ;
|
_maxValue = std::max(_maxValue,values[i].y()) ;
|
||||||
|
|
||||||
// remove midle point when 3 consecutive points have the same value.
|
// remove midle point when 3 consecutive points have the same value.
|
||||||
|
|
||||||
if(points.size() > 1 && points[points.size()-2].y() == points.back().y() && points.back().y() == py)
|
if(points.size() > 1 && points[points.size()-2].y() == points.back().y() && points.back().y() == py)
|
||||||
points.pop_back() ;
|
points.pop_back() ;
|
||||||
|
|
||||||
// if(fabs(px - last_px)/_time_scale > min_x_no_data_threshold)
|
// if(fabs(px - last_px)/_time_scale > min_x_no_data_threshold)
|
||||||
// {
|
// {
|
||||||
// points << QPointF(last_px,y) ;
|
// points << QPointF(last_px,y) ;
|
||||||
// points << QPointF(px,y) ;
|
// points << QPointF(px,y) ;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
points << QPointF(px,py) ;
|
points << QPointF(px,py) ;
|
||||||
|
|
||||||
if(i==values.size()-1)
|
if(i==values.size()-1)
|
||||||
points << QPointF(px,y) ;
|
points << QPointF(px,y) ;
|
||||||
|
|
||||||
last_px = px ;
|
last_px = px ;
|
||||||
last_py = py ;
|
last_py = py ;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qreal RSGraphWidget::valueToPixels(qreal val)
|
qreal RSGraphWidget::valueToPixels(qreal val)
|
||||||
|
@ -601,12 +610,18 @@ void RSGraphWidget::paintScale2()
|
||||||
|
|
||||||
void RSGraphWidget::wheelEvent(QWheelEvent *e)
|
void RSGraphWidget::wheelEvent(QWheelEvent *e)
|
||||||
{
|
{
|
||||||
if(e->delta() > 0)
|
if(e->modifiers() & Qt::ShiftModifier)
|
||||||
_time_scale *= 1.1 ;
|
if(e->delta() > 0)
|
||||||
else
|
_time_filter *= 1.1 ;
|
||||||
_time_scale /= 1.1 ;
|
else
|
||||||
|
_time_filter /= 1.1 ;
|
||||||
|
else
|
||||||
|
if(e->delta() > 0)
|
||||||
|
_time_scale *= 1.1 ;
|
||||||
|
else
|
||||||
|
_time_scale /= 1.1 ;
|
||||||
|
|
||||||
update() ;
|
update() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RSGraphWidget::paintLegend()
|
void RSGraphWidget::paintLegend()
|
||||||
|
|
|
@ -73,7 +73,7 @@ public:
|
||||||
virtual QString legend(int i,float v) const ;
|
virtual QString legend(int i,float v) const ;
|
||||||
|
|
||||||
// Returns the n^th interpolated value at the given time in floating point seconds backward.
|
// Returns the n^th interpolated value at the given time in floating point seconds backward.
|
||||||
virtual void getDataPoints(int index, std::vector<QPointF>& pts) const ;
|
virtual void getDataPoints(int index, std::vector<QPointF>& pts, float filter_factor=0.0f) const ;
|
||||||
|
|
||||||
// returns the name to give to the nth entry in the graph
|
// returns the name to give to the nth entry in the graph
|
||||||
virtual QString displayName(int index) const ;
|
virtual QString displayName(int index) const ;
|
||||||
|
@ -113,108 +113,109 @@ 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
|
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_PLAIN = 0x0008 ;// use plain / line drawing style
|
||||||
static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph
|
static const uint32_t RSGRAPH_FLAGS_SHOW_LEGEND = 0x0010 ;// show legend in the graph
|
||||||
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes
|
static const uint32_t RSGRAPH_FLAGS_PAINT_STYLE_FLAT = 0x0020 ;// do not interpolate, and draw flat colored boxes
|
||||||
|
|
||||||
/** Bandwidth graph style. */
|
/** Bandwidth graph style. */
|
||||||
enum GraphStyle
|
enum GraphStyle
|
||||||
{
|
{
|
||||||
SolidLine = 0, /**< Plot bandwidth as solid lines. */
|
SolidLine = 0, /**< Plot bandwidth as solid lines. */
|
||||||
AreaGraph = 1 /**< Plot bandwidth as alpha blended area graphs. */
|
AreaGraph = 1 /**< Plot bandwidth as alpha blended area graphs. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Default Constructor */
|
/** Default Constructor */
|
||||||
RSGraphWidget(QWidget *parent = 0);
|
RSGraphWidget(QWidget *parent = 0);
|
||||||
/** Default Destructor */
|
/** Default Destructor */
|
||||||
~RSGraphWidget();
|
~RSGraphWidget();
|
||||||
|
|
||||||
// sets the update interval period.
|
// sets the update interval period.
|
||||||
//
|
//
|
||||||
void setTimerPeriod(int miliseconds) ;
|
void setTimerPeriod(int miliseconds) ;
|
||||||
void setSource(RSGraphSource *gs) ;
|
void setSource(RSGraphSource *gs) ;
|
||||||
void setTimeScale(float pixels_per_second) ;
|
void setTimeScale(float pixels_per_second) ;
|
||||||
|
|
||||||
/** Add data points. */
|
/** Add data points. */
|
||||||
//void addPoints(qreal rsDHT, qreal allDHT);
|
//void addPoints(qreal rsDHT, qreal allDHT);
|
||||||
/** Clears the graph. */
|
/** Clears the graph. */
|
||||||
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);
|
||||||
|
|
||||||
void setShowEntry(uint32_t entry, bool show) ;
|
void setShowEntry(uint32_t entry, bool show) ;
|
||||||
void setCurvesOpacity(float f) ;
|
void setCurvesOpacity(float f) ;
|
||||||
|
|
||||||
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 ; }
|
||||||
protected:
|
protected:
|
||||||
/** Overloaded QWidget::paintEvent() */
|
/** Overloaded QWidget::paintEvent() */
|
||||||
void paintEvent(QPaintEvent *event);
|
void paintEvent(QPaintEvent *event);
|
||||||
|
|
||||||
virtual QSizeF sizeHint( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
|
virtual QSizeF sizeHint( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void updateIfPossible() ;
|
void updateIfPossible() ;
|
||||||
|
|
||||||
virtual void wheelEvent(QWheelEvent *e);
|
virtual void wheelEvent(QWheelEvent *e);
|
||||||
private:
|
private:
|
||||||
/** Gets the width of the desktop, the max # of points. */
|
/** Gets the width of the desktop, the max # of points. */
|
||||||
int getNumPoints();
|
int getNumPoints();
|
||||||
|
|
||||||
/** Paints an integral and an outline of that integral for each data set
|
/** Paints an integral and an outline of that integral for each data set
|
||||||
* (rsdht and/or alldht) that is to be displayed. */
|
* (rsdht and/or alldht) that is to be displayed. */
|
||||||
void paintData();
|
void paintData();
|
||||||
/** 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 paintLegend();
|
void paintLegend();
|
||||||
/** Paints the scale in the graph. */
|
/** Paints the scale in the graph. */
|
||||||
void paintScale1();
|
void paintScale1();
|
||||||
void paintScale2();
|
void paintScale2();
|
||||||
|
|
||||||
QColor getColor(int i) ;
|
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
|
||||||
* of rsdht or alldht values. */
|
* of rsdht or alldht values. */
|
||||||
void pointsFromData(const std::vector<QPointF>& values, QVector<QPointF> &points ) ;
|
void pointsFromData(const std::vector<QPointF>& values, QVector<QPointF> &points ) ;
|
||||||
|
|
||||||
/** Paints a line with the data in <b>points</b>. */
|
/** Paints a line with the data in <b>points</b>. */
|
||||||
void paintLine(const QVector<QPointF>& points, QColor color,
|
void paintLine(const QVector<QPointF>& points, QColor color,
|
||||||
Qt::PenStyle lineStyle = Qt::SolidLine);
|
Qt::PenStyle lineStyle = Qt::SolidLine);
|
||||||
/** 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);
|
||||||
|
|
||||||
/** 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. */
|
||||||
QRect _rec;
|
QRect _rec;
|
||||||
/** The maximum data value plotted. */
|
/** The maximum data value plotted. */
|
||||||
qreal _maxValue;
|
qreal _maxValue;
|
||||||
/** The maximum number of points to store. */
|
/** The maximum number of points to store. */
|
||||||
qreal _y_scale ;
|
qreal _y_scale ;
|
||||||
qreal _opacity ;
|
qreal _opacity ;
|
||||||
|
|
||||||
qreal pixelsToValue(qreal) ;
|
qreal pixelsToValue(qreal) ;
|
||||||
qreal valueToPixels(qreal) ;
|
qreal valueToPixels(qreal) ;
|
||||||
int _maxPoints;
|
int _maxPoints;
|
||||||
|
|
||||||
std::set<std::string> _masked_entries ;
|
std::set<std::string> _masked_entries ;
|
||||||
|
|
||||||
qreal _time_scale ; // horizontal scale in pixels per sec.
|
qreal _time_scale ; // horizontal scale in pixels per sec.
|
||||||
|
qreal _time_filter ; // time filter. Goes from 0 to infinity. Will be converted into 1-1/(1+f)
|
||||||
|
|
||||||
/** Show the respective lines and counters. */
|
/** Show the respective lines and counters. */
|
||||||
//bool _showRSDHT;
|
//bool _showRSDHT;
|
||||||
//bool _showALLDHT;
|
//bool _showALLDHT;
|
||||||
|
|
||||||
uint32_t _flags ;
|
uint32_t _flags ;
|
||||||
QTimer *_timer ;
|
QTimer *_timer ;
|
||||||
|
|
||||||
RSGraphSource *_source ;
|
RSGraphSource *_source ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue