Commit 08ec1dde709de6fe520165512f61bd5f323f6e04

Authored by Benjamin Renard
1 parent 2d40f7de

Add propertie _used to an axis to know if the axes is used by a parameter

Fix a bug with page margin calculation
Axes are stored by a map in Panel, that don't preserve the insertion order. In calculatePlotArea we need to be sure that ZAxis are taking in account at last.
src/ParamOutputImpl/Plot/Axis.cc
@@ -20,6 +20,7 @@ Axis::Axis(bool isZAxis) : @@ -20,6 +20,7 @@ Axis::Axis(bool isZAxis) :
20 _reverse(false), 20 _reverse(false),
21 _tick(), 21 _tick(),
22 _visible(true), 22 _visible(true),
  23 + _used(false),
23 _thickness(1), 24 _thickness(1),
24 _legend(), 25 _legend(),
25 _drawn(false), 26 _drawn(false),
src/ParamOutputImpl/Plot/Axis.hh
@@ -125,6 +125,11 @@ public: @@ -125,6 +125,11 @@ public:
125 bool _visible; 125 bool _visible;
126 126
127 /** 127 /**
  128 + * @brief Axis is used for the plot or not
  129 + */
  130 + bool _used;
  131 +
  132 + /**
128 * @brief Axis draw thickness 133 * @brief Axis draw thickness
129 */ 134 */
130 int _thickness; 135 int _thickness;
src/ParamOutputImpl/Plot/CommonNode.cc
@@ -21,14 +21,14 @@ void MarginNode::proceed(xmlNodePtr pNode, @@ -21,14 +21,14 @@ void MarginNode::proceed(xmlNodePtr pNode,
21 // -- horizontal margin 21 // -- horizontal margin
22 value = xmlGetProp(pNode, (const xmlChar *) "x"); 22 value = xmlGetProp(pNode, (const xmlChar *) "x");
23 if (value) { 23 if (value) {
24 - element->calculateRelativeXMargin(element->_orientation, element->_dimension, atof((const char*) value)); 24 + element->_xMargin = atof((const char*) value);
25 xmlFree(value); 25 xmlFree(value);
26 } 26 }
27 27
28 // -- vertical margin 28 // -- vertical margin
29 value = xmlGetProp(pNode, (const xmlChar *) "y"); 29 value = xmlGetProp(pNode, (const xmlChar *) "y");
30 if (value) { 30 if (value) {
31 - element->calculateRelativeYMargin(element->_orientation, element->_dimension, atof((const char*) value)); 31 + element->_yMargin = atof((const char*) value);
32 xmlFree(value); 32 xmlFree(value);
33 } 33 }
34 } 34 }
src/ParamOutputImpl/Plot/Epoch/EpochPlot.cc
@@ -70,6 +70,8 @@ void EpochPlot::preparePlotArea(double startTime, double stopTime, int intervalI @@ -70,6 +70,8 @@ void EpochPlot::preparePlotArea(double startTime, double stopTime, int intervalI
70 _epochDecoratorPtr->configure(this, getEpochAxis(), 70 _epochDecoratorPtr->configure(this, getEpochAxis(),
71 getEpochAxis()->getRange().getMin(), getEpochAxis()->getRange().getMax(), _pParameterValues); 71 getEpochAxis()->getRange().getMin(), getEpochAxis()->getRange().getMax(), _pParameterValues);
72 72
  73 + getEpochAxis()->_used = true;
  74 +
73 PanelPlotOutput::preparePlotArea(startTime,stopTime,intervalIndex); 75 PanelPlotOutput::preparePlotArea(startTime,stopTime,intervalIndex);
74 } 76 }
75 77
@@ -180,6 +182,7 @@ void EpochPlot::configureSeriesAxis() { @@ -180,6 +182,7 @@ void EpochPlot::configureSeriesAxis() {
180 lError << "EpochPlot::configureSeriesAxis" << ": Y axis with id '" << lSeriesProperties.getYAxisId() << "' not found."; 182 lError << "EpochPlot::configureSeriesAxis" << ": Y axis with id '" << lSeriesProperties.getYAxisId() << "' not found.";
181 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 183 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
182 } 184 }
  185 + lYAxis->_used = true;
