diff --git a/limereport/items/charts/lrgridlineschart.cpp b/limereport/items/charts/lrgridlineschart.cpp index 6ce6411..5c2f3bc 100644 --- a/limereport/items/charts/lrgridlineschart.cpp +++ b/limereport/items/charts/lrgridlineschart.cpp @@ -9,15 +9,19 @@ void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect) const qreal vPadding = this->vPadding(chartRect); const qreal valuesVMargin = this->valuesVMargin(painter); - const qreal topOffset = painter->fontMetrics().height(); QRectF gridRect = chartRect.adjusted( hPadding, - vPadding + valuesVMargin + topOffset, + vPadding + valuesVMargin * 2, -hPadding * 3, - -vPadding + -vPadding * 3 ); + if (!m_chartItem->horizontalAxisOnTop()) { + // If horizontal axis is on the bottom, move grid a little up + gridRect.adjust(0, -valuesVMargin, 0 , -valuesVMargin); + } + // Adapt font for horizontal axis painter->setFont(adaptFont((gridRect.width() - this->valuesHMargin(painter)) / xAxisData().segmentCount() * 0.8, painter->font(), @@ -25,23 +29,8 @@ void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect) const qreal valuesHMargin = this->valuesHMargin(painter); - QRectF calcRect = horizontalLabelsRect( - painter, - chartRect.adjusted( - hPadding * 2 + valuesHMargin, - chartRect.height() - (painter->fontMetrics().height() + vPadding*2), - -(hPadding * 2), - -vPadding - ) - ); - gridRect.adjust(0, 0, 0, -calcRect.height()); - - if (!m_chartItem->horizontalAxisOnTop()) { - // Draw labels above the grid - const qreal height = calcRect.height(); - calcRect.setBottom(gridRect.top()); - calcRect.setTop(calcRect.bottom() - height); - } + // Adjust vertical axis labels padding + gridRect.adjust(valuesHMargin * 0.2, 0, 0, 0); paintGrid(painter, gridRect); @@ -49,7 +38,6 @@ void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect) painter, gridRect.adjusted(hPadding + valuesHMargin, 0, 0, 0) ); - paintHorizontalLabels(painter, calcRect); } void GridLinesChart::paintSerialLines(QPainter* painter, QRectF barsRect) diff --git a/limereport/items/lrchartitem.cpp b/limereport/items/lrchartitem.cpp index 401b92f..565b3cf 100644 --- a/limereport/items/lrchartitem.cpp +++ b/limereport/items/lrchartitem.cpp @@ -844,7 +844,7 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect) const qreal valuesHMargin = this->valuesHMargin(painter); const qreal vStep = gridRect.height() / yAxisSegmentCount; const qreal hStep = (gridRect.width() - valuesHMargin - gridOffset.width()) / xAxisSegmentCount; - const qreal textPositionHOffset = valuesHMargin * 0.2; + const qreal textPositionHOffset = valuesHMargin * 0.1; // Vertical axis lines const QTextOption verticalTextOption(Qt::AlignRight);