[apps/stats] Adapt box vertical size to number of boxes.

This commit is contained in:
Léa Saviot
2018-05-25 15:56:37 +02:00
parent 6e9021ed35
commit ed703c20cd
3 changed files with 19 additions and 8 deletions

View File

@@ -33,8 +33,8 @@ void BoxView::reload() {
CalculPointer calculationMethods[5] = {&Store::minValue, &Store::firstQuartile, &Store::median, &Store::thirdQuartile,
&Store::maxValue};
float calculation = (m_store->*calculationMethods[(int)*m_selectedQuantile])(m_series);
float pixelUpperBound = floatToPixel(Axis::Vertical, 0.2f)+1;
float pixelLowerBound = floatToPixel(Axis::Vertical, 0.8)-1;
float pixelUpperBound = boxUpperBoundPixel();
float pixelLowerBound = boxLowerBoundPixel();
float selectedValueInPixels = floatToPixel(Axis::Horizontal, calculation)-1;
KDRect dirtyZone(KDRect(selectedValueInPixels, pixelLowerBound, 4, pixelUpperBound - pixelLowerBound));
markRectAsDirty(dirtyZone);
@@ -43,9 +43,10 @@ void BoxView::reload() {
void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, KDColorWhite);
// TODO : recompute drawing position without axis
float lowBound = 0.35f;
float upBound = 0.65f;
KDCoordinate lowBoundPixel = boxLowerBoundPixel();
KDCoordinate upBoundPixel = boxUpperBoundPixel();
float lowBound = pixelToFloat(Axis::Vertical, upBoundPixel);
float upBound = pixelToFloat(Axis::Vertical, lowBoundPixel);
double minVal = m_store->minValue(m_series);
double firstQuart = m_store->firstQuartile(m_series);
double thirdQuart = m_store->thirdQuartile(m_series);
@@ -54,8 +55,6 @@ void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
// Draw the main box
KDCoordinate firstQuartilePixels = std::round(floatToPixel(Axis::Horizontal, firstQuart));
KDCoordinate thirdQuartilePixels = std::round(floatToPixel(Axis::Horizontal, thirdQuart));
KDCoordinate lowBoundPixel = std::round(floatToPixel(Axis::Vertical, upBound));
KDCoordinate upBoundPixel = std::round(floatToPixel(Axis::Vertical, lowBound));
ctx->fillRect(KDRect(firstQuartilePixels, lowBoundPixel, thirdQuartilePixels - firstQuartilePixels+2,
upBoundPixel-lowBoundPixel), Palette::GreyWhite);
// Draw the horizontal lines linking the box to the extreme bounds
@@ -77,4 +76,13 @@ void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
}
}
KDCoordinate BoxView::boxLowerBoundPixel() const {
return bounds().height() / 2 - k_boxHeight / 2;
}
KDCoordinate BoxView::boxUpperBoundPixel() const {
return bounds().height() / 2 + k_boxHeight / 2;
}
}

View File

@@ -30,6 +30,9 @@ public:
// View
void drawRect(KDContext * ctx, KDRect rect) const override;
private:
static constexpr KDCoordinate k_boxHeight = 40;
KDCoordinate boxLowerBoundPixel() const;
KDCoordinate boxUpperBoundPixel() const;
char * label(Axis axis, int index) const override { return nullptr; }
Store * m_store;
BoxRange m_boxRange;

View File

@@ -25,7 +25,7 @@ public:
View * subviewAtIndex(int index) override;
private:
static constexpr KDCoordinate k_axisViewHeight = 20;
static constexpr KDCoordinate k_axisViewHeight = 21;
BoxView m_boxView1;
BoxView m_boxView2;
BoxView m_boxView3;