Blame view

src/ParamOutputImpl/Plot/TickPlot/TickMarkDecorator.cc 16.5 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
 * TickMarkDecorator.cc
 *
 *  Created on: Dec 18, 2013
 *      Author: amdadev
 */

#include "TickMarkDecorator.hh"

#include <iosfwd>
#include <boost/format.hpp>
#include <tuple>

#include "log4cxx/logger.h"
#include "plplot/plplot.h"

#include "boost/exception/all.hpp"

#include "PlotLogger.hh"
#include "TimeAxis.hh"
#include "Page.hh"
#include "Time/TimePlot.hh"
#include "TickPlot.hh"
f6eaec4e   Benjamin Renard   Optimize plot ele...
24
#include "PlPlotUtil.hh"
505546bc   Benjamin Renard   Tickplot: compone...
25
#include "ParamMgr.hh"
fbe3c2bb   Benjamin Renard   First commit
26
27
28
29
30
31
32
33

using boost::tuples::get;

namespace plot {

log4cxx::LoggerPtr TickMarkDecorator::_logger(
		log4cxx::Logger::getLogger("AMDA-Kernel.Plot.Time.TickMarkDecorator"));

8c860e4f   Benjamin Renard   Rework for tickpl...
34
TickMarkDecorator::TickMarkDecorator (PanelPlotOutput* decoratorPlot) :
fbe3c2bb   Benjamin Renard   First commit
35
		TimeAxisDecorator(),
fbe3c2bb   Benjamin Renard   First commit
36
		_valuesFormat("% -4.4G"),
fbe3c2bb   Benjamin Renard   First commit
37
38
39
40
41
		_decoratorPlot(decoratorPlot) {
	_pTimeInfo = TimeInfoPtr(new TimeInfo());
}

TickMarkDecorator::TickMarkDecorator(const TickMarkDecorator& ref_) :
8c860e4f   Benjamin Renard   Rework for tickpl...
42
43
		TimeAxisDecorator(ref_), _tickInfoList(ref_._tickInfoList), _valuesFormat(ref_._valuesFormat),
		_decoratorPlot(	ref_._decoratorPlot) {
fbe3c2bb   Benjamin Renard   First commit
44
45
46
47
48
49
50
51
52
53
	_pTimeInfo = TimeInfoPtr(new TimeInfo(*(ref_._pTimeInfo)));
}

TickMarkDecorator& TickMarkDecorator::operator=(const TickMarkDecorator& ref_) {
	if (_pTimeInfo == nullptr) {
		_pTimeInfo = boost::shared_ptr<TimeInfo>(
				new TimeInfo(*(ref_._pTimeInfo)));
	} else {
		_pTimeInfo->_timeFormat = ref_._pTimeInfo->_timeFormat;
		_pTimeInfo->_timeTitle = ref_._pTimeInfo->_timeTitle;
fbe3c2bb   Benjamin Renard   First commit
54
	}
8c860e4f   Benjamin Renard   Rework for tickpl...
55
	_tickInfoList = ref_._tickInfoList;
fbe3c2bb   Benjamin Renard   First commit
56
	_valuesFormat = ref_._valuesFormat;
fbe3c2bb   Benjamin Renard   First commit
57
58
59
60
61
62
63
64
	_decoratorPlot = ref_._decoratorPlot;

	return *this;
}

TickMarkDecorator::~TickMarkDecorator() {
}

8c860e4f   Benjamin Renard   Rework for tickpl...
65
void TickMarkDecorator::updatePlotArea(PanelPlotOutput* pplot_, Axis* axis_, const Bounds& panelBounds_, Bounds& bounds_) {
fbe3c2bb   Benjamin Renard   First commit
66
67
68
69
70

	LOG4CXX_DEBUG(_logger, "TickMarkDecorator Updating plot area : "<<bounds_.toString());

	TimeAxis* pAxis = (TimeAxis*) axis_;

fbe3c2bb   Benjamin Renard   First commit
71
	// calculate char size for labels:
8c860e4f   Benjamin Renard   Rework for tickpl...
72
	Font legendFont(axis_->getLegendFont(pplot_->_panel.get()));
f6eaec4e   Benjamin Renard   Optimize plot ele...
73
74
	PlPlotUtil::setPlFont(legendFont);
	CharSize legendSize = PlPlotUtil::getCharacterSizeInPlPage(pplot_->_panel->_page);
fbe3c2bb   Benjamin Renard   First commit
75

8c860e4f   Benjamin Renard   Rework for tickpl...
76
77
78
79
	// update top and bottom space
	if (_decoratorPlot->isStandalone()) {
		bounds_._y += (bounds_._height + legendSize.second * 1.2) ;
		bounds_._height = legendSize.second * 1.2;
fbe3c2bb   Benjamin Renard   First commit
80
	}
8c860e4f   Benjamin Renard   Rework for tickpl...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	else {
		int tickLines = 0;
		for (TickParamInfoList::iterator it = _tickInfoList.begin(); it != _tickInfoList.end(); ++it) {
			tickLines += it->_indexesInfo.size();
			bool isScalar = (it->_indexesInfo.size() == 1) && (it->_indexesInfo[0]._index.getDim1Index() == -1) && (it->_indexesInfo[0]._index.getDim2Index() == -1);
			std::string description = getTickParamDescription(it->_paramId, isScalar);
			if (!description.empty()) {
				++tickLines;
			}
		}
		double tickLinesHeight = tickLines * legendSize.second * 1.2;
		if (pAxis->_position == PlotCommon::POS_BOTTOM) {
			bounds_._y += tickLinesHeight;
		}
		bounds_._height -= tickLinesHeight;
fbe3c2bb   Benjamin Renard   First commit
96
	}
8c860e4f   Benjamin Renard   Rework for tickpl...
97
98
99
100
101
102
103
104
105
106
107
108
109
110

	double maxWidth = 0;
	for (TickParamInfoList::iterator it = _tickInfoList.begin(); it != _tickInfoList.end(); ++it) {
		bool isScalar = (it->_indexesInfo.size() == 1) && (it->_indexesInfo[0]._index.getDim1Index() == -1) && (it->_indexesInfo[0]._index.getDim2Index() == -1);
		std::string description = getTickParamDescription(it->_paramId, isScalar);
		if (!description.empty()) {
			double descWidth = PlPlotUtil::getTextWidthInPlPage(pplot_->_panel->_page, description.c_str());
			maxWidth = std::max(maxWidth, descWidth);
		}
		for (std::vector<TickParamIndexInfo>::iterator itIndex = it->_indexesInfo.begin(); itIndex != it->_indexesInfo.end(); ++itIndex) {
			std::string label = getTickParamLabel(it->_paramId, (*itIndex)._index);
			double labelWidth = PlPlotUtil::getTextWidthInPlPage(pplot_->_panel->_page, label.c_str());
			maxWidth = std::max(maxWidth, labelWidth);
		}
fbe3c2bb   Benjamin Renard   First commit
111
112
	}

8c860e4f   Benjamin Renard   Rework for tickpl...
113
114
115
	if (_pTimeInfo->_pAxis->_showTickMark) {
		double width = PlPlotUtil::getTextWidthInPlPage(pplot_->_panel->_page, _pTimeInfo->_timeTitle.c_str());
		maxWidth = std::max(maxWidth, width);
fbe3c2bb   Benjamin Renard   First commit
116
117
	}

8c860e4f   Benjamin Renard   Rework for tickpl...
118
119
120
121
122
123
124
	PLFLT lDefaultCharHeight, lCurrentCharHeight;
	plgchr(&lDefaultCharHeight, &lCurrentCharHeight);
	maxWidth += 6 * lCurrentCharHeight / (std::get < 0 > (pplot_->_panel->_page->getSizeInMm()) * (pplot_->_panel->_page->_dpi / 90.));

	if (_decoratorPlot->isStandalone()) {
		bounds_._x += maxWidth;
		bounds_._width -= maxWidth;
fbe3c2bb   Benjamin Renard   First commit
125
	}
8c860e4f   Benjamin Renard   Rework for tickpl...
126
127
128
	else if (bounds_._x - panelBounds_._x < maxWidth) {
		bounds_._width -= (maxWidth - bounds_._x + panelBounds_._x);
		bounds_._x += (maxWidth - bounds_._x + panelBounds_._x);
fbe3c2bb   Benjamin Renard   First commit
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
	}

	LOG4CXX_DEBUG(_logger, "Updated plot area : "<<bounds_.toString());
}

double TickMarkDecorator::computeStartDateWidth(PanelPlotOutput* pplot_,
		TimeAxis* pAxis_) {
	// not very efficient ...
	long int lTime = static_cast<long int>(pAxis_->getRange().getMin());
	tm * lTimeTm = gmtime(&lTime);
	char lTimeChr[80];

	// Format date.
	size_t datelen =
			strftime(lTimeChr, 80,
					getPlStartTimeFormat(pAxis_->_timeFormat,
							pAxis_->getRange().getMin(),
							pAxis_->getRange().getMax()).c_str(), lTimeTm);
f6eaec4e   Benjamin Renard   Optimize plot ele...
147
148
	PlPlotUtil::setPlFont(pplot_->_panel->getFont());
	CharSize fontSize = PlPlotUtil::getCharacterSizeInPlPage(pplot_->_panel->_page);
fbe3c2bb   Benjamin Renard   First commit
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
	return fontSize.first * datelen;
}

void TickMarkDecorator::configure(PanelPlotOutput* pplot_, Axis* axis_, double start_,
		double stop_, std::map<std::string, ParameterData> *pParameterValues) {
	LOG4CXX_DEBUG(_logger, "TickMarkDecorator::configure");
	_pParameterValues = pParameterValues;

	// retrieve time axis
	TimeAxis* pTimeAxis = (TimeAxis*) axis_;

	// configure x axis range
	pTimeAxis->setRange(start_, stop_);

	// show xAxis or not
8c860e4f   Benjamin Renard   Rework for tickpl...
164
	pTimeAxis->setOnlyTickmarks(_decoratorPlot->isStandalone());
fbe3c2bb   Benjamin Renard   First commit
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184

	setPlFormat(
			getPlTimeFormat(pTimeAxis->_timeFormat,
					pTimeAxis->getRange().getMin(),
					pTimeAxis->getRange().getMax(),
					getMajorTickNumber(pTimeAxis,
							pTimeAxis->getRange().getMin(),
							pTimeAxis->getRange().getMax())));

	// install label generator
	installLabelGenerator(pplot_, pTimeAxis);

}

void TickMarkDecorator::draw(PanelPlotOutput* pplot_, Axis* axis_,
		std::shared_ptr<plstream> pls_) {

	// draw a virtual axis for each entry // take into account plot orientation
	TimeAxis* pAxis = (TimeAxis*) axis_;

fbe3c2bb   Benjamin Renard   First commit
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
	// tick configuration for this axis :
	double xtick = getMajorTickSpace(pAxis, pAxis->getRange().getMin(),
			pAxis->getRange().getMax());
	int nxsub = getMinorTickNumber(pAxis, pAxis->getRange().getMin(),
			pAxis->getRange().getMax(), xtick);

	// set color for drawing axis :
	Color lInitialColor = changeColor(pls_, pAxis->_color,
			pplot_->_panel->_page->_mode);

	// Set tick (major and minor) length factor
	PLFLT lTickLenFact = PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR;
	if (!isnan(pAxis->_tick._lengthFactor)) {
		lTickLenFact = pAxis->_tick._lengthFactor;
	}
	// 0 => keep tick height in millimeters.
	pls_->smaj(0, lTickLenFact);
	pls_->smin(0, lTickLenFact);

	// Set font to draw axes.
8c860e4f   Benjamin Renard   Rework for tickpl...
205
206
	Font legendFont(axis_->getLegendFont(pplot_->_panel.get()));
        PlPlotUtil::setPlFont(legendFont);
f6eaec4e   Benjamin Renard   Optimize plot ele...
207
	CharSize legendCharSize = PlPlotUtil::getCharacterSizeInPlPage(pplot_->_panel->_page);
fbe3c2bb   Benjamin Renard   First commit
208

af253df2   Benjamin Renard   First step for re...
209
	double yInc = legendCharSize.second * 1.2;
fbe3c2bb   Benjamin Renard   First commit
210
211
212
213
214

	std::string options = "";
	int start;
	int end;
	int dir;
86a2f0f0   Benjamin Renard   Tickbar at top of...
215
	bool top = (pAxis->_position == PlotCommon::POS_TOP);
f6eaec4e   Benjamin Renard   Optimize plot ele...
216

86a2f0f0   Benjamin Renard   Tickbar at top of...
217
	if (top) {
fbe3c2bb   Benjamin Renard   First commit
218
		options = "mxo"; // options means : m=display above axe, x=do not plot ticks, o=user label function provided.
8c860e4f   Benjamin Renard   Rework for tickpl...
219
		start = _tickInfoList.size() - 1;
fbe3c2bb   Benjamin Renard   First commit
220
221
		end = -1;
		dir = -1;
fbe3c2bb   Benjamin Renard   First commit
222
223
224
	} else {
		options = "nxo";// options means : n=display below axe, x=do not plot ticks, o=user label function provided.
		start = 0;
8c860e4f   Benjamin Renard   Rework for tickpl...
225
		end = _tickInfoList.size();
fbe3c2bb   Benjamin Renard   First commit
226
		dir = 1;
fbe3c2bb   Benjamin Renard   First commit
227
	}
fbe3c2bb   Benjamin Renard   First commit
228

8c860e4f   Benjamin Renard   Rework for tickpl...
229
230
231
	// Get plot area viewport
	PLFLT lXMin, lXMax, lYMin, lYMax;
	pls_->gvpd(lXMin, lXMax, lYMin, lYMax);
06e9bdd5   Benjamin Renard   Improve tickplot ...
232

8c860e4f   Benjamin Renard   Rework for tickpl...
233
234
235
	// Get window
	PLFLT xwmin, xwmax, ywmin, ywmax;
	pls_->gvpw(xwmin, xwmax, ywmin, ywmax);
06e9bdd5   Benjamin Renard   Improve tickplot ...
236

8c860e4f   Benjamin Renard   Rework for tickpl...
237
	double position = top ? lYMax - yInc : lYMin;
06e9bdd5   Benjamin Renard   Improve tickplot ...
238

8c860e4f   Benjamin Renard   Rework for tickpl...
239
240
	for (int i = start; i != end; i += dir) {
		if ((i == start) && _pTimeInfo->_pAxis->_showTickMark) {
06e9bdd5   Benjamin Renard   Improve tickplot ...
241
			//Draw time axis legend
8c860e4f   Benjamin Renard   Rework for tickpl...
242
			pls_->vpor(lXMin, lXMax, position, position + yInc);
06e9bdd5   Benjamin Renard   Improve tickplot ...
243
244
			pls_->wind(xwmin, xwmax, 0, 1);
			pls_->mtex("lv", 4, top ? 2 : -1, 1, _pTimeInfo->_timeTitle.c_str());
8c860e4f   Benjamin Renard   Rework for tickpl...
245
			position -= dir*yInc;
86a2f0f0   Benjamin Renard   Tickbar at top of...
246
		}
fbe3c2bb   Benjamin Renard   First commit
247

af253df2   Benjamin Renard   First step for re...
248

8c860e4f   Benjamin Renard   Rework for tickpl...
249
250
251
252
253
254
255
		bool isScalar = (_tickInfoList[i]._indexesInfo.size() == 1) && (_tickInfoList[i]._indexesInfo[0]._index.getDim1Index() == -1) && (_tickInfoList[i]._indexesInfo[0]._index.getDim2Index() == -1);
		std::string description = getTickParamDescription(_tickInfoList[i]._paramId, isScalar);
		int startIndex = 0;
		int endIndex   = _tickInfoList[i]._indexesInfo.size();
		if (top) {
			startIndex = _tickInfoList[i]._indexesInfo.size()-1;
			endIndex = -1;
06e9bdd5   Benjamin Renard   Improve tickplot ...
256
		}
8c860e4f   Benjamin Renard   Rework for tickpl...
257
258
259
260
261
262
263
264
265
266
		for (int j = startIndex; j != endIndex; j += dir) {
			if ((j == 0) && !description.empty()) {
				// Draw description
				pls_->vpor(lXMin, lXMax, top ? position + yInc : position, top ? position + 2*yInc : position + yInc);
				pls_->wind(xwmin, xwmax, 0, 1);
				pls_->mtex("lv", 4, top ? 2 : -1, 1, description.c_str());
				if (!top) {
					position -= dir*yInc;
				}
			}
af253df2   Benjamin Renard   First step for re...
267

8c860e4f   Benjamin Renard   Rework for tickpl...
268
269
			pls_->vpor(lXMin, lXMax, position, position + yInc);
			pls_->wind(xwmin, xwmax, 0, 1);
06e9bdd5   Benjamin Renard   Improve tickplot ...
270
		
8c860e4f   Benjamin Renard   Rework for tickpl...
271
272
			// install label generator specific for that virtual axis
			pls_->slabelfunc(generateTickSerieLabel, &_tickInfoList[i]._indexesInfo[j]);
af253df2   Benjamin Renard   First step for re...
273

8c860e4f   Benjamin Renard   Rework for tickpl...
274
275
			// draw virtual axis
			pls_->box(options.c_str(), xtick, nxsub, "", 0, 0);
af253df2   Benjamin Renard   First step for re...
276

8c860e4f   Benjamin Renard   Rework for tickpl...
277
278
279
			// draw legend
			std::string label = getTickParamLabel(_tickInfoList[i]._paramId, _tickInfoList[i]._indexesInfo[j]._index);
			pls_->mtex("lv", 4, top ? 2 : -1, 1, label.c_str());
af253df2   Benjamin Renard   First step for re...
280

8c860e4f   Benjamin Renard   Rework for tickpl...
281
282
			// restore viewport
			pls_->vpor(lXMin, lXMax, lYMin, lYMax);
af253df2   Benjamin Renard   First step for re...
283

8c860e4f   Benjamin Renard   Rework for tickpl...
284
285
			// restore window
			pls_->wind(xwmin, xwmax, ywmin, ywmax);
af253df2   Benjamin Renard   First step for re...
286

8c860e4f   Benjamin Renard   Rework for tickpl...
287
288
289
290
291
292
			// increment offset
			position -= dir*yInc;
			if (top && (j == 0) && !description.empty()) {
				position -= dir*yInc;
			}
		}
06e9bdd5   Benjamin Renard   Improve tickplot ...
293
294
295
296
	}

	// Restore initial color.
	restoreColor(pls_, lInitialColor, pplot_->_panel->_page->_mode);
fbe3c2bb   Benjamin Renard   First commit
297
}
fbe3c2bb   Benjamin Renard   First commit
298
299
300
301
302

void TickMarkDecorator::installLabelGenerator(PanelPlotOutput* /*pplot_*/, TimeAxis* timeAxis_) {

	LOG4CXX_TRACE(_logger, "installing LabelGenerator function");
	// axis label :
df45df5e   Benjamin Renard   Introduce AxisLeg...
303
	LOG4CXX_TRACE(_logger, "processing axis : "<< timeAxis_->_legend.getText());
fbe3c2bb   Benjamin Renard   First commit
304
305
	// install time format
	_pTimeInfo->_timeFormat = getPlFormat();
df45df5e   Benjamin Renard   Introduce AxisLeg...
306
	_pTimeInfo->_timeTitle = timeAxis_->_legend.getText();
fbe3c2bb   Benjamin Renard   First commit
307

8c860e4f   Benjamin Renard   Rework for tickpl...
308
309
	_pTimeInfo->_pAxis = timeAxis_;

fbe3c2bb   Benjamin Renard   First commit
310
311
312
313
314
	// init maximum value len with formatted time :
	if (TimePlot::qsasconfig == NULL) {
		configqsas(1. / 86400., 0., 0., 0x0, 1, 1970, 0, 1, 0, 0, 0.,
				&TimePlot::qsasconfig);
	}
fbe3c2bb   Benjamin Renard   First commit
315
316

	// build all series names :
8c860e4f   Benjamin Renard   Rework for tickpl...
317
	_tickInfoList.clear();
fbe3c2bb   Benjamin Renard   First commit
318
	for (auto p : _decoratorPlot->_parameterAxesList) {
8c860e4f   Benjamin Renard   Rework for tickpl...
319
		LOG4CXX_DEBUG(_logger, " inspecting parameter : " << p._originalParamId);
2fc1f2f8   Benjamin Renard   Full rework for s...
320
		for(auto lSeriesProperties : p.getYSeriePropertiesList()) {
8c860e4f   Benjamin Renard   Rework for tickpl...
321
322
323
324
325
326
327
328
329
330
331
332
333
			TickParamInfo* paramInfoPtr = NULL;
			for (TickParamInfoList::iterator it = _tickInfoList.begin(); it != _tickInfoList.end(); ++it) {
				if (it->_paramId.compare(lSeriesProperties.getParamId()) == 0) {
					paramInfoPtr = &(*it);
					break;
				}
			}
			if (paramInfoPtr == NULL) {
				TickParamInfo paramInfo;
				paramInfo._paramId = lSeriesProperties.getParamId();
				_tickInfoList.push_back(paramInfo);
				paramInfoPtr = &(_tickInfoList[_tickInfoList.size()-1]);
			}
2fc1f2f8   Benjamin Renard   Full rework for s...
334
			for (auto index : lSeriesProperties.getIndexList(_pParameterValues)) {
8c860e4f   Benjamin Renard   Rework for tickpl...
335
336
337
338
				TickParamIndexInfo* paramIndexInfoPtr = NULL;
				for (std::vector<TickParamIndexInfo>::iterator indexIt = paramInfoPtr->_indexesInfo.begin(); indexIt != paramInfoPtr->_indexesInfo.end(); ++indexIt) {
					if (indexIt->_index == index) {
						paramIndexInfoPtr = &(*indexIt);
505546bc   Benjamin Renard   Tickplot: compone...
339
					}
46858100   Benjamin Renard   Tickplot: Add mis...
340
				}
8c860e4f   Benjamin Renard   Rework for tickpl...
341
342
343
344
345
346
347
				if (paramIndexInfoPtr == NULL) {
					TickParamIndexInfo indexInfo;
					indexInfo._valuesFormat = getValuesFormat();
					indexInfo._parameterData = &((*_pParameterValues)[lSeriesProperties.getParamId()]);
					indexInfo._index = AMDA::Common::ParameterIndexComponent(index.getDim1Index(),index.getDim2Index());
					paramInfoPtr->_indexesInfo.push_back(indexInfo);
					
505546bc   Benjamin Renard   Tickplot: compone...
348
				}
8c860e4f   Benjamin Renard   Rework for tickpl...
349
350
351
			}
		}
	}
505546bc   Benjamin Renard   Tickplot: compone...
352

8c860e4f   Benjamin Renard   Rework for tickpl...
353
354
	// no legend for this axe since it is displayed at axis origin:
	timeAxis_->_legend.clearLabels();
46858100   Benjamin Renard   Tickplot: Add mis...
355

8c860e4f   Benjamin Renard   Rework for tickpl...
356
357
358
359
	// install label generator for main axe (the one that is displayed)
	timeAxis_->_labelGenerator->_data = _pTimeInfo.get();
	timeAxis_->_labelGenerator->_function = generateTickTimeLabel;
}
46858100   Benjamin Renard   Tickplot: Add mis...
360

8c860e4f   Benjamin Renard   Rework for tickpl...
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
std::string TickMarkDecorator::getTickParamLabel(const std::string& paramId, const AMDA::Common::ParameterIndexComponent& index) {
	AMDA::Parameters::ParameterSPtr param = _decoratorPlot->_parameterManager.getParameter(paramId);
	AMDA::Info::ParamMgr* piMgr = AMDA::Info::ParamMgr::getInstance();
	AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(param->getInfoId());

	std::ostringstream osstr;
	bool skipIndex = false;
	if (paramInfo != nullptr) {
		if (paramInfo->getComponents(index).empty() == false) {
			osstr << paramInfo->getComponents(index);
			skipIndex = true;
		}
		else {
			osstr << paramInfo->getShortName();
		}
	}
	else {
		osstr << paramId;
	}
46858100   Benjamin Renard   Tickplot: Add mis...
380

8c860e4f   Benjamin Renard   Rework for tickpl...
381
382
383
384
385
386
387
388
389
390
391
	if (!skipIndex) {
		if(index.getDim1Index() != -1){
			osstr << "[" << index.getDim1Index() ;
			if (index.getDim2Index() != -1)
				osstr << "," << index.getDim2Index();
			osstr << "]";
		}
		else if (index.getDim2Index() != -1) {
			osstr << "[" << index.getDim2Index() << "]";
		}
	}
2fc1f2f8   Benjamin Renard   Full rework for s...
392

8c860e4f   Benjamin Renard   Rework for tickpl...
393
394
395
	if ((paramInfo != nullptr) && (paramInfo->getUnits().empty() == false)) {
		osstr << ", " << paramInfo->getUnits();
	}
2fc1f2f8   Benjamin Renard   Full rework for s...
396

8c860e4f   Benjamin Renard   Rework for tickpl...
397
398
	return osstr.str();
}
2fc1f2f8   Benjamin Renard   Full rework for s...
399

8c860e4f   Benjamin Renard   Rework for tickpl...
400
401
402
403
404
405
406
407
408
409
410
std::string TickMarkDecorator::getTickParamDescription(const std::string& paramId, bool isScalar) {
	AMDA::Parameters::ParameterSPtr param = _decoratorPlot->_parameterManager.getParameter(paramId);
	AMDA::Info::ParamMgr* piMgr = AMDA::Info::ParamMgr::getInstance();
	AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(param->getInfoId());

	std::string description;
	if (paramInfo != nullptr) {
		description = paramInfo->getInstrumentId();
		if (!description.empty()) {
			if (description.find('_') != std::string::npos) {
				description = description.substr(0, description.find('_'));
fbe3c2bb   Benjamin Renard   First commit
411
			}
8c860e4f   Benjamin Renard   Rework for tickpl...
412
			std::transform(description.begin(), description.end(), description.begin(), ::toupper);
fbe3c2bb   Benjamin Renard   First commit
413
414
415
		}
	}

8c860e4f   Benjamin Renard   Rework for tickpl...
416
417
418
419
420
421
422
	if (description.empty() && !isScalar) {
		if (paramInfo != nullptr) {
			description = paramInfo->getShortName();
		}
		if (description.empty()) {
			description = paramId;
		}
fbe3c2bb   Benjamin Renard   First commit
423
424
	}

8c860e4f   Benjamin Renard   Rework for tickpl...
425
426
427
428
	if ((paramInfo != nullptr) && (paramInfo->getCoordinatesSystem().empty() == false)) {
		description += ", ";
		description += paramInfo->getCoordinatesSystem();
	}
fbe3c2bb   Benjamin Renard   First commit
429

8c860e4f   Benjamin Renard   Rework for tickpl...
430
	return description;
fbe3c2bb   Benjamin Renard   First commit
431
432
433
}

/***************************** EXTERNAL METHODS ********************************/
8c860e4f   Benjamin Renard   Rework for tickpl...
434
void generateTickSerieLabel(PLINT axis, PLFLT value, char *label, PLINT length,
fbe3c2bb   Benjamin Renard   First commit
435
436
437
438
		PLPointer data) {
	if (axis == PL_X_AXIS) {
		if (data == NULL) {
			std::cout
8c860e4f   Benjamin Renard   Rework for tickpl...
439
					<< "WARNING !!!! NO DATA FOUND FOR generateTickSerieLabel FUNCTION !!!"
fbe3c2bb   Benjamin Renard   First commit
440
441
					<< std::endl << std::endl;
			LOG4CXX_WARN(gLogger,
8c860e4f   Benjamin Renard   Rework for tickpl...
442
					"WARNING !!!! NO DATA FOUND FOR generateTickSerieLabel FUNCTION !!");
fbe3c2bb   Benjamin Renard   First commit
443
444
			return;
		}
8c860e4f   Benjamin Renard   Rework for tickpl...
445
		TickParamIndexInfo* pInfo = static_cast<TickParamIndexInfo*> (data);
af253df2   Benjamin Renard   First step for re...
446
447
		// display formatted value
		std::ostringstream labels;
225ac17f   Benjamin Renard   Fix tickmarks plot
448

af253df2   Benjamin Renard   First step for re...
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
		//get nearest value
		double crtTime = (double) value;

		int crtIndex = pInfo->_parameterData->indexOf(crtTime);

		if (crtIndex == -1 && (crtTime - (pInfo->_parameterData->getTimes()[pInfo->_parameterData->getSize()-1]) < pInfo->_parameterData->getParamGapSize()))
			//Fix last value
			crtIndex = pInfo->_parameterData->getSize()-1;
		else if ((crtTime - (pInfo->_parameterData->getTimes()[crtIndex])) > pInfo->_parameterData->getParamGapSize())
			//Be sure that we are not in a data gap
			crtIndex = -1;

		if (crtIndex == -1) {
			labels << "NaN" << std::endl;
		}
		else {
8c860e4f   Benjamin Renard   Rework for tickpl...
465
			labels << boost::format(pInfo->_valuesFormat) % (*pInfo->_parameterData->getValues(pInfo->_index, crtIndex));
fbe3c2bb   Benjamin Renard   First commit
466
		}
af253df2   Benjamin Renard   First step for re...
467
			snprintf(label, length, "%s", labels.str().c_str());
fbe3c2bb   Benjamin Renard   First commit
468
469
470
	}
}

8c860e4f   Benjamin Renard   Rework for tickpl...
471
void generateTickTimeLabel(PLINT axis, PLFLT value, char *label, PLINT length,
fbe3c2bb   Benjamin Renard   First commit
472
473
474
475
476
477
478
479
480
481
482
483
		PLPointer data) {

	if (axis == PL_X_AXIS) {
		if (data == NULL) {
			std::cout
					<< "WARNING !!!! NO DATA FOUND FOR generateOrbitTimeLabel FUNCTION !!!"
					<< std::endl << std::endl;
			LOG4CXX_WARN(gLogger,
					"WARNING !!!! NO DATA FOUND FOR generateOrbitTimeLabel FUNCTION !!");
			return;
		}
		TimeInfo* pInfo = static_cast<TimeInfo*> (data);
fbe3c2bb   Benjamin Renard   First commit
484

8c860e4f   Benjamin Renard   Rework for tickpl...
485
486
487
488
489
		if (!pInfo->_pAxis->_showTickMark) {
			label [0] = 0;
			return;
		}

af253df2   Benjamin Renard   First step for re...
490
491
492
493
		// display formatted time
		std::string timeFormatstr = pInfo->_timeFormat.c_str();
		char *timeFormat = new char[timeFormatstr.length() + 1];
		strcpy(timeFormat, timeFormatstr.c_str());
fbe3c2bb   Benjamin Renard   First commit
494

af253df2   Benjamin Renard   First step for re...
495
496
497
		if (TimePlot::qsasconfig == NULL) {
			configqsas(1. / 86400., 0., 0., 0x0, 1, 1970, 0, 1, 0, 0, 0.,
					&TimePlot::qsasconfig);
fbe3c2bb   Benjamin Renard   First commit
498
		}
af253df2   Benjamin Renard   First step for re...
499
500
501
502
503
504
505
		char formattedTime[40];

		strfqsas(formattedTime, 40, timeFormat, (double) value,
					TimePlot::qsasconfig);
		delete[] timeFormat;

		snprintf(label, length, "%s", formattedTime);
fbe3c2bb   Benjamin Renard   First commit
506
507
508
509
	}
}

} /* namespace plot */