##// END OF EJS Templates
scaledomain fix for barchart
sauimone -
r1423:4a12a8646078
parent child
Show More
@@ -482,6 +482,44 qreal QBarSeriesPrivate::maxCategorySum()
482 482 return max;
483 483 }
484 484
485 qreal QBarSeriesPrivate::minX()
486 {
487 if (m_barSets.count() <= 0) {
488 return 0;
489 }
490 qreal min = INT_MAX;
491
492 for (int i = 0; i < m_barSets.count(); i++) {
493 int categoryCount = m_barSets.at(i)->count();
494 for (int j = 0; j < categoryCount; j++) {
495 qreal temp = m_barSets.at(i)->at(j).x();
496 if (temp < min)
497 min = temp;
498 }
499 }
500 return min;
501 }
502
503 qreal QBarSeriesPrivate::maxX()
504 {
505 if (m_barSets.count() <= 0) {
506 return 0;
507 }
508 qreal max = INT_MIN;
509
510 for (int i = 0; i < m_barSets.count(); i++) {
511 int categoryCount = m_barSets.at(i)->count();
512 for (int j = 0; j < categoryCount; j++) {
513 qreal temp = m_barSets.at(i)->at(j).x();
514 if (temp > max)
515 max = temp;
516 }
517 }
518
519 return max;
520 }
521
522
485 523 void QBarSeriesPrivate::scaleDomain(Domain& domain)
486 524 {
487 525 qreal minX(domain.minX());
@@ -491,13 +529,14 void QBarSeriesPrivate::scaleDomain(Domain& domain)
491 529 int tickXCount(domain.tickXCount());
492 530 int tickYCount(domain.tickYCount());
493 531
494 qreal x = categoryCount();
532 qreal seriesMinX = this->minX();
533 qreal seriesMaxX = this->maxX();
495 534 qreal y = max();
496 minX = qMin(minX, x) - 0.5;
535 minX = qMin(minX, seriesMinX - 0.5);
497 536 minY = qMin(minY, y);
498 maxX = qMax(maxX, x) + 0.5;
537 maxX = qMax(maxX, seriesMaxX + 0.5);
499 538 maxY = qMax(maxY, y);
500 tickXCount = x+1;
539 tickXCount = categoryCount()+1;
501 540
502 541 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
503 542 }
@@ -76,6 +76,8 public:
76 76 qreal categorySum(int category);
77 77 qreal absoluteCategorySum(int category);
78 78 qreal maxCategorySum();
79 qreal minX();
80 qreal maxX();
79 81
80 82 Q_SIGNALS:
81 83 void clicked(QBarSet *barset, int index);
@@ -77,9 +77,9 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
77 77
78 78 qreal x = categoryCount();
79 79 qreal y = max();
80 minX = qMin(minX, x) - 0.5;
80 minX = qMin(minX, -0.5);
81 81 minY = qMin(minY, y);
82 maxX = qMax(maxX, x) - 0.5;
82 maxX = qMax(maxX, x - 0.5);
83 83 maxY = qMax(maxY, y);
84 84 tickXCount = x+1;
85 85
@@ -76,8 +76,8 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
76 76 int tickYCount(domain.tickYCount());
77 77
78 78 qreal x = categoryCount();
79 minX = qMin(minX, x) - 0.5;
80 maxX = qMax(maxX, x) - 0.5;
79 minX = qMin(minX, -0.5);
80 maxX = qMax(maxX, x - 0.5);
81 81 minY = 0;
82 82 maxY = 100;
83 83 tickXCount = x+1;
@@ -77,9 +77,9 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
77 77
78 78 qreal x = categoryCount();
79 79 qreal y = maxCategorySum();
80 minX = qMin(minX, x) - 0.5;
80 minX = qMin(minX, -0.5);
81 81 minY = qMin(minY, y);
82 maxX = qMax(maxX, x) - 0.5;
82 maxX = qMax(maxX, x - 0.5);
83 83 maxY = qMax(maxY, y);
84 84 tickXCount = x+1;
85 85
General Comments 0
You need to be logged in to leave comments. Login now