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

Mike Fenton mike at staikos.net
Wed Jun 24 20:29:02 CEST 2009


SVN commit 986540 by fenton:

Prevent too many ticks being drawn when limiting the ticks due to label size constraints.


 M  +14 -3     plotaxis.cpp  
 M  +1 -1      plotaxis.h  


--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #986539:986540
@@ -800,7 +800,12 @@
   } 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);
+    qreal majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation, false);
+
+    if (useOverrideTicks && (((max - min) / majorTickSpacing) > majorTickCount)) {
+      majorTickSpacing = computedMajorTickSpacing(majorTickCount, _orientation, true);
+    }
+
     qreal firstTick = ceil(min / majorTickSpacing) * majorTickSpacing;
 
 #if MAJOR_TICK_DEBUG 
@@ -933,10 +938,15 @@
  * 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) {
+qreal PlotAxis::computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation, bool maxTicks) {
   qreal R = orientation == Qt::Horizontal ? plotItem()->projectionRect().width() : plotItem()->projectionRect().height();
   qreal M = majorTickCount;
-  qreal B = floor(log10(R/M));
+  qreal B;
+  if (maxTicks) {
+    B = ceil(log10(R/M));
+  } else {
+    B = floor(log10(R/M));
+  }
 
   qreal d1 = 1 * pow(10, B);
   qreal d2 = 2 * pow(10, B);
@@ -950,6 +960,7 @@
   qDebug() << "MajorTickMode:" << M << "Range:" << R
            << "\n\tranges:" << r1 << r2 << r5
            << "\n\tspaces:" << d1 << d2 << d5
+           << "\n\tmax tick mode:" << maxTicks
            << endl;
 #endif
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.h #986539:986540
@@ -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);
+    qreal computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation, bool maxTicks);
     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