Swap axis settings when swapping Grid Cross Plot axes + fix inverted axes for summary plot

This commit is contained in:
Gaute Lindkvist 2019-03-13 08:38:18 +01:00
parent 925747b9d4
commit 0ce69d41dd
8 changed files with 173 additions and 119 deletions

View File

@ -40,7 +40,7 @@ void RicSwapGridCrossPlotCurveSetAxesFeature::onActionTriggered(bool isChecked)
else if (caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlot>())
{
auto plot = caf::SelectionManager::instance()->selectedItemOfType<RimGridCrossPlot>();
plot->swapAllAxisProperties();
plot->swapAxes();
}
}

View File

@ -521,13 +521,29 @@ void RimGridCrossPlot::updateCurveNamesAndPlotTitle()
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimGridCrossPlot::swapAllAxisProperties()
void RimGridCrossPlot::swapAxes()
{
RimPlotAxisProperties* xAxisProperties = m_xAxisProperties();
RimPlotAxisProperties* yAxisProperties = m_yAxisProperties();
QString tmpName = xAxisProperties->name();
QwtPlot::Axis tmpAxis = xAxisProperties->qwtPlotAxisType();
xAxisProperties->setNameAndAxis(yAxisProperties->name(), yAxisProperties->qwtPlotAxisType());
yAxisProperties->setNameAndAxis(tmpName, tmpAxis);
m_xAxisProperties.removeChildObject(xAxisProperties);
m_yAxisProperties.removeChildObject(yAxisProperties);
m_yAxisProperties = xAxisProperties;
m_xAxisProperties = yAxisProperties;
for (auto curveSet : m_crossPlotCurveSets)
{
curveSet->swapAxisProperties(false);
}
loadDataAndUpdate();
updateAxisDisplay();
}
//--------------------------------------------------------------------------------------------------
@ -672,6 +688,15 @@ void RimGridCrossPlot::updateAxisInQwt(RiaDefines::PlotAxis axisType)
m_qwtPlot->setAxisScaleEngine(axisProperties->qwtPlotAxisType(), new QwtLogScaleEngine);
m_qwtPlot->setAxisMaxMinor(axisProperties->qwtPlotAxisType(), 5);
}
if (axisProperties->isAutoZoom())
{
m_qwtPlot->setAxisAutoScale(qwtAxisId);
}
else
{
m_qwtPlot->setAxisScale(qwtAxisId, axisProperties->visibleRangeMin, axisProperties->visibleRangeMax);
}
}
else
{
@ -682,8 +707,6 @@ void RimGridCrossPlot::updateAxisInQwt(RiaDefines::PlotAxis axisType)
m_qwtPlot->setAxisScaleEngine(axisProperties->qwtPlotAxisType(), new QwtLinearScaleEngine);
m_qwtPlot->setAxisMaxMinor(axisProperties->qwtPlotAxisType(), 3);
}
}
m_qwtPlot->axisScaleEngine(axisProperties->qwtPlotAxisType())->setAttribute(QwtScaleEngine::Inverted, axisProperties->isAxisInverted());
if (axisProperties->isAutoZoom())
{
@ -693,8 +716,8 @@ void RimGridCrossPlot::updateAxisInQwt(RiaDefines::PlotAxis axisType)
{
m_qwtPlot->setAxisScale(qwtAxisId, axisProperties->visibleRangeMin, axisProperties->visibleRangeMax);
}
}
m_qwtPlot->axisScaleEngine(axisProperties->qwtPlotAxisType())->setAttribute(QwtScaleEngine::Inverted, axisProperties->isAxisInverted());
}
else
{

View File

@ -70,7 +70,7 @@ public:
void detachAllCurves();
void performAutoNameUpdate() override;
void updateCurveNamesAndPlotTitle();
void swapAllAxisProperties();
void swapAxes();
QString asciiTitleForPlotExport(int curveSetIndex) const;
QString asciiDataForPlotExport(int curveSetIndex) const;
RiuGridCrossQwtPlot* qwtPlot() const;

View File

@ -20,6 +20,7 @@
#include "RimPlotAxisProperties.h"
#include "RiaDefines.h"
#include "RigStatisticsCalculator.h"
#include "RimRiuQwtPlotOwnerInterface.h"
@ -27,6 +28,8 @@
#include <cmath>
#include <qwt_plot_curve.h>
// clang-format off
namespace caf
{
@ -222,6 +225,14 @@ QwtPlot::Axis RimPlotAxisProperties::qwtPlotAxisType() const
return m_axis;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPlotAxisProperties::name() const
{
return m_name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@ -358,3 +369,89 @@ caf::PdmFieldHandle* RimPlotAxisProperties::objectToggleField()
{
return &m_isActive;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimPlotAxisRangeCalculator::RimPlotAxisRangeCalculator(QwtPlot::Axis axis,
const std::vector<QwtPlotCurve*>& qwtCurves,
const std::vector<double>& axisValuesForAllCurves)
: m_singleCurves(qwtCurves)
, m_axisValuesForAllCurves(axisValuesForAllCurves)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPlotAxisRangeCalculator::computeAxisRange(double* min, double* max) const
{
double minValue = HUGE_VAL;
double maxValue = -HUGE_VAL;
for (QwtPlotCurve* curve : m_singleCurves)
{
double minCurveValue = HUGE_VAL;
double maxCurveValue = -HUGE_VAL;
if (curveValueRange(curve, &minCurveValue, &maxCurveValue))
{
if (minCurveValue < minValue)
{
minValue = minCurveValue;
}
if (maxCurveValue > maxValue)
{
maxValue = maxCurveValue;
}
}
}
if (minValue == HUGE_VAL)
{
minValue = RiaDefines::minimumDefaultValuePlot();
maxValue = RiaDefines::maximumDefaultValuePlot();
}
// For logarithmic auto scaling, compute positive curve value closest to zero and use
// this value as the plot visible minimum
double pos = HUGE_VAL;
double neg = -HUGE_VAL;
RigStatisticsCalculator::posNegClosestToZero(m_axisValuesForAllCurves, pos, neg);
if (pos != HUGE_VAL)
{
minValue = pos;
}
*min = minValue;
*max = maxValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPlotAxisRangeCalculator::curveValueRange(const QwtPlotCurve* qwtCurve, double* min, double* max) const
{
if (!qwtCurve) return false;
if (qwtCurve->data()->size() < 1)
{
return false;
}
if (m_axis == QwtPlot::xBottom || m_axis == QwtPlot::xTop)
{
*min = qwtCurve->minXValue();
*max = qwtCurve->maxXValue();
}
else
{
*min = qwtCurve->minYValue();
*max = qwtCurve->maxYValue();
}
return true;
}

View File

@ -57,7 +57,9 @@ public:
void setEnableTitleTextSettings(bool enable);
void setNameAndAxis(const QString& name, QwtPlot::Axis axis);
QwtPlot::Axis qwtPlotAxisType() const;
QString name() const;
RiaDefines::PlotAxis plotAxisType() const;
bool useAutoTitle() const;
bool showDescription() const;
@ -111,3 +113,27 @@ private:
bool m_enableTitleTextSettings;
};
class QwtPlotCurve;
//==================================================================================================
///
///
//==================================================================================================
class RimPlotAxisRangeCalculator
{
public:
RimPlotAxisRangeCalculator(QwtPlot::Axis axis,
const std::vector<QwtPlotCurve*>& qwtCurves,
const std::vector<double>& axisValuesForAllCurves);
void computeAxisRange(double* min, double* max) const;
private:
bool curveValueRange(const QwtPlotCurve* qwtCurve, double* min, double* max) const;
private:
QwtPlot::Axis m_axis;
const std::vector<QwtPlotCurve*> m_singleCurves;
const std::vector<double> m_axisValuesForAllCurves;
};

View File

@ -18,8 +18,6 @@
#include "RimSummaryCurvesCalculator.h"
#include "RigStatisticsCalculator.h"
#include "RiaDefines.h"
#include "RimSummaryCurve.h"
#include "RimPlotAxisProperties.h"
@ -319,86 +317,3 @@ std::string RimSummaryPlotYAxisFormatter::shortCalculationName(const std::string
return calculationShortName.toStdString();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimSummaryPlotYAxisRangeCalculator::RimSummaryPlotYAxisRangeCalculator(
const std::vector<QwtPlotCurve*>& qwtCurves,
const std::vector<double>& yValuesForAllCurves)
:
m_singleCurves(qwtCurves),
m_yValuesForAllCurves(yValuesForAllCurves)
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimSummaryPlotYAxisRangeCalculator::computeYRange(double* min, double* max) const
{
double minValue = HUGE_VAL;
double maxValue = -HUGE_VAL;
for (QwtPlotCurve* curve : m_singleCurves)
{
double minCurveValue = HUGE_VAL;
double maxCurveValue = -HUGE_VAL;
if (curveValueRangeY(curve, &minCurveValue, &maxCurveValue))
{
if (minCurveValue < minValue)
{
minValue = minCurveValue;
}
if (maxCurveValue > maxValue)
{
maxValue = maxCurveValue;
}
}
}
if (minValue == HUGE_VAL)
{
minValue = RiaDefines::minimumDefaultValuePlot();
maxValue = RiaDefines::maximumDefaultValuePlot();
}
// For logarithmic auto scaling, compute positive curve value closest to zero and use
// this value as the plot visible minimum
double pos = HUGE_VAL;
double neg = -HUGE_VAL;
RigStatisticsCalculator::posNegClosestToZero(m_yValuesForAllCurves, pos, neg);
if (pos != HUGE_VAL)
{
minValue = pos;
}
*min = minValue;
*max = maxValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimSummaryPlotYAxisRangeCalculator::curveValueRangeY(const QwtPlotCurve* qwtCurve, double* min, double* max) const
{
if (!qwtCurve) return false;
if (qwtCurve->data()->size() < 1)
{
return false;
}
*min = qwtCurve->minYValue();
*max = qwtCurve->maxYValue();
return true;
}

View File

@ -22,6 +22,8 @@
#include <vector>
#include <set>
#include <qwt_plot.h>
class RimAsciiDataCurve;
class RimSummaryCurve;
class RimPlotAxisProperties;
@ -52,20 +54,3 @@ private:
const std::set<QString> m_timeHistoryCurveQuantities;
};
class RimSummaryPlotYAxisRangeCalculator
{
public:
RimSummaryPlotYAxisRangeCalculator( const std::vector<QwtPlotCurve*>& qwtCurves,
const std::vector<double>& yValuesForAllCurves);
void computeYRange(double* min, double* max) const;
private:
bool curveValueRangeY(const QwtPlotCurve* qwtCurve, double* min, double* max) const;
private:
const std::vector<QwtPlotCurve*> m_singleCurves;
const std::vector<double> m_yValuesForAllCurves;
};

View File

@ -54,6 +54,7 @@
#include "qwt_plot_curve.h"
#include "qwt_plot_renderer.h"
#include "qwt_plot_textlabel.h"
#include "qwt_scale_engine.h"
#include <QDateTime>
#include <QString>
@ -659,8 +660,13 @@ void RimSummaryPlot::updateZoomForAxis(RiaDefines::PlotAxis plotAxis)
}
double min, max;
RimSummaryPlotYAxisRangeCalculator calc(plotCurves, yValues);
calc.computeYRange(&min, &max);
RimPlotAxisRangeCalculator calc(QwtPlot::yLeft, plotCurves, yValues);
calc.computeAxisRange(&min, &max);
if (yAxisProps->isAxisInverted())
{
std::swap(min, max);
}
m_qwtPlot->setAxisScale(yAxisProps->qwtPlotAxisType(), min, max);
}
@ -673,6 +679,8 @@ void RimSummaryPlot::updateZoomForAxis(RiaDefines::PlotAxis plotAxis)
{
m_qwtPlot->setAxisScale(yAxisProps->qwtPlotAxisType(), yAxisProps->visibleRangeMin(), yAxisProps->visibleRangeMax());
}
m_qwtPlot->axisScaleEngine(yAxisProps->qwtPlotAxisType())->setAttribute(QwtScaleEngine::Inverted, yAxisProps->isAxisInverted());
}
}