Commit bdc50075aa8f412fc7fba1fc8b53430a0fda68aa

Authored by Benjamin Renard
1 parent 99a73aaf

Fix bug for position of the right axis when a left axis is defined

src/ParamOutputImpl/Plot/PanelPlotOutput.cc
... ... @@ -104,6 +104,21 @@ void PanelPlotOutput::calculatePlotArea(Bounds& bounds_) {
104 104 _panel->reserveSpaceForTitle(topSpace, bottomSpace, titleHeight);
105 105  
106 106 // Reserve space for axes
  107 +
  108 + //
  109 + std::map<PlotCommon::Position, int> nbAxesBySide;
  110 + nbAxesBySide[PlotCommon::Position::POS_TOP] = 0;
  111 + nbAxesBySide[PlotCommon::Position::POS_BOTTOM] = 0;
  112 + nbAxesBySide[PlotCommon::Position::POS_RIGHT] = 0;
  113 + nbAxesBySide[PlotCommon::Position::POS_LEFT] = 0;
  114 + for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end(); ++it)
  115 + {
  116 + boost::shared_ptr<Axis> lAxis = it->second;
  117 + if ((lAxis == nullptr) || (lAxis->_isZAxis) || (!lAxis->_visible) || (lAxis->_position == PlotCommon::Position::POS_CENTER))
  118 + continue;
  119 + ++nbAxesBySide[lAxis->_position];
  120 + }
  121 +
107 122 // ZAxis must be drawn at last!
108 123 for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end(); ++it)
109 124 {
... ... @@ -111,7 +126,7 @@ void PanelPlotOutput::calculatePlotArea(Bounds&amp; bounds_) {
111 126 boost::shared_ptr<Axis> lAxis = it->second;
112 127 if ((lAxis == nullptr) || (lAxis->_isZAxis))
113 128 continue;
114   - reserveSpaceForAxis(lAxis, titleHeight, topSpace, bottomSpace, leftSpace, rightSpace);
  129 + reserveSpaceForAxis(lAxis, titleHeight, nbAxesBySide, topSpace, bottomSpace, leftSpace, rightSpace);
115 130 }
116 131  
117 132 for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end(); ++it)
... ... @@ -120,7 +135,7 @@ void PanelPlotOutput::calculatePlotArea(Bounds&amp; bounds_) {
120 135 boost::shared_ptr<Axis> lAxis = it->second;
121 136 if ((lAxis == nullptr) || (!lAxis->_isZAxis))
122 137 continue;
123   - reserveSpaceForAxis(lAxis, titleHeight, topSpace, bottomSpace, leftSpace, rightSpace);
  138 + reserveSpaceForAxis(lAxis, titleHeight, nbAxesBySide, topSpace, bottomSpace, leftSpace, rightSpace);
124 139 }
125 140  
126 141 // Get character size for panel.
... ... @@ -211,7 +226,8 @@ void PanelPlotOutput::calculatePlotArea(Bounds&amp; bounds_) {
211 226 bounds_._height -= (bottomSpace + topSpace);
212 227 }
213 228  
214   -void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr<Axis>& pAxis, double titleHeight, double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace) {
  229 +void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr<Axis>& pAxis, double titleHeight, std::map<PlotCommon::Position, int> nbAxesBySide,
  230 + double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace) {
215 231 if (pAxis == nullptr || !pAxis->_used || !pAxis->_visible)
216 232 return;
217 233  
... ... @@ -242,8 +258,9 @@ void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr&lt;Axis&gt;&amp; pAxis, doubl
242 258 if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
243 259 double tickSize = getVerticalTickLength(pAxis.get(), legendCharSizePanel.second);
244 260 bottomSpace += tickSize;
245   - //add space for oposite axis
246   - topSpace += tickSize;
  261 + if (nbAxesBySide[PlotCommon::Position::POS_TOP] == 0)
  262 + //add space for oposite axis
  263 + topSpace += tickSize;
247 264 }
248 265  
249 266 //Reserve space for ticks labels
... ... @@ -273,8 +290,9 @@ void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr&lt;Axis&gt;&amp; pAxis, doubl
273 290 if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
274 291 double tickSize = getVerticalTickLength(pAxis.get(), legendCharSizePanel.second);
275 292 topSpace += tickSize;
276   - //add space for oposite axis
277   - bottomSpace += tickSize;
  293 + if (nbAxesBySide[PlotCommon::Position::POS_BOTTOM] == 0)
  294 + //add space for oposite axis
  295 + bottomSpace += tickSize;
278 296 }
279 297  
280 298 //Reserve space for ticks labels
... ... @@ -312,8 +330,9 @@ void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr&lt;Axis&gt;&amp; pAxis, doubl
312 330 if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
313 331 double tickSize = getHorizontalTickLength(pAxis.get(), legendCharSizePanel.second);
314 332 leftSpace += tickSize;
315   - //add space for oposite axis
316   - rightSpace += tickSize;
  333 + if (nbAxesBySide[PlotCommon::Position::POS_RIGHT] == 0)
  334 + //add space for oposite axis
  335 + rightSpace += tickSize;
317 336 }
318 337  
319 338 // Reserve space for legend
... ... @@ -326,6 +345,7 @@ void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr&lt;Axis&gt;&amp; pAxis, doubl
326 345 break;
327 346 case PlotCommon::Position::POS_RIGHT:
328 347 // Record axis offset used for multi-axes
  348 +
329 349 pAxis->setAxisOffset (rightSpace);
330 350  
331 351 if (pAxis->isZAxis()) {
... ... @@ -344,13 +364,15 @@ void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr&lt;Axis&gt;&amp; pAxis, doubl
344 364 if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
345 365 double tickSize = getHorizontalTickLength(pAxis.get(), legendCharSizePanel.second);
346 366 rightSpace += tickSize;
347   - leftSpace += tickSize;
  367 + if (nbAxesBySide[PlotCommon::Position::POS_LEFT] == 0)
  368 + //add space for oposite axis
  369 + leftSpace += tickSize;
348 370 }
349 371  
350 372 //Reserve space for legend
351 373 if ((pAxis->_showLegend == true) && (nbLegendRows != 0)) {
352 374 rightSpace += PlPlotUtil::LINE_SPACE_TITLE * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize);
353   - pAxis->setLegendOffset(rightSpace - 0.5 * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize));
  375 + pAxis->setLegendOffset(rightSpace + 0.5 * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize));
354 376 rightSpace += (nbLegendRows + PlPlotUtil::LINE_SPACE_TITLE * (nbLegendRows + 1)) * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize) ;
355 377 }
356 378  
... ...
src/ParamOutputImpl/Plot/PanelPlotOutput.hh
... ... @@ -528,7 +528,8 @@ private:
528 528 */
529 529 int _automaticSerieColorCursor;
530 530  
531   - void reserveSpaceForAxis (boost::shared_ptr<Axis>& pAxis, double titleHeight, double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace);
  531 + void reserveSpaceForAxis (boost::shared_ptr<Axis>& pAxis, double titleHeight, std::map<PlotCommon::Position, int> nbAxesBySide,
  532 + double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace);
532 533  
533 534 void reserveSpaceForTextLegend (boost::shared_ptr<TextLegendProperties>& pTextLegendProp, double titleHeight, double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace);
534 535 };
... ...