Created attachment 148139 [details]
Screenshot of not particularly meaningful horizontal bars.
I'd like to use the Horizontal Bars style to show my total CPU usage, RAM usage, and Swap usage. But because of the way the bars are designed to show a dot with the bar's radius even when the value is zero, I can't get any useful information from it that way.
If I try tweaking the QML such that it does take zero as a valid value, what ends up happening is that the left side of the bar has zero radius whenever the value is less than the radius. So is this actually a QML bug because of the fact that rectangle radius gets discarded when its width is smaller than its specified radius?
The only way I can get the bars to show anything meaningful without looking inconsistent is if I tweak the QML to make their radius zero.
STEPS TO REPRODUCE
1. Create a system monitor widget with horizontal bars style
2. Select sensors that you can reasonably expect to be low to zero, like total CPU usage percent and Swap usage percent.
Values of zero are not meaningfully conveyed; they look more like 10% on a 40px vertical panel.
A legitimately empty bar is shown when the value is zero, and some sort of small fill is shown for low values.
Linux/KDE Plasma: KDE Neon 5.24.4
(available in About System)
KDE Plasma Version: 5.24.5
KDE Frameworks Version: 5.93
Qt Version: 5.15.3
I did manage to come up with something. By centering the second rectangle vertically within the parent and then making the height the minimum between parent.height and width x percentage, it at least looks better than no radius and/or letting it just square off the corners when the value is zero. I'll attach my patch and a screenshot of what it looks like now with low values. If this rectangle radius thing is something that can't be fixed in QML, I at least think this will make the horizontal bars more usable and meaningful.
Created attachment 148140 [details]
Screenshot of horizontal bars after patch, using smaller circles for low values.
Created attachment 148141 [details]
Patch to Bar.qml to allow for using smaller circles than the parent's height for low values.
Created attachment 148142 [details]
Patch to Bar.qml to allow for using smaller circles than the parent's height for low values. (Corrected.)
Looks like a legitimate issue, and your change seems sane to me. Would you be interested in submitting a merge request with it? I can help!
(In reply to Nate Graham from comment #5)
> Looks like a legitimate issue, and your change seems sane to me. Would you
> be interested in submitting a merge request with it? I can help!
Definitely! And I would very much appreciate the help.
The only thing I think I would want to change about my patch as it is now is that I might want to round up the rectangle height for the lowe values somehow such that it's always centered within the bar. So if the bar is 7px high, it will never have a 4px high rectangle that it can't actually center, or if the bar is 8px high, it will never have a 5px rectangle that it can't actually center. I'm sure there's some math to do this, but I haven't thought it up yet, haha.
I don't think the bar can have an odd-numbered height... or if it can, that's a bug we should fix in our qqc2-desktop-style. So I don't think it's something you need to worry about per se.
That said, it's good practice to use Math.round() whenever you divide size numbers in UI code, just to avoid having the toolkit trying to draw on fractional pixels.
I'm not sure if the bar can or can't have an odd-numbered height, but in my earlier implementation, the inner bar *could* have an odd-numbered height, which would result in more space on bottom than on top. I figured out a way to bump the height up to the nearest number that leaves equal space on top and bottom. This does lose precision, but it looks better. I'll attach my patch here anyways, but I think I found where the faces are upstream, so I'm going to get an MR ready. :)
Created attachment 148302 [details]
Patch to Bar.qml to use smaller circles than the parent's height for low values, now clamping to values that fit evenly within parent.
Fixed by Trent McPheron with https://invent.kde.org/plasma/libksysguard/-/commit/3d6acfc69c96a26d8274d426c4178fb6f449bdce in Plasma 5.25!