Skip to content

Commit

Permalink
Add filtering on axis orientation
Browse files Browse the repository at this point in the history
Makes it possible to show only horizontal or vertical axes when selecting an axis to attach a curve to.
  • Loading branch information
magnesj committed Sep 25, 2023
1 parent 5d42863 commit 9fcd817
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 52 deletions.
7 changes: 7 additions & 0 deletions ApplicationLibCode/ProjectDataModel/RimPlotAxisProperties.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class RimPlotAxisProperties : public RimPlotAxisPropertiesInterface
NUMBER_FORMAT_SCIENTIFIC
};

enum class Orientation
{
HORIZONTAL,
VERTICAL,
ANY
};

public:
caf::Signal<bool> logarithmicChanged;
caf::Signal<RimPlotAxisProperties*, RiuPlotAxis, RiuPlotAxis> axisPositionChanged;
Expand Down
23 changes: 12 additions & 11 deletions ApplicationLibCode/ProjectDataModel/Summary/RimEnsembleCurveSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ RimEnsembleCurveSet::RimEnsembleCurveSet()

CAF_PDM_InitFieldNoDefault( &m_xAddressSelector, "XAddressSelector", "" );
m_xAddressSelector = new RimSummaryAddressSelector;
m_xAddressSelector->setAxisOrientation( RimPlotAxisProperties::Orientation::HORIZONTAL );
m_xAddressSelector.uiCapability()->setUiTreeHidden( true );
m_xAddressSelector.uiCapability()->setUiTreeChildrenHidden( true );

Expand Down Expand Up @@ -203,7 +204,7 @@ RimEnsembleCurveSet::RimEnsembleCurveSet()
CAF_PDM_InitFieldNoDefault( &m_plotAxis_OBSOLETE, "PlotAxis", "Axis" );
m_plotAxis_OBSOLETE.xmlCapability()->setIOWritable( false );

CAF_PDM_InitFieldNoDefault( &m_plotAxisProperties, "Axis", "Axis" );
CAF_PDM_InitFieldNoDefault( &m_yPlotAxisProperties, "Axis", "Axis" );

