mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
Legend: Added tick number formatting control
Auto, Fixed and Scientific. Fixed and Scientific respects the precision set. p4#: 21504
This commit is contained in:
parent
60f86cfc3f
commit
be0a2ec728
@ -65,6 +65,16 @@ namespace caf {
|
||||
}
|
||||
}
|
||||
|
||||
namespace caf {
|
||||
template<>
|
||||
void AppEnum<RimLegendConfig::NumberFormatType>::setUp()
|
||||
{
|
||||
addItem( RimLegendConfig::AUTO, "AUTO", "Automatic");
|
||||
addItem( RimLegendConfig::FIXED, "FIXED", "Fixed, decimal");
|
||||
addItem( RimLegendConfig::SCIENTIFIC, "SCIENTIFIC", "Scientific notation");
|
||||
setDefault(RimLegendConfig::FIXED);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -78,6 +88,8 @@ RimLegendConfig::RimLegendConfig()
|
||||
CAF_PDM_InitObject("Legend Definition", ":/Legend.png", "", "");
|
||||
CAF_PDM_InitField(&m_numLevels, "NumberOfLevels", 8, "Number of levels", "", "","");
|
||||
CAF_PDM_InitField(&m_precision, "Precision", 2, "Precision", "", "","");
|
||||
CAF_PDM_InitField(&m_tickNumberFormat, "TickNumberFormat", caf::AppEnum<RimLegendConfig::NumberFormatType>(FIXED), "Precision", "", "","");
|
||||
|
||||
CAF_PDM_InitField(&m_colorRangeMode, "ColorRangeMode", ColorRangeEnum(NORMAL) , "Color range", "", "", "");
|
||||
CAF_PDM_InitField(&m_mappingMode, "MappingMode", MappingEnum(LINEAR_CONTINUOUS) , "Mapping", "", "", "");
|
||||
CAF_PDM_InitField(&m_rangeMode, "RangeType", caf::AppEnum<RimLegendConfig::RangeModeType>(AUTOMATIC_ALLTIMESTEPS), "Legend range type", "", "Switches between automatic and user defined range on the legend", "");
|
||||
@ -260,6 +272,10 @@ void RimLegendConfig::updateLegend()
|
||||
}
|
||||
|
||||
m_legend->setScalarMapper(m_currentScalarMapper.p());
|
||||
m_legend->setTickPrecision(m_precision());
|
||||
|
||||
NumberFormatType nft = m_tickNumberFormat();
|
||||
m_legend->setTickFormat((cvf::OverlayScalarMapperLegend::NumberFormat)nft);
|
||||
|
||||
|
||||
if (m_globalAutoMax != cvf::UNDEFINED_DOUBLE )
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
LOG10_CONTINUOUS,
|
||||
LOG10_DISCRETE
|
||||
};
|
||||
enum NumberFormatType { AUTO, SCIENTIFIC, FIXED};
|
||||
|
||||
typedef caf::AppEnum<MappingType> MappingEnum;
|
||||
void recreateLegend();
|
||||
@ -109,6 +110,7 @@ private:
|
||||
// Fields
|
||||
caf::PdmField<int> m_numLevels;
|
||||
caf::PdmField<int> m_precision;
|
||||
caf::PdmField<caf::AppEnum<NumberFormatType> > m_tickNumberFormat;
|
||||
caf::PdmField<caf::AppEnum<RangeModeType> > m_rangeMode;
|
||||
caf::PdmField<double> m_userDefinedMaxValue;
|
||||
caf::PdmField<double> m_userDefinedMinValue;
|
||||
|
@ -64,7 +64,9 @@ OverlayScalarMapperLegend::OverlayScalarMapperLegend(Font* font)
|
||||
m_color(Color3::BLACK),
|
||||
m_lineColor(Color3::BLACK),
|
||||
m_lineWidth(1),
|
||||
m_font(font)
|
||||
m_font(font),
|
||||
m_tickNumberPrecision(4),
|
||||
m_numberFormat(AUTO)
|
||||
{
|
||||
CVF_ASSERT(font);
|
||||
CVF_ASSERT(!font->isEmpty());
|
||||
@ -326,7 +328,20 @@ void OverlayScalarMapperLegend::setupTextDrawer(TextDrawer* textDrawer, OverlayC
|
||||
}
|
||||
|
||||
double tickValue = m_tickValues[it];
|
||||
String valueString = String::number(tickValue);
|
||||
String valueString;
|
||||
switch (m_numberFormat)
|
||||
{
|
||||
case FIXED:
|
||||
valueString = String::number(tickValue, 'f', m_tickNumberPrecision);
|
||||
break;
|
||||
case SCIENTIFIC:
|
||||
valueString = String::number(tickValue, 'e', m_tickNumberPrecision);
|
||||
break;
|
||||
default:
|
||||
valueString = String::number(tickValue);
|
||||
break;
|
||||
}
|
||||
|
||||
Vec2f pos(textX, textY);
|
||||
textDrawer->addText(valueString, pos);
|
||||
|
||||
@ -733,5 +748,21 @@ int OverlayScalarMapperLegend::lineWidth() const
|
||||
return m_lineWidth;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScalarMapperLegend::setTickPrecision(int precision)
|
||||
{
|
||||
m_tickNumberPrecision = precision;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void OverlayScalarMapperLegend::setTickFormat(NumberFormat format)
|
||||
{
|
||||
m_numberFormat = format;
|
||||
}
|
||||
|
||||
} // namespace cvf
|
||||
|
||||
|
@ -64,6 +64,9 @@ public:
|
||||
const Color3f& lineColor() const;
|
||||
void setLineWidth(int lineWidth);
|
||||
int lineWidth() const;
|
||||
void setTickPrecision(int precision);
|
||||
enum NumberFormat { AUTO, SCIENTIFIC, FIXED};
|
||||
void setTickFormat(NumberFormat format);
|
||||
|
||||
void setTitle(const String& title);
|
||||
String title() const;
|
||||
@ -116,6 +119,8 @@ protected:
|
||||
int m_lineWidth;
|
||||
std::vector<String> m_titleStrings;
|
||||
ref<Font> m_font;
|
||||
int m_tickNumberPrecision;
|
||||
NumberFormat m_numberFormat;
|
||||
|
||||
cref<ScalarMapper> m_scalarMapper;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user