##// END OF EJS Templates
Separate the initialization of the properties of the graph of the update of the units of the graph....
Separate the initialization of the properties of the graph of the update of the units of the graph. The initialization of the properties is carried out when adding a variable in the graph, the update of the units is carried out when loading the data of this variable

File last commit:

r1143:0e96e473601d
r1308:41b7c6aab8be
Show More
SqpColorScale.cpp
60 lines | 1.8 KiB | text/x-c | CppLexer
Alexandre Leroux
Creates color scale for Sciqlop...
r1049 #include "Visualization/SqpColorScale.h"
Alexandre Leroux
Creates method that computes thresholds of a SqpColorScale
r1059 #include <Data/DataSeriesUtils.h>
#include <Visualization/QCPColorMapIterator.h>
Q_LOGGING_CATEGORY(LOG_SqpColorScale, "SqpColorScale")
Alexandre Leroux
Creates color scale for Sciqlop...
r1049 namespace {
const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet;
const auto DEFAULT_RANGE = QCPRange{1.0e3, 1.7e7};
} // namespace
Alexandre Leroux
Creates method that computes thresholds of a SqpColorScale
r1059 std::pair<double, double> SqpColorScale::computeThresholds(const SqpColorScale &scale)
{
auto qcpScale = scale.m_Scale;
auto colorMaps = qcpScale->colorMaps();
if (colorMaps.size() != 1) {
return {std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN()};
}
// Computes thresholds
auto isLogarithmicScale = qcpScale->dataScaleType() == QCPAxis::stLogarithmic;
auto colorMapData = colorMaps.first()->data();
QCPColorMapIterator begin{colorMapData, true};
QCPColorMapIterator end{colorMapData, false};
return DataSeriesUtils::thresholds(begin, end, isLogarithmicScale);
}
Alexandre Leroux
Creates color scale for Sciqlop...
r1049 SqpColorScale::SqpColorScale(QCustomPlot &plot)
: m_Scale{new QCPColorScale{&plot}},
Alexandre Leroux
Minor fix...
r1143 m_AutomaticThreshold{false},
Alexandre Leroux
Creates color scale for Sciqlop...
r1049 m_GradientPreset{DEFAULT_GRADIENT_PRESET}
{
m_Scale->setGradient(m_GradientPreset);
m_Scale->setDataRange(DEFAULT_RANGE);
}
Alexandre Leroux
Updates sqp color scale thresholds (1)...
r1060
void SqpColorScale::updateDataRange() noexcept
{
// Updates data range only if mode is automatic
if (!m_AutomaticThreshold) {
return;
}
double minThreshold, maxThreshold;
std::tie(minThreshold, maxThreshold) = computeThresholds(*this);
if (std::isnan(minThreshold) || std::isnan(maxThreshold)) {
qCCritical(LOG_SqpColorScale())
<< "Can't update data range of color scale: thresholds computed are invalid";
return;
}
// Updates thresholds
m_Scale->setDataRange({minThreshold, maxThreshold});
}