forked from NHERI-SimCenter/quoFEM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimCenterGraphPlot.cpp
148 lines (117 loc) · 3.43 KB
/
SimCenterGraphPlot.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
#include "SimCenterGraphPlot.h"
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSpinBox>
#include <qcustomplot.h>
SimCenterGraphPlot::SimCenterGraphPlot(
QString xLabel,
QString yLabel,
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 = QGuiApplication::screens()[0]->geometry();
int height = 0.2*rec.height();
int 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(
QString xLabel,
QString yLabel,
int minWidth,
int minHeight,
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);
thePlot->setMinimumWidth(minWidth);
thePlot->setMinimumHeight(minHeight);
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);
graph->setBrush(QBrush(QColor(0, 0, 255, 20))); // adding color below PDF - sy
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();
}