Mercurial > hg > svgui
diff layer/TimeValueLayer.cpp @ 665:ab9fefdaa103
Make scale drawing in log scale a bit less dumb
author | Chris Cannam |
---|---|
date | Tue, 16 Jul 2013 13:38:53 +0100 |
parents | 62330d542e1d |
children | d52751e2728b |
line wrap: on
line diff
--- a/layer/TimeValueLayer.cpp Tue Jul 16 13:22:31 2013 +0100 +++ b/layer/TimeValueLayer.cpp Tue Jul 16 13:38:53 2013 +0100 @@ -1263,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 } @@ -1303,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); }