##// END OF EJS Templates
Fix label truncate issues with multiple axes...
Miikka Heikkinen -
r2411:6fca0e6f42a3
parent child
Show More
@@ -28,7 +28,7
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 static const qreal golden_ratio = 0.4;
31 static const qreal maxAxisPortion = 0.4;
32 32
33 33 ChartLayout::ChartLayout(ChartPresenter *presenter)
34 34 : m_presenter(presenter),
@@ -159,15 +159,51 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
159 159 }
160 160 }
161 161
162 int horizontal = leftCount + rightCount;
163 qreal hratio = 0 ;
164 if(horizontal>0)
165 hratio = (golden_ratio*geometry.width())/horizontal;
162 int totalVerticalAxes = leftCount + rightCount;
163 qreal leftSqueezeRatio = 1.0;
164 qreal rightSqueezeRatio = 1.0;
165 qreal vratio = 0;
166 166
167 if(leftCount>0)
168 left.setWidth(qMin(left.width(),hratio*leftCount));
169 if(rightCount>0)
170 right.setWidth(qMin(right.width(),hratio*rightCount));
167 if (totalVerticalAxes > 0)
168 vratio = (maxAxisPortion * geometry.width()) / totalVerticalAxes;
169
170 if (leftCount > 0) {
171 int maxWidth = vratio * leftCount;
172 if (left.width() > maxWidth) {
173 leftSqueezeRatio = maxWidth / left.width();
174 left.setWidth(maxWidth);
175 }
176 }
177 if (rightCount > 0) {
178 int maxWidth = vratio * rightCount;
179 if (right.width() > maxWidth) {
180 rightSqueezeRatio = maxWidth / right.width();
181 right.setWidth(maxWidth);
182 }
183 }
184
185 int totalHorizontalAxes = topCount + bottomCount;
186 qreal topSqueezeRatio = 1.0;
187 qreal bottomSqueezeRatio = 1.0;
188 qreal hratio = 0;
189
190 if (totalHorizontalAxes > 0)
191 hratio = (maxAxisPortion * geometry.height()) / totalHorizontalAxes;
192
193 if (topCount > 0) {
194 int maxHeight = hratio * topCount;
195 if (top.height() > maxHeight) {
196 topSqueezeRatio = maxHeight / top.height();
197 top.setHeight(maxHeight);
198 }
199 }
200 if (bottomCount > 0) {
201 int maxHeight = hratio * bottomCount;
202 if (bottom.height() > maxHeight) {
203 bottomSqueezeRatio = maxHeight / bottom.height();
204 bottom.setHeight(maxHeight);
205 }
206 }
171 207
172 208 qreal minHeight = qMax(minLeft.height(),minRight.height()) + 1;
173 209 qreal minWidth = qMax(minTop.width(),minBottom.width()) + 1;
@@ -191,24 +227,35 QRectF ChartLayout::calculateAxisGeometry(const QRectF &geometry, const QList<Ch
191 227
192 228 switch(axis->alignment()){
193 229 case Qt::AlignLeft:{
194 qreal width = qMin(size.width(),(left.width()/leftCount));
230 qreal width = size.width();
231 if (leftSqueezeRatio < 1.0)
232 width *= leftSqueezeRatio;
195 233 leftOffset+=width;
196 234 axis->setGeometry(QRect(chartRect.left()-leftOffset, geometry.top(),width, geometry.bottom()),chartRect);
197 235 break;
198 236 }
199 237 case Qt::AlignRight:{
200 qreal width = qMin(size.width(),(right.width()/rightCount));
238 qreal width = size.width();
239 if (rightSqueezeRatio < 1.0)
240 width *= rightSqueezeRatio;
201 241 axis->setGeometry(QRect(chartRect.right()+rightOffset,geometry.top(),width,geometry.bottom()),chartRect);
202 242 rightOffset+=width;
203 243 break;
204 244 }
205 case Qt::AlignTop:
206 axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - size.height(), geometry.width(), size.height()), chartRect);
207 topOffset += size.height();
245 case Qt::AlignTop: {
246 qreal height = size.height();
247 if (topSqueezeRatio < 1.0)
248 height *= topSqueezeRatio;
249 axis->setGeometry(QRect(geometry.left(), chartRect.top() - topOffset - height, geometry.width(), height), chartRect);
250 topOffset += height;
208 251 break;
252 }
209 253 case Qt::AlignBottom:
210 axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), size.height()), chartRect);
211 bottomOffset += size.height();
254 qreal height = size.height();
255 if (bottomSqueezeRatio < 1.0)
256 height *= bottomSqueezeRatio;
257 axis->setGeometry(QRect(geometry.left(), chartRect.bottom() + bottomOffset, geometry.width(), height), chartRect);
258 bottomOffset += height;
212 259 break;
213 260 }
214 261 }
@@ -270,13 +317,13 QRectF ChartLayout::calculateLegendGeometry(const QRectF &geometry, QLegend *leg
270 317 break;
271 318 }
272 319 case Qt::AlignLeft: {
273 qreal width = qMin(size.width(), geometry.width() * golden_ratio);
320 qreal width = qMin(size.width(), geometry.width() * maxAxisPortion);
274 321 legendRect = QRectF(geometry.topLeft(), QSizeF(width, geometry.height()));
275 322 result = geometry.adjusted(width, 0, 0, 0);
276 323 break;
277 324 }
278 325 case Qt::AlignRight: {
279 qreal width = qMin(size.width(), geometry.width() * golden_ratio);
326 qreal width = qMin(size.width(), geometry.width() * maxAxisPortion);
280 327 legendRect = QRectF(QPointF(geometry.right() - width, geometry.top()), QSizeF(width, geometry.height()));
281 328 result = geometry.adjusted(0, 0, -width, 0);
282 329 break;
General Comments 0
You need to be logged in to leave comments. Login now