From 9c9ea4460c50d2140f402a7537864ebca8653622 Mon Sep 17 00:00:00 2001 From: R E Broadley Date: Wed, 24 Nov 2021 21:41:37 +0100 Subject: [PATCH 01/13] gui: network graph - remove uneccesary clear() when changing interval --- src/qt/trafficgraphwidget.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index ac103e9dc3b..373361b5ecf 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -159,8 +159,7 @@ void TrafficGraphWidget::setGraphRangeMins(int mins) int msecsPerSample = nMins * 60 * 1000 / DESIRED_SAMPLES; timer->stop(); timer->setInterval(msecsPerSample); - - clear(); + timer->start(); } void TrafficGraphWidget::clear() From 0fc40e32239c14cd206ec596de48033302e519de Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Tue, 25 Jan 2022 18:50:24 -0500 Subject: [PATCH 02/13] gui: network graph - scale view based on time interval --- src/qt/trafficgraphwidget.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index 373361b5ecf..d1b5132b629 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -55,7 +55,7 @@ void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue &samples) int x = XMARGIN + w; path.moveTo(x, YMARGIN + h); for(int i = 0; i < sampleCount; ++i) { - x = XMARGIN + w - w * i / DESIRED_SAMPLES; + x = XMARGIN + w - w * i / DESIRED_SAMPLES / (getGraphRangeMins()/5); int y = YMARGIN + h - (int)(h * samples.at(i) / fMax); path.lineTo(x, y); } @@ -135,10 +135,10 @@ void TrafficGraphWidget::updateRates() nLastBytesIn = bytesIn; nLastBytesOut = bytesOut; - while(vSamplesIn.size() > DESIRED_SAMPLES) { + while(vSamplesIn.size() > DESIRED_SAMPLES * (getGraphRangeMins() / 5)) { vSamplesIn.pop_back(); } - while(vSamplesOut.size() > DESIRED_SAMPLES) { + while(vSamplesOut.size() > DESIRED_SAMPLES * (getGraphRangeMins() / 5)) { vSamplesOut.pop_back(); } @@ -159,6 +159,7 @@ void TrafficGraphWidget::setGraphRangeMins(int mins) int msecsPerSample = nMins * 60 * 1000 / DESIRED_SAMPLES; timer->stop(); timer->setInterval(msecsPerSample); + update(); timer->start(); } From 55bae833d092cb60993fae8cce0f2d9128a06399 Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Wed, 26 Jan 2022 20:42:32 -0500 Subject: [PATCH 03/13] gui: network graph - retain enough samples for large time intervals --- src/qt/trafficgraphwidget.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index d1b5132b629..21c78f9fced 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -12,6 +12,7 @@ #include #include +#include #define DESIRED_SAMPLES 800 @@ -135,10 +136,10 @@ void TrafficGraphWidget::updateRates() nLastBytesIn = bytesIn; nLastBytesOut = bytesOut; - while(vSamplesIn.size() > DESIRED_SAMPLES * (getGraphRangeMins() / 5)) { + while(vSamplesIn.size() > FLT_MAX - 1) { vSamplesIn.pop_back(); } - while(vSamplesOut.size() > DESIRED_SAMPLES * (getGraphRangeMins() / 5)) { + while(vSamplesOut.size() > FLT_MAX - 1) { vSamplesOut.pop_back(); } @@ -156,7 +157,7 @@ void TrafficGraphWidget::updateRates() void TrafficGraphWidget::setGraphRangeMins(int mins) { nMins = mins; - int msecsPerSample = nMins * 60 * 1000 / DESIRED_SAMPLES; + int msecsPerSample = nMins * 60 * 1000 / (DESIRED_SAMPLES * (getGraphRangeMins() / 5)); timer->stop(); timer->setInterval(msecsPerSample); update(); From 1d8a548476d5be29ac314f5cb991d4b243fa65e1 Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Thu, 27 Jan 2022 00:58:04 -0500 Subject: [PATCH 04/13] gui: network graph - fix left margin to hide paths --- src/qt/trafficgraphwidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index 21c78f9fced..c2359ca79dc 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -121,6 +121,7 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) painter.setPen(Qt::red); painter.drawPath(p); } + painter.fillRect(0,0,XMARGIN,height(), Qt::black); } void TrafficGraphWidget::updateRates() From aaf1bc3daed9655d33e2927fc2d9a152f680e376 Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Fri, 28 Jan 2022 01:16:18 -0500 Subject: [PATCH 05/13] gui: network graph - use samples subset to determine tmax --- src/qt/trafficgraphwidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index c2359ca79dc..044efef4454 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -145,10 +145,10 @@ void TrafficGraphWidget::updateRates() } float tmax = 0.0f; - for (const float f : vSamplesIn) { + for (const float f : vSamplesIn.mid(0,(DESIRED_SAMPLES*(getGraphRangeMins()/5)))) { if(f > tmax) tmax = f; } - for (const float f : vSamplesOut) { + for (const float f : vSamplesOut.mid(0,(DESIRED_SAMPLES*(getGraphRangeMins()/5)))) { if(f > tmax) tmax = f; } fMax = tmax; From 85b6adb008fefd93ee4c2b304a7da9a28f87fa1c Mon Sep 17 00:00:00 2001 From: Shashwat Date: Wed, 12 Jan 2022 19:06:28 +0530 Subject: [PATCH 06/13] qt:refactor: Use std::chrono in TrafficGraphWidget class --- src/qt/rpcconsole.cpp | 4 +++- src/qt/trafficgraphwidget.cpp | 16 ++++++++++------ src/qt/trafficgraphwidget.h | 6 ++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 08729a77220..c5e5e69df6a 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -54,6 +54,8 @@ #include #include +#include + const int CONSOLE_HISTORY = 50; const int INITIAL_TRAFFIC_GRAPH_MINS = 30; const QSize FONT_RANGE(4, 40); @@ -1140,7 +1142,7 @@ void RPCConsole::on_sldGraphRange_valueChanged(int value) void RPCConsole::setTrafficGraphRange(int mins) { - ui->trafficGraph->setGraphRangeMins(mins); + ui->trafficGraph->setGraphRange(std::chrono::minutes{mins}); ui->lblGraphRange->setText(GUIUtil::formatDurationStr(std::chrono::minutes{mins})); } diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index 044efef4454..dc768dfbb38 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -145,22 +146,25 @@ void TrafficGraphWidget::updateRates() } float tmax = 0.0f; - for (const float f : vSamplesIn.mid(0,(DESIRED_SAMPLES*(getGraphRangeMins()/5)))) { + for (const float f : vSamplesIn.mid(0,(DESIRED_SAMPLES*getGraphRangeMins()/5))) { if(f > tmax) tmax = f; } - for (const float f : vSamplesOut.mid(0,(DESIRED_SAMPLES*(getGraphRangeMins()/5)))) { + for (const float f : vSamplesOut.mid(0,(DESIRED_SAMPLES*getGraphRangeMins()/5))) { if(f > tmax) tmax = f; } fMax = tmax; update(); } -void TrafficGraphWidget::setGraphRangeMins(int mins) +void TrafficGraphWidget::setGraphRange(std::chrono::minutes new_range) { - nMins = mins; - int msecsPerSample = nMins * 60 * 1000 / (DESIRED_SAMPLES * (getGraphRangeMins() / 5)); + using namespace std::chrono_literals; + const auto range{new_range}; + nMins = new_range.count(); + auto msecs_per_sample = nMins * 60 * 1000 / (DESIRED_SAMPLES * (range.count() / 5)); timer->stop(); - timer->setInterval(msecsPerSample); + timer->setInterval(msecs_per_sample); + update(); timer->start(); } diff --git a/src/qt/trafficgraphwidget.h b/src/qt/trafficgraphwidget.h index 2d8c825815a..d2768cbba19 100644 --- a/src/qt/trafficgraphwidget.h +++ b/src/qt/trafficgraphwidget.h @@ -8,6 +8,8 @@ #include #include +#include + class ClientModel; QT_BEGIN_NAMESPACE @@ -29,7 +31,7 @@ class TrafficGraphWidget : public QWidget public Q_SLOTS: void updateRates(); - void setGraphRangeMins(int mins); + void setGraphRange(std::chrono::minutes new_range); void clear(); private: @@ -37,7 +39,7 @@ public Q_SLOTS: QTimer *timer; float fMax; - int nMins; + long nMins; QQueue vSamplesIn; QQueue vSamplesOut; quint64 nLastBytesIn; From c7ac1b824b73d0632373d84a1d966a5ad16a3205 Mon Sep 17 00:00:00 2001 From: R E Broadley Date: Thu, 2 Dec 2021 13:27:34 +0100 Subject: [PATCH 07/13] gui: network graph - add log-scale toggle --- src/qt/trafficgraphwidget.cpp | 52 +++++++++++++++++++++++------------ src/qt/trafficgraphwidget.h | 3 ++ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index dc768dfbb38..904a568d65d 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -49,22 +49,35 @@ int TrafficGraphWidget::getGraphRangeMins() const return nMins; } +int TrafficGraphWidget::y_value(float value) +{ + int h = height() - YMARGIN * 2; + return YMARGIN + h - (h * 1.0 * (fToggle ? (pow(value, 0.30102) / pow(fMax, 0.30102)) : (value / fMax))); +} + void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue &samples) { int sampleCount = samples.size(); - if(sampleCount > 0) { + if(sampleCount > 0 && fMax > 0) { int h = height() - YMARGIN * 2, w = width() - XMARGIN * 2; int x = XMARGIN + w; path.moveTo(x, YMARGIN + h); for(int i = 0; i < sampleCount; ++i) { x = XMARGIN + w - w * i / DESIRED_SAMPLES / (getGraphRangeMins()/5); - int y = YMARGIN + h - (int)(h * samples.at(i) / fMax); + int y = y_value(samples.at(i)); path.lineTo(x, y); } path.lineTo(x, YMARGIN + h); } } +void TrafficGraphWidget::mousePressEvent(QMouseEvent *event) +{ + QWidget::mousePressEvent(event); + fToggle = !fToggle; + update(); +} + void TrafficGraphWidget::paintEvent(QPaintEvent *) { QPainter painter(this); @@ -84,28 +97,33 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) const QString units = tr("kB/s"); const float yMarginText = 2.0; - // draw lines - painter.setPen(axisCol); - painter.drawText(XMARGIN, YMARGIN + h - h * val / fMax-yMarginText, QString("%1 %2").arg(val).arg(units)); - for(float y = val; y < fMax; y += val) { - int yy = YMARGIN + h - h * y / fMax; - painter.drawLine(XMARGIN, yy, width() - XMARGIN, yy); - } - // if we drew 3 or fewer lines, break them up at the next lower order of magnitude - if(fMax / val <= 3.0f) { - axisCol = axisCol.darker(); + // if we drew 10 or 3 fewer lines, break them up at the next lower order of magnitude + if(fMax / val <= (fToggle ? 10.0f : 3.0f)) { + float oldval = val; val = pow(10.0f, base - 1); - painter.setPen(axisCol); - painter.drawText(XMARGIN, YMARGIN + h - h * val / fMax-yMarginText, QString("%1 %2").arg(val).arg(units)); + painter.setPen(axisCol.darker()); + painter.drawText(XMARGIN, y_value(val)-yMarginText, QString("%1 %2").arg(val).arg(units)); + if (fToggle) { + int yy = y_value(val*0.1); + painter.drawText(XMARGIN, yy-yMarginText, QString("%1 %2").arg(val*0.1).arg(units)); + painter.drawLine(XMARGIN, yy, width() - XMARGIN, yy); + } int count = 1; - for(float y = val; y < fMax; y += val, count++) { - // don't overwrite lines drawn above + for(float y = val; y < (!fToggle || fMax / val < 20 ? fMax : oldval); y += val, count++) { if(count % 10 == 0) continue; - int yy = YMARGIN + h - h * y / fMax; + int yy = y_value(y); painter.drawLine(XMARGIN, yy, width() - XMARGIN, yy); } + val = oldval; + } + // draw lines + painter.setPen(axisCol); + for(float y = val; y < fMax; y += val) { + int yy = y_value(y); + painter.drawLine(XMARGIN, yy, width() - XMARGIN, yy); } + painter.drawText(XMARGIN, y_value(val)-yMarginText, QString("%1 %2").arg(val).arg(units)); painter.setRenderHint(QPainter::Antialiasing); if(!vSamplesIn.empty()) { diff --git a/src/qt/trafficgraphwidget.h b/src/qt/trafficgraphwidget.h index d2768cbba19..19878cf0c71 100644 --- a/src/qt/trafficgraphwidget.h +++ b/src/qt/trafficgraphwidget.h @@ -28,6 +28,9 @@ class TrafficGraphWidget : public QWidget protected: void paintEvent(QPaintEvent *) override; + int y_value(float value); + void mousePressEvent(QMouseEvent *event) override; + bool fToggle = true; public Q_SLOTS: void updateRates(); From f0871d15d076d845b4e65b362b959d1750ed4cc9 Mon Sep 17 00:00:00 2001 From: R E Broadley Date: Thu, 2 Dec 2021 13:27:34 +0100 Subject: [PATCH 08/13] gui: network graph - add log-scale toggle on double click --- src/qt/trafficgraphwidget.cpp | 2 +- src/qt/trafficgraphwidget.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index 904a568d65d..cb44ced4807 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -71,7 +71,7 @@ void TrafficGraphWidget::paintPath(QPainterPath &path, QQueue &samples) } } -void TrafficGraphWidget::mousePressEvent(QMouseEvent *event) +void TrafficGraphWidget::mouseDoubleClickEvent(QMouseEvent *event) { QWidget::mousePressEvent(event); fToggle = !fToggle; diff --git a/src/qt/trafficgraphwidget.h b/src/qt/trafficgraphwidget.h index 19878cf0c71..f6d8eb89785 100644 --- a/src/qt/trafficgraphwidget.h +++ b/src/qt/trafficgraphwidget.h @@ -29,7 +29,7 @@ class TrafficGraphWidget : public QWidget protected: void paintEvent(QPaintEvent *) override; int y_value(float value); - void mousePressEvent(QMouseEvent *event) override; + void mouseDoubleClickEvent(QMouseEvent *event) override; bool fToggle = true; public Q_SLOTS: From 909494147edb6a3ada89f4a12cbbe2987af8e4f4 Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Sat, 29 Jan 2022 08:03:33 -0500 Subject: [PATCH 09/13] gui: network graph - clean up colors - look better in log scale --- src/qt/trafficgraphwidget.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index cb44ced4807..da9ba4fe2c8 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -85,7 +85,7 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) if(fMax <= 0.0f) return; - QColor axisCol(Qt::gray); + QColor axisCol(QColor(78,78,78,255)); int h = height() - YMARGIN * 2; painter.setPen(axisCol); painter.drawLine(XMARGIN, YMARGIN + h, width() - XMARGIN, YMARGIN + h); @@ -101,7 +101,7 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) if(fMax / val <= (fToggle ? 10.0f : 3.0f)) { float oldval = val; val = pow(10.0f, base - 1); - painter.setPen(axisCol.darker()); + painter.setPen(axisCol.lighter()); painter.drawText(XMARGIN, y_value(val)-yMarginText, QString("%1 %2").arg(val).arg(units)); if (fToggle) { int yy = y_value(val*0.1); @@ -126,20 +126,25 @@ void TrafficGraphWidget::paintEvent(QPaintEvent *) painter.drawText(XMARGIN, y_value(val)-yMarginText, QString("%1 %2").arg(val).arg(units)); painter.setRenderHint(QPainter::Antialiasing); + if(!vSamplesIn.empty()) { QPainterPath p; paintPath(p, vSamplesIn); - painter.fillPath(p, QColor(0, 255, 0, 128)); - painter.setPen(Qt::green); + QPen ppen (QColor(0,255,0,0),0,Qt::SolidLine); + painter.setPen(ppen); + painter.fillPath(p, QColor(0, 255, 0, 255)); painter.drawPath(p); } + if(!vSamplesOut.empty()) { QPainterPath p; paintPath(p, vSamplesOut); - painter.fillPath(p, QColor(255, 0, 0, 128)); - painter.setPen(Qt::red); + QPen ppen (QColor(255,0,0,0),0,Qt::SolidLine); + painter.setPen(ppen); + painter.fillPath(p, QColor(255, 0, 0, 255)); painter.drawPath(p); } + painter.fillRect(0,0,XMARGIN,height(), Qt::black); } From 255774f35fb0bc972f768c230e7942f970805d6b Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Sat, 29 Jan 2022 13:50:28 -0500 Subject: [PATCH 10/13] gui: network graph - set initial QSlider value to first position (5 mins) --- src/qt/forms/debugwindow.ui | 2 +- src/qt/rpcconsole.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/debugwindow.ui b/src/qt/forms/debugwindow.ui index 21968010230..fbdda8b8963 100644 --- a/src/qt/forms/debugwindow.ui +++ b/src/qt/forms/debugwindow.ui @@ -639,7 +639,7 @@ 12 - 6 + 1 Qt::Horizontal diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index c5e5e69df6a..4f142d704b6 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -57,7 +57,7 @@ #include const int CONSOLE_HISTORY = 50; -const int INITIAL_TRAFFIC_GRAPH_MINS = 30; +const int INITIAL_TRAFFIC_GRAPH_MINS = 5; const QSize FONT_RANGE(4, 40); const char fontSizeSettingsKey[] = "consoleFontSize"; From bb5b4cc41c700dc1a9c97f8e112e183f436f3ef1 Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Wed, 2 Feb 2022 03:08:14 -0500 Subject: [PATCH 11/13] gui: netowrk graph - reduce DESIRED_SAMPLES to 300 --- src/qt/trafficgraphwidget.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/trafficgraphwidget.cpp b/src/qt/trafficgraphwidget.cpp index da9ba4fe2c8..ef40df7bee2 100644 --- a/src/qt/trafficgraphwidget.cpp +++ b/src/qt/trafficgraphwidget.cpp @@ -15,7 +15,7 @@ #include #include -#define DESIRED_SAMPLES 800 +#define DESIRED_SAMPLES 300 #define XMARGIN 10 #define YMARGIN 10 From c0f46d293a283fd0bbcab168ff7e2ebfc383d81b Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Wed, 2 Feb 2022 03:15:50 -0500 Subject: [PATCH 12/13] gui: netowrk graph - linear scale default --- src/qt/trafficgraphwidget.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qt/trafficgraphwidget.h b/src/qt/trafficgraphwidget.h index f6d8eb89785..90e176645f3 100644 --- a/src/qt/trafficgraphwidget.h +++ b/src/qt/trafficgraphwidget.h @@ -30,7 +30,7 @@ class TrafficGraphWidget : public QWidget void paintEvent(QPaintEvent *) override; int y_value(float value); void mouseDoubleClickEvent(QMouseEvent *event) override; - bool fToggle = true; + bool fToggle = false; public Q_SLOTS: void updateRates(); From 874b2d8ced4e63fb4a2d95951373e1a845d7231b Mon Sep 17 00:00:00 2001 From: randymcmillan Date: Mon, 31 Jan 2022 13:27:02 -0500 Subject: [PATCH 13/13] gui: network graph - show/hide panels based on window width/height The debugwindow - network graph hides ui elements btnClearTrafficGraph, lblGraphRange, sldGraphRange when at minimumHeight, it also hides the groupBox at minimumWidth - this maximizes the dimensions of the traffic graph in these small dimensions. --- src/qt/rpcconsole.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 4f142d704b6..598bb41fcb1 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -1228,6 +1228,22 @@ void RPCConsole::updateDetailWidget() void RPCConsole::resizeEvent(QResizeEvent *event) { QWidget::resizeEvent(event); + if (width()<=minimumWidth()*2){ + ui->groupBox->hide(); + }else{ + ui->groupBox->show(); + } + if (height()==minimumHeight()){ + ui->sldGraphRange->hide(); + ui->lblGraphRange->hide(); + ui->btnClearTrafficGraph->hide(); + }else{ + ui->sldGraphRange->show(); + ui->lblGraphRange->show(); + ui->btnClearTrafficGraph->show(); + } + + } void RPCConsole::showEvent(QShowEvent *event)