[apps/regression] In graph view, display a specific legend when the mean

dot is selected

Change-Id: Ib55101435c1205709ea5a17616e7daa09ae388bc
This commit is contained in:
Émilie Feral
2017-01-03 11:39:14 +01:00
parent 3b7f0ae1b5
commit 029b75793d
3 changed files with 20 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -103,6 +103,10 @@ int Data::moveCursorHorizontally(int direction) {
return windowHasMoved;
}
int Data::selectedDotIndex() {
return m_selectedDotIndex;
}
/* Window */
void Data::setDefault() {

View File

@@ -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();