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