##// END OF EJS Templates
bar chart layout fixing
sauimone -
r99:f2e3978c70a1
parent child
Show More
@@ -54,7 +54,7 int BarChartSeries::max()
54 }
54 }
55
55
56
56
57 int BarChartSeries::countSeries()
57 int BarChartSeries::countRows()
58 {
58 {
59 return mModel->rowCount();
59 return mModel->rowCount();
60 }
60 }
@@ -27,7 +27,7 public:
27 // Methods to find out minimum and maximum values of data
27 // Methods to find out minimum and maximum values of data
28 int min();
28 int min();
29 int max();
29 int max();
30 int countSeries();
30 int countRows();
31 int countColumns(); // Count items in one series.
31 int countColumns(); // Count items in one series.
32 int countTotalItems();
32 int countTotalItems();
33 int valueAt(int row, int column);
33 int valueAt(int row, int column);
@@ -95,32 +95,64 void BarGroup::layoutChanged()
95 {
95 {
96 // Scale bars to new layout
96 // Scale bars to new layout
97 // Layout for bars:
97 // Layout for bars:
98 if (mSeries.countSeries() <= 0) {
98 if (mSeries.countRows() <= 0) {
99 // Nothing to do.
99 // Nothing to do.
100 return;
100 return;
101 }
101 }
102
102
103 // TODO: better way to auto-layout
103 // TODO: better way to auto-layout
104 int count = mSeries.countColumns();
104 // Use reals for accurancy (we might get some compiler warnings... :)
105 int posStep = (mWidth / (count+1));
105 int columnCount = mSeries.countColumns();
106 int startPos = (mWidth / (count+1)) - mSeries.countSeries() * mBarDefaultWidth /2;
106 int rowCount = mSeries.countRows();
107 qDebug() << "startpos" << startPos;
108
107
108 qreal tW = mWidth;
109 qreal tH = mHeight;
110 qreal tM = mMax;
111 qreal scale = (tH/tM);
112
113 qreal tC = columnCount+1;
114 qreal xStepPerSeries = (tW/tC);
115
116 //qint startPos = (mWidth / (count+1)) - mSeries.countSeries() * mBarDefaultWidth /2;
117 // qDebug() << "XPOS:" << xPos;
118
119 qDebug() << "XSTEP:" << xStepPerSeries;
120
121 // TODO: Correct the calculations...
109 // Scaling.
122 // Scaling.
110 int itemIndex(0);
123 int itemIndex(0);
111 for (int series = 0; series < mSeries.countSeries(); series++) {
124 for (int column=0; column < columnCount; column++) {
125 qreal xPos = xStepPerSeries * column + ((tW + mBarDefaultWidth*rowCount)/(columnCount*2));
126 qDebug() << "XPOS:" << xPos;
127 for (int row = 0; row < rowCount; row++) {
128 qreal barHeight = mSeries.valueAt(row, column) * scale;
129 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
130
131 // TODO: width settable per bar?
132 bar->resize(mBarDefaultWidth, barHeight);
133 bar->setColor(mColors.at(row));
134 bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight);
135 itemIndex++;
136 xPos += mBarDefaultWidth;
137 }
138 }
139
140 /*
141 for (int series = 0; series < mSeries.countRows(); series++) {
112 for (int item=0; item < mSeries.countColumns(); item++) {
142 for (int item=0; item < mSeries.countColumns(); item++) {
113 qDebug() << itemIndex;
143 qreal barHeight = mSeries.valueAt(series, item) * scale;
114 int barHeight = mSeries.valueAt(series, item) * mHeight / mMax;
115 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
144 Bar* bar = reinterpret_cast<Bar*> (childItems().at(itemIndex));
116
145
117 // TODO: width settable per bar?
146 // TODO: width settable per bar?
118 bar->resize(mBarDefaultWidth, barHeight);
147 bar->resize(mBarDefaultWidth, barHeight);
119 bar->setColor(mColors.at(series));
148 bar->setColor(mColors.at(series));
120 bar->setPos(item*posStep+startPos + series * mBarDefaultWidth, mHeight);
149 bar->setPos(xPos, mHeight); // item*posStep+startPos + series * mBarDefaultWidth, mHeight);
121 itemIndex++;
150 itemIndex++;
151 xPos += mBarDefaultWidth;
122 }
152 }
153 xPos = xStepPerSeries * series;
123 }
154 }
155 */
124 mLayoutDirty = true;
156 mLayoutDirty = true;
125 }
157 }
126
158
@@ -101,7 +101,7 void StackedBarGroup::layoutChanged()
101 }
101 }
102
102
103 // TODO: better way to auto-layout
103 // TODO: better way to auto-layout
104 // Use reals for accurancy (implicit casting here, we get a warning)
104 // Use reals for accurancy (we might get some compiler warnings... :)
105 qreal maxSum = mSeries.maxColumnSum();
105 qreal maxSum = mSeries.maxColumnSum();
106 qreal h = mHeight;
106 qreal h = mHeight;
107 qreal scale = (h / maxSum);
107 qreal scale = (h / maxSum);
General Comments 0
You need to be logged in to leave comments. Login now