From 3397dbd03951f631e93fc38f4aefa0dcc195c38c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Fri, 16 Nov 2018 11:19:24 +0100 Subject: [PATCH] [apps] Clean regression/graph_controller files --- apps/regression/graph_controller.cpp | 84 ++++++++++++++-------------- apps/regression/graph_controller.h | 4 +- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/apps/regression/graph_controller.cpp b/apps/regression/graph_controller.cpp index 7cae98b09..1f5d15a11 100644 --- a/apps/regression/graph_controller.cpp +++ b/apps/regression/graph_controller.cpp @@ -69,22 +69,26 @@ void GraphController::selectRegressionCurve() { m_roundCursorView.setColor(Palette::DataColor[*m_selectedSeriesIndex]); } +// Private + Poincare::Context * GraphController::globalContext() { return const_cast(static_cast(app()->container()))->globalContext(); } -CurveView * GraphController::curveView() { - return &m_view; +float GraphController::cursorBottomMarginRatio() { + float f = (m_view.cursorView()->minimalSizeForOptimalDisplay().height()/2 + 2 + estimatedBannerHeight())/k_viewHeight; + return f; } -InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() { - return m_store; +float GraphController::estimatedBannerHeight() const { + if (selectedSeriesIndex() < 0) { + return KDFont::SmallFont->glyphSize().height() * 3; + } + float result = KDFont::SmallFont->glyphSize().height() * m_store->modelForSeries(selectedSeriesIndex())->bannerLinesCount(); + return result; } -bool GraphController::handleEnter() { - stackController()->push(&m_graphOptionsController); - return true; -} +// SimpleInteractiveCurveViewController void GraphController::reloadBannerView() { if (*m_selectedSeriesIndex < 0) { @@ -222,21 +226,6 @@ void GraphController::reloadBannerView() { } } -void GraphController::initRangeParameters() { - m_store->setDefault(); -} - -void GraphController::initCursorParameters() { - if (*m_selectedSeriesIndex < 0 || m_store->seriesIsEmpty(*m_selectedSeriesIndex)) { - *m_selectedSeriesIndex = m_store->indexOfKthNonEmptySeries(0); - } - double x = m_store->meanOfColumn(*m_selectedSeriesIndex, 0); - double y = m_store->meanOfColumn(*m_selectedSeriesIndex, 1); - m_cursor->moveTo(x, y); - m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); - *m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex); -} - bool GraphController::moveCursorHorizontally(int direction) { if (*m_selectedDotIndex >= 0) { int dotSelected = m_store->nextDot(*m_selectedSeriesIndex, direction, *m_selectedDotIndex); @@ -262,6 +251,35 @@ bool GraphController::moveCursorHorizontally(int direction) { return true; } +InteractiveCurveViewRange * GraphController::interactiveCurveViewRange() { + return m_store; +} + +CurveView * GraphController::curveView() { + return &m_view; +} + +bool GraphController::handleEnter() { + stackController()->push(&m_graphOptionsController); + return true; +} + +// InteractiveCurveViewController +void GraphController::initRangeParameters() { + m_store->setDefault(); +} + +void GraphController::initCursorParameters() { + if (*m_selectedSeriesIndex < 0 || m_store->seriesIsEmpty(*m_selectedSeriesIndex)) { + *m_selectedSeriesIndex = m_store->indexOfKthNonEmptySeries(0); + } + double x = m_store->meanOfColumn(*m_selectedSeriesIndex, 0); + double y = m_store->meanOfColumn(*m_selectedSeriesIndex, 1); + m_cursor->moveTo(x, y); + m_store->panToMakePointVisible(x, y, cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); + *m_selectedDotIndex = m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex); +} + bool GraphController::moveCursorVertically(int direction) { Poincare::Context * context = globalContext(); double x = m_cursor->x(); @@ -295,12 +313,9 @@ bool GraphController::moveCursorVertically(int direction) { } else { // Compare the y distances double regressionDistanceY = std::fabs(yValue(closestRegressionSeries, x, context) - y); - double dotDistanceY = -1; - if (dotSelected == m_store->numberOfPairsOfSeries(closestDotSeries)) { - dotDistanceY = std::fabs(m_store->meanOfColumn(closestDotSeries, 1) - y); - } else { + double dotDistanceY = (dotSelected == m_store->numberOfPairsOfSeries(closestDotSeries)) ? + dotDistanceY = std::fabs(m_store->meanOfColumn(closestDotSeries, 1) - y) : dotDistanceY = std::fabs(m_store->get(closestDotSeries, 1, dotSelected) - y); - } if (regressionDistanceY <= dotDistanceY) { validDot = false; } else { @@ -369,11 +384,6 @@ int GraphController::numberOfCurves() const { return Store::k_numberOfSeries; } -float GraphController::cursorBottomMarginRatio() { - float f = (m_view.cursorView()->minimalSizeForOptimalDisplay().height()/2 + 2 + estimatedBannerHeight())/k_viewHeight; - return f; -} - float GraphController::displayTopMarginRatio() { return 0.12f; // cursorHeight/graphViewHeight } @@ -383,14 +393,6 @@ float GraphController::displayBottomMarginRatio() { return f; } -float GraphController::estimatedBannerHeight() const { - if (selectedSeriesIndex() < 0) { - return KDFont::SmallFont->glyphSize().height() * 3; - } - float result = KDFont::SmallFont->glyphSize().height() * m_store->modelForSeries(selectedSeriesIndex())->bannerLinesCount(); - return result; -} - InteractiveCurveViewRangeDelegate::Range GraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) { float minY = FLT_MAX; float maxY = -FLT_MAX; diff --git a/apps/regression/graph_controller.h b/apps/regression/graph_controller.h index 43a3505b7..d5b45feef 100644 --- a/apps/regression/graph_controller.h +++ b/apps/regression/graph_controller.h @@ -1,7 +1,6 @@ #ifndef REGRESSION_GRAPH_CONTROLLER_H #define REGRESSION_GRAPH_CONTROLLER_H -#include #include "banner_view.h" #include "store.h" #include "graph_options_controller.h" @@ -55,7 +54,8 @@ private: // InteractiveCurveViewRangeDelegate float displayTopMarginRatio() override; - float displayBottomMarginRatio() override; Shared::InteractiveCurveViewRangeDelegate::Range computeYRange(Shared::InteractiveCurveViewRange * interactiveCurveViewRange) override; + float displayBottomMarginRatio() override; + Shared::InteractiveCurveViewRangeDelegate::Range computeYRange(Shared::InteractiveCurveViewRange * interactiveCurveViewRange) override; Shared::CursorView m_crossCursorView; Shared::RoundCursorView m_roundCursorView;