diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index e09421114..02f5279db 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -39,6 +39,19 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) { m_displayDerivativeInBanner = displayDerivative; } +float GraphController::interestingXRange() { + float characteristicRange = 0.0f; + TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); + for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { + Function * f = functionStore()->activeFunctionAtIndex(i); + float fRange = f->expression(myApp->localContext())->characteristicXRange(*(myApp->localContext())); + if (!std::isnan(fRange)) { + characteristicRange = fRange > characteristicRange ? fRange : characteristicRange; + } + } + return (characteristicRange > 0.0f ? 1.6f*characteristicRange : 10.0f); +} + void GraphController::selectFunctionWithCursor(int functionIndex) { FunctionGraphController::selectFunctionWithCursor(functionIndex); CartesianFunction * f = m_functionStore->activeFunctionAtIndex(indexFunctionSelectedByCursor()); diff --git a/apps/graph/graph/graph_controller.h b/apps/graph/graph/graph_controller.h index bcb3c9d81..00f193d4d 100644 --- a/apps/graph/graph/graph_controller.h +++ b/apps/graph/graph/graph_controller.h @@ -20,6 +20,7 @@ public: void viewWillAppear() override; bool displayDerivativeInBanner() const; void setDisplayDerivativeInBanner(bool displayDerivative); + float interestingXRange() override; private: void selectFunctionWithCursor(int functionIndex) override; BannerView * bannerView() override; diff --git a/apps/sequence/graph/curve_view_range.cpp b/apps/sequence/graph/curve_view_range.cpp index eecb7fd3f..f069cd14a 100644 --- a/apps/sequence/graph/curve_view_range.cpp +++ b/apps/sequence/graph/curve_view_range.cpp @@ -75,7 +75,8 @@ void CurveViewRange::setTrigonometric() { } void CurveViewRange::setDefault() { - m_xMax = 10.0f; + assert(m_delegate); + m_xMax = m_delegate->interestingXRange(); m_xMin = -k_displayLeftMarginRatio*m_xMax; m_xGridUnit = computeGridUnit(Axis::X, m_xMin, m_xMax); setYAuto(true); diff --git a/apps/shared/interactive_curve_view_range.cpp b/apps/shared/interactive_curve_view_range.cpp index 880625a0a..c8158a880 100644 --- a/apps/shared/interactive_curve_view_range.cpp +++ b/apps/shared/interactive_curve_view_range.cpp @@ -167,8 +167,9 @@ void InteractiveCurveViewRange::setTrigonometric() { } void InteractiveCurveViewRange::setDefault() { - m_xMax = 10.0f; - MemoizedCurveViewRange::setXMin(-10.0f); + assert(m_delegate); + m_xMax = m_delegate->interestingXRange(); + MemoizedCurveViewRange::setXMin(-m_xMax); setYAuto(true); } diff --git a/apps/shared/interactive_curve_view_range_delegate.cpp b/apps/shared/interactive_curve_view_range_delegate.cpp index 46802886f..33598fe08 100644 --- a/apps/shared/interactive_curve_view_range_delegate.cpp +++ b/apps/shared/interactive_curve_view_range_delegate.cpp @@ -48,4 +48,8 @@ bool InteractiveCurveViewRangeDelegate::didChangeRange(InteractiveCurveViewRange return true; } +float InteractiveCurveViewRangeDelegate::interestingXRange() { + return 10.0f; +} + } diff --git a/apps/shared/interactive_curve_view_range_delegate.h b/apps/shared/interactive_curve_view_range_delegate.h index 67b28a30e..841e8f43c 100644 --- a/apps/shared/interactive_curve_view_range_delegate.h +++ b/apps/shared/interactive_curve_view_range_delegate.h @@ -8,6 +8,7 @@ class InteractiveCurveViewRange; class InteractiveCurveViewRangeDelegate { public: bool didChangeRange(InteractiveCurveViewRange * interactiveCurveViewRange); + virtual float interestingXRange(); protected: struct Range { float min;