Commit af253df26107243bb5edfe3b57eff08156bf835f

Authored by Benjamin Renard
1 parent 0f321c54

First step for rework of tickplot legend

src/ParamOutputImpl/Plot/TickPlot/TickMarkDecorator.cc
... ... @@ -212,27 +212,6 @@ void TickMarkDecorator::draw(PanelPlotOutput* pplot_, Axis* axis_,
212 212 // draw a virtual axis for each entry // take into account plot orientation
213 213 TimeAxis* pAxis = (TimeAxis*) axis_;
214 214  
215   - // Get plot area viewport.
216   - Bounds vpBounds;
217   - PLFLT lXMin, lXMax, lYMin, lYMax;
218   - pls_->gvpd(lXMin, lXMax, lYMin, lYMax);
219   - vpBounds._x = lXMin;
220   - vpBounds._y = lYMin;
221   - vpBounds._width = lXMax - lXMin;
222   - vpBounds._height = lYMax - lYMin;
223   -
224   - // get windows
225   - Bounds winBounds;
226   - PLFLT xwmin, xwmax, ywmin, ywmax;
227   - pls_->gvpw(xwmin, xwmax, ywmin, ywmax);
228   - winBounds._x = xwmin;
229   - winBounds._y = ywmin;
230   - winBounds._width = xwmax - xwmin;
231   - winBounds._height = ywmax - ywmin;
232   -
233   - LOG4CXX_DEBUG(_logger, " viewport :"<<vpBounds.toString());
234   - LOG4CXX_DEBUG(_logger, " window :"<<winBounds.toString());
235   -
236 215 // tick configuration for this axis :
237 216 double xtick = getMajorTickSpace(pAxis, pAxis->getRange().getMin(),
238 217 pAxis->getRange().getMax());
... ... @@ -270,21 +249,18 @@ void TickMarkDecorator::draw(PanelPlotOutput* pplot_, Axis* axis_,
270 249 PlPlotUtil::setPlFont(legendFont);
271 250 CharSize legendCharSize = PlPlotUtil::getCharacterSizeInPlPage(pplot_->_panel->_page);
272 251  
273   - // delta is negative when axis is at bottom (which is the default case). positive otherwise.
274   - // (viewport origin is in the left bottom corner of the page).
275   - double yDelta = -legendCharSize.second * 2;
  252 + double yInc = legendCharSize.second * 1.2;
276 253  
277 254 std::string options = "";
278 255 int start;
279 256 int end;
280 257 int dir;
  258 + double yDelta = 0;
281 259  
282 260 PlPlotUtil::setPlFont(legendFont);
283 261  
284 262 if (pAxis->_position == PlotCommon::POS_TOP) {
285 263 options = "mxo"; // options means : m=display above axe, x=do not plot ticks, o=user label function provided.
286   - yDelta = -yDelta; // if axis is displayed on top of graph we have to use an inverse translation delta.
287   - // reverse direction :
288 264 start = _seriesInfoList.size() - 1;
289 265 end = -1;
290 266 dir = -1;
... ... @@ -294,51 +270,52 @@ void TickMarkDecorator::draw(PanelPlotOutput* pplot_, Axis* axis_,
294 270 end = _seriesInfoList.size();
295 271 dir = 1;
296 272 }
297   - LOG4CXX_DEBUG(_logger, " viewport translation:"<<yDelta);
298   - LOG4CXX_DEBUG(_logger, " virtual axis options:"<<options);
299 273  
300   - // store initial delta, as it is also the increment to add to delta at each new serie (see below).
301   - double yInc = yDelta;
  274 + yDelta = yInc * dir;
302 275  
303   - // at this point, we change viewport to be able to plot each virtual axis
304   - // (only labels are plotted)...
305   -
306   - // We need to take into account tick length.
307   - if (pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
308   - // set room for tick, tickmarks (graduation) and extra space between tickmarks (graduation) and data time.
309   - yDelta = getVerticalTickLength(pAxis, panelCharSize.second) + yDelta + (0.5 * yInc);
310   - } else {
311   - // for the first serie, we add an extra space (half of yInc) to add a sepration with time labels
312   - yDelta = yDelta + (0.5 * yInc);
313   - }
  276 + LOG4CXX_DEBUG(_logger, " viewport translation:"<<yDelta);
  277 + LOG4CXX_DEBUG(_logger, " virtual axis options:"<<options);
314 278  
315 279 for (int i = start; i != end; i += dir) {
316 280 LOG4CXX_TRACE(_logger, " virtual axis ["<<i<<"]");
317 281 // install label generator specific for that virtual axis
318 282 pls_->slabelfunc(generateYLabel, _seriesInfoList[i].get());
319   - // translate viewport :
320   - pls_->vpor(vpBounds._x, vpBounds._x + vpBounds._width,
321   - vpBounds._y + yDelta, vpBounds._y + vpBounds._height + yDelta);
322   - // sets windows for new viewport :
323   - pls_->wind(winBounds._x, winBounds._x + winBounds._width, winBounds._y,
324   - winBounds._y + winBounds._height);
325   - pls_->box(options.c_str(), xtick, nxsub, "", 0, 0);
326   -
  283 + // draw virtual axis
  284 + drawVirtualAxis(yDelta * dir, yInc, _seriesInfoList[i]->_name.c_str(), xtick, nxsub, options.c_str(), pls_);
  285 + // increment offset
327 286 yDelta = yDelta + yInc;
328   -
329 287 }
330 288  
331   - // restore viewport.
332   - pls_->vpor(vpBounds._x, vpBounds._x + vpBounds._width, vpBounds._y,
333   - vpBounds._y + vpBounds._height);
334   -
335   - // restore window
336   - pls_->wind(winBounds._x, winBounds._x + winBounds._width, winBounds._y,
337   - winBounds._y + winBounds._height);
338   -
339 289 // Restore initial color.
340 290 restoreColor(pls_, lInitialColor, pplot_->_panel->_page->_mode);
  291 +}
  292 +
  293 +void TickMarkDecorator::drawVirtualAxis(double offset, double height, const char* legend, double xtick, int nxsub, const char* options, std::shared_ptr<plstream> pls_) {
  294 + // Get plot area viewport
  295 + PLFLT lXMin, lXMax, lYMin, lYMax;
  296 + pls_->gvpd(lXMin, lXMax, lYMin, lYMax);
341 297  
  298 + // Get window
  299 + PLFLT xwmin, xwmax, ywmin, ywmax;
  300 + pls_->gvpw(xwmin, xwmax, ywmin, ywmax);
  301 +
  302 + // translate viewport :
  303 + pls_->vpor(lXMin, lXMax, lYMin - offset, lYMin - offset + height);
  304 +
  305 + // sets windows for new viewport :
  306 + pls_->wind(xwmin, xwmax, 0, 1);
  307 +
  308 + // draw virtual axis
  309 + pls_->box(options, xtick, nxsub, "", 0, 0);
  310 +
  311 + // draw legend
  312 + pls_->mtex("lv", 3, -1, 1, legend);
  313 +
  314 + // restore viewport
  315 + pls_->vpor(lXMin, lXMax, lYMin, lYMax);
  316 +
  317 + // restore window
  318 + pls_->wind(xwmin, xwmax, ywmin, ywmax);
342 319 }
343 320  
344 321 void TickMarkDecorator::installLabelGenerator(PanelPlotOutput* /*pplot_*/, TimeAxis* timeAxis_) {
... ... @@ -432,39 +409,28 @@ void generateYLabel(PLINT axis, PLFLT value, char *label, PLINT length,
432 409 return;
433 410 }
434 411 SeriesInfo* pInfo = static_cast<SeriesInfo*> (data);
435   - // if value equals min, display _name string
436   - // otherwise, format value and display it
437   - if (pInfo->_isFirstLabel) {
438   - // do not display min value label
439   - // but display title :
440   - snprintf(label, length, "%*s", pInfo->_maxLen,
441   - pInfo->_name.c_str());
442   - pInfo->_isFirstLabel = false;
443   - } else {
444   - // display formatted value
445   - std::ostringstream labels;
446   -
447   - //get nearest value
448   - double crtTime = (double) value;
449   -
450   - int crtIndex = pInfo->_parameterData->indexOf(crtTime);
451   -
452   - if (crtIndex == -1 && (crtTime - (pInfo->_parameterData->getTimes()[pInfo->_parameterData->getSize()-1]) < pInfo->_parameterData->getParamGapSize()))
453   - //Fix last value
454   - crtIndex = pInfo->_parameterData->getSize()-1;
455   - else if ((crtTime - (pInfo->_parameterData->getTimes()[crtIndex])) > pInfo->_parameterData->getParamGapSize())
456   - //Be sure that we are not in a data gap
457   - crtIndex = -1;
458   -
459   - if (crtIndex == -1) {
460   - labels << "NaN" << std::endl;
461   - }
462   - else {
463   - labels << boost::format(pInfo->_valuesFormat) % (*pInfo->_parameterData->getValues(pInfo->_indexComponents, crtIndex));
464   - }
  412 + // display formatted value
  413 + std::ostringstream labels;
465 414  
466   - snprintf(label, length, "%s", labels.str().c_str());
  415 + //get nearest value
  416 + double crtTime = (double) value;
  417 +
  418 + int crtIndex = pInfo->_parameterData->indexOf(crtTime);
  419 +
  420 + if (crtIndex == -1 && (crtTime - (pInfo->_parameterData->getTimes()[pInfo->_parameterData->getSize()-1]) < pInfo->_parameterData->getParamGapSize()))
  421 + //Fix last value
  422 + crtIndex = pInfo->_parameterData->getSize()-1;
  423 + else if ((crtTime - (pInfo->_parameterData->getTimes()[crtIndex])) > pInfo->_parameterData->getParamGapSize())
  424 + //Be sure that we are not in a data gap
  425 + crtIndex = -1;
  426 +
  427 + if (crtIndex == -1) {
  428 + labels << "NaN" << std::endl;
  429 + }
  430 + else {
  431 + labels << boost::format(pInfo->_valuesFormat) % (*pInfo->_parameterData->getValues(pInfo->_indexComponents, crtIndex));
467 432 }
  433 + snprintf(label, length, "%s", labels.str().c_str());
468 434 }
469 435 }
470 436  
... ... @@ -481,35 +447,23 @@ void generateOrbitTimeLabel(PLINT axis, PLFLT value, char *label, PLINT length,
481 447 return;
482 448 }
483 449 TimeInfo* pInfo = static_cast<TimeInfo*> (data);
484   - // get time format and min value
485   - // if value equals min, display an empty string
486   - // otherwise, format time and display formatted time
487   -
488   - if (pInfo->_isFirstLabel) {
489   - // do not display min value label
490   - // but display title :
491   - snprintf(label, length, "%*s", pInfo->_maxLen,
492   - pInfo->_timeTitle.c_str());
493   - pInfo->_isFirstLabel = false;
494   -
495   - } else {
496   - // display formatted time
497   - std::string timeFormatstr = pInfo->_timeFormat.c_str();
498   - char *timeFormat = new char[timeFormatstr.length() + 1];
499   - strcpy(timeFormat, timeFormatstr.c_str());
500   -
501   - if (TimePlot::qsasconfig == NULL) {
502   - configqsas(1. / 86400., 0., 0., 0x0, 1, 1970, 0, 1, 0, 0, 0.,
503   - &TimePlot::qsasconfig);
504   - }
505   - char formattedTime[40];
506 450  
507   - strfqsas(formattedTime, 40, timeFormat, (double) value,
508   - TimePlot::qsasconfig);
509   - delete[] timeFormat;
  451 + // display formatted time
  452 + std::string timeFormatstr = pInfo->_timeFormat.c_str();
  453 + char *timeFormat = new char[timeFormatstr.length() + 1];
  454 + strcpy(timeFormat, timeFormatstr.c_str());
510 455  
511   - snprintf(label, length, "%s", formattedTime);
  456 + if (TimePlot::qsasconfig == NULL) {
  457 + configqsas(1. / 86400., 0., 0., 0x0, 1, 1970, 0, 1, 0, 0, 0.,
  458 + &TimePlot::qsasconfig);
512 459 }
  460 + char formattedTime[40];
  461 +
  462 + strfqsas(formattedTime, 40, timeFormat, (double) value,
  463 + TimePlot::qsasconfig);
  464 + delete[] timeFormat;
  465 +
  466 + snprintf(label, length, "%s", formattedTime);
513 467 }
514 468 }
515 469  
... ...
src/ParamOutputImpl/Plot/TickPlot/TickMarkDecorator.hh
... ... @@ -127,6 +127,11 @@ protected:
127 127 private:
128 128  
129 129 /**
  130 + * @brief Draw virtual axis
  131 + */
  132 + void drawVirtualAxis(double offset, double height, const char* legend, double xtick, int nxsub, const char* options, std::shared_ptr<plstream> pls_);
  133 +
  134 + /**
130 135 * @brief Calculates plot area for date display
131 136 */
132 137 double computeStartDateWidth(PanelPlotOutput* pplot_, TimeAxis* pAxis_);
... ...