[apps/graph] init Range to -5..5 if polar/param

This commit is contained in:
Léa Saviot
2019-09-02 15:19:17 +02:00
parent 27859dc923
commit 18a458bae5
5 changed files with 27 additions and 4 deletions

View File

@@ -34,10 +34,15 @@ void GraphController::viewWillAppear() {
}
float GraphController::interestingXHalfRange() const {
if (displaysNonCartesianFunctions())
{
return 5.0f;
}
float characteristicRange = 0.0f;
Poincare::Context * context = textFieldDelegateApp()->localContext();
for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) {
ExpiringPointer<CartesianFunction> f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i));
CartesianFunctionStore * store = functionStore();
for (int i = 0; i < store->numberOfActiveFunctions(); i++) {
ExpiringPointer<CartesianFunction> f = store->modelForRecord(store->activeRecordAtIndex(i));
float fRange = f->expressionReduced(context).characteristicXRange(context, Poincare::Preferences::sharedPreferences()->angleUnit());
if (!std::isnan(fRange)) {
characteristicRange = maxFloat(fRange, characteristicRange);
@@ -83,4 +88,10 @@ double GraphController::defaultCursorT(Ion::Storage::Record record) {
return function->tMin();
}
bool GraphController::displaysNonCartesianFunctions() const {
CartesianFunctionStore * store = functionStore();
return store->numberOfActiveFunctionsOfType(CartesianFunction::PlotType::Polar) > 0
|| store->numberOfActiveFunctionsOfType(CartesianFunction::PlotType::Parametric) > 0;
}
}

View File

@@ -21,6 +21,7 @@ public:
bool displayDerivativeInBanner() const { return m_displayDerivativeInBanner; }
void setDisplayDerivativeInBanner(bool displayDerivative) { m_displayDerivativeInBanner = displayDerivative; }
float interestingXHalfRange() const override;
private:
int estimatedBannerNumberOfLines() const override { return 1 + m_displayDerivativeInBanner; }
void selectFunctionWithCursor(int functionIndex) override;
@@ -33,6 +34,9 @@ private:
GraphView * functionGraphView() override { return &m_view; }
CurveParameterController * curveParameterController() override { return &m_curveParameterController; }
CartesianFunctionStore * functionStore() const override { return static_cast<CartesianFunctionStore *>(Shared::FunctionGraphController::functionStore()); }
bool displaysNonCartesianFunctions() const;
bool defautRangeIsNormalized() const override { return displaysNonCartesianFunctions(); }
Shared::RoundCursorView m_cursorView;
BannerView m_bannerView;
GraphView m_view;

View File

@@ -33,6 +33,7 @@ protected:
int selectedCurveIndex() const override { return *m_indexFunctionSelectedByCursor; }
Poincare::Coordinate2D<double> xyValues(int curveIndex, double t, Poincare::Context * context) const override;
int numberOfCurves() const override;
void initCursorParameters() override;
private:
virtual FunctionGraphView * functionGraphView() = 0;
@@ -42,7 +43,6 @@ private:
InteractiveCurveViewRangeDelegate::Range computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) override;
// InteractiveCurveViewController
void initCursorParameters() override;
bool moveCursorVertically(int direction) override;
CurveView * curveView() override;
uint32_t modelVersion() override;

View File

@@ -146,9 +146,16 @@ void InteractiveCurveViewRange::setDefault() {
if (m_delegate == nullptr) {
return;
}
m_yAuto = true;
m_xMax = m_delegate->interestingXHalfRange();
setXMin(-m_xMax);
if (!m_delegate->defautRangeIsNormalized()) {
m_yAuto = true;
return;
}
m_yAuto = false;
m_yMax = 3.0f;
setYMin(-m_yMax);
normalize();
}
void InteractiveCurveViewRange::centerAxisAround(Axis axis, float position) {

View File

@@ -10,6 +10,7 @@ public:
bool didChangeRange(InteractiveCurveViewRange * interactiveCurveViewRange);
virtual float interestingXMin() const { return -interestingXHalfRange(); }
virtual float interestingXHalfRange() const { return 10.0f; }
virtual bool defautRangeIsNormalized() const { return false; }
protected:
struct Range {
float min;