mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#6252 Category Colors : Name and corresponding color do not match
Set category data directly to the category mapper with no reverse ordering When drawing the color legend, always draw categories with lower index first
This commit is contained in:
@@ -995,7 +995,7 @@ void RimGridCrossPlotDataSet::updateLegendRange()
|
||||
const std::vector<QString> categoryNames = eclipseCase->eclipseCaseData()->formationNames();
|
||||
if ( !categoryNames.empty() )
|
||||
{
|
||||
legendConfig()->setNamedCategoriesInverse( categoryNames );
|
||||
legendConfig()->setNamedCategories( categoryNames );
|
||||
legendConfig()->setAutomaticRanges( 0, categoryNames.size() - 1, 0, categoryNames.size() - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1887,13 +1887,13 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
|
||||
++tracerIndex;
|
||||
}
|
||||
|
||||
std::vector<std::tuple<QString, int, cvf::Color3ub>> reverseCategories;
|
||||
for ( auto tupIt = categories.rbegin(); tupIt != categories.rend(); ++tupIt )
|
||||
std::vector<std::tuple<QString, int, cvf::Color3ub>> categoryVector;
|
||||
for ( auto tupIt : categories )
|
||||
{
|
||||
reverseCategories.push_back( *tupIt );
|
||||
categoryVector.push_back( tupIt );
|
||||
}
|
||||
|
||||
legendConfigToUpdate->setCategoryItems( reverseCategories );
|
||||
legendConfigToUpdate->setCategoryItems( categoryVector );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1950,7 +1950,7 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
|
||||
if ( this->resultType() == RiaDefines::ResultCatType::FORMATION_NAMES )
|
||||
{
|
||||
std::vector<QString> fnVector = eclipseCaseData->formationNames();
|
||||
legendConfigToUpdate->setNamedCategoriesInverse( fnVector );
|
||||
legendConfigToUpdate->setNamedCategories( fnVector );
|
||||
}
|
||||
else if ( this->resultType() == RiaDefines::ResultCatType::ALLAN_DIAGRAMS )
|
||||
{
|
||||
@@ -1958,8 +1958,10 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
|
||||
{
|
||||
const std::vector<QString> fnVector = eclipseCaseData->formationNames();
|
||||
std::vector<int> fnameIdxes;
|
||||
for ( int i = static_cast<int>( fnVector.size() ); i > 0; --i )
|
||||
fnameIdxes.push_back( i - 1 );
|
||||
for ( int i = 0; i < static_cast<int>( fnVector.size() ); i++ )
|
||||
{
|
||||
fnameIdxes.push_back( i );
|
||||
}
|
||||
|
||||
cvf::Color3ubArray legendBaseColors = RiaColorTables::categoryPaletteColors().color3ubArray();
|
||||
|
||||
@@ -1967,7 +1969,7 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
|
||||
formationColorMapper->setCategories( fnameIdxes );
|
||||
formationColorMapper->setInterpolateColors( legendBaseColors );
|
||||
|
||||
const std::map<std::pair<int, int>, int>& formationCombToCathegory =
|
||||
const std::map<std::pair<int, int>, int>& formationCombToCategory =
|
||||
eclipseCaseData->allanDiagramData()->formationCombinationToCategory();
|
||||
|
||||
std::vector<std::tuple<QString, int, cvf::Color3ub>> categories;
|
||||
@@ -1977,11 +1979,11 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
|
||||
categories.emplace_back( std::make_tuple( fnVector[frmNameIdx], frmNameIdx, formationColor ) );
|
||||
}
|
||||
|
||||
for ( auto it = formationCombToCathegory.rbegin(); it != formationCombToCathegory.rend(); ++it )
|
||||
for ( auto it : formationCombToCategory )
|
||||
{
|
||||
int frmIdx1 = it->first.first;
|
||||
int frmIdx2 = it->first.second;
|
||||
int combIndex = it->second;
|
||||
int frmIdx1 = it.first.first;
|
||||
int frmIdx2 = it.first.second;
|
||||
int combIndex = it.second;
|
||||
|
||||
int fnVectorSize = static_cast<int>( fnVector.size() );
|
||||
if ( frmIdx1 >= fnVectorSize || frmIdx2 >= fnVectorSize ) continue;
|
||||
|
||||
@@ -1363,7 +1363,7 @@ void RimEclipseView::onUpdateLegends()
|
||||
else
|
||||
{
|
||||
const std::vector<QString> fnVector = eclipseCase->formationNames();
|
||||
cellEdgeResult()->legendConfig()->setNamedCategoriesInverse( fnVector );
|
||||
cellEdgeResult()->legendConfig()->setNamedCategories( fnVector );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -971,7 +971,7 @@ void RimGeoMechResultDefinition::updateLegendTextAndRanges( RimRegularLegendConf
|
||||
if ( this->hasCategoryResult() )
|
||||
{
|
||||
std::vector<QString> fnVector = gmCase->femPartResults()->formationNames();
|
||||
legendConfigToUpdate->setNamedCategoriesInverse( fnVector );
|
||||
legendConfigToUpdate->setNamedCategories( fnVector );
|
||||
}
|
||||
|
||||
QString legendTitle = legendHeading + caf::AppEnum<RigFemResultPosEnum>( this->resultPositionType() ).uiText() +
|
||||
|
||||
@@ -214,7 +214,7 @@ RimRegularLegendConfig::~RimRegularLegendConfig()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setNamedCategories( const std::vector<QString>& categoryNames, bool inverse )
|
||||
void RimRegularLegendConfig::setNamedCategories( const std::vector<QString>& categoryNames )
|
||||
{
|
||||
std::list<int> nameIndices;
|
||||
std::list<cvf::String> names;
|
||||
@@ -222,16 +222,8 @@ void RimRegularLegendConfig::setNamedCategories( const std::vector<QString>& cat
|
||||
int categoriesCount = static_cast<int>( categoryNames.size() );
|
||||
for ( int i = 0; i < categoriesCount; i++ )
|
||||
{
|
||||
if ( !inverse )
|
||||
{
|
||||
nameIndices.push_back( i );
|
||||
names.push_back( cvfqt::Utils::toString( categoryNames[i] ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
nameIndices.push_front( i );
|
||||
names.push_front( cvfqt::Utils::toString( categoryNames[i] ) );
|
||||
}
|
||||
nameIndices.push_back( i );
|
||||
names.push_back( cvfqt::Utils::toString( categoryNames[i] ) );
|
||||
}
|
||||
|
||||
m_categories = std::vector<int>( nameIndices.begin(), nameIndices.end() );
|
||||
@@ -766,22 +758,6 @@ void RimRegularLegendConfig::setIntegerCategories( const std::vector<int>& categ
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setNamedCategories( const std::vector<QString>& categoryNames )
|
||||
{
|
||||
setNamedCategories( categoryNames, false );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setNamedCategoriesInverse( const std::vector<QString>& categoryNames )
|
||||
{
|
||||
setNamedCategories( categoryNames, true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -129,7 +129,6 @@ public:
|
||||
|
||||
void setIntegerCategories( const std::vector<int>& categories );
|
||||
void setNamedCategories( const std::vector<QString>& categoryNames );
|
||||
void setNamedCategoriesInverse( const std::vector<QString>& categoryNames );
|
||||
void setCategoryItems( const std::vector<std::tuple<QString, int, cvf::Color3ub>>& categories );
|
||||
QString categoryNameFromCategoryValue( double categoryResultValue ) const;
|
||||
double categoryValueFromCategoryName( const QString& categoryName ) const;
|
||||
@@ -154,7 +153,6 @@ public:
|
||||
void updateFonts() override;
|
||||
|
||||
private:
|
||||
void setNamedCategories( const std::vector<QString>& categoryNames, bool inverse );
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
void initAfterRead() override;
|
||||
caf::PdmFieldHandle* objectToggleField() override;
|
||||
|
||||
@@ -217,7 +217,8 @@ void CategoryLegend::setupTextDrawer( TextDrawer* textDrawer, const OverlayColor
|
||||
}
|
||||
}
|
||||
|
||||
String displayText = m_categoryMapper->textForCategoryIndex( it );
|
||||
size_t inverseIndex = numLabels - 1 - it;
|
||||
String displayText = m_categoryMapper->textForCategoryIndex( inverseIndex );
|
||||
|
||||
Vec2f pos( textX, textY );
|
||||
textDrawer->addText( displayText, pos );
|
||||
@@ -292,10 +293,11 @@ void CategoryLegend::renderLegendUsingShaders( OpenGLContext* ogl
|
||||
int iPx;
|
||||
for ( iPx = 0; iPx < legendHeightPixelCount; iPx++ )
|
||||
{
|
||||
const Color3ub& clr =
|
||||
m_categoryMapper->mapToColor( m_categoryMapper->domainValue( ( iPx + 0.5 ) / legendHeightPixelCount ) );
|
||||
float y0 = static_cast<float>( layout->colorBarRect.min().y() + iPx );
|
||||
float y1 = static_cast<float>( layout->colorBarRect.min().y() + iPx + 1 );
|
||||
double normalizedValue = ( iPx + 0.5 ) / legendHeightPixelCount;
|
||||
double invertedNormalizedValue = 1.0 - normalizedValue;
|
||||
const Color3ub& clr = m_categoryMapper->mapToColor( m_categoryMapper->domainValue( invertedNormalizedValue ) );
|
||||
float y0 = static_cast<float>( layout->colorBarRect.min().y() + iPx );
|
||||
float y1 = static_cast<float>( layout->colorBarRect.min().y() + iPx + 1 );
|
||||
|
||||
// Dynamic coordinates for rectangle
|
||||
v0[1] = v1[1] = y0;
|
||||
@@ -409,8 +411,9 @@ void CategoryLegend::renderLegendImmediateMode( OpenGLContext* oglContext, Overl
|
||||
int iPx;
|
||||
for ( iPx = 0; iPx < legendHeightPixelCount; iPx++ )
|
||||
{
|
||||
const Color3ub& clr =
|
||||
m_categoryMapper->mapToColor( m_categoryMapper->domainValue( ( iPx + 0.5 ) / legendHeightPixelCount ) );
|
||||
double normalizedValue = ( iPx + 0.5 ) / legendHeightPixelCount;
|
||||
double invertedNormalizedValue = 1.0 - normalizedValue;
|
||||
const Color3ub& clr = m_categoryMapper->mapToColor( m_categoryMapper->domainValue( invertedNormalizedValue ) );
|
||||
float y0 = static_cast<float>( layout->colorBarRect.min().y() + iPx );
|
||||
float y1 = static_cast<float>( layout->colorBarRect.min().y() + iPx + 1 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user