Adjust auto plot settings

* Adjust the max value for summary curves to get more space on top of plot
* Compute axis range before computing auto plot settings
* Use axis object name as key when computing aggregated min/max
* Guard infinite recursion for enableAutoValue()
This commit is contained in:
Magne Sjaastad
2022-09-13 17:45:41 +02:00
parent 8dc04d00e1
commit 60aeda1e6f
5 changed files with 121 additions and 83 deletions

View File

@@ -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<RimPlotAxisProperties*>( 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<double, double> 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 };
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -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<double, double> adjustedMinMax( const RimPlotAxisProperties* axis, double min, double max ) const;
private:
caf::PdmField<bool> m_autoPlotTitle;
caf::PdmField<bool> m_autoSubPlotTitle;

View File

@@ -508,7 +508,7 @@ void RiuMultiPlotBook::performUpdate( RiaDefines::MultiPlotPageUpdateType whatTo
updateGeometry();
RimSummaryMultiPlot* multiPlot = dynamic_cast<RimSummaryMultiPlot*>( 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 )