[apps/reg] Init the graph selected series at cursor initialization

This commit is contained in:
Léa Saviot
2018-05-30 15:31:50 +02:00
parent 7f71faf0c2
commit 32e00b5e1e
3 changed files with 32 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ GraphController::GraphController(Responder * parentResponder, ButtonRowControlle
m_initialisationParameterController(this, m_store),
m_predictionParameterController(this, m_store, m_cursor, this),
m_selectedDotIndex(selectedDotIndex),
m_selectedSeries(0) // TODO -1
m_selectedSeries(-1)
{
m_store->setCursor(m_cursor);
}
@@ -191,7 +191,7 @@ void GraphController::initRangeParameters() {
}
void GraphController::initCursorParameters() {
assert(m_selectedSeries >= 0);
m_selectedSeries = m_store->indexOfKthNonEmptySeries(0);
double x = m_store->meanOfColumn(m_selectedSeries, 0);
double y = m_store->meanOfColumn(m_selectedSeries, 1);
m_cursor->moveTo(x, y);

View File

@@ -137,7 +137,7 @@ void Store::setDefault() {
}
bool Store::isEmpty() const {
for (int i = 0; i < k_numberOfSeries; i ++) {
for (int i = 0; i < k_numberOfSeries; i++) {
if (!seriesIsEmpty(i)) {
return false;
}
@@ -145,10 +145,37 @@ bool Store::isEmpty() const {
return true;
}
int Store::numberOfNonEmptySeries() const {
// TODO Share with stats in FLoatPairStore
int nonEmptySeriesCount = 0;
for (int i = 0; i< k_numberOfSeries; i++) {
if (!seriesIsEmpty(i)) {
nonEmptySeriesCount++;
}
}
return nonEmptySeriesCount;
}
bool Store::seriesIsEmpty(int series) const {
return numberOfPairsOfSeries(series) < 2;
}
int Store::indexOfKthNonEmptySeries(int k) const {
// TODO put in FloatPairStore (it is also in stats/store)
assert(k >= 0 && k < numberOfNonEmptySeries());
int nonEmptySeriesCount = 0;
for (int i = 0; i < k_numberOfSeries; i++) {
if (!seriesIsEmpty(i)) {
if (nonEmptySeriesCount == k) {
return i;
}
nonEmptySeriesCount++;
}
}
assert(false);
return 0;
}
/* Calculations */
double Store::doubleCastedNumberOfPairsOfSeries(int series) const {

View File

@@ -23,7 +23,9 @@ public:
// Series
bool isEmpty() const;
int numberOfNonEmptySeries() const;
bool seriesIsEmpty(int series) const;
int indexOfKthNonEmptySeries(int k) const;
// Calculation
double doubleCastedNumberOfPairsOfSeries(int series) const;