mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps//regression] Create a graph view
Change-Id: I434e3647f7acf7b1358203f894d5847b787a2375
This commit is contained in:
@@ -4,6 +4,7 @@ app_objs += $(addprefix apps/regression/,\
|
||||
calculation_controller.o\
|
||||
data.o\
|
||||
graph_controller.o\
|
||||
graph_view.o\
|
||||
)
|
||||
|
||||
app_images += apps/regression/regression_icon.png
|
||||
|
||||
56
apps/regression/graph_view.cpp
Normal file
56
apps/regression/graph_view.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "graph_view.h"
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace Regression {
|
||||
|
||||
GraphView::GraphView(Data * data) :
|
||||
CurveViewWithBanner(data, 0.2f, 0.2f, 0.4f, 0.2f),
|
||||
m_data(data),
|
||||
m_bannerView(BannerView(data))
|
||||
{
|
||||
}
|
||||
|
||||
void GraphView::reloadSelection() {
|
||||
float pixelXSelection = roundf(floatToPixel(Axis::Horizontal, m_data->xCursorPosition()));
|
||||
float pixelYSelection = roundf(floatToPixel(Axis::Vertical, m_data->yCursorPosition()));
|
||||
KDRect dirtyZone(KDRect(pixelXSelection - k_dotSize/2, pixelYSelection - k_dotSize/2, k_dotSize, k_dotSize));
|
||||
markRectAsDirty(dirtyZone);
|
||||
m_bannerView.reload();
|
||||
}
|
||||
|
||||
void GraphView::reload() {
|
||||
markRectAsDirty(bounds());
|
||||
computeLabels(Axis::Horizontal);
|
||||
computeLabels(Axis::Vertical);
|
||||
m_bannerView.reload();
|
||||
}
|
||||
|
||||
void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
|
||||
ctx->fillRect(rect, KDColorWhite);
|
||||
drawAxes(ctx, rect, Axis::Horizontal);
|
||||
drawAxes(ctx, rect, Axis::Vertical);
|
||||
drawLabels(ctx, rect, Axis::Horizontal, true);
|
||||
drawLabels(ctx, rect, Axis::Vertical, true);
|
||||
drawCurve(ctx, rect, nullptr, KDColorRed);
|
||||
for (int index = 0; index < m_data->numberOfPairs(); index++) {
|
||||
drawDot(ctx, rect, m_data->xValueAtIndex(index), m_data->yValueAtIndex(index), KDColorBlue, KDSize(k_dotSize, k_dotSize));
|
||||
}
|
||||
}
|
||||
|
||||
char * GraphView::label(Axis axis, int index) const {
|
||||
if (axis == Axis::Vertical) {
|
||||
return (char *)m_yLabels[index];
|
||||
}
|
||||
return (char *)m_xLabels[index];
|
||||
}
|
||||
|
||||
View * GraphView::bannerView() {
|
||||
return &m_bannerView;
|
||||
}
|
||||
|
||||
float GraphView::evaluateModelWithParameter(Model * curve, float t) const {
|
||||
return m_data->yValueForXValue(t);
|
||||
}
|
||||
|
||||
}
|
||||
32
apps/regression/graph_view.h
Normal file
32
apps/regression/graph_view.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef REGRESSION_GRAPH_VIEW_H
|
||||
#define REGRESSION_GRAPH_VIEW_H
|
||||
|
||||
#include <escher.h>
|
||||
#include "data.h"
|
||||
#include "banner_view.h"
|
||||
#include "../constant.h"
|
||||
#include "../curve_view_with_banner.h"
|
||||
|
||||
namespace Regression {
|
||||
|
||||
class GraphView : public CurveViewWithBanner {
|
||||
public:
|
||||
GraphView(Data * m_data);
|
||||
void reloadSelection() override;
|
||||
void reload();
|
||||
void drawRect(KDContext * ctx, KDRect rect) const override;
|
||||
private:
|
||||
constexpr static KDCoordinate k_dotSize = 4;
|
||||
char * label(Axis axis, int index) const override;
|
||||
View * bannerView() override;
|
||||
float evaluateModelWithParameter(Model * curve, float t) const override;
|
||||
Data * m_data;
|
||||
char m_xLabels[k_maxNumberOfXLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
char m_yLabels[k_maxNumberOfYLabels][Constant::FloatBufferSizeInScientificMode];
|
||||
BannerView m_bannerView;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user