Add multi selection for Correlation Cross Plot and fix label font sizes for Tornado plots

This commit is contained in:
Gaute Lindkvist 2020-06-08 16:12:32 +02:00
parent c1ca5054e8
commit 457cdae367
11 changed files with 134 additions and 65 deletions

View File

@ -417,7 +417,6 @@ void RimAnalysisPlot::fieldChangedByUi( const caf::PdmFieldHandle* changedField,
dlg.enableIndividualEnsembleCaseSelection( true );
dlg.setCurveSelection( this->curveDefinitionsWithoutEnsembleReference() );
dlg.setCaseAndAddress( nullptr, RifEclipseSummaryAddress() );
if ( dlg.exec() == QDialog::Accepted )
{

View File

@ -56,6 +56,8 @@ RimAbstractCorrelationPlot::RimAbstractCorrelationPlot()
CAF_PDM_InitFieldNoDefault( &m_axisTitleFontSize, "AxisTitleFontSize", "Axis Title Font Size", "", "", "" );
CAF_PDM_InitFieldNoDefault( &m_axisValueFontSize, "AxisValueFontSize", "Axis Value Font Size", "", "", "" );
m_axisValueFontSize = caf::FontTools::RelativeSize::XSmall;
m_legendFontSize = caf::FontTools::RelativeSize::XSmall;
}
//--------------------------------------------------------------------------------------------------
@ -101,7 +103,6 @@ void RimAbstractCorrelationPlot::fieldChangedByUi( const caf::PdmFieldHandle* ch
dlg.enableMultiSelect( true );
}
dlg.setCaseAndAddress( nullptr, RifEclipseSummaryAddress() );
dlg.setCurveSelection( curveDefinitions() );
if ( dlg.exec() == QDialog::Accepted )
@ -134,7 +135,7 @@ void RimAbstractCorrelationPlot::fieldChangedByUi( const caf::PdmFieldHandle* ch
this->updatePlotTitle();
}
else if ( changedField == &m_labelFontSize || changedField == &m_axisTitleFontSize ||
changedField == &m_axisValueFontSize )
changedField == &m_axisValueFontSize || changedField == &m_legendFontSize || changedField == &m_titleFontSize )
{
this->loadDataAndUpdate();
}

View File

@ -246,6 +246,8 @@ void RimCorrelationMatrixPlot::defineUiOrdering( QString uiConfigName, caf::PdmU
plotGroup->add( &m_description );
m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() );
RimPlot::defineUiOrdering( uiConfigName, *plotGroup );
plotGroup->add( &m_titleFontSize );
plotGroup->add( &m_labelFontSize );
plotGroup->add( &m_axisTitleFontSize );
plotGroup->add( &m_axisValueFontSize );

View File

