#14524 Histogram: Enable logarithmic binning when selecting a logarithmic property

Selecting a logarithmic result manually in the grid statistics data source
property editor now enables logarithmic binning and a logarithmic x-axis, the
same as creating the plot from a 3D view.

The previously selected result variable is tracked so that only an actual
property change enables logarithmic binning: other property edits leave a
user-selected binning mode alone, and binning modes stored in project files are
kept as-is on load.
This commit is contained in:
Kristian Bendiksen
2026-08-19 12:23:07 +02:00
parent 6c2c13770e
commit aaaf5689aa
3 changed files with 53 additions and 1 deletions
@@ -302,6 +302,10 @@ void RimGridStatisticsHistogramDataSource ::initAfterRead()
{
m_property->setEclipseCase( eclipseCase );
}
// A binning mode stored in the project file is a user choice: only property changes made after
// the project was loaded should enable logarithmic binning.
m_previousResultVariable = m_property->resultVariable();
}
//--------------------------------------------------------------------------------------------------
@@ -342,9 +346,31 @@ void RimGridStatisticsHistogramDataSource::cellFilterViewUpdated()
//--------------------------------------------------------------------------------------------------
void RimGridStatisticsHistogramDataSource::loadDataAndUpdate()
{
updateBinningModeOnPropertyChange();
dataSourceChanged.send();
}
//--------------------------------------------------------------------------------------------------
/// Logarithmic results are best viewed with logarithmic binning: enable it once when a logarithmic
/// property is selected. The user stays in control of the binning mode afterwards.
//--------------------------------------------------------------------------------------------------
bool RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( const QString& previousResultVariable,
const QString& newResultVariable )
{
return newResultVariable != previousResultVariable && RiaResultNames::isLogarithmicResult( newResultVariable );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridStatisticsHistogramDataSource::updateBinningModeOnPropertyChange()
{
const QString resultVariable = m_property()->resultVariable();
if ( shouldEnableLogarithmicBinning( m_previousResultVariable, resultVariable ) ) enableLogarithmicBinning();
m_previousResultVariable = resultVariable;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -360,7 +386,7 @@ void RimGridStatisticsHistogramDataSource::setPropertiesFromView( RimEclipseView
const RimEclipseResultDefinition* resDef = dynamic_cast<const RimEclipseResultDefinition*>( view->cellResult() );
if ( resDef ) m_property->simpleCopy( resDef );
if ( RiaResultNames::isLogarithmicResult( m_property->resultVariable() ) ) enableLogarithmicBinning();
updateBinningModeOnPropertyChange();
dataSourceChanged.send();
}
@@ -64,6 +64,8 @@ public:
void setPropertiesFromView( RimEclipseView* view );
static bool shouldEnableLogarithmicBinning( const QString& previousResultVariable, const QString& newResultVariable );
protected:
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override;
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
@@ -72,10 +74,15 @@ protected:
RigHistogramData createStatisticsData() const;
void updateBinningModeOnPropertyChange();
caf::PdmPtrField<RimCase*> m_case;
caf::PdmField<int> m_timeStep;
caf::PdmPtrField<RimGridView*> m_cellFilterView;
caf::PdmChildField<RimEclipseResultDefinition*> m_property;
caf::PdmField<int> m_numBins;
caf::PdmField<bool> m_cumulative;
private:
QString m_previousResultVariable;
};
@@ -243,3 +243,22 @@ TEST( RimHistogramDataSourceTest, FilterDescriptionsDefaultIsEmpty )
RimGridStatisticsHistogramDataSource dataSource;
EXPECT_TRUE( dataSource.filterDescriptions().empty() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
TEST( RimHistogramDataSourceTest, ShouldEnableLogarithmicBinning )
{
// Selecting a logarithmic property enables logarithmic binning
EXPECT_TRUE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "", "PERMX" ) );
EXPECT_TRUE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "PORO", "PERMZ" ) );
EXPECT_TRUE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "PORO", "TRANX" ) );
EXPECT_TRUE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "PERMX", "PERMZ" ) );
// Linear properties never enable logarithmic binning
EXPECT_FALSE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "", "PORO" ) );
EXPECT_FALSE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "PERMX", "PORO" ) );
// An unchanged property must not re-enable logarithmic binning: the user stays in control
EXPECT_FALSE( RimGridStatisticsHistogramDataSource::shouldEnableLogarithmicBinning( "PERMX", "PERMX" ) );
}