graph_view.cpp
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "graph_view.h"
#include <assert.h>
using namespace Shared;
namespace Regression {
GraphView::GraphView(Store * store, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView) :
CurveView(store, cursor, bannerView, cursorView),
m_store(store),
m_xLabels{},
m_yLabels{},
m_slope(NAN),
m_yIntercept(NAN)
{
}
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);
m_slope = m_store->slope();
m_yIntercept = m_store->yIntercept();
drawCurve(ctx, rect, nullptr, Palette::YellowDark);
for (int index = 0; index < m_store->numberOfPairs(); index++) {
drawDot(ctx, rect, m_store->get(0,index), m_store->get(1,index), Palette::Red);
}
drawDot(ctx, rect, m_store->meanOfColumn(0), m_store->meanOfColumn(1), Palette::Palette::YellowDark, true);
drawDot(ctx, rect, m_store->meanOfColumn(0), m_store->meanOfColumn(1), KDColorWhite);
}
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_slope*t+m_yIntercept;
}
}