mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/statistics] Make histogram view and box view inherits from curve
view with banner Change-Id: Iab25cb2442ee7b20a97dfa4e4fce9742f16e5a96
This commit is contained in:
@@ -20,7 +20,7 @@ View * BoxController::view() {
|
||||
|
||||
bool BoxController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Up) {
|
||||
m_view.selectAnyQuantile(false);
|
||||
m_view.selectMainView(false);
|
||||
app()->setFirstResponder(tabController());
|
||||
return true;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ bool BoxController::handleEvent(Ion::Events::Event event) {
|
||||
}
|
||||
|
||||
void BoxController::didBecomeFirstResponder() {
|
||||
m_view.selectAnyQuantile(true);
|
||||
m_view.selectMainView(true);
|
||||
m_view.reload(-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,15 +5,18 @@
|
||||
namespace Statistics {
|
||||
|
||||
BoxView::BoxView(Data * data) :
|
||||
CurveView(&m_boxWindow, 0.0f, 0.2f, 0.4f, 0.2f),
|
||||
CurveViewWithBanner(&m_boxWindow, 0.0f, 0.2f, 0.4f, 0.2f),
|
||||
m_data(data),
|
||||
m_boxWindow(BoxWindow(data)),
|
||||
m_anyQuantileSelected(true),
|
||||
m_selectedQuantile(0),
|
||||
m_bannerView(BoxBannerView(data, this))
|
||||
{
|
||||
}
|
||||
|
||||
void BoxView::reloadMainView() {
|
||||
reload(m_selectedQuantile);
|
||||
}
|
||||
|
||||
void BoxView::reload(int selectedQuantile) {
|
||||
if (selectedQuantile < 0) {
|
||||
markRectAsDirty(bounds());
|
||||
@@ -28,6 +31,7 @@ void BoxView::reload(int selectedQuantile) {
|
||||
}
|
||||
m_bannerView.reload();
|
||||
}
|
||||
|
||||
int BoxView::selectedQuantile() {
|
||||
return m_selectedQuantile;
|
||||
}
|
||||
@@ -44,18 +48,6 @@ bool BoxView::selectQuantile(int selectedQuantile) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BoxView::isAnyQuantileSelected() {
|
||||
return m_anyQuantileSelected;
|
||||
}
|
||||
|
||||
void BoxView::selectAnyQuantile(bool anyQuantileSelected) {
|
||||
if (m_anyQuantileSelected != anyQuantileSelected) {
|
||||
m_anyQuantileSelected = anyQuantileSelected;
|
||||
reload(m_selectedQuantile);
|
||||
layoutSubviews();
|
||||
}
|
||||
}
|
||||
|
||||
void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
@@ -66,7 +58,7 @@ void BoxView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
for (int k = 0; k < 5; k++) {
|
||||
drawSegment(ctx, rect, Axis::Vertical, calculations[k], lowBounds[k], upBounds[k], KDColorBlack);
|
||||
}
|
||||
if (m_anyQuantileSelected) {
|
||||
if (m_mainViewSelected) {
|
||||
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);
|
||||
@@ -82,21 +74,8 @@ char * BoxView::label(Axis axis, int index) const {
|
||||
return (char *)m_labels[index];
|
||||
}
|
||||
|
||||
int BoxView::numberOfSubviews() const {
|
||||
return 1;
|
||||
};
|
||||
|
||||
View * BoxView::subviewAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
View * BoxView::bannerView() {
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
void BoxView::layoutSubviews() {
|
||||
KDRect bannerFrame(KDRect(0, bounds().height()- k_bannerHeight, bounds().width(), k_bannerHeight));
|
||||
if (!m_anyQuantileSelected) {
|
||||
bannerFrame = KDRectZero;
|
||||
}
|
||||
m_bannerView.setFrame(bannerFrame);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,30 +6,26 @@
|
||||
#include "box_banner_view.h"
|
||||
#include "box_window.h"
|
||||
#include "../constant.h"
|
||||
#include "../curve_view.h"
|
||||
#include "../curve_view_with_banner.h"
|
||||
|
||||
namespace Statistics {
|
||||
|
||||
class BoxView : public CurveView {
|
||||
class BoxView : public CurveViewWithBanner {
|
||||
public:
|
||||
BoxView(Data * m_data);
|
||||
void reloadMainView() override;
|
||||
void reload(int selectedQuantile);
|
||||
int selectedQuantile();
|
||||
bool selectQuantile(int selectedQuantile);
|
||||
bool isAnyQuantileSelected();
|
||||
void selectAnyQuantile(bool selectAnyQuantile);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_bannerHeight = 30;
|
||||
char * label(Axis axis, int index) const override;
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
View * bannerView() override;
|
||||
Data * m_data;
|
||||
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;
|
||||
BoxBannerView m_bannerView;
|
||||
};
|
||||
|
||||
@@ -37,25 +37,25 @@ HistogramParameterController * HistogramController::histogramParameterController
|
||||
|
||||
bool HistogramController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::Down) {
|
||||
if (!m_view.selectedBins()) {
|
||||
if (!m_view.isMainViewSelected()) {
|
||||
headerViewController()->setSelectedButton(-1);
|
||||
m_view.selectBins(true);
|
||||
m_view.selectMainView(true);
|
||||
m_view.reload(m_data->selectedBar());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (event == Ion::Events::Up) {
|
||||
if (!m_view.selectedBins()) {
|
||||
if (!m_view.isMainViewSelected()) {
|
||||
headerViewController()->setSelectedButton(-1);
|
||||
app()->setFirstResponder(tabController());
|
||||
return true;
|
||||
}
|
||||
m_view.selectBins(false);
|
||||
m_view.selectMainView(false);
|
||||
headerViewController()->setSelectedButton(0);
|
||||
return true;
|
||||
}
|
||||
if (m_view.selectedBins() && (event == Ion::Events::Left || event == Ion::Events::Right)) {
|
||||
if (m_view.isMainViewSelected() && (event == Ion::Events::Left || event == Ion::Events::Right)) {
|
||||
int direction = event == Ion::Events::Left ? -1 : 1;
|
||||
m_view.reload(m_data->selectedBar());
|
||||
if (m_data->selectNextBarToward(direction)) {
|
||||
@@ -70,7 +70,7 @@ bool HistogramController::handleEvent(Ion::Events::Event event) {
|
||||
|
||||
void HistogramController::didBecomeFirstResponder() {
|
||||
headerViewController()->setSelectedButton(-1);
|
||||
m_view.selectBins(true);
|
||||
m_view.selectMainView(true);
|
||||
m_view.reload(NAN);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,13 +5,16 @@
|
||||
namespace Statistics {
|
||||
|
||||
HistogramView::HistogramView(Data * data) :
|
||||
CurveView(data, 0.2f, 0.1f, 0.4f, 0.1f),
|
||||
CurveViewWithBanner(data, 0.2f, 0.1f, 0.4f, 0.1f),
|
||||
m_data(data),
|
||||
m_selectedBins(true),
|
||||
m_bannerView(BannerView(data))
|
||||
{
|
||||
}
|
||||
|
||||
void HistogramView::reloadMainView() {
|
||||
reload(m_data->selectedBar());
|
||||
}
|
||||
|
||||
void HistogramView::reload(float dirtyZoneCenter) {
|
||||
if (isnan(dirtyZoneCenter)) {
|
||||
markRectAsDirty(bounds());
|
||||
@@ -28,24 +31,11 @@ void HistogramView::reload(float dirtyZoneCenter) {
|
||||
m_bannerView.reload();
|
||||
}
|
||||
|
||||
bool HistogramView::selectedBins() {
|
||||
return m_selectedBins;
|
||||
}
|
||||
|
||||
void HistogramView::selectBins(bool selectedBins) {
|
||||
if (m_selectedBins != selectedBins) {
|
||||
reload(m_data->selectedBar());
|
||||
m_selectedBins = selectedBins;
|
||||
reload(m_data->selectedBar());
|
||||
layoutSubviews();
|
||||
}
|
||||
}
|
||||
|
||||
void HistogramView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
drawLabels(ctx, rect, Axis::Horizontal, true);
|
||||
if (m_selectedBins) {
|
||||
if (m_mainViewSelected) {
|
||||
drawHistogram(ctx, rect, nullptr, m_data->firsBarAbscissa(), m_data->barWidth(), true, KDColorBlack, KDColorRed,
|
||||
m_data->selectedBar() - m_data->barWidth()/2, m_data->selectedBar() + m_data->barWidth()/2);
|
||||
} else {
|
||||
@@ -53,23 +43,6 @@ void HistogramView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
}
|
||||
}
|
||||
|
||||
int HistogramView::numberOfSubviews() const {
|
||||
return 1;
|
||||
};
|
||||
|
||||
View * HistogramView::subviewAtIndex(int index) {
|
||||
assert(index == 0);
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
void HistogramView::layoutSubviews() {
|
||||
KDRect bannerFrame(KDRect(0, bounds().height()- k_bannerHeight, bounds().width(), k_bannerHeight));
|
||||
if (!m_selectedBins) {
|
||||
bannerFrame = KDRectZero;
|
||||
}
|
||||
m_bannerView.setFrame(bannerFrame);
|
||||
}
|
||||
|
||||
char * HistogramView::label(Axis axis, int index) const {
|
||||
if (axis == Axis::Vertical) {
|
||||
return nullptr;
|
||||
@@ -77,6 +50,10 @@ char * HistogramView::label(Axis axis, int index) const {
|
||||
return (char *)m_labels[index];
|
||||
}
|
||||
|
||||
View * HistogramView::bannerView() {
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
float HistogramView::evaluateModelWithParameter(Model * curve, float t) const {
|
||||
return (float)m_data->heightForBarAtValue(t)/(float)m_data->totalSize();
|
||||
}
|
||||
|
||||
@@ -5,27 +5,23 @@
|
||||
#include "data.h"
|
||||
#include "banner_view.h"
|
||||
#include "../constant.h"
|
||||
#include "../curve_view.h"
|
||||
#include "../curve_view_with_banner.h"
|
||||
|
||||
namespace Statistics {
|
||||
|
||||
class HistogramView : public CurveView {
|
||||
class HistogramView : public CurveViewWithBanner {
|
||||
public:
|
||||
HistogramView(Data * m_data);
|
||||
void reloadMainView() override;
|
||||
void reload(float dirtyZoneCenter);
|
||||
bool selectedBins();
|
||||
void selectBins(bool selectedBins);
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_bannerHeight = 30;
|
||||
int numberOfSubviews() const override;
|
||||
View * subviewAtIndex(int index) override;
|
||||
void layoutSubviews() override;
|
||||
char * label(Axis axis, int index) const override;
|
||||
View * bannerView() override;
|
||||
float evaluateModelWithParameter(Model * curve, float t) const override;
|
||||
Data * m_data;
|
||||
char m_labels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
bool m_selectedBins;
|
||||
BannerView m_bannerView;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user