mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
3D Cross Plot: Improve colors and symbols in legend
This commit is contained in:
parent
6b3808b696
commit
7e57ec39ea
@ -17,6 +17,9 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "RiaColorTables.h"
|
#include "RiaColorTables.h"
|
||||||
|
#include "RiaColorTools.h"
|
||||||
|
|
||||||
|
#include "cvfAssert.h"
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
@ -538,6 +541,32 @@ RiaColorTables::WellPathComponentColors RiaColorTables::wellPathComponentColors(
|
|||||||
{RiaDefines::UNDEFINED_COMPONENT, cvf::Color3::MAGENTA}};
|
{RiaDefines::UNDEFINED_COMPONENT, cvf::Color3::MAGENTA}};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
caf::ColorTable RiaColorTables::createBrightnessBasedColorTable(cvf::Color3ub baseColor, int brightnessLevelCount)
|
||||||
|
{
|
||||||
|
CVF_ASSERT(brightnessLevelCount >= 1);
|
||||||
|
QColor baseRGB(baseColor.r(), baseColor.g(), baseColor.b());
|
||||||
|
float hueF = baseRGB.hslHueF();
|
||||||
|
float satF = baseRGB.hslSaturationF();
|
||||||
|
|
||||||
|
std::vector<cvf::Color3ub> colors;
|
||||||
|
if (brightnessLevelCount == 1)
|
||||||
|
{
|
||||||
|
colors.push_back(cvf::Color3ub(RiaColorTools::fromQColorTo3f(QColor::fromHslF(hueF, satF, 0.5))));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < brightnessLevelCount; ++i)
|
||||||
|
{
|
||||||
|
float brightness = static_cast<float>(i) / static_cast<float>(brightnessLevelCount - 1);
|
||||||
|
colors.push_back(cvf::Color3ub(RiaColorTools::fromQColorTo3f(QColor::fromHslF(hueF, satF, brightness))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return caf::ColorTable(colors);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -64,6 +64,7 @@ public:
|
|||||||
|
|
||||||
static WellPathComponentColors wellPathComponentColors();
|
static WellPathComponentColors wellPathComponentColors();
|
||||||
|
|
||||||
|
static caf::ColorTable createBrightnessBasedColorTable(cvf::Color3ub baseColor, int brightnessLevelCount);
|
||||||
private:
|
private:
|
||||||
static std::vector<cvf::Color3ub> categoryColors();
|
static std::vector<cvf::Color3ub> categoryColors();
|
||||||
static std::vector<cvf::Color3ub> contrastCategoryColors();
|
static std::vector<cvf::Color3ub> contrastCategoryColors();
|
||||||
|
@ -133,6 +133,14 @@ QColor RiaColorTools::toQColor(cvf::Color4f color)
|
|||||||
return toQColor(color.toColor3f(), color.a());
|
return toQColor(color.toColor3f(), color.a());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
cvf::Color3f RiaColorTools::fromQColorTo3f(QColor color)
|
||||||
|
{
|
||||||
|
return cvf::Color3f(color.redF(), color.greenF(), color.blueF());
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -41,6 +41,7 @@ public:
|
|||||||
static cvf::Color3f contrastColor(cvf::Color3f backgroundColor, bool softerContrast = false);
|
static cvf::Color3f contrastColor(cvf::Color3f backgroundColor, bool softerContrast = false);
|
||||||
static QColor toQColor(cvf::Color3f color, float alpha = 1.0f);
|
static QColor toQColor(cvf::Color3f color, float alpha = 1.0f);
|
||||||
static QColor toQColor(cvf::Color4f color);
|
static QColor toQColor(cvf::Color4f color);
|
||||||
|
static cvf::Color3f fromQColorTo3f(QColor);
|
||||||
static float contrastRatio(cvf::Color3f color1, cvf::Color3f color2);
|
static float contrastRatio(cvf::Color3f color1, cvf::Color3f color2);
|
||||||
private:
|
private:
|
||||||
static float relativeLuminance(cvf::Color3f backgroundColor);
|
static float relativeLuminance(cvf::Color3f backgroundColor);
|
||||||
|
@ -43,18 +43,30 @@ CAF_PDM_SOURCE_INIT(RimGridCrossPlotCurve, "GridCrossPlotCurve");
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RimGridCrossPlotCurve::determineColorAndSymbol(int curveSetIndex, int categoryIndex, bool contrastColors)
|
void RimGridCrossPlotCurve::determineColorAndSymbol(int curveSetIndex, int categoryIndex, int nCategories, bool contrastColors)
|
||||||
{
|
{
|
||||||
const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors();
|
if (contrastColors)
|
||||||
int colorIndex = categoryIndex + curveSetIndex; // Offset cycle for each curve set
|
{
|
||||||
setColor(colors.cycledColor3f(colorIndex));
|
const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors();
|
||||||
int numColors = (int) colors.size();
|
int colorIndex = categoryIndex + curveSetIndex; // Offset cycle for each curve set
|
||||||
|
setColor(colors.cycledColor3f(colorIndex));
|
||||||
|
int numColors = (int)colors.size();
|
||||||
|
|
||||||
// Retain same symbol until we've gone full cycle in colors
|
// Retain same symbol until we've gone full cycle in colors
|
||||||
int symbolIndex = categoryIndex / numColors;
|
int symbolIndex = categoryIndex / numColors;
|
||||||
|
|
||||||
RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledSymbolStyle(curveSetIndex, symbolIndex);
|
RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledSymbolStyle(curveSetIndex, symbolIndex);
|
||||||
setSymbol(symbol);
|
setSymbol(symbol);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const caf::ColorTable& colors = RiaColorTables::contrastCategoryPaletteColors();
|
||||||
|
cvf::Color3ub cycledBaseColor = colors.cycledColor3ub(curveSetIndex);
|
||||||
|
caf::ColorTable hueConstColTable = RiaColorTables::createBrightnessBasedColorTable(cycledBaseColor, nCategories);
|
||||||
|
setColor(hueConstColTable.cycledColor3f(categoryIndex));
|
||||||
|
RiuQwtSymbol::PointSymbolEnum symbol = RiuQwtSymbol::cycledFilledSymbolStyle(curveSetIndex);
|
||||||
|
setSymbol(symbol);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -65,6 +77,8 @@ RimGridCrossPlotCurve::RimGridCrossPlotCurve()
|
|||||||
CAF_PDM_InitObject("Cross Plot Points", ":/WellLogCurve16x16.png", "", "");
|
CAF_PDM_InitObject("Cross Plot Points", ":/WellLogCurve16x16.png", "", "");
|
||||||
|
|
||||||
setLineStyle(RiuQwtPlotCurve::STYLE_NONE);
|
setLineStyle(RiuQwtPlotCurve::STYLE_NONE);
|
||||||
|
setLineThickness(0);
|
||||||
|
setSymbol(RiuQwtSymbol::SYMBOL_NONE);
|
||||||
setSymbolSize(6);
|
setSymbolSize(6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class RimGridCrossPlotCurve : public RimPlotCurve
|
|||||||
public:
|
public:
|
||||||
RimGridCrossPlotCurve();
|
RimGridCrossPlotCurve();
|
||||||
~RimGridCrossPlotCurve() override = default;
|
~RimGridCrossPlotCurve() override = default;
|
||||||
void determineColorAndSymbol(int curveSetIndex, int categoryIndex, bool contrastColors = false);
|
void determineColorAndSymbol(int curveSetIndex, int categoryIndex, int nCategories, bool contrastColors = false);
|
||||||
void setSamples(const QVector<QPointF>& samples);
|
void setSamples(const QVector<QPointF>& samples);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -154,6 +154,17 @@ QString RimGridCrossPlotCurveSet::createAutoName() const
|
|||||||
return nameTags.join(", ");
|
return nameTags.join(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void RimGridCrossPlotCurveSet::detachAllCurves()
|
||||||
|
{
|
||||||
|
for (auto curve : m_crossPlotCurves())
|
||||||
|
{
|
||||||
|
curve->detachQwtCurve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -173,7 +184,8 @@ void RimGridCrossPlotCurveSet::initAfterRead()
|
|||||||
void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
||||||
{
|
{
|
||||||
performAutoNameUpdate();
|
performAutoNameUpdate();
|
||||||
|
|
||||||
|
detachAllCurves();
|
||||||
m_crossPlotCurves.deleteAllChildObjects();
|
m_crossPlotCurves.deleteAllChildObjects();
|
||||||
|
|
||||||
std::map<int, QVector<QPointF>> samples;
|
std::map<int, QVector<QPointF>> samples;
|
||||||
@ -269,7 +281,7 @@ void RimGridCrossPlotCurveSet::onLoadDataAndUpdate(bool updateParentPlot)
|
|||||||
{
|
{
|
||||||
curve->setCustomName(QString("%1 : %2").arg(createAutoName()).arg(timeStepName));
|
curve->setCustomName(QString("%1 : %2").arg(createAutoName()).arg(timeStepName));
|
||||||
}
|
}
|
||||||
curve->determineColorAndSymbol(curveSetIndex, sampleCategory.first);
|
curve->determineColorAndSymbol(curveSetIndex, sampleCategory.first, (int) samples.size(), false);
|
||||||
curve->setSamples(sampleCategory.second);
|
curve->setSamples(sampleCategory.second);
|
||||||
curve->updateCurveAppearance();
|
curve->updateCurveAppearance();
|
||||||
curve->updateCurveNameAndUpdatePlotLegendAndTitle();
|
curve->updateCurveNameAndUpdatePlotLegendAndTitle();
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
int indexInPlot() const;
|
int indexInPlot() const;
|
||||||
QString createAutoName() const override;
|
QString createAutoName() const override;
|
||||||
|
void detachAllCurves();
|
||||||
protected:
|
protected:
|
||||||
void initAfterRead() override;
|
void initAfterRead() override;
|
||||||
void onLoadDataAndUpdate(bool updateParentPlot);
|
void onLoadDataAndUpdate(bool updateParentPlot);
|
||||||
|
@ -164,7 +164,7 @@ RiuQwtSymbol::PointSymbolEnum RiuQwtSymbol::cycledSymbolStyle(int indexLevel1, i
|
|||||||
std::vector<std::vector<PointSymbolEnum>> categorisedStyles =
|
std::vector<std::vector<PointSymbolEnum>> categorisedStyles =
|
||||||
{
|
{
|
||||||
{SYMBOL_ELLIPSE, SYMBOL_RECT, SYMBOL_DIAMOND},
|
{SYMBOL_ELLIPSE, SYMBOL_RECT, SYMBOL_DIAMOND},
|
||||||
{SYMBOL_TRIANGLE, SYMBOL_DOWN_TRIANGLE, SYMBOL_UP_TRIANGLE},
|
{SYMBOL_DOWN_TRIANGLE, SYMBOL_UP_TRIANGLE},
|
||||||
{SYMBOL_LEFT_TRIANGLE, SYMBOL_RIGHT_TRIANGLE},
|
{SYMBOL_LEFT_TRIANGLE, SYMBOL_RIGHT_TRIANGLE},
|
||||||
{SYMBOL_LEFT_ANGLED_TRIANGLE, SYMBOL_RIGHT_ANGLED_TRIANGLE},
|
{SYMBOL_LEFT_ANGLED_TRIANGLE, SYMBOL_RIGHT_ANGLED_TRIANGLE},
|
||||||
{SYMBOL_CROSS, SYMBOL_XCROSS},
|
{SYMBOL_CROSS, SYMBOL_XCROSS},
|
||||||
@ -177,6 +177,18 @@ RiuQwtSymbol::PointSymbolEnum RiuQwtSymbol::cycledSymbolStyle(int indexLevel1, i
|
|||||||
return categorisedStyles[level1Category][level2Category];
|
return categorisedStyles[level1Category][level2Category];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
RiuQwtSymbol::PointSymbolEnum RiuQwtSymbol::cycledFilledSymbolStyle(int indexLevel)
|
||||||
|
{
|
||||||
|
std::vector<PointSymbolEnum> contrastingSymbols =
|
||||||
|
{
|
||||||
|
SYMBOL_ELLIPSE, SYMBOL_RECT };
|
||||||
|
|
||||||
|
return contrastingSymbols[indexLevel % (int)contrastingSymbols.size()];
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
@ -66,6 +66,7 @@ public:
|
|||||||
void setLabelPosition(LabelPosition labelPosition);
|
void setLabelPosition(LabelPosition labelPosition);
|
||||||
|
|
||||||
static PointSymbolEnum cycledSymbolStyle(int indexLevel1, int indexLevel2);
|
static PointSymbolEnum cycledSymbolStyle(int indexLevel1, int indexLevel2);
|
||||||
|
static PointSymbolEnum cycledFilledSymbolStyle(int indexLevel);
|
||||||
private:
|
private:
|
||||||
QRect labelBoundingRect(const QPainter* painter, const QRect& symbolRect) const;
|
QRect labelBoundingRect(const QPainter* painter, const QRect& symbolRect) const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user