diff --git a/src/axis/horizontalaxis.cpp b/src/axis/horizontalaxis.cpp index 5d2bfbd..95b786d 100644 --- a/src/axis/horizontalaxis.cpp +++ b/src/axis/horizontalaxis.cpp @@ -136,14 +136,23 @@ void HorizontalAxis::updateGeometry() tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding()); } - //label in beetwen - if(intervalAxis()&& i+1!=layout.size()) { - const qreal delta = (layout[i+1] - layout[i])/2; - labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y()); + //label in between + bool forceHide = false; + if (intervalAxis() && (i + 1) != layout.size()) { + qreal leftBound = qMax(layout[i], gridRect.left()); + qreal rightBound = qMin(layout[i + 1], gridRect.right()); + const qreal delta = rightBound - leftBound; + // Hide label in case visible part of the category at the grid edge is too narrow + if (delta < boundingRect.width() + && (leftBound == gridRect.left() || rightBound == gridRect.right())) { + forceHide = true; + } else { + 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 || + if (labelItem->pos().x() < width || forceHide || labelItem->pos().x() < (axisRect.left() - 1.0) || (labelItem->pos().x() + boundingRect.width() - 1.0) > axisRect.right()){ labelItem->setVisible(false); diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 9c9d462..38a6107 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -146,14 +146,23 @@ void VerticalAxis::updateGeometry() tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]); } - //label in beetwen - if(intervalAxis()&& i+1!=layout.size()) { - const qreal delta = (layout[i+1] - layout[i])/2; - labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y()); + //label in between + bool forceHide = false; + if (intervalAxis() && (i + 1) != layout.size()) { + qreal lowerBound = qMin(layout[i], gridRect.bottom()); + qreal upperBound = qMax(layout[i + 1], gridRect.top()); + const qreal delta = lowerBound - upperBound; + // Hide label in case visible part of the category at the grid edge is too narrow + if (delta < boundingRect.height() + && (lowerBound == gridRect.bottom() || upperBound == gridRect.top())) { + forceHide = true; + } else { + labelItem->setPos(labelItem->pos().x() , lowerBound - (delta / 2.0) - center.y()); + } } //label overlap detection - compensate one pixel for rounding errors - if (labelItem->pos().y() + boundingRect.height() > height || + 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->setVisible(false);