Files
Upsilon/apps/graph/graph/graph_view.cpp
Émilie Feral c3008ca360 [apps] Improvements of MVC structure regarding curve views and ranges
Change-Id: Iec8031dbf349c34c18694dffabd02ef9c88ebf2d
2017-01-18 14:31:42 +01:00

46 lines
1.3 KiB
C++

#include "graph_view.h"
#include <assert.h>
#include <math.h>
#include <float.h>
namespace Graph {
GraphView::GraphView(FunctionStore * functionStore, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, ::BannerView * bannerView, View * cursorView) :
CurveView(graphRange, cursor, bannerView, cursorView),
m_functionStore(functionStore),
m_context(nullptr)
{
}
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);
for (int i = 0; i < m_functionStore->numberOfActiveFunctions(); i++) {
Function * f = m_functionStore->activeFunctionAtIndex(i);
drawCurve(ctx, rect, f, f->color());
}
}
void GraphView::setContext(Context * context) {
m_context = context;
}
Context * GraphView::context() const {
return m_context;
}
char * GraphView::label(Axis axis, int index) const {
return (axis == Axis::Horizontal ? (char *)m_xLabels[index] : (char *)m_yLabels[index]);
}
float GraphView::evaluateModelWithParameter(Model * curve, float abscissa) const {
Function * f = (Function *)curve;
return f->evaluateAtAbscissa(abscissa, m_context);
}
}