0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-01-11 17:18:10 +03:00

Fix drawing vertical lines in grid chart

This commit is contained in:
Emil Sawicki 2022-01-29 08:57:50 +01:00
parent 2452e37334
commit 25dff69679
2 changed files with 21 additions and 11 deletions

View File

@ -21,14 +21,21 @@ void GridLinesChart::paintChart(QPainter *painter, QRectF chartRect)
) )
); );
const qreal barsShift = calcRect.height(); const qreal barsShift = calcRect.height();
const qreal topOffset = painter->fontMetrics().height() * (m_chartItem->horizontalAxisOnTop() ? 1 : -1); const qreal topOffset = painter->fontMetrics().height();
const QRectF gridRect = chartRect.adjusted( QRectF gridRect = chartRect.adjusted(
hPadding, hPadding,
vPadding + valuesVMargin + topOffset, vPadding + valuesVMargin + topOffset,
-hPadding * 3, -hPadding * 3,
-(vPadding + barsShift) -(vPadding + barsShift)
); );
if (!m_chartItem->horizontalAxisOnTop()) {
// Draw labels above the grid
const qreal height = calcRect.height();
calcRect.setBottom(gridRect.top());
calcRect.setTop(calcRect.bottom() - height);
}
paintGrid(painter, gridRect); paintGrid(painter, gridRect);
paintSerialLines( paintSerialLines(

View File

@ -838,12 +838,15 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect)
const int yAxisSegmentCount = yAxisData.segmentCount(); const int yAxisSegmentCount = yAxisData.segmentCount();
const int yAxisLineCount = yAxisSegmentCount + 1; const int yAxisLineCount = yAxisSegmentCount + 1;
const qreal gridOffset = hPadding(gridRect);
const int fontHeight = painter->fontMetrics().height(); const int fontHeight = painter->fontMetrics().height();
const int halfFontHeight = fontHeight / 2; const int halfFontHeight = fontHeight / 2;
const QSizeF gridOffset = QSizeF(hPadding(gridRect), vPadding(gridRect));
const qreal valuesHMargin = this->valuesHMargin(painter); const qreal valuesHMargin = this->valuesHMargin(painter);
const qreal vStep = gridRect.height() / yAxisSegmentCount; const qreal vStep = gridRect.height() / yAxisSegmentCount;
const qreal hStep = (gridRect.width() - valuesHMargin - gridOffset) / xAxisSegmentCount; const qreal hStep = (gridRect.width() - valuesHMargin - gridOffset.width()) / xAxisSegmentCount;
const qreal textPositionHOffset = valuesHMargin * 0.2;
// TODO_ES horizontal axis labels doesn't adapt font
painter->setFont(adaptValuesFont(hStep-4, painter->font())); painter->setFont(adaptValuesFont(hStep-4, painter->font()));
@ -853,37 +856,37 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect)
const qreal y = vStep * i; const qreal y = vStep * i;
const bool drawFullLine = m_chartItem->gridChartLines() & ChartItem::HorizontalLine const bool drawFullLine = m_chartItem->gridChartLines() & ChartItem::HorizontalLine
|| i == 0 || i == xAxisSegmentCount; || i == 0 || i == xAxisSegmentCount;
painter->drawText(QRectF(gridRect.bottomLeft()-QPointF(halfFontHeight, y + halfFontHeight), painter->drawText(QRectF(gridRect.bottomLeft()-QPointF(textPositionHOffset, y + halfFontHeight),
QSizeF(valuesHMargin,fontHeight)), QSizeF(valuesHMargin,fontHeight)),
axisLabel(i, yAxisData), axisLabel(i, yAxisData),
verticalTextOption); verticalTextOption);
QPointF lineEndPos = gridRect.bottomRight() - QPointF(0, y); QPointF lineEndPos = gridRect.bottomRight() - QPointF(0, y);
if (!drawFullLine) { if (!drawFullLine) {
lineEndPos.setX(gridRect.left() + valuesHMargin + gridOffset); lineEndPos.setX(gridRect.left() + valuesHMargin + gridOffset.width());
} }
painter->drawLine(gridRect.bottomLeft() - QPointF(-valuesHMargin, y), lineEndPos); painter->drawLine(gridRect.bottomLeft() - QPointF(-valuesHMargin, y), lineEndPos);
} }
// Horizontal axis lines // Horizontal axis lines
for (int i = 0 ; i < xAxisLineCount ; i++) { for (int i = 0 ; i < xAxisLineCount ; i++) {
const qreal x = gridRect.left() + hStep * i + valuesHMargin + gridOffset; const qreal x = gridRect.left() + hStep * i + valuesHMargin + gridOffset.width();
const bool drawFullLine = m_chartItem->gridChartLines() & ChartItem::VerticalLine const bool drawFullLine = m_chartItem->gridChartLines() & ChartItem::VerticalLine
|| i == 0 || i == xAxisSegmentCount; || i == 0 || i == xAxisSegmentCount;
const QString text = axisLabel(i, xAxisData); const QString text = axisLabel(i, xAxisData);
if (m_chartItem->horizontalAxisOnTop()) { if (m_chartItem->horizontalAxisOnTop()) {
painter->drawLine(x, gridRect.top() - gridOffset, painter->drawLine(x, gridRect.top() - gridOffset.height(),
x, (drawFullLine ? gridRect.bottom() : gridRect.top())); x, (drawFullLine ? gridRect.bottom() : gridRect.top()));
painter->drawText(QRectF(x - painter->fontMetrics().width(text) / 2, painter->drawText(QRectF(x - painter->fontMetrics().width(text) / 2,
gridRect.top() - (fontHeight + gridOffset), gridRect.top() - (fontHeight + gridOffset.height()),
hStep, fontHeight), hStep, fontHeight),
text); text);
} else { } else {
painter->drawLine(x, gridRect.bottom() + gridOffset, painter->drawLine(x, gridRect.bottom() + gridOffset.height(),
x, (drawFullLine ? gridRect.top() : gridRect.bottom())); x, (drawFullLine ? gridRect.top() : gridRect.bottom()));
painter->drawText(QRectF(x - painter->fontMetrics().width(text) / 2, painter->drawText(QRectF(x - painter->fontMetrics().width(text) / 2,
gridRect.bottom() + halfFontHeight + gridOffset, gridRect.bottom() + halfFontHeight * 0 + gridOffset.height(),
hStep, fontHeight), hStep, fontHeight),
text); text);
} }