##// END OF EJS Templates
Update display don"t force to rescale anyway (avoid zoom rescale bug)
perrinel -
r436:d7f549f3c548
parent child
Show More
@@ -1,160 +1,159
1 1 #include "Visualization/VisualizationGraphHelper.h"
2 2 #include "Visualization/qcustomplot.h"
3 3
4 4 #include <Data/ScalarSeries.h>
5 5
6 6 #include <Variable/Variable.h>
7 7
8 8 Q_LOGGING_CATEGORY(LOG_VisualizationGraphHelper, "VisualizationGraphHelper")
9 9
10 10 namespace {
11 11
12 12 class SqpDataContainer : public QCPGraphDataContainer {
13 13 public:
14 14 void appendGraphDataUnsorted(const QCPGraphData &data) { mData.append(data); }
15 15 };
16 16
17 17
18 18 /// Format for datetimes on a axis
19 19 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
20 20
21 21 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
22 22 /// non-time data
23 23 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
24 24 {
25 25 if (isTimeAxis) {
26 26 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
27 27 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
28 28
29 29 return dateTicker;
30 30 }
31 31 else {
32 32 // default ticker
33 33 return QSharedPointer<QCPAxisTicker>::create();
34 34 }
35 35 }
36 36
37 37 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
38 38 const SqpDateTime &dateTime)
39 39 {
40 40 qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData"
41 41 << QThread::currentThread()->objectName();
42 42 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
43 43 // Clean the graph
44 44 // NAIVE approch
45 45 scalarSeries.lockRead();
46 46 {
47 47 const auto xData = scalarSeries.xAxisData()->data();
48 48 const auto valuesData = scalarSeries.valuesData()->data();
49 49 const auto count = xData.count();
50 50 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points in cache"
51 51 << xData.count();
52 52
53 53 auto dataContainer = qcpGraph->data();
54 54 dataContainer->clear();
55 55 auto sqpDataContainer = QSharedPointer<SqpDataContainer>::create();
56 56 qcpGraph->setData(sqpDataContainer);
57 57
58 58 for (auto i = 0; i < count; ++i) {
59 59 const auto x = xData[i];
60 60 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
61 61 sqpDataContainer->appendGraphDataUnsorted(QCPGraphData(x, valuesData[i]));
62 62 }
63 63 }
64 64 sqpDataContainer->sort();
65 65 qCInfo(LOG_VisualizationGraphHelper()) << "TORM: Current points displayed"
66 66 << sqpDataContainer->size();
67 67 }
68 68 scalarSeries.unlock();
69 69
70 70
71 71 // Display all data
72 component->rescaleAxes();
73 72 component->parentPlot()->replot();
74 73 }
75 74 else {
76 75 /// @todo DEBUG
77 76 }
78 77 }
79 78
80 79 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
81 80 const SqpDateTime &dateTime)
82 81 {
83 82 auto component = plot.addGraph();
84 83
85 84 if (component) {
86 85 // // Graph data
87 86 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
88 87 true);
89 88
90 89 updateScalarData(component, scalarSeries, dateTime);
91 90
92 91 // Axes properties
93 92 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
94 93 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
95 94
96 95 auto setAxisProperties = [](auto axis, const auto &unit) {
97 96 // label (unit name)
98 97 axis->setLabel(unit.m_Name);
99 98
100 99 // ticker (depending on the type of unit)
101 100 axis->setTicker(axisTicker(unit.m_TimeUnit));
102 101 };
103 102 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
104 103 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
105 104
106 105 // Display all data
107 106 component->rescaleAxes();
108 107 plot.replot();
109 108 }
110 109 else {
111 110 qCDebug(LOG_VisualizationGraphHelper())
112 111 << QObject::tr("Can't create graph for the scalar series");
113 112 }
114 113
115 114 return component;
116 115 }
117 116
118 117 } // namespace
119 118
120 119 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
121 120 QCustomPlot &plot) noexcept
122 121 {
123 122 auto result = QVector<QCPAbstractPlottable *>{};
124 123
125 124 if (variable) {
126 125 // Gets the data series of the variable to call the creation of the right components
127 126 // according to its type
128 127 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
129 128 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
130 129 }
131 130 else {
132 131 qCDebug(LOG_VisualizationGraphHelper())
133 132 << QObject::tr("Can't create graph plottables : unmanaged data series type");
134 133 }
135 134 }
136 135 else {
137 136 qCDebug(LOG_VisualizationGraphHelper())
138 137 << QObject::tr("Can't create graph plottables : the variable is null");
139 138 }
140 139
141 140 return result;
142 141 }
143 142
144 143 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
145 144 IDataSeries *dataSeries, const SqpDateTime &dateTime)
146 145 {
147 146 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
148 147 if (plotableVect.size() == 1) {
149 148 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
150 149 }
151 150 else {
152 151 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
153 152 "Can't update Data of a scalarSeries because there is not only one component "
154 153 "associated");
155 154 }
156 155 }
157 156 else {
158 157 /// @todo DEBUG
159 158 }
160 159 }
General Comments 0
You need to be logged in to leave comments. Login now