mirror of
https://github.com/OPM/ResInsight.git
synced 2026-10-24 14:17:52 -05:00
Show RFT tornado plot labels at left side of the plot area
This commit is contained in:
1 parent
96370a6077
commit
186c4795f9
3 files changed
+50
-6
No files matched your search
@@ -48,6 +48,12 @@
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimRftTornadoPlot, "RftTornadoPlot" );
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr double axisMinAbsolute = -0.7;
|
||||
constexpr double anchorMargin = 0.03;
|
||||
} // namespace
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -225,8 +231,8 @@ void RimRftTornadoPlot::updateAxes()
|
||||
if ( m_showAbsoluteValues() )
|
||||
{
|
||||
m_plotWidget->setAxisTitleText( RiuPlotAxis::defaultBottom(), "Pearson Correlation Coefficient ABS" );
|
||||
// Use a small negative margin so bar label text (anchored at x=0) remains visible
|
||||
m_plotWidget->setAxisRange( RiuPlotAxis::defaultBottom(), -0.15, 1.0 );
|
||||
// Leave room left of zero for the bar labels
|
||||
m_plotWidget->setAxisRange( RiuPlotAxis::defaultBottom(), axisMinAbsolute, 1.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -320,6 +326,10 @@ void RimRftTornadoPlot::onLoadDataAndUpdate()
|
||||
m_lastCorrelations = addDataToChartBuilder( chartBuilder );
|
||||
const int labelSize = caf::FontTools::absolutePointSize( RiaPreferences::current()->defaultPlotFontSize(), m_labelFontSize() );
|
||||
chartBuilder.setLabelFontSize( labelSize );
|
||||
// Labels start at the left edge of the plot, in the empty space left of the bars. The anchor must be slightly inside
|
||||
// the axis range, as Qwt skips scale items positioned outside the canvas. Only used for absolute values, as signed
|
||||
// values have bars on both sides of zero.
|
||||
if ( m_showAbsoluteValues() ) chartBuilder.setBarTextAnchor( axisMinAbsolute + anchorMargin );
|
||||
RiuRftCorrelationPlotTools::addHorizontalBarChart( m_plotWidget, chartBuilder, m_showOnlyTopNCorrelations() ? m_topNFilterCount() : -1 );
|
||||
RimCorrelationBarChartTools::highlightSelectedParameterBar( m_plotWidget,
|
||||
m_selectedParameter,
|
||||
|
||||
@@ -367,6 +367,8 @@ void RiuGroupedBarChartBuilder::setBarColor( const QColor& color )
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientation barOrientation, int maxBarCount )
|
||||
{
|
||||
const bool showBarTextAtAnchor = m_barTextAnchor.has_value() && barOrientation == Qt::Horizontal;
|
||||
|
||||
const double majGroupSpacing = 1.6;
|
||||
const double midGroupSpacing = 0.5;
|
||||
const double minGroupSpacing = 0.2;
|
||||
@@ -629,8 +631,19 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
|
||||
barPoints->push_back( { currentBarPosition, barDef.m_value } );
|
||||
if ( !barDef.m_barText.isEmpty() )
|
||||
{
|
||||
QString barText = barDef.m_barText;
|
||||
if ( showBarTextAtAnchor )
|
||||
{
|
||||
// Long labels are shortened in the middle to limit the space used inside the plot
|
||||
const int maxLabelLength = 26;
|
||||
if ( barText.size() > maxLabelLength )
|
||||
{
|
||||
barText = barText.left( 10 ) + QString::fromUtf8( "…" ) + barText.right( maxLabelLength - 11 );
|
||||
}
|
||||
}
|
||||
|
||||
positionedBarLabels[currentBarPosition] =
|
||||
RiuBarChartScaleDraw::RiuBarChartTick( QwtScaleDiv::MinorTick, barDef.m_barText, barDef.m_value < 0.0 );
|
||||
RiuBarChartScaleDraw::RiuBarChartTick( QwtScaleDiv::MinorTick, barText, !showBarTextAtAnchor && barDef.m_value < 0.0 );
|
||||
}
|
||||
|
||||
// Increment the bar position for the next bar
|
||||
@@ -797,12 +810,19 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
|
||||
QwtScaleDraw::Alignment alignment = QwtScaleDraw::TopScale;
|
||||
double labelRotation = -90.0;
|
||||
Qt::Alignment labelAlignment = Qt::AlignVCenter | Qt::AlignRight;
|
||||
double scalePosition = 0.0;
|
||||
if ( barOrientation == Qt::Horizontal )
|
||||
{
|
||||
alignment = QwtScaleDraw::RightScale;
|
||||
labelRotation = 0.0;
|
||||
}
|
||||
|
||||
if ( showBarTextAtAnchor )
|
||||
{
|
||||
// Labels start at the anchor position and extend to the right
|
||||
scalePosition = *m_barTextAnchor;
|
||||
}
|
||||
|
||||
QwtScaleDiv barTextScaleDiv( 0, currentBarPosition );
|
||||
{
|
||||
QList<double> onBarTickPositions;
|
||||
@@ -826,7 +846,7 @@ void RiuGroupedBarChartBuilder::addBarChartToPlot( QwtPlot* plot, Qt::Orientatio
|
||||
barTextScaleDrawer->setLabelRotation( labelRotation );
|
||||
barTextScaleDrawer->setLabelAlignment( labelAlignment );
|
||||
|
||||
QwtPlotScaleItem* barTextScale = new QwtPlotScaleItem( alignment, 0.0 );
|
||||
QwtPlotScaleItem* barTextScale = new QwtPlotScaleItem( alignment, scalePosition );
|
||||
barTextScale->setScaleDraw( barTextScaleDrawer );
|
||||
barTextScale->setScaleDiv( barTextScaleDiv );
|
||||
barTextScale->attach( plot );
|
||||
@@ -842,6 +862,14 @@ void RiuGroupedBarChartBuilder::setLabelFontSize( int labelPointSize )
|
||||
m_labelPointSize = labelPointSize;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RiuGroupedBarChartBuilder::setBarTextAnchor( double valueAxisPosition )
|
||||
{
|
||||
m_barTextAnchor = valueAxisPosition;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
|
||||
class QwtPlot;
|
||||
@@ -50,6 +51,10 @@ public:
|
||||
void addBarChartToPlot( QwtPlot* plot, Qt::Orientation orientation, int maxBarCount = -1 );
|
||||
void setLabelFontSize( int labelPointSize );
|
||||
|
||||
// For horizontal bar charts: left-align the bar texts at the given value axis position instead of
|
||||
// placing them next to the bars
|
||||
void setBarTextAnchor( double valueAxisPosition );
|
||||
|
||||
QString plotContentAsText() const;
|
||||
|
||||
private:
|
||||
@@ -91,6 +96,7 @@ private:
|
||||
bool m_isSortingByMaxValueInGroups;
|
||||
int m_labelPointSize;
|
||||
|
||||
bool m_useBarColor = false;
|
||||
QColor m_barColor;
|
||||
std::optional<double> m_barTextAnchor;
|
||||
bool m_useBarColor = false;
|
||||
QColor m_barColor;
|
||||
};
|
||||
Reference in new issue
Block a user