From c35cc2181be82df1a705426e8f0331e08e7eae10 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Tue, 12 Oct 2021 13:38:37 +0100 Subject: [PATCH] Fix radiometer autoscaling --- .../radioastronomy/radioastronomygui.cpp | 51 ++++++++++++------- .../radioastronomy/radioastronomygui.h | 1 + 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/plugins/channelrx/radioastronomy/radioastronomygui.cpp b/plugins/channelrx/radioastronomy/radioastronomygui.cpp index f771ee517..a4660ba0b 100644 --- a/plugins/channelrx/radioastronomy/radioastronomygui.cpp +++ b/plugins/channelrx/radioastronomy/radioastronomygui.cpp @@ -474,11 +474,8 @@ void RadioAstronomyGUI::addToPowerSeries(FFTMeasurement *fft, bool skipCalcs) { if (m_settings.m_powerAutoscale) { - double max = m_powerMax + (m_powerMax-m_powerMin)*0.2; // Add 20% space for markers - double range = max - m_powerMin; blockApplySettings(true); - ui->powerRange->setValue(range); - ui->powerReference->setValue(max); + powerAutoscaleY(false); blockApplySettings(false); } } @@ -764,19 +761,39 @@ void RadioAstronomyGUI::on_powerAutoscale_toggled(bool checked) applySettings(); } +void RadioAstronomyGUI::powerAutoscaleY(bool adjustAxis) +{ + double min = m_powerMin; + double max = m_powerMax; + double range = max - min; + // Round to 1 or 2 decimal places + if (range > 1.0) + { + min = std::floor(min * 10.0) / 10.0; + max = std::ceil(max * 10.0) / 10.0; + } + else + { + min = std::floor(min * 100.0) / 100.0; + max = std::ceil(max * 100.0) / 100.0; + } + range = max - min; + max += range * 0.2; // Add 20% space for markers + range = max - min; + range = std::max(0.1, range); // Don't be smaller than minimum value we can set in GUI + + if (adjustAxis) { + m_powerYAxis->setRange(min, max); + } + ui->powerRange->setValue(range); // Call before setting reference, so number of decimals are adjusted + ui->powerReference->setValue(max); +} + // Scale Y axis according to min and max values void RadioAstronomyGUI::on_powerAutoscaleY_clicked() { - if (m_powerYAxis) - { - double min = m_powerMin; - double max = m_powerMax + (m_powerMax-m_powerMin)*0.2; // Add 20% space for markers - double range = m_powerMax - m_powerMin; - range = std::max(0.1, range); // Don't be smaller than minimum value we can set in GUI - - m_powerYAxis->setRange(min, max); - ui->powerRange->setValue(range); // Call before setting reference, so number of decimals are adjusted - ui->powerReference->setValue(max); + if (m_powerYAxis) { + powerAutoscaleY(true); } } @@ -2857,9 +2874,6 @@ void RadioAstronomyGUI::on_powerYUnits_currentIndexChanged(int index) ui->powerColourScaleMinUnits->setText(text); ui->powerColourScaleMaxUnits->setText(text); } - if (m_settings.m_powerColourAutoscale && (ui->powerChartSelect->currentIndex() == 4)) { - powerColourAutoscale(); - } applySettings(); plotPowerChart(); } @@ -3025,6 +3039,9 @@ void RadioAstronomyGUI::plot2DChart() for (int i = 0; i < m_fftMeasurements.size(); i++) { update2DImage(m_fftMeasurements[i], i < m_fftMeasurements.size() - 1); } + if (m_settings.m_powerColourAutoscale) { + powerColourAutoscale(); + } connect(m_2DChart, SIGNAL(plotAreaChanged(QRectF)), this, SLOT(plotAreaChanged(QRectF))); diff --git a/plugins/channelrx/radioastronomy/radioastronomygui.h b/plugins/channelrx/radioastronomy/radioastronomygui.h index 84ce11ed4..0725492fe 100644 --- a/plugins/channelrx/radioastronomy/radioastronomygui.h +++ b/plugins/channelrx/radioastronomy/radioastronomygui.h @@ -392,6 +392,7 @@ private: void updatePowerSelect(); void spectrumAutoscale(); void powerAutoscale(); + void powerAutoscaleY(bool adjustAxis); void calcSpectrumMarkerDelta(); void calcPowerMarkerDelta(); void calcPowerPeakDelta();