diff options
author | Dimitrios Apostolou <jimis@qt.io> | 2021-05-10 16:20:41 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-05-12 16:19:47 +0000 |
commit | 230ac625403d52107c1b8050dbf6978bdd72790e (patch) | |
tree | cb3fa3e978d9b131d4b93cef7705ccbb448f4181 /src/charts/axis/chartaxiselement.cpp | |
parent | d3b5b6c24ae47eaa19d426ff428b8e0f58d4678c (diff) |
Add comments and clarify some code
Change-Id: Ib0280e18d8e788631ae3c11674398c2725cbafa6
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
(cherry picked from commit b1e5084099c28c0b937f4f9ab070d6d5556cf54d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/charts/axis/chartaxiselement.cpp')
-rw-r--r-- | src/charts/axis/chartaxiselement.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/charts/axis/chartaxiselement.cpp b/src/charts/axis/chartaxiselement.cpp index 9ca59b08..17f36e61 100644 --- a/src/charts/axis/chartaxiselement.cpp +++ b/src/charts/axis/chartaxiselement.cpp @@ -419,7 +419,11 @@ QStringList ChartAxisElement::createValueLabels(qreal min, qreal max, int ticks, return labels; if (format.isEmpty()) { - int n = qMax(int(-qFloor(std::log10((max - min) / (ticks - 1)))), 0) + 1; + // Calculate how many decimal digits are needed to show difference between ticks, + // for example tick marks 1.002 and 1.003 have a difference of 0.001 and need 3 decimals. + // For differences >= 1 (positive log10) use always 1 decimal. + double l10 = std::log10((max - min) / (ticks - 1)); + int n = qMax(int(-qFloor(l10)), 0) + 1; if (tickType == QValueAxis::TicksFixed) { for (int i = 0; i < ticks; i++) { qreal value = min + (i * (max - min) / (ticks - 1)); |