summaryrefslogtreecommitdiffstats
path: root/src/charts/axis/cartesianchartaxis.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/charts/axis/cartesianchartaxis.cpp')
-rw-r--r--src/charts/axis/cartesianchartaxis.cpp27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/charts/axis/cartesianchartaxis.cpp b/src/charts/axis/cartesianchartaxis.cpp
index 935a9601..6389c17e 100644
--- a/src/charts/axis/cartesianchartaxis.cpp
+++ b/src/charts/axis/cartesianchartaxis.cpp
@@ -130,15 +130,16 @@ void CartesianChartAxis::updateMinorTickItems()
expectedCount = qMax(expectedCount, 0);
} else {
const qreal interval = valueAxis->tickInterval();
- qreal firstMajorTick = valueAxis->tickAnchor();
+ const qreal anchor = valueAxis->tickAnchor();
const qreal max = valueAxis->max();
const qreal min = valueAxis->min();
const int _minorTickCount = valueAxis->minorTickCount();
- if (min < firstMajorTick)
- firstMajorTick = firstMajorTick - qCeil((firstMajorTick - min) / interval) * interval;
- else
- firstMajorTick = firstMajorTick + int((min - firstMajorTick) / interval) * interval;
+ // Find the closest major tick <= the min of the range, even if it's not drawn!
+ // This is where we'll start counting minor ticks from, because minor ticks
+ // might need to be drawn even before the first major tick.
+ const qreal ticksFromAnchor = (anchor - min) / interval;
+ const qreal firstMajorTick = anchor - std::ceil(ticksFromAnchor) * interval;
const qreal deltaMinor = interval / qreal(_minorTickCount + 1);
qreal minorTick = firstMajorTick + deltaMinor;
@@ -265,7 +266,7 @@ bool CartesianChartAxis::isEmpty()
{
return axisGeometry().isEmpty()
|| gridGeometry().isEmpty()
- || qFuzzyCompare(min(), max());
+ || qFuzzyIsNull(max() - min());
}
void CartesianChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
@@ -371,16 +372,16 @@ void CartesianChartAxis::updateLabelsValues(QValueAxis *axis)
static_cast<ValueAxisLabel *>(labelItems().at(i))->setValue(value);
}
} else {
- qreal value = axis->tickAnchor();
- if (value > min())
- value = value - int((value - min()) / axis->tickInterval()) * axis->tickInterval();
- else
- value = value + qCeil((min() - value) / axis->tickInterval()) * axis->tickInterval();
+ const qreal anchor = axis->tickAnchor();
+ const qreal interval = axis->tickInterval();
+ const qreal ticksFromAnchor = (anchor - min()) / interval;
+ const qreal firstMajorTick = anchor - std::floor(ticksFromAnchor) * interval;
int i = axis->isReverse() ? labelItems().count()-1 : 0;
- while (value <= max() || qFuzzyCompare(value, max())) {
+ qreal value = firstMajorTick;
+ while (value <= max()) {
static_cast<ValueAxisLabel *>(labelItems().at(i))->setValue(value);
- value += axis->tickInterval();
+ value += interval;
i += axis->isReverse() ? -1 : 1;
}
}