Numworks Epsilon  1.4.1
Graphing Calculator Operating System
calculation_controller.cpp
Go to the documentation of this file.
2 #include "../constant.h"
3 #include "../apps_container.h"
4 #include "app.h"
5 #include <poincare.h>
6 #include <assert.h>
7 
8 using namespace Shared;
9 using namespace Poincare;
10 
11 namespace Statistics {
12 
13 CalculationController::CalculationController(Responder * parentResponder, ButtonRowController * header, Store * store) :
14  TabTableController(parentResponder, this),
15  ButtonRowDelegate(header, nullptr),
16  m_titleCells{},
17  m_calculationCells{},
18  m_store(store)
19 {
20 }
21 
23  return I18n::translate(I18n::Message::StatTab);
24 }
25 
27  if (event == Ion::Events::Up) {
29  app()->setFirstResponder(tabController());
30  return true;
31  }
32  if (event == Ion::Events::Copy && selectedColumn() == 1) {
35  return true;
36  }
37  return false;
38 }
39 
41  if (selectedRow() == -1) {
43  } else {
45  }
46  TabTableController::didBecomeFirstResponder();
47 }
48 
50  if (m_store->sumOfColumn(1) == 0) {
51  return true;
52  }
53  return false;
54 }
55 
57  return I18n::Message::NoValueToCompute;
58 }
59 
61  return tabController();
62 }
63 
65  return k_totalNumberOfRows;
66 }
67 
69  return 2;
70 }
71 
73  EvenOddCell * myCell = (EvenOddCell *)cell;
74  myCell->setEven(j%2 == 0);
75  myCell->setHighlighted(i == selectedColumn() && j == selectedRow());
76  if (i == 0) {
77  I18n::Message titles[k_totalNumberOfRows] = {I18n::Message::TotalSize, I18n::Message::Minimum, I18n::Message::Maximum, I18n::Message::Range, I18n::Message::Mean, I18n::Message::StandardDeviationSigma, I18n::Message::Deviation, I18n::Message::FirstQuartile, I18n::Message::ThirdQuartile, I18n::Message::Median, I18n::Message::InterquartileRange, I18n::Message::Sum, I18n::Message::SquareSum, I18n::Message::SampleStandardDeviationS};
79  myCell->setMessage(titles[j]);
80  } else {
81  CalculPointer calculationMethods[k_totalNumberOfRows] = {&Store::sumOfOccurrences, &Store::minValue,
84  double calculation = (m_store->*calculationMethods[j])();
86  char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
87  PrintFloat::convertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
88  myCell->setText(buffer);
89  }
90 }
91 
93  if (i == 0) {
94  return k_titleCellWidth;
95  }
97 }
98 
100  return k_cellHeight;
101 }
102 
104  int result = 0;
105  for (int k = 0; k < i; k++) {
106  result += columnWidth(k);
107  }
108  return result;
109 }
110 
112  return j*rowHeight(0);
113 }
114 
116  int result = 0;
117  int i = 0;
118  while (result < offsetX && i < numberOfRows()) {
119  result += rowHeight(i++);
120  }
121  return (result < offsetX || offsetX == 0) ? i : i - 1;
122 }
123 
125  return (offsetY-1) / rowHeight(0);
126 }
127 
129  assert(index < k_totalNumberOfRows);
130  if (type == 0) {
131  return m_titleCells[index];
132  }
133  return m_calculationCells[index];
134 }
135 
137  return k_maxNumberOfDisplayableRows;
138 }
139 
141  return i;
142 }
143 
144 Responder * CalculationController::tabController() const {
146 }
147 
148 View * CalculationController::loadView() {
149  for (int i = 0; i < k_maxNumberOfDisplayableRows; i++) {
150  m_titleCells[i] = new EvenOddMessageTextCell(KDText::FontSize::Small);
151  m_titleCells[i]->setAlignment(1.0f, 0.5f);
152  m_calculationCells[i] = new EvenOddBufferTextCell(KDText::FontSize::Small);
153  m_calculationCells[i]->setTextColor(Palette::GreyDark);
154  }
155  return TabTableController::loadView();
156 }
157 
158 
159 void CalculationController::unloadView(View * view) {
160  for (int i = 0; i < k_maxNumberOfDisplayableRows; i++) {
161  delete m_titleCells[i];
162  m_titleCells[i] = nullptr;
163  delete m_calculationCells[i];
164  m_calculationCells[i] = nullptr;
165  }
166  TabTableController::unloadView(view);
167 }
168 
169 }
170 
double sumOfOccurrences()
Definition: store.cpp:94
void setAlignment(float horizontalAlignment, float verticalAlignment)
#define assert(e)
Definition: assert.h:9
HighlightCell * selectedCell()
KDCoordinate cumulatedWidthFromIndex(int i) override
virtual void setEven(bool even)
KDCoordinate cumulatedHeightFromIndex(int j) override
static constexpr KDCoordinate CommonRightMargin
Definition: metric.h:9
constexpr int Width
Definition: display.h:26
int16_t KDCoordinate
Definition: coordinate.h:6
double maxValue()
Definition: store.cpp:98
Responder * parentResponder() const
Definition: responder.cpp:12
static constexpr KDColor GreyDark
Definition: palette.h:15
constexpr Event Up
Definition: events.h:62
double standardDeviation()
Definition: store.cpp:131
double sum()
Definition: store.cpp:168
double range()
Definition: store.cpp:118
void setTextColor(KDColor textColor)
void setText(const char *textContent)
void store(const char *storedText)
Definition: clipboard.cpp:9
double minValue()
Definition: store.cpp:108
enum Message uint16_t enum Language uint16_t const char * translate(Message m, Language l=(Language) 0)
Definition: i18n.cpp:5
double median()
Definition: store.cpp:155
int indexFromCumulatedWidth(KDCoordinate offsetX) override
HighlightCell * reusableCell(int index, int type) override
double sampleStandardDeviation()
Definition: store.cpp:135
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
double firstQuartile()
Definition: store.cpp:141
bool handleEvent(Ion::Events::Event event) override
double(Store::* CalculPointer)()
Definition: store.h:56
int indexFromCumulatedHeight(KDCoordinate offsetY) override
double quartileRange()
Definition: store.cpp:151
static constexpr KDCoordinate CommonLeftMargin
Definition: metric.h:8
void setMessage(I18n::Message textContent, KDColor textColor=KDColorBlack)
double thirdQuartile()
Definition: store.cpp:146
constexpr Event Copy
Definition: events.h:123
void willDisplayCellAtLocation(HighlightCell *cell, int i, int j) override
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
double mean()
Definition: store.cpp:122
static Clipboard * sharedClipboard()
Definition: clipboard.cpp:5
KDCoordinate columnWidth(int i) override
App * app()
Definition: responder.cpp:77
virtual void setHighlighted(bool highlight)
int typeAtLocation(int i, int j) override
KDCoordinate rowHeight(int j) override
double squaredValueSum()
Definition: store.cpp:176
SelectableTableView * selectableTableView()
double variance()
Definition: store.cpp:126