183 186
184 Range lRange(lYAxis->getRange()); 187 Range lRange(lYAxis->getRange());
185 // If range status for this axis is set by the user do not update range "automatically". 188 // If range status for this axis is set by the user do not update range "automatically".
@@ -206,6 +209,7 @@ void EpochPlot::configureSeriesAxis() { @@ -206,6 +209,7 @@ void EpochPlot::configureSeriesAxis() {
206 { 209 {
207 if (!lSeriesProperties.getColorParamId().empty()) 210 if (!lSeriesProperties.getColorParamId().empty())
208 { 211 {
  212 + lZAxis->_used = true;
209 Range lRange(lZAxis->getRange()); 213 Range lRange(lZAxis->getRange());
210 ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId()); 214 ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
211 if (colorSerieParameterAxes == NULL) 215 if (colorSerieParameterAxes == NULL)
src/ParamOutputImpl/Plot/InstantPlot/InstantPlot.cc
@@ -593,6 +593,8 @@ void InstantPlot::configureSeriesAxis() { @@ -593,6 +593,8 @@ void InstantPlot::configureSeriesAxis() {
593 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 593 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
594 } 594 }
595 595
  596 + lXAxis->_used = true;
  597 +
596 boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSerieProperties->getYAxisId()); 598 boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSerieProperties->getYAxisId());
597 if (lYAxis.get() == nullptr) { 599 if (lYAxis.get() == nullptr) {
598 std::stringstream lError; 600 std::stringstream lError;
@@ -600,6 +602,8 @@ void InstantPlot::configureSeriesAxis() { @@ -600,6 +602,8 @@ void InstantPlot::configureSeriesAxis() {
600 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 602 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
601 } 603 }
602 604
  605 + lYAxis->_used = true;
  606 +
603 if (_iSerieProperties->getTableOnXAxis()) 607 if (_iSerieProperties->getTableOnXAxis())
604 { 608 {
605 configureTableAxis (lXAxis, false, 0); 609 configureTableAxis (lXAxis, false, 0);
@@ -973,6 +977,7 @@ void InstantPlot::configureSpectroAxis() @@ -973,6 +977,7 @@ void InstantPlot::configureSpectroAxis()
973 lError << "InstantPlot::configureSpectroAxis" << ": X axis with id '" << _iSpectroProperties->getXAxisId() << "' not found."; 977 lError << "InstantPlot::configureSpectroAxis" << ": X axis with id '" << _iSpectroProperties->getXAxisId() << "' not found.";
974 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 978 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
975 } 979 }
  980 + lXAxis->_used = true;
976 981
977 boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSpectroProperties->getYAxisId()); 982 boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSpectroProperties->getYAxisId());
978 if (lYAxis.get() == nullptr) { 983 if (lYAxis.get() == nullptr) {
@@ -980,6 +985,7 @@ void InstantPlot::configureSpectroAxis() @@ -980,6 +985,7 @@ void InstantPlot::configureSpectroAxis()
980 lError << "InstantPlot::configureSpectroAxis" << ": Y axis with id '" << _iSpectroProperties->getYAxisId() << "' not found."; 985 lError << "InstantPlot::configureSpectroAxis" << ": Y axis with id '" << _iSpectroProperties->getYAxisId() << "' not found.";
981 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 986 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
982 } 987 }
  988 + lYAxis->_used = true;
983 989
984 boost::shared_ptr<Axis> lZAxis = _panel->getAxis(_iSpectroProperties->getZAxisId()); 990 boost::shared_ptr<Axis> lZAxis = _panel->getAxis(_iSpectroProperties->getZAxisId());
985 if (lZAxis.get() == nullptr) { 991 if (lZAxis.get() == nullptr) {
@@ -987,6 +993,7 @@ void InstantPlot::configureSpectroAxis() @@ -987,6 +993,7 @@ void InstantPlot::configureSpectroAxis()
987 lError << "InstantPlot::configureSpectroAxis" << ": Z axis with id '" << _iSpectroProperties->getYAxisId() << "' not found."; 993 lError << "InstantPlot::configureSpectroAxis" << ": Z axis with id '" << _iSpectroProperties->getYAxisId() << "' not found.";
988 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 994 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
989 } 995 }
  996 + lZAxis->_used = true;
990 997
991 if (_iSpectroProperties->getDimOnXAxis() == 0) 998 if (_iSpectroProperties->getDimOnXAxis() == 0)
992 { 999 {
src/ParamOutputImpl/Plot/Page.cc
@@ -316,9 +316,13 @@ void Page::writeCopywrite(std::shared_ptr&lt;plstream&gt;&amp; pls) { @@ -316,9 +316,13 @@ void Page::writeCopywrite(std::shared_ptr&lt;plstream&gt;&amp; pls) {
316 void Page::initPageParameters(std::shared_ptr<plstream>& pls) { 316 void Page::initPageParameters(std::shared_ptr<plstream>& pls) {
317 // get default margin if not set 317 // get default margin if not set
318 if (_xMargin == -1) 318 if (_xMargin == -1)
319 - _xMargin = DefaultPlotConfiguration::getInstance()._defaultPage._xMargin; 319 + calculateRelativeXMargin(_orientation, _dimension, DefaultPlotConfiguration::getInstance()._defaultPage._xMargin);
  320 + else
  321 + calculateRelativeXMargin(_orientation, _dimension, _xMargin);
320 if (_yMargin == -1) 322 if (_yMargin == -1)
321 - _yMargin = DefaultPlotConfiguration::getInstance()._defaultPage._yMargin; 323 + calculateRelativeYMargin(_orientation, _dimension, DefaultPlotConfiguration::getInstance()._defaultPage._yMargin);
  324 + else
  325 + calculateRelativeYMargin(_orientation, _dimension, _yMargin);
322 326
323 // set page size according to page format A4 or letter 327 // set page size according to page format A4 or letter
324 // offset not seams to work 328 // offset not seams to work
src/ParamOutputImpl/Plot/PanelPlotOutput.cc
@@ -173,14 +173,36 @@ void PanelPlotOutput::calculatePlotArea(Bounds&amp; bounds_) { @@ -173,14 +173,36 @@ void PanelPlotOutput::calculatePlotArea(Bounds&amp; bounds_) {
173 float leftTickMarkSpace = 0; 173 float leftTickMarkSpace = 0;
174 float rightTickMarkSpace = 0; 174 float rightTickMarkSpace = 0;
175 175
  176 + // ZAxis must be drawn at last!
  177 + std::vector<std::pair<std::string,boost::shared_ptr<Axis>>> workingAxesList;
  178 + for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end(); ++it)
  179 + {
  180 + //Add X and Y axis to the working list
  181 + boost::shared_ptr<Axis> lAxis = it->second;
  182 + if (lAxis->_isZAxis)
  183 + continue;
  184 + workingAxesList.push_back(std::pair<std::string,boost::shared_ptr<Axis>>(it->first,lAxis));
  185 + }
  186 + for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end(); ++it)
  187 + {
  188 + //Add Z axis to the working list
  189 + boost::shared_ptr<Axis> lAxis = it->second;
  190 + if (!lAxis->_isZAxis)
  191 + continue;
  192 + workingAxesList.push_back(std::pair<std::string,boost::shared_ptr<Axis>>(it->first,lAxis));
  193 + }
  194 +
176 // Get each axes information to create plot area bounds (set space for legends). 195 // Get each axes information to create plot area bounds (set space for legends).
177 - for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end(); ++it) { 196 + for (std::vector<std::pair<std::string,boost::shared_ptr<Axis>>>::iterator it = workingAxesList.begin(); it != workingAxesList.end(); ++it) {
178 197
179 boost::shared_ptr<Axis> lAxis = it->second; 198 boost::shared_ptr<Axis> lAxis = it->second;
180 199
181 if (lAxis == nullptr) 200 if (lAxis == nullptr)
182 continue; 201 continue;
183 202
  203 + if (!lAxis->_used)
  204 + continue;
  205 +
184 // Axis space legends is only took into account when axis is visible 206 // Axis space legends is only took into account when axis is visible
185 // otherwise legend is not drawn. 207 // otherwise legend is not drawn.
186 if (lAxis->_visible) { 208 if (lAxis->_visible) {
@@ -2189,7 +2211,7 @@ void PanelPlotOutput::writeContext(ContextFileWriter&amp; writer) { @@ -2189,7 +2211,7 @@ void PanelPlotOutput::writeContext(ContextFileWriter&amp; writer) {
2189 if (lAxis == nullptr) 2211 if (lAxis == nullptr)
2190 continue; 2212 continue;
2191 2213
2192 - if (lAxis->_visible) 2214 + if (lAxis->_visible && lAxis->_used)
2193 lAxis->writeContext(writer); 2215 lAxis->writeContext(writer);
2194 } 2216 }
2195 } 2217 }
@@ -2247,6 +2269,11 @@ void PanelPlotOutput::draw(double startTime, double stopTime, int intervalIndex, @@ -2247,6 +2269,11 @@ void PanelPlotOutput::draw(double startTime, double stopTime, int intervalIndex,
2247 // Sets panel plplot viewport, draw background & title for the panel 2269 // Sets panel plplot viewport, draw background & title for the panel
2248 _panel->draw(_pls); 2270 _panel->draw(_pls);
2249 2271
  2272 + if (_parameterAxesList.empty())
  2273 + {
  2274 + _pls->mtex("b", -1., 1, 1, std::string("Empty panel").c_str());
  2275 + }
  2276 +
2250 if (isFirstInterval) 2277 if (isFirstInterval)
2251 _panel->_paramsLegendProperties.reset(); 2278 _panel->_paramsLegendProperties.reset();
2252 2279
src/ParamOutputImpl/Plot/Scatter/XYPlot.cc
@@ -871,6 +871,7 @@ void XYPlot::configureSeriesAxis() { @@ -871,6 +871,7 @@ void XYPlot::configureSeriesAxis() {
871 lError << "XYPlot::configureSeriesAxis" << ": X axis with id '" << lSeriesProperties.getXAxisId() << "' not found."; 871 lError << "XYPlot::configureSeriesAxis" << ": X axis with id '" << lSeriesProperties.getXAxisId() << "' not found.";
872 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 872 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
873 } 873 }
  874 + lXAxis->_used = true;
874 875
875 Range lXRange(lXAxis->getRange()); 876 Range lXRange(lXAxis->getRange());
876 // If user didn't set a range, calculate range automatically (based on parameters values). 877 // If user didn't set a range, calculate range automatically (based on parameters values).
@@ -907,6 +908,7 @@ void XYPlot::configureSeriesAxis() { @@ -907,6 +908,7 @@ void XYPlot::configureSeriesAxis() {
907 lError << "XYPlot::configureSeriesAxis" << ": Y axis with id '" << lSeriesProperties.getYAxisId() << "' not found."; 908 lError << "XYPlot::configureSeriesAxis" << ": Y axis with id '" << lSeriesProperties.getYAxisId() << "' not found.";
908 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 909 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
909 } 910 }
  911 + lYAxis->_used = true;
910 912
911 // Configure range for Y axis. 913 // Configure range for Y axis.
912 Range lYRange(lYAxis->getRange()); 914 Range lYRange(lYAxis->getRange());
@@ -934,6 +936,7 @@ void XYPlot::configureSeriesAxis() { @@ -934,6 +936,7 @@ void XYPlot::configureSeriesAxis() {
934 { 936 {
935 if (!lSeriesProperties.getColorParamId().empty()) 937 if (!lSeriesProperties.getColorParamId().empty())
936 { 938 {
  939 + lZAxis->_used = true;
937 Range lRange(lZAxis->getRange()); 940 Range lRange(lZAxis->getRange());
938 ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId()); 941 ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
939 if (colorSerieParameterAxes == NULL) 942 if (colorSerieParameterAxes == NULL)
src/ParamOutputImpl/Plot/Time/TimePlot.cc
@@ -80,6 +80,7 @@ void TimePlot::preparePlotArea(double startTime, double stopTime, int intervalIn @@ -80,6 +80,7 @@ void TimePlot::preparePlotArea(double startTime, double stopTime, int intervalIn
80 80
81 // configure X axis 81 // configure X axis
82 getTimeAxisDecorator()->configure(this, getTimeAxis(), startTime, stopTime, _pParameterValues); 82 getTimeAxisDecorator()->configure(this, getTimeAxis(), startTime, stopTime, _pParameterValues);
  83 + getTimeAxis()->_used = true;
83 _pls->timefmt(getTimeAxisDecorator()->getPlFormat().c_str()); 84 _pls->timefmt(getTimeAxisDecorator()->getPlFormat().c_str());
84 85
85 PanelPlotOutput::preparePlotArea(startTime,stopTime,intervalIndex); 86 PanelPlotOutput::preparePlotArea(startTime,stopTime,intervalIndex);
@@ -91,7 +92,7 @@ void TimePlot::draw(double startTime, double stopTime, int intervalIndex, @@ -91,7 +92,7 @@ void TimePlot::draw(double startTime, double stopTime, int intervalIndex,
91 PanelPlotOutput::draw(startTime,stopTime,intervalIndex,isFirstInterval,isLastInterval); 92 PanelPlotOutput::draw(startTime,stopTime,intervalIndex,isFirstInterval,isLastInterval);
92 93
93 // Draw start date 94 // Draw start date
94 - if (!_startDateDrawn) 95 + if (!_startDateDrawn && getTimeAxis()->_used)
95 drawStartDate (getTimeAxis(), startTime,stopTime); 96 drawStartDate (getTimeAxis(), startTime,stopTime);
96 _startDateDrawn = true; 97 _startDateDrawn = true;
97 } 98 }
@@ -128,6 +129,7 @@ void TimePlot::configureSeriesAxis() { @@ -128,6 +129,7 @@ void TimePlot::configureSeriesAxis() {
128 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 129 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
129 } 130 }
130 131
  132 + lYAxis->_used = true;
131 Range lRange(lYAxis->getRange()); 133 Range lRange(lYAxis->getRange());
132 // If range status for this axis is set by the user do not update range "automatically". 134 // If range status for this axis is set by the user do not update range "automatically".
133 if (isnan(lRange.getMin()) && isnan(lRange.getMax())) { 135 if (isnan(lRange.getMin()) && isnan(lRange.getMax())) {
@@ -174,6 +176,7 @@ void TimePlot::configureSeriesAxis() { @@ -174,6 +176,7 @@ void TimePlot::configureSeriesAxis() {
174 { 176 {
175 if (!lSeriesProperties.getColorParamId().empty()) 177 if (!lSeriesProperties.getColorParamId().empty())
176 { 178 {
  179 + lZAxis->_used = true;
177 Range lRange(lZAxis->getRange()); 180 Range lRange(lZAxis->getRange());
178 ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId()); 181 ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
179 if (colorSerieParameterAxes == NULL) 182 if (colorSerieParameterAxes == NULL)
@@ -238,6 +241,8 @@ void TimePlot::configureSpectroAxis() { @@ -238,6 +241,8 @@ void TimePlot::configureSpectroAxis() {
238 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 241 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
239 } 242 }
240 243
  244 + lYAxis->_used = true;
  245 +
241 //set Z axis range 246 //set Z axis range
242 boost::shared_ptr<Axis> lZAxis = _panel->getAxis(spectroPropertiesPtr->getZAxisId()); 247 boost::shared_ptr<Axis> lZAxis = _panel->getAxis(spectroPropertiesPtr->getZAxisId());
243 if (lZAxis.get() == nullptr) { 248 if (lZAxis.get() == nullptr) {
@@ -246,6 +251,8 @@ void TimePlot::configureSpectroAxis() { @@ -246,6 +251,8 @@ void TimePlot::configureSpectroAxis() {
246 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str())); 251 BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
247 } 252 }
248 253
  254 + lZAxis->_used = true;
  255 +
249 ParameterSPtr p = _parameterManager.getParameter(param._originalParamId); 256 ParameterSPtr p = _parameterManager.getParameter(param._originalParamId);
250 int parameterDimension; 257 int parameterDimension;
251 if (spectroPropertiesPtr->getRelatedDim() == 0) 258 if (spectroPropertiesPtr->getRelatedDim() == 0)
@@ -947,7 +954,7 @@ void TimePlot::drawSpectro(double startDate, double stopDate, std::string pParam @@ -947,7 +954,7 @@ void TimePlot::drawSpectro(double startDate, double stopDate, std::string pParam
947 void TimePlot::drawStartDate(TimeAxis* pXAxis, double startTime, double stopTime) { 954 void TimePlot::drawStartDate(TimeAxis* pXAxis, double startTime, double stopTime) {
948 LOG4CXX_DEBUG(gLogger, "Drawing start date."); 955 LOG4CXX_DEBUG(gLogger, "Drawing start date.");
949 956
950 - if (pXAxis->_showTickMark == false) 957 + if (pXAxis->_showTickMark == false || !pXAxis->_drawn || !pXAxis->_visible)
951 return; 958 return;
952 959
953 // use panel font to draw start date. 960 // use panel font to draw start date.