Bug 88337 - hysteresis for tick density would be nice
Summary: hysteresis for tick density would be nice
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.x
Platform: RedHat Enterprise Linux Linux
: NOR wishlist
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-28 21:16 UTC by Matthew Truch
Modified: 2004-09-03 19:16 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Truch 2004-08-28 21:16:37 UTC
Version:           1.0.0_devel (using KDE KDE 3.2.2)
Installed from:    RedHat RPMs
OS:                Linux

When looking at live data which is changing and/or noisy, the tick density code can get in a situtation where it will alternate between one or another tick separation value.  I have seen some cases where this change occurs almost every update, which makes it very hard to read the scale and determine what value places are on the plot (visually).  It would be very nice if there was a hysteresis in the tick separation, so that this effect could be minimized.
Comment 1 Andrew Walker 2004-09-03 19:16:23 UTC
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@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