@@ -210,23 +210,22 public: | |||||
210 | return it == cbegin() ? cend() : --it; |
|
210 | return it == cbegin() ? cend() : --it; | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 |
std::pair<DataSeriesIterator, DataSeriesIterator> |
|
213 | std::pair<DataSeriesIterator, DataSeriesIterator> xAxisRange(double minXAxisData, | |
|
214 | double maxXAxisData) const override | |||
214 | { |
|
215 | { | |
215 | if (min > max) { |
|
216 | if (minXAxisData > maxXAxisData) { | |
216 | std::swap(min, max); |
|
217 | std::swap(minXAxisData, maxXAxisData); | |
217 | } |
|
218 | } | |
218 |
|
219 | |||
219 | auto begin = cbegin(); |
|
220 | auto begin = cbegin(); | |
220 | auto end = cend(); |
|
221 | auto end = cend(); | |
221 |
|
222 | |||
222 | auto lowerIt |
|
223 | auto lowerIt = std::lower_bound( | |
223 | = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) { |
|
224 | begin, end, minXAxisData, | |
224 | return itValue.x() < value; |
|
225 | [](const auto &itValue, const auto &value) { return itValue.x() < value; }); | |
225 | }); |
|
226 | auto upperIt = std::upper_bound( | |
226 | auto upperIt |
|
227 | begin, end, maxXAxisData, | |
227 |
|
|
228 | [](const auto &value, const auto &itValue) { return value < itValue.x(); }); | |
228 | return value < itValue.x(); |
|
|||
229 | }); |
|
|||
230 |
|
229 | |||
231 | return std::make_pair(lowerIt, upperIt); |
|
230 | return std::make_pair(lowerIt, upperIt); | |
232 | } |
|
231 | } |
@@ -78,8 +78,10 public: | |||||
78 | /// equal to the value passed in parameter, or the end iterator if there is no matching value |
|
78 | /// equal to the value passed in parameter, or the end iterator if there is no matching value | |
79 | virtual DataSeriesIterator maxXAxisData(double maxXAxisData) const = 0; |
|
79 | virtual DataSeriesIterator maxXAxisData(double maxXAxisData) const = 0; | |
80 |
|
80 | |||
81 | virtual std::pair<DataSeriesIterator, DataSeriesIterator> subData(double min, |
|
81 | /// @return the iterators pointing to the range of data whose x-axis values are between min and | |
82 | double max) const = 0; |
|
82 | /// max passed in parameters | |
|
83 | virtual std::pair<DataSeriesIterator, DataSeriesIterator> | |||
|
84 | xAxisRange(double minXAxisData, double maxXAxisData) const = 0; | |||
83 |
|
85 | |||
84 | // /////// // |
|
86 | // /////// // | |
85 | // Mutexes // |
|
87 | // Mutexes // |
@@ -18,7 +18,7 std::shared_ptr<IDataSeries> ScalarSeries::subDataSeries(const SqpRange &range) | |||||
18 | auto subValuesData = QVector<double>(); |
|
18 | auto subValuesData = QVector<double>(); | |
19 | this->lockRead(); |
|
19 | this->lockRead(); | |
20 | { |
|
20 | { | |
21 |
auto bounds = |
|
21 | auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); | |
22 | for (auto it = bounds.first; it != bounds.second; ++it) { |
|
22 | for (auto it = bounds.first; it != bounds.second; ++it) { | |
23 | subXAxisData.append(it->x()); |
|
23 | subXAxisData.append(it->x()); | |
24 | subValuesData.append(it->value()); |
|
24 | subValuesData.append(it->value()); |
@@ -24,7 +24,7 std::shared_ptr<IDataSeries> VectorSeries::subDataSeries(const SqpRange &range) | |||||
24 |
|
24 | |||
25 | this->lockRead(); |
|
25 | this->lockRead(); | |
26 | { |
|
26 | { | |
27 |
auto bounds = |
|
27 | auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); | |
28 | for (auto it = bounds.first; it != bounds.second; ++it) { |
|
28 | for (auto it = bounds.first; it != bounds.second; ++it) { | |
29 | subXAxisData.append(it->x()); |
|
29 | subXAxisData.append(it->x()); | |
30 | subXValuesData.append(it->value(0)); |
|
30 | subXValuesData.append(it->value(0)); |
@@ -38,11 +38,11 private slots: | |||||
38 | void testMaxXAxisData(); |
|
38 | void testMaxXAxisData(); | |
39 |
|
39 | |||
40 | /// Input test data |
|
40 | /// Input test data | |
41 |
/// @sa test |
|
41 | /// @sa testXAxisRange() | |
42 |
void test |
|
42 | void testXAxisRange_data(); | |
43 |
|
43 | |||
44 |
/// Tests get |
|
44 | /// Tests get x-axis range of a data series | |
45 |
void test |
|
45 | void testXAxisRange(); | |
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 | void TestDataSeries::testCtor_data() |
|
48 | void TestDataSeries::testCtor_data() | |
@@ -289,20 +289,20 void TestDataSeries::testMaxXAxisData() | |||||
289 | } |
|
289 | } | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 |
void TestDataSeries::test |
|
292 | void TestDataSeries::testXAxisRange_data() | |
293 | { |
|
293 | { | |
294 | // ////////////// // |
|
294 | // ////////////// // | |
295 | // Test structure // |
|
295 | // Test structure // | |
296 | // ////////////// // |
|
296 | // ////////////// // | |
297 |
|
297 | |||
298 |
// Data series to get |
|
298 | // Data series to get x-axis range | |
299 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); |
|
299 | QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries"); | |
300 |
|
300 | |||
301 | // Min/max values |
|
301 | // Min/max values | |
302 | QTest::addColumn<double>("min"); |
|
302 | QTest::addColumn<double>("min"); | |
303 | QTest::addColumn<double>("max"); |
|
303 | QTest::addColumn<double>("max"); | |
304 |
|
304 | |||
305 |
// Expected values |
|
305 | // Expected values | |
306 | QTest::addColumn<QVector<double> >("expectedXAxisData"); |
|
306 | QTest::addColumn<QVector<double> >("expectedXAxisData"); | |
307 | QTest::addColumn<QVector<double> >("expectedValuesData"); |
|
307 | QTest::addColumn<QVector<double> >("expectedValuesData"); | |
308 |
|
308 | |||
@@ -310,29 +310,37 void TestDataSeries::testSubdata_data() | |||||
310 | // Test cases // |
|
310 | // Test cases // | |
311 | // ////////// // |
|
311 | // ////////// // | |
312 |
|
312 | |||
313 |
QTest::newRow(" |
|
313 | QTest::newRow("xAxisRange1") << createSeries({1., 2., 3., 4., 5.}, | |
|
314 | {100., 200., 300., 400., 500.}) | |||
314 | << -1. << 3.2 << QVector<double>{1., 2., 3.} |
|
315 | << -1. << 3.2 << QVector<double>{1., 2., 3.} | |
315 | << QVector<double>{100., 200., 300.}; |
|
316 | << QVector<double>{100., 200., 300.}; | |
316 |
QTest::newRow(" |
|
317 | QTest::newRow("xAxisRange2") << createSeries({1., 2., 3., 4., 5.}, | |
|
318 | {100., 200., 300., 400., 500.}) | |||
317 | << 1. << 4. << QVector<double>{1., 2., 3., 4.} |
|
319 | << 1. << 4. << QVector<double>{1., 2., 3., 4.} | |
318 | << QVector<double>{100., 200., 300., 400.}; |
|
320 | << QVector<double>{100., 200., 300., 400.}; | |
319 |
QTest::newRow(" |
|
321 | QTest::newRow("xAxisRange3") << createSeries({1., 2., 3., 4., 5.}, | |
|
322 | {100., 200., 300., 400., 500.}) | |||
320 | << 1. << 3.9 << QVector<double>{1., 2., 3.} |
|
323 | << 1. << 3.9 << QVector<double>{1., 2., 3.} | |
321 | << QVector<double>{100., 200., 300.}; |
|
324 | << QVector<double>{100., 200., 300.}; | |
322 |
QTest::newRow(" |
|
325 | QTest::newRow("xAxisRange4") << createSeries({1., 2., 3., 4., 5.}, | |
|
326 | {100., 200., 300., 400., 500.}) | |||
323 | << 0. << 0.9 << QVector<double>{} << QVector<double>{}; |
|
327 | << 0. << 0.9 << QVector<double>{} << QVector<double>{}; | |
324 |
QTest::newRow(" |
|
328 | QTest::newRow("xAxisRange5") << createSeries({1., 2., 3., 4., 5.}, | |
|
329 | {100., 200., 300., 400., 500.}) | |||
325 | << 0. << 1. << QVector<double>{1.} << QVector<double>{100.}; |
|
330 | << 0. << 1. << QVector<double>{1.} << QVector<double>{100.}; | |
326 |
QTest::newRow(" |
|
331 | QTest::newRow("xAxisRange6") << createSeries({1., 2., 3., 4., 5.}, | |
|
332 | {100., 200., 300., 400., 500.}) | |||
327 | << 2.1 << 6. << QVector<double>{3., 4., 5.} |
|
333 | << 2.1 << 6. << QVector<double>{3., 4., 5.} | |
328 | << QVector<double>{300., 400., 500.}; |
|
334 | << QVector<double>{300., 400., 500.}; | |
329 |
QTest::newRow(" |
|
335 | QTest::newRow("xAxisRange7") << createSeries({1., 2., 3., 4., 5.}, | |
|
336 | {100., 200., 300., 400., 500.}) | |||
330 | << 6. << 9. << QVector<double>{} << QVector<double>{}; |
|
337 | << 6. << 9. << QVector<double>{} << QVector<double>{}; | |
331 |
QTest::newRow(" |
|
338 | QTest::newRow("xAxisRange8") << createSeries({1., 2., 3., 4., 5.}, | |
|
339 | {100., 200., 300., 400., 500.}) | |||
332 | << 5. << 9. << QVector<double>{5.} << QVector<double>{500.}; |
|
340 | << 5. << 9. << QVector<double>{5.} << QVector<double>{500.}; | |
333 | } |
|
341 | } | |
334 |
|
342 | |||
335 |
void TestDataSeries::test |
|
343 | void TestDataSeries::testXAxisRange() | |
336 | { |
|
344 | { | |
337 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); |
|
345 | QFETCH(std::shared_ptr<ScalarSeries>, dataSeries); | |
338 | QFETCH(double, min); |
|
346 | QFETCH(double, min); | |
@@ -341,7 +349,7 void TestDataSeries::testSubdata() | |||||
341 | QFETCH(QVector<double>, expectedXAxisData); |
|
349 | QFETCH(QVector<double>, expectedXAxisData); | |
342 | QFETCH(QVector<double>, expectedValuesData); |
|
350 | QFETCH(QVector<double>, expectedValuesData); | |
343 |
|
351 | |||
344 |
auto bounds = dataSeries-> |
|
352 | auto bounds = dataSeries->xAxisRange(min, max); | |
345 | QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(), |
|
353 | QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(), | |
346 | expectedXAxisData.cend(), |
|
354 | expectedXAxisData.cend(), | |
347 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); |
|
355 | [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); |
@@ -149,7 +149,7 struct PlottablesUpdater<T, | |||||
149 | // - Gets the data of the series included in the current range |
|
149 | // - Gets the data of the series included in the current range | |
150 | // - Updates each plottable by adding, for each data item, a point that takes x-axis data |
|
150 | // - Updates each plottable by adding, for each data item, a point that takes x-axis data | |
151 | // and value data. The correct value is retrieved according to the index of the component |
|
151 | // and value data. The correct value is retrieved according to the index of the component | |
152 |
auto subDataIts = dataSeries. |
|
152 | auto subDataIts = dataSeries.xAxisRange(range.m_TStart, range.m_TEnd); | |
153 | for (auto it = subDataIts.first; it != subDataIts.second; ++it) { |
|
153 | for (auto it = subDataIts.first; it != subDataIts.second; ++it) { | |
154 | for (const auto &dataContainer : dataContainers) { |
|
154 | for (const auto &dataContainer : dataContainers) { | |
155 | auto componentIndex = dataContainer.first; |
|
155 | auto componentIndex = dataContainer.first; |
General Comments 0
You need to be logged in to leave comments.
Login now