mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#7664 Statistics Plot: add option for relative frequency in histogram
This commit is contained in:
parent
b00734265a
commit
8d1bc7bfd9
@ -50,6 +50,17 @@
|
||||
|
||||
using namespace QtCharts;
|
||||
|
||||
namespace caf
|
||||
{
|
||||
template <>
|
||||
void caf::AppEnum<RimStatisticsPlot::HistogramFrequencyType>::setUp()
|
||||
{
|
||||
addItem( RimStatisticsPlot::HistogramFrequencyType::ABSOLUTE, "ABSOLUTE", "Absolute" );
|
||||
addItem( RimStatisticsPlot::HistogramFrequencyType::RELATIVE, "RELATIVE", "Relative" );
|
||||
setDefault( RimStatisticsPlot::HistogramFrequencyType::ABSOLUTE );
|
||||
}
|
||||
} // namespace caf
|
||||
|
||||
CAF_PDM_ABSTRACT_SOURCE_INIT( RimStatisticsPlot, "StatisticsPlot" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -68,6 +79,8 @@ RimStatisticsPlot::RimStatisticsPlot()
|
||||
CAF_PDM_InitField( &m_histogramBarWidth, "HistogramBarWidth", 1.0, "Bar Width", "", "", "" );
|
||||
m_histogramBarWidth.uiCapability()->setUiEditorTypeName( caf::PdmUiDoubleSliderEditor::uiEditorTypeName() );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_histogramFrequencyType, "HistogramFrequencyType", "Frequency", "", "", "" );
|
||||
|
||||
m_plotLegendsHorizontal.uiCapability()->setUiHidden( true );
|
||||
|
||||
setDeletable( true );
|
||||
@ -218,6 +231,7 @@ void RimStatisticsPlot::uiOrderingForHistogram( QString uiConfigName, caf::PdmUi
|
||||
histogramGroup->add( &m_numHistogramBins );
|
||||
histogramGroup->add( &m_histogramBarColor );
|
||||
histogramGroup->add( &m_histogramBarWidth );
|
||||
histogramGroup->add( &m_histogramFrequencyType );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -245,8 +259,14 @@ void RimStatisticsPlot::updatePlots()
|
||||
QBarSet* set0 = new QBarSet( m_plotWindowTitle );
|
||||
double minValue = std::numeric_limits<double>::max();
|
||||
double maxValue = -std::numeric_limits<double>::max();
|
||||
|
||||
double sumElements = 0.0;
|
||||
for ( double value : histogramData.histogram )
|
||||
sumElements += value;
|
||||
|
||||
for ( double value : histogramData.histogram )
|
||||
{
|
||||
if ( m_histogramFrequencyType() == HistogramFrequencyType::RELATIVE ) value /= sumElements;
|
||||
*set0 << value;
|
||||
minValue = std::min( minValue, value );
|
||||
maxValue = std::max( maxValue, value );
|
||||
|
@ -42,6 +42,12 @@ class RimStatisticsPlot : public RimPlotWindow
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
enum class HistogramFrequencyType
|
||||
{
|
||||
ABSOLUTE,
|
||||
RELATIVE
|
||||
};
|
||||
|
||||
RimStatisticsPlot();
|
||||
~RimStatisticsPlot() override;
|
||||
|
||||
@ -82,8 +88,9 @@ private:
|
||||
protected:
|
||||
QPointer<RiuQtChartView> m_viewer;
|
||||
|
||||
caf::PdmField<QString> m_plotWindowTitle;
|
||||
caf::PdmField<int> m_numHistogramBins;
|
||||
caf::PdmField<cvf::Color3f> m_histogramBarColor;
|
||||
caf::PdmField<double> m_histogramBarWidth;
|
||||
caf::PdmField<QString> m_plotWindowTitle;
|
||||
caf::PdmField<int> m_numHistogramBins;
|
||||
caf::PdmField<cvf::Color3f> m_histogramBarColor;
|
||||
caf::PdmField<double> m_histogramBarWidth;
|
||||
caf::PdmField<caf::AppEnum<HistogramFrequencyType>> m_histogramFrequencyType;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user