mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#5539 Add optional top N filter
Adjust layout in Analysis Plot property panel Add colormap option to barchart builder
This commit is contained in:
parent
afea6963b2
commit
782b5c360d
@ -38,6 +38,7 @@
|
||||
#include "RimSummaryCase.h"
|
||||
#include "RimSummaryCaseCollection.h"
|
||||
|
||||
#include "cafPdmUiCheckBoxEditor.h"
|
||||
#include "cafPdmUiComboBoxEditor.h"
|
||||
#include "cafPdmUiListEditor.h"
|
||||
|
||||
@ -113,12 +114,15 @@ RimAnalysisPlot::RimAnalysisPlot()
|
||||
{
|
||||
CAF_PDM_InitObject( "Analysis Plot", ":/Histogram16x16.png", "", "" );
|
||||
|
||||
CAF_PDM_InitField( &m_showPlotTitle, "ShowPlotTitle", true, "Plot Title", "", "", "" );
|
||||
CAF_PDM_InitField( &m_showPlotTitle, "ShowPlotTitle", true, "Title", "", "", "" );
|
||||
m_showPlotTitle.xmlCapability()->setIOWritable( false );
|
||||
m_showPlotTitle.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitField( &m_useAutoPlotTitle, "IsUsingAutoName", true, "Auto Title", "", "", "" );
|
||||
CAF_PDM_InitField( &m_useAutoPlotTitle, "IsUsingAutoName", true, "Auto", "", "", "" );
|
||||
m_useAutoPlotTitle.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitField( &m_description, "PlotDescription", QString( "Analysis Plot" ), "Title", "", "", "" );
|
||||
m_description.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_barOrientation, "BarOrientation", "Bar Orientation", "", "", "" );
|
||||
|
||||
@ -143,6 +147,12 @@ RimAnalysisPlot::RimAnalysisPlot()
|
||||
m_selectedTimeSteps.uiCapability()->setUiEditorTypeName( caf::PdmUiListEditor::uiEditorTypeName() );
|
||||
m_selectedTimeSteps.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitField( &m_useTopBarsFilter, "UseTopBarsFilter", false, "Show Only Top", "", "", "" );
|
||||
m_useTopBarsFilter.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitField( &m_maxBarCount, "MaxBarCount", 20, "Bar Count", "", "", "" );
|
||||
m_maxBarCount.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_majorGroupType, "MajorGroupType", "Major Grouping", "", "", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_mediumGroupType, "MediumGroupType", "Medium Grouping", "", "", "" );
|
||||
CAF_PDM_InitFieldNoDefault( &m_minorGroupType, "MinorGroupType", "Minor Grouping", "", "", "" );
|
||||
@ -151,7 +161,9 @@ RimAnalysisPlot::RimAnalysisPlot()
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_sortGroupForLegend, "groupForLegend", "Legend Using", "", "", "" );
|
||||
|
||||
CAF_PDM_InitField( &m_useBarText, "UseBarText", true, "Label Bars", "", "", "" );
|
||||
CAF_PDM_InitField( &m_useBarText, "UseBarText", true, "Activate Bar Labels", "", "", "" );
|
||||
m_useBarText.uiCapability()->setUiLabelPosition( caf::PdmUiItemInfo::HIDDEN );
|
||||
|
||||
CAF_PDM_InitField( &m_useCaseInBarText, "UseCaseInBarText", true, "Case Name", "", "", "" );
|
||||
CAF_PDM_InitField( &m_useEnsembleInBarText, "UseEnsembleInBarText", true, "Ensemble", "", "", "" );
|
||||
CAF_PDM_InitField( &m_useSummaryItemInBarText, "UseSummaryItemInBarText", true, "Summary Item", "", "", "" );
|
||||
@ -478,17 +490,20 @@ void RimAnalysisPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering
|
||||
timeStepGrp->add( &m_selectedTimeSteps );
|
||||
|
||||
uiOrdering.add( &m_showPlotTitle );
|
||||
uiOrdering.add( &m_useAutoPlotTitle );
|
||||
uiOrdering.add( &m_description );
|
||||
uiOrdering.add( &m_useAutoPlotTitle, {false} );
|
||||
uiOrdering.add( &m_description, {false} );
|
||||
m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() );
|
||||
|
||||
uiOrdering.add( &m_barOrientation );
|
||||
uiOrdering.add( &m_barOrientation, {true, 3, 2} );
|
||||
|
||||
caf::PdmUiGroup* sortGrp = uiOrdering.addNewGroup( "Sorting and Grouping" );
|
||||
sortGrp->add( &m_majorGroupType );
|
||||
sortGrp->add( &m_mediumGroupType );
|
||||
sortGrp->add( &m_minorGroupType );
|
||||
sortGrp->add( &m_valueSortOperation );
|
||||
sortGrp->add( &m_useTopBarsFilter );
|
||||
sortGrp->add( &m_maxBarCount, {false} );
|
||||
m_maxBarCount.uiCapability()->setUiReadOnly( !m_useTopBarsFilter() );
|
||||
|
||||
caf::PdmUiGroup* legendGrp = uiOrdering.addNewGroup( "Legend" );
|
||||
legendGrp->add( &m_showPlotLegends );
|
||||
@ -498,7 +513,7 @@ void RimAnalysisPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering
|
||||
m_legendFontSize.uiCapability()->setUiReadOnly( !m_showPlotLegends() );
|
||||
|
||||
caf::PdmUiGroup* barLabelGrp = uiOrdering.addNewGroup( "Bar Labels" );
|
||||
barLabelGrp->add( &m_useBarText, {true, 4, 1} );
|
||||
barLabelGrp->add( &m_useBarText );
|
||||
barLabelGrp->add( &m_useQuantityInBarText );
|
||||
barLabelGrp->add( &m_useSummaryItemInBarText, {false} );
|
||||
barLabelGrp->add( &m_useCaseInBarText );
|
||||
@ -603,7 +618,9 @@ void RimAnalysisPlot::onLoadDataAndUpdate()
|
||||
// buildTestPlot( chartBuilder );
|
||||
addDataToChartBuilder( chartBuilder );
|
||||
|
||||
chartBuilder.addBarChartToPlot( m_plotWidget, m_barOrientation == BARS_HORIZONTAL ? Qt::Horizontal : Qt::Vertical );
|
||||
chartBuilder.addBarChartToPlot( m_plotWidget,
|
||||
m_barOrientation == BARS_HORIZONTAL ? Qt::Horizontal : Qt::Vertical,
|
||||
m_useTopBarsFilter() ? m_maxBarCount : -1 );
|
||||
|
||||
if ( m_showPlotLegends && m_plotWidget->legend() == nullptr )
|
||||
{
|
||||
@ -696,6 +713,10 @@ void RimAnalysisPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chartBui
|
||||
RifSummaryReaderInterface* reader = dataEntry->summaryCase()->summaryReader();
|
||||
if ( !reader ) continue;
|
||||
|
||||
// Todo:
|
||||
// If is RimGridSummaryCase and using summary item ans legend and summary items are wells, then:
|
||||
/// use color from eclCase->defaultWellColor( wellName );
|
||||
|
||||
const std::vector<time_t>& timesteps = reader->timeSteps( dataEntry->summaryAddress() );
|
||||
|
||||
std::vector<double> values;
|
||||
@ -888,3 +909,20 @@ std::vector<RiaSummaryCurveDefinition> RimAnalysisPlot::curveDefinitions()
|
||||
|
||||
return curveDefs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimAnalysisPlot::defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute )
|
||||
{
|
||||
if ( field == &m_useTopBarsFilter || field == &m_useBarText || field == &m_showPlotTitle || field == &m_useAutoPlotTitle )
|
||||
{
|
||||
auto attrib = dynamic_cast<caf::PdmUiCheckBoxEditorAttribute*>( attribute );
|
||||
if ( attrib )
|
||||
{
|
||||
attrib->m_useNativeCheckBoxLabel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -103,13 +103,16 @@ private:
|
||||
void doRemoveFromCollection() override;
|
||||
|
||||
QImage snapshotWindowContent() override;
|
||||
void onLoadDataAndUpdate() override;
|
||||
|
||||
// Overridden PDM methods
|
||||
caf::PdmFieldHandle* userDescriptionField() override;
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void defineUiTreeOrdering( caf::PdmUiTreeOrdering& uiTreeOrdering, QString uiConfigName = "" ) override;
|
||||
void defineUiOrdering( QString uiConfigName, caf::PdmUiOrdering& uiOrdering ) override;
|
||||
void onLoadDataAndUpdate() override;
|
||||
void defineEditorAttribute( const caf::PdmFieldHandle* field,
|
||||
QString uiConfigName,
|
||||
caf::PdmUiEditorAttribute* attribute ) override;
|
||||
QList<caf::PdmOptionItemInfo> calculateValueOptions( const caf::PdmFieldHandle* fieldNeedingOptions,
|
||||
bool* useOptionsOnly ) override;
|
||||
|
||||
@ -146,6 +149,9 @@ private:
|
||||
caf::PdmField<QDateTime> m_addTimestepUiField;
|
||||
caf::PdmField<std::vector<QDateTime>> m_selectedTimeSteps;
|
||||
|
||||
caf::PdmField<bool> m_useTopBarsFilter;
|
||||
caf::PdmField<int> m_maxBarCount;
|
||||
|
||||
caf::PdmField<SortGroupAppEnum> m_majorGroupType;
|
||||
caf::PdmField<SortGroupAppEnum> m_mediumGroupType;
|
||||
caf::PdmField<SortGroupAppEnum> m_minorGroupType;
|
||||
|
@ -206,7 +206,15 @@ void RiuGroupedBarChartBuilder::addBarEntry( const QString& majorTickText,
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientation barOrientation )
|
||||
void RiuGroupedBarChartBuilder::setLegendColorMap( const std::map<QString, QColor>& legendColors )
|
||||
{
|
||||
m_legendColors = legendColors;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientation barOrientation, int maxBarCount )
|
||||
{
|
||||
const double majGroupSpacing = 1.6;
|
||||
const double midGroupSpacing = 0.5;
|
||||
@ -234,6 +242,42 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
|
||||
QList<double> midTickPositions;
|
||||
QList<double> minTickPositions;
|
||||
|
||||
// Filter the entries according to value
|
||||
std::multiset<BarEntry> filteredBarEntries;
|
||||
if ( maxBarCount >= 0 )
|
||||
{
|
||||
std::map<double, BarEntry> valueFilteredBarEntries;
|
||||
int mapSize = 0;
|
||||
|
||||
for ( const BarEntry& barDef : m_sortedBarEntries )
|
||||
{
|
||||
if ( mapSize < maxBarCount )
|
||||
{
|
||||
if ( valueFilteredBarEntries.insert( std::make_pair( fabs( barDef.m_value ), barDef ) ).second )
|
||||
{
|
||||
mapSize++;
|
||||
}
|
||||
}
|
||||
else if ( fabs( barDef.m_value ) > valueFilteredBarEntries.begin()->first )
|
||||
{
|
||||
if ( valueFilteredBarEntries.insert( std::make_pair( fabs( barDef.m_value ), barDef ) ).second )
|
||||
{
|
||||
valueFilteredBarEntries.erase( valueFilteredBarEntries.begin() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( auto valEntryPair : valueFilteredBarEntries )
|
||||
{
|
||||
filteredBarEntries.insert( valEntryPair.second );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// No filtering
|
||||
filteredBarEntries = m_sortedBarEntries;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
auto addGroupTickText = [&]( double groupStartPos, QString tickText, QList<double>& groupTickPosList )
|
||||
{
|
||||
@ -259,7 +303,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
|
||||
|
||||
// Loop over entries, calculate tick positions and bar positions as we go
|
||||
|
||||
for ( const BarEntry& barDef : m_sortedBarEntries )
|
||||
for ( const BarEntry& barDef : filteredBarEntries )
|
||||
{
|
||||
bool hasAnyMajTics = !majTickTexts.empty();
|
||||
auto majInsertResult = majTickTexts.insert( barDef.m_majTickText );
|
||||
@ -379,11 +423,15 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
|
||||
int idx = 0;
|
||||
for ( const auto& legendToBarPointsPair : legendToBarPointsMap )
|
||||
{
|
||||
addQwtBarChart( plot,
|
||||
legendToBarPointsPair.second,
|
||||
legendToBarPointsPair.first,
|
||||
RiaColorTables::summaryCurveDefaultPaletteColors().cycledQColor( idx ),
|
||||
barOrientation );
|
||||
QColor legendColor = RiaColorTables::categoryPaletteColors().cycledQColor( idx );
|
||||
|
||||
auto legendColorPairIt = m_legendColors.find( legendToBarPointsPair.first );
|
||||
if ( legendColorPairIt != m_legendColors.end() )
|
||||
{
|
||||
legendColor = legendColorPairIt->second;
|
||||
}
|
||||
|
||||
addQwtBarChart( plot, legendToBarPointsPair.second, legendToBarPointsPair.first, legendColor, barOrientation );
|
||||
idx++;
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class QwtPlot;
|
||||
@ -42,13 +43,12 @@ public:
|
||||
const QString& barText,
|
||||
const double value );
|
||||
|
||||
void addBarChartToPlot( QwtPlot* plot, Qt::Orientation orientation );
|
||||
void setLegendColorMap( const std::map<QString, QColor>& legendColors );
|
||||
|
||||
void addBarChartToPlot( QwtPlot* plot, Qt::Orientation orientation, int maxBarCount = -1 );
|
||||
|
||||
private:
|
||||
double midPoint( double v1, double v2 )
|
||||
{
|
||||
return v1 + 0.5 * ( v2 - 1.0 - v1 );
|
||||
}
|
||||
double midPoint( double v1, double v2 ) { return v1 + 0.5 * ( v2 - 1.0 - v1 ); }
|
||||
|
||||
void addQwtBarChart( QwtPlot* plot,
|
||||
const QVector<QPointF>& posAndValue,
|
||||
@ -80,6 +80,7 @@ private:
|
||||
bool operator<( const BarEntry& other ) const;
|
||||
};
|
||||
|
||||
std::multiset<BarEntry> m_sortedBarEntries;
|
||||
Qt::Orientation m_orientation;
|
||||
std::multiset<BarEntry> m_sortedBarEntries;
|
||||
Qt::Orientation m_orientation;
|
||||
std::map<QString, QColor> m_legendColors;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user