##// END OF EJS Templates
Fix logarithmic axis point calculation...
Titta Heikkala -
r2611:f23ac1927350
parent child
Show More
@@ -81,9 +81,6 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
81 81
82 82 QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(value, category - barWidth / 2 + (set + 1)/setCount * barWidth), m_validData);
83 83
84 if (!m_validData)
85 return QVector<QRectF>();
86
87 84 rect.setTopLeft(topLeft);
88 85 rect.setBottomRight(bottomRight);
89 86 layout.append(rect.normalized());
@@ -82,8 +82,6 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
82 82 topLeft = domain()->calculateGeometryPoint(QPointF(set ? 100 * sum/categorySum : 0, category - barWidth/2), m_validData);
83 83 QPointF bottomRight = domain()->calculateGeometryPoint(QPointF(100 * (value + sum)/categorySum, category + barWidth/2), m_validData);
84 84
85 if (!m_validData)
86 return QVector<QRectF>();
87 85 rect.setTopLeft(topLeft);
88 86 rect.setBottomRight(bottomRight);
89 87 layout.append(rect.normalized());
@@ -92,8 +92,7 QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
92 92 topLeft = domain()->calculateGeometryPoint(QPointF(set ? positiveSum : 0, category + barWidth / 2), m_validData);
93 93 positiveSum += value;
94 94 }
95 if (!m_validData)
96 return QVector<QRectF>();
95
97 96 rect.setTopLeft(topLeft);
98 97 rect.setBottomRight(bottomRight);
99 98 layout.append(rect.normalized());
@@ -81,9 +81,6 QVector<QRectF> BarChartItem::calculateLayout()
81 81 else
82 82 bottomRight = domain()->calculateGeometryPoint(QPointF(category - barWidth / 2 + (set + 1)/(setCount) * barWidth, 0), m_validData);
83 83
84 if (!m_validData)
85 return QVector<QRectF>();
86
87 84 rect.setTopLeft(topLeft);
88 85 rect.setBottomRight(bottomRight);
89 86 layout.append(rect.normalized());
@@ -84,8 +84,6 QVector<QRectF> PercentBarChartItem::calculateLayout()
84 84 else
85 85 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth/2, set ? 100 * sum/categorySum : 0), m_validData);
86 86
87 if (!m_validData)
88 return QVector<QRectF>();
89 87 rect.setTopLeft(topLeft);
90 88 rect.setBottomRight(bottomRight);
91 89 layout.append(rect.normalized());
@@ -93,8 +93,7 QVector<QRectF> StackedBarChartItem::calculateLayout()
93 93 bottomRight = domain()->calculateGeometryPoint(QPointF(category + barWidth / 2, set ? positiveSum : 0), m_validData);
94 94 positiveSum += value;
95 95 }
96 if (!m_validData)
97 return QVector<QRectF>();
96
98 97 rect.setTopLeft(topLeft);
99 98 rect.setBottomRight(bottomRight);
100 99 layout.append(rect.normalized());
@@ -138,18 +138,29 void LogXLogYDomain::move(qreal dx, qreal dy)
138 138
139 139 QPointF LogXLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
140 140 {
141 const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX);
142 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
143 qreal x(0);
144 qreal y(0);
141 145 if (point.x() > 0 && point.y() > 0) {
142 const qreal deltaX = m_size.width() / qAbs(m_logRightX - m_logLeftX);
143 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
144 qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
145 qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
146 x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
147 y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
146 148 ok = true;
147 return QPointF(x, y);
148 149 } else {
149 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
150 qWarning() << "Logarithms of zero and negative values are undefined.";
150 151 ok = false;
151 return QPointF();
152 if (point.x() > 0)
153 x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
154 else
155 x = 0;
156 if (point.y() > 0) {
157 y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY
158 + m_size.height();
159 } else {
160 y = m_size.height();
161 }
152 162 }
163 return QPointF(x, y);
153 164 }
154 165
155 166 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
@@ -167,7 +178,7 QVector<QPointF> LogXLogYDomain::calculateGeometryPoints(const QList<QPointF> &v
167 178 result[i].setX(x);
168 179 result[i].setY(y);
169 180 } else {
170 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
181 qWarning() << "Logarithms of zero and negative values are undefined.";
171 182 return QVector<QPointF>();
172 183 }
173 184 }
@@ -131,20 +131,20 void LogXYDomain::move(qreal dx, qreal dy)
131 131
132 132 QPointF LogXYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
133 133 {
134 const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX);
135 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
134 136
137 qreal x(0);
138 qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
135 139 if (point.x() > 0) {
136 const qreal deltaX = m_size.width() / (m_logRightX - m_logLeftX);
137 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
138
139 qreal x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
140 qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
140 x = (log10(point.x()) / log10(m_logBaseX)) * deltaX - m_logLeftX * deltaX;
141 141 ok = true;
142 return QPointF(x, y);
143 142 } else {
144 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
143 x = 0;
144 qWarning() << "Logarithms of zero and negative values are undefined.";
145 145 ok = false;
146 return QPointF();
147 146 }
147 return QPointF(x, y);
148 148 }
149 149
150 150 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
@@ -162,9 +162,10 QVector<QPointF> LogXYDomain::calculateGeometryPoints(const QList<QPointF> &vect
162 162 result[i].setX(x);
163 163 result[i].setY(y);
164 164 } else {
165 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
165 qWarning() << "Logarithms of zero and negative values are undefined.";
166 166 return QVector<QPointF>();
167 167 }
168
168 169 }
169 170 return result;
170 171 }
@@ -131,19 +131,20 void XLogYDomain::move(qreal dx, qreal dy)
131 131
132 132 QPointF XLogYDomain::calculateGeometryPoint(const QPointF &point, bool &ok) const
133 133 {
134 if (point.y() > 0) {
135 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
136 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
134 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
135 const qreal deltaY = m_size.height() / qAbs(m_logRightY - m_logLeftY);
137 136
138 qreal x = (point.x() - m_minX) * deltaX;
139 qreal y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
137 qreal x = (point.x() - m_minX) * deltaX;
138 qreal y(0);
139 if (point.y() > 0) {
140 y = (log10(point.y()) / log10(m_logBaseY)) * -deltaY - m_logLeftY * -deltaY + m_size.height();
140 141 ok = true;
141 return QPointF(x, y);
142 142 } else {
143 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
143 y = m_size.height();
144 qWarning() << "Logarithms of zero and negative values are undefined.";
144 145 ok = false;
145 return QPointF();
146 146 }
147 return QPointF(x, y);
147 148 }
148 149
149 150 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF> &vector) const
@@ -161,7 +162,7 QVector<QPointF> XLogYDomain::calculateGeometryPoints(const QList<QPointF> &vect
161 162 result[i].setX(x);
162 163 result[i].setY(y);
163 164 } else {
164 qWarning() << "Logarithm of negative value is undefined. Empty layout returned.";
165 qWarning() << "Logarithms of zero and negative values are undefined.";
165 166 return QVector<QPointF>();
166 167 }
167 168 }
General Comments 0
You need to be logged in to leave comments. Login now