mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-30 09:00:20 -05:00
Histogram Plot: add P10, mean and P90.
This commit is contained in:
1 parent
48f1597953
commit
b46e55bc21
9 files changed
+117
-80
No files matched your search
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "RimHistogramCurve.h"
|
||||
|
||||
#include "RiaColorTools.h"
|
||||
#include "RiaGuiApplication.h"
|
||||
#include "RiaPlotDefines.h"
|
||||
|
||||
@@ -28,13 +29,17 @@
|
||||
#include "RimProject.h"
|
||||
#include "RimTools.h"
|
||||
|
||||
#include "RiuPlotAnnotationTool.h"
|
||||
#include "RiuPlotAxis.h"
|
||||
#include "RiuPlotCurve.h"
|
||||
#include "RiuPlotMainWindow.h"
|
||||
#include "RiuQwtPlotWidget.h"
|
||||
|
||||
#include "cafAssert.h"
|
||||
#include "cafPdmUiTreeOrdering.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimHistogramCurve, "HistogramCurve" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -49,10 +54,14 @@ RimHistogramCurve::RimHistogramCurve()
|
||||
CAF_PDM_InitFieldNoDefault( &m_dataSource, "DataSource", "Data Source" );
|
||||
m_dataSource.uiCapability()->setUiTreeHidden( true );
|
||||
|
||||
CAF_PDM_InitField( &m_showPercentiles, "ShowPercentiles", true, "Show P10, Mean, and P90" );
|
||||
|
||||
setSymbolSkipDistance( 10.0f );
|
||||
setLineThickness( 2 );
|
||||
|
||||
setDeletable( true );
|
||||
|
||||
m_annotationTool = std::make_unique<RiuPlotAnnotationTool>();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -128,7 +137,7 @@ std::vector<double> RimHistogramCurve::valuesY() const
|
||||
if ( m_dataSource )
|
||||
{
|
||||
RimHistogramPlot* plot = firstAncestorOrThisOfTypeAsserted<RimHistogramPlot>();
|
||||
return m_dataSource()->valuesY( plot->graphType(), plot->frequencyType() );
|
||||
return m_dataSource()->compute( plot->graphType(), plot->frequencyType() ).valuesY;
|
||||
}
|
||||
else
|
||||
return {};
|
||||
@@ -142,7 +151,7 @@ std::vector<double> RimHistogramCurve::valuesX() const
|
||||
if ( m_dataSource )
|
||||
{
|
||||
RimHistogramPlot* plot = firstAncestorOrThisOfTypeAsserted<RimHistogramPlot>();
|
||||
return m_dataSource()->valuesX( plot->graphType() );
|
||||
return m_dataSource()->compute( plot->graphType(), plot->frequencyType() ).valuesX;
|
||||
}
|
||||
else
|
||||
return {};
|
||||
@@ -238,15 +247,45 @@ void RimHistogramCurve::onLoadDataAndUpdate( bool updateParentPlot )
|
||||
|
||||
updateConnectedEditors();
|
||||
|
||||
if ( isChecked() )
|
||||
{
|
||||
std::vector<double> curveValuesX = valuesX();
|
||||
std::vector<double> curveValuesY = valuesY();
|
||||
m_annotationTool->detachAllAnnotations();
|
||||
|
||||
if ( isChecked() && m_dataSource() )
|
||||
{
|
||||
RimHistogramPlot* plot = firstAncestorOrThisOfTypeAsserted<RimHistogramPlot>();
|
||||
|
||||
auto result = m_dataSource->compute( plot->graphType(), plot->frequencyType() );
|
||||
|
||||
auto plot = firstAncestorOrThisOfTypeAsserted<RimHistogramPlot>();
|
||||
bool useLogarithmicScale = plot->isLogarithmicScaleEnabled( axisY() );
|
||||
|
||||
setSamplesFromXYValues( curveValuesX, curveValuesY, useLogarithmicScale );
|
||||
QColor color = RiaColorTools::toQColor( m_curveAppearance->color() );
|
||||
if ( plot->plotWidget() )
|
||||
{
|
||||
if ( m_showPercentiles() )
|
||||
{
|
||||
QwtPlot* qwtPlot = dynamic_cast<RiuQwtPlotWidget*>( plot->plotWidget() )->qwtPlot();
|
||||
|
||||
QString autoName = createCurveAutoName();
|
||||
std::map<QString, double> percentiles = { { QString( "P10: %1" ).arg( autoName ), result.p10 },
|
||||
{ QString( "Mean: %1" ).arg( autoName ), result.mean },
|
||||
{ QString( "P90: %1" ).arg( autoName ), result.p90 } };
|
||||
|
||||
for ( const auto& [name, value] : percentiles )
|
||||
{
|
||||
if ( !std::isinf( value ) )
|
||||
{
|
||||
m_annotationTool->attachAnnotationLine( qwtPlot,
|
||||
color,
|
||||
name,
|
||||
Qt::PenStyle::DashDotDotLine,
|
||||
value,
|
||||
RiaDefines::Orientation::VERTICAL,
|
||||
Qt::AlignmentFlag::AlignCenter );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setSamplesFromXYValues( result.valuesX, result.valuesY, useLogarithmicScale );
|
||||
}
|
||||
|
||||
if ( updateParentPlot && hasParentPlot() )
|
||||
@@ -306,6 +345,8 @@ void RimHistogramCurve::defineUiOrdering( QString uiConfigName, caf::PdmUiOrderi
|
||||
nameGroup->add( &m_showLegend );
|
||||
RimPlotCurve::curveNameUiOrdering( *nameGroup );
|
||||
|
||||
uiOrdering.add( &m_showPercentiles );
|
||||
|
||||
uiOrdering.skipRemainingFields();
|
||||
}
|
||||
|
||||
@@ -345,6 +386,10 @@ void RimHistogramCurve::fieldChangedByUi( const caf::PdmFieldHandle* changedFiel
|
||||
plot->updateAxes();
|
||||
dataChanged.send();
|
||||
}
|
||||
else if ( changedField == &m_showPercentiles )
|
||||
{
|
||||
loadAndUpdate = true;
|
||||
}
|
||||
|
||||
if ( loadAndUpdate )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user