summaryrefslogtreecommitdiffstats
path: root/src/barchart
diff options
context:
space:
mode:
authorMarek Rosa <marek.rosa@digia.com>2012-12-07 17:18:25 +0200
committerMarek Rosa <marek.rosa@digia.com>2012-12-10 09:41:52 +0200
commitc0053ad31507a3361f89733c154f5e50d16a168e (patch)
tree3dc05aeebe2576bb5fcbec20fc1f5a302f0b78e1 /src/barchart
parent66a2c62c4a9bfb409a669d082e451ea834f87e5e (diff)
Negative values with log axis handled
Diffstat (limited to 'src/barchart')
-rw-r--r--src/barchart/horizontal/bar/horizontalbarchartitem.cpp21
-rw-r--r--src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp20
-rw-r--r--src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp25
-rw-r--r--src/barchart/vertical/bar/barchartitem.cpp20
-rw-r--r--src/barchart/vertical/percent/percentbarchartitem.cpp20
-rw-r--r--src/barchart/vertical/stacked/stackedbarchartitem.cpp25
6 files changed, 83 insertions, 48 deletions
diff --git a/src/barchart/horizontal/bar/horizontalbarchartitem.cpp b/src/barchart/horizontal/bar/horizontalbarchartitem.cpp
index c3633e54..b2cedc51 100644
--- a/src/barchart/horizontal/bar/horizontalbarchartitem.cpp
+++ b/src/barchart/horizontal/bar/horizontalbarchartitem.cpp
@@ -43,13 +43,16 @@ void HorizontalBarChartItem::initializeLayout()
QPointF topLeft;
QPointF bottomRight;
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
- topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth));
- bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2 + (set + 1)/setCount * barWidth));
+ topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2 + (set + 1)/setCount * barWidth), m_validData);
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth));
- bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth));
+ topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData);
}
+ if (!m_validData)
+ return;
+
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
@@ -72,11 +75,15 @@ QVector<QRectF> HorizontalBarChartItem::calculateLayout()
QRectF rect;
QPointF topLeft;
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth));
+ topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2 + set/setCount * barWidth), m_validData);
else
- topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth));
+ topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2 + set/setCount * barWidth), m_validData);
+
+ QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData);
+
+ if (!m_validData)
+ return QVector<QRectF>();
- QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth));
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
layout.append(rect.normalized());
diff --git a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp
index af679d03..dd650a9e 100644
--- a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp
+++ b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp
@@ -43,13 +43,16 @@ void HorizontalPercentBarChartItem::initializeLayout()
QPointF topLeft;
QPointF bottomRight;
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
- topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2));
- bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2), m_validData);
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2));
- bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2), m_validData);
}
+ if (!m_validData)
+ return;
+
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
@@ -74,10 +77,13 @@ QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
QRectF rect;
QPointF topLeft;
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category - barWidth/2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : domain()->minX(), category - barWidth/2), m_validData);
else
- topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2));
- QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2), m_validData);
+ QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2), m_validData);
+
+ if (!m_validData)
+ return QVector<QRectF>();
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
layout.append(rect.normalized());
diff --git a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp
index e603d04a..88227ad0 100644
--- a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp
+++ b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp
@@ -43,13 +43,16 @@ void HorizontalStackedBarChartItem::initializeLayout()
QPointF topLeft;
QPointF bottomRight;
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
- topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2));
- bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category - barWidth / 2), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(domain()->minX(), category + barWidth / 2), m_validData);
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2));
- bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(0, category - barWidth / 2), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(0, category + barWidth / 2), m_validData);
}
+ if (!m_validData)
+ return;
+
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
@@ -75,20 +78,22 @@ QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
QPointF topLeft;
QPointF bottomRight;
if (value < 0) {
- bottomRight = domain()->calculateGeometryPoint(QPointF(value + negativeSum, category - barWidth / 2));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(value + negativeSum, category - barWidth / 2), m_validData);
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : domain()->minX(), category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : domain()->minX(), category + barWidth / 2), m_validData);
else
- topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : 0, category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(set ? negativeSum : 0, category + barWidth / 2), m_validData);
negativeSum += value;
} else {
- bottomRight = domain()->calculateGeometryPoint(QPointF(value + positiveSum, category - barWidth / 2));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(value + positiveSum, category - barWidth / 2), m_validData);
if (domain()->type() == AbstractDomain::LogXYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : domain()->minX(), category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : domain()->minX(), category + barWidth / 2), m_validData);
else
- topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2));
+ topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2), m_validData);
positiveSum += value;
}
+ if (!m_validData)
+ return QVector<QRectF>();
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
layout.append(rect.normalized());
diff --git a/src/barchart/vertical/bar/barchartitem.cpp b/src/barchart/vertical/bar/barchartitem.cpp
index d58ca357..7fb17f2a 100644
--- a/src/barchart/vertical/bar/barchartitem.cpp
+++ b/src/barchart/vertical/bar/barchartitem.cpp
@@ -45,13 +45,15 @@ void BarChartItem::initializeLayout()
QPointF bottomRight;
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()));
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY()));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, domain()->minY()), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2 + (set + 1)/setCount * barWidth, domain()->minY()), m_validData);
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0));
- bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + set/setCount * barWidth, 0), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/setCount * barWidth, 0), m_validData);
}
+ if (!m_validData)
+ return;
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
@@ -72,12 +74,16 @@ QVector<QRectF> BarChartItem::calculateLayout()
for (int set = 0; set < setCount; set++) {
qreal value = m_series->barSets().at(set)->at(category);
QRectF rect;
- QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value));
+ QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set)/(setCount) * barWidth, value), m_validData);
QPointF bottomRight;
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, domain()->minY()), m_validData);
else
- bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData);
+
+ if (!m_validData)
+ return QVector<QRectF>();
+
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
layout.append(rect.normalized());
diff --git a/src/barchart/vertical/percent/percentbarchartitem.cpp b/src/barchart/vertical/percent/percentbarchartitem.cpp
index a7e952ed..fc04d345 100644
--- a/src/barchart/vertical/percent/percentbarchartitem.cpp
+++ b/src/barchart/vertical/percent/percentbarchartitem.cpp
@@ -45,13 +45,16 @@ void PercentBarChartItem::initializeLayout()
QPointF bottomRight;
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()));
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()), m_validData);
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0));
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0), m_validData);
}
+ if (!m_validData)
+ return;
+
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
@@ -74,12 +77,15 @@ QVector<QRectF> PercentBarChartItem::calculateLayout()
for (int set = 0; set < setCount; set++) {
qreal value = m_series->barSets().at(set)->at(category);
QRectF rect;
- QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum));
+ QPointF topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth/2, 100 * (value + sum)/categorySum), m_validData);
QPointF bottomRight;
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY()));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : domain()->minY()), m_validData);
else
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0), m_validData);
+
+ if (!m_validData)
+ return QVector<QRectF>();
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
layout.append(rect.normalized());
diff --git a/src/barchart/vertical/stacked/stackedbarchartitem.cpp b/src/barchart/vertical/stacked/stackedbarchartitem.cpp
index 377bd5da..9acb1259 100644
--- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp
+++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp
@@ -45,13 +45,16 @@ void StackedBarChartItem::initializeLayout()
QPointF bottomRight;
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain) {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()));
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, domain()->minY()), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, domain()->minY()), m_validData);
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0));
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, 0), m_validData);
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, 0), m_validData);
}
+ if (!m_validData)
+ return;
+
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
m_layout.append(rect.normalized());
@@ -76,20 +79,22 @@ QVector<QRectF> StackedBarChartItem::calculateLayout()
QPointF topLeft;
QPointF bottomRight;
if (value < 0) {
- bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + negativeSum));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + negativeSum), m_validData);
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : domain()->minY()));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : domain()->minY()), m_validData);
else
- topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? negativeSum : 0), m_validData);
negativeSum += value;
} else {
- topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum));
+ topLeft = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2, value + positiveSum), m_validData);
if (domain()->type() == AbstractDomain::XLogYDomain || domain()->type() == AbstractDomain::LogXLogYDomain)
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY()));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : domain()->minY()), m_validData);
else
- bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0));
+ bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0), m_validData);
positiveSum += value;
}
+ if (!m_validData)
+ return QVector<QRectF>();
rect.setTopLeft(topLeft);
rect.setBottomRight(bottomRight);
layout.append(rect.normalized());