Merge pull request #8387 from OPM/qtcharts-summary-plots

Closes #8228 

Major refactoring of summary plotting. Now possible to create plots both with Qwt and QtChart as plotting tool.
This commit is contained in:
Kristian Bendiksen
2022-01-17 13:14:21 +01:00
committed by GitHub
parent d9bb82de91
commit 258fbddc10
145 changed files with 7245 additions and 2932 deletions

View File

@@ -42,6 +42,8 @@
#include "cafPdmUiPushButtonEditor.h"
#include "cafPdmUiToolButtonEditor.h"
#include "qwt_plot.h"
CAF_PDM_ABSTRACT_SOURCE_INIT( RimAbstractCorrelationPlot, "AbstractCorrelationPlot" );
//--------------------------------------------------------------------------------------------------
@@ -557,7 +559,7 @@ QString RimAbstractCorrelationPlot::description() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuQwtPlotWidget* RimAbstractCorrelationPlot::doCreatePlotViewWidget( QWidget* mainWindowParent /*= nullptr */ )
RiuPlotWidget* RimAbstractCorrelationPlot::doCreatePlotViewWidget( QWidget* mainWindowParent /*= nullptr */ )
{
if ( !m_plotWidget )
{
@@ -576,12 +578,20 @@ RiuQwtPlotWidget* RimAbstractCorrelationPlot::viewer()
return m_plotWidget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiuPlotWidget* RimAbstractCorrelationPlot::plotWidget()
{
return m_plotWidget;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimAbstractCorrelationPlot::detachAllCurves()
{
if ( m_plotWidget ) m_plotWidget->detachItems();
if ( m_plotWidget ) m_plotWidget->qwtPlot()->detachItems();
}
//--------------------------------------------------------------------------------------------------
@@ -661,7 +671,7 @@ void RimAbstractCorrelationPlot::updateLegend()
{
if ( m_plotWidget )
{
m_plotWidget->insertLegend( nullptr );
m_plotWidget->qwtPlot()->insertLegend( nullptr );
}
}

View File

@@ -61,7 +61,8 @@ public:
RimEnsembleCurveSet* caseFilterDataSource() const;
void setCaseFilterDataSource( RimEnsembleCurveSet* ensemble );
RiuQwtPlotWidget* viewer() override;
RiuQwtPlotWidget* viewer();
RiuPlotWidget* plotWidget() override;
void detachAllCurves() override;
QDateTime timeStep() const;
QString timeStepString() const;
@@ -103,17 +104,14 @@ protected:
void doUpdateLayout() override {}
// RimPlot Overrides
RiuQwtPlotWidget* doCreatePlotViewWidget( QWidget* mainWindowParent = nullptr ) override;
RiuPlotWidget* doCreatePlotViewWidget( QWidget* mainWindowParent = nullptr ) override;
void reattachAllCurves() override {}
void updateZoomInQwt() override {}
void updateZoomFromQwt() override {}
void setAutoScaleXEnabled( bool enabled ) override {}
void setAutoScaleYEnabled( bool enabled ) override {}
void updateLegend() override;
QString asciiDataForPlotExport() const override { return ""; }
caf::PdmObject* findPdmObjectFromQwtCurve( const QwtPlotCurve* curve ) const override { return nullptr; }
QString asciiDataForPlotExport() const override { return ""; }
void cleanupBeforeClose();
virtual void updatePlotTitle() = 0;

View File

@@ -25,6 +25,7 @@
#include "RiaSummaryCurveDefinition.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtLinearScaleEngine.h"
#include "RiuQwtPlotItem.h"
#include "RiuQwtPlotTools.h"
#include "RiuQwtPlotWidget.h"
@@ -369,14 +370,14 @@ void RimCorrelationMatrixPlot::onLoadDataAndUpdate()
if ( m_plotWidget )
{
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotBarChart );
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotScale );
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotItem );
m_plotWidget->qwtPlot()->detachItems( QwtPlotItem::Rtti_PlotBarChart );
m_plotWidget->qwtPlot()->detachItems( QwtPlotItem::Rtti_PlotScale );
m_plotWidget->qwtPlot()->detachItems( QwtPlotItem::Rtti_PlotItem );
updateLegend();
createMatrix();
m_plotWidget->insertLegend( nullptr );
m_plotWidget->qwtPlot()->insertLegend( nullptr );
this->updateAxes();
this->updatePlotTitle();
@@ -399,14 +400,18 @@ void RimCorrelationMatrixPlot::updateAxes()
{
if ( !m_plotWidget ) return;
m_plotWidget->setAxisScaleDraw( QwtPlot::yLeft, new TextScaleDraw( m_resultLabels ) );
m_plotWidget->setAxisScaleEngine( QwtPlot::yLeft, new RiuQwtLinearScaleEngine );
m_plotWidget->setAxisTitleText( QwtPlot::yLeft, "Result Vector" );
m_plotWidget->setAxisTitleEnabled( QwtPlot::yLeft, true );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::yLeft, axisTitleFontSize(), axisValueFontSize(), false, Qt::AlignCenter );
m_plotWidget->setAxisLabelsAndTicksEnabled( QwtPlot::yLeft, true, false );
m_plotWidget->setAxisRange( QwtPlot::yLeft, 0.0, (double)m_resultLabels.size() + 1 );
m_plotWidget->setMajorAndMinorTickIntervalsAndRange( QwtPlot::yLeft,
m_plotWidget->qwtPlot()->setAxisScaleDraw( QwtPlot::yLeft, new TextScaleDraw( m_resultLabels ) );
m_plotWidget->qwtPlot()->setAxisScaleEngine( QwtPlot::yLeft, new RiuQwtLinearScaleEngine );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, "Result Vector" );
m_plotWidget->setAxisTitleEnabled( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true );
m_plotWidget->setAxisFontsAndAlignment( RiaDefines::PlotAxis::PLOT_AXIS_LEFT,
axisTitleFontSize(),
axisValueFontSize(),
false,
Qt::AlignCenter );
m_plotWidget->setAxisLabelsAndTicksEnabled( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true, false );
m_plotWidget->setAxisRange( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, 0.0, (double)m_resultLabels.size() + 1 );
m_plotWidget->setMajorAndMinorTickIntervalsAndRange( RiaDefines::PlotAxis::PLOT_AXIS_LEFT,
1.0,
0.0,
0.5,
@@ -416,19 +421,18 @@ void RimCorrelationMatrixPlot::updateAxes()
auto scaleDraw = new TextScaleDraw( m_paramLabels );
scaleDraw->setLabelRotation( 30.0 );
m_plotWidget->setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
m_plotWidget->setAxisScaleEngine( QwtPlot::xBottom, new RiuQwtLinearScaleEngine );
m_plotWidget->setAxisTitleText( QwtPlot::xBottom, "Ensemble Parameter" );
m_plotWidget->setAxisTitleEnabled( QwtPlot::xBottom, true );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::xBottom,
m_plotWidget->qwtPlot()->setAxisScaleDraw( QwtPlot::xBottom, scaleDraw );
m_plotWidget->qwtPlot()->setAxisScaleEngine( QwtPlot::xBottom, new RiuQwtLinearScaleEngine );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, "Ensemble Parameter" );
m_plotWidget->setAxisTitleEnabled( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true );
m_plotWidget->setAxisFontsAndAlignment( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM,
axisTitleFontSize(),
axisValueFontSize(),
false,
Qt::AlignCenter | Qt::AlignTop );
m_plotWidget->setAxisLabelsAndTicksEnabled( QwtPlot::xBottom, true, false );
m_plotWidget->setAxisRange( QwtPlot::xBottom, 0.0, (double)m_paramLabels.size() + 1 );
m_plotWidget->setMajorAndMinorTickIntervalsAndRange( QwtPlot::xBottom,
m_plotWidget->setAxisLabelsAndTicksEnabled( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true, false );
m_plotWidget->setAxisRange( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, 0.0, (double)m_paramLabels.size() + 1 );
m_plotWidget->setMajorAndMinorTickIntervalsAndRange( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM,
1.0,
0.0,
0.5,
@@ -436,7 +440,7 @@ void RimCorrelationMatrixPlot::updateAxes()
0.0,
(double)m_paramLabels.size() );
m_plotWidget->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignRight );
m_plotWidget->qwtPlot()->setAxisLabelAlignment( QwtPlot::xBottom, Qt::AlignRight );
}
template <typename KeyType, typename ValueType>
@@ -636,8 +640,8 @@ void RimCorrelationMatrixPlot::createMatrix()
marker->setLabel( textLabel );
marker->setXValue( colIdx + 0.5 );
marker->setYValue( rowIdx + 0.5 );
rectangle->attach( m_plotWidget );
marker->attach( m_plotWidget );
rectangle->attach( m_plotWidget->qwtPlot() );
marker->attach( m_plotWidget->qwtPlot() );
m_paramLabels[colIdx] = correlationMatrixRows[rowIdx].m_values[colIdx];
}
@@ -682,9 +686,12 @@ void RimCorrelationMatrixPlot::updateLegend()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationMatrixPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex )
void RimCorrelationMatrixPlot::onPlotItemSelected( std::shared_ptr<RiuPlotItem> plotItem, bool toggle, int sampleIndex )
{
CorrelationMatrixShapeItem* matrixItem = dynamic_cast<CorrelationMatrixShapeItem*>( plotItem );
RiuQwtPlotItem* qwtPlotItem = dynamic_cast<RiuQwtPlotItem*>( plotItem.get() );
if ( !qwtPlotItem ) return;
CorrelationMatrixShapeItem* matrixItem = dynamic_cast<CorrelationMatrixShapeItem*>( qwtPlotItem->qwtPlotItem() );
if ( matrixItem )
{
matrixCellSelected.send( std::make_pair( matrixItem->parameter, matrixItem->curveDef ) );

View File

@@ -22,11 +22,11 @@
#include "cafAppEnum.h"
#include <QDateTime>
class RimRegularLegendConfig;
class RimSummaryAddress;
class RiuGroupedBarChartBuilder;
class RiuPlotItem;
//==================================================================================================
///
@@ -79,7 +79,7 @@ private:
void createMatrix();
void updatePlotTitle() override;
void updateLegend() override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex ) override;
void onPlotItemSelected( std::shared_ptr<RiuPlotItem> plotItem, bool toggle, int sampleIndex ) override;
private:
caf::PdmField<bool> m_showAbsoluteValues;

View File

@@ -22,6 +22,7 @@
#include "RiaQDateTimeTools.h"
#include "RiuGroupedBarChartBuilder.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtPlotItem.h"
#include "RiuQwtPlotWidget.h"
#include "RifSummaryReaderInterface.h"
@@ -40,6 +41,7 @@
#include "cafPdmUiComboBoxEditor.h"
#include "cafPdmUiTreeSelectionEditor.h"
#include "qwt_plot.h"
#include "qwt_plot_barchart.h"
#include <limits>
@@ -176,19 +178,19 @@ void RimCorrelationPlot::onLoadDataAndUpdate()
if ( m_plotWidget && m_analyserOfSelectedCurveDefs )
{
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotBarChart );
m_plotWidget->detachItems( QwtPlotItem::Rtti_PlotScale );
m_plotWidget->qwtPlot()->detachItems( QwtPlotItem::Rtti_PlotBarChart );
m_plotWidget->qwtPlot()->detachItems( QwtPlotItem::Rtti_PlotScale );
RiuGroupedBarChartBuilder chartBuilder;
addDataToChartBuilder( chartBuilder );
chartBuilder.addBarChartToPlot( m_plotWidget,
chartBuilder.addBarChartToPlot( m_plotWidget->qwtPlot(),
Qt::Horizontal,
m_showOnlyTopNCorrelations() ? m_topNFilterCount() : -1 );
chartBuilder.setLabelFontSize( labelFontSize() );
m_plotWidget->insertLegend( nullptr );
m_plotWidget->qwtPlot()->insertLegend( nullptr );
m_plotWidget->updateLegend();
this->updateAxes();
@@ -204,22 +206,30 @@ void RimCorrelationPlot::updateAxes()
{
if ( !m_plotWidget ) return;
m_plotWidget->setAxisTitleText( QwtPlot::yLeft, "Parameter" );
m_plotWidget->setAxisTitleEnabled( QwtPlot::yLeft, true );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::yLeft, axisTitleFontSize(), axisValueFontSize(), false, Qt::AlignCenter );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, "Parameter" );
m_plotWidget->setAxisTitleEnabled( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true );
m_plotWidget->setAxisFontsAndAlignment( RiaDefines::PlotAxis::PLOT_AXIS_LEFT,
axisTitleFontSize(),
axisValueFontSize(),
false,
Qt::AlignCenter );
m_plotWidget->setAxisTitleText( QwtPlot::xBottom, "Pearson Correlation Coefficient" );
m_plotWidget->setAxisTitleEnabled( QwtPlot::xBottom, true );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::xBottom, axisTitleFontSize(), axisValueFontSize(), false, Qt::AlignCenter );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, "Pearson Correlation Coefficient" );
m_plotWidget->setAxisTitleEnabled( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true );
m_plotWidget->setAxisFontsAndAlignment( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM,
axisTitleFontSize(),
axisValueFontSize(),
false,
Qt::AlignCenter );
if ( m_showAbsoluteValues )
{
m_plotWidget->setAxisTitleText( QwtPlot::xBottom, "Pearson Correlation Coefficient ABS" );
m_plotWidget->setAxisRange( QwtPlot::xBottom, 0.0, 1.0 );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, "Pearson Correlation Coefficient ABS" );
m_plotWidget->setAxisRange( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, 0.0, 1.0 );
}
else
{
m_plotWidget->setAxisTitleText( QwtPlot::xBottom, "Pearson Correlation Coefficient" );
m_plotWidget->setAxisRange( QwtPlot::xBottom, -1.0, 1.0 );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, "Pearson Correlation Coefficient" );
m_plotWidget->setAxisRange( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, -1.0, 1.0 );
}
}
@@ -273,9 +283,12 @@ void RimCorrelationPlot::updatePlotTitle()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimCorrelationPlot::onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex )
void RimCorrelationPlot::onPlotItemSelected( std::shared_ptr<RiuPlotItem> plotItem, bool toggle, int sampleIndex )
{
QwtPlotBarChart* barChart = dynamic_cast<QwtPlotBarChart*>( plotItem );
RiuQwtPlotItem* qwtPlotItem = dynamic_cast<RiuQwtPlotItem*>( plotItem.get() );
if ( !qwtPlotItem ) return;
QwtPlotBarChart* barChart = dynamic_cast<QwtPlotBarChart*>( qwtPlotItem->qwtPlotItem() );
if ( barChart && !curveDefinitions().empty() )
{
auto curveDef = curveDefinitions().front();

View File

@@ -28,6 +28,7 @@
class RimSummaryAddress;
class RiuGroupedBarChartBuilder;
class RiuPlotItem;
//==================================================================================================
///
@@ -70,7 +71,7 @@ private:
// Private methods
void addDataToChartBuilder( RiuGroupedBarChartBuilder& chartBuilder );
void updatePlotTitle() override;
void onPlotItemSelected( QwtPlotItem* plotItem, bool toggle, int sampleIndex ) override;
void onPlotItemSelected( std::shared_ptr<RiuPlotItem> plotItem, bool toggle, int sampleIndex ) override;
private:
caf::PdmField<bool> m_showAbsoluteValues;

View File

@@ -29,6 +29,8 @@
#include "RimSummaryCaseCollection.h"
#include "RiuMultiPlotPage.h"
#include "RiuPlotWidget.h"
#include "RiuQwtPlotWidget.h"
#include "cafAssert.h"
#include "cafPdmUiOrdering.h"

View File

@@ -39,6 +39,7 @@
#include "RimSummaryCaseCollection.h"
#include "RimSummaryPlotAxisFormatter.h"
#include "RiuPlotCurve.h"
#include "RiuPlotMainWindowTools.h"
#include "RiuQwtPlotCurve.h"
#include "RiuSummaryQwtPlot.h"
@@ -49,6 +50,7 @@
#include "cafPdmUiPushButtonEditor.h"
#include "qwt_legend.h"
#include "qwt_plot.h"
#include "qwt_plot_curve.h"
#include "qwt_scale_engine.h"
@@ -168,7 +170,7 @@ void RimParameterResultCrossPlot::onLoadDataAndUpdate()
if ( m_showPlotLegends && !isSubPlot<RimMultiPlot>() )
{
QwtLegend* legend = new QwtLegend( m_plotWidget );
m_plotWidget->insertLegend( legend, QwtPlot::RightLegend );
m_plotWidget->qwtPlot()->insertLegend( legend, QwtPlot::RightLegend );
m_plotWidget->setLegendFontSize( legendFontSize() );
m_plotWidget->updateLegend();
}
@@ -186,19 +188,31 @@ void RimParameterResultCrossPlot::updateAxes()
{
if ( !m_plotWidget ) return;
m_plotWidget->setAxisTitleText( QwtPlot::yLeft, completeAddressText() );
m_plotWidget->setAxisTitleEnabled( QwtPlot::yLeft, true );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::yLeft, axisTitleFontSize(), axisValueFontSize(), false, Qt::AlignCenter );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, completeAddressText() );
m_plotWidget->setAxisTitleEnabled( RiaDefines::PlotAxis::PLOT_AXIS_LEFT, true );
m_plotWidget->setAxisFontsAndAlignment( RiaDefines::PlotAxis::PLOT_AXIS_LEFT,
axisTitleFontSize(),
axisValueFontSize(),
false,
Qt::AlignCenter );
double yRangeWidth = m_yRange.second - m_yRange.first;
m_plotWidget->setAxisRange( QwtPlot::yLeft, m_yRange.first - yRangeWidth * 0.1, m_yRange.second + yRangeWidth * 0.1 );
m_plotWidget->setAxisRange( RiaDefines::PlotAxis::PLOT_AXIS_LEFT,
m_yRange.first - yRangeWidth * 0.1,
m_yRange.second + yRangeWidth * 0.1 );
m_plotWidget->setAxisTitleText( QwtPlot::xBottom, m_ensembleParameter );
m_plotWidget->setAxisTitleEnabled( QwtPlot::xBottom, true );
m_plotWidget->setAxisFontsAndAlignment( QwtPlot::xBottom, axisTitleFontSize(), axisValueFontSize(), false, Qt::AlignCenter );
m_plotWidget->setAxisTitleText( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, m_ensembleParameter );
m_plotWidget->setAxisTitleEnabled( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM, true );
m_plotWidget->setAxisFontsAndAlignment( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM,
axisTitleFontSize(),
axisValueFontSize(),
false,
Qt::AlignCenter );
double xRangeWidth = m_xRange.second - m_xRange.first;
m_plotWidget->setAxisRange( QwtPlot::xBottom, m_xRange.first - xRangeWidth * 0.1, m_xRange.second + xRangeWidth * 0.1 );
m_plotWidget->setAxisRange( RiaDefines::PlotAxis::PLOT_AXIS_BOTTOM,
m_xRange.first - xRangeWidth * 0.1,
m_xRange.second + xRangeWidth * 0.1 );
}
//--------------------------------------------------------------------------------------------------
@@ -295,10 +309,10 @@ void RimParameterResultCrossPlot::createPoints()
m_yRange.second = std::max( m_yRange.second, closestValue );
RiuQwtPlotCurve* plotCurve = new RiuQwtPlotCurve;
plotCurve->setSamples( parameterValues.data(), caseValuesAtTimestep.data(), (int)parameterValues.size() );
plotCurve->setSamplesValues( parameterValues, caseValuesAtTimestep );
plotCurve->setStyle( QwtPlotCurve::NoCurve );
RiuQwtSymbol* symbol =
new RiuQwtSymbol( RiuQwtSymbol::cycledSymbolStyle( ensembleIdx, addressIdx ), "" );
new RiuQwtSymbol( RiuPlotCurveSymbol::cycledSymbolStyle( ensembleIdx, addressIdx ), "" );
symbol->setSize( legendFontSize(), legendFontSize() );
symbol->setColor( colorTable.cycledQColor( caseIdx ) );
plotCurve->setSymbol( symbol );
@@ -309,7 +323,7 @@ void RimParameterResultCrossPlot::createPoints()
plotCurve->setTitle( curveName.join( " - " ) );
plotCurve->attach( m_plotWidget );
plotCurve->attach( m_plotWidget->qwtPlot() );
}
}
addressIdx++;