mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[apps/graph] Remove horizontal margins when panning on some graph calculations
Change-Id: I1a28555c5b4f04986b223617ab15110711a74841
This commit is contained in:
committed by
Émilie Feral
parent
c04a7af22f
commit
bd2609bcba
@@ -30,7 +30,7 @@ void CalculationGraphController::viewWillAppear() {
|
||||
m_isActive = true;
|
||||
assert(App::app()->functionStore()->modelForRecord(m_record)->plotType() == Shared::ContinuousFunction::PlotType::Cartesian);
|
||||
m_cursor->moveTo(pointOfInterest.x1(), pointOfInterest.x1(), pointOfInterest.x2());
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
m_bannerView->setNumberOfSubviews(Shared::XYBannerView::k_numberOfSubviews);
|
||||
reloadBannerView();
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ public:
|
||||
TELEMETRY_ID("Minimum");
|
||||
private:
|
||||
Poincare::Coordinate2D<double> computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) override;
|
||||
// Prevent horizontal panning to preserve search interval
|
||||
float cursorRightMarginRatio() override { return 0.0f; }
|
||||
float cursorLeftMarginRatio() override { return 0.0f; }
|
||||
};
|
||||
|
||||
class MaximumGraphController : public CalculationGraphController {
|
||||
@@ -21,6 +24,9 @@ public:
|
||||
TELEMETRY_ID("Maximum");
|
||||
private:
|
||||
Poincare::Coordinate2D<double> computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) override;
|
||||
// Prevent horizontal panning to preserve search interval
|
||||
float cursorRightMarginRatio() override { return 0.0f; }
|
||||
float cursorLeftMarginRatio() override { return 0.0f; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ private:
|
||||
void reloadBannerView() override;
|
||||
Poincare::Coordinate2D<double> computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) override;
|
||||
Ion::Storage::Record m_intersectedRecord;
|
||||
// Prevent horizontal panning to preserve search interval
|
||||
float cursorRightMarginRatio() override { return 0.0f; }
|
||||
float cursorLeftMarginRatio() override { return 0.0f; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@ public:
|
||||
TELEMETRY_ID("Root");
|
||||
private:
|
||||
Poincare::Coordinate2D<double> computeNewPointOfInterest(double start, double step, double max, Poincare::Context * context) override;
|
||||
// Prevent horizontal panning to preserve search interval
|
||||
float cursorRightMarginRatio() override { return 0.0f; }
|
||||
float cursorLeftMarginRatio() override { return 0.0f; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ const char * TangentGraphController::title() {
|
||||
|
||||
void TangentGraphController::viewWillAppear() {
|
||||
Shared::SimpleInteractiveCurveViewController::viewWillAppear();
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
m_graphView->drawTangent(true);
|
||||
m_graphView->setOkView(nullptr);
|
||||
m_graphView->selectMainView(true);
|
||||
@@ -51,7 +51,7 @@ bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, co
|
||||
assert(function->plotType() == Shared::ContinuousFunction::PlotType::Cartesian);
|
||||
double y = function->evaluate2DAtParameter(floatBody, myApp->localContext()).x2();
|
||||
m_cursor->moveTo(floatBody, floatBody, y);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
reloadBannerView();
|
||||
curveView()->reload();
|
||||
return true;
|
||||
|
||||
@@ -262,7 +262,7 @@ void GraphController::initCursorParameters() {
|
||||
double y = m_store->meanOfColumn(*m_selectedSeriesIndex, 1);
|
||||
m_cursor->moveTo(x, x, y);
|
||||
if (m_store->yAuto()) {
|
||||
m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
}
|
||||
*m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ bool GraphController::textFieldDidFinishEditing(TextField * textField, const cha
|
||||
floatBody = std::fmax(0, std::round(floatBody));
|
||||
double y = xyValues(selectedCurveIndex(), floatBody, myApp->localContext()).x2();
|
||||
m_cursor->moveTo(floatBody, floatBody, y);
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
reloadBannerView();
|
||||
m_view.reload();
|
||||
return true;
|
||||
|
||||
@@ -146,7 +146,7 @@ void FunctionGraphController::initCursorParameters() {
|
||||
}
|
||||
m_cursor->moveTo(t, xy.x1(), xy.x2());
|
||||
if (interactiveCurveViewRange()->yAuto()) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(xy.x1(), xy.x2(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
interactiveCurveViewRange()->panToMakePointVisible(xy.x1(), xy.x2(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
}
|
||||
selectFunctionWithCursor(functionIndex);
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ float InteractiveCurveViewController::addMargin(float y, float range, bool isVer
|
||||
* bottomMarginRatio = bottomMargin / viewHeight.
|
||||
* The same goes horizontally.
|
||||
*/
|
||||
float topMarginRatio = isVertical ? cursorTopMarginRatio() : k_cursorRightMarginRatio;
|
||||
float bottomMarginRatio = isVertical ? cursorBottomMarginRatio() : k_cursorLeftMarginRatio;
|
||||
float topMarginRatio = isVertical ? cursorTopMarginRatio() : cursorRightMarginRatio();
|
||||
float bottomMarginRatio = isVertical ? cursorBottomMarginRatio() : cursorLeftMarginRatio();
|
||||
assert(topMarginRatio + bottomMarginRatio < 1); // Assertion so that the formula is correct
|
||||
float ratioDenominator = 1 - bottomMarginRatio - topMarginRatio;
|
||||
float ratio = isMin ? -bottomMarginRatio : topMarginRatio;
|
||||
@@ -93,7 +93,7 @@ bool InteractiveCurveViewController::handleEvent(Ion::Events::Event event) {
|
||||
if (moveCursorVertically(direction)) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(
|
||||
m_cursor->x(), m_cursor->y(),
|
||||
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio,
|
||||
cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(),
|
||||
curveView()->pixelWidth()
|
||||
);
|
||||
reloadBannerView();
|
||||
@@ -221,7 +221,7 @@ bool InteractiveCurveViewController::textFieldDidFinishEditing(TextField * textF
|
||||
}
|
||||
Coordinate2D<double> xy = xyValues(selectedCurveIndex(), floatBody, textFieldDelegateApp()->localContext());
|
||||
m_cursor->moveTo(floatBody, xy.x1(), xy.x2());
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
reloadBannerView();
|
||||
curveView()->reload();
|
||||
return true;
|
||||
@@ -247,10 +247,10 @@ bool InteractiveCurveViewController::isCursorVisible() {
|
||||
float xRange = range->xMax() - range->xMin();
|
||||
float yRange = range->yMax() - range->yMin();
|
||||
return
|
||||
m_cursor->x() >= range->xMin() + k_cursorLeftMarginRatio * xRange &&
|
||||
m_cursor->x() <= range->xMax() - k_cursorRightMarginRatio * xRange &&
|
||||
m_cursor->y() >= range->yMin() + cursorBottomMarginRatio() * yRange &&
|
||||
m_cursor->y() <= range->yMax() - cursorTopMarginRatio() * yRange;
|
||||
m_cursor->x() >= range->xMin() + cursorLeftMarginRatio() * xRange &&
|
||||
m_cursor->x() <= range->xMax() - cursorRightMarginRatio() * xRange &&
|
||||
m_cursor->y() >= range->yMin() + cursorBottomMarginRatio() * yRange &&
|
||||
m_cursor->y() <= range->yMax() - cursorTopMarginRatio() * yRange;
|
||||
}
|
||||
|
||||
int InteractiveCurveViewController::closestCurveIndexVertically(bool goingUp, int currentCurveIndex, Poincare::Context * context) const {
|
||||
|
||||
@@ -31,7 +31,7 @@ bool SimpleInteractiveCurveViewController::handleLeftRightEvent(Ion::Events::Eve
|
||||
if (moveCursorHorizontally(direction, Ion::Events::repetitionFactor())) {
|
||||
interactiveCurveViewRange()->panToMakePointVisible(
|
||||
m_cursor->x(), m_cursor->y(),
|
||||
cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio,
|
||||
cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(),
|
||||
curveView()->pixelWidth()
|
||||
);
|
||||
reloadBannerView();
|
||||
|
||||
@@ -15,8 +15,8 @@ public:
|
||||
bool handleEvent(Ion::Events::Event event) override;
|
||||
bool textFieldDidReceiveEvent(TextField * textField, Ion::Events::Event event) override;
|
||||
protected:
|
||||
constexpr static float k_cursorRightMarginRatio = 0.04f; // (cursorWidth/2)/(graphViewWidth-1)
|
||||
constexpr static float k_cursorLeftMarginRatio = 0.04f; // (cursorWidth/2)/(graphViewWidth-1)
|
||||
virtual float cursorRightMarginRatio() { return 0.04f; } // (cursorWidth/2)/(graphViewWidth-1)
|
||||
virtual float cursorLeftMarginRatio() { return 0.04f; } // (cursorWidth/2)/(graphViewWidth-1)
|
||||
virtual float cursorTopMarginRatio() { return 0.07f; } // (cursorHeight/2)/(graphViewHeight-1)
|
||||
virtual float cursorBottomMarginRatio() = 0; // (cursorHeight/2+bannerHeight)/(graphViewHeight-1)
|
||||
constexpr static float k_numberOfCursorStepsInGradUnit = 5.0f;
|
||||
|
||||
@@ -26,7 +26,7 @@ SumGraphController::SumGraphController(Responder * parentResponder, InputEventHa
|
||||
|
||||
void SumGraphController::viewWillAppear() {
|
||||
SimpleInteractiveCurveViewController::viewWillAppear();
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphRange->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
m_graphView->setBannerView(&m_legendView);
|
||||
m_graphView->setCursorView(&m_cursorView);
|
||||
m_graphView->setOkView(nullptr);
|
||||
@@ -77,7 +77,7 @@ bool SumGraphController::moveCursorHorizontallyToPosition(double x) {
|
||||
m_graphView->setAreaHighlight(m_startSum, m_cursor->x());
|
||||
}
|
||||
m_legendView.setEditableZone(m_cursor->x());
|
||||
m_graphRange->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio, curveView()->pixelWidth());
|
||||
m_graphRange->panToMakePointVisible(x, y, cursorTopMarginRatio(), cursorRightMarginRatio(), cursorBottomMarginRatio(), cursorLeftMarginRatio(), curveView()->pixelWidth());
|
||||
m_graphView->reload();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user