##// END OF EJS Templates
Fixes categories wrong labeling issue for *barseries
Michal Klocek -
r1706:368f6161c675
parent child
Show More
@@ -41,14 +41,14 ChartCategoriesAxisX::~ChartCategoriesAxisX()
41 41
42 42 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
43 43 {
44 Q_ASSERT(m_categoriesAxis->categories().count()>=2);
44 Q_ASSERT(m_categoriesAxis->categories().count()>=1);
45 45
46 46 QVector<qreal> points;
47 points.resize(m_categoriesAxis->categories().count());
47 points.resize(m_categoriesAxis->categories().count()+1);
48 48
49 49 // TODO: shift logic
50 const qreal deltaX = m_rect.width()/(m_categoriesAxis->categories().count()-1);
51 for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) {
50 const qreal deltaX = m_rect.width()/(m_categoriesAxis->categories().count());
51 for (int i = 0; i < m_categoriesAxis->categories().count()+1; ++i) {
52 52 int x = i * deltaX + m_rect.left();
53 53 points[i] = x;
54 54 }
@@ -73,8 +73,8 void ChartCategoriesAxisX::updateGeometry()
73 73 QList<QGraphicsItem *> shades = m_shades->childItems();
74 74 QList<QGraphicsItem *> axis = m_axis->childItems();
75 75
76 Q_ASSERT(labels.size() == ticksList.size());
77 Q_ASSERT(layout.size() == ticksList.size());
76 Q_ASSERT(labels.size()-1 == ticksList.size());
77 Q_ASSERT(layout.size()-1 == ticksList.size());
78 78
79 79 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
80 80 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
@@ -41,13 +41,13 ChartCategoriesAxisY::~ChartCategoriesAxisY()
41 41
42 42 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
43 43 {
44 Q_ASSERT(m_categoriesAxis->categories().count()>=2);
44 Q_ASSERT(m_categoriesAxis->categories().count()>=1);
45 45
46 46 QVector<qreal> points;
47 points.resize(m_categoriesAxis->categories().count());
47 points.resize(m_categoriesAxis->categories().count()+1);
48 48
49 const qreal deltaY = m_rect.height()/(m_categoriesAxis->categories().count()-1);
50 for (int i = 0; i < m_categoriesAxis->categories().count(); ++i) {
49 const qreal deltaY = m_rect.height()/(m_categoriesAxis->categories().count());
50 for (int i = 0; i < m_categoriesAxis->categories().count()+1; ++i) {
51 51 int y = i * -deltaY + m_rect.bottom();
52 52 points[i] = y;
53 53 }
@@ -73,8 +73,8 void ChartCategoriesAxisY::updateGeometry()
73 73 QList<QGraphicsItem *> shades = m_shades->childItems();
74 74 QList<QGraphicsItem *> axis = m_axis->childItems();
75 75
76 Q_ASSERT(labels.size() == ticksList.size());
77 Q_ASSERT(layout.size() == ticksList.size());
76 Q_ASSERT(labels.size()-1 == ticksList.size());
77 Q_ASSERT(layout.size()-1 == ticksList.size());
78 78
79 79 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
80 80 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
@@ -342,7 +342,7 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &ma
342 342 qreal QBarCategoriesAxisPrivate::min()
343 343 {
344 344 //TODO:: cache it
345 return m_categories.indexOf(m_minCategory) + 0.5;
345 return m_categories.indexOf(m_minCategory) - 0.5;
346 346 }
347 347
348 348 qreal QBarCategoriesAxisPrivate::max()
@@ -706,9 +706,11 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
706 706 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
707 707 Q_ASSERT(cataxis);
708 708 QStringList categories;
709 if(cataxis->categories().isEmpty()){
709 710 for (int i(1); i < categoryCount()+1; i++)
710 711 categories << QString::number(i);
711 712 cataxis->append(categories);
713 }
712 714 }
713 715 }
714 716
@@ -68,9 +68,11 void QHorizontalBarSeriesPrivate::initializeAxis(QAbstractAxis* axis)
68 68 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
69 69 Q_ASSERT(cataxis);
70 70 QStringList categories;
71 if(cataxis->categories().isEmpty()){
71 72 for (int i(1); i < categoryCount()+1; i++)
72 73 categories << QString::number(i);
73 74 cataxis->append(categories);
75 }
74 76 }
75 77 }
76 78
@@ -56,16 +56,6 Chart* QHorizontalPercentBarSeriesPrivate::createGraphics(ChartPresenter* presen
56 56 return bar;
57 57 }
58 58
59 QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisXType() const
60 {
61 return QAbstractAxis::AxisTypeValues;
62 }
63
64 QAbstractAxis::AxisType QHorizontalPercentBarSeriesPrivate::defaultAxisYType() const
65 {
66 return QAbstractAxis::AxisTypeCategories;
67 }
68
69 59
70 60 #include "moc_qhorizontalpercentbarseries.cpp"
71 61
@@ -41,8 +41,6 public:
41 41 QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries* q);
42 42 Chart* createGraphics(ChartPresenter* presenter);
43 43 void scaleDomain(Domain& domain);
44 QAbstractAxis::AxisType defaultAxisXType() const;
45 QAbstractAxis::AxisType defaultAxisYType() const;
46 44
47 45 private:
48 46 Q_DECLARE_PUBLIC(QHorizontalPercentBarSeries)
@@ -380,7 +380,6 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Ori
380 380
381 381 if(orientation==Qt::Vertical) {
382 382 seriesAxisMap= &m_seriesAxisYMap;
383
384 383 }else{
385 384 seriesAxisMap= &m_seriesAxisXMap;
386 385 }
General Comments 0
You need to be logged in to leave comments. Login now