Commit bc435e2fdf49fb24e08ee75aae784d383d4d812a

Authored by Benjamin Renard
2 parents ec48a62a 29818855

Merge branch '5390' into develop

config/xsd/request/plot.xsd
... ... @@ -570,6 +570,7 @@
570 570 </xs:sequence>
571 571 <xs:attribute name="backgroundColor"
572 572 type="xs:string" />
  573 + <xs:attribute name="plotAreaBackgroundColor" type="xs:string"/>
573 574 <xs:attribute name="colorMapIndex"
574 575 type="xs:integer" />
575 576 <xs:attribute name="preferedWidth"
... ...
src/ParamOutputImpl/Plot/Panel.cc
... ... @@ -18,77 +18,75 @@ namespace plot {
18 18 //Auto id set to a negative number to preserve id defined in request
19 19 int Panel::PANEL_COUNTER = -1;
20 20  
21   -Panel::Panel() :
22   - _id(--PANEL_COUNTER),
23   - _index(-1),
24   - _resolution(0),
25   - _updateTitleOnNextInterval(false),
26   - _bounds(Bounds()),
27   - _backgroundColor(Color()),
28   - _titleAlign(PlotCommon::Align::CENTER),
29   - _titlePosition(PlotCommon::Position::POS_TOP),
30   - _drawn(false),
31   - _page(),
32   - _preferedWidth(-1),
33   - _preferedHeight(-1),
34   - _leftMargin(-1),
35   - _rightMargin(-1),
36   - _topMargin(-1),
37   - _bottomMargin(-1),
38   - _paramsLegendProperties(),
39   - _textLegendPropertiesList(),
40   - _font(Font("", 0)),
41   - _title(Font("", 0))
  21 +Panel::Panel() : _id(--PANEL_COUNTER),
  22 + _index(-1),
  23 + _resolution(0),
  24 + _updateTitleOnNextInterval(false),
  25 + _bounds(Bounds()),
  26 + _backgroundColor(Color()),
  27 + _plotAreaBackgroundColor(Color()),
  28 + _titleAlign(PlotCommon::Align::CENTER),
  29 + _titlePosition(PlotCommon::Position::POS_TOP),
  30 + _drawn(false),
  31 + _page(),
  32 + _preferedWidth(-1),
  33 + _preferedHeight(-1),
  34 + _leftMargin(-1),
  35 + _rightMargin(-1),
  36 + _topMargin(-1),
  37 + _bottomMargin(-1),
  38 + _paramsLegendProperties(),
  39 + _textLegendPropertiesList(),
  40 + _font(Font("", 0)),
  41 + _title(Font("", 0))
42 42 {
43 43 }
44 44  
45   -Panel::Panel(DefaultPlotConfiguration& defaults) :
46   - _id(--PANEL_COUNTER),
47   - _index(defaults._defaultPanel._index),
48   - _resolution(defaults._defaultPanel._resolution),
49   - _updateTitleOnNextInterval(false),
50   - _bounds(Bounds()),
51   - _backgroundColor(defaults._defaultPanel._backgroundColor),
52   - _titleAlign(defaults._defaultPanel._titleAlign),
53   - _titlePosition(defaults._defaultPanel._titlePosition),
54   - _drawn(false),
55   - _page(),
56   - _preferedWidth(defaults._defaultPanel._preferedWidth),
57   - _preferedHeight(defaults._defaultPanel._preferedHeight),
58   - _leftMargin(defaults._defaultPanel._leftMargin),
59   - _rightMargin(defaults._defaultPanel._rightMargin),
60   - _topMargin(defaults._defaultPanel._topMargin),
61   - _bottomMargin(defaults._defaultPanel._bottomMargin),
62   - _textLegendPropertiesList(defaults._defaultPanel._textLegendPropertiesList),
63   - _font(defaults._defaultPanel.getFont()),
64   - _title(defaults._defaultPanel.getFont())
  45 +Panel::Panel(DefaultPlotConfiguration &defaults) : _id(--PANEL_COUNTER),
  46 + _index(defaults._defaultPanel._index),
  47 + _resolution(defaults._defaultPanel._resolution),
  48 + _updateTitleOnNextInterval(false),
  49 + _bounds(Bounds()),
  50 + _backgroundColor(defaults._defaultPanel._backgroundColor),
  51 + _plotAreaBackgroundColor(defaults._defaultPanel._backgroundColor),
  52 + _titleAlign(defaults._defaultPanel._titleAlign),
  53 + _titlePosition(defaults._defaultPanel._titlePosition),
  54 + _drawn(false),
  55 + _page(),
  56 + _preferedWidth(defaults._defaultPanel._preferedWidth),
  57 + _preferedHeight(defaults._defaultPanel._preferedHeight),
  58 + _leftMargin(defaults._defaultPanel._leftMargin),
  59 + _rightMargin(defaults._defaultPanel._rightMargin),
  60 + _topMargin(defaults._defaultPanel._topMargin),
  61 + _bottomMargin(defaults._defaultPanel._bottomMargin),
  62 + _textLegendPropertiesList(defaults._defaultPanel._textLegendPropertiesList),
  63 + _font(defaults._defaultPanel.getFont()),
  64 + _title(defaults._defaultPanel.getFont())
65 65 {
66 66 }
67 67  
68   -Panel::Panel(Page* page) :
69   - _id(--PANEL_COUNTER),
70   - _index(-1),
71   - _resolution(DefaultPlotConfiguration::getInstance()._defaultPanel._resolution),
72   - _updateTitleOnNextInterval(false),
73   - _bounds(Bounds()),
74   - _backgroundColor(DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor),
75   - _titleAlign(DefaultPlotConfiguration::getInstance()._defaultPanel._titleAlign),
76   - _titlePosition(DefaultPlotConfiguration::getInstance()._defaultPanel._titlePosition),
77   - _drawn(false),
78   - _page(page),
79   - _preferedWidth(DefaultPlotConfiguration::getInstance()._defaultPanel._preferedWidth),
80   - _preferedHeight(DefaultPlotConfiguration::getInstance()._defaultPanel._preferedHeight),
81   - _leftMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._leftMargin),
82   - _rightMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._rightMargin),
83   - _topMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._topMargin),
84   - _bottomMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._bottomMargin),
85   - _textLegendPropertiesList(DefaultPlotConfiguration::getInstance()._defaultPanel._textLegendPropertiesList),
86   - _font(Font(
87   - DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getName().empty() ?
88   - page->getFont().getName() : DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getName(),
89   - DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getSize() != 0 ?
90   - DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getSize() : page->getFont().getSize())),
91   - _title(_font)
  68 +Panel::Panel(Page *page) : _id(--PANEL_COUNTER),
  69 + _index(-1),
  70 + _resolution(DefaultPlotConfiguration::getInstance()._defaultPanel._resolution),
  71 + _updateTitleOnNextInterval(false),
  72 + _bounds(Bounds()),
  73 + _backgroundColor(DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor),
  74 + _plotAreaBackgroundColor(DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor),
  75 + _titleAlign(DefaultPlotConfiguration::getInstance()._defaultPanel._titleAlign),
  76 + _titlePosition(DefaultPlotConfiguration::getInstance()._defaultPanel._titlePosition),
  77 + _drawn(false),
  78 + _page(page),
  79 + _preferedWidth(DefaultPlotConfiguration::getInstance()._defaultPanel._preferedWidth),
  80 + _preferedHeight(DefaultPlotConfiguration::getInstance()._defaultPanel._preferedHeight),
  81 + _leftMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._leftMargin),
  82 + _rightMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._rightMargin),
  83 + _topMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._topMargin),
  84 + _bottomMargin(DefaultPlotConfiguration::getInstance()._defaultPanel._bottomMargin),
  85 + _textLegendPropertiesList(DefaultPlotConfiguration::getInstance()._defaultPanel._textLegendPropertiesList),
  86 + _font(Font(
  87 + DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getName().empty() ? page->getFont().getName() : DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getName(),
  88 + DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getSize() != 0 ? DefaultPlotConfiguration::getInstance()._defaultPanel.getFont().getSize() : page->getFont().getSize())),
  89 + _title(_font)
