@@ -75,17 +75,24 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout() | |||||
75 | for (int set = 0; set < setCount; set++) { |
|
75 | for (int set = 0; set < setCount; set++) { | |
76 | qreal value = m_series->barSets().at(set)->at(category); |
|
76 | qreal value = m_series->barSets().at(set)->at(category); | |
77 | QRectF rect; |
|
77 | QRectF rect; | |
|
78 | qreal topX = 0; | |||
|
79 | if (sum > 0) | |||
|
80 | topX = 100 * sum / categorySum; | |||
|
81 | qreal bottomX = 0; | |||
|
82 | qreal newSum = value + sum; | |||
|
83 | if (newSum > 0) | |||
|
84 | bottomX = 100 * newSum / categorySum; | |||
78 | QPointF topLeft; |
|
85 | QPointF topLeft; | |
79 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
86 | if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
80 |
topLeft = domain()->calculateGeometryPoint(QPointF(set ? |
|
87 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? topX : domain()->minX(), category - barWidth/2), m_validData); | |
81 | else |
|
88 | else | |
82 |
topLeft = domain()->calculateGeometryPoint(QPointF(set ? |
|
89 | topLeft = domain()->calculateGeometryPoint(QPointF(set ? topX : 0, category - barWidth/2), m_validData); | |
83 |
QPointF bottomRight = domain()->calculateGeometryPoint(QPointF( |
|
90 | QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(bottomX, category + barWidth/2), m_validData); | |
84 |
|
91 | |||
85 | rect.setTopLeft(topLeft); |
|
92 | rect.setTopLeft(topLeft); | |
86 | rect.setBottomRight(bottomRight); |
|
93 | rect.setBottomRight(bottomRight); | |
87 | layout.append(rect.normalized()); |
|
94 | layout.append(rect.normalized()); | |
88 |
sum |
|
95 | sum = newSum; | |
89 | } |
|
96 | } | |
90 | } |
|
97 | } | |
91 | return layout; |
|
98 | return layout; |
@@ -32,14 +32,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
32 | \brief Series for creating horizontal percent bar chart. |
|
32 | \brief Series for creating horizontal percent bar chart. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 |
QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this |
|
35 | QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this | |
36 |
as groups, where bars in same category are grouped next to each other. |
|
36 | class is to draw bars as groups, where bars in same category are grouped next to each other. | |
37 |
from sets to categories, which are defined by a |
|
37 | QHorizontalPercentBarSeries groups the data from sets to categories, which are defined by a | |
|
38 | QStringList. Bars with zero value are not drawn. | |||
38 |
|
39 | |||
39 |
See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn |
|
40 | See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn | |
|
41 | how to create a horizontal percent bar chart. | |||
40 | \image examples_horizontalpercentbarchart.png |
|
42 | \image examples_horizontalpercentbarchart.png | |
41 |
|
43 | |||
42 |
\sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, |
|
44 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, | |
|
45 | QHorizontalStackedBarSeries, QHorizontalBarSeries | |||
43 | */ |
|
46 | */ | |
44 | #ifdef QDOC_QT5 |
|
47 | #ifdef QDOC_QT5 | |
45 | /*! |
|
48 | /*! |
@@ -80,17 +80,24 QVector<QRectF> PercentBarChartItem::calculateLayout() | |||||
80 | for (int set = 0; set < setCount; set++) { |
|
80 | for (int set = 0; set < setCount; set++) { | |
81 | qreal value = m_series->barSets().at(set)->at(category); |
|
81 | qreal value = m_series->barSets().at(set)->at(category); | |
82 | QRectF rect; |
|
82 | QRectF rect; | |
83 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum), m_validData); |
|
83 | qreal topY = 0; | |
|
84 | qreal newSum = value + sum; | |||
|
85 | if (newSum > 0) | |||
|
86 | topY = 100 * newSum / categorySum; | |||
|
87 | qreal bottomY = 0; | |||
|
88 | if (sum > 0) | |||
|
89 | bottomY = 100 * sum / categorySum; | |||
|
90 | QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, topY), m_validData); | |||
84 | QPointF bottomRight; |
|
91 | QPointF bottomRight; | |
85 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) |
|
92 | if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) | |
86 |
bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? |
|
93 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? bottomY : domain()->minY()), m_validData); | |
87 | else |
|
94 | else | |
88 |
bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? |
|
95 | bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? bottomY : 0), m_validData); | |
89 |
|
96 | |||
90 | rect.setTopLeft(topLeft); |
|
97 | rect.setTopLeft(topLeft); | |
91 | rect.setBottomRight(bottomRight); |
|
98 | rect.setBottomRight(bottomRight); | |
92 | layout.append(rect.normalized()); |
|
99 | layout.append(rect.normalized()); | |
93 |
sum |
|
100 | sum = newSum; | |
94 | } |
|
101 | } | |
95 | } |
|
102 | } | |
96 | return layout; |
|
103 | return layout; |
@@ -33,11 +33,13 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
33 | \brief Series for creating percent bar chart. |
|
33 | \brief Series for creating percent bar chart. | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 |
QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to |
|
36 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to | |
37 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
37 | draw bars as stacks, where each bar is shown as percentage of all bars in that category. | |
38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
|
39 | Bars with zero value are not drawn. | |||
39 |
|
40 | |||
40 |
See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a |
|
41 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a | |
|
42 | percent bar chart. | |||
41 | \image examples_percentbarchart.png |
|
43 | \image examples_percentbarchart.png | |
42 |
|
44 | |||
43 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
|
45 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
@@ -51,6 +51,7 private slots: | |||||
51 | void mouseclicked(); |
|
51 | void mouseclicked(); | |
52 | void mousehovered_data(); |
|
52 | void mousehovered_data(); | |
53 | void mousehovered(); |
|
53 | void mousehovered(); | |
|
54 | void zeroValuesInSeries(); | |||
54 |
|
55 | |||
55 | private: |
|
56 | private: | |
56 | QHorizontalPercentBarSeries* m_barseries; |
|
57 | QHorizontalPercentBarSeries* m_barseries; | |
@@ -653,6 +654,25 void tst_QHorizontalPercentBarSeries::mousehovered() | |||||
653 | QVERIFY(setIndexSpyArg.at(1).toInt() == 1); |
|
654 | QVERIFY(setIndexSpyArg.at(1).toInt() == 1); | |
654 | } |
|
655 | } | |
655 |
|
656 | |||
|
657 | void tst_QHorizontalPercentBarSeries::zeroValuesInSeries() | |||
|
658 | { | |||
|
659 | QHorizontalPercentBarSeries *series = new QHorizontalPercentBarSeries(); | |||
|
660 | QBarSet *set1 = new QBarSet(QString("set 1")); | |||
|
661 | *set1 << 100 << 0.0 << 10; | |||
|
662 | series->append(set1); | |||
|
663 | ||||
|
664 | QBarSet *set2 = new QBarSet(QString("set 2")); | |||
|
665 | *set2 << 0.0 << 0.0 << 70; | |||
|
666 | series->append(set2); | |||
|
667 | ||||
|
668 | QChartView view(new QChart()); | |||
|
669 | view.chart()->addSeries(series); | |||
|
670 | view.chart()->createDefaultAxes(); | |||
|
671 | view.show(); | |||
|
672 | ||||
|
673 | QTest::qWaitForWindowShown(&view); | |||
|
674 | } | |||
|
675 | ||||
656 | QTEST_MAIN(tst_QHorizontalPercentBarSeries) |
|
676 | QTEST_MAIN(tst_QHorizontalPercentBarSeries) | |
657 |
|
677 | |||
658 | #include "tst_qhorizontalpercentbarseries.moc" |
|
678 | #include "tst_qhorizontalpercentbarseries.moc" |
@@ -51,6 +51,7 private slots: | |||||
51 | void mouseclicked(); |
|
51 | void mouseclicked(); | |
52 | void mousehovered_data(); |
|
52 | void mousehovered_data(); | |
53 | void mousehovered(); |
|
53 | void mousehovered(); | |
|
54 | void zeroValuesInSeries(); | |||
54 |
|
55 | |||
55 | private: |
|
56 | private: | |
56 | QPercentBarSeries* m_barseries; |
|
57 | QPercentBarSeries* m_barseries; | |
@@ -657,6 +658,25 void tst_QPercentBarSeries::mousehovered() | |||||
657 | QVERIFY(setIndexSpyArg.at(1).toInt() == 1); |
|
658 | QVERIFY(setIndexSpyArg.at(1).toInt() == 1); | |
658 | } |
|
659 | } | |
659 |
|
660 | |||
|
661 | void tst_QPercentBarSeries::zeroValuesInSeries() | |||
|
662 | { | |||
|
663 | QPercentBarSeries *series = new QPercentBarSeries(); | |||
|
664 | QBarSet *set1 = new QBarSet(QString("set 1")); | |||
|
665 | *set1 << 100 << 0.0 << 10; | |||
|
666 | series->append(set1); | |||
|
667 | ||||
|
668 | QBarSet *set2 = new QBarSet(QString("set 2")); | |||
|
669 | *set2 << 0.0 << 0.0 << 70; | |||
|
670 | series->append(set2); | |||
|
671 | ||||
|
672 | QChartView view(new QChart()); | |||
|
673 | view.chart()->addSeries(series); | |||
|
674 | view.chart()->createDefaultAxes(); | |||
|
675 | view.show(); | |||
|
676 | ||||
|
677 | QTest::qWaitForWindowShown(&view); | |||
|
678 | } | |||
|
679 | ||||
660 | QTEST_MAIN(tst_QPercentBarSeries) |
|
680 | QTEST_MAIN(tst_QPercentBarSeries) | |
661 |
|
681 | |||
662 | #include "tst_qpercentbarseries.moc" |
|
682 | #include "tst_qpercentbarseries.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now