Skip to content

Commit d68eeca

Browse files
committed
qt: Enhance TrafficGraphWidget with multi-timeframe support and data persistence
This commit significantly improves the network traffic graph widget with: 1. Multiple timeframe support - View traffic data across different time periods (5 minutes to 28 days) using an enhanced slider interface 2. Traffic data persistence - Save and restore traffic information between sessions, preserving historical traffic patterns 3. Interactive visualization features: - Logarithmic scale toggle (mouse click) for better visualization of varying traffic volumes - Interactive tooltips showing detailed traffic information at specific points - Yellow highlight indicators for selected data points 4. Smooth transitions between different time ranges with animated scaling These improvements allow users to better monitor and analyze network traffic patterns over time, which is especially useful for debugging connectivity issues or understanding network behavior under different conditions. The implementation includes proper thread-safety considerations and handles edge cases like time jumps or missing data appropriately.
1 parent 6a046e5 commit d68eeca

File tree

5 files changed

+656
-117
lines changed

5 files changed

+656
-117
lines changed

src/qt/forms/debugwindow.ui

+13-14
Original file line numberDiff line numberDiff line change
@@ -665,20 +665,29 @@
665665
<item>
666666
<widget class="QSlider" name="sldGraphRange">
667667
<property name="minimum">
668-
<number>1</number>
668+
<number>0</number>
669669
</property>
670670
<property name="maximum">
671-
<number>288</number>
671+
<number>2400</number>
672+
</property>
673+
<property name="singleStep">
674+
<number>200</number>
672675
</property>
673676
<property name="pageStep">
674-
<number>12</number>
677+
<number>200</number>
675678
</property>
676679
<property name="value">
677-
<number>6</number>
680+
<number>0</number>
678681
</property>
679682
<property name="orientation">
680683
<enum>Qt::Horizontal</enum>
681684
</property>
685+
<property name="tickPosition">
686+
<enum>QSlider::TicksBelow</enum>
687+
</property>
688+
<property name="tickInterval">
689+
<number>200</number>
690+
</property>
682691
</widget>
683692
</item>
684693
<item>
@@ -694,16 +703,6 @@
694703
</property>
695704
</widget>
696705
</item>
697-
<item>
698-
<widget class="QPushButton" name="btnClearTrafficGraph">
699-
<property name="text">
700-
<string>&amp;Reset</string>
701-
</property>
702-
<property name="autoDefault">
703-
<bool>false</bool>
704-
</property>
705-
</widget>
706-
</item>
707706
</layout>
708707
</item>
709708
</layout>

src/qt/rpcconsole.cpp

+51-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
using util::Join;
5454

5555
const int CONSOLE_HISTORY = 50;
56-
const int INITIAL_TRAFFIC_GRAPH_MINS = 30;
5756
const QSize FONT_RANGE(4, 40);
5857
const char fontSizeSettingsKey[] = "consoleFontSize";
5958

@@ -566,7 +565,6 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
566565
connect(ui->clearButton, &QAbstractButton::clicked, [this] { clear(); });
567566
connect(ui->fontBiggerButton, &QAbstractButton::clicked, this, &RPCConsole::fontBigger);
568567
connect(ui->fontSmallerButton, &QAbstractButton::clicked, this, &RPCConsole::fontSmaller);
569-
connect(ui->btnClearTrafficGraph, &QPushButton::clicked, ui->trafficGraph, &TrafficGraphWidget::clear);
570568