92 90 {
93 91 }
94 92  
... ...
src/ParamOutputImpl/Plot/Panel.hh
... ... @@ -165,6 +165,11 @@ public:
165 165 Color _backgroundColor;
166 166  
167 167 /**
  168 + * @brief Plot Area Background color
  169 + */
  170 + Color _plotAreaBackgroundColor;
  171 +
  172 + /**
168 173 * @brief Panel title Align (center, left, right)
169 174 */
170 175 PlotCommon::Align _titleAlign;
... ...
src/ParamOutputImpl/Plot/PanelNode.cc
... ... @@ -87,6 +87,25 @@ void PanelNode::proceed(xmlNodePtr pNode,
87 87 DefaultPlotConfiguration::getInstance()._defaultPanel._backgroundColor;
88 88 }
89 89  
  90 + // -- plot area color
  91 + Color pabgcolor;
  92 + value = xmlGetProp(pNode, (const xmlChar *)"plotAreaBackgroundColor");
  93 + if (value)
  94 + {
  95 + try
  96 + {
  97 + std::string strValue((const char *)value);
  98 + createColor(pabgcolor, strValue);
  99 + }
  100 + catch (std::logic_error &e)
  101 + {
  102 + LOG4CXX_WARN(gLogger, "Plot Area BackgroundColor : " << e.what());
  103 + }
  104 + xmlFree(value);
  105 + }
  106 +
  107 + panel->_plotAreaBackgroundColor = pabgcolor;
  108 +
