From 4233f197d3a479b8252004fe9fb2bfebfad52905 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 12 Nov 2020 14:43:17 +0100 Subject: [PATCH] [shared] Keep graph units when using navigation When using the Navigate menu on graphs, the grid units are computed using the normal graph's range, so that the units won't change. Change-Id: I8ff8853868e5c90319619a6271d6a7d87ae82ab0 --- apps/shared/curve_view_range.h | 3 ++- apps/shared/function_zoom_and_pan_curve_view_controller.cpp | 5 ++++- apps/shared/interactive_curve_view_range.h | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/shared/curve_view_range.h b/apps/shared/curve_view_range.h index 40c0709bb..5867ab566 100644 --- a/apps/shared/curve_view_range.h +++ b/apps/shared/curve_view_range.h @@ -24,7 +24,7 @@ public: return computeGridUnit(k_minNumberOfXGridUnits, k_maxNumberOfXGridUnits, xMax() - xMin()); } virtual float yGridUnit() const { - return computeGridUnit(k_minNumberOfYGridUnits, k_maxNumberOfYGridUnits, yMax() - yMin()); + return computeGridUnit(k_minNumberOfYGridUnits, k_maxNumberOfYGridUnits, yMax() - yMin() + offscreenYAxis()); } constexpr static float k_maxNumberOfXGridUnits = 18.0f; constexpr static float k_maxNumberOfYGridUnits = 13.0f; @@ -32,6 +32,7 @@ protected: constexpr static float k_minNumberOfXGridUnits = 7.0f; constexpr static float k_minNumberOfYGridUnits = 5.0f; private: + virtual float offscreenYAxis() const { return 0.f; } /* The grid units is constrained to be a number of type: k*10^n with k = 1,2 or 5 * and n a relative integer. The choice of x and y grid units depend on the * grid range.*/ diff --git a/apps/shared/function_zoom_and_pan_curve_view_controller.cpp b/apps/shared/function_zoom_and_pan_curve_view_controller.cpp index cd1edbf60..72fb708ed 100644 --- a/apps/shared/function_zoom_and_pan_curve_view_controller.cpp +++ b/apps/shared/function_zoom_and_pan_curve_view_controller.cpp @@ -37,9 +37,12 @@ void FunctionZoomAndPanCurveViewController::adaptCurveRange(bool viewWillAppear) float currentRange = m_interactiveRange->yMax() - m_interactiveRange->yMin(); float newYMin = 0; if (viewWillAppear) { - newYMin = currentYMin + ((float)ContentView::k_legendHeight)/((float)k_standardViewHeight)*currentRange; + float rangeOffscreen = ((float)ContentView::k_legendHeight)/((float)k_standardViewHeight)*currentRange; + newYMin = currentYMin + rangeOffscreen; + m_interactiveRange->setOffscreenYAxis(rangeOffscreen); } else { newYMin = m_interactiveRange->yMax() - currentRange*((float)k_standardViewHeight)/(((float)k_standardViewHeight)-((float)ContentView::k_legendHeight)); + m_interactiveRange->setOffscreenYAxis(0.f); } m_interactiveRange->setYMin(newYMin); m_contentView.curveView()->reload(); diff --git a/apps/shared/interactive_curve_view_range.h b/apps/shared/interactive_curve_view_range.h index a44169986..ced28f46d 100644 --- a/apps/shared/interactive_curve_view_range.h +++ b/apps/shared/interactive_curve_view_range.h @@ -46,6 +46,8 @@ public: void setYMin(float f) override; void setYMax(float f) override; + void setOffscreenYAxis(float f) { m_offscreenYAxis = f; } + // Window void zoom(float ratio, float x, float y); void panWithVector(float x, float y); @@ -77,6 +79,9 @@ protected: constexpr static float NormalizedYHalfRange(float unit) { return 3.06f * unit; } InteractiveCurveViewRangeDelegate * m_delegate; private: + float offscreenYAxis() const override { return m_offscreenYAxis; } + + float m_offscreenYAxis; bool m_zoomAuto; bool m_zoomNormalize; };