#1469 Add large symbols for each value in Lorenz plot + legend

This commit is contained in:
Magne Sjaastad 2017-05-11 14:04:29 +02:00
parent 0c0c21e495
commit 764a68c032
2 changed files with 42 additions and 15 deletions

View File

@ -32,9 +32,10 @@
#include "cvfColor3.h"
#include "qwt_date.h"
#include "qwt_legend.h"
#include "qwt_plot.h"
#include "qwt_plot_zoneitem.h"
#include "qwt_plot_zoomer.h"
#include "qwt_symbol.h"
#include <QBoxLayout>
#include <QContextMenuEvent>
@ -64,6 +65,9 @@ RiuFlowCharacteristicsPlot::RiuFlowCharacteristicsPlot(RimFlowCharacteristicsPlo
this->setPalette(pal);
m_lorenzPlot = new QwtPlot(this);
QwtLegend* legend = new QwtLegend(this);
m_lorenzPlot->insertLegend(legend, QwtPlot::BottomLegend);
m_flowCapVsStorageCapPlot = new QwtPlot(this);
m_sweepEffPlot = new QwtPlot(this);
@ -118,29 +122,50 @@ void RiuFlowCharacteristicsPlot::setLorenzCurve(const std::vector<QDateTime>& da
initializeColors(dateTimes);
m_lorenzPlot->detachItems(QwtPlotItem::Rtti_PlotCurve, true);
auto curve = createEmptyCurve(m_lorenzPlot, "Lorenz Coefficient", QColor(0, 0, 0));
curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
for ( size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx )
for (size_t tsIdx = 0; tsIdx < dateTimes.size(); ++tsIdx)
{
double currentTsValue = QwtDate::toDouble(dateTimes[tsIdx]);
if (timeHistoryValues[tsIdx] == HUGE_VAL) continue;
double minTsValue = currentTsValue;
if ( tsIdx > 0 ) minTsValue = 0.5 * (currentTsValue + QwtDate::toDouble(dateTimes[tsIdx-1]));
double maxTsValue = currentTsValue;
if ( tsIdx < dateTimes.size()-1 ) maxTsValue = 0.5 * (currentTsValue + QwtDate::toDouble(dateTimes[tsIdx+1]));
QDateTime dateTime = dateTimes[tsIdx];
double timeHistoryValue = timeHistoryValues[tsIdx];
auto plotZone = new QwtPlotZoneItem();
plotZone->setOrientation(Qt::Vertical);
plotZone->setInterval(minTsValue, maxTsValue);
plotZone->setBrush(QBrush(m_dateToColorMap[dateTimes[tsIdx]]));
plotZone->attach(m_lorenzPlot);
QString curveName = dateTime.toString();
RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(m_lorenzPlot, curveName, m_dateToColorMap[dateTime], dateTime, timeHistoryValue);
}
m_lorenzPlot->replot();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiuFlowCharacteristicsPlot::addCurveWithLargeSymbol(QwtPlot* plot, const QString& curveName, const QColor& color, const QDateTime& dateTime, double timeHistoryValue)
{
auto curve = createEmptyCurve(plot, curveName, color);
QwtSymbol::Style style = QwtSymbol::Diamond;
QwtSymbol* symbol = new QwtSymbol(style);
symbol->setSize(20, 20);
symbol->setColor(color);
curve->setSymbol(symbol);
// Add date and value twice to avoid a cross as symbol generated by RiuLineSegmentQwtPlotCurve
std::vector<QDateTime> dateTimes;
dateTimes.push_back(dateTime);
dateTimes.push_back(dateTime);
std::vector<double> timeHistoryValues;
timeHistoryValues.push_back(timeHistoryValue);
timeHistoryValues.push_back(timeHistoryValue);
curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false);
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -70,6 +70,8 @@ protected:
private:
void setDefaults();
void initializeColors(const std::vector<QDateTime>& dateTimes);
static void addCurveWithLargeSymbol(QwtPlot* plot, const QString& curveName, const QColor& color, const QDateTime& dateTime, double timeHistoryValue);
private:
caf::PdmPointer<RimFlowCharacteristicsPlot> m_plotDefinition;