comparison layer/TimeValueLayer.cpp @ 668:d52751e2728b

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
author Chris Cannam
date Tue, 16 Jul 2013 17:52:16 +0100
parents ab9fefdaa103
children 1a0dfcbffaf1
comparison
equal deleted inserted replaced
667:2727bc3aab59 668:d52751e2728b
318 bool 318 bool
319 TimeValueLayer::getValueExtents(float &min, float &max, 319 TimeValueLayer::getValueExtents(float &min, float &max,
320 bool &logarithmic, QString &unit) const 320 bool &logarithmic, QString &unit) const
321 { 321 {
322 if (!m_model) return false; 322 if (!m_model) return false;
323
323 min = m_model->getValueMinimum(); 324 min = m_model->getValueMinimum();
324 max = m_model->getValueMaximum(); 325 max = m_model->getValueMaximum();
326
325 logarithmic = (m_verticalScale == LogScale); 327 logarithmic = (m_verticalScale == LogScale);
328
326 unit = m_model->getScaleUnits(); 329 unit = m_model->getScaleUnits();
330
327 if (m_derivative) { 331 if (m_derivative) {
328 max = std::max(fabsf(min), fabsf(max)); 332 max = std::max(fabsf(min), fabsf(max));
329 min = -max; 333 min = -max;
330 } 334 }
331 335
332 #ifdef DEBUG_TIME_VALUE_LAYER 336 #ifdef DEBUG_TIME_VALUE_LAYER
333 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl; 337 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << std::endl;
334 #endif 338 #endif
335 339
340 if (!shouldAutoAlign() && !logarithmic && !m_derivative) {
341
342 if (max == min) {
343 max = max + 0.5;
344 min = min - 0.5;
345 } else {
346 float margin = (max - min) / 10.0;
347 max = max + margin;
348 min = min - margin;
349 }
350
351 #ifdef DEBUG_TIME_VALUE_LAYER
352 std::cerr << "TimeValueLayer::getValueExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl;
353 #endif
354 }
355
336 return true; 356 return true;
337 } 357 }
338 358
339 bool 359 bool
340 TimeValueLayer::getDisplayExtents(float &min, float &max) const 360 TimeValueLayer::getDisplayExtents(float &min, float &max) const
341 { 361 {
342 if (!m_model || shouldAutoAlign()) return false; 362 if (!m_model || shouldAutoAlign()) return false;
343 363
344 if (m_scaleMinimum == m_scaleMaximum) { 364 if (m_scaleMinimum == m_scaleMaximum) {
345 min = m_model->getValueMinimum(); 365 bool log;
346 max = m_model->getValueMaximum(); 366 QString unit;
367 getValueExtents(min, max, log, unit);
347 } else { 368 } else {
348 min = m_scaleMinimum; 369 min = m_scaleMinimum;
349 max = m_scaleMaximum; 370 max = m_scaleMaximum;
350 } 371 }
351 372
744 { 765 {
745 min = 0.0; 766 min = 0.0;
746 max = 0.0; 767 max = 0.0;
747 log = false; 768 log = false;
748 769
749 bool haveAutoAlignment = false;
750
751 if (shouldAutoAlign()) { 770 if (shouldAutoAlign()) {
752 771
753 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) { 772 if (!v->getValueExtents(m_model->getScaleUnits(), min, max, log)) {
754 min = m_model->getValueMinimum(); 773 min = m_model->getValueMinimum();
755 max = m_model->getValueMaximum(); 774 max = m_model->getValueMaximum();
756 } else { 775 } else if (log) {
757 haveAutoAlignment = true; 776 LogRange::mapRange(min, max);
758 if (log) {
759 LogRange::mapRange(min, max);
760 }
761 } 777 }
762 778
763 } else if (m_verticalScale == PlusMinusOneScale) { 779 } else if (m_verticalScale == PlusMinusOneScale) {
764 780
765 min = -1.0; 781 min = -1.0;
776 } 792 }
777 793
778 #ifdef DEBUG_TIME_VALUE_LAYER 794 #ifdef DEBUG_TIME_VALUE_LAYER
779 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl; 795 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << std::endl;
780 #endif 796 #endif
781
782 if (!haveAutoAlignment) {
783
784 if (max == min) {
785 max = max + 0.5;
786 min = min - 0.5;
787 } else {
788 float margin = (max - min) / 10.0;
789 max = max + margin;
790 min = min - margin;
791 }
792
793 #ifdef DEBUG_TIME_VALUE_LAYER
794 std::cerr << "TimeValueLayer::getScaleExtents: min = " << min << ", max = " << max << " (after adjustment)" << std::endl;
795 #endif
796 }
797 } 797 }
798 798
799 int 799 int
800 TimeValueLayer::getYForValue(View *v, float val) const 800 TimeValueLayer::getYForValue(View *v, float val) const
801 { 801 {