diff --git a/limereport/items/charts/lrlineschart.cpp b/limereport/items/charts/lrlineschart.cpp index 5919ee7..01da6b0 100644 --- a/limereport/items/charts/lrlineschart.cpp +++ b/limereport/items/charts/lrlineschart.cpp @@ -81,8 +81,9 @@ qreal LinesChart::calculatePos(const AxisData &data, qreal value, qreal rectSize void LinesChart::paintSeries(QPainter *painter, SeriesItem *series, QRectF barsRect) { const AxisData &yAxisData = this->yAxisData(); + const AxisData &xAxisData = this->xAxisData(); - const qreal xAxisDiff = std::max(1.0, maxXValue() - minXValue()); + const qreal xAxisDiff = std::max(1.0, xAxisData.maxValue() - xAxisData.minValue()); const qreal hStep = barsRect.width() / xAxisDiff; const qreal topMargin = barsRect.top(); diff --git a/limereport/items/lrchartitem.cpp b/limereport/items/lrchartitem.cpp index 90db91b..0130c67 100644 --- a/limereport/items/lrchartitem.cpp +++ b/limereport/items/lrchartitem.cpp @@ -143,7 +143,7 @@ ChartItem::ChartItem(QObject *owner, QGraphicsItem *parent) m_legendAlign(LegendAlignCenter), m_titleAlign(TitleAlignCenter), m_chartType(Pie), m_labelsField(""), m_isEmpty(true), m_showLegend(true), m_drawPoints(true), m_seriesLineWidth(4), - m_horizontalAxisOnTop(false), m_legendStyle(LegendPoints) + m_horizontalAxisOnTop(false) { m_labels<<"First"<<"Second"<<"Thrid"; m_chart = new PieChart(this); @@ -589,11 +589,11 @@ qreal AbstractSeriesChart::minValue() AxisData AbstractSeriesChart::yAxisData() { return m_yAxisData; -qreal AbstractSeriesChart::minXValue() -{ - return m_chartItem->xAxisData()->minValue(); } +AxisData AbstractSeriesChart::xAxisData() +{ + return m_xAxisData; } void AbstractSeriesChart::updateMinAndMaxValues() @@ -612,11 +612,8 @@ void AbstractSeriesChart::updateMinAndMaxValues() maxYValue = std::max(maxYValue, value); } if (series->data()->xAxisValues().isEmpty()) { - // Grid plot starts from 0 on x axis so x range must be decresed by 1 - const bool startingFromZero = m_chartItem->chartType() == ChartItem::GridLines; - const qreal valuesCount = this->valuesCount() - (startingFromZero ? 1 : 0); minXValue = std::min(0.0, minXValue); - maxXValue = std::max(valuesCount, maxXValue); + maxXValue = std::max((qreal)valuesCount(), maxXValue); } else { for (qreal value : series->data()->xAxisValues()){ minXValue = std::min(value, minXValue); @@ -627,6 +624,8 @@ void AbstractSeriesChart::updateMinAndMaxValues() } m_yAxisData = AxisData(minYValue, maxYValue); + m_xAxisData = AxisData(minXValue, maxXValue); + m_xAxisData.setReverseDirection(true); } qreal AbstractSeriesChart::hPadding(QRectF chartRect) diff --git a/limereport/items/lrchartitem.h b/limereport/items/lrchartitem.h index c088dce..7a20767 100644 --- a/limereport/items/lrchartitem.h +++ b/limereport/items/lrchartitem.h @@ -89,10 +89,10 @@ class AbstractSeriesChart: public AbstractChart{ public: AbstractSeriesChart(ChartItem* chartItem); protected: + AxisData yAxisData(); + AxisData xAxisData(); qreal maxValue(); qreal minValue(); - qreal maxXValue(); - qreal minXValue(); void updateMinAndMaxValues(); int valuesCount(); int seriesCount(); @@ -113,7 +113,7 @@ protected: virtual QString verticalLabel(int i, qreal step, qreal min); private: - AxisData m_yAxisData; + AxisData m_yAxisData, m_xAxisData; qreal m_designValues [9]; }; diff --git a/limereport/lraxisdata.cpp b/limereport/lraxisdata.cpp index fbe7f2a..34ef9e9 100644 --- a/limereport/lraxisdata.cpp +++ b/limereport/lraxisdata.cpp @@ -53,6 +53,16 @@ qreal AxisData::delta() const return m_delta; } +bool AxisData::reverseDirection() const +{ + return m_reverseDirection; +} + +void AxisData::setReverseDirection(bool reverseDirection) +{ + m_reverseDirection = reverseDirection; +} + void AxisData::calculateValuesAboveMax(qreal minValue, qreal maxValue, int segments) { const int delta = maxValue - minValue; diff --git a/limereport/lraxisdata.h b/limereport/lraxisdata.h index 84a40c7..f69d72d 100644 --- a/limereport/lraxisdata.h +++ b/limereport/lraxisdata.h @@ -20,9 +20,12 @@ public: qreal step() const; qreal delta() const; + + bool reverseDirection() const; + void setReverseDirection(bool reverseDirection); + private: void calculateValuesAboveMax(qreal minValue, qreal maxValue, int segments); - qreal calculateNiceNum(qreal range, bool round); qreal m_rangeMin; qreal m_rangeMax; @@ -31,6 +34,7 @@ private: qreal m_step; qreal m_delta; int m_segmentCount; + bool m_reverseDirection; }; };