From 029b75793daab1a9a3c4cf86a553cfc7bfb00a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 3 Jan 2017 11:39:14 +0100 Subject: [PATCH] [apps/regression] In graph view, display a specific legend when the mean dot is selected Change-Id: Ib55101435c1205709ea5a17616e7daa09ae388bc --- apps/regression/banner_view.cpp | 17 +++++++++++++---- apps/regression/data.cpp | 4 ++++ apps/regression/data.h | 3 +++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/apps/regression/banner_view.cpp b/apps/regression/banner_view.cpp index 1ec0afbc8..3d2e0a4fd 100644 --- a/apps/regression/banner_view.cpp +++ b/apps/regression/banner_view.cpp @@ -20,30 +20,39 @@ void BannerView::reload() { m_regressionTypeView.setText("y = ax+b"); char buffer[k_maxNumberOfCharacters]; const char * legend = "a = "; + float slope = m_data->slope(); int legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); - float slope = m_data->slope(); Float(slope).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); m_slopeView.setText(buffer); legend = "b = "; + float yIntercept = m_data->yIntercept(); legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); - float yIntercept = m_data->yIntercept(); Float(yIntercept).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); m_yInterceptView.setText(buffer); legend = "x = "; + float x = m_data->xCursorPosition(); + // Display a specific legend if the mean dot is selected + if (m_data->selectedDotIndex() == m_data->numberOfPairs()) { + legend = "x^ = "; + x = m_data->xMean(); + } legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); - float x = m_data->xCursorPosition(); Float(x).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); m_xView.setText(buffer); legend = "y = "; + float y = m_data->yCursorPosition(); + if (m_data->selectedDotIndex() == m_data->numberOfPairs()) { + legend = "y^ = "; + y = m_data->yMean(); + } legendLength = strlen(legend); strlcpy(buffer, legend, legendLength+1); - float y = m_data->yCursorPosition(); Float(y).convertFloatToText(buffer+legendLength, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); m_yView.setText(buffer); } diff --git a/apps/regression/data.cpp b/apps/regression/data.cpp index 5c390e46f..67d4235d8 100644 --- a/apps/regression/data.cpp +++ b/apps/regression/data.cpp @@ -103,6 +103,10 @@ int Data::moveCursorHorizontally(int direction) { return windowHasMoved; } +int Data::selectedDotIndex() { + return m_selectedDotIndex; +} + /* Window */ void Data::setDefault() { diff --git a/apps/regression/data.h b/apps/regression/data.h index 773d6b9e3..f8b4731d4 100644 --- a/apps/regression/data.h +++ b/apps/regression/data.h @@ -24,6 +24,9 @@ public: // the result of moveCursorVertically means: // 0-> the window has not changed 1->the window changed int moveCursorVertically(int direction) override; + /* The selectedDotIndex is -1 when no dot is selected, m_numberOfPairs when + * the mean dot is selected and the dot index otherwise */ + int selectedDotIndex(); // Window void setDefault();