@ -126,6 +126,7 @@ void RimCorrelationPlot::defineUiOrdering( QString uiConfigName, caf::PdmUiOrder
plotGroup->add( &m_useAutoPlotTitle );
plotGroup->add( &m_description );
RimPlot::defineUiOrdering( uiConfigName, *plotGroup );
plotGroup->add( &m_titleFontSize );
plotGroup->add( &m_axisTitleFontSize );
plotGroup->add( &m_axisValueFontSize );
@ -168,6 +169,7 @@ void RimCorrelationPlot::onLoadDataAndUpdate()
addDataToChartBuilder( chartBuilder );
chartBuilder.addBarChartToPlot( m_plotWidget, Qt::Horizontal );
chartBuilder.setLabelFontSize( labelFontSize() );
m_plotWidget->insertLegend( nullptr );
m_plotWidget->updateLegend();
@ -275,7 +277,7 @@ void RimCorrelationPlot::addDataToChartBuilder( RiuGroupedBarChartBuilder& chart
correlationResults.push_back( std::make_pair( parameterValuesPair.first, correlation ) );
}
QString timestepString = m_timeStep().toString( Qt::ISODate );
QString timestepString = m_timeStep().toString( RiaPreferences::current()->dateTimeFormat() );
for ( auto parameterCorrPair : correlationResults )
{

View File

@ -315,6 +315,7 @@ void RimCorrelationReportPlot::onLoadDataAndUpdate()
m_correlationPlot->setAxisValueFontSize( m_axisValueFontSize() );
m_parameterResultCrossPlot->setLabelFontSize( m_labelFontSize() );
m_parameterResultCrossPlot->setLegendFontSize( m_legendFontSize() );
m_parameterResultCrossPlot->setAxisTitleFontSize( m_axisTitleFontSize() );
m_parameterResultCrossPlot->setAxisValueFontSize( m_axisValueFontSize() );
@ -339,6 +340,7 @@ void RimCorrelationReportPlot::defineUiOrdering( QString uiConfigName, caf::PdmU
plotGroup->add( &m_titleFontSize );
plotGroup->add( &m_subTitleFontSize );
plotGroup->add( &m_labelFontSize );
plotGroup->add( &m_legendFontSize );
plotGroup->add( &m_axisTitleFontSize );
plotGroup->add( &m_axisValueFontSize );
m_correlationMatrixPlot->legendConfig()->uiOrdering( "ColorsOnly", *plotGroup );

View File

@ -45,6 +45,8 @@
#include "qwt_legend.h"
#include "qwt_plot_curve.h"
#include <QStringList>
#include <limits>
#include <map>
#include <set>
@ -61,6 +63,10 @@ RimParameterResultCrossPlot::RimParameterResultCrossPlot()
CAF_PDM_InitField( &m_ensembleParameter, "EnsembleParameter", QString( "" ), "Ensemble Parameter", "", "", "" );
m_ensembleParameter.uiCapability()->setUiEditorTypeName( caf::PdmUiComboBoxEditor::uiEditorTypeName() );
m_selectMultipleVectors = true;
m_legendFontSize = caf::FontTools::RelativeSize::XSmall;
}
//--------------------------------------------------------------------------------------------------
@ -115,6 +121,10 @@ void RimParameterResultCrossPlot::defineUiOrdering( QString uiConfigName, caf::P
plotGroup->add( &m_useAutoPlotTitle );
plotGroup->add( &m_description );
RimPlot::defineUiOrdering( uiConfigName, *plotGroup );
plotGroup->add( &m_titleFontSize );
plotGroup->add( &m_legendFontSize );
plotGroup->add( &m_axisTitleFontSize );
plotGroup->add( &m_axisValueFontSize );
m_description.uiCapability()->setUiReadOnly( m_useAutoPlotTitle() );
uiOrdering.skipRemainingFields( true );
@ -152,10 +162,11 @@ void RimParameterResultCrossPlot::onLoadDataAndUpdate()
if ( m_plotWidget && m_analyserOfSelectedCurveDefs )
{
m_plotWidget->insertLegend( nullptr );
m_plotWidget->updateLegend();
createPoints();
QwtLegend* legend = new QwtLegend( m_plotWidget );
m_plotWidget->insertLegend( legend, QwtPlot::RightLegend );
m_plotWidget->setLegendFontSize( legendFontSize() );
m_plotWidget->updateLegend();
this->updateAxes();
this->updatePlotTitle();
@ -195,54 +206,73 @@ void RimParameterResultCrossPlot::createPoints()
if ( ensembles().empty() ) return;
if ( addresses().empty() ) return;
auto ensemble = *ensembles().begin();
auto address = *addresses().begin();
EnsembleParameter parameter = ensembleParameter( m_ensembleParameter );
if ( !( parameter.isNumeric() && parameter.isValid() ) ) return;
bool showEnsembleName = ensembles().size() > 1u;
bool showAddressName = addresses().size() > 1u;
for ( size_t caseIdx = 0u; caseIdx < ensemble->allSummaryCases().size(); ++caseIdx )
int ensembleIdx = 0;
for ( auto ensemble : ensembles() )
{
std::vector<double> caseValuesAtTimestep;
std::vector<double> parameterValues;
auto summaryCase = ensemble->allSummaryCases()[caseIdx];
RifSummaryReaderInterface* reader = summaryCase->summaryReader();
if ( !reader ) continue;
if ( !summaryCase->caseRealizationParameters() ) continue;
std::vector<double> values;
double closestValue = std::numeric_limits<double>::infinity();
time_t closestTimeStep = 0;
if ( reader->values( address, &values ) )
int addressIdx = 0;
for ( auto address : addresses() )
{
const std::vector<time_t>& timeSteps = reader->timeSteps( address );
for ( size_t i = 0; i < timeSteps.size(); ++i )
EnsembleParameter parameter = ensembleParameter( m_ensembleParameter );
if ( !( parameter.isNumeric() && parameter.isValid() ) ) return;
for ( size_t caseIdx = 0u; caseIdx < ensemble->allSummaryCases().size(); ++caseIdx )
{
if ( timeDiff( timeSteps[i], selectedTimestep ) < timeDiff( selectedTimestep, closestTimeStep ) )
std::vector<double> caseValuesAtTimestep;
std::vector<double> parameterValues;
auto summaryCase = ensemble->allSummaryCases()[caseIdx];
RifSummaryReaderInterface* reader = summaryCase->summaryReader();
if ( !reader ) continue;
if ( !summaryCase->caseRealizationParameters() ) continue;
std::vector<double> values;
double closestValue = std::numeric_limits<double>::infinity();
time_t closestTimeStep = 0;
if ( reader->values( address, &values ) )
{
closestValue = values[i];
closestTimeStep = timeSteps[i];
const std::vector<time_t>& timeSteps = reader->timeSteps( address );
for ( size_t i = 0; i < timeSteps.size(); ++i )
{
if ( timeDiff( timeSteps[i], selectedTimestep ) < timeDiff( selectedTimestep, closestTimeStep ) )
{
closestValue = values[i];
closestTimeStep = timeSteps[i];
}
}
}
if ( closestValue != std::numeric_limits<double>::infinity() )
{
caseValuesAtTimestep.push_back( closestValue );
double paramValue = parameter.values[caseIdx].toDouble();
parameterValues.push_back( paramValue );
RiuQwtPlotCurve* plotCurve = new RiuQwtPlotCurve;
plotCurve->setSamples( parameterValues.data(), caseValuesAtTimestep.data(), (int)parameterValues.size() );
plotCurve->setStyle( QwtPlotCurve::NoCurve );
RiuQwtSymbol* symbol =
new RiuQwtSymbol( RiuQwtSymbol::cycledSymbolStyle( ensembleIdx, addressIdx ), "" );
symbol->setSize( legendFontSize(), legendFontSize() );
symbol->setColor( colorTable.cycledQColor( caseIdx ) );
plotCurve->setSymbol( symbol );
QStringList curveName;
if ( showEnsembleName ) curveName += ensemble->name();
curveName += summaryCase->displayCaseName();
if ( showAddressName ) curveName += QString::fromStdString( address.uiText() );
plotCurve->setTitle( curveName.join( " - " ) );
plotCurve->attach( m_plotWidget );
}
}
addressIdx++;
}
if ( closestValue != std::numeric_limits<double>::infinity() )
{
caseValuesAtTimestep.push_back( closestValue );
double paramValue = parameter.values[caseIdx].toDouble();
parameterValues.push_back( paramValue );
QwtPlotCurve* plotCurve = new QwtPlotCurve;
plotCurve->setSamples( parameterValues.data(), caseValuesAtTimestep.data(), (int)parameterValues.size() );
plotCurve->setStyle( QwtPlotCurve::NoCurve );
RiuQwtSymbol* symbol = new RiuQwtSymbol( RiuQwtSymbol::SYMBOL_DIAMOND, "" );
symbol->setSize( 12, 12 );
symbol->setColor( colorTable.cycledQColor( caseIdx ) );
plotCurve->setSymbol( symbol );
plotCurve->attach( m_plotWidget );
}
ensembleIdx++;
}
}

View File

@ -154,6 +154,14 @@ int RimPlotWindow::legendFontSize() const
return caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(), m_legendFontSize() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotWindow::setLegendFontSize( caf::FontTools::RelativeSize fontSize )
{
m_legendFontSize = fontSize;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -62,6 +62,8 @@ public:
int titleFontSize() const;
int legendFontSize() const;
void setLegendFontSize( caf::FontTools::RelativeSize fontSize );
void updateLayout();
void updateParentLayout();

View File

@ -19,6 +19,9 @@
#include "RiuGroupedBarChartBuilder.h"
#include "RiaColorTables.h"
#include "RiaPreferences.h"
#include "cafFontTools.h"
#include "qwt_column_symbol.h"
#include "qwt_legend.h"
@ -89,8 +92,10 @@ public:
class RiuBarChartScaleDraw : public QwtScaleDraw
{
public:
RiuBarChartScaleDraw( const std::map<double, std::pair<QwtScaleDiv::TickType, QString>>& posTickTypeAndTexts )
RiuBarChartScaleDraw( const std::map<double, std::pair<QwtScaleDiv::TickType, QString>>& posTickTypeAndTexts,
int labelFontPointSize )
: m_posTickTypeAndTexts( posTickTypeAndTexts )
, m_labelFontPointSize( labelFontPointSize )
{
this->setTickLength( QwtScaleDiv::MajorTick, 0 );
this->setTickLength( QwtScaleDiv::MediumTick, 0 );
@ -122,6 +127,14 @@ public:
m_majSpacing = m_medSpacing + QString().fill( ' ', 2 * medTickMaxTextSize );
}
QwtText createLabelFromString( const QString& string ) const
{
QwtText text( string );
QFont font = text.font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( m_labelFontPointSize ) );
text.setFont( font );
return text;
}
/// Override to add new lines to the labels according to the tick level
QwtText label( double v ) const override
@ -133,36 +146,36 @@ public:
{
if ( posTypeTextPairIt->second.first == QwtScaleDiv::MediumTick )
{
return m_medLineBreak + posTypeTextPairIt->second.second;
return createLabelFromString( m_medLineBreak + posTypeTextPairIt->second.second );
}
else if ( posTypeTextPairIt->second.first == QwtScaleDiv::MajorTick )
{
return m_majLineBreak + posTypeTextPairIt->second.second;
return createLabelFromString( m_majLineBreak + posTypeTextPairIt->second.second );
}
else
{
return posTypeTextPairIt->second.second;
return createLabelFromString( posTypeTextPairIt->second.second );
}
}
else if ( this->alignment() == LeftScale )
{
if ( posTypeTextPairIt->second.first == QwtScaleDiv::MediumTick )
{
return posTypeTextPairIt->second.second + m_medSpacing;
return createLabelFromString( posTypeTextPairIt->second.second + m_medSpacing );
}
else if ( posTypeTextPairIt->second.first == QwtScaleDiv::MajorTick )
{
return posTypeTextPairIt->second.second + m_majSpacing;
return createLabelFromString( posTypeTextPairIt->second.second + m_majSpacing );
}
else
{
return posTypeTextPairIt->second.second;
return createLabelFromString( posTypeTextPairIt->second.second );
}
}
else
{
return posTypeTextPairIt->second.second;
return createLabelFromString( posTypeTextPairIt->second.second );
}
}
else
@ -212,6 +225,8 @@ private:
QString m_majLineBreak;
QString m_medSpacing;
QString m_majSpacing;
int m_labelFontPointSize;
};
//--------------------------------------------------------------------------------------------------
@ -220,6 +235,8 @@ private:
RiuGroupedBarChartBuilder::RiuGroupedBarChartBuilder( bool sortGroupsByMaxValueInGroup )
: m_isSortingByMaxValueInGroups( sortGroupsByMaxValueInGroup )
{
m_labelPointSize = caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(),
caf::FontTools::RelativeSize::Small );
}
//--------------------------------------------------------------------------------------------------
@ -575,7 +592,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
}
}
RiuBarChartScaleDraw* scaleDrawer = new RiuBarChartScaleDraw( groupPositionedAxisTexts );
RiuBarChartScaleDraw* scaleDrawer = new RiuBarChartScaleDraw( groupPositionedAxisTexts, m_labelPointSize );
plot->setAxisScaleDraw( axis, scaleDrawer );
plot->setAxisScaleDiv( axis, groupAxisScaleDiv );
@ -700,7 +717,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
}
}
RiuBarChartScaleDraw* barTextScaleDrawer = new RiuBarChartScaleDraw( positionedBarLabels );
RiuBarChartScaleDraw* barTextScaleDrawer = new RiuBarChartScaleDraw( positionedBarLabels, m_labelPointSize );
barTextScaleDrawer->setAlignment( alignment );
barTextScaleDrawer->setLabelRotation( labelRotation );
barTextScaleDrawer->setLabelAlignment( labelAlignment );
@ -713,6 +730,14 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuGroupedBarChartBuilder::setLabelFontSize( int labelPointSize )
{
m_labelPointSize = labelPointSize;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -47,6 +47,7 @@ public:
void setLegendColorMap( const std::map<QString, QColor>& legendColors );
void addBarChartToPlot( QwtPlot* plot, Qt::Orientation orientation, int maxBarCount = -1 );
void setLabelFontSize( int labelPointSize );
private:
double midPoint( double v1, double v2 ) { return v1 + 0.5 * ( v2 - 1.0 - v1 ); }
@ -87,4 +88,5 @@ private:
Qt::Orientation m_orientation;
std::map<QString, QColor> m_legendColors;
bool m_isSortingByMaxValueInGroups;
int m_labelPointSize;
};

