diff --git a/gui/include/Visualization/SqpColorScale.h b/gui/include/Visualization/SqpColorScale.h index c968fd3..4fbbe46 100644 --- a/gui/include/Visualization/SqpColorScale.h +++ b/gui/include/Visualization/SqpColorScale.h @@ -19,6 +19,8 @@ struct SqpColorScale { explicit SqpColorScale(QCustomPlot &plot); + void updateDataRange() noexcept; + /// QCustomPlot object representing the color scale. /// @remarks The SqpColorScale instance has not the property on this pointer. The pointer must /// remain valid throughout the existence of the SqpColorScale instance diff --git a/gui/src/Visualization/SqpColorScale.cpp b/gui/src/Visualization/SqpColorScale.cpp index 0060ce1..6c36bed 100644 --- a/gui/src/Visualization/SqpColorScale.cpp +++ b/gui/src/Visualization/SqpColorScale.cpp @@ -33,9 +33,28 @@ std::pair SqpColorScale::computeThresholds(const SqpColorScale & SqpColorScale::SqpColorScale(QCustomPlot &plot) : m_Scale{new QCPColorScale{&plot}}, - m_AutomaticThreshold{false}, + m_AutomaticThreshold{true}, m_GradientPreset{DEFAULT_GRADIENT_PRESET} { m_Scale->setGradient(m_GradientPreset); m_Scale->setDataRange(DEFAULT_RANGE); } + +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}); +}