##// END OF EJS Templates
Fix positioning errors with category ticks...
Miikka Heikkinen -
r2436:da2d1b637d93
parent child
Show More
@@ -45,21 +45,22 QVector<qreal> ChartBarCategoryAxisX::calculateLayout() const
45 QVector<qreal> points;
45 QVector<qreal> points;
46 const QRectF& gridRect = gridGeometry();
46 const QRectF& gridRect = gridGeometry();
47 qreal range = max() - min();
47 qreal range = max() - min();
48 const qreal delta = gridRect.width()/range;
48 const qreal delta = gridRect.width() / range;
49
49
50 if(delta<2) return points;
50 if (delta < 2)
51 return points;
51
52
52 qreal offset =-min()-0.5;
53 qreal adjustedMin = min() + 0.5;
53 offset = int(offset * delta)%int(delta);
54 qreal offset = (ceil(adjustedMin) - adjustedMin) * delta;
54
55
55 int count = qFloor(range);
56 int count = qFloor(range);
56 if(count < 1 ) return points;
57 if (count < 1)
58 return points;
57
59
58 points.resize(count+2);
60 points.resize(count + 2);
59
61
60 for (int i = 0; i < count+2; ++i) {
62 for (int i = 0; i < count + 2; ++i)
61 points[i] = offset + i * delta + gridRect.left();
63 points[i] = offset + (i * delta) + gridRect.left();
62 }
63
64
64 return points;
65 return points;
65 }
66 }
@@ -45,21 +45,22 QVector<qreal> ChartBarCategoryAxisY::calculateLayout() const
45 QVector<qreal> points;
45 QVector<qreal> points;
46 const QRectF& gridRect = gridGeometry();
46 const QRectF& gridRect = gridGeometry();
47 qreal range = max() - min();
47 qreal range = max() - min();
48 const qreal delta = gridRect.height()/range;
48 const qreal delta = gridRect.height() / range;
49
49
50 if(delta<2) return points;
50 if (delta < 2)
51 return points;
51
52
52 qreal offset = - min() - 0.5;
53 qreal adjustedMin = min() + 0.5;
53 offset = int(offset * delta)%int(delta);
54 qreal offset = (ceil(adjustedMin) - adjustedMin) * delta;
54
55
55 int count = qFloor(range);
56 int count = qFloor(range);
56 if(count < 1 ) return points;
57 if (count < 1)
58 return points;
57
59
58 points.resize(count+2);
60 points.resize(count + 2);
59
61
60 for (int i = 0; i < count+2; ++i) {
62 for (int i = 0; i < count + 2; ++i)
61 points[i] = gridRect.bottom() - i * delta -offset;
63 points[i] = gridRect.bottom() - (i * delta) - offset;
62 }
63
64
64 return points;
65 return points;
65 }
66 }
@@ -53,10 +53,10 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
53 qreal scale = gridRect.width() / range;
53 qreal scale = gridRect.width() / range;
54 for (int i = 0; i < tickCount; ++i) {
54 for (int i = 0; i < tickCount; ++i) {
55 if (i < tickCount - 1) {
55 if (i < tickCount - 1) {
56 int x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
56 qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
57 points[i] = x;
57 points[i] = x;
58 } else {
58 } else {
59 int x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
59 qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
60 points[i] = x;
60 points[i] = x;
61 }
61 }
62 }
62 }
@@ -54,10 +54,10 QVector<qreal> ChartCategoryAxisY::calculateLayout() const
54 qreal scale = gridRect.height() / range;
54 qreal scale = gridRect.height() / range;
55 for (int i = 0; i < tickCount; ++i) {
55 for (int i = 0; i < tickCount; ++i) {
56 if (i < tickCount - 1) {
56 if (i < tickCount - 1) {
57 int y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom();
57 qreal y = -(m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.bottom();
58 points[i] = y;
58 points[i] = y;
59 } else {
59 } else {
60 int y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom();
60 qreal y = -(m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.bottom();
61 points[i] = y;
61 points[i] = y;
62 }
62 }
63 }
63 }
General Comments 0
You need to be logged in to leave comments. Login now