[Kst] [Bug 94232] Time increment value is sometimes 'strange'

netterfield at astro.utoronto.ca netterfield at astro.utoronto.ca
Fri Dec 10 03:30:16 CET 2004


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
        
http://bugs.kde.org/show_bug.cgi?id=94232        
netterfield astro utoronto ca changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From netterfield astro utoronto ca  2004-12-10 03:30 -------
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);



More information about the Kst mailing list