Bug 435268

Summary: Ends of graph have weird lumps
Product: [Frameworks and Libraries] frameworks-kquickcharts Reporter: Alex <alex765>
Component: generalAssignee: Arjen Hiemstra <ahiemstra>
Status: RESOLVED FIXED    
Severity: minor CC: ahiemstra, kde, kde, kdelibs-bugs, kitt997, nate, plasma-bugs
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Fedora RPMs   
OS: Linux   
Latest Commit: Version Fixed In: 5.83
Attachments: Screenshot of systemmonitor history tab

Description Alex 2021-04-02 14:14:54 UTC
Created attachment 137274 [details]
Screenshot of systemmonitor history tab

Its especially noticeable on the end of the Memory graph, see the attached screenshot.

This is on the Wayland session, Qt 5.15.2.
Comment 1 Nate Graham 2021-04-06 03:39:54 UTC
Can confirm the weird lumps on X11 too.
Comment 2 David Redondo 2021-04-06 08:07:47 UTC
Afaik that's an artifact of the line smoothing algorithm
Comment 3 Arjen Hiemstra 2021-04-06 10:37:06 UTC
Yes it is. The same happens in for example libreoffice calc when using a smoothed line chart with the values [0, 0, 1000, 1000, 1000] or Google Charts: https://jsfiddle.net/dswy5vmh/ . Generally smoothing algorithms are a case of choosing which tradeoffs to accept, I decided that it'd be better to follow what other charts do rather than doing something special.
Comment 4 Nate Graham 2021-04-06 16:28:08 UTC
Is there any way to tweak the smoothing algorithm so we still get nicely smoothed graphs, without the tiny lumps?
Comment 5 David Redondo 2021-05-20 07:57:50 UTC
*** Bug 437309 has been marked as a duplicate of this bug. ***
Comment 6 David Edmundson 2021-05-22 12:15:42 UTC
There is an algorithm called "Monotone cubic interpolation" that looks encouraging.

https://en.wikipedia.org/wiki/Monotone_cubic_interpolation
Comment 7 David 2021-05-24 16:48:41 UTC
I hate asking trivial questions, but did you have a look at ksysguards's implementation? because graphs were fine there.

Also, I don't know well enough the actual implementation of systemmonitor's graphs, but does it make sense to polynomially interpolate a non-functional data set in the first place? It's not like, say, sin(x) what we're trying to draw. Points are function of time, but of no known/meaningful model.
We're not interested in reconstructing the function behind some points in a data set, we only want to draw a smooth graph. This looks to my innocent eyes more like a linear interpolation of the data set, plus some graphical smoothing of the resulting curve afterwards.
Comment 8 Nate Graham 2021-05-25 17:59:40 UTC
FWIW ksysguard's older implementation is not relevant because it uses an older custom graph rather than the fancy new GPU-accelerated graphing framework we use for lots of things. Unifying on a single implementation that can take advantage of hardware acceleration on modern computers to use fewer CPU resources.

One advantage of the new system is that once this bug is fixed in one place, it will be fixed for all clients that use it (e.g. System Monitor app, System Monitor widgets, Network applet's speed graph, and so on.)
Comment 9 David 2021-05-25 21:49:58 UTC
(In reply to Nate Graham from comment #8)
> FWIW ksysguard's older implementation is not relevant because it uses an
> older custom graph rather than the fancy new GPU-accelerated graphing
> framework we use for lots of things. Unifying on a single implementation
> that can take advantage of hardware acceleration on modern computers to use
> fewer CPU resources.
> 
> One advantage of the new system is that once this bug is fixed in one place,
> it will be fixed for all clients that use it (e.g. System Monitor app,
> System Monitor widgets, Network applet's speed graph, and so on.)

ah right, understand
Comment 10 Arjen Hiemstra 2021-06-03 14:00:28 UTC
Git commit c91c837fbab2e966165c47f4fbbe96e16eb3f073 by Arjen Hiemstra.
Committed on 03/06/2021 at 11:42.
Pushed by ahiemstra into branch 'master'.

Implement monotonic cubic interpolation for line charts

Replace the existing cubic interpolation in the line chart with cubic
monotonic interpolation, which tries harder to preserve monotonicity and
that way avoids over or under shooting the target point. As a bonus, the
implementation turns out simpler than the cubic implementation we
currently have, which should improve performance.

M  +114  -92   src/LineChart.cpp

https://invent.kde.org/frameworks/kquickcharts/commit/c91c837fbab2e966165c47f4fbbe96e16eb3f073