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 committed by GitHub
parent 58852781c3
commit 22cd06b4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,6 +1212,11 @@ void RimSummaryMultiPlot::duplicate()
//--------------------------------------------------------------------------------------------------
void RimSummaryMultiPlot::analyzePlotsAndAdjustAppearanceSettings()
{
if ( m_autoAdjustAppearance )
{
// Required to sync axis ranges before computing the auto scale
syncAxisRanges();
RiaSummaryAddressAnalyzer analyzer;
for ( auto p : summaryPlots() )
@ -1236,50 +1225,63 @@ void RimSummaryMultiPlot::analyzePlotsAndAdjustAppearanceSettings()
analyzer.appendAddresses( addresses );
}
bool hasOnlyOneQuantity = analyzer.isSingleQuantityIgnoreHistory();
bool canShowOneAxisTitlePerRow = analyzer.isSingleQuantityIgnoreHistory() &&
( m_axisRangeAggregation() != AxisRangeAggregation::NONE );
for ( auto p : summaryPlots() )
{
auto timeAxisProp = p->timeAxisProperties();
if ( columnCount() < 3 )
timeAxisProp->setAutoValueForMajorTickmarkCount( RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT );
else
timeAxisProp->setAutoValueForMajorTickmarkCount( RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW );
auto tickMarkCount = ( columnCount() < 3 ) ? RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT
: RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW;
for ( RimPlotAxisPropertiesInterface* axisInterface : p->plotYAxes() )
timeAxisProp->setAutoValueForMajorTickmarkCount( tickMarkCount );
for ( auto* axisProp : p->plotYAxes() )
{
auto axisProp = dynamic_cast<RimPlotAxisProperties*>( axisInterface );
if ( !axisProp ) continue;
if ( rowsPerPage() == 1 )
axisProp->setAutoValueForMajorTickmarkCount(
RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_DEFAULT );
else
axisProp->setAutoValueForMajorTickmarkCount(
RimPlotAxisPropertiesInterface::LegendTickmarkCount::TICKMARK_FEW );
auto tickMarkCount = ( rowsPerPage() == 1 ) ? RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT
: RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW;
axisProp->setAutoValueForMajorTickmarkCount( tickMarkCount );
axisProp->computeAndSetAutoValueForScaleFactor();
if ( hasOnlyOneQuantity )
if ( canShowOneAxisTitlePerRow )
{
auto [row, col] = gridLayoutInfoForSubPlot( p );
if ( col == 0 )
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();
}
}
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 )

View File

@ -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<std::pair<QString, QStri
{
if ( valueString == "TRUE" )
{
enableAutoValue( true );
// If notifyFieldChanged equals true, recursion will happen. Triggered by
// RimSummaryPlot::copyMatchingAxisPropertiesFromOther(), where data from one object is copied and set
// in another object using readObjectFromXmlString()
bool notifyFieldChanged = false;
enableAutoValue( true, notifyFieldChanged );
}
}
else if ( key == "autoValueSupported" )
@ -257,6 +253,18 @@ bool PdmUiFieldHandle::isQVariantDataEqual( const QVariant& oldUiBasedQVariant,
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmUiFieldHandle::applyAutoValueAndUpdateEditors( bool notifyFieldChanged )
{
if ( m_useAutoValue && m_autoValue.isValid() )
{
setValueFromUiEditor( m_autoValue, notifyFieldChanged );
updateConnectedEditors();
}
}
//--------------------------------------------------------------------------------------------------
/// Implementation of uiCapability() defined in cafPdmFieldHandle.h
//--------------------------------------------------------------------------------------------------

View File

@ -30,7 +30,7 @@ public:
void enableAndSetAutoValue( const QVariant& autoValue );
void setAutoValue( const QVariant& autoValue, bool notifyFieldChanged = true );
QVariant autoValue() const;
void enableAutoValue( bool enable );
void enableAutoValue( bool enable, bool notifyFieldChanged = true );
bool isAutoValueEnabled() const;
void enableAutoValueSupport( bool enable );
bool isAutoValueSupported() const;
@ -46,6 +46,8 @@ private:
// custom types.
virtual bool isQVariantDataEqual( const QVariant& oldUiBasedQVariant, const QVariant& newUiBasedQVariant ) const;
void applyAutoValueAndUpdateEditors( bool notifyFieldChanged );
private:
PdmFieldHandle* m_owner;
bool m_isAutoAddingOptionFromValue;