diff --git a/apps/sequence/graph/curve_view_range.cpp b/apps/sequence/graph/curve_view_range.cpp index c82e766c8..983bda7b3 100644 --- a/apps/sequence/graph/curve_view_range.cpp +++ b/apps/sequence/graph/curve_view_range.cpp @@ -15,8 +15,8 @@ CurveViewRange::CurveViewRange(InteractiveCurveViewRangeDelegate * delegate) : MemoizedCurveViewRange::protectedSetXMin(-k_displayLeftMarginRatio * xMax(), k_lowerMaxFloat, k_upperMaxFloat); } -void CurveViewRange::normalize() { - Shared::InteractiveCurveViewRange::normalize(); +void CurveViewRange::normalize(bool forceChangeY) { + Shared::InteractiveCurveViewRange::normalize(forceChangeY); /* The X axis is not supposed to go into the negatives, save for a small * margin. However, after normalizing, it could be the case. We thus shift diff --git a/apps/sequence/graph/curve_view_range.h b/apps/sequence/graph/curve_view_range.h index 5611b6056..93561f3a9 100644 --- a/apps/sequence/graph/curve_view_range.h +++ b/apps/sequence/graph/curve_view_range.h @@ -8,7 +8,7 @@ namespace Sequence { class CurveViewRange : public Shared::InteractiveCurveViewRange { public: CurveViewRange(Shared::InteractiveCurveViewRangeDelegate * delegate = nullptr); - void normalize() override; + void normalize(bool forceChangeY = false) override; private: constexpr static float k_displayLeftMarginRatio = 0.1f; }; diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index f8f82d125..e91a681dd 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -131,7 +131,7 @@ void InteractiveCurveViewRange::panWithVector(float x, float y) { MemoizedCurveViewRange::protectedSetYMin(yMin() + y, k_lowerMaxFloat, k_upperMaxFloat); } -void InteractiveCurveViewRange::normalize() { +void InteractiveCurveViewRange::normalize(bool forceChangeY) { /* We center the ranges on the current range center, and put each axis so that * 1cm = 2 current units. */ @@ -148,7 +148,11 @@ void InteractiveCurveViewRange::normalize() { const float newYHalfRange = NormalizedYHalfRange(unit); float normalizedYXRatio = newYHalfRange/newXHalfRange; - Zoom::SetToRatio(normalizedYXRatio, &newXMin, &newXMax, &newYMin, &newYMax); + /* Most of the time, we do not want to shrink, to avoid hiding parts of the + * function. However, when forceChangeY is true, we shrink if the Y range is + * the longer one. */ + bool shrink = forceChangeY && (newYMax - newYMin) / (newXMax - newXMin) > normalizedYXRatio; + Zoom::SetToRatio(normalizedYXRatio, &newXMin, &newXMax, &newYMin, &newYMax, shrink); m_xRange.setMin(newXMin, k_lowerMaxFloat, k_upperMaxFloat); MemoizedCurveViewRange::protectedSetXMax(newXMax, k_lowerMaxFloat, k_upperMaxFloat); diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index eec430989..1c89c9e2c 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -52,7 +52,7 @@ public: // Window void zoom(float ratio, float x, float y); void panWithVector(float x, float y); - virtual void normalize(); + virtual void normalize(bool forceChangeY = false); virtual void setDefault(); void centerAxisAround(Axis axis, float position); void panToMakePointVisible(float x, float y, float topMarginRatio, float rightMarginRatio, float bottomMarginRation, float leftMarginRation, float pixelWidth);