diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp index bcc5518614..4a5dfdf117 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.cpp @@ -455,6 +455,8 @@ void RimSummaryMultiPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedFi { setAutoValueStates(); syncAxisRanges(); + analyzePlotsAndAdjustAppearanceSettings(); + zoomAll(); } else if ( changedField == &m_hidePlotsWithValuesBelow ) { @@ -493,7 +495,7 @@ void RimSummaryMultiPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedFi else if ( changedField == &m_autoAdjustAppearance ) { setAutoValueStates(); - checkAndApplyAutoAppearance(); + analyzePlotsAndAdjustAppearanceSettings(); } else { @@ -723,7 +725,7 @@ void RimSummaryMultiPlot::onLoadDataAndUpdate() RimMultiPlot::onLoadDataAndUpdate(); updatePlotWindowTitle(); - checkAndApplyAutoAppearance(); + analyzePlotsAndAdjustAppearanceSettings(); } //-------------------------------------------------------------------------------------------------- @@ -811,18 +813,6 @@ void RimSummaryMultiPlot::setDefaultRangeAggregationSteppingDimension() setAutoValueStates(); } -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -void RimSummaryMultiPlot::checkAndApplyAutoAppearance() -{ - if ( m_autoAdjustAppearance ) - { - analyzePlotsAndAdjustAppearanceSettings(); - syncAxisRanges(); - } -} - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -862,16 +852,15 @@ void RimSummaryMultiPlot::syncAxisRanges() double maxVal = axis->visibleRangeMax(); if ( axis->isAxisInverted() ) std::swap( minVal, maxVal ); - auto axisTitleText = axis->axisTitleText(); - if ( axisRanges.count( axisTitleText ) == 0 ) + auto key = axis->objectName(); + if ( axisRanges.count( key ) == 0 ) { - axisRanges[axisTitleText] = std::make_pair( minVal, maxVal ); + axisRanges[key] = std::make_pair( minVal, maxVal ); } else { - auto& [currentMin, currentMax] = axisRanges[axisTitleText]; - axisRanges[axisTitleText] = - std::make_pair( std::min( currentMin, minVal ), std::max( currentMax, maxVal ) ); + auto& [currentMin, currentMax] = axisRanges[key]; + axisRanges[key] = std::make_pair( std::min( currentMin, minVal ), std::max( currentMax, maxVal ) ); } } } @@ -881,9 +870,10 @@ void RimSummaryMultiPlot::syncAxisRanges() { for ( auto axis : plot->plotYAxes() ) { - auto [minVal, maxVal] = axisRanges[axis->axisTitleText()]; + auto [minVal, maxVal] = axisRanges[axis->objectName()]; if ( axis->isAxisInverted() ) std::swap( minVal, maxVal ); axis->setAutoZoom( false ); + axis->setAutoValueVisibleRangeMin( minVal ); axis->setAutoValueVisibleRangeMax( maxVal ); } @@ -1122,16 +1112,10 @@ void RimSummaryMultiPlot::computeAggregatedAxisRange() if ( axis->isAxisInverted() ) std::swap( minVal, maxVal ); - if ( !axis->isLogarithmicScaleEnabled() ) - { - int maxMajorTickIntervalCount = 8; - double stepSize = 0.0; - QwtLinearScaleEngine scaleEngine; - scaleEngine.autoScale( maxMajorTickIntervalCount, minVal, maxVal, stepSize ); - } + auto [adjustedMinVal, adjustedMaxVal] = adjustedMinMax( axis, minVal, maxVal ); - axis->setAutoValueVisibleRangeMin( minVal ); - axis->setAutoValueVisibleRangeMax( maxVal ); + axis->setAutoValueVisibleRangeMin( adjustedMinVal ); + axis->setAutoValueVisibleRangeMax( adjustedMaxVal ); } } @@ -1228,57 +1212,75 @@ void RimSummaryMultiPlot::duplicate() //-------------------------------------------------------------------------------------------------- void RimSummaryMultiPlot::analyzePlotsAndAdjustAppearanceSettings() { - RiaSummaryAddressAnalyzer analyzer; - - for ( auto p : summaryPlots() ) + if ( m_autoAdjustAppearance ) { - auto addresses = RimSummaryAddressModifier::createEclipseSummaryAddress( p ); - analyzer.appendAddresses( addresses ); - } + // Required to sync axis ranges before computing the auto scale + syncAxisRanges(); - bool hasOnlyOneQuantity = analyzer.isSingleQuantityIgnoreHistory(); + RiaSummaryAddressAnalyzer analyzer; - for ( auto p : summaryPlots() ) - { - auto timeAxisProp = p->timeAxisProperties(); - - if ( columnCount() < 3 ) - timeAxisProp->setAutoValueForMajorTickmarkCount( RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT ); - else - timeAxisProp->setAutoValueForMajorTickmarkCount( RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW ); - - for ( RimPlotAxisPropertiesInterface* axisInterface : p->plotYAxes() ) + for ( auto p : summaryPlots() ) { - auto axisProp = dynamic_cast( axisInterface ); + auto addresses = RimSummaryAddressModifier::createEclipseSummaryAddress( p ); + analyzer.appendAddresses( addresses ); + } - if ( !axisProp ) continue; + bool canShowOneAxisTitlePerRow = analyzer.isSingleQuantityIgnoreHistory() && + ( m_axisRangeAggregation() != AxisRangeAggregation::NONE ); - if ( rowsPerPage() == 1 ) - axisProp->setAutoValueForMajorTickmarkCount( - RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_DEFAULT ); - else - axisProp->setAutoValueForMajorTickmarkCount( - RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_FEW ); + for ( auto p : summaryPlots() ) + { + auto timeAxisProp = p->timeAxisProperties(); - axisProp->computeAndSetAutoValueForScaleFactor(); + auto tickMarkCount = ( columnCount() < 3 ) ? RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT + : RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW; - if ( hasOnlyOneQuantity ) + timeAxisProp->setAutoValueForMajorTickmarkCount( tickMarkCount ); + + for ( auto* axisProp : p->plotYAxes() ) { - auto [row, col] = gridLayoutInfoForSubPlot( p ); - if ( col == 0 ) + if ( !axisProp ) continue; + + auto tickMarkCount = ( rowsPerPage() == 1 ) ? RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT + : RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW; + + axisProp->setAutoValueForMajorTickmarkCount( tickMarkCount ); + + axisProp->computeAndSetAutoValueForScaleFactor(); + + if ( canShowOneAxisTitlePerRow ) + { + auto [row, col] = gridLayoutInfoForSubPlot( p ); + + bool isFirstColumn = ( col == 0 ); + axisProp->setShowUnitText( isFirstColumn ); + axisProp->setShowDescription( isFirstColumn ); + } + else { axisProp->setShowUnitText( true ); axisProp->setShowDescription( true ); } - else - { - axisProp->setShowUnitText( false ); - axisProp->setShowDescription( false ); - } } - } - p->updateAxes(); + p->updateAxes(); + } + } + else + { + for ( auto p : summaryPlots() ) + { + for ( auto* axisProp : p->plotYAxes() ) + { + if ( !axisProp ) continue; + + axisProp->computeAndSetAutoValueForScaleFactor(); + axisProp->setShowUnitText( true ); + axisProp->setShowDescription( true ); + } + + p->updateAxes(); + } } } @@ -1383,6 +1385,31 @@ void RimSummaryMultiPlot::updateReadOnlyState() m_axisRangeAggregation.uiCapability()->setUiReadOnly( m_linkSubPlotAxes() ); } +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::pair RimSummaryMultiPlot::adjustedMinMax( const RimPlotAxisProperties* axis, double min, double max ) const +{ + if ( !axis->isLogarithmicScaleEnabled() ) + { + int maxMajorTickIntervalCount = axis->tickmarkCountFromEnum( axis->majorTickmarkCount() ); + double stepSize = 0.0; + QwtLinearScaleEngine scaleEngine; + + // Do not adjust minimum value, as we usually want to keep zero unchanged + double adjustedMin = min; + + // Adjust the max value to get some space between the top of the plot and the top of the curve + double adjustedMax = max * 1.05; + + scaleEngine.autoScale( maxMajorTickIntervalCount, adjustedMin, adjustedMax, stepSize ); + + return { adjustedMin, adjustedMax }; + } + + return { min, max }; +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h index fbac41864a..d097ebb622 100644 --- a/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h +++ b/ApplicationLibCode/ProjectDataModel/Summary/RimSummaryMultiPlot.h @@ -34,6 +34,7 @@ class RimSummaryPlot; class RimSummaryPlotSourceStepping; class RimSummaryPlotNameHelper; class RimSummaryNameHelper; +class RimPlotAxisProperties; //================================================================================================== /// @@ -104,7 +105,7 @@ public: void zoomAll() override; void setDefaultRangeAggregationSteppingDimension(); - void checkAndApplyAutoAppearance(); + void analyzePlotsAndAdjustAppearanceSettings(); void keepVisiblePageAfterUpdate( bool keepPage ); @@ -144,14 +145,14 @@ private: void appendSubPlotByStepping( int direction ); void appendCurveByStepping( int direction ); - void analyzePlotsAndAdjustAppearanceSettings(); - void onSubPlotChanged( const caf::SignalEmitter* emitter ); void onSubPlotZoomed( const caf::SignalEmitter* emitter ); void onSubPlotAxisChanged( const caf::SignalEmitter* emitter, RimSummaryPlot* summaryPlot ); void updateReadOnlyState(); + std::pair adjustedMinMax( const RimPlotAxisProperties* axis, double min, double max ) const; + private: caf::PdmField m_autoPlotTitle; caf::PdmField m_autoSubPlotTitle; diff --git a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp index e866660621..1280ae6147 100644 --- a/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp +++ b/ApplicationLibCode/UserInterface/RiuMultiPlotBook.cpp @@ -508,7 +508,7 @@ void RiuMultiPlotBook::performUpdate( RiaDefines::MultiPlotPageUpdateType whatTo updateGeometry(); RimSummaryMultiPlot* multiPlot = dynamic_cast( m_plotDefinition.p() ); - if ( multiPlot ) multiPlot->checkAndApplyAutoAppearance(); + if ( multiPlot ) multiPlot->analyzePlotsAndAdjustAppearanceSettings(); // use a timer to trigger a viewer page change, if needed if ( m_goToPageAfterUpdate ) diff --git a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldHandle.cpp b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldHandle.cpp index 4b62e355d1..28522d5ea1 100644 --- a/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldHandle.cpp +++ b/Fwk/AppFwk/cafProjectDataModel/cafPdmUiCore/cafPdmUiFieldHandle.cpp @@ -140,11 +140,7 @@ void PdmUiFieldHandle::setAutoValue( const QVariant& autoValue, bool notifyField { m_autoValue = autoValue; - if ( m_useAutoValue && m_autoValue.isValid() ) - { - setValueFromUiEditor( m_autoValue, notifyFieldChanged ); - updateConnectedEditors(); - } + applyAutoValueAndUpdateEditors( notifyFieldChanged ); } //-------------------------------------------------------------------------------------------------- @@ -158,15 +154,11 @@ QVariant PdmUiFieldHandle::autoValue() const //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void PdmUiFieldHandle::enableAutoValue( bool enable ) +void PdmUiFieldHandle::enableAutoValue( bool enable, bool notifyFieldChanged ) { m_useAutoValue = enable; - if ( m_useAutoValue && m_autoValue.isValid() ) - { - setValueFromUiEditor( m_autoValue, true ); - updateConnectedEditors(); - } + applyAutoValueAndUpdateEditors( notifyFieldChanged ); } //-------------------------------------------------------------------------------------------------- @@ -228,7 +220,11 @@ void PdmUiFieldHandle::setAttributes( const std::vector