Fix vertical axis labels padding

This commit is contained in:
Emil Sawicki 2022-01-30 17:46:04 +01:00
parent 74c0f52369
commit df0e4d8393
2 changed files with 10 additions and 22 deletions

View File

@ -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)

View File

@ -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);