Numworks Epsilon  1.4.1
Graphing Calculator Operating System
box_controller.cpp
Go to the documentation of this file.
1 #include "box_controller.h"
2 #include "app.h"
3 #include "../apps_container.h"
4 
5 using namespace Poincare;
6 
7 namespace Statistics {
8 
9 BoxController::BoxController(Responder * parentResponder, ButtonRowController * header, Store * store, BoxView::Quantile * selectedQuantile) :
10  ViewController(parentResponder),
11  ButtonRowDelegate(header, nullptr),
12  m_boxBannerView(),
13  m_view(store, &m_boxBannerView, selectedQuantile),
14  m_store(store)
15 {
16 }
17 
18 const char * BoxController::title() {
19  return I18n::translate(I18n::Message::BoxTab);
20 }
21 
23  return &m_view;
24 }
25 
27  if (event == Ion::Events::Up) {
28  m_view.selectMainView(false);
29  app()->setFirstResponder(tabController());
30  return true;
31  }
32  if (event == Ion::Events::Left || event == Ion::Events::Right) {
33  int nextSelectedQuantile = event == Ion::Events::Left ? (int)m_view.selectedQuantile()-1 : (int)m_view.selectedQuantile()+1;
34  if (m_view.selectQuantile(nextSelectedQuantile)) {
35  reloadBannerView();
36  return true;
37  }
38  return false;
39  }
40  return false;
41 }
42 
44  m_view.selectMainView(true);
45  m_view.reload();
46 }
47 
48 bool BoxController::isEmpty() const {
49  if (m_store->sumOfColumn(1) == 0) {
50  return true;
51  }
52  return false;
53 }
54 
55 I18n::Message BoxController::emptyMessage() {
56  return I18n::Message::NoDataToPlot;
57 }
58 
60  return tabController();
61 }
62 
63 Responder * BoxController::tabController() const {
65 }
66 
67 void BoxController::reloadBannerView() {
68  I18n::Message calculationName[5] = {I18n::Message::Minimum, I18n::Message::FirstQuartile, I18n::Message::Median, I18n::Message::ThirdQuartile, I18n::Message::Maximum};
69  m_boxBannerView.setMessageAtIndex(calculationName[(int)m_view.selectedQuantile()], 0);
70  char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
73  double calculation = (m_store->*calculationMethods[(int)m_view.selectedQuantile()])();
74  PrintFloat::convertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
75  m_boxBannerView.setLegendAtIndex(buffer, 1);
76 }
77 
79  m_view.selectMainView(true);
80  reloadBannerView();
81  m_view.reload();
82 }
83 
85  if (nextFirstResponder == tabController()) {
86  m_view.selectMainView(false);
87  m_view.reload();
88  }
89 }
90 
91 }
void setLegendAtIndex(char *text, int index)
Definition: banner_view.cpp:7
void reload() override
Definition: box_view.cpp:18
double maxValue()
Definition: store.cpp:98
Responder * parentResponder() const
Definition: responder.cpp:12
constexpr Event Up
Definition: events.h:62
const char * title() override
void setMessageAtIndex(I18n::Message text, int index)
Definition: banner_view.cpp:18
void didBecomeFirstResponder() override
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
void willExitResponderChain(Responder *nextFirstResponder) override
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
double firstQuartile()
Definition: store.cpp:141
double(Store::* CalculPointer)()
Definition: store.h:56
void viewWillAppear() override
constexpr Event Left
Definition: events.h:61
double thirdQuartile()
Definition: store.cpp:146
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
constexpr Event Right
Definition: events.h:64
void selectMainView(bool mainViewSelected)
Definition: curve_view.cpp:46
I18n::Message emptyMessage() override
bool isEmpty() const override
Responder * defaultController() override
App * app()
Definition: responder.cpp:77
Quantile selectedQuantile()
Definition: box_view.cpp:30
bool handleEvent(Ion::Events::Event event) override
bool selectQuantile(int selectedQuantile)
Definition: box_view.cpp:34