Files
Upsilon/apps/graph/graph/graph_view.cpp
Émilie Feral 39dab5125c [apps] Add angle unit preference in apps
Change-Id: I25eb760883d164563cb3059d73e8d1fff92ad6da
2017-02-06 16:30:48 +01:00

52 lines
1.4 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),
m_preferences(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;
}
void GraphView::setPreferences(Preferences * preferences) {
m_preferences = preferences;
}
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, m_preferences->angleUnit());
}
}