diff --git a/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.cpp b/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.cpp index bbd5dc2f7f..f46a8fed1b 100644 --- a/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.cpp +++ b/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.cpp @@ -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 #include @@ -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& 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 dateTimes; + dateTimes.push_back(dateTime); + dateTimes.push_back(dateTime); + + std::vector timeHistoryValues; + timeHistoryValues.push_back(timeHistoryValue); + timeHistoryValues.push_back(timeHistoryValue); + + curve->setSamplesFromDateAndValues(dateTimes, timeHistoryValues, false); +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.h b/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.h index 0520c18a48..67797a1d9d 100644 --- a/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.h +++ b/ApplicationCode/UserInterface/RiuFlowCharacteristicsPlot.h @@ -70,6 +70,8 @@ protected: private: void setDefaults(); void initializeColors(const std::vector& dateTimes); + + static void addCurveWithLargeSymbol(QwtPlot* plot, const QString& curveName, const QColor& color, const QDateTime& dateTime, double timeHistoryValue); private: caf::PdmPointer m_plotDefinition;