diff --git a/core/include/Data/DataSeries.h b/core/include/Data/DataSeries.h index 458b28d..1fa35a7 100644 --- a/core/include/Data/DataSeries.h +++ b/core/include/Data/DataSeries.h @@ -210,23 +210,22 @@ public: return it == cbegin() ? cend() : --it; } - std::pair subData(double min, double max) const override + std::pair xAxisRange(double minXAxisData, + double maxXAxisData) const override { - if (min > max) { - std::swap(min, max); + if (minXAxisData > maxXAxisData) { + std::swap(minXAxisData, maxXAxisData); } auto begin = cbegin(); auto end = cend(); - auto lowerIt - = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) { - return itValue.x() < value; - }); - auto upperIt - = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) { - return value < itValue.x(); - }); + auto lowerIt = std::lower_bound( + begin, end, minXAxisData, + [](const auto &itValue, const auto &value) { return itValue.x() < value; }); + auto upperIt = std::upper_bound( + begin, end, maxXAxisData, + [](const auto &value, const auto &itValue) { return value < itValue.x(); }); return std::make_pair(lowerIt, upperIt); } diff --git a/core/include/Data/IDataSeries.h b/core/include/Data/IDataSeries.h index 5ccf611..2d134ee 100644 --- a/core/include/Data/IDataSeries.h +++ b/core/include/Data/IDataSeries.h @@ -78,8 +78,10 @@ public: /// equal to the value passed in parameter, or the end iterator if there is no matching value virtual DataSeriesIterator maxXAxisData(double maxXAxisData) const = 0; - virtual std::pair subData(double min, - double max) const = 0; + /// @return the iterators pointing to the range of data whose x-axis values are between min and + /// max passed in parameters + virtual std::pair + xAxisRange(double minXAxisData, double maxXAxisData) const = 0; // /////// // // Mutexes // diff --git a/core/src/Data/ScalarSeries.cpp b/core/src/Data/ScalarSeries.cpp index 7b5b64a..49bec2e 100644 --- a/core/src/Data/ScalarSeries.cpp +++ b/core/src/Data/ScalarSeries.cpp @@ -18,7 +18,7 @@ std::shared_ptr ScalarSeries::subDataSeries(const SqpRange &range) auto subValuesData = QVector(); this->lockRead(); { - auto bounds = subData(range.m_TStart, range.m_TEnd); + auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); for (auto it = bounds.first; it != bounds.second; ++it) { subXAxisData.append(it->x()); subValuesData.append(it->value()); diff --git a/core/src/Data/VectorSeries.cpp b/core/src/Data/VectorSeries.cpp index 06432e5..a8091b2 100644 --- a/core/src/Data/VectorSeries.cpp +++ b/core/src/Data/VectorSeries.cpp @@ -24,7 +24,7 @@ std::shared_ptr VectorSeries::subDataSeries(const SqpRange &range) this->lockRead(); { - auto bounds = subData(range.m_TStart, range.m_TEnd); + auto bounds = xAxisRange(range.m_TStart, range.m_TEnd); for (auto it = bounds.first; it != bounds.second; ++it) { subXAxisData.append(it->x()); subXValuesData.append(it->value(0)); diff --git a/core/tests/Data/TestDataSeries.cpp b/core/tests/Data/TestDataSeries.cpp index 9ac0052..d0d580e 100644 --- a/core/tests/Data/TestDataSeries.cpp +++ b/core/tests/Data/TestDataSeries.cpp @@ -38,11 +38,11 @@ private slots: void testMaxXAxisData(); /// Input test data - /// @sa testSubdata() - void testSubdata_data(); + /// @sa testXAxisRange() + void testXAxisRange_data(); - /// Tests get subdata of two data series - void testSubdata(); + /// Tests get x-axis range of a data series + void testXAxisRange(); }; void TestDataSeries::testCtor_data() @@ -289,20 +289,20 @@ void TestDataSeries::testMaxXAxisData() } } -void TestDataSeries::testSubdata_data() +void TestDataSeries::testXAxisRange_data() { // ////////////// // // Test structure // // ////////////// // - // Data series to get subdata + // Data series to get x-axis range QTest::addColumn >("dataSeries"); // Min/max values QTest::addColumn("min"); QTest::addColumn("max"); - // Expected values after subdata + // Expected values QTest::addColumn >("expectedXAxisData"); QTest::addColumn >("expectedValuesData"); @@ -310,29 +310,37 @@ void TestDataSeries::testSubdata_data() // Test cases // // ////////// // - QTest::newRow("subData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << -1. << 3.2 << QVector{1., 2., 3.} - << QVector{100., 200., 300.}; - QTest::newRow("subData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 1. << 4. << QVector{1., 2., 3., 4.} - << QVector{100., 200., 300., 400.}; - QTest::newRow("subData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 1. << 3.9 << QVector{1., 2., 3.} - << QVector{100., 200., 300.}; - QTest::newRow("subData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 0. << 0.9 << QVector{} << QVector{}; - QTest::newRow("subData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 0. << 1. << QVector{1.} << QVector{100.}; - QTest::newRow("subData6") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 2.1 << 6. << QVector{3., 4., 5.} - << QVector{300., 400., 500.}; - QTest::newRow("subData7") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 6. << 9. << QVector{} << QVector{}; - QTest::newRow("subData8") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.}) - << 5. << 9. << QVector{5.} << QVector{500.}; + QTest::newRow("xAxisRange1") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << -1. << 3.2 << QVector{1., 2., 3.} + << QVector{100., 200., 300.}; + QTest::newRow("xAxisRange2") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 1. << 4. << QVector{1., 2., 3., 4.} + << QVector{100., 200., 300., 400.}; + QTest::newRow("xAxisRange3") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 1. << 3.9 << QVector{1., 2., 3.} + << QVector{100., 200., 300.}; + QTest::newRow("xAxisRange4") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 0. << 0.9 << QVector{} << QVector{}; + QTest::newRow("xAxisRange5") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 0. << 1. << QVector{1.} << QVector{100.}; + QTest::newRow("xAxisRange6") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 2.1 << 6. << QVector{3., 4., 5.} + << QVector{300., 400., 500.}; + QTest::newRow("xAxisRange7") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 6. << 9. << QVector{} << QVector{}; + QTest::newRow("xAxisRange8") << createSeries({1., 2., 3., 4., 5.}, + {100., 200., 300., 400., 500.}) + << 5. << 9. << QVector{5.} << QVector{500.}; } -void TestDataSeries::testSubdata() +void TestDataSeries::testXAxisRange() { QFETCH(std::shared_ptr, dataSeries); QFETCH(double, min); @@ -341,7 +349,7 @@ void TestDataSeries::testSubdata() QFETCH(QVector, expectedXAxisData); QFETCH(QVector, expectedValuesData); - auto bounds = dataSeries->subData(min, max); + auto bounds = dataSeries->xAxisRange(min, max); QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(), expectedXAxisData.cend(), [](const auto &it, const auto &expectedX) { return it.x() == expectedX; })); diff --git a/gui/src/Visualization/VisualizationGraphHelper.cpp b/gui/src/Visualization/VisualizationGraphHelper.cpp index bd80ba7..64edc65 100644 --- a/gui/src/Visualization/VisualizationGraphHelper.cpp +++ b/gui/src/Visualization/VisualizationGraphHelper.cpp @@ -149,7 +149,7 @@ struct PlottablesUpdater