Fix ordinate axis labels when zooming

Authored by rszczesiak on May 2 2020, 4:57 AM.

Description

Fix ordinate axis labels when zooming

Summary:
If I understand the intent of the author correctly, the sole purpose of
KReportChartView::slotNeedUpdate() was one-time customization of
ordinate axis labels at the time of chart creation. The fact that signal
is disconnected immediately after execution of slot starts seems to
confirm my understanding.

The problem begins when one zooms the chart (using so-called rubber band
zooming feature from KDiagram project). Axis ticks and labels are
recalculated but still they are overridden with "hard labels" defined in
the slot body. The number of axis ticks increases and is grater than the
number of hard labels, so the labels are repeated in cycle. In and of
itself it is really a feature rather than a bug but the feature works to
our disadvantage in this case.
Please find below a quote from AbstractAxis Class documentation:

void AbstractAxis::setLabels( const QStringList & list )
Use this to specify your own set of strings, to be used as axis

labels.

Labels specified via setLabels take precedence: If a non-empty list is

passed, KD Chart will use these strings as axis labels, instead of
calculating them.

**If you pass a smaller number of strings than the number of labels

drawn at this axis, KD Chart will repeat the strings until all labels
are drawn**. As an example you could specify the seven days of the week
as abscissa labels, which would be repeatedly used then.

Unfortunately, mere removal of disconnect method call does not solve the
problem but the same documentation provides a way to customize axis
labels when needed. It is done through overriding of `const QString
AbstractAxis::customizedLabel( const QString & label ) const`

My solution proposed in attached patch goes this way and also simplifies
calculations where they seemed over-complicated to me. Please correct my
understanding if i missed the point of removed lines.

Please find attached screenshots before and after the fix.
Balance history chart before fix with no zoom:


Balance history chart before fix with zoom::

Balance history chart after fix with no zoom:

Balance history chart after fix with zoom::

As a footnote, I would like to sincerely thank to all the people who
have contributed to this project. I started to use KMyMoney recently and
I am surprised how good it is, especially for an open-source project run
by the community. It suits my need for personal finance and
investment-supporting software amazingly well. If you find my
contribution valuable, I would love to provide more patches in the
future if I find more bugs or feel that some feature is missing. In
fact, I have little to no industrial experience in C++ as I work mostly
in Java. Please let me know if I broke any C++ coding rules.

BUG: 420767

Reviewers: KMyMoney, tbaumgart

Reviewed By: KMyMoney, tbaumgart

Subscribers: tbaumgart

Tags: KMyMoney, KDiagram

Differential Revision: https://phabricator.kde.org/D29255

Details

Committed
tbaumgartMay 2 2020, 5:11 AM
Reviewer
KMyMoney
Differential Revision
D29255: Fix ordinate axis labels when zooming
Parents
R261:c8eda97b6152: SVN_SILENT made messages (.desktop file) - always resolve ours
Branches
Unknown
Tags
Unknown