[Kst] branches/work/kst/portto4/kst/src/libkstapp

Mike Fenton mike at staikos.net
Tue Jul 7 21:19:14 CEST 2009


SVN commit 992828 by fenton:

Remove maximum check and replace with minimum check on calculating tick spacing to prevent overlap when reducing the tick count programmatically.


 M  +7 -12     plotaxis.cpp  
 M  +1 -1      plotaxis.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #992827:992828
@@ -800,10 +800,10 @@
   } else {
     qreal min = _orientation == Qt::Horizontal ? plotItem()->projectionRect().left() : plotItem()->projectionRect().top();
     qreal max = _orientation == Qt::Horizontal ? plotItem()->projectionRect().right() : plotItem()->projectionRect().bottom();
-    qreal majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation, false);
+    qreal majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation);
 
     if (useOverrideTicks && (((max - min) / majorTickSpacing) > majorTickCount)) {
-      majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation, true);
+      majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation, false);
     }
 
     qreal firstTick = ceil(min / majorTickSpacing) * majorTickSpacing;
@@ -938,15 +938,10 @@
  * on the axis (but at least 2). The value of M is set by the requested
  * MajorTickMode.
  */
-qreal PlotAxis::computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation, bool maxTicks) {
+qreal PlotAxis::computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation, bool enforceMin) {
   qreal R = orientation == Qt::Horizontal ? plotItem()->projectionRect().width() : plotItem()->projectionRect().height();
   qreal M = majorTickCount;
-  qreal B;
-  if (maxTicks) {
-    B = ceil(log10(R/M));
-  } else {
-    B = floor(log10(R/M));
-  }
+  qreal B = floor(log10(R/M));
 
   qreal d1 = 1 * pow(10, B);
   qreal d2 = 2 * pow(10, B);
@@ -960,7 +955,7 @@
   qDebug() << "MajorTickMode:" << M << "Range:" << R
            << "\n\tranges:" << r1 << r2 << r5
            << "\n\tspaces:" << d1 << d2 << d5
-           << "\n\tmax tick mode:" << maxTicks
+           << "\n\tenforce min tick mode:" << enforceMin
            << endl;
 #endif
 
@@ -972,7 +967,7 @@
   if (s1 <= s2 && s1 <= s5) {
     return d1;
   } else if (s2 <= s5) {
-    if ((M == 2) && (r2 > R)) {
+    if (enforceMin && (M == 2) && (r2 > R)) {
 #if MAJOR_TICK_DEBUG 
       qDebug() << "Minimum ticks not met using d2 using d1 instead";
 #endif
@@ -982,7 +977,7 @@
       return d2;
     }
   } else {
-    if ((M == 2) && (r5 > R)) {
+    if (enforceMin && (M == 2) && (r5 > R)) {
 #if MAJOR_TICK_DEBUG 
       qDebug() << "Minimum ticks not met using d5 using d2 instead";
 #endif
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.h #992827:992828
@@ -134,7 +134,7 @@
     double convertTimeDiffValueToDays(AxisInterpretationType axisInterpretation, double offsetIn);
     double interpretOffset(AxisInterpretationType axisInterpretation, AxisDisplayType axisDisplay, double base, double value);
 
-    qreal computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation, bool maxTicks);
+    qreal computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation, bool enforceMin = true);
     void computeLogTicks(QList<qreal> *MajorTicks, QList<qreal> *MinorTicks, QMap<qreal, QString> *Labels, qreal min, qreal max, MajorTickMode tickMode);
 
     MajorTickMode convertToMajorTickMode(int tickCount);


More information about the Kst mailing list