##// END OF EJS Templates
Reimplement zoom/scroll hanling for barcategoryaxis Y
Michal Klocek -
r2145:2a67480b6cc7
parent child
Show More
@@ -20,6 +20,12 SOURCES += \
20 axis/barcategoryaxisy.cpp \
20 axis/barcategoryaxisy.cpp \
21 axis/datetimeaxisx.cpp \
21 axis/datetimeaxisx.cpp \
22 axis/datetimeaxisy.cpp \
22 axis/datetimeaxisy.cpp \
23 axis/valueaxis2.cpp \
24 axis/categoryaxis2.cpp \
25 axis/barcategoryaxisx2.cpp \
26 axis/barcategoryaxisy2.cpp \
27 axis/datetimeaxisx2.cpp \
28 axis/datetimeaxisy2.cpp \
23 multiaxis/multivalueaxis.cpp \
29 multiaxis/multivalueaxis.cpp \
24 multiaxis/multivalueaxis2.cpp \
30 multiaxis/multivalueaxis2.cpp \
25 multiaxis/multivalueaxis3.cpp \
31 multiaxis/multivalueaxis3.cpp \
@@ -41,27 +41,22 ChartBarCategoryAxisX::~ChartBarCategoryAxisX()
41 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const
41 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const
42 {
42 {
43 QVector<qreal> points;
43 QVector<qreal> points;
44
45 const QRectF& gridRect = gridGeometry();
44 const QRectF& gridRect = gridGeometry();
46 qreal range = max() - min();
45 qreal range = max() - min();
47
48 const qreal delta = gridRect.width()/range;
46 const qreal delta = gridRect.width()/range;
49
47
50 if(delta<2) return points;
48 if(delta<2) return points;
51
49
52 qreal offset =-min()-0.5;
50 qreal offset =-min()-0.5;
53
54 offset = int(offset * delta)%int(delta);
51 offset = int(offset * delta)%int(delta);
55
52
56 int count = qFloor(range);
53 int count = qFloor(range);
57
58 if(count < 1 ) return points;
54 if(count < 1 ) return points;
59
55
60 points.resize(count+2);
56 points.resize(count+2);
61
57
62 for (int i = 0; i < count+2; ++i) {
58 for (int i = 0; i < count+2; ++i) {
63 qreal x = offset + i * delta + gridRect.left();
59 points[i] = offset + i * delta + gridRect.left();
64 points[i] = x;
65 }
60 }
66
61
67 return points;
62 return points;
@@ -71,8 +66,8 QStringList ChartBarCategoryAxisX::createCategoryLabels(const QVector<qreal>& la
71 {
66 {
72 QStringList result ;
67 QStringList result ;
73 const QRectF &gridRect = gridGeometry();
68 const QRectF &gridRect = gridGeometry();
74
75 qreal d = (max() - min()) / gridRect.width();
69 qreal d = (max() - min()) / gridRect.width();
70
76 for (int i = 0; i < layout.count() - 1; ++i) {
71 for (int i = 0; i < layout.count() - 1; ++i) {
77 qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5));
72 qreal x = qFloor((((layout[i] + layout[i + 1]) / 2 - gridRect.left()) * d + min() + 0.5));
78 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
73 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
@@ -39,30 +39,25 ChartBarCategoryAxisY::~ChartBarCategoryAxisY()
39
39
40 QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const
40 QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const
41 {
41 {
42 int count = m_categoriesAxis->d_ptr->count();
43
44 Q_ASSERT(count >= 1);
45
46 QVector<qreal> points;
42 QVector<qreal> points;
47 points.resize(count + 2);
48
49 const QRectF &gridRect = gridGeometry();
43 const QRectF& gridRect = gridGeometry();
44 qreal range = max() - min();
45 const qreal delta = gridRect.height()/range;
46
47 if(delta<2) return points;
50
48
51 const qreal delta = gridRect.height() / (count);
52 qreal offset = - min() - 0.5;
49 qreal offset = - min() - 0.5;
50 offset = int(offset * delta)%int(delta);
53
51
54 if (delta < 1)
52 int count = qFloor(range);
55 return points;
53 if(count < 1 ) return points;
56
54
57 if (offset < 0)
55 points.resize(count+2);
58 offset = int(offset * gridRect.height() / (max() - min())) % int(delta) + delta;
59 else
60 offset = int(offset * gridRect.height() / (max() - min())) % int(delta);
61
56
62 for (int i = -1; i < count + 1; ++i) {
57 for (int i = 0; i < count+2; ++i) {
63 int y = gridRect.bottom() - i * delta - offset;
58 points[i] = gridRect.bottom() - i * delta -offset;
64 points[i + 1] = y;
65 }
59 }
60
66 return points;
61 return points;
67 }
62 }
68
63
@@ -71,6 +66,7 QStringList ChartBarCategoryAxisY::createCategoryLabels(const QVector<qreal>& la
71 QStringList result;
66 QStringList result;
72 const QRectF &gridRect = gridGeometry();
67 const QRectF &gridRect = gridGeometry();
73 qreal d = (max() - min()) / gridRect.height();
68 qreal d = (max() - min()) / gridRect.height();
69
74 for (int i = 0; i < layout.count() - 1; ++i) {
70 for (int i = 0; i < layout.count() - 1; ++i) {
75 qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5));
71 qreal x = qFloor(((gridRect.height() - (layout[i + 1] + layout[i]) / 2 + gridRect.top()) * d + min() + 0.5));
76 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
72 if ((x < m_categoriesAxis->categories().count()) && (x >= 0)) {
@@ -82,10 +82,10 void HorizontalAxis::updateGeometry()
82 //wrapping in case of interval axis
82 //wrapping in case of interval axis
83 const qreal delta = layout[i+1] - layout[i];
83 const qreal delta = layout[i+1] - layout[i];
84 QString text = labelList.at(i);
84 QString text = labelList.at(i);
85 if (fn.boundingRect(text).width() > delta )
85 if (fn.boundingRect(text).width() + 1 > delta )
86 {
86 {
87 QString label = text + "...";
87 QString label = text + "...";
88 while (fn.boundingRect(label).width() > delta && label.length() > 3)
88 while (fn.boundingRect(label).width() >= delta && label.length() > 3)
89 label.remove(label.length() - 4, 1);
89 label.remove(label.length() - 4, 1);
90 labelItem->setText(label);
90 labelItem->setText(label);
91 }
91 }
@@ -117,12 +117,11 void HorizontalAxis::updateGeometry()
117 }
117 }
118
118
119 //label overlap detection
119 //label overlap detection
120 if(labelItem->pos().x() <= width ||
120 if(labelItem->pos().x() < width ||
121 labelItem->pos().x() < axisRect.left() ||
121 labelItem->pos().x() < axisRect.left() ||
122 labelItem->pos().x() + rect.width() > axisRect.right()) {
122 labelItem->pos().x() + rect.width() > axisRect.right()) {
123 labelItem->setVisible(false);
123 labelItem->setVisible(false);
124 }
124 } else {
125 else {
126 labelItem->setVisible(true);
125 labelItem->setVisible(true);
127 width=rect.width()+labelItem->pos().x();
126 width=rect.width()+labelItem->pos().x();
128 }
127 }
General Comments 0
You need to be logged in to leave comments. Login now