mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 00:33:02 +03:00
Handle horizontal bars
This commit is contained in:
parent
5dac77083f
commit
d0830a7a37
@ -20,7 +20,9 @@ void HorizontalBarChart::paintChart(QPainter *painter, QRectF chartRect)
|
||||
paintHorizontalGrid(painter, chartRect.adjusted(
|
||||
hPadding(chartRect) + barsShift,
|
||||
vPadding(chartRect),
|
||||
-(hPadding(chartRect)),-vPadding(chartRect)));
|
||||
-(hPadding(chartRect)),
|
||||
-vPadding(chartRect)));
|
||||
|
||||
paintHorizontalBars(painter, chartRect.adjusted(
|
||||
hPadding(chartRect) + barsShift,
|
||||
vPadding(chartRect) * 2,
|
||||
@ -36,25 +38,33 @@ void HorizontalBarChart::paintHorizontalBars(QPainter *painter, QRectF barsRect)
|
||||
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||
|
||||
const AxisData &yAxisData = this->yAxisData();
|
||||
const qreal delta = yAxisData.delta();
|
||||
|
||||
qreal vStep = (barsRect.height()-painter->fontMetrics().height()) / valuesCount() / seriesCount();
|
||||
const qreal verticalOffset = painter->fontMetrics().height();
|
||||
qreal vStep = (barsRect.height() - verticalOffset) / valuesCount() / seriesCount();
|
||||
qreal hStep = (barsRect.width()-painter->fontMetrics().boundingRect(QString::number(maxValue())).width()) / delta;
|
||||
|
||||
if (!m_chartItem->series().isEmpty() && (m_chartItem->itemMode() != DesignMode)){
|
||||
int curSeries = 0;
|
||||
foreach (SeriesItem* series, m_chartItem->series()) {
|
||||
qreal curVOffset = curSeries*vStep+barsRect.top();
|
||||
painter->setBrush(series->color());
|
||||
foreach (qreal value, series->data()->values()) {
|
||||
painter->drawRect(QRectF((-minValue()*hStep)+barsRect.left(), curVOffset, value*hStep, vStep));
|
||||
curVOffset+=vStep*seriesCount();
|
||||
qreal curVOffset = barsRect.top();
|
||||
if (m_chartItem->horizontalAxisOnTop()) {
|
||||
curVOffset += verticalOffset;
|
||||
}
|
||||
curSeries++;
|
||||
foreach (SeriesItem* series, m_chartItem->series()) {
|
||||
painter->setBrush(series->color());
|
||||
qreal y = curVOffset;
|
||||
foreach (qreal value, series->data()->values()) {
|
||||
painter->drawRect(QRectF((-minValue()*hStep)+barsRect.left(), y, value*hStep, vStep));
|
||||
y+=vStep*seriesCount();
|
||||
}
|
||||
curVOffset += vStep;
|
||||
}
|
||||
} else {
|
||||
qreal curVOffset = barsRect.top();
|
||||
if (m_chartItem->horizontalAxisOnTop()) {
|
||||
curVOffset += verticalOffset;
|
||||
}
|
||||
int curColor = 0;
|
||||
for (int i=0; i<9; ++i){
|
||||
if (curColor==3) curColor=0;
|
||||
|
@ -633,7 +633,6 @@ void AbstractSeriesChart::updateMinAndMaxValues()
|
||||
|
||||
m_yAxisData = AxisData(minYValue, maxYValue);
|
||||
m_xAxisData = AxisData(minXValue, maxXValue);
|
||||
m_xAxisData.setReverseDirection(true);
|
||||
}
|
||||
|
||||
qreal AbstractSeriesChart::hPadding(QRectF chartRect)
|
||||
@ -761,13 +760,18 @@ void AbstractSeriesChart::paintHorizontalGrid(QPainter *painter, QRectF gridRect
|
||||
|
||||
painter->setFont(adaptValuesFont(hStep-4, painter->font()));
|
||||
|
||||
QPointF textPos;
|
||||
if (m_chartItem->horizontalAxisOnTop()) {
|
||||
textPos.setY(gridRect.top());
|
||||
} else {
|
||||
textPos.setY(gridRect.bottom() - painter->fontMetrics().height());
|
||||
}
|
||||
for (int i = 0 ; i < lineCount ; i++ ) {
|
||||
painter->drawText(QRectF(gridRect.left() + 4 + hStep * i, gridRect.bottom() - painter->fontMetrics().height(),
|
||||
hStep, painter->fontMetrics().height()),
|
||||
const qreal x = gridRect.left() + hStep * i;
|
||||
textPos.setX(x + 4);
|
||||
painter->drawText(QRectF(textPos, QSizeF(hStep, painter->fontMetrics().height())),
|
||||
axisLabel(i, yAxisData));
|
||||
painter->drawLine( gridRect.left()+hStep*i, gridRect.bottom(),
|
||||
gridRect.left()+hStep*i, gridRect.top());
|
||||
|
||||
painter->drawLine(x, gridRect.bottom(), x, gridRect.top());
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
@ -790,7 +794,6 @@ void AbstractSeriesChart::paintVerticalGrid(QPainter *painter, QRectF gridRect)
|
||||
const QTextOption verticalTextOption(Qt::AlignRight);
|
||||
for (int i = 0 ; i < lineCount ; i++ ) {
|
||||
const qreal y = vStep * i;
|
||||
// TODO_ES handle horizontalAxisOnTop
|
||||
painter->drawText(QRectF(gridRect.bottomLeft()-QPointF(textPositionOffset,y+halfFontHeight),
|
||||
QSizeF(valuesHMargin,fontHeight)),
|
||||
axisLabel(i, yAxisData),
|
||||
@ -823,6 +826,8 @@ void AbstractSeriesChart::paintGrid(QPainter *painter, QRectF gridRect)
|
||||
const qreal vStep = gridRect.height() / yAxisSegmentCount;
|
||||
const qreal hStep = (gridRect.width() - valuesHMargin - gridOffset) / xAxisSegmentCount;
|
||||
|
||||
painter->setFont(adaptValuesFont(hStep-4, painter->font()));
|
||||
|
||||
// Vertical axis lines
|
||||
const QTextOption verticalTextOption(Qt::AlignRight);
|
||||
for (int i = 0 ; i < yAxisLineCount ; i++ ) {
|
||||
|
Loading…
Reference in New Issue
Block a user