##// END OF EJS Templates
Fix the close button on the graphs and multi selection in the same graph
Fix the close button on the graphs and multi selection in the same graph

File last commit:

r1031:958f5923ee65
r1094:f391b1d9fb19
Show More
OptionalAxis.cpp
107 lines | 2.6 KiB | text/x-c | CppLexer
/ core / src / Data / OptionalAxis.cpp
Alexandre Leroux
Introduces optional axis for a dataseries...
r865 #include <Data/OptionalAxis.h>
#include "Data/ArrayData.h"
Alexandre Leroux
Updates access to y-axis properties of the data series (2)...
r1031 OptionalAxis::OptionalAxis()
: m_Defined{false}, m_Data{std::make_shared<ArrayData<1> >(std::vector<double>{})}, m_Unit{}
Alexandre Leroux
Introduces optional axis for a dataseries...
r865 {
}
OptionalAxis::OptionalAxis(std::shared_ptr<ArrayData<1> > data, Unit unit)
: m_Defined{true}, m_Data{data}, m_Unit{std::move(unit)}
{
if (m_Data == nullptr) {
throw std::invalid_argument{"Data can't be null for a defined axis"};
}
}
OptionalAxis::OptionalAxis(const OptionalAxis &other)
Alexandre Leroux
Updates access to y-axis properties of the data series (2)...
r1031 : m_Defined{other.m_Defined}, m_Data{other.m_Data}, m_Unit{other.m_Unit}
Alexandre Leroux
Introduces optional axis for a dataseries...
r865 {
}
OptionalAxis &OptionalAxis::operator=(OptionalAxis other)
{
std::swap(m_Defined, other.m_Defined);
std::swap(m_Data, other.m_Data);
std::swap(m_Unit, other.m_Unit);
Alexandre Leroux
Fixes missing return
r924
return *this;
Alexandre Leroux
Introduces optional axis for a dataseries...
r865 }
bool OptionalAxis::isDefined() const
{
return m_Defined;
}
Alexandre Leroux
Implements OptionalAxis::bounds() method...
r904 std::pair<double, double> OptionalAxis::bounds() const
{
if (!m_Defined || m_Data->size() == 0) {
return std::make_pair(std::numeric_limits<double>::quiet_NaN(),
std::numeric_limits<double>::quiet_NaN());
}
else {
auto minIt = std::min_element(
m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) {
return SortUtils::minCompareWithNaN(it1.first(), it2.first());
});
// Gets the iterator on the max of all values data
auto maxIt = std::max_element(
m_Data->cbegin(), m_Data->cend(), [](const auto &it1, const auto &it2) {
return SortUtils::maxCompareWithNaN(it1.first(), it2.first());
});
return std::make_pair(minIt->first(), maxIt->first());
}
}
Alexandre Leroux
Introduces optional axis for a dataseries...
r865 int OptionalAxis::size() const
{
return m_Defined ? m_Data->size() : 0;
}
Unit OptionalAxis::unit() const
{
return m_Defined ? m_Unit : Unit{};
}
bool OptionalAxis::operator==(const OptionalAxis &other)
{
// Axis not defined
if (!m_Defined) {
return !other.m_Defined;
}
// Axis defined
return m_Unit == other.m_Unit
&& std::equal(
m_Data->cbegin(), m_Data->cend(), other.m_Data->cbegin(), other.m_Data->cend(),
[](const auto &it1, const auto &it2) { return it1.values() == it2.values(); });
}
bool OptionalAxis::operator!=(const OptionalAxis &other)
{
return !(*this == other);
}
Alexandre Leroux
Updates access to y-axis properties of the data series (2)...
r1031
ArrayDataIterator OptionalAxis::begin()
{
return m_Data->begin();
}
ArrayDataIterator OptionalAxis::end()
{
return m_Data->end();
}
ArrayDataIterator OptionalAxis::cbegin() const
{
return m_Data->cbegin();
}
ArrayDataIterator OptionalAxis::cend() const
{
return m_Data->cend();
}