[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Wed Jan 21 20:25:13 CET 2009
SVN commit 914791 by fenton:
Add clipping of PlotAxis labels instead of omitting.
Add Tick Debugging Mode
Fix rounding bug for PlotAxis numbers.
Enforce minimum of 2 Major Plot Ticks.
M +41 -9 plotaxis.cpp
M +8 -6 plotitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #914790:914791
@@ -15,6 +15,8 @@
#include "settings.h"
#include <QDate>
+#define MAJOR_TICK_DEBUG 0
+
static int FULL_PRECISION = 15;
static qreal JD1900 = 2415020.5;
static qreal JD1970 = 2440587.5;
@@ -671,6 +673,10 @@
qreal majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation);
qreal firstTick = ceil(min / majorTickSpacing) * majorTickSpacing;
+#if MAJOR_TICK_DEBUG
+ qDebug() << "Major Ticks spacing:" << majorTickSpacing << "\nFirst Tick" << firstTick;
+#endif
+
int i = 0;
qreal nextTick = firstTick;
while (1) {
@@ -752,6 +758,17 @@
} else {
_axisLabels = labels;
}
+#if MAJOR_TICK_DEBUG
+ qDebug() << "Calculated Major Ticks:" << _axisMajorTicks;
+ if (_orientation == Qt::Horizontal) {
+ qDebug() << "Horizontal";
+ } else {
+ qDebug() << "Vertical";
+ }
+ qDebug() << "\nLabels:" << _axisLabels
+ << "\nbase Label:" << _baseLabel
+ << endl;
+#endif
}
@@ -773,11 +790,11 @@
qreal d2 = 2 * pow(10, B);
qreal d5 = 5 * pow(10, B);
- qreal r1 = d1 * M - 1;
- qreal r2 = d2 * M - 1;
- qreal r5 = d5 * M - 1;
+ qreal r1 = d1 * M;
+ qreal r2 = d2 * M;
+ qreal r5 = d5 * M;
-#ifdef MAJOR_TICK_DEBUG
+#if MAJOR_TICK_DEBUG
qDebug() << "MajorTickMode:" << M << "Range:" << R
<< "\n\tranges:" << r1 << r2 << r5
<< "\n\tspaces:" << d1 << d2 << d5
@@ -788,12 +805,27 @@
qreal s2 = qAbs(r2 - R);
qreal s5 = qAbs(r5 - R);
- if (s1 < s2 && s1 < s5)
+ if (s1 <= s2 && s1 <= s5) {
return d1;
- else if (s2 < s5)
- return d2;
- else
- return d5;
+ } else if (s2 <= s5) {
+ if ((M == 2) && (r2 > R)) {
+#if MAJOR_TICK_DEBUG
+ qDebug() << "Minimum ticks not met using d2 using d1 instead";
+#endif
+ return d1;
+ } else {
+ return d2;
+ }
+ } else {
+ if ((M == 2) && (r5 > R)) {
+#if MAJOR_TICK_DEBUG
+ qDebug() << "Minimum ticks not met using d5 using d2 instead";
+#endif
+ return d2;
+ } else {
+ return d5;
+ }
+ }
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #914790:914791
@@ -728,9 +728,10 @@
xLabelRect = bound;
}
- if ((rect().left() < bound.left()) && (rect().right() > bound.right())) {
- painter->drawText(bound, flags, xLabelIt.value());
- }
+ if (rect().left() > bound.left()) bound.setLeft(rect().left());
+ if (rect().right() < bound.right()) bound.setRight(rect().right());
+
+ painter->drawText(bound, flags, xLabelIt.value());
}
if (!_xAxis->baseLabel().isEmpty()) {
@@ -781,9 +782,10 @@
yLabelRect = bound;
}
- if ((rect().top() < bound.top()) && (rect().bottom() > bound.bottom())) {
- painter->drawText(bound, flags, yLabelIt.value());
- }
+ if (rect().top() > bound.top()) bound.setTop(rect().top());
+ if (rect().bottom() < bound.bottom()) bound.setBottom(rect().bottom());
+
+ painter->drawText(bound, flags, yLabelIt.value());
}
if (!_yAxis->baseLabel().isEmpty()) {
More information about the Kst
mailing list