Blame view

build6/epsilon-master/apps/regression/graph_view.cpp 2.06 KB
6663b6c9   adorian   projet complet av...
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
47
48
49
50
51
52
53
54
  #include "graph_view.h"
  #include "model/model.h"
  #include <apps/apps_container.h>
  #include <poincare/context.h>
  #include <assert.h>
  
  using namespace Shared;
  
  namespace Regression {
  
  GraphView::GraphView(Store * store, CurveViewCursor * cursor, BannerView * bannerView, View * cursorView, Responder * controller) :
    CurveView(store, cursor, bannerView, cursorView),
    m_store(store),
    m_xLabels{},
    m_yLabels{},
    m_controller(controller)
  {
  }
  
  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 series = 0; series < Store::k_numberOfSeries; series++) {
      if (!m_store->seriesIsEmpty(series)) {
        KDColor color = Palette::DataColor[series];
        Model * seriesModel = m_store->modelForSeries(series);
        Poincare::Context * globContext = const_cast<AppsContainer *>(static_cast<const AppsContainer *>(m_controller->app()->container()))->globalContext();
        drawCurve(ctx, rect, [](float abscissa, void * model, void * context) {
            Model * regressionModel = static_cast<Model *>(model);
            double * regressionCoefficients = static_cast<double *>(context);
            return (float)regressionModel->evaluate(regressionCoefficients, abscissa);
            },
            seriesModel, m_store->coefficientsForSeries(series, globContext), color);
        for (int index = 0; index < m_store->numberOfPairsOfSeries(series); index++) {
          drawDot(ctx, rect, m_store->get(series, 0, index), m_store->get(series, 1, index), color);
        }
        drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), color, true);
        drawDot(ctx, rect, m_store->meanOfColumn(series, 0), m_store->meanOfColumn(series, 1), KDColorWhite);
      }
    }
  }
  
  char * GraphView::label(Axis axis, int index) const {
    if (axis == Axis::Vertical) {
      return (char *)m_yLabels[index];
    }
    return (char *)m_xLabels[index];
  }
  
  }