571569
// disable the wallet selector by default
572570
ui->WalletSelector->setVisible(false);
@@ -578,7 +576,7 @@ RPCConsole::RPCConsole(interfaces::Node& node, const PlatformStyle *_platformSty
578576
// based timer interface
579577
m_node.rpcSetTimerInterfaceIfUnset(rpcTimerInterface);
580578

581-
setTrafficGraphRange(INITIAL_TRAFFIC_GRAPH_MINS);
579+
setTrafficGraphRange(1); // 1 is the lowest setting (0 bumps up)
582580
updateDetailWidget();
583581

584582
consoleFontSize = settings.value(fontSizeSettingsKey, QFont().pointSize()).toInt();
@@ -1166,21 +1164,64 @@ void RPCConsole::scrollToEnd()
11661164

11671165
void RPCConsole::on_sldGraphRange_valueChanged(int value)
11681166
{
1169-
const int multiplier = 5; // each position on the slider represents 5 min
1170-
int mins = value * multiplier;
1171-
setTrafficGraphRange(mins);
1167+
static int64_t last_click_time = 0;
1168+
static bool last_click_was_up = false;
1169+
unsigned int range = (value + 100) / 200 + 1; // minimum of 1, 0 reserve for scale bump
1170+
bool bouncing = false;
1171+
if (!m_slider_in_use) {
1172+
// Avoid accidental oscillation of direction due to rapid mouse clicks
1173+
int64_t now = GetTime<std::chrono::milliseconds>().count();
1174+
bool this_click_is_up = false;
1175+
if (value > m_set_slider_value) this_click_is_up = true;
1176+
if (now - last_click_time < 250 && this_click_is_up != last_click_was_up) {
1177+
bouncing = true;
1178+
ui->sldGraphRange->blockSignals(true);
1179+
ui->sldGraphRange->setValue(m_set_slider_value);
1180+
ui->sldGraphRange->blockSignals(false);
1181+
}
1182+
last_click_time = now;
1183+
last_click_was_up = this_click_is_up;
1184+
}
1185+
m_set_slider_value = value;
1186+
if (bouncing) return;
1187+
setTrafficGraphRange(range);
11721188
}
11731189

1174-
void RPCConsole::setTrafficGraphRange(int mins)
1190+
void RPCConsole::setTrafficGraphRange(int value)
11751191
{
1176-
ui->trafficGraph->setGraphRange(std::chrono::minutes{mins});
1192+
int mins = ui->trafficGraph->setGraphRange(value);
1193+
if (value)
1194+
m_set_slider_value = (value - 1) * 200;
1195+
else {
1196+
// When bumping, calculate the proper slider position based on the traffic graph's new value
1197+
unsigned int new_graph_value = ui->trafficGraph->getCurrentRangeIndex() + 1; // +1 because the index is 0-based
1198+
m_set_slider_value = (new_graph_value - 1) * 200;
1199+
ui->sldGraphRange->blockSignals(true);
1200+
ui->sldGraphRange->setValue(m_set_slider_value);
1201+
ui->sldGraphRange->blockSignals(false);
1202+
}
11771203
ui->lblGraphRange->setText(GUIUtil::formatDurationStr(std::chrono::minutes{mins}));
11781204
}
11791205

1206+
void RPCConsole::on_sldGraphRange_sliderReleased()
1207+
{
1208+
ui->sldGraphRange->setValue(m_set_slider_value);
1209+
m_slider_in_use = false;
1210+
}
1211+
1212+
void RPCConsole::on_sldGraphRange_sliderPressed() { m_slider_in_use = true; }
1213+
11801214
void RPCConsole::updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut)
11811215
{
1182-
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalBytesIn));
1183-
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalBytesOut));
1216+
if (!m_slider_in_use && ui->trafficGraph->GraphRangeBump())
1217+
setTrafficGraphRange(0); // bump it up
1218+
1219+
// Add baseline values to the current node values
1220+
quint64 totalIn = totalBytesIn + ui->trafficGraph->getBaselineBytesRecv();
1221+
quint64 totalOut = totalBytesOut + ui->trafficGraph->getBaselineBytesSent();
1222+
1223+
ui->lblBytesIn->setText(GUIUtil::formatBytes(totalIn));
1224+
ui->lblBytesOut->setText(GUIUtil::formatBytes(totalOut));
11841225
}
11851226

11861227
void RPCConsole::updateDetailWidget()

src/qt/rpcconsole.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ private Q_SLOTS:
9090
void on_openDebugLogfileButton_clicked();
9191
/** change the time range of the network traffic graph */
9292
void on_sldGraphRange_valueChanged(int value);
93+
void on_sldGraphRange_sliderReleased();
94+
void on_sldGraphRange_sliderPressed();
9395
/** update traffic statistics */
9496
void updateTrafficStats(quint64 totalBytesIn, quint64 totalBytesOut);
9597
void resizeEvent(QResizeEvent *event) override;
@@ -146,10 +148,9 @@ public Q_SLOTS:
146148
} const ts;
147149

148150
void startExecutor();
149-
void setTrafficGraphRange(int mins);
151+
void setTrafficGraphRange(int value);
150152

151-
enum ColumnWidths
152-
{
153+
enum ColumnWidths {
153154
ADDRESS_COLUMN_WIDTH = 200,
154155
SUBVERSION_COLUMN_WIDTH = 150,
155156
PING_COLUMN_WIDTH = 80,
@@ -177,6 +178,8 @@ public Q_SLOTS:
177178
bool m_is_executing{false};
178179
QByteArray m_peer_widget_header_state;
179180
QByteArray m_banlist_widget_header_state;
181+
bool m_slider_in_use{false};
182+
int m_set_slider_value{0};
180183

181184
/** Update UI with latest network info from model. */
182185
void updateNetworkState();

0 commit comments

Comments
 (0)