mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
This commit is contained in:
parent
09c09a7386
commit
ca91409002
@ -21,6 +21,10 @@
|
||||
#include "RimSummaryPlot.h"
|
||||
#include "RiaDefines.h"
|
||||
|
||||
#include "cafPdmUiSliderEditor.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -72,6 +76,11 @@ RimSummaryAxisProperties::RimSummaryAxisProperties()
|
||||
CAF_PDM_InitField(&visibleRangeMin, "VisibleRangeMin", RiaDefines::minimumDefaultValuePlot(), "Min", "", "", "");
|
||||
|
||||
CAF_PDM_InitFieldNoDefault(&numberFormat, "NumberFormat", "Number Format", "", "", "");
|
||||
CAF_PDM_InitField(&numberOfDecimals, "Decimals", 2, "Number of Decimals", "", "", "");
|
||||
CAF_PDM_InitField(&scaleFactor, "ScaleFactor", 1.0, "Scale Factor", "", "", "");
|
||||
|
||||
numberOfDecimals.uiCapability()->setUiEditorTypeName(caf::PdmUiSliderEditor::uiEditorTypeName());
|
||||
|
||||
|
||||
CAF_PDM_InitField(&isLogarithmicScaleEnabled, "LogarithmicScale", false, "Logarithmic Scale", "", "", "");
|
||||
|
||||
@ -109,6 +118,18 @@ QList<caf::PdmOptionItemInfo> RimSummaryAxisProperties::calculateValueOptions(co
|
||||
options.push_back(caf::PdmOptionItemInfo(text, value));
|
||||
}
|
||||
}
|
||||
else if (fieldNeedingOptions == &scaleFactor)
|
||||
{
|
||||
for (int exp = -12; exp <= 12; exp += 3)
|
||||
{
|
||||
QString uiText =
|
||||
exp == 0 ? "1" :
|
||||
QString("10 ^ %1").arg(exp);
|
||||
double value = std::pow(10, exp);
|
||||
|
||||
options.push_back(caf::PdmOptionItemInfo(uiText, value));
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
@ -127,9 +148,17 @@ void RimSummaryAxisProperties::defineUiOrdering(QString uiConfigName, caf::PdmUi
|
||||
caf::PdmUiGroup& scaleGroup = *(uiOrdering.addNewGroup("Axis Values"));
|
||||
scaleGroup.add(&isLogarithmicScaleEnabled);
|
||||
scaleGroup.add(&numberFormat);
|
||||
|
||||
if (numberFormat() != NUMBER_FORMAT_AUTO)
|
||||
{
|
||||
scaleGroup.add(&numberOfDecimals);
|
||||
scaleGroup.add(&scaleFactor);
|
||||
}
|
||||
|
||||
scaleGroup.add(&visibleRangeMin);
|
||||
scaleGroup.add(&visibleRangeMax);
|
||||
|
||||
uiOrdering.skipRemainingFields(true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -70,6 +70,8 @@ public:
|
||||
caf::PdmField<double> visibleRangeMax;
|
||||
|
||||
caf::PdmField< caf::AppEnum< NumberFormatType > > numberFormat;
|
||||
caf::PdmField<int> numberOfDecimals;
|
||||
caf::PdmField<double> scaleFactor;
|
||||
|
||||
caf::PdmField<bool> isLogarithmicScaleEnabled;
|
||||
|
||||
|
@ -46,51 +46,58 @@
|
||||
class DecimalScaleDraw : public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
DecimalScaleDraw(double scaleFactor, int numberOfDecimals)
|
||||
{
|
||||
m_scaleFactor = scaleFactor;
|
||||
m_numberOfDecimals = numberOfDecimals;
|
||||
}
|
||||
|
||||
virtual QwtText label(double value) const override
|
||||
{
|
||||
if (qFuzzyCompare(value + 1.0, 1.0))
|
||||
if (qFuzzyCompare(scaledValue(value) + 1.0, 1.0))
|
||||
value = 0.0;
|
||||
|
||||
int precision = DecimalScaleDraw::calculatePrecision(value);
|
||||
|
||||
return QString::number(value, 'f', precision);
|
||||
return QString::number(scaledValue(value), 'f', m_numberOfDecimals);
|
||||
}
|
||||
|
||||
private:
|
||||
static int calculatePrecision(double value)
|
||||
double scaledValue(double value) const
|
||||
{
|
||||
double absVal = fabs(value);
|
||||
|
||||
const int numberOfDigits = 2;
|
||||
|
||||
if (1e-16 < absVal && absVal < 1.0e3)
|
||||
{
|
||||
int logVal = static_cast<int>(log10(absVal));
|
||||
int numDigitsAfterPoint = abs(logVal - numberOfDigits);
|
||||
return numDigitsAfterPoint;
|
||||
}
|
||||
else
|
||||
{
|
||||
return numberOfDigits;
|
||||
}
|
||||
return value / m_scaleFactor;
|
||||
}
|
||||
};
|
||||
|
||||
double m_scaleFactor;
|
||||
int m_numberOfDecimals;
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class ScientificScaleDraw : public QwtScaleDraw
|
||||
{
|
||||
|
||||
public:
|
||||
ScientificScaleDraw(double scaleFactor, int numberOfDecimals)
|
||||
{
|
||||
m_scaleFactor = scaleFactor;
|
||||
m_numberOfDecimals = numberOfDecimals;
|
||||
}
|
||||
|
||||
virtual QwtText label(double value) const override
|
||||
{
|
||||
if (qFuzzyCompare(value + 1.0, 1.0))
|
||||
if (qFuzzyCompare(scaledValue(value) + 1.0, 1.0))
|
||||
value = 0.0;
|
||||
|
||||
return QString::number(value, 'e', 2);
|
||||
return QString::number(scaledValue(value), 'e', m_numberOfDecimals);
|
||||
}
|
||||
|
||||
private:
|
||||
double scaledValue(double value) const
|
||||
{
|
||||
return value / m_scaleFactor;
|
||||
}
|
||||
|
||||
double m_scaleFactor;
|
||||
int m_numberOfDecimals;
|
||||
};
|
||||
|
||||
|
||||
@ -108,7 +115,6 @@ RimSummaryPlotYAxisFormatter::RimSummaryPlotYAxisFormatter(RimSummaryAxisPropert
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -156,13 +162,14 @@ void RimSummaryPlotYAxisFormatter::applyYAxisPropertiesToPlot(RiuSummaryQwtPlot*
|
||||
}
|
||||
else if (m_axisProperties->numberFormat == RimSummaryAxisProperties::NUMBER_FORMAT_DECIMAL)
|
||||
{
|
||||
qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new DecimalScaleDraw);
|
||||
qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(),
|
||||
new DecimalScaleDraw(m_axisProperties->scaleFactor(), m_axisProperties->numberOfDecimals()));
|
||||
}
|
||||
else if (m_axisProperties->numberFormat == RimSummaryAxisProperties::NUMBER_FORMAT_SCIENTIFIC)
|
||||
{
|
||||
qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(), new ScientificScaleDraw());
|
||||
qwtPlot->setAxisScaleDraw(m_axisProperties->qwtPlotAxisType(),
|
||||
new ScientificScaleDraw(m_axisProperties->scaleFactor(), m_axisProperties->numberOfDecimals()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
@ -214,6 +221,17 @@ QString RimSummaryPlotYAxisFormatter::autoAxisTitle() const
|
||||
}
|
||||
|
||||
QString assembledYAxisText;
|
||||
QString scaleFactorText = "";
|
||||
|
||||
if (m_axisProperties->numberFormat() != RimSummaryAxisProperties::NUMBER_FORMAT_AUTO)
|
||||
{
|
||||
if (m_axisProperties->scaleFactor() != 1.0)
|
||||
{
|
||||
int exponent = std::log10(m_axisProperties->scaleFactor());
|
||||
scaleFactorText = QString(" x 10<sup>%1</sup> ").arg(QString::number(exponent));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for ( auto unitIt : unitToQuantityNameMap )
|
||||
{
|
||||
@ -221,7 +239,7 @@ QString RimSummaryPlotYAxisFormatter::autoAxisTitle() const
|
||||
{
|
||||
assembledYAxisText += QString::fromStdString(quantIt) + " ";
|
||||
}
|
||||
assembledYAxisText += "[" + QString::fromStdString(unitIt.first) + "] ";
|
||||
assembledYAxisText += "[" + QString::fromStdString(unitIt.first) + scaleFactorText + "] ";
|
||||
}
|
||||
|
||||
if (m_timeHistoryCurveQuantities.size() > 0)
|
||||
|
Loading…
Reference in New Issue
Block a user