From 05588f4327aa3c7d5c366a79907d756c31b18f2f Mon Sep 17 00:00:00 2001 From: Kristian Bendiksen Date: Fri, 14 Aug 2026 11:02:58 +0200 Subject: [PATCH] #14524 Histogram: Reset user-defined bin range on property change A user-defined bin range is tied to the value range of a specific result: a range set up for FLUXNUM does not apply to PERMX. Reset the bin range mode to Automatic and the min/max cutoffs to their defaults when another property is selected, and reset the stale cutoffs when the user sets the bin range mode back to Automatic. --- .../RimGridStatisticsHistogramDataSource.cpp | 14 ++++++----- .../RimGridStatisticsHistogramDataSource.h | 2 +- .../Histogram/RimHistogramDataSource.cpp | 16 ++++++++++++ .../Histogram/RimHistogramDataSource.h | 1 + .../UnitTests/RimHistogramDataSource-Test.cpp | 25 +++++++++++++++++++ 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp index c2bfb9c8a9..b73f7cb486 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp @@ -346,7 +346,7 @@ void RimGridStatisticsHistogramDataSource::cellFilterViewUpdated() //-------------------------------------------------------------------------------------------------- void RimGridStatisticsHistogramDataSource::loadDataAndUpdate() { - updateBinningModeOnPropertyChange(); + updateBinningOnPropertyChange(); dataSourceChanged.send(); } @@ -361,16 +361,18 @@ RigHistogramCalculator::BinningMode RimGridStatisticsHistogramDataSource::binnin } //-------------------------------------------------------------------------------------------------- -/// The binning mode follows the selected property: logarithmic results are best viewed with -/// logarithmic binning, others with linear binning. Only an actual property change updates the -/// binning mode: the user stays in control of the setting afterwards. +/// The binning follows the selected property: logarithmic results are best viewed with logarithmic +/// binning, others with linear binning, and a user-defined bin range set up for one result does not +/// apply to the value range of another. Only an actual property change updates the binning: the +/// user stays in control of the settings afterwards. //-------------------------------------------------------------------------------------------------- -void RimGridStatisticsHistogramDataSource::updateBinningModeOnPropertyChange() +void RimGridStatisticsHistogramDataSource::updateBinningOnPropertyChange() { const QString resultVariable = m_property()->resultVariable(); if ( resultVariable != m_previousResultVariable ) { setBinningMode( binningModeForResult( resultVariable ) ); + resetBinRange(); m_previousResultVariable = resultVariable; } } @@ -390,7 +392,7 @@ void RimGridStatisticsHistogramDataSource::setPropertiesFromView( RimEclipseView const RimEclipseResultDefinition* resDef = dynamic_cast( view->cellResult() ); if ( resDef ) m_property->simpleCopy( resDef ); - updateBinningModeOnPropertyChange(); + updateBinningOnPropertyChange(); dataSourceChanged.send(); } diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h index 6b3c51c3e0..4945caea2b 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h @@ -74,7 +74,7 @@ protected: RigHistogramData createStatisticsData() const; - void updateBinningModeOnPropertyChange(); + void updateBinningOnPropertyChange(); caf::PdmPtrField m_case; caf::PdmField m_timeStep; diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp index de60c851d2..2e521eee19 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp @@ -99,6 +99,16 @@ void RimHistogramDataSource::setBinningMode( RigHistogramCalculator::BinningMode binningModeChanged.send( binningMode ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramDataSource::resetBinRange() +{ + m_binRangeMode = BinRangeMode::AUTOMATIC; + m_binRangeMin = m_binRangeMin.defaultValue(); + m_binRangeMax = m_binRangeMax.defaultValue(); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -126,6 +136,12 @@ void RimHistogramDataSource::fieldChangedByUi( const caf::PdmFieldHandle* change { binningModeChanged.send( m_binningMode() ); } + + // Stale cutoffs are of no use when the user returns to a user-defined range later + if ( changedField == &m_binRangeMode && m_binRangeMode() == BinRangeMode::AUTOMATIC ) + { + resetBinRange(); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h index 6769b5fb5b..280ab37a43 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h @@ -81,6 +81,7 @@ public: virtual void setShowCumulativeCurve( bool showCumulativeCurve ); void setBinningMode( RigHistogramCalculator::BinningMode binningMode ); + void resetBinRange(); virtual std::vector filterDescriptions() const; static QString userDefinedRangeFilterText( double min, double max ); diff --git a/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp b/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp index 3f8b2d3f4d..8fea3e4582 100644 --- a/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp +++ b/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp @@ -260,3 +260,28 @@ TEST( RimHistogramDataSourceTest, BinningModeForResult ) EXPECT_EQ( RigHistogramCalculator::BinningMode::LINEAR, RimGridStatisticsHistogramDataSource::binningModeForResult( "FLUXNUM" ) ); EXPECT_EQ( RigHistogramCalculator::BinningMode::LINEAR, RimGridStatisticsHistogramDataSource::binningModeForResult( "" ) ); } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RimHistogramDataSourceTest, ResetBinRange ) +{ + RimGridStatisticsHistogramDataSource dataSource; + + auto* binRangeMode = + dynamic_cast>*>( dataSource.findField( "BinRangeMode" ) ); + auto* binRangeMin = dynamic_cast*>( dataSource.findField( "BinRangeMin" ) ); + auto* binRangeMax = dynamic_cast*>( dataSource.findField( "BinRangeMax" ) ); + ASSERT_TRUE( binRangeMode && binRangeMin && binRangeMax ); + + *binRangeMode = RimHistogramDataSource::BinRangeMode::USER_DEFINED; + *binRangeMin = 0.2; + *binRangeMax = 0.8; + EXPECT_FALSE( dataSource.filterDescriptions().empty() ); + + dataSource.resetBinRange(); + + EXPECT_TRUE( dataSource.filterDescriptions().empty() ); + EXPECT_DOUBLE_EQ( 0.0, binRangeMin->value() ); + EXPECT_DOUBLE_EQ( 1.0, binRangeMax->value() ); +}