diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp index ea9b606a5d..475e58cbe4 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp @@ -18,6 +18,8 @@ #include "RimGridStatisticsHistogramDataSource.h" +#include "RiaResultNames.h" + #include "Histogram/RimHistogramPlot.h" #include "RimEclipseCase.h" #include "RimEclipseCellColors.h" @@ -212,13 +214,21 @@ RimHistogramDataSource::HistogramResult RimGridStatisticsHistogramDataSource::co //-------------------------------------------------------------------------------------------------- RigHistogramData RimGridStatisticsHistogramDataSource::createStatisticsData() const { - std::unique_ptr histogramCalculator = std::make_unique(); - histogramCalculator->setNumBins( static_cast( m_numBins() ) ); + RimHistogramCalculator histogramCalculator; + histogramCalculator.setNumBins( static_cast( m_numBins() ) ); std::optional> customBinRange; if ( useUserDefinedBinRange() ) customBinRange = std::make_pair( m_binRangeMin(), m_binRangeMax() ); - histogramCalculator->setBinningParameters( binningMode(), outOfRangeHandling(), customBinRange ); + histogramCalculator.setBinningParameters( binningMode(), outOfRangeHandling(), customBinRange ); + + return statisticsData( histogramCalculator ); +} +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigHistogramData RimGridStatisticsHistogramDataSource::statisticsData( RimHistogramCalculator& histogramCalculator ) const +{ RimHistogramCalculator::StatisticsCellRangeType cellRange = RimHistogramCalculator::StatisticsCellRangeType::ALL_CELLS; RimHistogramCalculator::StatisticsTimeRangeType timeRange = RimHistogramCalculator::StatisticsTimeRangeType::ALL_TIMESTEPS; @@ -234,15 +244,30 @@ RigHistogramData RimGridStatisticsHistogramDataSource::createStatisticsData() co // Filter by visible cells of the view cellRange = RimHistogramCalculator::StatisticsCellRangeType::VISIBLE_CELLS; RimEclipseView* eclipseView = dynamic_cast( m_cellFilterView.value() ); - return histogramCalculator->histogramData( eclipseView, m_property.value(), cellRange, timeRange, timeStep ); + return histogramCalculator.histogramData( eclipseView, m_property.value(), cellRange, timeRange, timeStep ); } else { RimEclipseView* eclipseView = nullptr; - return histogramCalculator->histogramData( eclipseView, m_property.value(), cellRange, timeRange, timeStep ); + return histogramCalculator.histogramData( eclipseView, m_property.value(), cellRange, timeRange, timeStep ); } } +//-------------------------------------------------------------------------------------------------- +/// The range of the data selected for the histogram: the statistics are computed without custom +/// binning, where min and max always are the data range. +//-------------------------------------------------------------------------------------------------- +std::optional> RimGridStatisticsHistogramDataSource::dataRange() const +{ + RimHistogramCalculator histogramCalculator; + RigHistogramData histogramData = statisticsData( histogramCalculator ); + + if ( !RigStatisticsTools::isValidNumber( histogramData.min ) || !RigStatisticsTools::isValidNumber( histogramData.max ) ) + return std::nullopt; + + return std::make_pair( histogramData.min, histogramData.max ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -277,6 +302,19 @@ std::string RimGridStatisticsHistogramDataSource::name() const return nameTags.join( ", " ).toStdString(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimGridStatisticsHistogramDataSource::filterDescriptions() const +{ + std::vector descriptions; + if ( m_cellFilterView() ) descriptions.push_back( "Filter: Visible cells in 3D view" ); + + auto baseDescriptions = RimHistogramDataSource::filterDescriptions(); + descriptions.insert( descriptions.end(), baseDescriptions.begin(), baseDescriptions.end() ); + return descriptions; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -287,6 +325,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(); } //-------------------------------------------------------------------------------------------------- @@ -327,9 +369,37 @@ void RimGridStatisticsHistogramDataSource::cellFilterViewUpdated() //-------------------------------------------------------------------------------------------------- void RimGridStatisticsHistogramDataSource::loadDataAndUpdate() { + updateBinningOnPropertyChange(); + dataSourceChanged.send(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigHistogramCalculator::BinningMode RimGridStatisticsHistogramDataSource::binningModeForResult( const QString& resultVariable ) +{ + return RiaResultNames::isLogarithmicResult( resultVariable ) ? RigHistogramCalculator::BinningMode::LOGARITHMIC + : RigHistogramCalculator::BinningMode::LINEAR; +} + +//-------------------------------------------------------------------------------------------------- +/// 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::updateBinningOnPropertyChange() +{ + const QString resultVariable = m_property()->resultVariable(); + if ( resultVariable != m_previousResultVariable ) + { + setBinningMode( binningModeForResult( resultVariable ) ); + resetBinRange(); + m_previousResultVariable = resultVariable; + } +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -345,5 +415,7 @@ void RimGridStatisticsHistogramDataSource::setPropertiesFromView( RimEclipseView const RimEclipseResultDefinition* resDef = dynamic_cast( view->cellResult() ); if ( resDef ) m_property->simpleCopy( resDef ); + updateBinningOnPropertyChange(); + dataSourceChanged.send(); } diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h index 631db3fb61..5027398e70 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h @@ -29,6 +29,7 @@ class RimCase; class RimGridView; class RimEclipseResultDefinition; class RimEclipseView; +class RimHistogramCalculator; //================================================================================================== /// @@ -54,6 +55,8 @@ class RimGridStatisticsHistogramDataSource : public RimHistogramDataSource std::string name() const override; + std::vector filterDescriptions() const override; + void setDefaults() override; void cellFilterViewUpdated(); @@ -62,6 +65,10 @@ class RimGridStatisticsHistogramDataSource : public RimHistogramDataSource void setPropertiesFromView( RimEclipseView* view ); + static RigHistogramCalculator::BinningMode binningModeForResult( const QString& resultVariable ); + + std::optional> dataRange() const override; + protected: QList calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions ) override; void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override; @@ -69,6 +76,9 @@ class RimGridStatisticsHistogramDataSource : public RimHistogramDataSource void initAfterRead() override; RigHistogramData createStatisticsData() const; + RigHistogramData statisticsData( RimHistogramCalculator& histogramCalculator ) const; + + void updateBinningOnPropertyChange(); caf::PdmPtrField m_case; caf::PdmField m_timeStep; @@ -76,4 +86,7 @@ class RimGridStatisticsHistogramDataSource : public RimHistogramDataSource caf::PdmChildField m_property; caf::PdmField m_numBins; caf::PdmField m_cumulative; + +private: + QString m_previousResultVariable; }; diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp index 5f8eba66c6..7864b3c0f0 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp @@ -117,7 +117,7 @@ void RimHistogramCurve::setDataSource( RimHistogramDataSource* dataSource ) m_dataSource->uiCapability()->setUiTreeHidden( true ); m_dataSource->dataSourceChanged.connect( this, &RimHistogramCurve::onDataSourceChanged ); m_dataSource->cumulativeChanged.connect( this, &RimHistogramCurve::onCumulativeChanged ); - m_dataSource->logarithmicBinningEnabled.connect( this, &RimHistogramCurve::onLogarithmicBinningEnabled ); + m_dataSource->binningModeChanged.connect( this, &RimHistogramCurve::onBinningModeChanged ); } } @@ -606,16 +606,16 @@ void RimHistogramCurve::onCumulativeChanged( const caf::SignalEmitter* emitter ) } //-------------------------------------------------------------------------------------------------- -/// Logarithmic bins are best viewed on a logarithmic axis: enable it once when logarithmic binning -/// is selected. The user stays in control of the axis setting afterwards. +/// Bins are best viewed on a matching axis: select a logarithmic axis for logarithmic binning and a +/// linear axis for linear binning. The user stays in control of the axis setting afterwards. //-------------------------------------------------------------------------------------------------- -void RimHistogramCurve::onLogarithmicBinningEnabled( const caf::SignalEmitter* emitter ) +void RimHistogramCurve::onBinningModeChanged( const caf::SignalEmitter* emitter, RigHistogramCalculator::BinningMode binningMode ) { auto plot = firstAncestorOrThisOfType(); if ( !plot ) return; auto axisProperties = dynamic_cast( plot->axisPropertiesForPlotAxis( axisX() ) ); - if ( axisProperties ) axisProperties->setLogarithmicScaleEnabled( true ); + if ( axisProperties ) axisProperties->setLogarithmicScaleEnabled( binningMode == RigHistogramCalculator::BinningMode::LOGARITHMIC ); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h index 7addbf0e0c..daaac5a108 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h @@ -18,6 +18,8 @@ #pragma once +#include "RigStatisticsMath.h" + #include "RiuPlotAnnotationTool.h" #include "cafPdmChildField.h" #include "cafPdmField.h" @@ -86,7 +88,7 @@ class RimHistogramCurve : public RimStackablePlotCurve void onDataSourceChanged( const caf::SignalEmitter* emitter ); void onCumulativeChanged( const caf::SignalEmitter* emitter ); - void onLogarithmicBinningEnabled( const caf::SignalEmitter* emitter ); + void onBinningModeChanged( const caf::SignalEmitter* emitter, RigHistogramCalculator::BinningMode binningMode ); void updateCumulativeCurve(); void connectReferencedDataSourceSignals(); diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurveCollection.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurveCollection.cpp index 3518040076..359137b059 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurveCollection.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurveCollection.cpp @@ -68,6 +68,7 @@ void RimHistogramCurveCollection::loadDataAndUpdate( bool updateParentPlot ) { auto parentPlot = firstAncestorOrThisOfTypeAsserted(); parentPlot->updateAll(); + parentPlot->updatePlotInfoLabel(); } } diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp index 44c7ed84dc..692e835d08 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp @@ -57,7 +57,7 @@ void caf::AppEnum::setUp() RimHistogramDataSource::RimHistogramDataSource() : dataSourceChanged( this ) , cumulativeChanged( this ) - , logarithmicBinningEnabled( this ) + , binningModeChanged( this ) { CAF_PDM_InitObject( "Histogram Data Source", ); @@ -90,14 +90,75 @@ void RimHistogramDataSource::setShowCumulativeCurve( bool showCumulativeCurve ) { } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramDataSource::setBinningMode( RigHistogramCalculator::BinningMode binningMode ) +{ + m_binningMode = binningMode; + binningModeChanged.send( binningMode ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramDataSource::resetBinRange() +{ + m_binRangeMode = BinRangeMode::AUTOMATIC; + m_binRangeMin = m_binRangeMin.defaultValue(); + m_binRangeMax = m_binRangeMax.defaultValue(); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::optional> RimHistogramDataSource::dataRange() const +{ + return std::nullopt; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector RimHistogramDataSource::filterDescriptions() const +{ + if ( useUserDefinedBinRange() ) return { userDefinedRangeFilterText( m_binRangeMin(), m_binRangeMax() ) }; + + return {}; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +QString RimHistogramDataSource::userDefinedRangeFilterText( double min, double max ) +{ + return QString( "Filter: User defined x-range [%1..%2]" ).arg( min ).arg( max ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void RimHistogramDataSource::fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) { - if ( changedField == &m_binningMode && m_binningMode() == RigHistogramCalculator::BinningMode::LOGARITHMIC ) + if ( changedField == &m_binningMode ) { - logarithmicBinningEnabled.send(); + 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(); + } + + // Start a user-defined range at the data range: the default [0..1] could exclude most values + if ( changedField == &m_binRangeMode && m_binRangeMode() == BinRangeMode::USER_DEFINED ) + { + if ( auto range = dataRange() ) + { + m_binRangeMin = range->first; + m_binRangeMax = range->second; + } } } diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h index 745d0e81e1..0ddf9fb03a 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h @@ -27,8 +27,12 @@ #include "cafPdmObject.h" #include "cafSignal.h" +#include + #include +#include #include +#include //================================================================================================== /// @@ -64,9 +68,9 @@ class RimHistogramDataSource : public caf::PdmObject RimHistogramDataSource(); ~RimHistogramDataSource() override; - caf::Signal<> dataSourceChanged; - caf::Signal<> cumulativeChanged; - caf::Signal<> logarithmicBinningEnabled; + caf::Signal<> dataSourceChanged; + caf::Signal<> cumulativeChanged; + caf::Signal binningModeChanged; virtual std::string unitNameX() const = 0; virtual std::string unitNameY() const = 0; @@ -77,6 +81,14 @@ class RimHistogramDataSource : public caf::PdmObject virtual bool showCumulativeCurve() const; virtual void setShowCumulativeCurve( bool showCumulativeCurve ); + void setBinningMode( RigHistogramCalculator::BinningMode binningMode ); + void resetBinRange(); + + virtual std::optional> dataRange() const; + + virtual std::vector filterDescriptions() const; + static QString userDefinedRangeFilterText( double min, double max ); + virtual void setDefaults() = 0; virtual std::string name() const = 0; diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp index 4ad5d4fcf1..d79ab92aa5 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.cpp @@ -38,7 +38,9 @@ #include "Summary/RimSummaryAddress.h" #include "Tools/RimPlotAxisTools.h" +#include "RiuAbstractOverlayContentFrame.h" #include "RiuContextMenuLauncher.h" +#include "RiuDraggableOverlayFrame.h" #include "RiuPlotAxis.h" #include "RiuPlotMainWindow.h" #include "RiuPlotMainWindowTools.h" @@ -52,8 +54,6 @@ #include "cafPdmUiTreeOrdering.h" #include "cafSelectionManager.h" -#include "qwt_text.h" - #include #include #include @@ -355,6 +355,60 @@ void RimHistogramPlot::setLegendPosition( RiuPlotWidget::Legend position ) m_legendPosition = position; } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramPlot::showPlotInfoLabel( bool show ) +{ + if ( !m_plotInfoFrame ) return; + + if ( show ) + { + if ( plotWidget() ) plotWidget()->addOverlayFrame( m_plotInfoFrame ); + } + else + { + if ( plotWidget() ) plotWidget()->removeOverlayFrame( m_plotInfoFrame ); + delete m_plotInfoFrame; + m_plotInfoFrame = nullptr; + } +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramPlot::updatePlotInfoLabel() +{ + QStringList descriptions; + if ( m_histogramCurveCollection->isCurvesVisible() ) + { + for ( RimHistogramCurve* curve : histogramCurves() ) + { + if ( !curve->isChecked() || !curve->dataSource() ) continue; + + for ( const QString& description : curve->dataSource()->filterDescriptions() ) + { + if ( !descriptions.contains( description ) ) descriptions += description; + } + } + } + + if ( !descriptions.isEmpty() && plotWidget() ) + { + if ( !m_plotInfoFrame ) + { + m_plotInfoFrame = new RiuDraggableOverlayFrame( plotWidget()->getParentForOverlay(), plotWidget()->overlayMargins() ); + m_plotInfoFrame->setAnchorCorner( RiuDraggableOverlayFrame::AnchorCorner::TopRight ); + + m_plotInfoTextFrame = new RiuTextOverlayContentFrame( m_plotInfoFrame ); + m_plotInfoFrame->setContentFrame( m_plotInfoTextFrame ); + } + m_plotInfoTextFrame->setText( descriptions.join( "\n" ) ); + } + + showPlotInfoLabel( !descriptions.isEmpty() ); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -718,6 +772,8 @@ void RimHistogramPlot::onLoadDataAndUpdate() updateAxes(); updateStackedCurveData(); + + updatePlotInfoLabel(); } //-------------------------------------------------------------------------------------------------- @@ -1110,6 +1166,8 @@ void RimHistogramPlot::detachAllPlotItems() { m_histogramCurveCollection->detachPlotCurves(); } + + showPlotInfoLabel( false ); } //-------------------------------------------------------------------------------------------------- @@ -1167,6 +1225,7 @@ void RimHistogramPlot::onCurveCollectionChanged( const SignalEmitter* emitter ) curvesChanged.send(); updateStackedCurveData(); + updatePlotInfoLabel(); scheduleReplotIfVisible(); updateAllRequiredEditors(); diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.h index ccd086d76b..5b3828450e 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramPlot.h @@ -39,12 +39,13 @@ class RimPlotAxisPropertiesInterface; class RimPlotAxisProperties; class RimPlotTemplateFileItem; class RimStackablePlotCurve; +class RiuDraggableOverlayFrame; +class RiuTextOverlayContentFrame; class PdmUiTreeOrdering; class QwtInterval; class QwtPlotCurve; -class QwtPlotTextLabel; class QKeyEvent; @@ -233,6 +234,9 @@ private slots: QPointer m_histogramPlot; + QPointer m_plotInfoFrame; + QPointer m_plotInfoTextFrame; + bool m_isValid; RiuPlotWidget::Legend m_legendPosition; }; diff --git a/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp b/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp index 6c336bf7f2..8fea3e4582 100644 --- a/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp +++ b/ApplicationLibCode/UnitTests/RimHistogramDataSource-Test.cpp @@ -1,5 +1,6 @@ #include "gtest/gtest.h" +#include "Histogram/RimGridStatisticsHistogramDataSource.h" #include "Histogram/RimHistogramDataSource.h" //-------------------------------------------------------------------------------------------------- @@ -224,3 +225,63 @@ TEST( RimHistogramDataSourceTest, ComputeBinRange ) EXPECT_DOUBLE_EQ( 6.0, max ); } } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RimHistogramDataSourceTest, UserDefinedRangeFilterText ) +{ + EXPECT_EQ( "Filter: User defined x-range [0.1..100]", RimHistogramDataSource::userDefinedRangeFilterText( 0.1, 100.0 ).toStdString() ); + EXPECT_EQ( "Filter: User defined x-range [-2.5..0]", RimHistogramDataSource::userDefinedRangeFilterText( -2.5, 0.0 ).toStdString() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RimHistogramDataSourceTest, FilterDescriptionsDefaultIsEmpty ) +{ + RimGridStatisticsHistogramDataSource dataSource; + EXPECT_TRUE( dataSource.filterDescriptions().empty() ); +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +TEST( RimHistogramDataSourceTest, BinningModeForResult ) +{ + // Logarithmic results get logarithmic binning + EXPECT_EQ( RigHistogramCalculator::BinningMode::LOGARITHMIC, RimGridStatisticsHistogramDataSource::binningModeForResult( "PERMX" ) ); + EXPECT_EQ( RigHistogramCalculator::BinningMode::LOGARITHMIC, RimGridStatisticsHistogramDataSource::binningModeForResult( "PERMZ" ) ); + EXPECT_EQ( RigHistogramCalculator::BinningMode::LOGARITHMIC, RimGridStatisticsHistogramDataSource::binningModeForResult( "TRANX" ) ); + EXPECT_EQ( RigHistogramCalculator::BinningMode::LOGARITHMIC, RimGridStatisticsHistogramDataSource::binningModeForResult( "MULTZ" ) ); + + // All other results get linear binning + EXPECT_EQ( RigHistogramCalculator::BinningMode::LINEAR, RimGridStatisticsHistogramDataSource::binningModeForResult( "PORO" ) ); + 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() ); +}