[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Fri Sep 3 19:16:18 CEST 2004


CVS commit by arwalker: 

Provide some hysteresis in the tick seperation. This is designed only to solve the problem of the y-axis tick spacing jumping in value following a small change in the max-min difference of the curve. For other scenarios, where the difference change is more extreme, a fixed scale should be set by the user.

CCMAIL: 88337-done at bugs.kde.org


  M +32 -13    kst2dplot.cpp   1.258
  M +3 -1      kst2dplot.h   1.106


--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.257:1.258
@@ -42,4 +42,5 @@
 
 #define MAX_NUM_POLYLINES     1000
+#define TICK_HYSTERESIS_FACTOR  2.0
 #define DIFFERENCE_PRECISION  7
 #define LABEL_PRECISION       9
@@ -325,4 +326,6 @@ void Kst2DPlot::commonConstructor(const 
   _xLog = x_log;
   _yLog = y_log;
+  _tickYLast = 0.0;
+  _stLast = 0.0;
 
   setTagName(in_tag);
@@ -1890,6 +1893,6 @@ void Kst2DPlot::GenerateDefaultLabels() 
 void Kst2DPlot::setTicks(double& tick, double& org,
                        double max, double min, bool is_log, bool isX) {
-  double St,Mant1,Mant2;  // used to generate tick interval
-  double Exp,Log,FLog;    // used to generate tick interval
+  double St=0.0;
+  double Exp,Mant1,Mant2;  // used to generate tick interval
   int auto_tick = 5;
   int majorDensity = isX ? _xMajorTicks : _yMajorTicks;
@@ -1898,13 +1901,15 @@ void Kst2DPlot::setTicks(double& tick, d
     tick = 1.0;
   } else {
-    /* Determine tick Interval */
-    St = (max - min) / (double)majorDensity;       /* ticks */
-    Log = log10(St);
-    FLog = floor(Log);
-    Exp = pow(10.0, FLog);
+    //
+    // determine tick interval...
+    //
+    St = (max - min) / (double)majorDensity;
+    Exp = pow(10.0, floor(log10(St)));
     Mant1 = fabs(Exp - St) < fabs(2.0 * Exp - St) ? Exp : 2.0 * Exp;
     Mant2 = fabs(5.0 * Exp - St) < fabs(10.0 * Exp - St) ? 5.0 * Exp : 10.0 * Exp;
     tick = fabs(Mant1 - St) < fabs(Mant2 - St) ? Mant1 : Mant2;
-    if (tick==2.0*Exp) auto_tick=4;
+    if (tick == 2.0*Exp) {
+      auto_tick = 4;
+    }
   }
 
@@ -1923,4 +1928,12 @@ void Kst2DPlot::setTicks(double& tick, d
   }
 
+  if (!isX && St != 0.0) {
+    if (is_log == _isLogLast && _stLast != 0.0) {
+      if (St/_stLast < TICK_HYSTERESIS_FACTOR && St/_stLast > 1.0/TICK_HYSTERESIS_FACTOR) {
+        tick = _tickYLast;
+      }
+    }
+  }
+  
   /* Determine Location of Origin */
   if (min > 0.0) {
@@ -1931,4 +1944,10 @@ void Kst2DPlot::setTicks(double& tick, d
     org = 0.0;
   }
+
+  if (!isX) {
+    _stLast    = St;
+    _tickYLast = tick;
+    _isLogLast = is_log;
+  }                   
 }
 

--- kdeextragear-2/kst/kst/kst2dplot.h  #1.105:1.106
@@ -364,4 +364,6 @@ private:
   QRect _oldAlignment;
   double _m_X, _b_X, _m_Y, _b_Y;
+  double _tickYLast, _stLast;
+  bool _isLogLast;
 
   //the list of more than one image





More information about the Kst mailing list