@@ -191,8 +191,11 QVector<QRectF> BarChartItem::calculateLayout() | |||||
191 | int categoryCount = mSeries->categoryCount(); |
|
191 | int categoryCount = mSeries->categoryCount(); | |
192 | int setCount = mSeries->barsetCount(); |
|
192 | int setCount = mSeries->barsetCount(); | |
193 |
|
193 | |||
194 | qreal tW = mWidth; |
|
194 | // qreal tW = mWidth; | |
195 | qreal tH = mHeight; |
|
195 | // qreal tH = mHeight; | |
|
196 | qreal width = geometry().width(); | |||
|
197 | qreal height = geometry().height(); | |||
|
198 | ||||
196 | qreal tM = mSeries->max(); |
|
199 | qreal tM = mSeries->max(); | |
197 |
|
200 | |||
198 | // Domain: |
|
201 | // Domain: | |
@@ -200,20 +203,20 QVector<QRectF> BarChartItem::calculateLayout() | |||||
200 | tM = mDomainMaxY; |
|
203 | tM = mDomainMaxY; | |
201 | } |
|
204 | } | |
202 |
|
205 | |||
203 |
qreal scale = (t |
|
206 | qreal scale = (height/tM); | |
204 | qreal tC = categoryCount + 1; |
|
207 | qreal tC = categoryCount + 1; | |
205 |
qreal categoryWidth = |
|
208 | qreal categoryWidth = width/tC; | |
206 |
|
|
209 | qreal barWidth = categoryWidth / (setCount+1); | |
207 |
|
210 | |||
208 | int itemIndex(0); |
|
211 | int itemIndex(0); | |
209 | for (int category=0; category < categoryCount; category++) { |
|
212 | for (int category=0; category < categoryCount; category++) { | |
210 |
qreal xPos = categoryWidth * category + categoryWidth /2 + |
|
213 | qreal xPos = categoryWidth * category + categoryWidth /2 + barWidth/2; | |
211 |
qreal yPos = |
|
214 | qreal yPos = height; | |
212 | for (int set = 0; set < setCount; set++) { |
|
215 | for (int set = 0; set < setCount; set++) { | |
213 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
216 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
214 | Bar* bar = mBars.at(itemIndex); |
|
217 | Bar* bar = mBars.at(itemIndex); | |
215 |
|
218 | |||
216 |
QRectF rect(xPos,yPos-barHeight, |
|
219 | QRectF rect(xPos,yPos-barHeight,barWidth,barHeight); | |
217 | //layout.insert(bar,rect); |
|
220 | //layout.insert(bar,rect); | |
218 | layout.append(rect); |
|
221 | layout.append(rect); | |
219 | // TODO: width settable per bar? |
|
222 | // TODO: width settable per bar? | |
@@ -223,15 +226,15 QVector<QRectF> BarChartItem::calculateLayout() | |||||
223 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
226 | bar->setBrush(mSeries->barsetAt(set)->brush()); | |
224 | // bar->setPos(xPos, yPos-barHeight); |
|
227 | // bar->setPos(xPos, yPos-barHeight); | |
225 | itemIndex++; |
|
228 | itemIndex++; | |
226 |
xPos += |
|
229 | xPos += barWidth; | |
227 | } |
|
230 | } | |
228 | } |
|
231 | } | |
229 |
|
232 | |||
230 | // Position floating values |
|
233 | // Position floating values | |
231 | itemIndex = 0; |
|
234 | itemIndex = 0; | |
232 | for (int category=0; category < mSeries->categoryCount(); category++) { |
|
235 | for (int category=0; category < mSeries->categoryCount(); category++) { | |
233 |
qreal xPos = categoryWidth * category + categoryWidth/2 + |
|
236 | qreal xPos = categoryWidth * category + categoryWidth/2 + barWidth; | |
234 |
qreal yPos = |
|
237 | qreal yPos = height; | |
235 | for (int set=0; set < mSeries->barsetCount(); set++) { |
|
238 | for (int set=0; set < mSeries->barsetCount(); set++) { | |
236 | qreal barHeight = mSeries->valueAt(set,category) * scale; |
|
239 | qreal barHeight = mSeries->valueAt(set,category) * scale; | |
237 | BarValue* value = mFloatingValues.at(itemIndex); |
|
240 | BarValue* value = mFloatingValues.at(itemIndex); | |
@@ -248,7 +251,7 QVector<QRectF> BarChartItem::calculateLayout() | |||||
248 | } |
|
251 | } | |
249 |
|
252 | |||
250 | itemIndex++; |
|
253 | itemIndex++; | |
251 |
xPos += |
|
254 | xPos += barWidth; | |
252 | } |
|
255 | } | |
253 | } |
|
256 | } | |
254 |
|
257 | |||
@@ -329,7 +332,7 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal | |||||
329 | void BarChartItem::handleGeometryChanged(const QRectF& rect) |
|
332 | void BarChartItem::handleGeometryChanged(const QRectF& rect) | |
330 | { |
|
333 | { | |
331 | m_rect=rect; |
|
334 | m_rect=rect; | |
332 | layoutChanged(); |
|
335 | handleLayoutChanged(); | |
333 | mLayoutSet = true; |
|
336 | mLayoutSet = true; | |
334 | setPos(rect.topLeft()); |
|
337 | setPos(rect.topLeft()); | |
335 | } |
|
338 | } |
General Comments 0
You need to be logged in to leave comments.
Login now