@@ -34,6 +34,8 struct VisualizationGraphHelper { | |||||
34 |
|
34 | |||
35 | static void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries, |
|
35 | static void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries, | |
36 | const SqpRange &dateTime); |
|
36 | const SqpRange &dateTime); | |
|
37 | ||||
|
38 | static void setYAxisRange(std::shared_ptr<Variable> variable, QCustomPlot &plot) noexcept; | |||
37 | }; |
|
39 | }; | |
38 |
|
40 | |||
39 | #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H |
|
41 | #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H |
@@ -46,7 +46,8 public: | |||||
46 | /// Returns the list of all variables used in the graph |
|
46 | /// Returns the list of all variables used in the graph | |
47 | QList<std::shared_ptr<Variable> > variables() const; |
|
47 | QList<std::shared_ptr<Variable> > variables() const; | |
48 |
|
48 | |||
49 | void setYRange(const SqpRange &range); |
|
49 | /// Sets the y-axis range based on the data of a variable | |
|
50 | void setYRange(std::shared_ptr<Variable> variable); | |||
50 | SqpRange graphRange() const noexcept; |
|
51 | SqpRange graphRange() const noexcept; | |
51 | void setGraphRange(const SqpRange &range); |
|
52 | void setGraphRange(const SqpRange &range); | |
52 |
|
53 |
@@ -75,6 +75,12 struct PlottablesCreator<T, | |||||
75 | */ |
|
75 | */ | |
76 | template <typename T, typename Enabled = void> |
|
76 | template <typename T, typename Enabled = void> | |
77 | struct PlottablesUpdater { |
|
77 | struct PlottablesUpdater { | |
|
78 | static void setPlotYAxisRange(T &, const SqpRange &, QCustomPlot &) | |||
|
79 | { | |||
|
80 | qCCritical(LOG_DataSeries()) | |||
|
81 | << QObject::tr("Can't set plot y-axis range: unmanaged data series type"); | |||
|
82 | } | |||
|
83 | ||||
78 | static void updatePlottables(T &, PlottablesMap &, const SqpRange &, bool) |
|
84 | static void updatePlottables(T &, PlottablesMap &, const SqpRange &, bool) | |
79 | { |
|
85 | { | |
80 | qCCritical(LOG_DataSeries()) |
|
86 | qCCritical(LOG_DataSeries()) | |
@@ -91,6 +97,24 template <typename T> | |||||
91 | struct PlottablesUpdater<T, |
|
97 | struct PlottablesUpdater<T, | |
92 | typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value |
|
98 | typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value | |
93 | or std::is_base_of<VectorSeries, T>::value> > { |
|
99 | or std::is_base_of<VectorSeries, T>::value> > { | |
|
100 | static void setPlotYAxisRange(T &dataSeries, const SqpRange &xAxisRange, QCustomPlot &plot) | |||
|
101 | { | |||
|
102 | auto minValue = 0., maxValue = 0.; | |||
|
103 | ||||
|
104 | dataSeries.lockRead(); | |||
|
105 | auto valuesBounds = dataSeries.valuesBounds(xAxisRange.m_TStart, xAxisRange.m_TEnd); | |||
|
106 | auto end = dataSeries.cend(); | |||
|
107 | if (valuesBounds.first != end && valuesBounds.second != end) { | |||
|
108 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; | |||
|
109 | ||||
|
110 | minValue = rangeValue(valuesBounds.first->minValue()); | |||
|
111 | maxValue = rangeValue(valuesBounds.second->maxValue()); | |||
|
112 | } | |||
|
113 | dataSeries.unlock(); | |||
|
114 | ||||
|
115 | plot.yAxis->setRange(QCPRange{minValue, maxValue}); | |||
|
116 | } | |||
|
117 | ||||
94 | static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const SqpRange &range, |
|
118 | static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const SqpRange &range, | |
95 | bool rescaleAxes) |
|
119 | bool rescaleAxes) | |
96 | { |
|
120 | { | |
@@ -139,6 +163,7 struct PlottablesUpdater<T, | |||||
139 | struct IPlottablesHelper { |
|
163 | struct IPlottablesHelper { | |
140 | virtual ~IPlottablesHelper() noexcept = default; |
|
164 | virtual ~IPlottablesHelper() noexcept = default; | |
141 | virtual PlottablesMap create(QCustomPlot &plot) const = 0; |
|
165 | virtual PlottablesMap create(QCustomPlot &plot) const = 0; | |
|
166 | virtual void setYAxisRange(const SqpRange &xAxisRange, QCustomPlot &plot) const = 0; | |||
142 | virtual void update(PlottablesMap &plottables, const SqpRange &range, |
|
167 | virtual void update(PlottablesMap &plottables, const SqpRange &range, | |
143 | bool rescaleAxes = false) const = 0; |
|
168 | bool rescaleAxes = false) const = 0; | |
144 | }; |
|
169 | }; | |
@@ -161,6 +186,11 struct PlottablesHelper : public IPlottablesHelper { | |||||
161 | PlottablesUpdater<T>::updatePlottables(m_DataSeries, plottables, range, rescaleAxes); |
|
186 | PlottablesUpdater<T>::updatePlottables(m_DataSeries, plottables, range, rescaleAxes); | |
162 | } |
|
187 | } | |
163 |
|
188 | |||
|
189 | void setYAxisRange(const SqpRange &xAxisRange, QCustomPlot &plot) const override | |||
|
190 | { | |||
|
191 | return PlottablesUpdater<T>::setPlotYAxisRange(m_DataSeries, xAxisRange, plot); | |||
|
192 | } | |||
|
193 | ||||
164 | T &m_DataSeries; |
|
194 | T &m_DataSeries; | |
165 | }; |
|
195 | }; | |
166 |
|
196 | |||
@@ -195,6 +225,19 PlottablesMap VisualizationGraphHelper::create(std::shared_ptr<Variable> variabl | |||||
195 | } |
|
225 | } | |
196 | } |
|
226 | } | |
197 |
|
227 | |||
|
228 | void VisualizationGraphHelper::setYAxisRange(std::shared_ptr<Variable> variable, | |||
|
229 | QCustomPlot &plot) noexcept | |||
|
230 | { | |||
|
231 | if (variable) { | |||
|
232 | auto helper = createHelper(variable->dataSeries()); | |||
|
233 | helper->setYAxisRange(variable->range(), plot); | |||
|
234 | } | |||
|
235 | else { | |||
|
236 | qCDebug(LOG_VisualizationGraphHelper()) | |||
|
237 | << QObject::tr("Can't set y-axis range of plot: the variable is null"); | |||
|
238 | } | |||
|
239 | } | |||
|
240 | ||||
198 | void VisualizationGraphHelper::updateData(PlottablesMap &plottables, |
|
241 | void VisualizationGraphHelper::updateData(PlottablesMap &plottables, | |
199 | std::shared_ptr<IDataSeries> dataSeries, |
|
242 | std::shared_ptr<IDataSeries> dataSeries, | |
200 | const SqpRange &dateTime) |
|
243 | const SqpRange &dateTime) |
@@ -177,9 +177,14 QList<std::shared_ptr<Variable> > VisualizationGraphWidget::variables() const | |||||
177 | return variables; |
|
177 | return variables; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 |
void VisualizationGraphWidget::setYRange( |
|
180 | void VisualizationGraphWidget::setYRange(std::shared_ptr<Variable> variable) | |
181 | { |
|
181 | { | |
182 | ui->widget->yAxis->setRange(range.m_TStart, range.m_TEnd); |
|
182 | if (!variable) { | |
|
183 | qCCritical(LOG_VisualizationGraphWidget()) << "Can't set y-axis range: variable is null"; | |||
|
184 | return; | |||
|
185 | } | |||
|
186 | ||||
|
187 | VisualizationGraphHelper::setYAxisRange(variable, *ui->widget); | |||
183 | } |
|
188 | } | |
184 |
|
189 | |||
185 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
|
190 | SqpRange VisualizationGraphWidget::graphRange() const noexcept |
@@ -271,23 +271,7 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V | |||||
271 | this->insertGraph(index, graphWidget); |
|
271 | this->insertGraph(index, graphWidget); | |
272 |
|
272 | |||
273 | graphWidget->addVariable(variable, range); |
|
273 | graphWidget->addVariable(variable, range); | |
274 |
|
274 | graphWidget->setYRange(variable); | ||
275 | // get y using variable range |
|
|||
276 | if (auto dataSeries = variable->dataSeries()) { |
|
|||
277 | dataSeries->lockRead(); |
|
|||
278 | auto valuesBounds |
|
|||
279 | = dataSeries->valuesBounds(variable->range().m_TStart, variable->range().m_TEnd); |
|
|||
280 | auto end = dataSeries->cend(); |
|
|||
281 | if (valuesBounds.first != end && valuesBounds.second != end) { |
|
|||
282 | auto rangeValue = [](const auto &value) { return std::isnan(value) ? 0. : value; }; |
|
|||
283 |
|
||||
284 | auto minValue = rangeValue(valuesBounds.first->minValue()); |
|
|||
285 | auto maxValue = rangeValue(valuesBounds.second->maxValue()); |
|
|||
286 |
|
||||
287 | graphWidget->setYRange(SqpRange{minValue, maxValue}); |
|
|||
288 | } |
|
|||
289 | dataSeries->unlock(); |
|
|||
290 | } |
|
|||
291 |
|
275 | |||
292 | return graphWidget; |
|
276 | return graphWidget; | |
293 | } |
|
277 | } |
General Comments 0
You need to be logged in to leave comments.
Login now