Bug 94232 - Time increment value is sometimes 'strange'
Summary: Time increment value is sometimes 'strange'
Status: RESOLVED FIXED
Alias: None
Product: kst
Classification: Applications
Component: general (show other bugs)
Version: 1.0.0
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: kst
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-01 19:52 UTC by Matthew Truch
Modified: 2004-12-10 03:30 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-12-01 19:52:46 UTC
Version:           1.0.0 (using KDE KDE 3.3.1)
Installed from:    Compiled From Sources
OS:                Linux

When one of the axes is interpreted as a time, the increment should not follow the standard possible values (1, 2, 4, 5?), but by something that makes sense for that time unit (maybe 1, 2, 5, 10, 15, 30 for seconds and minutes, and 1, 2, 6, 12 for hours etc).  It doesn't make sense to have seconds increment by 50, or hours by 20.
Comment 1 Netterfield 2004-12-10 03:30:13 UTC
CVS commit by netterfield: 

BUG: 94232
Make tick intervals special for hours, minutes, and seconds....


  M +54 -12    kst2dplot.cpp   1.307
  M +1 -1      kst2dplot.h   1.127


--- kdeextragear-2/kst/kst/kst2dplot.cpp  #1.306:1.307
@@ -70,7 +70,4 @@
 #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));
@@ -1517,4 +1514,5 @@ void Kst2DPlot::genAxisTickLabels(QPaint
   int iShort = 0;
   int i;
+  int base = 10;
 
   if (isX && _isXAxisInterpreted) {
@@ -1563,9 +1561,12 @@ void Kst2DPlot::genAxisTickLabels(QPaint
           scale /= 60.0 * 60.0;
           strUnits  = i18n("hours");
+          base = 24;
         } else if( range > 10.0 * 60.0 ) {
           scale /= 60.0;
           strUnits  = i18n("minutes");
+          base = 60;
         } else {
           strUnits  = i18n("seconds");
+          base = 60;
         }
         break;
@@ -1590,5 +1591,5 @@ void Kst2DPlot::genAxisTickLabels(QPaint
   tp.delta = false;
 
-  setTicks(tp.tick, tp.org, Max*scale, Min*scale, bLog, isX);
+  setTicks(tp.tick, tp.org, Max*scale, Min*scale, bLog, isX, base);
   tp.tick /= scale;
   tp.org  /= scale;
@@ -2446,9 +2447,30 @@ void Kst2DPlot::GenerateDefaultLabels() 
 
 void Kst2DPlot::setTicks(double& tick, double& org,
-                       double max, double min, bool is_log, bool isX) {
+                         double max, double min, bool is_log, bool isX,
+                         int base) {
   double St = 0.0;
   double Exp;
-  int auto_tick = 5;
+  int auto_tick;
   int majorDensity = isX ? _xMajorTicks : _yMajorTicks;
+  double *ticks;
+  int *autominor;
+  int nt;
+
+  static double b10_ticks[] = {1.0, 2.0, 5.0, 10.0};
+  static int b10_autominor[]= {  5,   4,   5,  5};
+  static int n_b10_ticks = sizeof(b10_ticks) / sizeof(double);
+  static double b24_ticks[] = {1.0, 2.0, 4.0, 6.0, 12.0, 24.0};
+  static int b24_autominor[]= {  5,   4,   4,   6,    6,  6};
+  static int n_b24_ticks = sizeof(b24_ticks) / sizeof(double);
+  static double b60_ticks[] = 
+    {1.0, 2.0, 5.0, 10.0, 15.0, 20.0, 30.0, 60.0};
+  static int b60_autominor[] =
+    {  5,   4,   5,    5,    3,    4,    6,    6};
+
+  static int n_b60_ticks = sizeof(b60_ticks) / sizeof(double);
+
+  ticks = b10_ticks;
+  nt = n_b10_ticks;
+  autominor = b10_autominor;
 
   //
@@ -2477,5 +2499,5 @@ void Kst2DPlot::setTicks(double& tick, d
 
       tick = ticks[0] * Exp;
-      for (int i=1; i<iNumTicks; i++) {
+      for (int i=1; i<nt; i++) {
         if (fabs((ticks[i] * Exp) - St) < fabs(tick - St)) {
           tick = ticks[i] * Exp;
@@ -2487,15 +2509,35 @@ void Kst2DPlot::setTicks(double& tick, d
     // determine tick interval...
     //
+    Exp = 0;
+    if (base == 60) {
+      if ((b60_ticks[0]*0.7<St) && 
+          (b60_ticks[n_b60_ticks-1]>St*0.7)) {
+        Exp = 1.0;
+        ticks = b60_ticks;
+        autominor = b60_autominor;
+        nt = n_b60_ticks;
+      }
+    } else if (base == 24) {
+      if ((b24_ticks[0]*0.7<St) && 
+          (b24_ticks[n_b24_ticks-1]>St*0.7)) {
+        Exp = 1.0;
+        ticks = b24_ticks;
+        autominor = b24_autominor;
+        nt = n_b24_ticks;
+      }
+    } 
+
+    if (Exp<0.5) {
     Exp = pow(10.0, floor(log10(St)));
+    }
 
     tick = ticks[0] * Exp;
-    for (int i=1; i<iNumTicks; i++) {
+    auto_tick = autominor[0];
+    for (int i=1; i<nt; i++) {
       if (fabs((ticks[i] * Exp) - St) < fabs(tick - St)) {
         tick = ticks[i] * Exp;
+        auto_tick = autominor[i];
       }
     }
-    if (tick == 2.0*Exp || tick == 4.0*Exp) {
-      auto_tick = 4;
-    }
   }
 

--- kdeextragear-2/kst/kst/kst2dplot.h  #1.126:1.127
@@ -359,5 +359,5 @@ private:
                          QPainter& p, bool& bOffsetX, bool& bOffsetY);
   void setTicks(double& tick, double& org,
-                double max, double min, bool is_log, bool isX);
+                double max, double min, bool is_log, bool isX, int base);
   double convertTimeValueToJD(double valueIn);
   double convertTimeDiffValueToDays(double diffIn);