[apps/stats] Fill with formula in statistics

This commit is contained in:
Léa Saviot
2018-06-01 10:30:54 +02:00
parent 5f3ea724f4
commit 5da90b5160
7 changed files with 61 additions and 22 deletions

View File

@@ -1,4 +1,5 @@
#include "store_controller.h"
#include "series_context.h"
#include "app.h"
#include "../apps_container.h"
#include "../constant.h"
@@ -6,16 +7,35 @@
#include <float.h>
#include <cmath>
using namespace Poincare;
using namespace Shared;
namespace Statistics {
StoreController::StoreController(Responder * parentResponder, Store * store, ButtonRowController * header) :
Shared::StoreController(parentResponder, store, header),
m_titleCells{}
m_titleCells{},
m_store(store)
{
}
void StoreController::fillColumnWithFormula(Expression * formula) {
int currentColumn = selectedColumn();
// Fetch the series used in the formula to:
// - Make sure the current filled column is not inside
// - Compute the size of the filled in series
SeriesContext seriesContext(m_store, const_cast<AppsContainer *>(static_cast<const AppsContainer *>(app()->container()))->globalContext());
for (int j = 0; j < 2; j++) {
// Set the context
seriesContext.setSeriesPairIndex(j);
// Compute the new value using the formula
double evaluation = formula->approximateToScalar<double>(seriesContext);
setDataAtLocation(evaluation, currentColumn, j + 1);
}
selectableTableView()->reloadData();
}
void StoreController::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
Shared::StoreController::willDisplayCellAtLocation(cell, i, j);
if (cellAtLocationIsEditable(i, j)) {