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