Commit 677db865c0f1815c4a644dac933d2339a8ae7400

Authored by Benjamin Renard
1 parent 7f62f27f

Draw intervals on a time plot

config/xsd/info/paramInfo.xsd
... ... @@ -67,10 +67,12 @@
67 67 </xs:complexType>
68 68 </xs:element>
69 69  
70   - <xs:attributeGroup name="StatusGroup">
  70 +
  71 + <xs:attributeGroup name="StatusGroup">
71 72 <xs:attribute name="minVal" type="xs:double" />
72 73 <xs:attribute name="maxVal" type="xs:double" />
73 74 <xs:attribute name="name" type="xs:string" />
  75 + <xs:attribute name="color" type="xs:string" />
74 76 </xs:attributeGroup>
75 77  
76 78 <xs:complexType name="paramInfoType">
... ...
src/ParamOutputImpl/Plot/IntervalsNode.hh
... ... @@ -58,13 +58,6 @@ public:
58 58 xmlFree(value);
59 59 }
60 60  
61   - // colorMapIndex attribute
62   - value = xmlGetProp(pNode_, (const xmlChar *) "colorMapIndex");
63   - if (value != nullptr) {
64   - intervalsPropsPtr->setColorMapIndex(atoi((const char*) value));
65   - xmlFree(value);
66   - }
67   -
68 61 // add intervals definition to parameter
69 62 plotOutput->getParameter((const char*)name).addIntervalsProperties(intervalsPropsPtr);
70 63 }
... ...
src/ParamOutputImpl/Plot/IntervalsProperties.hh
... ... @@ -31,24 +31,23 @@ public:
31 31 void dump(std::ostream& out_, std::string& prefix_);
32 32  
33 33 IntervalsProperties() :
34   - DrawingProperties(), _paramId(""), _indexDef(""), _colorMapIndex(0) {
  34 + DrawingProperties(), _paramId(""), _indexDef("") {
35 35 }
36 36  
37 37 IntervalsProperties(const DrawingProperties& ref_) :
38   - DrawingProperties(ref_), _paramId(""), _indexDef(""), _colorMapIndex(0) {
  38 + DrawingProperties(ref_), _paramId(""), _indexDef("") {
39 39  
40 40 }
41 41  
42 42 IntervalsProperties(const IntervalsProperties& pParamDrawingProperties_) :
43 43 DrawingProperties(pParamDrawingProperties_), _paramId(""),
44   - _indexDef(pParamDrawingProperties_._indexDef), _colorMapIndex(pParamDrawingProperties_._colorMapIndex) {
  44 + _indexDef(pParamDrawingProperties_._indexDef) {
45 45 }
46 46  
47 47 IntervalsProperties& operator=(const IntervalsProperties& ref_) {
48 48 DrawingProperties::operator=(ref_);
49 49 _paramId = ref_._paramId;
50 50 _indexDef = ref_._indexDef;
51   - _colorMapIndex = ref_._colorMapIndex;
52 51 return *this;
53 52 }
54 53  
... ... @@ -81,14 +80,6 @@ public:
81 80 _indexList = indexList;
82 81 }
83 82  
84   - void setColorMapIndex( int colorMapIndex){
85   - _colorMapIndex = colorMapIndex;
86   - }
87   -
88   - int getColorMapIndex() const{
89   - return _colorMapIndex;
90   - }
91   -
92 83 private:
93 84 /**
94 85 * @brief Calculated paramId (from resolution).
... ... @@ -104,11 +95,6 @@ private:
104 95 * @brief List of components used by the spectro
105 96 */
106 97 AMDA::Common::ParameterIndexComponentList _indexList;
107   -
108   - /**
109   - * @brief Color Map index to use
110   - */
111   - int _colorMapIndex;
112 98 };
113 99  
114 100 } /* namespace plot */
... ...
src/ParamOutputImpl/Plot/PanelPlotOutput.cc
... ... @@ -1358,16 +1358,20 @@ void PanelPlotOutput::drawLines(LineType pType, LineStyle pStyle, int pWidth, Co
1358 1358 /**
1359 1359 * Draw a rectangle
1360 1360 */
1361   -void PanelPlotOutput::drawRectangle(double xmin, double xmax, double ymin, double ymax, int colorIndex, int colorMapIndex, double alpha)
  1361 +void PanelPlotOutput::drawRectangle(double xmin, double xmax, double ymin, double ymax, Color& color, double alpha)
1362 1362 {
1363   - //set color map
1364   - std::string lFilePath = ColormapManager::getInstance().get(_panel->_page->_mode, colorMapIndex);
1365   - _pls->spal0(lFilePath.c_str());
1366   -
1367   - Color lInitialColor;
1368   - _pls->gcol0(0, lInitialColor._red, lInitialColor._green, lInitialColor._blue);
1369   -
  1363 + if (!color.isSet()) {
  1364 + return;
  1365 + }
  1366 +
  1367 + Color lInitialColor;
  1368 +
  1369 + // Set color.
  1370 + lInitialColor = changeColor(_pls, color, _panel->_page->_mode);
  1371 +
  1372 + // Draw rectangle
1370 1373 PLFLT x[4], y[4];
  1374 +
1371 1375 x[0] = xmin;
1372 1376 x[1] = xmin;
1373 1377 x[2] = xmax;
... ... @@ -1376,8 +1380,9 @@ void PanelPlotOutput::drawRectangle(double xmin, double xmax, double ymin, doubl
1376 1380 y[1] = ymax;
1377 1381 y[2] = ymax;
1378 1382 y[3] = ymin;
1379   -
1380   - PLINT icol = (PLINT)colorIndex;
  1383 +
  1384 + // Fill rectangle
  1385 + PLINT icol = 0;
1381 1386 PLINT r, g, b = 0;
1382 1387 PLFLT a = 0;
1383 1388 _pls->gcol0a( icol, r, g, b, a);
... ... @@ -1386,12 +1391,6 @@ void PanelPlotOutput::drawRectangle(double xmin, double xmax, double ymin, doubl
1386 1391 _pls->col0( icol );
1387 1392  
1388 1393 _pls->fill(4, x, y);
1389   -
1390   - //restore to initial color context
1391   - lFilePath = ColormapManager::getInstance().get(_panel->_page->_mode, 0);
1392   - _pls->spal0(lFilePath.c_str());
1393   -
1394   - _pls->scol0(0, lInitialColor._red, lInitialColor._green, lInitialColor._blue);
1395 1394  
1396 1395 // Restore color.
1397 1396 restoreColor(_pls, lInitialColor, _panel->_page->_mode);
... ...
src/ParamOutputImpl/Plot/PanelPlotOutput.hh
... ... @@ -328,7 +328,7 @@ protected:
328 328 /**
329 329 * Draw a rectangle
330 330 */
331   - void drawRectangle(double xmin, double xmax, double ymin, double ymax, int colorIndex, int colorMapIndex, double alpha = 1.);
  331 + void drawRectangle(double xmin, double xmax, double ymin, double ymax, Color& pColor, double alpha = 1.);
332 332  
333 333 /**
334 334 * Draw errors segments
... ...
src/ParamOutputImpl/Plot/Time/TimePlot.cc
... ... @@ -1016,6 +1016,47 @@ void TimePlot::drawSpectro(double startDate, double stopDate, std::string pParam
1016 1016 minValColor, maxValColor, lZAxis->_color._colorMapIndex, FALSE, pSpectro.getUseLog0AsMin());
1017 1017 }
1018 1018  
  1019 +Color TimePlot::getStatusColor(AMDA::Info::ParamInfoSPtr& paramInfo, double value) {
  1020 + Color color;
  1021 +
  1022 + if ((paramInfo != nullptr) && !paramInfo->getStatusDef().empty()) {
  1023 + for (int s = 0 ; s < (int)paramInfo->getStatusDef().size(); ++s) {
  1024 + if (value >= paramInfo->getStatusDef()[s].getMinValue() && value <= paramInfo->getStatusDef()[s].getMaxValue()) {
  1025 + if (!paramInfo->getStatusDef()[s].getColor().empty()) {
  1026 + std::string colorStr = paramInfo->getStatusDef()[s].getColor();
  1027 + createColor(color, colorStr);
  1028 + return color;
  1029 + }
  1030 + }
  1031 + }
  1032 + }
  1033 +
  1034 + return color;
  1035 +}
  1036 +
  1037 +void TimePlot::drawOneInterval(double tmin, double tmax, Color color) {
  1038 + if (!color.isSet()) {
  1039 + return;
  1040 + }
  1041 +
  1042 + //Fill interval
  1043 + PanelPlotOutput::drawRectangle(tmin, tmax, 0., 1., color, 0.25);
  1044 +
  1045 + //Draw borders
  1046 + PLFLT x[2], y[2];
  1047 + x[0] = tmin;
  1048 + y[0] = 0.;
  1049 + x[1] = tmin;
  1050 + y[1] = 1.;
  1051 + PanelPlotOutput::drawLines(LineType::LINE, LineStyle::PLAIN, 2, color, 2, x, y);
  1052 +
  1053 + x[0] = tmax;
  1054 + y[0] = 0.;
  1055 + x[1] = tmax;
  1056 + y[1] = 1.;
  1057 + PanelPlotOutput::drawLines(LineType::LINE, LineStyle::PLAIN, 2, color, 2, x, y);
  1058 +}
  1059 +
1019 1060 void TimePlot::drawIntervals(double startDate, double stopDate, std::string pParamId,
1020 1061 IntervalsProperties& pIntervals) {
1021 1062 LOG4CXX_DEBUG(gLogger, "TimePlot::drawIntervals Drawing intervals for parameter "<<pParamId);
... ... @@ -1028,14 +1069,15 @@ void TimePlot::drawIntervals(double startDate, double stopDate, std::string pPar
1028 1069 std::get<2>(lPlWindow), std::get<3>(lPlWindow));
1029 1070  
1030 1071 ParameterData& data = (*_pParameterValues)[pIntervals.getParamId()];
1031   -
1032   - std::string lFilePath = ColormapManager::getInstance().get(_panel->_page->_mode,
1033   - pIntervals.getColorMapIndex());
1034   - _pls->spal0(lFilePath.c_str());
  1072 +
  1073 + ParameterSPtr p = _parameterManager.getParameter(pIntervals.getParamId());
  1074 + AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
1035 1075  
1036 1076 //get computed values
1037 1077 int startIndex, nbData;
1038 1078 data.getIntervalBounds(startDate, stopDate, startIndex, nbData);
  1079 +
  1080 + Color crtColor;
1039 1081  
1040 1082 // Draw intervals
1041 1083 double crtVal = NAN;
... ... @@ -1055,10 +1097,11 @@ void TimePlot::drawIntervals(double startDate, double stopDate, std::string pPar
1055 1097 tmax = t2;
1056 1098 continue;
1057 1099 }
1058   -
1059   - //Draw interval between tmin and tmax
1060   - PanelPlotOutput::drawRectangle(tmin, tmax, 0., 1., (int)crtVal, pIntervals.getColorMapIndex(), 0.25);
1061   -
  1100 +
  1101 + crtColor = getStatusColor(paramInfo, crtVal);
  1102 +
  1103 + drawOneInterval(tmin, tmax, crtColor);
  1104 +
1062 1105 tmin = t1;
1063 1106 tmax = t2;
1064 1107 crtVal = v;
... ... @@ -1066,7 +1109,7 @@ void TimePlot::drawIntervals(double startDate, double stopDate, std::string pPar
1066 1109  
1067 1110 //Draw last interval if need
1068 1111 if (!isNAN(crtVal)) {
1069   - PanelPlotOutput::drawRectangle(tmin, tmax, 0., 1., (int)crtVal, pIntervals.getColorMapIndex(), 0.25);
  1112 + drawOneInterval(tmin, tmax, crtColor);
1070 1113 }
1071 1114 }
1072 1115  
... ...
src/ParamOutputImpl/Plot/Time/TimePlot.hh
... ... @@ -22,6 +22,8 @@
22 22  
23 23 #include "TimePlotNode.hh"
24 24  
  25 +#include "ParamInfo.hh"
  26 +
25 27 extern "C" {
26 28 #include <plplot/qsastime.h>
27 29 }
... ... @@ -202,6 +204,10 @@ private:
202 204 bool colorLessSpecified, Color& colorLess,
203 205 SeriesProperties &rSeriesProperties);
204 206  
  207 + Color getStatusColor(AMDA::Info::ParamInfoSPtr& paramInfo, double value);
  208 +
  209 + void drawOneInterval(double tmin, double tmax, Color color);
  210 +
205 211 std::shared_ptr<TimeAxisDecorator> _xdecoratorPtr;
206 212  
207 213 bool _startDateDrawn;
... ...