#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.
This commit is contained in:
Kristian Bendiksen
2026-08-19 12:23:07 +02:00
parent 5f465bf19a
commit 05588f4327
5 changed files with 51 additions and 7 deletions
@@ -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<const RimEclipseResultDefinition*>( view->cellResult() );
if ( resDef ) m_property->simpleCopy( resDef );
updateBinningModeOnPropertyChange();
updateBinningOnPropertyChange();
dataSourceChanged.send();
}
@@ -74,7 +74,7 @@ protected:
RigHistogramData createStatisticsData() const;
void updateBinningModeOnPropertyChange();
void updateBinningOnPropertyChange();
caf::PdmPtrField<RimCase*> m_case;
caf::PdmField<int> m_timeStep;
@@ -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();
}
}
//--------------------------------------------------------------------------------------------------
@@ -81,6 +81,7 @@ public:
virtual void setShowCumulativeCurve( bool showCumulativeCurve );
void setBinningMode( RigHistogramCalculator::BinningMode binningMode );
void resetBinRange();
virtual std::vector<QString> filterDescriptions() const;
static QString userDefinedRangeFilterText( double min, double max );
@@ -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<caf::PdmField<caf::AppEnum<RimHistogramDataSource::BinRangeMode>>*>( dataSource.findField( "BinRangeMode" ) );
auto* binRangeMin = dynamic_cast<caf::PdmField<double>*>( dataSource.findField( "BinRangeMin" ) );
auto* binRangeMax = dynamic_cast<caf::PdmField<double>*>( 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() );
}