forked from NHERI-SimCenter/EE-UQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimCenterGraphPlot.cpp
More file actions
115 lines (91 loc) · 2.57 KB
/
SimCenterGraphPlot.cpp
File metadata and controls
115 lines (91 loc) · 2.57 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
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
#include "SimCenterGraphPlot.h"
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <MainWindow.h>
#include <QSpinBox>
#include <qcustomplot.h>
SimCenterGraphPlot::SimCenterGraphPlot(
QString xLabel,
QString yLabel,
int width = 0,
int height = 0,
QWidget *parent)
: QWidget(parent), numGraphs(0)
{
yMinValue = 0;
yMaxValue = 0;
xMinValue = 0;
xMaxValue = 0;
// create a main layout
QVBoxLayout *mainLayout = new QVBoxLayout();
//
// graphic window
//
thePlot=new QCustomPlot();
thePlot->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
thePlot->setInteractions(QCP::iSelectPlottables);
QRect rec = QApplication::desktop()->screenGeometry();
height = (height > 0) ? height : 0.2*rec.height();
width = (width > 0) ? width : 0.5*rec.width();
thePlot->setMinimumWidth(width);
thePlot->setMinimumHeight(height);
mainLayout->addWidget(thePlot);
thePlot->xAxis->setLabel(xLabel);
thePlot->yAxis->setLabel(yLabel);
// thePlot->xAxis->setScaleType(QCPAxis::stLogarithmic);
this->setLayout(mainLayout);
}
SimCenterGraphPlot::~SimCenterGraphPlot()
{
}
void
SimCenterGraphPlot::clear() {
thePlot->clearGraphs();
thePlot->clearPlottables();
numGraphs=0;
yMinValue = 1e10;
yMaxValue = -1e10;
xMinValue = 1e10;
xMaxValue = -1e10;
}
void
SimCenterGraphPlot::addLine(QVector<double> &x, QVector<double> &y, int width, int r, int g, int b) {
//
// check size of vectors
//
int numSteps = y.size();
if (numSteps != x.size()) {
qDebug() << "SimCenterGraphPlot - vectors of differing sizes";
return;
}
//
// plot data
//
graph = thePlot->addGraph();
QPen pen;
pen.setWidth(width);
pen.setColor(QColor(r,g,b));
graph->setPen(pen);
thePlot->graph(numGraphs)->setData(x, y, true);
numGraphs++;
for (int i=0; i<numSteps; i++) {
double yValue = y.at(i);
double xValue = x.at(i);
if (yValue < yMinValue)
yMinValue = yValue;
if (yValue > yMaxValue)
yMaxValue = yValue;
if (xValue < xMinValue)
xMinValue = xValue;
if (xValue > xMaxValue)
xMaxValue = xValue;
}
//
// resize axis if needed
//
thePlot->yAxis->setRange(yMinValue, yMaxValue);
thePlot->xAxis->setRange(xMinValue, xMaxValue);
thePlot->replot();
}