# HG changeset patch # User Chris Cannam # Date 1373993536 -3600 # Node ID d52751e2728b3e714b31d7ff17d95035d1e4b706 # Parent 2727bc3aab593fbbab862b960e783ecdd607001d Better handling of padding around scale extents: associate them with the model extents, so as not to break auto-align (of this with other layers, and of other layers with this) and zoom diff -r 2727bc3aab59 -r d52751e2728b layer/TimeValueLayer.cpp --- a/layer/TimeValueLayer.cpp Tue Jul 16 17:51:37 2013 +0100 +++ b/layer/TimeValueLayer.cpp Tue Jul 16 17:52:16 2013 +0100 @@ -320,10 +320,14 @@ bool &logarithmic, QString &unit) const { if (!m_model) return false; + min = m_model->getValueMinimum(); max = m_model->getValueMaximum(); + logarithmic = (m_verticalScale == LogScale); + unit = m_model->getScaleUnits(); + if (m_derivative) { max = std::max(fabsf(min), fabsf(max)); min = -max; @@ -333,6 +337,22 @@ std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl; #endif + if (!shouldAutoAlign() && !logarithmic && !m_derivative) { + + 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::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl; +#endif + } + return true; } @@ -342,8 +362,9 @@ if (!m_model || shouldAutoAlign()) return false; if (m_scaleMinimum == m_scaleMaximum) { - min = m_model->getValueMinimum(); - max = m_model->getValueMaximum(); + bool log; + QString unit; + getValueExtents(min, max, log, unit); } else { min = m_scaleMinimum; max = m_scaleMaximum; @@ -746,18 +767,13 @@ 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 { - haveAutoAlignment = true; - if (log) { - LogRange::mapRange(min, max); - } + } else if (log) { + LogRange::mapRange(min, max); } } else if (m_verticalScale == PlusMinusOneScale) { @@ -778,22 +794,6 @@ #ifdef DEBUG_TIME_VALUE_LAYER std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl; #endif - - 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; -#endif - } } int