90 109 // -- color map index
91 110 value = xmlGetProp(pNode, (const xmlChar *) "colorMapIndex");
92 111 if (value) {
... ...
src/ParamOutputImpl/Plot/PanelPlotOutput.cc
... ... @@ -2109,34 +2109,66 @@ void PanelPlotOutput::writeContext(ContextFileWriter &amp;writer, AMDA::Parameters::
2109 2109 {
2110 2110 TimeTableCatalog::Catalog inputTTOrCat;
2111 2111 inputTTOrCat.read(ttOrCatPath, lReaderType);
2112   -
2113 2112 for (std::vector<TimeTableCatalog::TimeInterval>::const_iterator it = inputTTOrCat.getIntervals().begin(); it != inputTTOrCat.getIntervals().end(); ++it)
2114 2113 {
  2114 + double acceptedRatio = 0.005; // if the interval is too small, no more info given
  2115 + double timeRatio = (currentTimeInterval->_stopTime - currentTimeInterval->_startTime) / _plotAreaBounds._width;
  2116 +
  2117 + std::map<std::string, std::vector<std::string>> data;
  2118 + bool needTTWriter = false;
  2119 + bool needCatWriter = false;
  2120 + double startTime = it->_startTime;
  2121 + double stopTime = it->_stopTime;
  2122 +
2115 2123 if (it->_startTime >= currentTimeInterval->_startTime && it->_stopTime <= currentTimeInterval->_stopTime) // inside the interval
2116 2124 {
2117   - writer.startElement("intervals");
2118   - writer.addAttribute("name", inputTTOrCat._name.c_str());
2119   - writer.addAttribute("id", std::to_string(it->_index).c_str());
2120   - writer.addAttribute("startTime", std::to_string(it->_startTime).c_str());
2121   - writer.addAttribute("stopTime", std::to_string(it->_stopTime).c_str());
2122   - writer.endElement();
  2125 + if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)
  2126 + {
  2127 + needTTWriter = true;
  2128 + data = it->getAllParameterData();
  2129 + if (data.size() > 0)
  2130 + needCatWriter = true;
  2131 + }
2123 2132 }
2124 2133 else if (it->_startTime <= currentTimeInterval->_startTime && it->_stopTime <= currentTimeInterval->_stopTime && it->_stopTime >= currentTimeInterval->_startTime) // begins before, ends inside
2125 2134 {
2126   - writer.startElement("intervals");
2127   - writer.addAttribute("name", inputTTOrCat._name.c_str());
2128   - writer.addAttribute("id", std::to_string(it->_index).c_str());
2129   - writer.addAttribute("startTime", std::to_string(currentTimeInterval->_startTime).c_str());
2130   - writer.addAttribute("stopTime", std::to_string(it->_stopTime).c_str());
2131   - writer.endElement();
  2135 + startTime = currentTimeInterval->_startTime;
  2136 + if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)
  2137 + {
  2138 + needTTWriter = true;
  2139 + data = it->getAllParameterData();
  2140 + if (data.size() > 0)
  2141 + needCatWriter = true;
  2142 + }
2132 2143 }
2133 2144 else if (it->_startTime >= currentTimeInterval->_startTime && it->_startTime <= currentTimeInterval->_stopTime && it->_stopTime >= currentTimeInterval->_stopTime) // begins inside, ends after
2134 2145 {
  2146 + stopTime = currentTimeInterval->_stopTime;
  2147 + if (timeRatio * acceptedRatio < (stopTime - startTime) / _plotAreaBounds._width)
  2148 + {
  2149 + needTTWriter = true;
  2150 + data = it->getAllParameterData();
  2151 + if (data.size() > 0)
  2152 + needCatWriter = true;
  2153 + }
  2154 + }
  2155 +
  2156 + if (needTTWriter)
  2157 + {
2135 2158 writer.startElement("intervals");
2136 2159 writer.addAttribute("name", inputTTOrCat._name.c_str());
2137 2160 writer.addAttribute("id", std::to_string(it->_index).c_str());
2138   - writer.addAttribute("startTime", std::to_string(it->_startTime).c_str());
2139   - writer.addAttribute("stopTime", std::to_string(currentTimeInterval->_stopTime).c_str());
  2161 + writer.addAttribute("startTime", std::to_string(startTime).c_str());
  2162 + writer.addAttribute("stopTime", std::to_string(stopTime).c_str());
  2163 + if (needCatWriter)
  2164 + {
  2165 + std::string allParams;
  2166 + for (auto i : data)
  2167 + {
  2168 + allParams += i.second[0] + "|";
  2169 + }
  2170 + writer.addAttribute("params", allParams.c_str());
  2171 + }
2140 2172 writer.endElement();
2141 2173 }
2142 2174 }
... ... @@ -2191,6 +2223,42 @@ void PanelPlotOutput::preparePlotArea(double /*startTime*/, double /*stopTime*/,
2191 2223 _panel->_paramsLegendProperties.resetPlot();
2192 2224 }
2193 2225  
  2226 +void PanelPlotOutput::fillBackground(std::shared_ptr<plstream> &pls)
  2227 +{
  2228 + if (_panel->_plotAreaBackgroundColor._red != -1 && _panel->_plotAreaBackgroundColor._green != -1 && _panel->_plotAreaBackgroundColor._blue != -1)
  2229 + {
  2230 + Color plotAreaBackgroundColor = _panel->_plotAreaBackgroundColor;
  2231 +
  2232 + PLINT lInitialRed = -1, lInitialGreen = -1, lInitialBlue = -1;
  2233 + // Store initial color in first index.
  2234 + pls->gcol0(0, lInitialRed, lInitialGreen, lInitialBlue);
  2235 + pls->scol0(0, plotAreaBackgroundColor._red, plotAreaBackgroundColor._green,
  2236 + plotAreaBackgroundColor._blue);
  2237 + pls->col0(0);
  2238 +
  2239 + // Compute panel coordinate in the page
  2240 + Bounds lBounds = _plotAreaBounds;
  2241 + // Specify viewport for the panel
  2242 + pls->vpor(_plotAreaBounds._x, _plotAreaBounds._x + _plotAreaBounds._width,
  2243 + _plotAreaBounds._y, _plotAreaBounds._y + _plotAreaBounds._height);
  2244 +
  2245 + // Set window size.
  2246 + pls->wind(0, 1, 0, 1);
  2247 +
  2248 + // Fill background.
  2249 + PLFLT px[] = {0, 0, 1, 1};
  2250 + PLFLT py[] = {0, 1, 1, 0};
  2251 + pls->fill(4, px, py);
  2252 +
  2253 + pls->col0(0);
  2254 +
  2255 + if (lInitialRed != -1 && lInitialGreen != -1 && lInitialBlue != -1)
  2256 + {
  2257 + pls->scol0(0, lInitialRed, lInitialGreen, lInitialBlue);
  2258 + }
  2259 + }
  2260 +}
  2261 +
2194 2262 /**
2195 2263 * @brief Retrieve plot area bounds for the panel
2196 2264 */
... ... @@ -2260,11 +2328,13 @@ bool PanelPlotOutput::draw(double startTime, double stopTime, int intervalIndex,
2260 2328 bool isFirstInterval, bool isLastInterval) {
2261 2329 // Sets panel plplot viewport, draw background & title for the panel
2262 2330 _panel->draw(_pls);
  2331 + fillBackground(_pls);
2263 2332  
2264   - bool noData = true;
  2333 + bool noData = true;
2265 2334  
2266   - if (_parameterAxesList.empty()) {
2267   - noData = false; //Do not draw No Data if the panel is empty
  2335 + if (_parameterAxesList.empty())
  2336 + {
  2337 + noData = false; // Do not draw No Data if the panel is empty
2268 2338 _panel->drawEmptyPanel(_pls);
2269 2339 }
2270 2340  
... ...
src/ParamOutputImpl/Plot/PanelPlotOutput.hh
... ... @@ -113,7 +113,7 @@ public:
113 113 /*
114 114 * @brief Set a pointer to the time intervals list
115 115 */
116   - void setTimeIntervalListPtr(AMDA::Parameters::TimeIntervalList* timeIntervalListPtr);
  116 + void setTimeIntervalListPtr(AMDA::Parameters::TimeIntervalList *timeIntervalListPtr);
117 117  
118 118 /**
119 119 * Sets PLplot stream to draw panel and plot
... ... @@ -529,6 +529,14 @@ protected:
529 529 */
530 530 virtual void dump(std::ostream& out_);
531 531  
  532 + /**
  533 + * @brief Fill the background of the plot area
  534 + *
  535 + * @param pls
  536 + */
  537 +
  538 + void fillBackground(std::shared_ptr<plstream> &pls);
  539 +
532 540 private:
533 541  
534 542 void drawAxis(boost::shared_ptr<Axis> pAxis, TickConf& pTickConf, std::string pXAxisOptions,
... ...
src/TimeTableCatalog/TimeInterval.cc
... ... @@ -40,6 +40,11 @@ std::vector&lt;std::string&gt; &amp; TimeInterval:: getParameterData (const std::string &amp;p
40 40 return _parametersData [paramId];
41 41 }
42 42  
  43 +std::map<std::string, std::vector<std::string>> TimeInterval::getAllParameterData() const
  44 +{
  45 + return _parametersData;
  46 +}
  47 +
43 48 int TimeInterval:: getParameterDataCount () {
44 49 return _parametersData.size();
45 50 }
... ...
src/TimeTableCatalog/TimeInterval.hh
... ... @@ -45,6 +45,8 @@ public:
45 45 */
46 46 std::vector<std::string> & getParameterData (const std::string &paramKey);
47 47  
  48 + std::map<std::string, std::vector<std::string>> getAllParameterData() const;
  49 +
48 50 /**
49 51 * Retrievenumber of parameter data associated with the interval
50 52 */
... ...