summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTitta Heikkala <titta.heikkala@digia.com>2013-09-16 13:00:34 +0300
committerTitta Heikkala <titta.heikkala@digia.com>2013-09-16 13:57:45 +0300
commitf23ac19273506f9c0f9847ed336af2c36c202dc2 (patch)
tree70b46cc9ffe1d0bd2f9bd93ee298d6ac2fc327c5 /src
parent66fa88d106401d019172e2cdb6d0de2b2a22df1f (diff)
Fix logarithmic axis point calculation
For logarithmic axis the geometry point is set even if the point value is zero or negative. For zero and negative values the x-point is set to zero and the y-point is set to chart height. This way the bar chart items can ignore the return value from calculateGeometryPoint() method and not draw the bar for a value that does not have logarithm defined. Task-number: QTRD-2065 Change-Id: I7ba4efed6a0678eb487377e3e88bdee9c849a9a3 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/barchart/horizontal/bar/horizontalbarchartitem.cpp3
-rw-r--r--src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp2
-rw-r--r--src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp3
-rw-r--r--src/barchart/vertical/bar/barchartitem.cpp3
-rw-r--r--src/barchart/vertical/percent/percentbarchartitem.cpp2
-rw-r--r--src/barchart/vertical/stacked/stackedbarchartitem.cpp3
-rw-r--r--src/domain/logxlogydomain.cpp27
-rw-r--r--src/domain/logxydomain.cpp19
-rw-r--r--src/domain/xlogydomain.cpp19
9 files changed, 41 insertions, 40 deletions
diff --git a/src/barchart/horizontal/bar/horizontalbarchartitem.cpp b/src/barchart/horizontal/bar/horizontalbarchartitem.cpp
index 97d8ecb7..941a1645 100644
--- a/src/barchart/horizontal/bar/horizontalbarchartitem.cpp
+++ b/src/barchart/horizontal/bar/horizontalbarchartitem.cpp
@@ -81,9 +81,6 @@ QVector<QRectF> HorizontalBarChartItem::calculateLayout()
QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData);
- if (!m_validData)
- return QVector<QRectF>();
-
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 9d530e93..0a169ec5 100644
--- a/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp
+++ b/src/barchart/horizontal/percent/horizontalpercentbarchartitem.cpp
@@ -82,8 +82,6 @@ QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
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 0bfe8e6d..a4fad23c 100644
--- a/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp
+++ b/src/barchart/horizontal/stacked/horizontalstackedbarchartitem.cpp
@@ -92,8 +92,7 @@ QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
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 f5ea55ce..4b948afd 100644
--- a/src/barchart/vertical/bar/barchartitem.cpp
+++ b/src/barchart/vertical/bar/barchartitem.cpp
@@ -81,9 +81,6 @@ QVector<QRectF> BarChartItem::calculateLayout()
else
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 893b88da..e0e4a4a5 100644
--- a/src/barchart/vertical/percent/percentbarchartitem.cpp
+++ b/src/barchart/vertical/percent/percentbarchartitem.cpp
@@ -84,8 +84,6 @@ QVector<QRectF> PercentBarChartItem::calculateLayout()
else
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 42c2aad3..909d7d50 100644
--- a/src/barchart/vertical/stacked/stackedbarchartitem.cpp
+++ b/src/barchart/vertical/stacked/stackedbarchartitem.cpp
@@ -93,8 +93,7 @@ QVector<QRectF> StackedBarChartItem::calculateLayout()
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());
diff --git a/src/domain/logxlogydomain.cpp b/src/domain/logxlogydomain.cpp
index 9aa75fbe..85b9a019 100644
--- a/src/domain/logxlogydomain.cpp
+++ b/src/domain/logxlogydomain.cpp
@@ -138,18 +138,29 @@ void LogXLogYDomain::move(qreal dx, qreal dy)
QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
{
+ const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX);
+ const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
+ qreal x(0);
+ qreal y(0);
if (point.x() > 0 && point.y() > 0) {
- const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX);
- const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
- qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
- qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
+ x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
+ y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
ok = true;
- return QPointF(x, y);
} else {
- qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
+ qWarning() << "Logarithms of zero and negative values are undefined.";
ok = false;
- return QPointF();
+ if (point.x() > 0)
+ x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
+ else
+ x = 0;
+ if (point.y() > 0) {
+ y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY
+ + m_size.height();
+ } else {
+ y = m_size.height();
+ }
}
+ return QPointF(x, y);
}
QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
@@ -167,7 +178,7 @@ QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF> &v
result[i].setX(x);
result[i].setY(y);
} else {
- qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
+ qWarning() << "Logarithms of zero and negative values are undefined.";
return QVector<QPointF>();
}
}
diff --git a/src/domain/logxydomain.cpp b/src/domain/logxydomain.cpp
index f131096c..b42d1b64 100644
--- a/src/domain/logxydomain.cpp
+++ b/src/domain/logxydomain.cpp
@@ -131,20 +131,20 @@ void LogXYDomain::move(qreal dx, qreal dy)
QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
{
+ const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX);
+ const qreal deltaY = m_size.height() / (m_maxY - m_minY);
+ qreal x(0);
+ qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
if (point.x() > 0) {
- const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX);
- const qreal deltaY = m_size.height() / (m_maxY - m_minY);
-
- qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
- qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
+ x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
ok = true;
- return QPointF(x, y);
} else {
- qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
+ x = 0;
+ qWarning() << "Logarithms of zero and negative values are undefined.";
ok = false;
- return QPointF();
}
+ return QPointF(x, y);
}
QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
@@ -162,9 +162,10 @@ QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF> &vect
result[i].setX(x);
result[i].setY(y);
} else {
- qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
+ qWarning() << "Logarithms of zero and negative values are undefined.";
return QVector<QPointF>();
}
+
}
return result;
}
diff --git a/src/domain/xlogydomain.cpp b/src/domain/xlogydomain.cpp
index 7ad194b5..494e8f5b 100644
--- a/src/domain/xlogydomain.cpp
+++ b/src/domain/xlogydomain.cpp
@@ -131,19 +131,20 @@ void XLogYDomain::move(qreal dx, qreal dy)
QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
{
- if (point.y() > 0) {
- const qreal deltaX = m_size.width() / (m_maxX - m_minX);
- const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
+ const qreal deltaX = m_size.width() / (m_maxX - m_minX);
+ const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
- qreal x = (point.x() - m_minX) * deltaX;
- qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
+ qreal x = (point.x() - m_minX) * deltaX;
+ qreal y(0);
+ if (point.y() > 0) {
+ y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
ok = true;
- return QPointF(x, y);
} else {
- qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
+ y = m_size.height();
+ qWarning() << "Logarithms of zero and negative values are undefined.";
ok = false;
- return QPointF();
}
+ return QPointF(x, y);
}
QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
@@ -161,7 +162,7 @@ QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF> &vect
result[i].setX(x);
result[i].setY(y);
} else {
- qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
+ qWarning() << "Logarithms of zero and negative values are undefined.";
return QVector<QPointF>();
}
}