[Kst] kdeextragear-2/kst/kst

Andrew Walker arwalker at sumusltd.com
Fri Sep 3 22:08:08 CEST 2004


CVS commit by arwalker: 

Remember the auto-tick value for the y-axis hysteresis.


  M +30 -18    kst2dplot.cpp   1.260
  M +1 -0      kst2dplot.h   1.107


--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.259:1.260
@@ -42,5 +42,5 @@
 
 #define MAX_NUM_POLYLINES       1000
-#define TICK_HYSTERESIS_FACTOR  2.0
+#define TICK_HYSTERESIS_FACTOR  1.25
 #define DIFFERENCE_PRECISION    7
 #define LABEL_PRECISION         9
@@ -54,4 +54,7 @@
 #endif
 
+static double ticks[] = {1.0, 2.0, 4.0, 5.0, 10.0};
+static int iNumTicks = sizeof( ticks ) / sizeof( double );
+
 inline int d2i(double x) {
   return int(floor(x+0.5));
@@ -1893,6 +1896,6 @@ void Kst2DPlot::GenerateDefaultLabels() 
 void Kst2DPlot::setTicks(double& tick, double& org,
                        double max, double min, bool is_log, bool isX) {
-  double St=0.0;
-  double Exp,Mant1,Mant2;  // used to generate tick interval
+  double St = 0.0;
+  double Exp;
   int auto_tick = 5;
   int majorDensity = isX ? _xMajorTicks : _yMajorTicks;
@@ -1906,11 +1909,26 @@ void Kst2DPlot::setTicks(double& tick, d
     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) {
+
+    //
+    // check for hysteresis of y-axis tick spacing...
+    //
+    if (!isX && is_log == _isLogLast && _stLast != 0.0 &&
+        St/_stLast < TICK_HYSTERESIS_FACTOR &&
+        St/_stLast > 1.0/TICK_HYSTERESIS_FACTOR) {
+      St = _stLast;
+      tick = _tickYLast;
+      auto_tick = _autoTickYLast;
+    } else {
+      tick = ticks[0] * Exp;
+      for (int i=1; i<iNumTicks; i++) {
+        if (fabs((ticks[i] * Exp) - St) < fabs(tick - St)) {
+          tick = ticks[i] * Exp;
+        }
+      }
+      if (tick == 2.0*Exp || tick == 4.0*Exp) {
       auto_tick = 4;
     }
   }
+  }
 
   if (is_log) {
@@ -1928,14 +1946,7 @@ 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) {
-        St = _stLast;
-        tick = _tickYLast;
-      }
-    }
-  }
-  
-  /* Determine Location of Origin */
+  //
+  // determine location of the origin...
+  //
   if (min > 0.0) {
     org = ceil(min / tick) * tick;
@@ -1949,4 +1960,5 @@ void Kst2DPlot::setTicks(double& tick, d
     _stLast    = St;
     _tickYLast = tick;
+    _autoTickYLast = auto_tick;
     _isLogLast = is_log;
   }                   

--- kdeextragear-2/kst/kst/kst2dplot.h  #1.106:1.107
@@ -365,4 +365,5 @@ private:
   double _m_X, _b_X, _m_Y, _b_Y;
   double _tickYLast, _stLast;
+  int _autoTickYLast;
   bool _isLogLast;
   





More information about the Kst mailing list