View File

@ -83,11 +83,8 @@ void RiuSummaryVectorSelectionDialog::setCaseAndAddress( RimSummaryCase*
{
std::vector<RiaSummaryCurveDefinition> curveDefs;
curveDefs.push_back( RiaSummaryCurveDefinition( summaryCase, address ) );
summaryAddressSelection()->setSelectedCurveDefinitions( curveDefs );
setCurveSelection( curveDefs );
}
summaryAddressSelection()->updateConnectedEditors();
updateLabel();
}
//--------------------------------------------------------------------------------------------------
@ -100,11 +97,8 @@ void RiuSummaryVectorSelectionDialog::setEnsembleAndAddress( RimSummaryCaseColle
{
std::vector<RiaSummaryCurveDefinition> curveDefs;
curveDefs.push_back( RiaSummaryCurveDefinition( nullptr, address, ensemble ) );
summaryAddressSelection()->setSelectedCurveDefinitions( curveDefs );
setCurveSelection( curveDefs );
}
summaryAddressSelection()->updateConnectedEditors();
updateLabel();
}
//--------------------------------------------------------------------------------------------------
@ -113,6 +107,8 @@ void RiuSummaryVectorSelectionDialog::setEnsembleAndAddress( RimSummaryCaseColle
void RiuSummaryVectorSelectionDialog::setCurveSelection( const std::vector<RiaSummaryCurveDefinition>& selection )
{
summaryAddressSelection()->setSelectedCurveDefinitions( selection );
summaryAddressSelection()->updateConnectedEditors();
updateLabel();
}
//--------------------------------------------------------------------------------------------------