Skip to content

Commit f1f0b53

Browse files
authored
fine-tune metrics bar sizing
1 parent 122d45e commit f1f0b53

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/metrics_bar.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,11 @@ def setup_metrics_buffers(self):
244244
### Sparkline Visualization Class ###
245245

246246
class Sparkline(QWidget):
247-
def __init__(self, max_values=150, color="#0074D9"):
247+
def __init__(self, max_values=125, color="#0074D9"):
248248
super().__init__()
249249
self.max_values = max_values
250250
self.values = deque(maxlen=max_values)
251-
self.setFixedSize(90, 65)
251+
self.setFixedSize(125, 65)
252252
self.color = QColor(color)
253253

254254
def add_value(self, value):
@@ -418,8 +418,9 @@ def __init__(self, min_value=0, max_value=100, colors=None):
418418
self.min_value = min_value
419419
self.max_value = max_value
420420
self.current_value = 0
421+
# To change colors, modify this list. Each color corresponds to a section of the speedometer.
421422
self.colors = colors or ["#00FF00", "#FFFF00", "#FF0000"] # Green, Yellow, Red
422-
self.setFixedSize(65, 65) # pixel size
423+
self.setFixedSize(105, 105) # Adjust these values to change the overall size of the speedometer
423424

424425
def set_value(self, value):
425426
self.current_value = max(self.min_value, min(self.max_value, value))
@@ -433,7 +434,7 @@ def paintEvent(self, event):
433434
height = self.height()
434435
center_x = width / 2
435436
center_y = height / 2
436-
radius = min(width, height) / 2 * 0.7 # Adjusted radius
437+
radius = min(width, height) / 2 * 0.7 # Adjust the 0.7 factor to change the size of the arc relative to the widget
437438

438439
# Colored background arc
439440
start_angle = 180 * 16
@@ -454,8 +455,8 @@ def paintEvent(self, event):
454455
self.max_value - self.min_value
455456
) * 180
456457

457-
needle_length = radius * 0.9 # Needle length of 90% of radius
458-
needle_width = 5 # Thickness of the needle
458+
needle_length = radius * 0.9 # Adjust this factor to change the length of the needle
459+
needle_width = 5 # Adjust this value to change the thickness of the needle
459460
needle_angle = angle * (pi / 180)
460461

461462
needle_tip_x = center_x + needle_length * cos(needle_angle)
@@ -477,10 +478,12 @@ def paintEvent(self, event):
477478
needle = QPolygon([point1.toPoint(), point2.toPoint(), point3.toPoint()])
478479

479480
painter.setPen(Qt.NoPen)
480-
painter.setBrush(Qt.white)
481+
painter.setBrush(Qt.white) # Change this color to modify the needle color
481482
painter.drawPolygon(needle)
482483

483484
def get_color_at_angle(self, angle):
485+
# This method determines the color gradient of the speedometer.
486+
# Modify the color interpolation logic here to change the appearance.
484487
t = angle / 180
485488
if t <= 0:
486489
return QColor(self.colors[0])
@@ -507,14 +510,14 @@ def __init__(self):
507510

508511
def initUI(self):
509512
main_layout = QGridLayout(self)
510-
main_layout.setSpacing(1)
511-
main_layout.setContentsMargins(1, 1, 1, 1)
513+
main_layout.setSpacing(1) # Adjust this value to change the spacing between speedometers
514+
main_layout.setContentsMargins(1, 1, 1, 1) # Adjust these values to change the margins around the speedometers
512515

513516
def create_speedometer_group(name):
514517
group = QVBoxLayout()
515-
group.setSpacing(2) # spacing within the group
516-
speedometer = Speedometer(colors=["#00FF00", "#FFFF00", "#FF0000"])
517-
speedometer.setFixedSize(65, 65) # speedometer pixel size
518+
group.setSpacing(2) # Adjust this value to change the spacing between the speedometer and its label
519+
speedometer = Speedometer(colors=["#00FF00", "#FFFF00", "#FF0000"]) # Modify these colors to change the speedometer appearance
520+
speedometer.setFixedSize(105, 105) # Adjust these values to change the size of individual speedometers
518521
group.addWidget(speedometer, alignment=Qt.AlignCenter)
519522
label = QLabel(f"{name} 0.0%")
520523
label.setAlignment(Qt.AlignCenter)
@@ -556,6 +559,8 @@ def create_speedometer_group(name):
556559
main_layout.setColumnStretch(i, 1)
557560

558561
def update_metrics(self, metrics):
562+
# This method updates the speedometer values
563+
# Modify the formatting of the label text here if needed
559564
(
560565
cpu_usage,
561566
ram_usage_percent,
@@ -597,7 +602,7 @@ def update_metrics(self, metrics):
597602

598603
# Sets number of samples in rolling average to display
599604
def setup_metrics_buffers(self):
600-
buffer_size = 5
605+
buffer_size = 5 # Adjust this value to change the number of samples used for the rolling average
601606
self.cpu_buffer = deque(maxlen=buffer_size)
602607
self.ram_buffer = deque(maxlen=buffer_size)
603608
self.gpu_buffer = deque(maxlen=buffer_size)

0 commit comments

Comments
 (0)