##// END OF EJS Templates
fixing layout bug on stacked bar chart
sauimone -
r98:e7f551f0831b
parent child
Show More
@@ -67,7 +67,6 int StackedBarChartSeries::maxColumnSum()
67 max = sum;
67 max = sum;
68 }
68 }
69 }
69 }
70 qDebug() << "maxColumnSum" << max;
71 return max;
70 return max;
72 }
71 }
73
72
@@ -100,7 +99,6 int StackedBarChartSeries::columnSum(int column)
100 for (int row = 0; row < count; row++) {
99 for (int row = 0; row < count; row++) {
101 sum += mModel->data(mModel->index(row,column)).toInt();
100 sum += mModel->data(mModel->index(row,column)).toInt();
102 }
101 }
103 qDebug() << "sum for column" << column << "=" << sum;
104 return sum;
102 return sum;
105 }
103 }
106
104
@@ -107,25 +107,26 void StackedBarGroup::layoutChanged()
107 qreal scale = (h / maxSum);
107 qreal scale = (h / maxSum);
108
108
109 int count = mSeries.countColumns();
109 int count = mSeries.countColumns();
110 int posStepX = (mWidth / (count+1));
111
112 int itemIndex(0);
110 int itemIndex(0);
113 int xPos = (mWidth / (count+1)) - mSeries.countRows() * mBarDefaultWidth /2;
111 qreal tW = mWidth;
112 qreal tC = count+1;
113 qreal xStep = (tW/tC);
114 qreal xPos = ((tW/tC) + mBarDefaultWidth / 2);
115
114 for (int column = 0; column < mSeries.countColumns(); column++) {
116 for (int column = 0; column < mSeries.countColumns(); column++) {
115 int yPos = mHeight;
117 qreal yPos = h;
116 for (int row=0; row < mSeries.countRows(); row++) {
118 for (int row=0; row < mSeries.countRows(); row++) {
117 int barHeight = mSeries.valueAt(row, column) * scale;
119 qreal barHeight = mSeries.valueAt(row, column) * scale;
118 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
120 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
119
121
120 // TODO: width settable per bar?
122 // TODO: width settable per bar?
121 bar->resize(mBarDefaultWidth, barHeight);
123 bar->resize(mBarDefaultWidth, barHeight);
122 bar->setColor(mColors.at(row));
124 bar->setColor(mColors.at(row));
123 bar->setPos(xPos, yPos);
125 bar->setPos(xPos, yPos);
124 qDebug() << itemIndex << "pos" << xPos << yPos;
125 itemIndex++;
126 itemIndex++;
126 yPos -= barHeight;
127 yPos -= barHeight;
127 }
128 }
128 xPos += posStepX;
129 xPos += xStep;
129 }
130 }
130 mLayoutDirty = true;
131 mLayoutDirty = true;
131 }
132 }
General Comments 0
You need to be logged in to leave comments. Login now