Files
Upsilon/apps/regression/graph_view.cpp
Émilie Feral affda5eae9 [apps] Modular reimplementation of application models (stores and
ranges) and of curve views/curve view controllers.

Change-Id: If4ca9bf1bec024917ef540a3fc7baefa8700f7ba
2017-01-10 13:35:19 +01:00

39 lines
1.2 KiB
C++

#include "graph_view.h"
#include <assert.h>
#include <math.h>
namespace Regression {
GraphView::GraphView(Store * store, CurveViewCursor * cursor, View * bannerView, View * cursorView) :
CurveView(store, cursor, bannerView, cursorView, 0.05f, 0.05f, 0.25f, 0.05f),
m_store(store)
{
}
void GraphView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(rect, KDColorWhite);
drawGrid(ctx, rect);
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_store->numberOfPairs(); index++) {
drawDot(ctx, rect, m_store->get(0,index), m_store->get(1,index), KDColorBlue, KDSize(k_dotSize, k_dotSize));
}
drawDot(ctx, rect, m_store->meanOfColumn(0), m_store->meanOfColumn(1), KDColorGreen, 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];
}
float GraphView::evaluateModelWithParameter(Model * curve, float t) const {
return m_store->yValueForXValue(t);
}
}