box_controller.cpp
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "box_controller.h"
#include "app.h"
#include "../shared/poincare_helpers.h"
#include "../apps_container.h"
using namespace Poincare;
using namespace Shared;
namespace Statistics {
BoxController::BoxController(Responder * parentResponder, ButtonRowController * header, Store * store, BoxView::Quantile * selectedQuantile, int * selectedSeriesIndex) :
MultipleDataViewController(parentResponder, store, (int *)(selectedQuantile), selectedSeriesIndex),
ButtonRowDelegate(header, nullptr),
m_view(store, selectedQuantile)
{
}
bool BoxController::moveSelectionHorizontally(int deltaIndex) {
int selectedQuantile = (int)m_view.dataViewAtIndex(selectedSeriesIndex())->selectedQuantile();
int nextSelectedQuantile = selectedQuantile + deltaIndex;
if (m_view.dataViewAtIndex(selectedSeriesIndex())->selectQuantile(nextSelectedQuantile)) {
reloadBannerView();
return true;
}
return false;
}
const char * BoxController::title() {
return I18n::translate(I18n::Message::BoxTab);
}
Responder * BoxController::tabController() const {
return (parentResponder()->parentResponder()->parentResponder());
}
void BoxController::reloadBannerView() {
if (selectedSeriesIndex() < 0) {
return;
}
int selectedQuantile = (int)m_view.dataViewAtIndex(selectedSeriesIndex())->selectedQuantile();
// Set series name
char seriesChar = '0' + selectedSeriesIndex() + 1;
char bufferName[] = {' ', 'V', seriesChar, '/', 'N', seriesChar, 0};
m_view.editableBannerView()->setLegendAtIndex(bufferName, 0);
// Set calculation name
I18n::Message calculationName[5] = {I18n::Message::Minimum, I18n::Message::FirstQuartile, I18n::Message::Median, I18n::Message::ThirdQuartile, I18n::Message::Maximum};
m_view.editableBannerView()->setMessageAtIndex(calculationName[selectedQuantile], 1);
// Set calculation result
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits) + 1];
CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile,
&Store::maxValue};
double calculation = (m_store->*calculationMethods[selectedQuantile])(selectedSeriesIndex());
int numberOfChar = PoincareHelpers::ConvertFloatToText<double>(calculation, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
buffer[numberOfChar++] = ' ';
buffer[numberOfChar] = 0;
m_view.editableBannerView()->setLegendAtIndex(buffer, 2);
}
}