File: CategoryExample.C

package info (click to toggle)
witty 3.3.3%2Bdfsg-4.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 28,228 kB
  • ctags: 26,694
  • sloc: cpp: 147,809; ansic: 77,999; xml: 16,331; sh: 1,303; makefile: 198; java: 86; sql: 14
file content (136 lines) | stat: -rw-r--r-- 4,388 bytes parent folder | download
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "CategoryExample.h"
#include "Models.h"

#include "CsvUtil.h"
#include "Wt/WApplication"
#include "Wt/Chart/WStandardColorMap"
#include "Wt/Chart/WGridData"
#include "Wt/Chart/WEquidistantGridData"
#include "Wt/WFont"
#include "Wt/WString"

#include <fstream>
#include <string>
#include <iostream>

namespace {
  Wt::WStandardItemModel* readCsvFile(const std::string &fname)
  {
    WStandardItemModel *model = new WStandardItemModel(0, 0);
    std::ifstream f(fname.c_str());

    if (!f) {
      throw std::string("No .csv resource");
    }
    readFromCsv(f, model, -1, false);
    return model;
  }
}

CategoryExample::CategoryExample(WContainerWidget *parent)
  : WContainerWidget(parent)
{
  setContentAlignment(AlignCenter);
  chart_ = new WCartesian3DChart(this);
  if (chart_->isAlternative()) {
    xPlaneModelColor_ = 0;
    xPlaneModel_ = 0;
    yPlaneModel_ = 0;
    randomModel_ = 0;
    planeModel_ = 0;
    isotopeModel_ = 0;
    
    return;
  }
  chart_->setType(CategoryChart);

  Wt::WCssDecorationStyle style;
  style.setBorder(Wt::WBorder(Wt::WBorder::Solid, Wt::WBorder::Medium, Wt::black));
  chart_->setDecorationStyle(style);

  chart_->resize(600, 600);
  
  // **** Dataset
  isotopeModel_ = readCsvFile(WApplication::appRoot() + "isotope_decay.csv");
  // add some color-roles
  for (int i=1; i<isotopeModel_->rowCount(); i++) {
    for (int j=1; j<isotopeModel_->columnCount(); j++) {
      double value = Wt::asNumber(isotopeModel_->data(i, j));
      if (value < 3)
  	isotopeModel_->setData(i, j, WColor(blue), MarkerBrushColorRole);
    }
  }
  WGridData *isotopes = new WGridData(isotopeModel_);
  series_.push_back(isotopes);
  isotopes->setType(BarSeries3D);
  
  // **** Dataset
  planeModel_ = readCsvFile(WApplication::appRoot() + "hor_plane.csv");
  WGridData *horPlane = new WGridData(planeModel_);
  series_.push_back(horPlane);
  horPlane->setType(BarSeries3D);

  // **** Dataset
  randomModel_ = readCsvFile(WApplication::appRoot() + "hor_plane.csv");
  for (int i=1; i<randomModel_->rowCount(); i++) {
    for (int j=1; j<randomModel_->columnCount(); j++) {
      randomModel_->setData(i, j,Wt::asNumber(randomModel_->data(i, j)) + (rand() % 100)/100.0);
    }
  }
  WGridData *randomPlane = new WGridData(randomModel_);
  series_.push_back(randomPlane);
  randomPlane->setType(BarSeries3D);

  // **** Dataset
  yPlaneModel_ = new PlaneData(20, 20, 0, 1, 0, 1, true, 100, 100);
  WEquidistantGridData *yPlaneFunc = new WEquidistantGridData(yPlaneModel_,
							      0, 1, 0, 1);
  series_.push_back(yPlaneFunc);
  yPlaneFunc->setType(BarSeries3D);

  // **** Dataset
  xPlaneModel_ = new PlaneData(20, 20, 0, 1, 0, 1, false, 100, 100);
  WEquidistantGridData *xPlaneFunc = new WEquidistantGridData(xPlaneModel_,
							      0, 1, 0, 1);
  series_.push_back(xPlaneFunc);
  xPlaneFunc->setType(BarSeries3D);

  // **** Dataset
  xPlaneModelColor_ = new PlaneData(20, 20, 0, 1, 0, 1, false, 5, 100);
  WEquidistantGridData *xPlaneFuncColor = new WEquidistantGridData(xPlaneModelColor_, 0, 1, 0, 1);
  series_.push_back(xPlaneFuncColor);
  xPlaneFuncColor->setType(BarSeries3D);
  

  
  // Data configuration widget
  DataConfig *dataconfig = new DataConfig(chart_);
  dataconfig->addDataToCollection("Isotope data (10x10) with ColorRoles", isotopes);
  dataconfig->addDataToCollection("Horizontal Plane (10x10)", horPlane);  
  dataconfig->addDataToCollection("Random Data (10x10)", randomPlane);  
  // dataconfig->addDataToCollection("tilted plane y (20x20)", yPlaneFunc);
  // dataconfig->addDataToCollection("tilted plane x (20x20)", xPlaneFunc);
  // dataconfig->addDataToCollection("tilted plane x (20x20) with ColorRoles", xPlaneFuncColor);
  
  

  WTabWidget *configuration_ = new WTabWidget(this);
  configuration_->addTab(new ChartSettings(chart_), "General Chart Settings", Wt::WTabWidget::PreLoading);
  configuration_->addTab(dataconfig, "Data selection and configuration", Wt::WTabWidget::PreLoading);
}

CategoryExample::~CategoryExample()
{
  delete xPlaneModelColor_;
  delete xPlaneModel_;
  delete yPlaneModel_;
  delete randomModel_;
  delete planeModel_;
  delete isotopeModel_;

  std::vector<WAbstractDataSeries3D*> onChart = chart_->dataSeries();
  for (unsigned i=0; i < onChart.size(); i++)
    chart_->removeDataSeries(onChart[i]);
  for (unsigned i=0; i < series_.size(); i++)
    delete series_[i];
}