#6186 and #6191 Have sensible Analysis Plot defaults

This commit is contained in:
Gaute Lindkvist 2020-07-30 13:20:00 +02:00
parent 6f50201e3a
commit 1130fad55c
6 changed files with 151 additions and 72 deletions

View File

@ -18,6 +18,8 @@
#include "RimAnalysisPlot.h"
#include "RiaPreferences.h"
#include "RiuGroupedBarChartBuilder.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuSummaryQwtPlot.h"
@ -135,7 +137,9 @@ RimAnalysisPlot::RimAnalysisPlot()
CAF_PDM_InitFieldNoDefault( &m_valueSortOperation, "ValueSortOperation", "Sort by Value", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_sortGroupForLegend, "groupForLegend", "Legend Using", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_sortGroupForColors, "groupForColors", "Coloring Using", "", "", "" );
m_sortGroupForColors = RimAnalysisPlot::CASE;
m_showPlotLegends = false;
CAF_PDM_InitField( &m_useTopBarsFilter, "UseTopBarsFilter", false, "Show Only Top", "", "", "" );
m_useTopBarsFilter.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
@ -148,12 +152,14 @@ RimAnalysisPlot::RimAnalysisPlot()
CAF_PDM_InitField( &m_useBarText, "UseBarText", true, "Activate Bar Labels", "", "", "" );
m_useBarText.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
CAF_PDM_InitField( &m_useCaseInBarText, "UseCaseInBarText", false, "Case Name", "", "", "" );
CAF_PDM_InitField( &m_useCaseInBarText, "UseCaseInBarText", true, "Case Name", "", "", "" );
CAF_PDM_InitField( &m_useEnsembleInBarText, "UseEnsembleInBarText", false, "Ensemble", "", "", "" );
CAF_PDM_InitField( &m_useSummaryItemInBarText, "UseSummaryItemInBarText", false, "Summary Item", "", "", "" );
CAF_PDM_InitField( &m_useTimeStepInBarText, "UseTimeStepInBarText", false, "Time Step", "", "", "" );
CAF_PDM_InitField( &m_useQuantityInBarText, "UseQuantityInBarText", false, "Quantity", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_barTextFontSize, "BarTextFontSize", "Font Size", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_valueAxisProperties, "ValueAxisProperties", "ValueAxisProperties", "", "", "" );
m_valueAxisProperties.uiCapability()->setUiTreeHidden( true );
m_valueAxisProperties = new RimPlotAxisProperties;
@ -192,6 +198,25 @@ RimPlotDataFilterCollection* RimAnalysisPlot::plotDataFilterCollection() const
return m_plotDataFilterCollection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnalysisPlot::setCurveDefinitions( const std::vector<RiaSummaryCurveDefinition>& curveDefinitions )
{
m_analysisPlotDataSelection.deleteAllChildObjects();
for ( auto curveDef : curveDefinitions )
{
auto dataEntry = new RimAnalysisPlotDataEntry();
dataEntry->setFromCurveDefinition( curveDef );
m_analysisPlotDataSelection.push_back( dataEntry );
}
auto timeSteps = allAvailableTimeSteps();
if ( m_selectedTimeSteps().empty() && !timeSteps.empty() )
{
m_selectedTimeSteps.v().push_back( RiaQDateTimeTools::fromTime_t( *timeSteps.rbegin() ) );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -450,9 +475,9 @@ void RimAnalysisPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering
selVectorsGrp->add( &m_selectVariablesButtonField, {false} );
QString vectorNames;
if ( m_analyserOfSelectedCurveDefs )
if ( getOrCreateSelectedCurveDefAnalyser() )
{
for ( const std::string& quantityName : m_analyserOfSelectedCurveDefs->m_quantityNames )
for ( const std::string& quantityName : getOrCreateSelectedCurveDefAnalyser()->m_quantityNames )
{
vectorNames += QString::fromStdString( quantityName ) + ", ";
}
@ -478,7 +503,7 @@ void RimAnalysisPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering
uiOrdering.add( &m_barOrientation, {true, 3, 2} );
caf::PdmUiGroup* sortGrp = uiOrdering.addNewGroup( "Sorting and Grouping" );
caf::PdmUiGroup* sortGrp = uiOrdering.addNewGroup( "Sorting, Grouping and Coloring" );
sortGrp->add( &m_majorGroupType );
sortGrp->add( &m_mediumGroupType );
sortGrp->add( &m_minorGroupType );
@ -486,22 +511,23 @@ void RimAnalysisPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering
sortGrp->add( &m_useTopBarsFilter );
sortGrp->add( &m_maxBarCount, {false} );
m_maxBarCount.uiCapability()->setUiReadOnly( !m_useTopBarsFilter() );
sortGrp->add( &m_sortGroupForColors );
caf::PdmUiGroup* legendGrp = uiOrdering.addNewGroup( "Legend" );
legendGrp->add( &m_showPlotLegends );
legendGrp->add( &m_sortGroupForLegend );
legendGrp->add( &m_legendFontSize );
m_sortGroupForLegend.uiCapability()->setUiReadOnly( !m_showPlotLegends() );
m_legendFontSize.uiCapability()->setUiReadOnly( !m_showPlotLegends() );
caf::PdmUiGroup* barLabelGrp = uiOrdering.addNewGroup( "Bar Labels" );
barLabelGrp->add( &m_useBarText );
barLabelGrp->add( &m_barTextFontSize );
barLabelGrp->add( &m_useQuantityInBarText );
barLabelGrp->add( &m_useSummaryItemInBarText, {false} );
barLabelGrp->add( &m_useSummaryItemInBarText );
barLabelGrp->add( &m_useCaseInBarText );
barLabelGrp->add( &m_useEnsembleInBarText, {false} );
barLabelGrp->add( &m_useTimeStepInBarText, {true, 4, 1} );
barLabelGrp->add( &m_useEnsembleInBarText );
barLabelGrp->add( &m_useTimeStepInBarText );
m_barTextFontSize.uiCapability()->setUiReadOnly( !m_useBarText );
m_useQuantityInBarText.uiCapability()->setUiReadOnly( !m_useBarText );
m_useSummaryItemInBarText.uiCapability()->setUiReadOnly( !m_useBarText );
m_useCaseInBarText.uiCapability()->setUiReadOnly( !m_useBarText );
@ -546,12 +572,6 @@ QList<caf::PdmOptionItemInfo> RimAnalysisPlot::calculateValueOptions( const caf:
if ( !options.isEmpty() ) return options;
if ( !m_analyserOfSelectedCurveDefs )
{
m_analyserOfSelectedCurveDefs = std::unique_ptr<RiaSummaryCurveDefinitionAnalyser>(
new RiaSummaryCurveDefinitionAnalyser( this->curveDefinitionsWithoutEnsembleReference() ) );
}
if ( fieldNeedingOptions == &m_addTimestepUiField )
{
options.push_back( {"None", QDateTime()} );
@ -573,7 +593,7 @@ QList<caf::PdmOptionItemInfo> RimAnalysisPlot::calculateValueOptions( const caf:
options.push_back( caf::PdmOptionItemInfo( SortGroupAppEnum::uiText( ABS_VALUE ), ABS_VALUE ) );
}
else if ( fieldNeedingOptions == &m_majorGroupType || fieldNeedingOptions == &m_mediumGroupType ||
fieldNeedingOptions == &m_minorGroupType || fieldNeedingOptions == &m_sortGroupForLegend )
fieldNeedingOptions == &m_minorGroupType || fieldNeedingOptions == &m_sortGroupForColors )
{
options.push_back( caf::PdmOptionItemInfo( SortGroupAppEnum::uiText( NONE ), NONE ) );
options.push_back( caf::PdmOptionItemInfo( SortGroupAppEnum::uiText( SUMMARY_ITEM ), SUMMARY_ITEM ) );
@ -600,6 +620,10 @@ QList<caf::PdmOptionItemInfo> RimAnalysisPlot::calculateValueOptions( const caf:
options.push_back( {displayName, sumCase} );
}
}
else if ( fieldNeedingOptions == &m_barTextFontSize )
{
options = caf::FontTools::relativeSizeValueOptions( RiaPreferences::current()->defaultPlotFontSize() );
}
return options;
}
@ -629,7 +653,13 @@ std::set<time_t> RimAnalysisPlot::allAvailableTimeSteps()
//--------------------------------------------------------------------------------------------------
std::set<RimSummaryCase*> RimAnalysisPlot::timestepDefiningSourceCases()
{
std::set<RimSummaryCase*> timeStepDefiningSumCases = m_analyserOfSelectedCurveDefs->m_singleSummaryCases;
RiaSummaryCurveDefinitionAnalyser* analyserOfSelectedCurveDefs = getOrCreateSelectedCurveDefAnalyser();
std::set<RimSummaryCase*> timeStepDefiningSumCases = analyserOfSelectedCurveDefs->m_singleSummaryCases;
for ( auto ensemble : analyserOfSelectedCurveDefs->m_ensembles )
{
auto allSumCases = ensemble->allSummaryCases();
timeStepDefiningSumCases.insert( allSumCases.begin(), allSumCases.end() );
}
return timeStepDefiningSumCases;
}
@ -639,7 +669,8 @@ std::set<RimSummaryCase*> RimAnalysisPlot::timestepDefiningSourceCases()
//--------------------------------------------------------------------------------------------------
std::set<RimSummaryCase*> RimAnalysisPlot::allSourceCases()
{
std::set<RimSummaryCase*> allSumCases = m_analyserOfSelectedCurveDefs->m_singleSummaryCases;
RiaSummaryCurveDefinitionAnalyser* analyserOfSelectedCurveDefs = getOrCreateSelectedCurveDefAnalyser();
std::set<RimSummaryCase*> allSumCases = analyserOfSelectedCurveDefs->m_singleSummaryCases;
return allSumCases;
}
@ -667,8 +698,7 @@ void RimAnalysisPlot::onLoadDataAndUpdate()
{
updateMdiWindowVisibility();
m_analyserOfSelectedCurveDefs = std::unique_ptr<RiaSummaryCurveDefinitionAnalyser>(
new RiaSummaryCurveDefinitionAnalyser( this->curveDefinitionsWithoutEnsembleReference() ) );
getOrCreateSelectedCurveDefAnalyser();
if ( m_plotWidget )
{
@ -676,7 +706,7 @@ void RimAnalysisPlot::onLoadDataAndUpdate()
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotScale );
RiuGroupedBarChartBuilder chartBuilder;
chartBuilder.setLabelFontSize( barTextFontSize() );
// buildTestPlot( chartBuilder );
addDataToChartBuilder( chartBuilder );
@ -1416,7 +1446,7 @@ void RimAnalysisPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chartBui
QString majorText = assignGroupingText( m_majorGroupType(), curveDef, timestepString );
QString medText = assignGroupingText( m_mediumGroupType(), curveDef, timestepString );
QString minText = assignGroupingText( m_minorGroupType(), curveDef, timestepString );
QString legendText = assignGroupingText( m_sortGroupForLegend(), curveDef, timestepString );
QString legendText = assignGroupingText( m_sortGroupForColors(), curveDef, timestepString );
double value = values[timestepIdx];
@ -1471,29 +1501,30 @@ void RimAnalysisPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chartBui
//--------------------------------------------------------------------------------------------------
void RimAnalysisPlot::updatePlotTitle()
{
if ( m_useAutoPlotTitle && m_analyserOfSelectedCurveDefs )
if ( m_useAutoPlotTitle )
{
QString autoTitle;
QString separator = ", ";
if ( m_analyserOfSelectedCurveDefs->m_ensembles.size() == 1 )
if ( getOrCreateSelectedCurveDefAnalyser()->m_ensembles.size() == 1 )
{
autoTitle += ( *m_analyserOfSelectedCurveDefs->m_ensembles.begin() )->name();
autoTitle += ( *getOrCreateSelectedCurveDefAnalyser()->m_ensembles.begin() )->name();
}
if ( m_analyserOfSelectedCurveDefs->m_singleSummaryCases.size() == 1 )
if ( getOrCreateSelectedCurveDefAnalyser()->m_singleSummaryCases.size() == 1 )
{
if ( !autoTitle.isEmpty() ) autoTitle += separator;
autoTitle += ( *m_analyserOfSelectedCurveDefs->m_singleSummaryCases.begin() )->displayCaseName();
autoTitle += ( *getOrCreateSelectedCurveDefAnalyser()->m_singleSummaryCases.begin() )->displayCaseName();
}
if ( m_analyserOfSelectedCurveDefs->m_summaryItems.size() == 1 )
if ( getOrCreateSelectedCurveDefAnalyser()->m_summaryItems.size() == 1 )
{
if ( !autoTitle.isEmpty() ) autoTitle += separator;
autoTitle += QString::fromStdString( m_analyserOfSelectedCurveDefs->m_summaryItems.begin()->itemUiText() );
autoTitle +=
QString::fromStdString( getOrCreateSelectedCurveDefAnalyser()->m_summaryItems.begin()->itemUiText() );
}
for ( std::string quantName : m_analyserOfSelectedCurveDefs->m_quantityNames )
for ( std::string quantName : getOrCreateSelectedCurveDefAnalyser()->m_quantityNames )
{
if ( !autoTitle.isEmpty() ) autoTitle += separator;
autoTitle += QString::fromStdString( quantName );
@ -1668,3 +1699,11 @@ void RimAnalysisPlot::buildTestPlot( RiuGroupedBarChartBuilder& chartBuilder )
chartBuilder.addBarEntry( "", "", "", 1.6, "", "E", 1.6 );
chartBuilder.addBarEntry( "", "", "", 2.4, "", "F", -2.4 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
int RimAnalysisPlot::barTextFontSize() const
{
return caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(), m_barTextFontSize() );
}

View File

@ -46,29 +46,6 @@ class RimAnalysisPlot : public RimPlot
CAF_PDM_HEADER_INIT;
public:
RimAnalysisPlot();
~RimAnalysisPlot() override;
void updateCaseNameHasChanged();
RimPlotDataFilterCollection* plotDataFilterCollection() const;
std::set<RifEclipseSummaryAddress> unfilteredAddresses();
std::set<EnsembleParameter> ensembleParameters();
EnsembleParameter ensembleParameter( const QString& ensembleParameterName );
void maxMinValueFromAddress( const RifEclipseSummaryAddress& address,
RimPlotDataFilterItem::TimeStepSourceType timeStepSourceType,
const std::vector<QDateTime>& timeRangeOrSelection,
bool useAbsValue,
double* min,
double* max );
void onFiltersChanged();
std::vector<time_t> selectedTimeSteps();
public: // Internal. Public needed for AppEnum setup
enum BarOrientation
{
BARS_HORIZONTAL,
@ -90,6 +67,31 @@ public: // Internal. Public needed for AppEnum setup
};
typedef caf::AppEnum<SortGroupType> SortGroupAppEnum;
public:
RimAnalysisPlot();
~RimAnalysisPlot() override;
void updateCaseNameHasChanged();
RimPlotDataFilterCollection* plotDataFilterCollection() const;
void setCurveDefinitions( const std::vector<RiaSummaryCurveDefinition>& curveDefinitions );
std::set<RifEclipseSummaryAddress> unfilteredAddresses();
std::set<EnsembleParameter> ensembleParameters();
EnsembleParameter ensembleParameter( const QString& ensembleParameterName );
void maxMinValueFromAddress( const RifEclipseSummaryAddress& address,
RimPlotDataFilterItem::TimeStepSourceType timeStepSourceType,
const std::vector<QDateTime>& timeRangeOrSelection,
bool useAbsValue,
double* min,
double* max );
void onFiltersChanged();
std::vector<time_t> selectedTimeSteps();
private:
// Overridden PDM methods
@ -166,6 +168,8 @@ private:
void buildTestPlot( RiuGroupedBarChartBuilder& chartBuilder );
int barTextFontSize() const;
private:
std::unique_ptr<RiaSummaryCurveDefinitionAnalyser> m_analyserOfSelectedCurveDefs;
@ -197,14 +201,15 @@ private:
caf::PdmField<bool> m_useTopBarsFilter;
caf::PdmField<int> m_maxBarCount;
caf::PdmField<SortGroupAppEnum> m_sortGroupForLegend;
caf::PdmField<SortGroupAppEnum> m_sortGroupForColors;
caf::PdmField<bool> m_useBarText;
caf::PdmField<bool> m_useCaseInBarText;
caf::PdmField<bool> m_useEnsembleInBarText;
caf::PdmField<bool> m_useSummaryItemInBarText;
caf::PdmField<bool> m_useTimeStepInBarText;
caf::PdmField<bool> m_useQuantityInBarText;
caf::PdmField<bool> m_useBarText;
caf::PdmField<bool> m_useCaseInBarText;
caf::PdmField<bool> m_useEnsembleInBarText;
caf::PdmField<bool> m_useSummaryItemInBarText;
caf::PdmField<bool> m_useTimeStepInBarText;
caf::PdmField<bool> m_useQuantityInBarText;
caf::PdmField<caf::FontTools::RelativeSizeEnum> m_barTextFontSize;
caf::PdmChildField<RimPlotAxisProperties*> m_valueAxisProperties;
caf::PdmChildField<RimPlotDataFilterCollection*> m_plotDataFilterCollection;

View File

@ -19,6 +19,7 @@
#include "RimAnalysisPlotCollection.h"
#include "RimAnalysisPlot.h"
#include "RimProject.h"
CAF_PDM_SOURCE_INIT( RimAnalysisPlotCollection, "AnalysisPlotCollection" );
@ -48,9 +49,14 @@ RimAnalysisPlot* RimAnalysisPlotCollection::createAnalysisPlot()
RimAnalysisPlot* plot = new RimAnalysisPlot();
plot->setAsPlotMdiWindow();
applyFirstEnsembleFieldAddressesToPlot( plot, "FOPT" );
// plot->enableAutoPlotTitle( true );
m_analysisPlots.push_back( plot );
plot->loadDataAndUpdate();
plot->updateConnectedEditors();
return plot;
}
@ -88,3 +94,32 @@ void RimAnalysisPlotCollection::deleteAllChildObjects()
{
m_analysisPlots.deleteAllChildObjects();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAnalysisPlotCollection::applyFirstEnsembleFieldAddressesToPlot( RimAnalysisPlot* plot,
const std::string& quantityName )
{
std::vector<RimSummaryCaseCollection*> ensembles;
RimProject::current()->descendantsIncludingThisOfType( ensembles );
if ( !ensembles.empty() )
{
std::set<RifEclipseSummaryAddress> allAddresses = ensembles.front()->ensembleSummaryAddresses();
std::vector<RiaSummaryCurveDefinition> curveDefs;
for ( auto address : allAddresses )
{
if ( address.category() == RifEclipseSummaryAddress::SUMMARY_FIELD )
{
if ( quantityName.empty() || quantityName == address.quantityName() )
{
for ( auto summaryCase : ensembles.front()->allSummaryCases() )
{
curveDefs.push_back( RiaSummaryCurveDefinition( summaryCase, address, nullptr ) );
}
}
}
}
plot->setCurveDefinitions( curveDefs );
}
}

View File

@ -43,6 +43,9 @@ public:
void deleteAllChildObjects();
private:
void applyFirstEnsembleFieldAddressesToPlot( RimAnalysisPlot* plot, const std::string& quantityName = "" );
private:
caf::PdmChildArrayField<RimAnalysisPlot*> m_analysisPlots;
};

View File

@ -560,20 +560,17 @@ time_t RimAbstractCorrelationPlot::timeDiff( time_t lhs, time_t rhs )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimAbstractCorrelationPlot::selectedVarsText() const
QString RimAbstractCorrelationPlot::selectedVarsText()
{
QString vectorNames;
if ( m_analyserOfSelectedCurveDefs )
for ( const std::string& quantityName : getOrCreateSelectedCurveDefAnalyser()->m_quantityNames )
{
for ( const std::string& quantityName : m_analyserOfSelectedCurveDefs->m_quantityNames )
{
vectorNames += QString::fromStdString( quantityName ) + ", ";
}
vectorNames += QString::fromStdString( quantityName ) + ", ";
}
if ( !vectorNames.isEmpty() )
{
vectorNames.chop( 2 );
}
if ( !vectorNames.isEmpty() )
{
vectorNames.chop( 2 );
}
return vectorNames;

View File

@ -113,7 +113,7 @@ protected:
static time_t timeDiff( time_t lhs, time_t rhs );
QString selectedVarsText() const;
QString selectedVarsText();
protected:
std::unique_ptr<RiaSummaryCurveDefinitionAnalyser> m_analyserOfSelectedCurveDefs;