##// END OF EJS Templates
adds Andy's customer request, first call to createDaultAxis scales whole domain (if on common axis)
Michal Klocek -
r2408:f065af9daaed
parent child
Show More
@@ -303,11 +303,13 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation ori
303 303 //create one axis for all
304 304
305 305 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
306
306 qreal min = 0;
307 qreal max = 0;
308 findMinMaxForSeries(m_seriesList,orientation,min,max);
307 309 foreach(QAbstractSeries *s, m_seriesList) {
308 310 attachAxis(s,axis);
309 311 }
310
312 axis->setRange(min,max);
311 313 }
312 314 else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
313 315 //create separate axis
@@ -321,6 +323,21 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation ori
321 323 }
322 324 }
323 325
326 void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max)
327 {
328 Q_ASSERT(!series.isEmpty());
329
330 AbstractDomain* domain = series.first()->d_ptr->domain();
331 min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX();
332 max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX();
333
334 for(int i = 1; i< series.size(); i++) {
335 AbstractDomain* domain = series[i]->d_ptr->domain();
336 min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min);
337 max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max);
338 }
339 }
340
324 341 void ChartDataSet::deleteAllSeries()
325 342 {
326 343 foreach (QAbstractSeries *s , m_seriesList){
@@ -80,6 +80,7 private:
80 80 AbstractDomain* createDomain(AbstractDomain::DomainType type);
81 81 void deleteAllAxes();
82 82 void deleteAllSeries();
83 void findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max);
83 84 private:
84 85 QList<QAbstractSeries *> m_seriesList;
85 86 QList<QAbstractAxis *> m_axisList;
@@ -99,7 +99,8 private slots:
99 99 void zoomIn();
100 100 void zoomOut_data();
101 101 void zoomOut();
102
102 void createDefaultAxesForLineSeries_data();
103 void createDefaultAxesForLineSeries();
103 104 private:
104 105 void createTestData();
105 106
@@ -793,6 +794,83 void tst_QChart::zoomOut()
793 794
794 795 }
795 796
797 void tst_QChart::createDefaultAxesForLineSeries_data()
798 {
799 QTest::addColumn<qreal>("series1minX");
800 QTest::addColumn<qreal>("series1midX");
801 QTest::addColumn<qreal>("series1maxX");
802 QTest::addColumn<qreal>("series2minX");
803 QTest::addColumn<qreal>("series2midX");
804 QTest::addColumn<qreal>("series2maxX");
805 QTest::addColumn<qreal>("overallminX");
806 QTest::addColumn<qreal>("overallmaxX");
807 QTest::addColumn<qreal>("series1minY");
808 QTest::addColumn<qreal>("series1midY");
809 QTest::addColumn<qreal>("series1maxY");
810 QTest::addColumn<qreal>("series2minY");
811 QTest::addColumn<qreal>("series2midY");
812 QTest::addColumn<qreal>("series2maxY");
813 QTest::addColumn<qreal>("overallminY");
814 QTest::addColumn<qreal>("overallmaxY");
815 QTest::newRow("series1hasMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0
816 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0;
817 QTest::newRow("series2hasMinAndMax") << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0
818 << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0;
819 QTest::newRow("series1hasMinAndMaxX_series2hasMinAndMaxY") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0
820 << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0;
821 QTest::newRow("series1hasMin_series2hasMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0
822 << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0;
823 }
824
825 void tst_QChart::createDefaultAxesForLineSeries()
826 {
827 QFETCH(qreal, series1minX);
828 QFETCH(qreal, series1midX);
829 QFETCH(qreal, series1maxX);
830 QFETCH(qreal, series2minX);
831 QFETCH(qreal, series2midX);
832 QFETCH(qreal, series2maxX);
833 QFETCH(qreal, series1minY);
834 QFETCH(qreal, series1midY);
835 QFETCH(qreal, series1maxY);
836 QFETCH(qreal, series2minY);
837 QFETCH(qreal, series2midY);
838 QFETCH(qreal, series2maxY);
839 QFETCH(qreal, overallminX);
840 QFETCH(qreal, overallmaxX);
841 QFETCH(qreal, overallminY);
842 QFETCH(qreal, overallmaxY);
843 QLineSeries* series1 = new QLineSeries(this);
844 series1->append(series1minX, series1minY);
845 series1->append(series1midX, series1midY);
846 series1->append(series1maxX, series1maxY);
847 QLineSeries* series2 = new QLineSeries(this);
848 series2->append(series2minX, series2minY);
849 series2->append(series2midX, series2midY);
850 series2->append(series2maxX, series2maxY);
851 QChart chart;
852 chart.addSeries(series1);
853 chart.addSeries(series2);
854 chart.createDefaultAxes();
855 QValueAxis *xAxis = (QValueAxis *)chart.axisX();
856 QCOMPARE(xAxis->min(), overallminX);
857 QCOMPARE(xAxis->max(), overallmaxX);
858 QValueAxis *yAxis = (QValueAxis *)chart.axisY();
859 QCOMPARE(yAxis->min(), overallminY);
860 QCOMPARE(yAxis->max(), overallmaxY);
861 QLineSeries *series3 = new QLineSeries(this);
862 // Numbers clearly out of existing range
863 series3->append(0, 0);
864 series3->append(100, 100);
865 // Adding a new series should not change the axes as they have not been told to update
866 chart.addSeries(series3);
867 QCOMPARE(xAxis->min(), overallminX);
868 QCOMPARE(xAxis->max(), overallmaxX);
869 QCOMPARE(yAxis->min(), overallminY);
870 QCOMPARE(yAxis->max(), overallmaxY);
871
872 }
873
796 874 QTEST_MAIN(tst_QChart)
797 875 #include "tst_qchart.moc"
798 876
General Comments 0
You need to be logged in to leave comments. Login now