diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-04-28 07:57:32 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-05-18 07:54:37 +0000 |
commit | 985d9f42f7691a5b96f9d55b96c83e7f8debfee1 (patch) | |
tree | 989d1ddb9bd65d8a60186be11e60e44fbccf8fa8 /src | |
parent | df3f638f19c4a7bb506a23c72d7ff9a51681f78b (diff) |
Shift the label to be inside the bar if it is going to be cut off
Change-Id: I5616fa8a08da10f53a6aa43eb838ab44d63a4afb
Pick-to: 5.15
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
(cherry picked from commit 378968011f8a59769f6881358b4f316ebec6c866)
Diffstat (limited to 'src')
-rw-r--r-- | src/charts/barchart/abstractbarchartitem.cpp | 16 | ||||
-rw-r--r-- | src/charts/barchart/qabstractbarseries.cpp | 4 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/charts/barchart/abstractbarchartitem.cpp b/src/charts/barchart/abstractbarchartitem.cpp index 5cae977e..9695a60e 100644 --- a/src/charts/barchart/abstractbarchartitem.cpp +++ b/src/charts/barchart/abstractbarchartitem.cpp @@ -352,15 +352,17 @@ void AbstractBarChartItem::positionLabels() case QAbstractBarSeries::LabelsCenter: xPos = m_layout.at(bar->layoutIndex()).center().x() - center.x(); break; + case QAbstractBarSeries::LabelsOutsideEnd: + xPos = m_layout.at(bar->layoutIndex()).right() + offset + xDiff; + if (xPos + labelRect.width() - offset <= m_rect.right()) + break; + Q_FALLTHROUGH(); case QAbstractBarSeries::LabelsInsideEnd: xPos = m_layout.at(bar->layoutIndex()).right() - labelRect.width() - offset + xDiff; break; case QAbstractBarSeries::LabelsInsideBase: xPos = m_layout.at(bar->layoutIndex()).left() + offset + xDiff; break; - case QAbstractBarSeries::LabelsOutsideEnd: - xPos = m_layout.at(bar->layoutIndex()).right() + offset + xDiff; - break; default: // Invalid position, never comes here break; @@ -473,15 +475,17 @@ void AbstractBarChartItem::positionLabelsVertical() case QAbstractBarSeries::LabelsCenter: yPos = m_layout.at(bar->layoutIndex()).center().y() - center.y(); break; + case QAbstractBarSeries::LabelsOutsideEnd: + yPos = m_layout.at(bar->layoutIndex()).top() - labelRect.height() - offset + yDiff; + if (yPos + offset >= m_rect.y()) + break; + Q_FALLTHROUGH(); case QAbstractBarSeries::LabelsInsideEnd: yPos = m_layout.at(bar->layoutIndex()).top() + offset + yDiff; break; case QAbstractBarSeries::LabelsInsideBase: yPos = m_layout.at(bar->layoutIndex()).bottom() - labelRect.height() - offset + yDiff; break; - case QAbstractBarSeries::LabelsOutsideEnd: - yPos = m_layout.at(bar->layoutIndex()).top() - labelRect.height() - offset + yDiff; - break; default: // Invalid position, never comes here break; diff --git a/src/charts/barchart/qabstractbarseries.cpp b/src/charts/barchart/qabstractbarseries.cpp index 6427365c..7379e8e1 100644 --- a/src/charts/barchart/qabstractbarseries.cpp +++ b/src/charts/barchart/qabstractbarseries.cpp @@ -182,8 +182,8 @@ QT_CHARTS_BEGIN_NAMESPACE \endcode By default, the labels show the value of the bar. For the percent bar series, \e % is added - after the value. The labels are shown on the plot area, whereas labels on the edge of the plot - area are cut. If the bars are close to each other, the labels may overlap. + after the value. The labels are shown on the plot area, if the bars are close to each other, + the labels may overlap. \sa labelsVisible, labelsPosition, labelsPrecision */ |