diff layer/TimeValueLayer.cpp @ 669:123ebecd12e6 tonioni

Merge from default branch
author Chris Cannam
date Tue, 16 Jul 2013 14:45:55 +0100
parents ab9fefdaa103
children d52751e2728b
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp	Fri Jul 12 13:25:22 2013 +0100
+++ b/layer/TimeValueLayer.cpp	Tue Jul 16 14:45:55 2013 +0100
@@ -746,13 +746,18 @@
     max = 0.0;
     log = false;
 
+    bool haveAutoAlignment = false;
+
     if (shouldAutoAlign()) {
 
         if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) {
             min = m_model->getValueMinimum();
             max = m_model->getValueMaximum();
-        } else if (log) {
-            LogRange::mapRange(min, max);
+        } else {
+            haveAutoAlignment = true;
+            if (log) {
+                LogRange::mapRange(min, max);
+            }
         }
 
     } else if (m_verticalScale == PlusMinusOneScale) {
@@ -774,18 +779,21 @@
     std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl;
 #endif
 
-    if (max == min) {
-        max = max + 0.5;
-        min = min - 0.5;
-    } else {
-        float margin = (max - min) / 10.0;
-        max = max + margin;
-        min = min - margin;
-    }
+    if (!haveAutoAlignment) {
+
+        if (max == min) {
+            max = max + 0.5;
+            min = min - 0.5;
+        } else {
+            float margin = (max - min) / 10.0;
+            max = max + margin;
+            min = min - margin;
+        }
 
 #ifdef DEBUG_TIME_VALUE_LAYER
-    std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl;
+        std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl;
 #endif
+    }
 }
 
 int
@@ -1255,7 +1263,7 @@
         if (prec < 0) dp = -prec;
         round = powf(10.f, prec);
 #ifdef DEBUG_TIME_VALUE_LAYER
-        std::cerr << "inc = " << inc << ", round = " << round << std::endl;
+        std::cerr << "inc = " << inc << ", round = " << round << ", dp = " << dp << std::endl;
 #endif
     }
 
@@ -1295,7 +1303,11 @@
         }
 
         if (logarithmic) {
-            sprintf(buffer, "%.*g", dp < 2 ? 2 : dp, LogRange::unmap(dispval));
+            double dv = LogRange::unmap(dispval);
+            int digits = trunc(log10f(dv));
+            int sf = dp + (digits > 0 ? digits : 0);
+            if (sf < 2) sf = 2;
+            sprintf(buffer, "%.*g", sf, dv);
         } else {
             sprintf(buffer, "%.*f", dp, dispval);
         }