diff --git a/apps/statistics/box_controller.cpp b/apps/statistics/box_controller.cpp index 21e176b96..a9394ea50 100644 --- a/apps/statistics/box_controller.cpp +++ b/apps/statistics/box_controller.cpp @@ -26,7 +26,7 @@ bool BoxController::handleEvent(Ion::Events::Event event) { 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; + int nextSelectedQuantile = event == Ion::Events::Left ? (int)m_view.selectedQuantile()-1 : (int)m_view.selectedQuantile()+1; if (m_view.selectQuantile(nextSelectedQuantile)) { reloadBannerView(); return true; @@ -62,26 +62,28 @@ Responder * BoxController::tabController() const { void BoxController::reloadBannerView() { const char * calculationName[5] = {"Minimum", "Premier quartile", "Mediane", "Troisieme quartile", "Maximum"}; - m_boxBannerView.setLegendAtIndex((char *)calculationName[m_view.selectedQuantile()], 0); + m_boxBannerView.setLegendAtIndex((char *)calculationName[(int)m_view.selectedQuantile()], 0); char buffer[Constant::FloatBufferSizeInScientificMode]; float calculation = 0.0f; switch(m_view.selectedQuantile()) { - case 0: + case BoxView::Quantile::Min: calculation = m_store->minValue(); break; - case 1: + case BoxView::Quantile::FirstQuartile: calculation = m_store->firstQuartile(); break; - case 2: + case BoxView::Quantile::Median: calculation = m_store->median(); break; - case 3: + case BoxView::Quantile::ThirdQuartile: calculation = m_store->thirdQuartile(); break; - case 4: + case BoxView::Quantile::Max: calculation = m_store->maxValue(); break; + default: + break; } Float(calculation).convertFloatToText(buffer, Constant::FloatBufferSizeInScientificMode, Constant::NumberOfDigitsInMantissaInScientificMode); m_boxBannerView.setLegendAtIndex(buffer, 1); diff --git a/apps/statistics/box_view.cpp b/apps/statistics/box_view.cpp index e74780e3f..04fab2363 100644 --- a/apps/statistics/box_view.cpp +++ b/apps/statistics/box_view.cpp @@ -8,20 +8,39 @@ BoxView::BoxView(Store * store, View * bannerView) : CurveView(&m_boxRange, nullptr, bannerView, nullptr, 0.0f, 0.2f, 0.4f, 0.2f), m_store(store), m_boxRange(BoxRange(store)), - m_selectedQuantile(0) + m_selectedQuantile(Quantile::Min) { } void BoxView::reloadSelection() { - float calculations[5] = {m_store->minValue(), m_store->firstQuartile(), m_store->median(), m_store->thirdQuartile(), m_store->maxValue()}; + float calculation = 0.0f; + switch(m_selectedQuantile) { + case BoxView::Quantile::Min: + calculation = m_store->minValue(); + break; + case BoxView::Quantile::FirstQuartile: + calculation = m_store->firstQuartile(); + break; + case BoxView::Quantile::Median: + calculation = m_store->median(); + break; + case BoxView::Quantile::ThirdQuartile: + calculation = m_store->thirdQuartile(); + break; + case BoxView::Quantile::Max: + calculation = m_store->maxValue(); + break; + default: + break; + } float pixelUpperBound = floatToPixel(Axis::Vertical, 0.2f)+1; float pixelLowerBound = floatToPixel(Axis::Vertical, 0.8)-1; - float selectedValueInPixels = floatToPixel(Axis::Horizontal, calculations[m_selectedQuantile]); + float selectedValueInPixels = floatToPixel(Axis::Horizontal, calculation); KDRect dirtyZone(KDRect(selectedValueInPixels-1, pixelLowerBound, 2, pixelUpperBound - pixelLowerBound)); markRectAsDirty(dirtyZone); } -int BoxView::selectedQuantile() { +BoxView::Quantile BoxView::selectedQuantile() { return m_selectedQuantile; } @@ -29,9 +48,9 @@ bool BoxView::selectQuantile(int selectedQuantile) { if (selectedQuantile < 0 || selectedQuantile > 4) { return false; } - if (m_selectedQuantile != selectedQuantile) { + if ((int)m_selectedQuantile != selectedQuantile) { reloadSelection(); - m_selectedQuantile = selectedQuantile; + m_selectedQuantile = (Quantile)selectedQuantile; reloadSelection(); } return true; @@ -44,11 +63,16 @@ void BoxView::drawRect(KDContext * ctx, KDRect rect) const { float calculations[5] = {m_store->minValue(), m_store->firstQuartile(), m_store->median(), m_store->thirdQuartile(), m_store->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}; + /* We first draw all the vertical lines of the box and then recolor the + * the selected quantile (if there is one). As two quantiles can have the same + * value, we cannot choose line colors and then color only once the vertical + * lines. This solution could hide the highlighed line by coloring the next + * quantile if it has the same value. */ for (int k = 0; k < 5; k++) { drawSegment(ctx, rect, Axis::Vertical, calculations[k], lowBounds[k], upBounds[k], KDColorBlack); } if (isMainViewSelected()) { - drawSegment(ctx, rect, Axis::Vertical, calculations[m_selectedQuantile], lowBounds[m_selectedQuantile], upBounds[m_selectedQuantile], KDColorRed); + drawSegment(ctx, rect, Axis::Vertical, calculations[(int)m_selectedQuantile], lowBounds[(int)m_selectedQuantile], upBounds[(int)m_selectedQuantile], KDColorRed); } drawSegment(ctx, rect, Axis::Horizontal, 0.5f, m_store->minValue(), m_store->firstQuartile(), KDColorBlack); drawSegment(ctx, rect, Axis::Horizontal, 0.5f, m_store->thirdQuartile(), m_store->maxValue(), KDColorBlack); diff --git a/apps/statistics/box_view.h b/apps/statistics/box_view.h index 471747b37..ede113ac7 100644 --- a/apps/statistics/box_view.h +++ b/apps/statistics/box_view.h @@ -11,9 +11,17 @@ namespace Statistics { class BoxView : public CurveView { public: + enum class Quantile : int { + None = -1, + Min = 0, + FirstQuartile = 1, + Median = 2, + ThirdQuartile = 3, + Max = 4 + }; BoxView(Store * store, View * bannerView); void reloadSelection() override; - int selectedQuantile(); + Quantile selectedQuantile(); bool selectQuantile(int selectedQuantile); void drawRect(KDContext * ctx, KDRect rect) const override; private: @@ -21,8 +29,7 @@ private: Store * m_store; BoxRange m_boxRange; char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode]; - // -1->Unselect 0->min 1->first quartile 2->median 3->third quartile 4->max - int m_selectedQuantile; + Quantile m_selectedQuantile; }; }