mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/statistics] Handle selection in box
Change-Id: Id48d4f2af324bd53e8137b66695632f97396a196
This commit is contained in:
@@ -20,15 +20,22 @@ View * BoxController::view() {
|
||||
|
||||
bool BoxController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Up) {
|
||||
m_view.selectAnyQuantile(false);
|
||||
app()->setFirstResponder(tabController());
|
||||
return true;
|
||||
}
|
||||
if (event == Ion::Events::Left || event == Ion::Events::Right) {
|
||||
int nextSelectedQuantile = event == Ion::Events::Left ? m_view.selectedQuantile()-1 : m_view.selectedQuantile()+1;
|
||||
return m_view.selectQuantile(nextSelectedQuantile);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void BoxController::didBecomeFirstResponder() {
|
||||
m_view.reload(NAN);
|
||||
m_view.selectAnyQuantile(true);
|
||||
m_view.reload(-1);
|
||||
}
|
||||
|
||||
bool BoxController::isEmpty() {
|
||||
if (m_data->totalSize() == 0) {
|
||||
return true;
|
||||
|
||||
@@ -8,23 +8,48 @@ BoxView::BoxView(Data * data) :
|
||||
CurveView(&m_boxWindow),
|
||||
m_data(data),
|
||||
m_boxWindow(BoxWindow(data)),
|
||||
m_selectedQuantile(-1)
|
||||
m_anyQuantileSelected(true),
|
||||
m_selectedQuantile(0)
|
||||
{
|
||||
}
|
||||
|
||||
void BoxView::reload(float dirtyVertical) {
|
||||
markRectAsDirty(bounds());
|
||||
computeLabels(Axis::Horizontal);
|
||||
void BoxView::reload(int selectedQuantile) {
|
||||
if (selectedQuantile < 0) {
|
||||
markRectAsDirty(bounds());
|
||||
computeLabels(Axis::Horizontal);
|
||||
} else {
|
||||
float calculations[5] = {m_data->minValue(), m_data->firstQuartile(), m_data->median(), m_data->thirdQuartile(), m_data->maxValue()};
|
||||
float pixelUpperBound = floatToPixel(Axis::Vertical, 0.2f)+1;
|
||||
float pixelLowerBound = floatToPixel(Axis::Vertical, 0.8)-1;
|
||||
float selectedValueInPixels = floatToPixel(Axis::Horizontal, calculations[selectedQuantile]);
|
||||
KDRect dirtyZone(KDRect(selectedValueInPixels-1, pixelLowerBound, 2, pixelUpperBound - pixelLowerBound));
|
||||
markRectAsDirty(dirtyZone);
|
||||
}
|
||||
}
|
||||
|
||||
int BoxView::selectedQuantile() {
|
||||
return m_selectedQuantile;
|
||||
}
|
||||
|
||||
void BoxView::selectQuantile(int selectedQuantile) {
|
||||
bool BoxView::selectQuantile(int selectedQuantile) {
|
||||
if (selectedQuantile < 0 || selectedQuantile > 4) {
|
||||
return false;
|
||||
}
|
||||
if (m_selectedQuantile != selectedQuantile) {
|
||||
reload(m_selectedQuantile);
|
||||
m_selectedQuantile = selectedQuantile;
|
||||
markRectAsDirty(bounds());
|
||||
reload(m_selectedQuantile);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BoxView::isAnyQuantileSelected() {
|
||||
return m_anyQuantileSelected;
|
||||
}
|
||||
|
||||
void BoxView::selectAnyQuantile(bool anyQuantileSelected) {
|
||||
if (m_anyQuantileSelected != anyQuantileSelected) {
|
||||
m_anyQuantileSelected = anyQuantileSelected;
|
||||
reload(m_selectedQuantile);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,11 +57,15 @@ void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(Axis::Horizontal, ctx, rect);
|
||||
drawLabels(Axis::Horizontal, false, ctx, rect);
|
||||
drawSegment(ctx, rect, Axis::Vertical, m_data->minValue(), 0.4f, 0.6f, KDColorBlack);
|
||||
drawSegment(ctx, rect, Axis::Vertical, m_data->firstQuartile(), 0.2f, 0.8f, KDColorBlack);
|
||||
drawSegment(ctx, rect, Axis::Vertical, m_data->median(), 0.2f, 0.8f, KDColorBlack);
|
||||
drawSegment(ctx, rect, Axis::Vertical, m_data->thirdQuartile(), 0.2f, 0.8f, KDColorBlack);
|
||||
drawSegment(ctx, rect, Axis::Vertical, m_data->maxValue(), 0.4f, 0.6f, KDColorBlack);
|
||||
float calculations[5] = {m_data->minValue(), m_data->firstQuartile(), m_data->median(), m_data->thirdQuartile(), m_data->maxValue()};
|
||||
float lowBounds[5] = {0.4f, 0.2f, 0.2f, 0.2f, 0.4f};
|
||||
float upBounds[5] = {0.6f, 0.8f, 0.8f, 0.8f, 0.6f};
|
||||
for (int k = 0; k < 5; k++) {
|
||||
drawSegment(ctx, rect, Axis::Vertical, calculations[k], lowBounds[k], upBounds[k], KDColorBlack);
|
||||
}
|
||||
if (m_anyQuantileSelected) {
|
||||
drawSegment(ctx, rect, Axis::Vertical, calculations[m_selectedQuantile], lowBounds[m_selectedQuantile], upBounds[m_selectedQuantile], KDColorRed);
|
||||
}
|
||||
drawSegment(ctx, rect, Axis::Horizontal, 0.5f, m_data->minValue(), m_data->firstQuartile(), KDColorBlack);
|
||||
drawSegment(ctx, rect, Axis::Horizontal, 0.5f, m_data->thirdQuartile(), m_data->maxValue(), KDColorBlack);
|
||||
drawSegment(ctx, rect, Axis::Horizontal, 0.2f, m_data->firstQuartile(), m_data->thirdQuartile(), KDColorBlack);
|
||||
|
||||
@@ -12,9 +12,11 @@ namespace Statistics {
|
||||
class BoxView : public CurveView {
|
||||
public:
|
||||
BoxView(Data * m_data);
|
||||
void reload(float dirtyVertical);
|
||||
void reload(int selectedQuantile);
|
||||
int selectedQuantile();
|
||||
void selectQuantile(int selectedQuantile);
|
||||
bool selectQuantile(int selectedQuantile);
|
||||
bool isAnyQuantileSelected();
|
||||
void selectAnyQuantile(bool selectAnyQuantile);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
char * label(Axis axis, int index) const override;
|
||||
@@ -23,6 +25,7 @@ private:
|
||||
BoxWindow m_boxWindow;
|
||||
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
// -1->Unselect 0->min 1->first quartile 2->median 3->third quartile 4->max
|
||||
bool m_anyQuantileSelected;
|
||||
int m_selectedQuantile;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user