Blame view

build2/epsilon-master/apps/statistics/multiple_boxes_view.cpp 2.18 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
55
56
57
58
59
60
61
62
  #include "multiple_boxes_view.h"
  #include <assert.h>
  
  using namespace Shared;
  
  namespace Statistics {
  
  MultipleBoxesView::MultipleBoxesView(Store * store, BoxView::Quantile * selectedQuantile) :
    MultipleDataView(store),
    m_boxView1(store, 0, nullptr, selectedQuantile, DoublePairStore::colorOfSeriesAtIndex(0), DoublePairStore::colorLightOfSeriesAtIndex(0)),
    m_boxView2(store, 1, nullptr, selectedQuantile, DoublePairStore::colorOfSeriesAtIndex(1), DoublePairStore::colorLightOfSeriesAtIndex(1)),
    m_boxView3(store, 2, nullptr, selectedQuantile, DoublePairStore::colorOfSeriesAtIndex(2), DoublePairStore::colorLightOfSeriesAtIndex(2)),
    m_axisView(store),
    m_bannerView()
  {
  }
  
  BoxView *  MultipleBoxesView::dataViewAtIndex(int index) {
    assert(index >= 0 && index < 3);
    BoxView * views[] = {&m_boxView1, &m_boxView2, &m_boxView3};
    return views[index];
  }
  
  int MultipleBoxesView::seriesOfSubviewAtIndex(int index) {
    assert(index >= 0 && index < numberOfSubviews() - 1);
    return static_cast<BoxView *>(subviewAtIndex(index))->series();
  }
  
  void MultipleBoxesView::layoutDataSubviews() {
    int numberOfDataSubviews = m_store->numberOfNonEmptySeries();
    assert(numberOfDataSubviews > 0);
    KDCoordinate bannerHeight = bannerFrame().height();
    KDCoordinate subviewHeight = (bounds().height() - bannerHeight - k_axisViewHeight)/numberOfDataSubviews;
    int displayedSubviewIndex = 0;
    for (int i = 0; i < Store::k_numberOfSeries; i++) {
      if (!m_store->seriesIsEmpty(i)) {
        KDRect frame = KDRect(0, displayedSubviewIndex*subviewHeight, bounds().width(), subviewHeight);
        dataViewAtIndex(i)->setFrame(frame);
        displayedSubviewIndex++;
      }
    }
    m_axisView.setFrame(KDRect(0, displayedSubviewIndex*subviewHeight, bounds().width(), bounds().height() - bannerHeight - displayedSubviewIndex*subviewHeight));
  }
  
  void MultipleBoxesView::reload() {
    MultipleDataView::reload();
    m_axisView.reload();
  }
  
  int MultipleBoxesView::numberOfSubviews() const {
    return MultipleDataView::numberOfSubviews() + 1; // +1 for the axis view
  }
  
  View *  MultipleBoxesView::subviewAtIndex(int index) {
    if (index == numberOfSubviews() - 1) {
      return &m_axisView;
    }
    return MultipleDataView::subviewAtIndex(index);
  }
  
  
  }