From ac7068d4fd3722153bdfbfdfe942dc61d2d29619 2013-06-12 09:47:43 From: Miikka Heikkinen Date: 2013-06-12 09:47:43 Subject: [PATCH] Fix checking for labels out of axis grid. Change-Id: Ib55312f9e7cb58e6d1f47912d54f3bf56b8871cc Reviewed-by: Tomi Korpipää --- diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index a185d4a..f093810 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -122,6 +122,7 @@ void HorizontalAxis::updateGeometry() QPointF center = rect.center(); labelItem->setTransformOriginPoint(center.x(), center.y()); qreal heightDiff = rect.height() - boundingRect.height(); + qreal widthDiff = rect.width() - boundingRect.width(); //ticks and label position if (axis()->alignment() == Qt::AlignTop) { @@ -146,11 +147,10 @@ void HorizontalAxis::updateGeometry() labelItem->setPos(leftBound + (delta / 2.0) - center.x(), labelItem->pos().y()); } } - //label overlap detection - compensate one pixel for rounding errors if (labelItem->pos().x() < width || forceHide || - labelItem->pos().x() < (axisRect.left() - 1.0) || - (labelItem->pos().x() + boundingRect.width() - 1.0) > axisRect.right()){ + (labelItem->pos().x() + (widthDiff / 2.0)) < (axisRect.left() - 1.0) || + (labelItem->pos().x() + (widthDiff / 2.0) - 1.0) > axisRect.right()){ labelItem->setVisible(false); } else { labelItem->setVisible(true); diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 084a0bb..2573994 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -126,6 +126,7 @@ void VerticalAxis::updateGeometry() QPointF center = rect.center(); labelItem->setTransformOriginPoint(center.x(), center.y()); qreal widthDiff = rect.width() - boundingRect.width(); + qreal heightDiff = rect.height() - boundingRect.height(); //ticks and label position if (axis()->alignment() == Qt::AlignLeft) { @@ -153,8 +154,8 @@ void VerticalAxis::updateGeometry() //label overlap detection - compensate one pixel for rounding errors if (labelItem->pos().y() + boundingRect.height() > height || forceHide || - (labelItem->pos().y() + (boundingRect.height() / 2.0) - 1.0) > axisRect.bottom() || - labelItem->pos().y() + (boundingRect.height() / 2.0) < (axisRect.top() - 1.0)) { + (labelItem->pos().y() + (heightDiff / 2.0) - 1.0) > axisRect.bottom() || + labelItem->pos().y() + (heightDiff / 2.0) < (axisRect.top() - 1.0)) { labelItem->setVisible(false); } else {