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

Barth Netterfield netterfield at astro.utoronto.ca
Fri Jul 17 19:19:28 CEST 2009


SVN commit 998454 by netterfield:

Report a new bug (a crash case...)
Update bugs.
Fix axis label round-off errors
Fix tick count reduction (to avoid overlap).
Fix tick scaling/position (to avoid overlap).



 M  +7 -1      devel-docs/Kst2Specs/Bugs  
 M  +5 -1      devel-docs/Kst2Specs/FixedBugs  
 M  +32 -15    src/libkstapp/plotaxis.cpp  
 M  +4 -1      src/libkstapp/plotaxis.h  
 M  +6 -3      src/libkstapp/plotitem.cpp  


--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/Bugs #998453:998454
@@ -1,5 +1,11 @@
+Crash Case: crash second time opening config dialog.
+Start kst.
+Open the configuration dialog (settings->configure kst), close it, then open it again.
+Crash!
+
+---------
+
 Rounding problems in base/offset mode:
-  For extreme cases of base/offset mode there are  rounding errors related to the subtraction of the base.
   Log axis should never go to base offset mode - instead they should use scientific; powers should be relative to 1.
    - LogAxis are now using only two significant digits so that scientific notation is used by default.
 
--- branches/work/kst/portto4/kst/devel-docs/Kst2Specs/FixedBugs #998453:998454
@@ -1001,4 +1001,8 @@
 
 "kst setting dialog" interface to global ASCII options.
 kst can currently read default ascii settings from the kstrc file.
-These settings need to be settable from the kstsettingsdialog.  
\ No newline at end of file
+These settings need to be settable from the kstsettingsdialog.  
+
+---------
+
+For extreme cases of base/offset mode there are  rounding errors related to the subtraction of the base.
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.cpp #998453:998454
@@ -734,9 +734,9 @@
 
   for (int i = 0; i < (labels.count() - 1); i++) {
     if (!labels[i].intersected(labels[i+1]).isEmpty()) {
-
       qreal labelSize;
       qreal plotSize;
+      PlotAxis::MajorTickMode old_override_major_ticks = _axisOverrideMajorTicks;
 
       if (_orientation == Qt::Horizontal) {
         labelSize = qMax(labels[i].boundingRect().width(), labels[i+1].boundingRect().width());
@@ -746,10 +746,10 @@
         plotSize = plotItem()->plotRect().height();
       }
 
-      _axisOverrideMajorTicks = convertToMajorTickMode((plotSize / labelSize) - 1);
+      _axisOverrideMajorTicks = convertToMajorTickMode((plotSize / labelSize) - 1, old_override_major_ticks);
 
       if (_axisOverrideMajorTicks == None) {
-        qreal scale = plotSize / (labelSize * (Coarse + 1));
+        qreal scale = plotSize / (labelSize * (Normal - 1));
         if (scale < 1) {
           plotItem()->scaleAxisLabels(scale);
         }
@@ -761,18 +761,19 @@
     }
   }
   setTicksUpdated();
+
 }
 
 
-PlotAxis::MajorTickMode PlotAxis::convertToMajorTickMode(int tickCount) {
+PlotAxis::MajorTickMode PlotAxis::convertToMajorTickMode(int tickCount, PlotAxis::MajorTickMode old_mode) {
   MajorTickMode mode = None;
-  if (tickCount >= VeryFine) {
+  if ((tickCount >= VeryFine) && (old_mode > VeryFine)) {
     mode = VeryFine;
-  } else if (tickCount >= Fine) {
+  } else if ((tickCount >= Fine) && (old_mode > Fine)) {
     mode = Fine;
-  } else if (tickCount >= Normal) {
+  } else if ((tickCount >= Normal) && (old_mode > Normal)) {
     mode = Normal;
-  } else if (tickCount >= Coarse) {
+  } else if ((tickCount >= Coarse) && (old_mode > Coarse)) {
     mode = Coarse;
   }
   return mode;
@@ -877,6 +878,7 @@
     }
   }
 
+
   // (shortest > 3) so that you don't use automatic base/offset mode when
   // it wouldn't actually take up less space.
   if (_axisBaseOffset || _axisInterpret || ((longest > _axisSignificantDigits)&&(shortest>3)) || _axisBaseOffsetOverride ) {
@@ -892,18 +894,27 @@
       if (_axisInterpret) {
         offset = interpretOffset(_axisInterpretation, _axisDisplay, base, i.key());
       } else {
-        offset = i.key() - base; // FIXME FIX round off error for base/offet mode here
+        offset = i.key() - base;
       }
-      QString label;
+      QString label, num;
       if (offset < 0) {
-        label += "-";
+        label += "-[";
         offset = offset * -1;
       } else if (offset > 0) {
-        label += "+";
+        label += "+[";
       }
-      label += "[";
-      label += QString::number(offset, 'g', _axisSignificantDigits);
-      label += "]";
+
+      if (offset==0.0) {
+        num = "[0";
+      } else if ((fabs(offset)>9.9E3)||(fabs(offset)<0.99E-3)) {
+        num = QString::number(offset, 'e', 1);
+      } else {
+        num = QString::number(offset, 'g', 5);
+      }
+
+      ConvertScientificNotation(num);
+
+      label = label + num + "]";
       _axisLabels.insert(i.key(), label);
     }
   } else {
@@ -1123,6 +1134,12 @@
   return validTag;
 }
 
+void ConvertScientificNotation(QString &num) {
+  //num.replace(QRegExp(".0?[eE][+]0?([1-9]?\\d?)$"), "x10^{\\1}");
+  //num.replace(QRegExp(".0?[eE][-]0?([1-9]?\\d?)$"), "x10^{-\\1}");
 }
 
+
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/plotaxis.h #998453:998454
@@ -19,6 +19,9 @@
 
 namespace Kst {
 
+
+void ConvertScientificNotation(QString &num); // FIXME: should be somewhere else (?)
+
 class PlotAxis : public QObject
 {
   Q_OBJECT
@@ -137,7 +140,7 @@
     qreal computedMajorTickSpacing(MajorTickMode majorTickCount, Qt::Orientation orientation);
     void computeLogTicks(QList<qreal> *MajorTicks, QList<qreal> *MinorTicks, QMap<qreal, QString> *Labels, qreal min, qreal max, MajorTickMode tickMode);
 
-    MajorTickMode convertToMajorTickMode(int tickCount);
+    MajorTickMode convertToMajorTickMode(int tickCount, PlotAxis::MajorTickMode old_mode = VeryFine);
 
   private:
 
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #998453:998454
@@ -1132,18 +1132,21 @@
   painter->setPen(_numberLabelDetails->fontColor());
 
   int rotation = _xAxis->axisLabelRotation();
-
   foreach(CachedPlotLabel label, _xPlotLabels) {
+    QRectF bound = label.bound;
+    if (_numberAxisLabelScaleFactor<0.9999) {
+      bound.translate( bound.width() *(1.0-_numberAxisLabelScaleFactor)*0.5, 0.0);
+    }
     if (rotation != 0) {
       painter->save();
       QTransform t;
       t.rotate(-1*rotation);
       painter->rotate(rotation);
 
-      painter->drawText(t.mapRect(label.bound), flags, label.value);
+      painter->drawText(t.mapRect(bound), flags, label.value);
       painter->restore();
     } else {
-      painter->drawText(label.bound, flags, label.value);
+      painter->drawText(bound, flags, label.value);
     }
   }
   painter->restore();


More information about the Kst mailing list