##// END OF EJS Templates
Small refactor, adds subDomain to plotDomain
Michal Klocek -
r76:522426b793d2
parent child
Show More
@@ -28,4 +28,18 qreal PlotDomain::spanY() const
28 return m_maxY - m_minY;
28 return m_maxY - m_minY;
29 }
29 }
30
30
31 PlotDomain PlotDomain::subDomain(const QRect& rect, qreal maxWidth,qreal maxHeight) const
32 {
33 PlotDomain domain;
34
35 qreal dx = spanX() / maxWidth;
36 qreal dy = spanY() / maxHeight;
37
38 domain.m_minX = m_minX + dx * rect.left();
39 domain.m_maxX = m_minX + dx * rect.right();
40 domain.m_minY = m_maxY - dy * rect.bottom();
41 domain.m_maxY = m_maxY - dy * rect.top();
42
43 return domain;
44 }
31 QTCOMMERCIALCHART_END_NAMESPACE
45 QTCOMMERCIALCHART_END_NAMESPACE
@@ -13,6 +13,9 public:
13 qreal spanX() const;
13 qreal spanX() const;
14 qreal spanY() const;
14 qreal spanY() const;
15
15
16 PlotDomain subDomain(const QRect& rect, qreal maxWidth, qreal maxHeight) const;
17
18
16 public:
19 public:
17 qreal m_minX;
20 qreal m_minX;
18 qreal m_maxX;
21 qreal m_maxX;
@@ -269,18 +269,11 void QChart::zoomInToRect(const QRect& rectangle)
269 rect.translate(-margin, -margin);
269 rect.translate(-margin, -margin);
270
270
271 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
271 PlotDomain& oldDomain = m_plotDomainList[m_plotDataIndex];
272 PlotDomain newDomain;
273
272
274 qreal dx = oldDomain.spanX() / (m_rect.width() - 2 * margin);
273 PlotDomain domain = oldDomain.subDomain(rect,m_rect.width() - 2 * margin,m_rect.height() - 2 * margin);
275 qreal dy = oldDomain.spanY() / (m_rect.height() - 2 * margin);
276
277 newDomain.m_minX = oldDomain.m_minX + dx * rect.left();
278 newDomain.m_maxX = oldDomain.m_minX + dx * rect.right();
279 newDomain.m_minY = oldDomain.m_maxY - dy * rect.bottom();
280 newDomain.m_maxY = oldDomain.m_maxY - dy * rect.top();
281
274
282 m_plotDomainList.resize(m_plotDataIndex + 1);
275 m_plotDomainList.resize(m_plotDataIndex + 1);
283 m_plotDomainList<<newDomain;
276 m_plotDomainList<<domain;
284 m_plotDataIndex++;
277 m_plotDataIndex++;
285
278
286 foreach (ChartItem* item ,m_chartItems)
279 foreach (ChartItem* item ,m_chartItems)
General Comments 0
You need to be logged in to leave comments. Login now