Improve plot titles and layout adjustments

This commit is contained in:
Magne Sjaastad
2023-07-06 08:40:09 +02:00
committed by GitHub
parent 8e777bd987
commit aaecd846fd
19 changed files with 144 additions and 54 deletions

View File

@@ -154,6 +154,21 @@ RiuFlowCharacteristicsPlot::~RiuFlowCharacteristicsPlot()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::setCaseName( const QString& caseName )
{
QString title = "Lorenz Coefficient";
if ( !caseName.isEmpty() )
{
title += " - " + caseName;
}
m_lorenzPlot->setTitle( title );
setWindowTitle( title );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -308,14 +323,6 @@ void RiuFlowCharacteristicsPlot::showLegend( bool show )
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimFlowCharacteristicsPlot* RiuFlowCharacteristicsPlot::ownerPlotDefinition()
{
return m_plotDefinition;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -51,6 +51,7 @@ public:
RiuFlowCharacteristicsPlot( RimFlowCharacteristicsPlot* plotDefinition, QWidget* parent = nullptr );
~RiuFlowCharacteristicsPlot() override;
void setCaseName( const QString& caseName );
void setLorenzCurve( const QStringList& dateTimeStrings,
const std::vector<QDateTime>& dateTimes,
const std::vector<double>& timeHistoryValues );
@@ -62,8 +63,7 @@ public:
void showLegend( bool show );
RimFlowCharacteristicsPlot* ownerPlotDefinition();
RimViewWindow* ownerViewWindow() const override;
RimViewWindow* ownerViewWindow() const override;
static void addWindowZoom( QwtPlot* plot );
static RiuQwtPlotCurve* createEmptyCurve( QwtPlot* plot, const QString& curveName, const QColor& curveColor );

View File

@@ -334,6 +334,14 @@ void RiuMatrixPlotWidget::setValueFontSize( int fontSize )
m_plotWidget->scheduleReplot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuMatrixPlotWidget::setMaxColumnLabelCount( int maxLabelCount )
{
m_maxColumnLabelCount = maxLabelCount;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -342,7 +350,8 @@ void RiuMatrixPlotWidget::updateAxes()
if ( !m_plotWidget ) return;
// Labels on y-axis
m_plotWidget->qwtPlot()->setAxisScaleDraw( QwtAxis::YLeft, new TextScaleDraw( createIndexLabelMap( m_rowHeaders ) ) );
const int maxLabelCount = 1000;
m_plotWidget->qwtPlot()->setAxisScaleDraw( QwtAxis::YLeft, new TextScaleDraw( createIndexLabelMap( m_rowHeaders, maxLabelCount ) ) );
m_plotWidget->qwtPlot()->setAxisScaleEngine( QwtAxis::YLeft, new RiuQwtLinearScaleEngine );
m_plotWidget->setAxisTitleText( RiuPlotAxis::defaultLeft(), m_rowTitle );
m_plotWidget->setAxisTitleEnabled( RiuPlotAxis::defaultLeft(), true );
@@ -358,7 +367,7 @@ void RiuMatrixPlotWidget::updateAxes()
static_cast<double>( m_rowHeaders.size() ) );
// Labels on column axis
auto scaleDraw = new TextScaleDraw( createIndexLabelMap( m_columnHeaders ) );
auto scaleDraw = new TextScaleDraw( createIndexLabelMap( m_columnHeaders, m_maxColumnLabelCount ) );
scaleDraw->setLabelRotation( 30.0 );
m_plotWidget->qwtPlot()->setAxisScaleDraw( QwtAxis::XBottom, scaleDraw );
m_plotWidget->qwtPlot()->setAxisScaleEngine( QwtAxis::XBottom, new RiuQwtLinearScaleEngine );
@@ -437,13 +446,26 @@ void RiuMatrixPlotWidget::createMatrixCells()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<size_t, QString> RiuMatrixPlotWidget::createIndexLabelMap( const std::vector<QString>& labels )
std::map<size_t, QString> RiuMatrixPlotWidget::createIndexLabelMap( const std::vector<QString>& labels, int maxLabelCount )
{
std::map<size_t, QString> indexLabelMap;
for ( size_t i = 0; i < labels.size(); ++i )
if ( labels.empty() ) return {};
int increment = 1;
if ( (int)labels.size() > maxLabelCount )
{
indexLabelMap.emplace( i, labels[i] );
increment = (int)labels.size() / ( maxLabelCount - 1 );
increment = std::max( 1, increment );
}
std::map<size_t, QString> indexLabelMap;
for ( size_t i = 0; i < std::min( labels.size(), size_t( maxLabelCount - 1 ) ); ++i )
{
auto index = i * increment;
indexLabelMap.emplace( index, labels[index] );
}
indexLabelMap.emplace( labels.size() - 1, labels.back() );
return indexLabelMap;
}

View File

@@ -72,6 +72,7 @@ public:
void setAxisTitleFontSize( int fontSize );
void setAxisLabelFontSize( int fontSize );
void setValueFontSize( int fontSize );
void setMaxColumnLabelCount( int maxLabelCount );
void scheduleReplot();
@@ -86,7 +87,7 @@ private slots:
private:
void updateAxes();
void createMatrixCells();
std::map<size_t, QString> createIndexLabelMap( const std::vector<QString>& labels );
std::map<size_t, QString> createIndexLabelMap( const std::vector<QString>& labels, int maxLabelCount );
private:
QPointer<RiuQwtPlotWidget> m_plotWidget;
@@ -107,7 +108,8 @@ private:
QString m_rowTitle;
QString m_columnTitle;
int m_axisTitleFontSize = 8;
int m_axisLabelFontSize = 8;
int m_valueFontSize = 8;
int m_axisTitleFontSize = 8;
int m_axisLabelFontSize = 8;
int m_valueFontSize = 8;
int m_maxColumnLabelCount = 100;
};

View File

@@ -46,7 +46,7 @@ RiuPlotWidget::RiuPlotWidget( RimPlot* plotDefinition, QWidget* parent )
: QWidget( parent )
, m_plotDefinition( plotDefinition )
, m_overlayMargins( 5 )
, m_plotTitle( "" )
, m_plotTitleText( "" )
, m_plotTitleEnabled( true )
{
}
@@ -107,7 +107,7 @@ int RiuPlotWidget::rowSpan() const
//--------------------------------------------------------------------------------------------------
const QString& RiuPlotWidget::plotTitle() const
{
return m_plotTitle;
return m_plotTitleText;
}
//--------------------------------------------------------------------------------------------------

View File

@@ -202,7 +202,7 @@ protected:
std::map<RiuPlotAxis, QString> m_axisTitles;
std::map<RiuPlotAxis, bool> m_axisTitlesEnabled;
const int m_overlayMargins;
QString m_plotTitle;
QString m_plotTitleText;
bool m_plotTitleEnabled;
QList<QPointer<RiuDraggableOverlayFrame>> m_overlayFrames;

View File

@@ -235,7 +235,7 @@ void RiuQtChartsPlotWidget::setAxisFormat( RiuPlotAxis axis, const QString& form
//--------------------------------------------------------------------------------------------------
void RiuQtChartsPlotWidget::setPlotTitle( const QString& plotTitle )
{
m_plotTitle = plotTitle;
m_plotTitleText = plotTitle;
applyPlotTitleToPlot();
}
@@ -244,7 +244,7 @@ void RiuQtChartsPlotWidget::setPlotTitle( const QString& plotTitle )
//--------------------------------------------------------------------------------------------------
const QString& RiuQtChartsPlotWidget::plotTitle() const
{
return m_plotTitle;
return m_plotTitleText;
}
//--------------------------------------------------------------------------------------------------
@@ -547,7 +547,7 @@ void RiuQtChartsPlotWidget::keyPressEvent( QKeyEvent* event )
//--------------------------------------------------------------------------------------------------
void RiuQtChartsPlotWidget::applyPlotTitleToPlot()
{
QString plotTitleToApply = m_plotTitleEnabled ? m_plotTitle : QString( "" );
QString plotTitleToApply = m_plotTitleEnabled ? m_plotTitleText : QString( "" );
m_viewer->chart()->setTitle( plotTitleToApply );
m_viewer->chart()->update();
}

View File

@@ -78,7 +78,8 @@
//--------------------------------------------------------------------------------------------------
RiuQwtPlotWidget::RiuQwtPlotWidget( RimPlot* plotDefinition, QWidget* parent )
: RiuPlotWidget( plotDefinition, parent )
, m_titleRenderingFlags( Qt::AlignHCenter | Qt::TextSingleLine )
, m_titleRenderingFlags( Qt::AlignHCenter | Qt::TextWordWrap )
, m_titleFontSize( -1 )
{
auto* layout = new QVBoxLayout;
layout->setContentsMargins( 0, 0, 0, 0 );
@@ -211,7 +212,7 @@ void RiuQwtPlotWidget::setAxisTitleEnabled( RiuPlotAxis axis, bool enable )
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setPlotTitle( const QString& plotTitle )
{
m_plotTitle = plotTitle;
m_plotTitleText = plotTitle;
applyPlotTitleToQwt();
}
@@ -220,7 +221,7 @@ void RiuQwtPlotWidget::setPlotTitle( const QString& plotTitle )
//--------------------------------------------------------------------------------------------------
const QString& RiuQwtPlotWidget::plotTitle() const
{
return m_plotTitle;
return m_plotTitleText;
}
//--------------------------------------------------------------------------------------------------
@@ -245,20 +246,9 @@ bool RiuQwtPlotWidget::plotTitleEnabled() const
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setPlotTitleFontSize( int titleFontSize )
{
auto title = m_plot->title();
QFont font = title.font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( titleFontSize ) );
title.setFont( font );
title.setRenderFlags( title.renderFlags() | Qt::TextWordWrap );
m_plot->setTitle( title );
}
m_titleFontSize = titleFontSize;
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::setPlotTitleRenderingFlags( int flags )
{
m_titleRenderingFlags = flags;
applyPlotTitleToQwt();
}
//--------------------------------------------------------------------------------------------------
@@ -676,14 +666,19 @@ void RiuQwtPlotWidget::keyPressEvent( QKeyEvent* event )
//--------------------------------------------------------------------------------------------------
void RiuQwtPlotWidget::applyPlotTitleToQwt()
{
QString plotTitleToApply = m_plotTitleEnabled ? m_plotTitle : QString( "" );
QwtText plotTitle = m_plot->title();
plotTitle.setRenderFlags( m_titleRenderingFlags );
if ( plotTitleToApply != plotTitle.text() )
QString plotTitleToApply = m_plotTitleEnabled ? m_plotTitleText : QString( "" );
QwtText qwtText = m_plot->title();
qwtText.setRenderFlags( m_titleRenderingFlags );
if ( m_titleFontSize > 0 )
{
plotTitle.setText( plotTitleToApply );
m_plot->setTitle( plotTitle );
QFont font = qwtText.font();
font.setPixelSize( caf::FontTools::pointSizeToPixelSize( m_titleFontSize ) );
qwtText.setFont( font );
}
qwtText.setText( plotTitleToApply );
// Always set the title, as Qwt does not do anything if the text is the same
m_plot->setTitle( qwtText );
}
//--------------------------------------------------------------------------------------------------

View File

@@ -101,7 +101,6 @@ public:
void setPlotTitleEnabled( bool enabled ) override;
bool plotTitleEnabled() const override;
void setPlotTitleFontSize( int titleFontSize ) override;
void setPlotTitleRenderingFlags( int flags );
void setLegendFontSize( int fontSize ) override;
void setInternalLegendVisible( bool visible ) override;
@@ -237,4 +236,5 @@ private:
QPointer<QwtPlot> m_plot;
int m_titleRenderingFlags;
int m_titleFontSize;
};

View File

@@ -50,6 +50,9 @@ RiuWellAllocationPlot::RiuWellAllocationPlot( RimWellAllocationPlot* plotDefinit
this->layout()->setSpacing( 2 );
m_titleLabel = new QLabel( this );
m_titleLabel->setWordWrap( true );
m_titleLabel->setAlignment( Qt::AlignCenter );
new RiuPlotObjectPicker( m_titleLabel, m_plotDefinition->accumulatedWellFlowPlot() );
QFont font = m_titleLabel->font();
@@ -63,7 +66,7 @@ RiuWellAllocationPlot::RiuWellAllocationPlot( RimWellAllocationPlot* plotDefinit
this->setAutoFillBackground( true );
this->setPalette( pal );
mainLayout->addWidget( m_titleLabel, 0, Qt::AlignCenter );
mainLayout->addWidget( m_titleLabel );
auto plotWidgetsLayout = new QHBoxLayout();
auto leftColumnLayout = new QVBoxLayout();