From 442854cddd3d27b8f8837d02f82b8697bdf753ec Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Tue, 27 Oct 2026 19:05:53 +0100 Subject: [PATCH] #15063: Histogram: Zoom all when data is filtered by 3D view visibility Zoom all when the cell filter view is changed or when the visibility in the 3D view is updated, as the visible cells can have a very different value range than the full grid. --- .../RimGridStatisticsHistogramDataSource.cpp | 17 ++++++++++++++++- .../RimGridStatisticsHistogramDataSource.h | 3 +++ .../Histogram/RimHistogramCurve.cpp | 10 ++++++++++ .../Histogram/RimHistogramCurve.h | 1 + .../Histogram/RimHistogramDataSource.cpp | 1 + .../Histogram/RimHistogramDataSource.h | 1 + 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp index 475e58cbe4..416ab4de11 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.cpp @@ -20,7 +20,6 @@ #include "RiaResultNames.h" -#include "Histogram/RimHistogramPlot.h" #include "RimEclipseCase.h" #include "RimEclipseCellColors.h" #include "RimEclipseResultDefinition.h" @@ -162,6 +161,13 @@ void RimGridStatisticsHistogramDataSource::fieldChangedByUi( const caf::PdmField // deleted while it is being emitted. cumulativeChanged.send(); } + else if ( changedField == &m_cellFilterView ) + { + m_cellFilterViewDataRange = dataRange(); + + dataSourceChanged.send(); + zoomAllRequested.send(); + } else { dataSourceChanged.send(); @@ -362,6 +368,15 @@ void RimGridStatisticsHistogramDataSource::setDefaults() void RimGridStatisticsHistogramDataSource::cellFilterViewUpdated() { dataSourceChanged.send(); + + // The view is updated for many reasons not affecting the visible cells, e.g. a legend change. Only zoom all when the + // range of the visible data has changed, to keep the user's zoom otherwise. + const auto range = dataRange(); + if ( range != m_cellFilterViewDataRange ) + { + m_cellFilterViewDataRange = range; + zoomAllRequested.send(); + } } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h index 5027398e70..dc1975ffc4 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimGridStatisticsHistogramDataSource.h @@ -89,4 +89,7 @@ protected: private: QString m_previousResultVariable; + + // Range of the visible data at the last zoom all, used to detect changes in the cell filter view + std::optional> m_cellFilterViewDataRange; }; diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp index e9c09b8a6d..4946a4a947 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.cpp @@ -118,6 +118,7 @@ void RimHistogramCurve::setDataSource( RimHistogramDataSource* dataSource ) m_dataSource->dataSourceChanged.connect( this, &RimHistogramCurve::onDataSourceChanged ); m_dataSource->cumulativeChanged.connect( this, &RimHistogramCurve::onCumulativeChanged ); m_dataSource->binningModeChanged.connect( this, &RimHistogramCurve::onBinningModeChanged ); + m_dataSource->zoomAllRequested.connect( this, &RimHistogramCurve::onZoomAllRequested ); } } @@ -140,6 +141,7 @@ void RimHistogramCurve::connectReferencedDataSourceSignals() { // Connecting an already connected observer is a no-op m_dataSourceReference()->dataSourceChanged.connect( this, &RimHistogramCurve::onDataSourceChanged ); + m_dataSourceReference()->zoomAllRequested.connect( this, &RimHistogramCurve::onZoomAllRequested ); } } @@ -605,6 +607,14 @@ void RimHistogramCurve::onCumulativeChanged( const caf::SignalEmitter* emitter ) updateCumulativeCurve(); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RimHistogramCurve::onZoomAllRequested( const caf::SignalEmitter* emitter ) +{ + if ( auto plot = firstAncestorOrThisOfType() ) plot->zoomAll(); +} + //-------------------------------------------------------------------------------------------------- /// 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. diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h index daaac5a108..9e6c4cf20b 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramCurve.h @@ -88,6 +88,7 @@ protected: void onDataSourceChanged( const caf::SignalEmitter* emitter ); void onCumulativeChanged( const caf::SignalEmitter* emitter ); + void onZoomAllRequested( const caf::SignalEmitter* emitter ); void onBinningModeChanged( const caf::SignalEmitter* emitter, RigHistogramCalculator::BinningMode binningMode ); void updateCumulativeCurve(); diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp index 692e835d08..a7cd5269fd 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.cpp @@ -57,6 +57,7 @@ void caf::AppEnum::setUp() RimHistogramDataSource::RimHistogramDataSource() : dataSourceChanged( this ) , cumulativeChanged( this ) + , zoomAllRequested( this ) , binningModeChanged( this ) { CAF_PDM_InitObject( "Histogram Data Source", ); diff --git a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h index 0ddf9fb03a..eeaccaa8d3 100644 --- a/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h +++ b/ApplicationLibCode/ProjectDataModel/Histogram/RimHistogramDataSource.h @@ -70,6 +70,7 @@ public: caf::Signal<> dataSourceChanged; caf::Signal<> cumulativeChanged; + caf::Signal<> zoomAllRequested; caf::Signal binningModeChanged; virtual std::string unitNameX() const = 0;