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