CAF_PDM_InitFieldNoDefault( &m_legendConfig, "LegendConfig", "" );
m_legendConfig = new RimRegularLegendConfig();
Expand Down Expand Up @@ -853,7 +854,7 @@ void RimEnsembleCurveSet::fieldChangedByUi( const caf::PdmFieldHandle* changedFi
updateCurveColors();
updateTimeAnnotations();
}
else if ( changedField == &m_plotAxisProperties )
else if ( changedField == &m_yPlotAxisProperties )
{
for ( RimSummaryCurve* curve : curves() )
{
Expand Down Expand Up @@ -1000,7 +1001,7 @@ void RimEnsembleCurveSet::defineUiOrdering( QString uiConfigName, caf::PdmUiOrde
curveDataGroup->add( &m_yValuesSummaryAddressUiField );
curveDataGroup->add( &m_yPushButtonSelectSummaryAddress, { false, 1, 0 } );
curveDataGroup->add( &m_resampling );
curveDataGroup->add( &m_plotAxisProperties );
curveDataGroup->add( &m_yPlotAxisProperties );
}

{
Expand Down Expand Up @@ -1431,10 +1432,10 @@ QList<caf::PdmOptionItemInfo> RimEnsembleCurveSet::calculateValueOptions( const
options.push_back( caf::PdmOptionItemInfo( name, objFunc ) );
}
}
else if ( fieldNeedingOptions == &m_plotAxisProperties )
else if ( fieldNeedingOptions == &m_yPlotAxisProperties )
{
auto plot = firstAncestorOrThisOfTypeAsserted<RimSummaryPlot>();
for ( auto axis : plot->plotAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::VERTICAL ) )
{
options.push_back( caf::PdmOptionItemInfo( axis->objectName(), axis ) );
}
Expand Down Expand Up @@ -2391,8 +2392,8 @@ int statisticsCurveSymbolSize( RiuPlotCurveSymbol::PointSymbolEnum symbol )
//--------------------------------------------------------------------------------------------------
RiuPlotAxis RimEnsembleCurveSet::axisY() const
{
if ( m_plotAxisProperties )
return m_plotAxisProperties->plotAxis();
if ( m_yPlotAxisProperties )
return m_yPlotAxisProperties->plotAxis();
else
return RiuPlotAxis::defaultLeft();
}
Expand All @@ -2402,8 +2403,8 @@ RiuPlotAxis RimEnsembleCurveSet::axisY() const
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSet::setLeftOrRightAxisY( RiuPlotAxis plotAxis )
{
auto plot = firstAncestorOrThisOfTypeAsserted<RimSummaryPlot>();
m_plotAxisProperties = plot->axisPropertiesForPlotAxis( plotAxis );
auto plot = firstAncestorOrThisOfTypeAsserted<RimSummaryPlot>();
m_yPlotAxisProperties = plot->axisPropertiesForPlotAxis( plotAxis );

for ( RimSummaryCurve* curve : curves() )
{
Expand All @@ -2416,12 +2417,12 @@ void RimEnsembleCurveSet::setLeftOrRightAxisY( RiuPlotAxis plotAxis )
//--------------------------------------------------------------------------------------------------
void RimEnsembleCurveSet::initAfterRead()
{
if ( m_plotAxisProperties.value() == nullptr )
if ( m_yPlotAxisProperties.value() == nullptr )
{
auto plot = firstAncestorOrThisOfType<RimSummaryPlot>();
if ( plot )
{
m_plotAxisProperties = plot->axisPropertiesForPlotAxis( RiuPlotAxis( m_plotAxis_OBSOLETE() ) );
m_yPlotAxisProperties = plot->axisPropertiesForPlotAxis( RiuPlotAxis( m_plotAxis_OBSOLETE() ) );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class RimEnsembleCurveSet : public caf::PdmObject, public RimEnsembleCurveSetInt
caf::PdmField<std::vector<QDateTime>> m_selectedTimeSteps;

caf::PdmField<caf::AppEnum<RiaDefines::PlotAxis>> m_plotAxis_OBSOLETE;
caf::PdmPtrField<RimPlotAxisPropertiesInterface*> m_plotAxisProperties;
caf::PdmPtrField<RimPlotAxisPropertiesInterface*> m_yPlotAxisProperties;

caf::PdmChildField<RimRegularLegendConfig*> m_legendConfig;
caf::PdmChildField<RimEnsembleCurveFilterCollection*> m_curveFilters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ RimSummaryAddressSelector::RimSummaryAddressSelector()

CAF_PDM_InitFieldNoDefault( &m_resamplingPeriod, "Resampling", "Resampling" );

m_dataSource = SummaryDataSource::SINGLE_CASE;
m_showDataSource = true;
m_dataSource = SummaryDataSource::SINGLE_CASE;
m_showDataSource = true;
m_plotAxisOrientation = RimPlotAxisProperties::Orientation::ANY;
}

//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -126,6 +127,14 @@ void RimSummaryAddressSelector::setShowDataSource( bool enable )
m_showDataSource = enable;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryAddressSelector::setAxisOrientation( RimPlotAxisProperties::Orientation orientation )
{
m_plotAxisOrientation = orientation;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -304,7 +313,7 @@ QList<caf::PdmOptionItemInfo> RimSummaryAddressSelector::calculateValueOptions(
if ( auto plot = firstAncestorOrThisOfTypeAsserted<RimSummaryPlot>() )
{
QList<caf::PdmOptionItemInfo> options;
for ( auto axis : plot->plotAxes() )
for ( auto axis : plot->plotAxes( m_plotAxisOrientation ) )
{
options.push_back( caf::PdmOptionItemInfo( axis->objectName(), axis ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class RimSummaryAddressSelector : public caf::PdmObject
void setResamplingPeriod( RiaDefines::DateTimePeriodEnum resampling );
void setPlotAxisProperties( RimPlotAxisPropertiesInterface* plotAxisProperties );
void setShowDataSource( bool enable );
void setAxisOrientation( RimPlotAxisProperties::Orientation orientation );

RimSummaryCase* summaryCase() const;
RimSummaryCaseCollection* ensemble() const;
Expand All @@ -79,4 +80,6 @@ class RimSummaryAddressSelector : public caf::PdmObject

SummaryDataSource m_dataSource;
bool m_showDataSource;

RimPlotAxisProperties::Orientation m_plotAxisOrientation;
};
10 changes: 3 additions & 7 deletions ApplicationLibCode/ProjectDataModel/Summary/RimSummaryCurve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,20 +551,16 @@ QList<caf::PdmOptionItemInfo> RimSummaryCurve::calculateValueOptions( const caf:
{
auto plot = firstAncestorOrThisOfTypeAsserted<RimSummaryPlot>();

for ( auto axis : plot->plotAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::VERTICAL ) )
{
// TODO: Should we allow time axis to be used as Y axis?
if ( dynamic_cast<RimPlotAxisProperties*>( axis ) )
{
options.push_back( caf::PdmOptionItemInfo( axis->objectName(), axis ) );
}
options.push_back( caf::PdmOptionItemInfo( axis->objectName(), axis ) );
}
}
else if ( fieldNeedingOptions == &m_xPlotAxisProperties )
{
auto plot = firstAncestorOrThisOfTypeAsserted<RimSummaryPlot>();

for ( auto axis : plot->plotAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::HORIZONTAL ) )
{
options.push_back( caf::PdmOptionItemInfo( axis->objectName(), axis ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void RimSummaryMultiPlot::syncAxisRanges()

for ( auto p : summaryPlots() )
{
for ( auto ax : p->plotYAxes() )
for ( auto ax : p->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
ax->setAutoZoomIfNoCustomRangeIsSet();
}
Expand All @@ -878,7 +878,7 @@ void RimSummaryMultiPlot::syncAxisRanges()
// gather current min/max values for each category (axis label)
for ( auto plot : summaryPlots() )
{
for ( auto axis : plot->plotYAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
double minVal = axis->visibleRangeMin();
double maxVal = axis->visibleRangeMax();
Expand All @@ -900,7 +900,7 @@ void RimSummaryMultiPlot::syncAxisRanges()
// set all plots to use the global min/max values for each category
for ( auto plot : summaryPlots() )
{
for ( auto axis : plot->plotYAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
auto [minVal, maxVal] = axisRanges[axis->objectName()];
if ( axis->isAxisInverted() ) std::swap( minVal, maxVal );
Expand Down Expand Up @@ -1080,7 +1080,7 @@ void RimSummaryMultiPlot::computeAggregatedAxisRange()
{
std::map<RiuPlotAxis, std::pair<double, double>> axisRanges;

for ( auto axis : plot->plotYAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
for ( auto curve : plot->summaryCurves() )
{
Expand Down Expand Up @@ -1146,7 +1146,7 @@ void RimSummaryMultiPlot::computeAggregatedAxisRange()
}

// set all plots to use the global min/max values for each category
for ( auto axis : plot->plotYAxes() )
for ( auto axis : plot->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
auto [minVal, maxVal] = axisRanges[axis->plotAxis()];
if ( RiaDefines::isVertical( axis->plotAxis().axis() ) && !std::isinf( minVal ) && !std::isinf( maxVal ) )
Expand Down Expand Up @@ -1215,7 +1215,7 @@ void RimSummaryMultiPlot::setAutoValueStatesForPlot( RimSummaryPlot* summaryPlot
auto timeAxisProp = summaryPlot->timeAxisProperties();
if ( timeAxisProp ) timeAxisProp->enableAutoValueForMajorTickmarkCount( enableAutoValueAppearance );

for ( auto plotAxis : summaryPlot->plotYAxes() )
for ( auto plotAxis : summaryPlot->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
plotAxis->enableAutoValueMinMax( enableAutoValueMinMax );
plotAxis->enableAutoValueForMajorTickmarkCount( enableAutoValueAppearance );
Expand Down Expand Up @@ -1281,10 +1281,8 @@ void RimSummaryMultiPlot::analyzePlotsAndAdjustAppearanceSettings()
timeAxisProp->setAutoValueForMajorTickmarkCount( tickMarkCount, notifyFieldChanged );
}

for ( auto* axisProp : p->plotYAxes() )
for ( auto* axisProp : p->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
if ( !axisProp ) continue;

auto tickMarkCount = ( rowsPerPage() == 1 ) ? RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_DEFAULT
: RimPlotAxisProperties::LegendTickmarkCount::TICKMARK_FEW;

Expand Down Expand Up @@ -1314,10 +1312,8 @@ void RimSummaryMultiPlot::analyzePlotsAndAdjustAppearanceSettings()
{
for ( auto p : summaryPlots() )
{
for ( auto* axisProp : p->plotYAxes() )
for ( auto* axisProp : p->plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
if ( !axisProp ) continue;

axisProp->computeAndSetAutoValueForScaleFactor();
axisProp->setShowUnitText( true );
axisProp->setShowDescription( true );
Expand Down
33 changes: 17 additions & 16 deletions ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
#include "RimGridTimeHistoryCurve.h"
#include "RimMultiPlot.h"
#include "RimPlotAxisLogRangeCalculator.h"
#include "RimPlotAxisProperties.h"
#include "RimProject.h"
#include "RimSummaryAddress.h"
#include "RimSummaryAddressCollection.h"
Expand Down Expand Up @@ -621,7 +620,7 @@ const RimSummaryNameHelper* RimSummaryPlot::plotTitleHelper() const
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::copyAxisPropertiesFromOther( const RimSummaryPlot& sourceSummaryPlot )
{
for ( auto ap : sourceSummaryPlot.plotAxes() )
for ( auto ap : sourceSummaryPlot.allPlotAxes() )
{
QString data = ap->writeObjectToXmlString();

Expand All @@ -638,7 +637,7 @@ void RimSummaryPlot::copyAxisPropertiesFromOther( const RimSummaryPlot& sourceSu
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::copyAxisPropertiesFromOther( RiaDefines::PlotAxis plotAxisType, const RimSummaryPlot& sourceSummaryPlot )
{
for ( auto ap : sourceSummaryPlot.plotAxes() )
for ( auto ap : sourceSummaryPlot.allPlotAxes() )
{
if ( ap->plotAxis().axis() != plotAxisType ) continue;

Expand All @@ -657,9 +656,9 @@ void RimSummaryPlot::copyAxisPropertiesFromOther( RiaDefines::PlotAxis plotAxisT
//--------------------------------------------------------------------------------------------------
void RimSummaryPlot::copyMatchingAxisPropertiesFromOther( const RimSummaryPlot& summaryPlot )
{
for ( auto apToCopy : summaryPlot.plotAxes() )
for ( auto apToCopy : summaryPlot.allPlotAxes() )
{
for ( auto ap : plotAxes() )
for ( auto ap : allPlotAxes() )
{
if ( ap->objectName().compare( apToCopy->objectName() ) == 0 )
{
Expand Down Expand Up @@ -2659,7 +2658,7 @@ void RimSummaryPlot::onPlotZoomed()
setAutoScaleYEnabled( false );

// Disable auto value for min/max fields
for ( auto p : plotYAxes() )
for ( auto p : plotAxes( RimPlotAxisProperties::Orientation::ANY ) )
{
p->enableAutoValueMinMax( false );
}
Expand Down Expand Up @@ -3106,27 +3105,29 @@ bool RimSummaryPlot::isDeletable() const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotAxisPropertiesInterface*> RimSummaryPlot::plotAxes() const
std::vector<RimPlotAxisPropertiesInterface*> RimSummaryPlot::allPlotAxes() const
{
std::vector<RimPlotAxisPropertiesInterface*> axisProps;
for ( const auto& ap : m_axisPropertiesArray )
{
axisProps.push_back( ap );
}

return axisProps;
return m_axisPropertiesArray.childrenByType();
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<RimPlotAxisProperties*> RimSummaryPlot::plotYAxes() const
std::vector<RimPlotAxisProperties*> RimSummaryPlot::plotAxes( RimPlotAxisProperties::Orientation orientation ) const
{
std::vector<RimPlotAxisProperties*> axisProps;
for ( const auto& ap : m_axisPropertiesArray )
{
auto plotAxisProp = dynamic_cast<RimPlotAxisProperties*>( ap.p() );
if ( plotAxisProp && plotAxisProp->plotAxis().isVertical() )
if ( !plotAxisProp ) continue;

if ( ( orientation == RimPlotAxisProperties::Orientation::ANY ) ||
( orientation == RimPlotAxisProperties::Orientation::VERTICAL && plotAxisProp->plotAxis().isVertical() ) )
{
axisProps.push_back( plotAxisProp );
}
else if ( ( orientation == RimPlotAxisProperties::Orientation::ANY ) ||
( orientation == RimPlotAxisProperties::Orientation::HORIZONTAL && plotAxisProp->plotAxis().isHorizontal() ) )
{
axisProps.push_back( plotAxisProp );
}
Expand Down
6 changes: 4 additions & 2 deletions ApplicationLibCode/ProjectDataModel/Summary/RimSummaryPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "RiaPlotDefines.h"

#include "RimPlot.h"
#include "RimPlotAxisProperties.h"
#include "RimSummaryDataSourceStepping.h"

#include "RiuQwtPlotWidget.h"
Expand Down Expand Up @@ -201,8 +202,7 @@ class RimSummaryPlot : public RimPlot, public RimSummaryDataSourceStepping
std::vector<RimEnsembleCurveSet*> curveSets() const override;
std::vector<RimSummaryCurve*> allCurves( RimSummaryDataSourceStepping::Axis axis ) const override;

std::vector<RimPlotAxisPropertiesInterface*> plotAxes() const;
std::vector<RimPlotAxisProperties*> plotYAxes() const;
std::vector<RimPlotAxisProperties*> plotAxes( RimPlotAxisProperties::Orientation orientation ) const;

RimPlotAxisPropertiesInterface* axisPropertiesForPlotAxis( RiuPlotAxis plotAxis ) const;
RimPlotAxisProperties* addNewAxisProperties( RiaDefines::PlotAxis, const QString& name );
Expand Down Expand Up @@ -293,6 +293,8 @@ private slots:
RiuPlotAxis oldPlotAxis,
RiuPlotAxis newPlotAxis );

std::vector<RimPlotAxisPropertiesInterface*> allPlotAxes() const;

void timeAxisSettingsChanged( const caf::SignalEmitter* emitter );
void timeAxisSettingsChangedReloadRequired( const caf::SignalEmitter* emitter );

Expand Down

0 comments on commit 9fcd817

Please sign in to comment.