From e1b39b6f3a8eac007119174e0020f617aeff0eec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9a=20Saviot?= Date: Tue, 29 May 2018 16:48:08 +0200 Subject: [PATCH] [apps/stats] Fix box drawing and dirtying --- apps/statistics/box_view.cpp | 26 ++++++++++++++++++++----- apps/statistics/box_view.h | 2 ++ apps/statistics/multiple_boxes_view.cpp | 4 ++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/apps/statistics/box_view.cpp b/apps/statistics/box_view.cpp index 3338ec631..c43212fa3 100644 --- a/apps/statistics/box_view.cpp +++ b/apps/statistics/box_view.cpp @@ -24,16 +24,32 @@ bool BoxView::selectQuantile(int selectedQuantile) { return false; } if ((int)*m_selectedQuantile != selectedQuantile) { - reload(); + reloadQuantile(); *m_selectedQuantile = (Quantile)selectedQuantile; - reload(); + reloadQuantile(); } return true; } +void BoxView::reloadQuantile() { + CurveView::reload(); + KDCoordinate minY = boxLowerBoundPixel(); + KDCoordinate maxY = boxUpperBoundPixel(); + CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile, &Store::maxValue}; + double calculation = (m_store->*calculationMethods[(int)*m_selectedQuantile])(m_series); + KDCoordinate minX = std::round(floatToPixel(Axis::Horizontal, calculation)); + KDRect dirtyRect = KDRect(minX, minY, k_quantileBarWidth, maxY - minY); + markRectAsDirty(dirtyRect); +} + void BoxView::reload() { CurveView::reload(); - markRectAsDirty(bounds()); + KDCoordinate minY = boxLowerBoundPixel(); + KDCoordinate maxY = boxUpperBoundPixel(); + KDCoordinate minX = std::round(floatToPixel(Axis::Horizontal, m_store->minValue(m_series))); + KDCoordinate maxX = std::round(floatToPixel(Axis::Horizontal, m_store->maxValue(m_series))); + KDRect dirtyRect = KDRect(minX, minY, maxX - minX + k_quantileBarWidth, maxY - minY + k_quantileBarWidth); + markRectAsDirty(dirtyRect); } void BoxView::drawRect(KDContext * ctx, KDRect rect) const { @@ -69,10 +85,10 @@ void BoxView::drawRect(KDContext * ctx, KDRect rect) const { * lines. This solution could hide the highlighted 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], lowBound, upBound, Palette::GreyMiddle, 2); + drawSegment(ctx, rect, Axis::Vertical, calculations[k], lowBound, upBound, Palette::GreyMiddle, k_quantileBarWidth); } if (isMainViewSelected()) { - drawSegment(ctx, rect, Axis::Vertical, calculations[(int)*m_selectedQuantile], lowBound, upBound, Palette::YellowDark, 2); + drawSegment(ctx, rect, Axis::Vertical, calculations[(int)*m_selectedQuantile], lowBound, upBound, Palette::YellowDark, k_quantileBarWidth); } } diff --git a/apps/statistics/box_view.h b/apps/statistics/box_view.h index 43ce455d6..ab4b87b34 100644 --- a/apps/statistics/box_view.h +++ b/apps/statistics/box_view.h @@ -25,6 +25,7 @@ public: Quantile selectedQuantile() const { return *m_selectedQuantile; } bool selectQuantile(int selectedQuantile); int series() const { return m_series; } + void reloadQuantile(); // CurveView void reload() override; @@ -33,6 +34,7 @@ public: void drawRect(KDContext * ctx, KDRect rect) const override; private: static constexpr KDCoordinate k_boxHeight = 40; + static constexpr KDCoordinate k_quantileBarWidth = 2; KDCoordinate boxLowerBoundPixel() const; KDCoordinate boxUpperBoundPixel() const; char * label(Axis axis, int index) const override { return nullptr; } diff --git a/apps/statistics/multiple_boxes_view.cpp b/apps/statistics/multiple_boxes_view.cpp index 79a184946..edb29502d 100644 --- a/apps/statistics/multiple_boxes_view.cpp +++ b/apps/statistics/multiple_boxes_view.cpp @@ -8,8 +8,8 @@ namespace Statistics { MultipleBoxesView::MultipleBoxesView(BoxController * controller, Store * store, BoxView::Quantile * selectedQuantile) : MultipleDataView(store), m_boxView1(controller, store, 0, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(0), FloatPairStore::colorLightOfSeriesAtIndex(0)), - m_boxView2(controller, store, 1, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(1), FloatPairStore::colorLightOfSeriesAtIndex(0)), - m_boxView3(controller, store, 2, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(2), FloatPairStore::colorLightOfSeriesAtIndex(0)), + m_boxView2(controller, store, 1, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(1), FloatPairStore::colorLightOfSeriesAtIndex(1)), + m_boxView3(controller, store, 2, nullptr, selectedQuantile, FloatPairStore::colorOfSeriesAtIndex(2), FloatPairStore::colorLightOfSeriesAtIndex(2)), m_axisView(store), m_bannerView() {