Blame view

src/ParamOutputImpl/Plot/PanelPlotOutput.cc 103 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * PanelPlotOutput.cc
 *
 *  Created on: 29 oct. 2013
 *      Author: CS
 */

#include "PanelPlotOutput.hh"
#include "ColormapManager.hh"
#include "ColorAxis.hh"
#include "ParameterManager.hh"
#include "Page.hh"
#include "ShadesTools.hh"
#include "PlotLogger.hh"
#include "TimeUtil.hh"
#include "ParamMgr.hh"
7f7e3b39   Benjamin Renard   Fix a bug with st...
17
#include "DecoratorPlot.hh"
f6eaec4e   Benjamin Renard   Optimize plot ele...
18
#include "PlPlotUtil.hh"
fbe3c2bb   Benjamin Renard   First commit
19

8bb0f02b   Benjamin Renard   Set colors in axi...
20
#include <boost/range/adaptor/reversed.hpp>
fbe3c2bb   Benjamin Renard   First commit
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

using namespace AMDA::Parameters;
using namespace AMDA::Info;

namespace plot {

/**
 * Width character proportion is approximatively 0.83 times smaller than height.
 */
const float PanelPlotOutput::CHAR_RATIO = 5./6.;

const float PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR = 0.75;

// Vertical is for Y axis.
const float PanelPlotOutput::VERTICAL_TICK_LENGTH_LIMIT = 0.5;
// Horizontal is for X axis.
const float PanelPlotOutput::HORIZONTAL_TICK_LENGTH_LIMIT = 0.75;


PanelPlotOutput::PanelPlotOutput(AMDA::Parameters::ParameterManager& manager, boost::shared_ptr<Panel> panel) :
		_panel(panel),
		_parameterManager(manager),
		_pParameterValues(NULL),
		_timeIntervalListPtr(NULL),
fbe3c2bb   Benjamin Renard   First commit
45
46
47
48
49
50
51
52
53
		_panelPlotXYRatio(1),
		_leftAxisTickMarkWidth(0),
		_automaticSerieColorCursor(0)
{
}

PanelPlotOutput::~PanelPlotOutput() {
}

fbe3c2bb   Benjamin Renard   First commit
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
double getVerticalTickLength(Axis* pAxis, double charHeight) {
	float horizontalTickLengthLimit = PanelPlotOutput::HORIZONTAL_TICK_LENGTH_LIMIT;
	float defaultTickLengthFactor	= PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR;
	double tickLengthFactor 		= pAxis->_tick._lengthFactor;

	if ((!isnan(tickLengthFactor)) &&	(tickLengthFactor > horizontalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((tickLengthFactor - horizontalTickLengthLimit)
				* charHeight) / (defaultTickLengthFactor) );
	} else if ((isnan(tickLengthFactor))	&& (defaultTickLengthFactor > horizontalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((defaultTickLengthFactor - horizontalTickLengthLimit)
				* charHeight) / (defaultTickLengthFactor) );
	} else {
		return charHeight;
	}
}

double getHorizontalTickLength (Axis* pAxis, double charHeight) {
	float verticalTickLengthLimit 	= PanelPlotOutput::VERTICAL_TICK_LENGTH_LIMIT;
	float defaultTickLengthFactor	= PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR;
	double tickLengthFactor 		= pAxis->_tick._lengthFactor;

	if ((!isnan(tickLengthFactor)) && (tickLengthFactor > verticalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((tickLengthFactor - verticalTickLengthLimit)
				* charHeight * PanelPlotOutput::CHAR_RATIO) / (defaultTickLengthFactor) );
	} else if ((isnan(tickLengthFactor)) && (defaultTickLengthFactor > verticalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((defaultTickLengthFactor - verticalTickLengthLimit)
				* charHeight * PanelPlotOutput::CHAR_RATIO) / (defaultTickLengthFactor) );
	} else {
		return charHeight;
	}
}

void PanelPlotOutput::calculatePlotArea(Bounds& bounds_) {
	double topSpace 	= 0;
	double bottomSpace 	= 0;
	double leftSpace 	= 0;
	double rightSpace	= 0;
fbe3c2bb   Benjamin Renard   First commit
95

b96aa975   Benjamin Renard   Draw border aroun...
96
97
98
99
100
101
102
	//Init
	_plotAreaSideSet[PlotCommon::Position::POS_TOP] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_BOTTOM] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_RIGHT] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_LEFT] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_CENTER] = false;

f6eaec4e   Benjamin Renard   Optimize plot ele...
103
104
105
	// Reserve space for title
	double titleHeight = 0;
	_panel->reserveSpaceForTitle(topSpace, bottomSpace, titleHeight);
fbe3c2bb   Benjamin Renard   First commit
106

f6eaec4e   Benjamin Renard   Optimize plot ele...
107
	// Reserve space for axes
bdc50075   Benjamin Renard   Fix bug for posit...
108
109
110
111
112
113
114
115
116
117

	//
	std::map<PlotCommon::Position, int>  nbAxesBySide;
	nbAxesBySide[PlotCommon::Position::POS_TOP] = 0;
	nbAxesBySide[PlotCommon::Position::POS_BOTTOM] = 0;
	nbAxesBySide[PlotCommon::Position::POS_RIGHT] = 0;
	nbAxesBySide[PlotCommon::Position::POS_LEFT] = 0;
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it)
	{
		boost::shared_ptr<Axis> lAxis = it->second;
b76d3cfc   Benjamin Renard   Fix color axis po...
118
		if ((lAxis == nullptr) || (lAxis->_isZAxis) || (!lAxis->_used) || (!lAxis->_visible) || (lAxis->_position == PlotCommon::Position::POS_CENTER))
bdc50075   Benjamin Renard   Fix bug for posit...
119
120
121
122
			continue;
		++nbAxesBySide[lAxis->_position];
	}

08ec1dde   Benjamin Renard   Add propertie _us...
123
	// ZAxis must be drawn at last!
08ec1dde   Benjamin Renard   Add propertie _us...
124
125
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it)
	{
f6eaec4e   Benjamin Renard   Optimize plot ele...
126
		//Add X and Y axis
08ec1dde   Benjamin Renard   Add propertie _us...
127
		boost::shared_ptr<Axis> lAxis = it->second;
b96aa975   Benjamin Renard   Draw border aroun...
128
		if ((lAxis == nullptr) || (lAxis->_isZAxis))
08ec1dde   Benjamin Renard   Add propertie _us...
129
			continue;
bdc50075   Benjamin Renard   Fix bug for posit...
130
		reserveSpaceForAxis(lAxis, titleHeight, nbAxesBySide, topSpace, bottomSpace, leftSpace, rightSpace);
08ec1dde   Benjamin Renard   Add propertie _us...
131
	}
f6eaec4e   Benjamin Renard   Optimize plot ele...
132

08ec1dde   Benjamin Renard   Add propertie _us...
133
134
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it)
	{
f6eaec4e   Benjamin Renard   Optimize plot ele...
135
		//Add Z axis
08ec1dde   Benjamin Renard   Add propertie _us...
136
		boost::shared_ptr<Axis> lAxis = it->second;
b96aa975   Benjamin Renard   Draw border aroun...
137
		if ((lAxis == nullptr) || (!lAxis->_isZAxis))
08ec1dde   Benjamin Renard   Add propertie _us...
138
			continue;
bdc50075   Benjamin Renard   Fix bug for posit...
139
		reserveSpaceForAxis(lAxis, titleHeight, nbAxesBySide, topSpace, bottomSpace, leftSpace, rightSpace);
08ec1dde   Benjamin Renard   Add propertie _us...
140
141
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
142
143
144
145
146
	// Get character size for panel.
	PlPlotUtil::setPlFont(_panel->getFont());
	CharSize lCharSizePanel = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);
	double panelCharWidth 	= lCharSizePanel.first;
	double panelCharHeight 	= lCharSizePanel.second;
fbe3c2bb   Benjamin Renard   First commit
147

fbe3c2bb   Benjamin Renard   First commit
148
149
150
151
152
	//add params legend right space when outside
	if (!_panel->_paramsLegendProperties.getLegendLines().empty() &&
			_panel->_paramsLegendProperties.isVisible() &&
			(_panel->_paramsLegendProperties.getPosition() == ParamsLegendPosition::POS_OUTSIDE))
	{
f6eaec4e   Benjamin Renard   Optimize plot ele...
153
154
		PlPlotUtil::setPlFont(_panel->_paramsLegendProperties.getFont());
		CharSize lCharSizeLegend = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);
fbe3c2bb   Benjamin Renard   First commit
155
156
157
158
159
160
161
162
163
		double legendCharWidth 	= lCharSizeLegend.first;

		//set offset
		_panel->_paramsLegendProperties.setLeftOffset(rightSpace);

		//reserve place for legend
		rightSpace += _panel->_paramsLegendProperties.getEstimateWidth(legendCharWidth);
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
164
	// Reserve space for text legend ( maximum 1 text legend by position
fbe3c2bb   Benjamin Renard   First commit
165
166
167
168
169
170
	bool	leftTextLegendFound		= false;
	bool	rightTextLegendFound 	= false;
	bool	topTextLegendFound 		= false;
	bool	bottomTextLegendFound 	= false;

	for (auto textLegendProp : _panel->_textLegendPropertiesList) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
171
		bool toDraw = true;
fbe3c2bb   Benjamin Renard   First commit
172
173
174

		switch (textLegendProp->getPosition()) {
		case TextLegendPosition::POS_LEFT :
f6eaec4e   Benjamin Renard   Optimize plot ele...
175
176
177
			if (leftTextLegendFound)
				toDraw = false;
			leftTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
178
			break;
fbe3c2bb   Benjamin Renard   First commit
179
		case TextLegendPosition::POS_RIGHT :
f6eaec4e   Benjamin Renard   Optimize plot ele...
180
181
182
			if (rightTextLegendFound)
				toDraw = false;
			rightTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
183
			break;
fbe3c2bb   Benjamin Renard   First commit
184
		case TextLegendPosition::POS_TOP :
f6eaec4e   Benjamin Renard   Optimize plot ele...
185
186
187
			if (topTextLegendFound)
				toDraw = false;
			topTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
188
			break;
fbe3c2bb   Benjamin Renard   First commit
189
		case TextLegendPosition::POS_BOTTOM :
f6eaec4e   Benjamin Renard   Optimize plot ele...
190
191
192
			if (bottomTextLegendFound)
				toDraw = false;
			bottomTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
193
194
			break;
		}
f6eaec4e   Benjamin Renard   Optimize plot ele...
195
196
197

		if (toDraw)
			reserveSpaceForTextLegend (textLegendProp, titleHeight, topSpace, bottomSpace, leftSpace, rightSpace);
fbe3c2bb   Benjamin Renard   First commit
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
	}

	// Set specified left, right, top and bottom margins and display a warning
	// message if computed margins are bigger than specified ones
	if (_panel->_leftMargin != -1) {
		if ((_panel->_leftMargin * panelCharWidth) < leftSpace)
			LOG4CXX_WARN(gLogger, "Left margin for the panel was forced beyond computed size");
		leftSpace = _panel->_leftMargin * panelCharWidth;
	}
	if (_panel->_rightMargin != -1) {
		if ((_panel->_rightMargin * panelCharWidth) < rightSpace)
			LOG4CXX_WARN(gLogger, "Right margin for the panel was forced beyond computed size");
		rightSpace = _panel->_rightMargin * panelCharWidth;
	}
	if (_panel->_topMargin != -1) {
		if ((_panel->_topMargin * panelCharHeight) < topSpace)
			LOG4CXX_WARN(gLogger, "Top margin for the panel was forced beyond computed size");
		topSpace = _panel->_topMargin * panelCharHeight;
	}
	if (_panel->_bottomMargin != -1) {
		if ((_panel->_bottomMargin * panelCharHeight) < bottomSpace)
			LOG4CXX_WARN(gLogger, "Bottom margin for the panel was forced beyond computed size");
		bottomSpace = _panel->_bottomMargin * panelCharHeight;
	}

	// Update plot area bounds
	bounds_._x 		+= leftSpace;
	bounds_._y 		+= bottomSpace;
	bounds_._width 	-= (leftSpace + rightSpace);
	bounds_._height -= (bottomSpace + topSpace);
}

bdc50075   Benjamin Renard   Fix bug for posit...
230
231
void PanelPlotOutput::reserveSpaceForAxis (boost::shared_ptr<Axis>& pAxis, double titleHeight, std::map<PlotCommon::Position, int>  nbAxesBySide,
		double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
232
233
234
235
	if (pAxis == nullptr || !pAxis->_used || !pAxis->_visible)
		return;

	// Get number of line to draw for legend.
8bb0f02b   Benjamin Renard   Set colors in axi...
236
	int nbLegendRows = pAxis->_legend.getNbLines();
f6eaec4e   Benjamin Renard   Optimize plot ele...
237
238
239
240
241
	if ((nbLegendRows == 0) && pAxis->_showLegend)
		nbLegendRows = 1;

	// Compute legend character size
	Font legendFont(pAxis->getLegendFont(this->_panel.get()));
df45df5e   Benjamin Renard   Introduce AxisLeg...
242
	PlPlotUtil::setPlFont(legendFont);
f6eaec4e   Benjamin Renard   Optimize plot ele...
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
	CharSize legendCharSizePanel = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);

	std::tuple<float, float> pageSize = _panel->_page->getSizeInMm();

	// Reserve place in relation with the axis position
	switch (pAxis->_position) {
		case PlotCommon::Position::POS_BOTTOM:
			if (pAxis->isZAxis())
				LOG4CXX_WARN(gLogger, "PanelPlotOutput::calculatePlotArea: Unrecognized position for z axis '" << pAxis->_position << "'");

			// This attribute is used later (in function PanelPlotOutput::drawSeries).
			if (!pAxis->isZAxis())
				_plotAreaSideSet[pAxis->_position] = true;

			// Reserve space for ticks
			if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
				double tickSize = getVerticalTickLength(pAxis.get(), legendCharSizePanel.second);
				bottomSpace += tickSize;
bdc50075   Benjamin Renard   Fix bug for posit...
261
262
263
				if (nbAxesBySide[PlotCommon::Position::POS_TOP] == 0)
					//add space for oposite axis
					topSpace += tickSize;
f6eaec4e   Benjamin Renard   Optimize plot ele...
264
265
266
267
268
269
270
271
272
			}

			//Reserve space for ticks labels
			if (pAxis->_showTickMark == true)
				bottomSpace += legendCharSizePanel.second * (1 + 0.25);

			// Reserve space for legend
			if ((pAxis->_showLegend == true) && (nbLegendRows != 0)) {
				bottomSpace += PlPlotUtil::LINE_SPACE_TITLE * legendCharSizePanel.second;
58b353d5   Benjamin Renard   Set to version 3.4.0
273
274
275
276
				double legendOffset = bottomSpace + 0.5 * legendCharSizePanel.second;
				if (!_panel->getTitle()->_text.empty() && (_panel->_titlePosition == PlotCommon::Position::POS_BOTTOM))
					legendOffset -= titleHeight;
				pAxis->setLegendOffset(legendOffset);
8bb0f02b   Benjamin Renard   Set colors in axi...
277
				bottomSpace += (nbLegendRows + PlPlotUtil::LINE_SPACE_TITLE * (nbLegendRows + 1)) * legendCharSizePanel.second;
f6eaec4e   Benjamin Renard   Optimize plot ele...
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
			}

			break;
		case PlotCommon::Position::POS_TOP:
			if (pAxis->isZAxis())
				LOG4CXX_WARN(gLogger, "PanelPlotOutput::calculatePlotArea: Unrecognized position for z axis '" << pAxis->_position << "'");

			// This attribute is used later (in function PanelPlotOutput::drawSeries).
			if (!pAxis->isZAxis())
				_plotAreaSideSet[pAxis->_position] = true;

			// Reserve space for ticks
			if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
				double tickSize = getVerticalTickLength(pAxis.get(), legendCharSizePanel.second);
				topSpace += tickSize;
bdc50075   Benjamin Renard   Fix bug for posit...
293
294
295
				if (nbAxesBySide[PlotCommon::Position::POS_BOTTOM] == 0)
					//add space for oposite axis
					bottomSpace += tickSize;
f6eaec4e   Benjamin Renard   Optimize plot ele...
296
297
298
299
300
301
302
303
304
			}

			//Reserve space for ticks labels
			if (pAxis->_showTickMark == true)
				topSpace += legendCharSizePanel.second * (1 + 0.25);

			// Reserve space for legend
			if ((pAxis->_showLegend == true) && (nbLegendRows != 0)) {
				topSpace += PlPlotUtil::LINE_SPACE_TITLE * legendCharSizePanel.second;
58b353d5   Benjamin Renard   Set to version 3.4.0
305
306
307
308
				double legendOffset = topSpace - 0.5 * legendCharSizePanel.second;
				if (!_panel->getTitle()->_text.empty() && (_panel->_titlePosition == PlotCommon::Position::POS_TOP))
					legendOffset += titleHeight;
				pAxis->setLegendOffset(legendOffset);
f6eaec4e   Benjamin Renard   Optimize plot ele...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
				topSpace += (nbLegendRows + PlPlotUtil::LINE_SPACE_TITLE * (nbLegendRows + 1)) * legendCharSizePanel.second;
			}

			break;
		case PlotCommon::Position::POS_LEFT:
			// Record axis offset used for multi-axes
			pAxis->setAxisOffset (leftSpace);

			if (pAxis->isZAxis()) {
				leftSpace += estimateZAxisWidth(pAxis);
				break;
			}

			// This attribute is used later (in function PanelPlotOutput::drawSeries).
			_plotAreaSideSet[pAxis->_position] = true;

			//Reserve space for ticks labels
			if (pAxis->_showTickMark == true)
				leftSpace += legendCharSizePanel.first * (pAxis->getTickMarkSize().first + 2 * PlPlotUtil::LINE_SPACE_TITLE + 0.25);

			// Reserve space for ticks
			if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
				double tickSize = getHorizontalTickLength(pAxis.get(), legendCharSizePanel.second);
				leftSpace += tickSize;
bdc50075   Benjamin Renard   Fix bug for posit...
333
334
335
				if (nbAxesBySide[PlotCommon::Position::POS_RIGHT] == 0)
					//add space for oposite axis
					rightSpace += tickSize;
f6eaec4e   Benjamin Renard   Optimize plot ele...
336
337
338
339
340
341
342
343
344
345
346
347
			}

			// Reserve space for legend
			if ((pAxis->_showLegend == true) && (nbLegendRows != 0)) {
				leftSpace += PlPlotUtil::LINE_SPACE_TITLE * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize);
				pAxis->setLegendOffset(leftSpace + 0.5 * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize));
				leftSpace += (nbLegendRows + PlPlotUtil::LINE_SPACE_TITLE * (nbLegendRows + 1)) * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize) ;
			}

			break;
		case PlotCommon::Position::POS_RIGHT:
			// Record axis offset used for multi-axes
b76d3cfc   Benjamin Renard   Fix color axis po...
348
			pAxis->setAxisOffset(rightSpace);
f6eaec4e   Benjamin Renard   Optimize plot ele...
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365

			if (pAxis->isZAxis()) {
				rightSpace += estimateZAxisWidth(pAxis);
				break;
			}

			// This attribute is used later (in function PanelPlotOutput::drawSeries).
			_plotAreaSideSet[pAxis->_position] = true;

			//Reserve space for ticks labels
			if (pAxis->_showTickMark == true)
				rightSpace += legendCharSizePanel.first * (pAxis->getTickMarkSize().first + 2 * PlPlotUtil::LINE_SPACE_TITLE + 0.25);

			// Reserve space for ticks
			if(pAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
				double tickSize = getHorizontalTickLength(pAxis.get(), legendCharSizePanel.second);
				rightSpace += tickSize;
bdc50075   Benjamin Renard   Fix bug for posit...
366
367
368
				if (nbAxesBySide[PlotCommon::Position::POS_LEFT] == 0)
					//add space for oposite axis
					leftSpace += tickSize;
f6eaec4e   Benjamin Renard   Optimize plot ele...
369
370
371
372
373
			}

			//Reserve space for legend
			if ((pAxis->_showLegend == true) && (nbLegendRows != 0)) {
				rightSpace += PlPlotUtil::LINE_SPACE_TITLE * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize);
bdc50075   Benjamin Renard   Fix bug for posit...
374
				pAxis->setLegendOffset(rightSpace + 0.5 * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize));
f6eaec4e   Benjamin Renard   Optimize plot ele...
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
				rightSpace += (nbLegendRows + PlPlotUtil::LINE_SPACE_TITLE * (nbLegendRows + 1)) * legendCharSizePanel.second * std::get<1>(pageSize) / std::get<0>(pageSize) ;
			}


			break;
		case PlotCommon::Position::POS_CENTER:
		default:
			LOG4CXX_WARN(gLogger, "PanelPlotOutput::drawPlotArea: Unrecognized position for axis '" << pAxis->_position << "'");
	}
}

void PanelPlotOutput::reserveSpaceForTextLegend (boost::shared_ptr<TextLegendProperties>& pTextLegendProp, double titleHeight, double& topSpace, double& bottomSpace, double& leftSpace, double& rightSpace) {
	int textLegendLinesNb = pTextLegendProp->getTextLinesNb();

	if (textLegendLinesNb == 0)
		return;

	PlPlotUtil::setPlFont(pTextLegendProp->getFont());
	CharSize lCharSizeLegend = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);

	std::tuple<float, float> pageSize = _panel->_page->getSizeInMm();

	switch (pTextLegendProp->getPosition()) {
		case TextLegendPosition::POS_LEFT :
			pTextLegendProp->setOffset (leftSpace);
			leftSpace += (textLegendLinesNb + PlPlotUtil::LINE_SPACE_TITLE * (textLegendLinesNb + 1)) * lCharSizeLegend.second * std::get<1>(pageSize) / std::get<0>(pageSize);
			break;
		case TextLegendPosition::POS_RIGHT :
			pTextLegendProp->setOffset (rightSpace);
			rightSpace += (textLegendLinesNb + PlPlotUtil::LINE_SPACE_TITLE * (textLegendLinesNb + 1)) * lCharSizeLegend.second * std::get<1>(pageSize) / std::get<0>(pageSize);
			break;
		case TextLegendPosition::POS_TOP :
			if (_panel->_titlePosition == PlotCommon::Position::POS_TOP)
				pTextLegendProp->setOffset (topSpace - titleHeight);
			else
				pTextLegendProp->setOffset (topSpace);
			topSpace += (textLegendLinesNb + PlPlotUtil::LINE_SPACE_TITLE * (textLegendLinesNb + 1)) * lCharSizeLegend.second;
			break;
		case TextLegendPosition::POS_BOTTOM :
			if (_panel->_titlePosition == PlotCommon::Position::POS_BOTTOM)
				pTextLegendProp->setOffset (bottomSpace - titleHeight);
			else
				pTextLegendProp->setOffset (bottomSpace);
			bottomSpace += (textLegendLinesNb + PlPlotUtil::LINE_SPACE_TITLE * (textLegendLinesNb + 1)) * lCharSizeLegend.second;
			break;
	}
}

fbe3c2bb   Benjamin Renard   First commit
423
424
425
426
427
428
429
430
431
432
433
434
435
/**
 * @brief Compute panel XY ratio used for angular conversions
 */
void PanelPlotOutput::computePanelPlotXYRatio (void) {
	// panel plot XY ratio = page ratio * plot area bound size ratio
	_panelPlotXYRatio = (std::get < 0 > (_panel->_page->getSize()) / std::get < 1 > (_panel->_page->getSize()))
					  * (_plotAreaBounds._width / _plotAreaBounds._height);
}

/**
 * @brief Draw legend for each axis.
 */
void PanelPlotOutput::drawLegends(boost::shared_ptr<Axis>& pAxis, PlWindow& pPlWindow, Bounds& pPlotAreaSize) {
df45df5e   Benjamin Renard   Introduce AxisLeg...
436
	LOG4CXX_DEBUG(gLogger, "Drawing legend for axis "<< pAxis->_id << " : " << pAxis->_legend.getText());
fbe3c2bb   Benjamin Renard   First commit
437

f6eaec4e   Benjamin Renard   Optimize plot ele...
438
439
	// Set legend font
	Font legendFont(pAxis->getLegendFont(this->_panel.get()));
df45df5e   Benjamin Renard   Introduce AxisLeg...
440
	PlPlotUtil::setPlFont(legendFont);
fbe3c2bb   Benjamin Renard   First commit
441

f6eaec4e   Benjamin Renard   Optimize plot ele...
442
	// Get legend row info
8bb0f02b   Benjamin Renard   Set colors in axi...
443
	std::list< std::pair< std::string, Color > > lines = pAxis->_legend.getLines();
fbe3c2bb   Benjamin Renard   First commit
444

fbe3c2bb   Benjamin Renard   First commit
445
446
447
	// Check if there is something to draw !
	if ((pAxis->_visible == true) &&
		(pAxis->_showLegend == true) &&
8bb0f02b   Benjamin Renard   Set colors in axi...
448
		(lines.size() != 0)) {
fbe3c2bb   Benjamin Renard   First commit
449
450
451

		Color lInitialColor;
		// If legend has not it's own color set axis color.
df45df5e   Benjamin Renard   Introduce AxisLeg...
452
453
454
455
		if ((pAxis->_legend.getColor()._colorIndex == -1)
				&& ((pAxis->_legend.getColor()._red == -1)
				&& (pAxis->_legend.getColor()._green == -1)
				&& (pAxis->_legend.getColor()._blue == -1))) {
fbe3c2bb   Benjamin Renard   First commit
456
457
458
			lInitialColor = changeColor(_pls, pAxis->_color,
					_panel->_page->_mode);
		} else {
df45df5e   Benjamin Renard   Introduce AxisLeg...
459
460
			Color legendColor = pAxis->_legend.getColor();
			lInitialColor = changeColor(_pls, legendColor,
fbe3c2bb   Benjamin Renard   First commit
461
462
463
					_panel->_page->_mode);
		}

f6eaec4e   Benjamin Renard   Optimize plot ele...
464
465
		//Init position
		double lPosition = PlPlotUtil::LINE_SPACE_TITLE;
8bb0f02b   Benjamin Renard   Set colors in axi...
466
		unsigned int lineIndex = 0;
fbe3c2bb   Benjamin Renard   First commit
467
468
469
470

		// Depending on the way to draw legend, for BOTTOM position we have to draw from first legend line to last.
		switch (pAxis->_position) {
		case PlotCommon::Position::POS_BOTTOM:
8bb0f02b   Benjamin Renard   Set colors in axi...
471
		
f6eaec4e   Benjamin Renard   Optimize plot ele...
472
473
474
475
476
477
478
			_pls->vpor(pPlotAreaSize._x,
					   pPlotAreaSize._x + pPlotAreaSize._width,
					   pPlotAreaSize._y - pAxis->getLegendOffset(),
					   pPlotAreaSize._y - pAxis->getLegendOffset() + pPlotAreaSize._height);

			_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
						std::get<2>(pPlWindow), std::get<3>(pPlWindow));
fbe3c2bb   Benjamin Renard   First commit
479
480

			// Draw lines, beginning by the first one
8bb0f02b   Benjamin Renard   Set colors in axi...
481
482
483
			for (auto line : lines) {
				std::string lineToDraw = line.first;
				if (lineIndex == lines.size()-1)
fbe3c2bb   Benjamin Renard   First commit
484
485
486
487
488
489
490
491
492
				{
					//add unit if defined
					if (!pAxis->getAxisUnits().empty())
					{
						lineToDraw += " (";
						lineToDraw += pAxis->getAxisUnits();
						lineToDraw += ")";
					}
				}
8bb0f02b   Benjamin Renard   Set colors in axi...
493
494
495
496
				Color lSavedColor;
				if (line.second.isSet()) {
					lSavedColor = changeColor(_pls, line.second, _panel->_page->_mode);
				}
fbe3c2bb   Benjamin Renard   First commit
497
				_pls->mtex(getPlSide(pAxis->_position).c_str(), lPosition, 0.5, 0.5, lineToDraw.c_str());
f6eaec4e   Benjamin Renard   Optimize plot ele...
498
				lPosition += (1 + PlPlotUtil::LINE_SPACE_TITLE);
8bb0f02b   Benjamin Renard   Set colors in axi...
499
500
501
502
				if (line.second.isSet()) {
					restoreColor(_pls, lSavedColor, _panel->_page->_mode);
				}
				++lineIndex;
fbe3c2bb   Benjamin Renard   First commit
503
504
505
506
			}
			break;

		case PlotCommon::Position::POS_TOP:
f6eaec4e   Benjamin Renard   Optimize plot ele...
507
508
509
510
			_pls->vpor(pPlotAreaSize._x,
					   pPlotAreaSize._x + pPlotAreaSize._width,
					   pPlotAreaSize._y + pAxis->getLegendOffset(),
					   pPlotAreaSize._y + pAxis->getLegendOffset() + pPlotAreaSize._height);
fbe3c2bb   Benjamin Renard   First commit
511

f6eaec4e   Benjamin Renard   Optimize plot ele...
512
513
			_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
						std::get<2>(pPlWindow), std::get<3>(pPlWindow));
fbe3c2bb   Benjamin Renard   First commit
514
515

			// Draw lines, beginning by the last one
8bb0f02b   Benjamin Renard   Set colors in axi...
516
517
518
			for (auto line : boost::adaptors::reverse(lines)) {
				std::string lineToDraw = line.first;
				if (lineIndex == lines.size()-1)
fbe3c2bb   Benjamin Renard   First commit
519
520
521
522
523
524
525
526
527
				{
					//add unit if defined
					if (!pAxis->getAxisUnits().empty())
					{
						lineToDraw += " (";
						lineToDraw += pAxis->getAxisUnits();
						lineToDraw += ")";
					}
				}
8bb0f02b   Benjamin Renard   Set colors in axi...
528
529
530
531
				Color lSavedColor;
				if (line.second.isSet()) {
					lSavedColor = changeColor(_pls, line.second, _panel->_page->_mode);
				}
fbe3c2bb   Benjamin Renard   First commit
532
				_pls->mtex (getPlSide(pAxis->_position).c_str(), lPosition, 0.5, 0.5, lineToDraw.c_str());
f6eaec4e   Benjamin Renard   Optimize plot ele...
533
				lPosition += (1 + PlPlotUtil::LINE_SPACE_TITLE);
8bb0f02b   Benjamin Renard   Set colors in axi...
534
535
536
537
				if (line.second.isSet()) {
					restoreColor(_pls, lSavedColor, _panel->_page->_mode);
				}
				++lineIndex;
fbe3c2bb   Benjamin Renard   First commit
538
539
540
541
			}
			break;

		case PlotCommon::Position::POS_RIGHT:
f6eaec4e   Benjamin Renard   Optimize plot ele...
542
543
544

			_pls->vpor(pPlotAreaSize._x,
						pPlotAreaSize._x + pAxis->getLegendOffset() + pPlotAreaSize._width,
fbe3c2bb   Benjamin Renard   First commit
545
546
						pPlotAreaSize._y,
						pPlotAreaSize._y + pPlotAreaSize._height);
fbe3c2bb   Benjamin Renard   First commit
547

f6eaec4e   Benjamin Renard   Optimize plot ele...
548
549
			_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
						std::get<2>(pPlWindow), std::get<3>(pPlWindow));
fbe3c2bb   Benjamin Renard   First commit
550
551

			// Draw lines, beginning by the first one
8bb0f02b   Benjamin Renard   Set colors in axi...
552
553
554
			for (auto line : lines) {
				std::string lineToDraw = line.first;
				if (lineIndex == lines.size()-1)
fbe3c2bb   Benjamin Renard   First commit
555
556
557
558
559
560
561
562
563
				{
					//add unit if defined
					if (!pAxis->getAxisUnits().empty())
					{
						lineToDraw += " (";
						lineToDraw += pAxis->getAxisUnits();
						lineToDraw += ")";
					}
				}
8bb0f02b   Benjamin Renard   Set colors in axi...
564
565
566
567
				Color lSavedColor;
				if (line.second.isSet()) {
					lSavedColor = changeColor(_pls, line.second, _panel->_page->_mode);
				}
fbe3c2bb   Benjamin Renard   First commit
568
				_pls->mtex(getPlSide(pAxis->_position).c_str(), lPosition, 0.5, 0.5, lineToDraw.c_str());
f6eaec4e   Benjamin Renard   Optimize plot ele...
569
				lPosition += (1 + PlPlotUtil::LINE_SPACE_TITLE);
8bb0f02b   Benjamin Renard   Set colors in axi...
570
571
572
573
				if (line.second.isSet()) {
					restoreColor(_pls, lSavedColor, _panel->_page->_mode);
				}
				++lineIndex;
fbe3c2bb   Benjamin Renard   First commit
574
575
			}

fbe3c2bb   Benjamin Renard   First commit
576
577
578
			break;

		case PlotCommon::Position::POS_LEFT:
f6eaec4e   Benjamin Renard   Optimize plot ele...
579
580

			_pls->vpor(pPlotAreaSize._x - pAxis->getLegendOffset(),
fbe3c2bb   Benjamin Renard   First commit
581
582
583
						pPlotAreaSize._x + pPlotAreaSize._width,
						pPlotAreaSize._y,
						pPlotAreaSize._y + pPlotAreaSize._height);
fbe3c2bb   Benjamin Renard   First commit
584

f6eaec4e   Benjamin Renard   Optimize plot ele...
585
586
			_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
						std::get<2>(pPlWindow), std::get<3>(pPlWindow));
fbe3c2bb   Benjamin Renard   First commit
587
588

			// Draw lines, beginning by the last one
8bb0f02b   Benjamin Renard   Set colors in axi...
589
590
591
			for (auto line : boost::adaptors::reverse(lines)) {
				std::string lineToDraw = line.first;
				if (lineIndex == lines.size()-1)
fbe3c2bb   Benjamin Renard   First commit
592
593
594
595
596
597
598
599
600
				{
					//add unit if defined
					if (!pAxis->getAxisUnits().empty())
					{
						lineToDraw += " (";
						lineToDraw += pAxis->getAxisUnits();
						lineToDraw += ")";
					}
				}
8bb0f02b   Benjamin Renard   Set colors in axi...
601
602
603
604
				Color lSavedColor;
				if (line.second.isSet()) {
					lSavedColor = changeColor(_pls, line.second, _panel->_page->_mode);
				}
fbe3c2bb   Benjamin Renard   First commit
605
				_pls->mtex (getPlSide(pAxis->_position).c_str(), lPosition, 0.5, 0.5, lineToDraw.c_str());
f6eaec4e   Benjamin Renard   Optimize plot ele...
606
				lPosition += (1 + PlPlotUtil::LINE_SPACE_TITLE);
8bb0f02b   Benjamin Renard   Set colors in axi...
607
608
609
610
				if (line.second.isSet()) {
					restoreColor(_pls, lSavedColor, _panel->_page->_mode);
				}
				++lineIndex;
fbe3c2bb   Benjamin Renard   First commit
611
612
			}

fbe3c2bb   Benjamin Renard   First commit
613
614
615
616
617
618
619
			break;

		case PlotCommon::Position::POS_CENTER:
		default:
			LOG4CXX_WARN(gLogger, "PanelPlotOutput::drawPlotArea: Unrecognized position for axis '" << pAxis->_position << "'");
		}

f6eaec4e   Benjamin Renard   Optimize plot ele...
620
621
622
623
624
625
626
627
		_pls->vpor(pPlotAreaSize._x,
					pPlotAreaSize._x + pPlotAreaSize._width,
					pPlotAreaSize._y,
					pPlotAreaSize._y + pPlotAreaSize._height);

		_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
					std::get<2>(pPlWindow), std::get<3>(pPlWindow));

fbe3c2bb   Benjamin Renard   First commit
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
		// Restore initial color.
		restoreColor(_pls, lInitialColor, _panel->_page->_mode);
	}
}

void PanelPlotOutput::drawAxis(boost::shared_ptr<Axis> pAxis, TickConf& pTickConf,
		std::string pXAxisOptions,	std::string pYAxisOptions) {
	Color lInitialColor = changeColor(_pls, pAxis->_color, _panel->_page->_mode);

	// Set axis thickness.
	_pls->width(pAxis->_thickness);

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

	// if options contains "o" character we need to set label function
	if ((pXAxisOptions.find("o") != std::string::npos) || (pYAxisOptions.find("o") != std::string::npos)) {
		_pls->slabelfunc(pAxis->_labelGenerator->_function,	pAxis->_labelGenerator->_data);
	}

	// Set line style (force to be plain)
	_pls->lsty(static_cast<int>(getPlLineStyle(LineStyle::PLAIN)));

	// Set font to draw axes.
8bb0f02b   Benjamin Renard   Set colors in axi...
660
661
662
663
	Font axisFont(pAxis->getLegendFont(this->_panel.get()));
	axisFont.setStyle(Font::Style::NORMAL);
	axisFont.setWeight(Font::Weight::NORMAL);
	PlPlotUtil::setPlFont(axisFont);
fbe3c2bb   Benjamin Renard   First commit
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716

	size_t lPos;

	double xMajorTickSpace	= std::get<0>(pTickConf);
	double xMinorTickNumber	= std::get<1>(pTickConf);
	double yMajorTickSpace	= std::get<2>(pTickConf);
	double yMinorTickNumber	= std::get<3>(pTickConf);

	// if options contains "a" character we need to draw origin separately.
	if ((lPos = pXAxisOptions.find("a")) != std::string::npos) {
		pXAxisOptions.replace(lPos, 1, "");
		_pls->box("a", xMajorTickSpace, xMinorTickNumber, "", yMajorTickSpace, yMinorTickNumber);
	} else if  ((lPos = pYAxisOptions.find("a")) != std::string::npos) {
		pYAxisOptions.replace(lPos, 1, "");
		_pls->box("", xMajorTickSpace, xMinorTickNumber, "a", yMajorTickSpace, yMinorTickNumber);
	} else {
		// Nothing to do.
	}

	// Draw axis.
	_pls->box(pXAxisOptions.c_str(), xMajorTickSpace, xMinorTickNumber,
			  pYAxisOptions.c_str(), yMajorTickSpace, yMinorTickNumber);

	// Restore initial color.
	restoreColor(_pls, lInitialColor, _panel->_page->_mode);

	// Set axis as drawn.
	pAxis->_drawn = true;

}

void PanelPlotOutput::drawXAxis(boost::shared_ptr<Axis> pXAxis, PlWindow& pPlWindow, Bounds& pPlotAreaSize, TickConf& pTickConf) {
	// Set option to draw origin.
	std::string lAxisOption = pXAxis->getPlotOpt();
	std::string lTmpAxisOption = "xi";

	// plplot doesn't provide solution to set space between tick and tick mark.
	// To do that we need to play with viewport position and size.
	// So axis will be drawn in two times:
	//		- first draw tick marks
	//		- second draw tick and edge
	// Custom space  between tick marks and tick is only done when tick length is greater than 0.75.
	// Get extra tick mark space (only if they are outwards)
	if (pXAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
		float lTickLengthFactor = 0;
		if ((!isnan(pXAxis->_tick._lengthFactor)) && (pXAxis->_tick._lengthFactor > HORIZONTAL_TICK_LENGTH_LIMIT)) {
			lTickLengthFactor = pXAxis->_tick._lengthFactor;
		} else if ((isnan(pXAxis->_tick._lengthFactor)) && (DEFAULT_TICK_LENGTH_FACTOR > HORIZONTAL_TICK_LENGTH_LIMIT)) {
			lTickLengthFactor = DEFAULT_TICK_LENGTH_FACTOR;
		}

		if (lTickLengthFactor != 0) {
			// 1 character size is equal to 0.75 tick length.
f6eaec4e   Benjamin Renard   Optimize plot ele...
717
718
			PlPlotUtil::setPlFont(_panel->getFont());
			float lTickMarkSpace = (lTickLengthFactor - HORIZONTAL_TICK_LENGTH_LIMIT) * (PlPlotUtil::getCharacterSizeInPlPage(_panel->_page).second) / (DEFAULT_TICK_LENGTH_FACTOR);
fbe3c2bb   Benjamin Renard   First commit
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812

			size_t lPos;

			if ((lPos = lAxisOption.find("m")) != std::string::npos) {
				lTmpAxisOption += "m";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("n")) != std::string::npos) {
				lTmpAxisOption += "n";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("o")) != std::string::npos) {
				lTmpAxisOption += "o";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("d")) != std::string::npos) {
				lTmpAxisOption += "d";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("f")) != std::string::npos) {
				lTmpAxisOption += "f";
				lAxisOption.replace(lPos, 1, "");
			}

			if (pXAxis->_position == PlotCommon::Position::POS_BOTTOM) {
				_pls->vpor(pPlotAreaSize._x,
						pPlotAreaSize._x + pPlotAreaSize._width,
						pPlotAreaSize._y - lTickMarkSpace,
						pPlotAreaSize._y + pPlotAreaSize._height);
			} else {
				_pls->vpor(pPlotAreaSize._x,
						pPlotAreaSize._x + pPlotAreaSize._width,
						pPlotAreaSize._y,
						pPlotAreaSize._y + pPlotAreaSize._height + lTickMarkSpace);

			}

			_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
					std::get<2>(pPlWindow), std::get<3>(pPlWindow));

			// Draw tick mark.
			drawAxis(pXAxis, pTickConf, lTmpAxisOption, "");
		}
	}
	// Restore default plot area
	_pls->vpor(pPlotAreaSize._x,
			pPlotAreaSize._x + pPlotAreaSize._width,
			pPlotAreaSize._y,
			pPlotAreaSize._y + pPlotAreaSize._height);
	// Set window.
	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
			std::get<2>(pPlWindow), std::get<3>(pPlWindow));


	// Check if origin must be drawn.
	if (std::get<0>(pPlWindow) != 0 && std::get<1>(pPlWindow) && pXAxis->_origin == 0) {
		lAxisOption += "a";
	}

	// Check if opposite plot area side need to be drawn
	lAxisOption += drawOppositeSide(pXAxis);

	// Draw rest of axis.
	drawAxis(pXAxis, pTickConf, lAxisOption, "");

}

void PanelPlotOutput::drawYAxis(boost::shared_ptr<Axis> pYAxis, PlWindow& pPlWindow, Bounds& pPlotAreaSize, TickConf& pTickConf) {

	// Get axis offset in case of multi-axes
	double axisOffset = pYAxis->getAxisOffset();

	// Set option to draw origin ("v" is set to have numeric labels parallel to X axis).
	std::string lAxisOption = pYAxis->getPlotOpt();
	std::string lTmpAxisOption = "xiv";

	// plplot doesn't provide solution to set space between tick and tick mark.
	// To do that we need to play with viewport position and size.
	// So axis will be drawn in two times:
	//		- first draw tick marks
	//		- second draw tick and edge
	// Custom space  between tick marks and tick is only done when tick length is greater than 0.5.
	// Get extra tick mark space (only if they are outwards)

	if (pYAxis->_tick._position == Tick::TickPosition::OUTWARDS) {
		float lTickLengthFactor = 0;
		if ((!isnan(pYAxis->_tick._lengthFactor)) && (pYAxis->_tick._lengthFactor > VERTICAL_TICK_LENGTH_LIMIT)) {
			lTickLengthFactor = pYAxis->_tick._lengthFactor;
		} else if ((isnan(pYAxis->_tick._lengthFactor)) && (DEFAULT_TICK_LENGTH_FACTOR > VERTICAL_TICK_LENGTH_LIMIT)) {
			lTickLengthFactor = DEFAULT_TICK_LENGTH_FACTOR;
		}

		if (lTickLengthFactor != 0) {
			// 1 character size is equal to 0.75 tick length.
f6eaec4e   Benjamin Renard   Optimize plot ele...
813
814
			PlPlotUtil::setPlFont(_panel->getFont());
			double lTickMarkSpace = (lTickLengthFactor - VERTICAL_TICK_LENGTH_LIMIT) * (PlPlotUtil::getCharacterSizeInPlPage(_panel->_page).second) / (DEFAULT_TICK_LENGTH_FACTOR);
fbe3c2bb   Benjamin Renard   First commit
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907

			size_t lPos;

			if ((lPos = lAxisOption.find("m")) != std::string::npos) {
				lTmpAxisOption += "m";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("n")) != std::string::npos) {
				lTmpAxisOption += "n";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("o")) != std::string::npos) {
				lTmpAxisOption += "o";
				lAxisOption.replace(lPos, 1, "");
			}
			if ((lPos = lAxisOption.find("f")) != std::string::npos) {
				lTmpAxisOption += "f";
				lAxisOption.replace(lPos, 1, "");
			}
			if (lAxisOption.find("l") != std::string::npos) {
				// Do not remove on original axis option
				// because option is needed to draw logarithmic tick.
				lTmpAxisOption += "l";
			}

			// Set plot area used to draw tick mark
			if (pYAxis->_position == PlotCommon::Position::POS_LEFT) {
				_pls->vpor(pPlotAreaSize._x - lTickMarkSpace - axisOffset,
						pPlotAreaSize._x + pPlotAreaSize._width,
						pPlotAreaSize._y,
						pPlotAreaSize._y + pPlotAreaSize._height);
			} else {
				_pls->vpor(pPlotAreaSize._x,
						pPlotAreaSize._x + pPlotAreaSize._width + lTickMarkSpace + axisOffset,
						pPlotAreaSize._y,
						pPlotAreaSize._y + pPlotAreaSize._height);
			}

			_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
					   std::get<2>(pPlWindow), std::get<3>(pPlWindow));

			// Draw tick mark.
			drawAxis(pYAxis, pTickConf, "", lTmpAxisOption);

		}
	}

	// Set plot area used to draw tick
	if (pYAxis->_position == PlotCommon::Position::POS_LEFT) {
		_pls->vpor(pPlotAreaSize._x - axisOffset,
				pPlotAreaSize._x + pPlotAreaSize._width,
				pPlotAreaSize._y,
				pPlotAreaSize._y + pPlotAreaSize._height);
	} else {
		_pls->vpor(pPlotAreaSize._x,
				pPlotAreaSize._x + pPlotAreaSize._width + axisOffset,
				pPlotAreaSize._y,
				pPlotAreaSize._y + pPlotAreaSize._height);
	}

	// Set window.
	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
			   std::get<2>(pPlWindow), std::get<3>(pPlWindow));

	// Check if origin must be drawn.
	if (std::get<0>(pPlWindow) != 0 && std::get<1>(pPlWindow) && pYAxis->_origin == 0) {
		lAxisOption += "a";
	}

	// Check if opposite plot area side need to be drawn
	lAxisOption += drawOppositeSide(pYAxis);

	// Draw rest of axis.
	drawAxis(pYAxis, pTickConf, "", lAxisOption);

	// Restore default plot area
	_pls->vpor(pPlotAreaSize._x,
			pPlotAreaSize._x + pPlotAreaSize._width,
			pPlotAreaSize._y,
			pPlotAreaSize._y + pPlotAreaSize._height);

	// Set window.
	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),
			   std::get<2>(pPlWindow), std::get<3>(pPlWindow));
}

#define COLORBAR_X_OFFSET 0.01
#define COLORBAR_BODY_WIDTH 0.0375

double PanelPlotOutput::estimateZAxisWidth(boost::shared_ptr<Axis> pZAxis)
{
	double axisWidth = (COLORBAR_X_OFFSET + COLORBAR_BODY_WIDTH) * _panel->_bounds._width;

f6eaec4e   Benjamin Renard   Optimize plot ele...
908
909
	PlPlotUtil::setPlFont(_panel->getFont());
	CharSize lCharSize = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);
fbe3c2bb   Benjamin Renard   First commit
910

8bb0f02b   Benjamin Renard   Set colors in axi...
911
	int nbLineLegend = pZAxis->_legend.getNbLines();
fbe3c2bb   Benjamin Renard   First commit
912
913
914
915
916
917
918
919
920
921
922
923

	if ((pZAxis->_showLegend == true) && (nbLineLegend != 0))
	{
		if (_panel->_page->_orientation == PlotCommon::Orientation::LANDSCAPE)
			axisWidth += lCharSize.second * (2 * nbLineLegend + 1);
		else
			axisWidth += lCharSize.first * (2 * nbLineLegend + 1);
	}

	return axisWidth;
}

b76d3cfc   Benjamin Renard   Fix color axis po...
924
void PanelPlotOutput::drawZAxis(boost::shared_ptr<Axis> pZAxis, PlWindow& pPlWindow, Bounds& pPlotAreaSize, TickConf& /*pTickConf*/)
fbe3c2bb   Benjamin Renard   First commit
925
926
927
928
929
930
931
932
933
934
935
{
	Color lInitialColor;
	_pls->gcol0(0, lInitialColor._red, lInitialColor._green, lInitialColor._blue);

	// Set axis thickness.
	_pls->width(pZAxis->_thickness);

	// Set line style (force to be plain)
	_pls->lsty(static_cast<int>(getPlLineStyle(LineStyle::PLAIN)));

	// Set font to draw axes.
f6eaec4e   Benjamin Renard   Optimize plot ele...
936
	PlPlotUtil::setPlFont(_panel->getFont());
fbe3c2bb   Benjamin Renard   First commit
937
938

	std::string lAxisOption = pZAxis->getPlotOpt();
8bb0f02b   Benjamin Renard   Set colors in axi...
939
940
941
942
943
944
945
946
947
948
949
	std::string lAxisLegend = "";
	std::list< std::pair< std::string, Color > > lines = pZAxis->_legend.getLines();
	for (auto line : lines) {
		if (line.first.empty()) {
			continue;
		}
		if (!lAxisLegend.empty()) {
			lAxisLegend += "\n";
		}
		lAxisLegend += line.first;
	}
fbe3c2bb   Benjamin Renard   First commit
950
951
952
953
954
955
956
957

	PLFLT       colorbar_width, colorbar_height;
	const int   cont_color = 0;
	const PLFLT cont_width = 0.0;

	//set legend
	const PLINT      n_labels     = (lAxisLegend.empty()) ? 0 : 1;
	std::string label = lAxisLegend;
fbe3c2bb   Benjamin Renard   First commit
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010

	const char *labels[n_labels];
	if (!lAxisLegend.empty())
		labels[0] = label.c_str();

	//set axis options
	const PLINT      n_axis_opts  = 1;
	const char *axis_opts[n_axis_opts] = {
			lAxisOption.c_str(),
	    };

	PLFLT      axis_ticks[n_axis_opts] = {
			0
	    };
	PLINT      axis_subticks[n_axis_opts] = {
	        0
	    };

	// if options contains "o" character we need to set label function
	if (lAxisOption.find("o") != std::string::npos) {
		_pls->slabelfunc(pZAxis->_labelGenerator->_function, pZAxis->_labelGenerator->_data);
	}

	//set nb og colors
	const int nbCol = 20;

	PLINT      num_values[1]= {
			nbCol+1
	    };

	Range r = pZAxis->getRange();


	PLFLT       *shedge    = new PLFLT[nbCol+1];

	ShadesTools::computeEdgesLevels(r,nbCol+1,shedge);

	PLFLT      *values[1];
	values[0]     = shedge;

	//set color map
	_pls->spal1(
			ColormapManager::getInstance().getColorAxis(pZAxis->_color._colorMapIndex).c_str(), true);

	//set color bar and legend position
	PLINT position = PL_POSITION_OUTSIDE | PL_POSITION_VIEWPORT;
	PLINT label_opts[1];

	switch (pZAxis->_position)
	{
		case PlotCommon::Position::POS_LEFT   :
			position |= PL_POSITION_LEFT;
			label_opts[0] = PL_COLORBAR_LABEL_LEFT;
b76d3cfc   Benjamin Renard   Fix color axis po...
1011
			_pls->vpor(pPlotAreaSize._x - pZAxis->getAxisOffset(), pPlotAreaSize._x + pPlotAreaSize._width, pPlotAreaSize._y, pPlotAreaSize._y + pPlotAreaSize._height);
fbe3c2bb   Benjamin Renard   First commit
1012
1013
1014
1015
			break;
		case PlotCommon::Position::POS_RIGHT   :
			position |= PL_POSITION_RIGHT;
			label_opts[0] = PL_COLORBAR_LABEL_RIGHT;
b76d3cfc   Benjamin Renard   Fix color axis po...
1016
			_pls->vpor(pPlotAreaSize._x, pPlotAreaSize._x + pPlotAreaSize._width + pZAxis->getAxisOffset(), pPlotAreaSize._y, pPlotAreaSize._y + pPlotAreaSize._height);
fbe3c2bb   Benjamin Renard   First commit
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
			break;
		default:
		{
			std::stringstream lError;
			lError << "PanelPlotOutput::drawZAxis : Bad Z axis position";
			BOOST_THROW_EXCEPTION(
					PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
		}
	}

b76d3cfc   Benjamin Renard   Fix color axis po...
1027
1028
	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),std::get<2>(pPlWindow), std::get<3>(pPlWindow));

fbe3c2bb   Benjamin Renard   First commit
1029
1030
1031
1032
1033
	_pls->colorbar(
			&colorbar_width,
			&colorbar_height,
			PL_COLORBAR_GRADIENT, //PL_COLORBAR_SHADE,
	        position,
b76d3cfc   Benjamin Renard   Fix color axis po...
1034
	        0.0, //COLORBAR_X_OFFSET,
fbe3c2bb   Benjamin Renard   First commit
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
	        0.0,
	        COLORBAR_BODY_WIDTH,
	        0.875,
	        0, /*bg_color*/
	        1,
	        1,
	        0.0,
	        0.0,
	        cont_color,
	        cont_width,
	        n_labels,
	        label_opts,
	        labels,
	        n_axis_opts,
	        axis_opts,
	        axis_ticks,
	        axis_subticks,
	        num_values,
	        (const PLFLT * const *) values
	 );

	//reset color map
	_pls->spal1(
				ColormapManager::getInstance().get(_panel->_page->_mode,
									ColormapManager::DEFAULT_COLORMAP_1).c_str(), true);

	_pls->scol0(0, lInitialColor._red, lInitialColor._green, lInitialColor._blue);

	delete [] shedge;

	// Restore initial color.
	restoreColor(_pls, lInitialColor, _panel->_page->_mode);

b76d3cfc   Benjamin Renard   Fix color axis po...
1068
1069
1070
1071
1072
1073
1074
1075
1076
	// Restore default plot area
	_pls->vpor(pPlotAreaSize._x,
		pPlotAreaSize._x + pPlotAreaSize._width,
		pPlotAreaSize._y,
		pPlotAreaSize._y + pPlotAreaSize._height);

	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow),std::get<2>(pPlWindow), std::get<3>(pPlWindow));


fbe3c2bb   Benjamin Renard   First commit
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
	// Set axis as drawn.
	pZAxis->_drawn = true;
}

Range PanelPlotOutput::getXAxisRange (SeriesProperties& pSeries, boost::shared_ptr<Axis> pAxis) {

	if (pSeries.hasXAxis() && pAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "PanelPlotOutput::drawSeries" << ": X axis with id '"
				<< pSeries.getXAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(
				PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}
	else if(pSeries.hasXAxis()) {
		// fill X range (plplot window).
		return (pAxis->getRange());
	}
	return Range();
}

Range PanelPlotOutput::getYAxisRange (SeriesProperties& pSeries, boost::shared_ptr<Axis> pAxis) {

	if (pSeries.hasYAxis() && pAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "PanelPlotOutput::drawSeries" << ": Y axis with id '"
				<< pSeries.getYAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(
				PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}
	else if(pSeries.hasYAxis()) {
		// fill Y range (plplot window).
		return (pAxis->getRange());
	}
	return Range();
}

Range PanelPlotOutput::getZAxisRange (SeriesProperties& pSeries, boost::shared_ptr<Axis> pAxis) {

	if (pSeries.hasZAxis() && pAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "PanelPlotOutput::drawSeries" << ": Z axis with id '"
				<< pSeries.getYAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(
				PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}
	else if(pSeries.hasZAxis()) {
		// fill Z range (plplot window).
		return (pAxis->getRange());
	}
	return Range();
}


/**
 * Convert an X axis string value to a double X value
 */
double PanelPlotOutput::convertXAxisValue(const std::string &value) {
	return std::stod(value);
}

/**
 * Convert an Y axis string value to a double Y value
 */
double PanelPlotOutput::convertYAxisValue(const std::string &value) {
	return std::stod(value);
}

/**
 * Get colored value associated to a data value. Return false if the value is filtered.
 */
bool PanelPlotOutput::getColoredValue(double value, double filterMin, double filterMax, PLFLT &col)
{
	boost::shared_ptr<ColorAxis> lZAxis = _panel->getColorAxis();

	if (lZAxis == nullptr)
		return false;

	bool filterMinMax = (isNAN (filterMin) == false) || (isNAN (filterMax) == false);

	Range r = lZAxis->getRange();

	if (isnan(value))
		return false;

	if ((filterMinMax == true) && ((value < filterMin) || (value > filterMax)))
		return false;

	double correctedValue = value;
	if (lZAxis->_scale == Axis::Scale::LOGARITHMIC)
	{
		if (correctedValue <= 0)
			return false;

		correctedValue = log10(correctedValue);
	}

1c0193a5   Benjamin Renard   Implement variabl...
1173
1174
1175
1176
	if (!lZAxis->_reverse)
		col=(correctedValue-r.getMin())/(r.getMax() - r.getMin());
	else
		col=(correctedValue-r.getMax())/(r.getMin() - r.getMax());
fbe3c2bb   Benjamin Renard   First commit
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194

	return true;
}

/**
 * Draw list of symbols
 */
 void PanelPlotOutput::drawSymbols(SymbolType pType, int pSize, double pFactor, Color pColor,
	int pNbData, double* pXData, double* pYData, double* pZData, double filterZMin, double filterZMax)
{
	if (pType == SymbolType::NO)
		return;

	Color lInitialColor;

	// Set color.
	lInitialColor = changeColor(_pls, pColor, _panel->_page->_mode);

f6eaec4e   Benjamin Renard   Optimize plot ele...
1195
1196

	PlPlotUtil::setPlFont(_panel->_page->getFont());
3befa3ce   Benjamin Renard   Fix a bug with sy...
1197

fbe3c2bb   Benjamin Renard   First commit
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
	// Set size.
	_pls->ssym(pSize, pFactor);

	// Get colored axis
	boost::shared_ptr<ColorAxis> lZAxis = _panel->getColorAxis();

	//draw symbols
	if ((pZData == NULL) || (lZAxis == nullptr))
		_pls->poin(pNbData, pXData, pYData, static_cast<int>(pType));
	else
	{
		//set color map
		_pls->spal1(
			ColormapManager::getInstance().getColorAxis(lZAxis->_color._colorMapIndex).c_str(), true);

		//get specific colors for min / max values
		Color minValColor = lZAxis->getMinValColor();
		Color maxValColor = lZAxis->getMaxValColor();

		PLFLT col;
		for (int i = 0; i < pNbData; ++i)
		{
			if (!getColoredValue(pZData[i], filterZMin, filterZMax, col))
				continue;

			if(col <= 0.)
        	{
        		if (minValColor.isSet())
        		{
        			restoreColor(_pls, minValColor, _panel->_page->_mode);
					_pls->poin(1, &pXData[i], &pYData[i], static_cast<int>(pType));
        			_pls->spal1(ColormapManager::getInstance().getColorAxis(lZAxis->_color._colorMapIndex).c_str(), true);
        		}
        		else
        		{
        			_pls->col1(0);
        			_pls->poin(1, &pXData[i], &pYData[i], static_cast<int>(pType));
        		}
        	}
        	else if (col>=1.)
        	{
        		if (maxValColor.isSet())
        		{
        			restoreColor(_pls, maxValColor, _panel->_page->_mode);
        			_pls->poin(1, &pXData[i], &pYData[i], static_cast<int>(pType));
        			_pls->spal1(ColormapManager::getInstance().getColorAxis(lZAxis->_color._colorMapIndex).c_str(), true);
        		}
        		else
        		{
        			_pls->col1(1);
        			_pls->poin(1, &pXData[i], &pYData[i], static_cast<int>(pType));
        		}
        	}
           	else
        	{
           		_pls->col1(col);
        		_pls->poin(1, &pXData[i], &pYData[i], static_cast<int>(pType));
        	}

		}
	}

	// Restore color.
	restoreColor(_pls, lInitialColor, _panel->_page->_mode);
}

/**
 * Draw list of lines
 */
void PanelPlotOutput::drawLines(LineType pType, LineStyle pStyle, int pWidth, Color& pColor,
	int pNbData, double* pXData, double* pYData, double* pZData, double filterZMin, double filterZMax)
{
	if (pType == LineType::EMPTY)
		return;

	if (pType != LineType::LINE)
	{
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg("HISTO line type can't be used in time plot. Use LINE or EMPTY type"));
	}

	Color lInitialColor;

	// Set color.
	lInitialColor = changeColor(_pls, pColor, _panel->_page->_mode);

	// Set line type.
	_pls->lsty(static_cast<int>(getPlLineStyle(pStyle)));

	// Set line thickness.
	_pls->width(pWidth);

	// Get colored axis
	boost::shared_ptr<ColorAxis> lZAxis = _panel->getColorAxis();

	// draw lines.
	if ((pZData == NULL) || (lZAxis == nullptr)) {
		_pls->line(pNbData, pXData, pYData);
	}
	else
	{
		//set color map
		_pls->spal1(
				ColormapManager::getInstance().getColorAxis(lZAxis->_color._colorMapIndex).c_str(), true);

		//get specific colors for min / max values
		Color minValColor = lZAxis->getMinValColor();
		Color maxValColor = lZAxis->getMaxValColor();

		PLFLT col;
		for (int i = 0; i < pNbData - 1; ++i)
		{
			if (!getColoredValue(pZData[i], filterZMin, filterZMax, col))
				continue;

			if(col <= 0.)
        	{
        		if (minValColor.isSet())
        		{
        			restoreColor(_pls, minValColor, _panel->_page->_mode);
					_pls->line(2, &pXData[i], &pYData[i]);
        			_pls->spal1(ColormapManager::getInstance().getColorAxis(lZAxis->_color._colorMapIndex).c_str(), true);
        		}
        		else
        		{
        			_pls->col1(0);
        			_pls->line(2, &pXData[i], &pYData[i]);
        		}
        	}
        	else if (col>=1.)
        	{
        		if (maxValColor.isSet())
        		{
        			restoreColor(_pls, maxValColor, _panel->_page->_mode);
        			_pls->line(2, &pXData[i], &pYData[i]);
        			_pls->spal1(ColormapManager::getInstance().getColorAxis(lZAxis->_color._colorMapIndex).c_str(), true);
        		}
        		else
        		{
        			_pls->col1(1);
        			_pls->line(2, &pXData[i], &pYData[i]);
        		}
        	}
           	else
        	{
           		_pls->col1(col);
        		_pls->line(2, &pXData[i], &pYData[i]);
        	}
		}
	}

	// Restore color.
	restoreColor(_pls, lInitialColor, _panel->_page->_mode);
}

/*
 * @brief Draw a matrix
 */
void PanelPlotOutput::drawMatrix(MatrixGrid& matrixGrid, double minDataVal, double maxDataVal,
		Color minValColor, Color maxValColor, int colorMapIndex, bool dataValueIsColorIndex)
{
	//set color map
	_pls->spal1(
		ColormapManager::getInstance().getColorAxis(colorMapIndex).c_str(), true);

	Color lInitialColor;
	_pls->gcol0(0, lInitialColor._red, lInitialColor._green, lInitialColor._blue);

	//plot matrix
	PLFLT x[4], y[4];
	PLFLT col;

	for ( auto part : matrixGrid )
	{
		x[0] = part.x[0];
		x[1] = part.x[1];
		x[2] = x[1];
		x[3] = x[0];

		y[0] = part.y[0];
		y[1] = y[0];
		y[2] = part.y[1];
		y[3] = y[2];

f2db3c16   Benjamin Renard   Support variable ...
1381
1382
1383
		if (isNAN(part.value))
			continue;

fbe3c2bb   Benjamin Renard   First commit
1384
1385
1386
1387
1388
1389
1390
		if (!dataValueIsColorIndex)
		{
			if (!getColoredValue(part.value, minDataVal, maxDataVal, col))
				continue;
		}
		else
		{
fbe3c2bb   Benjamin Renard   First commit
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
			Color dataValueColor(colorMapIndex, (int)part.value);
			restoreColor(_pls, dataValueColor, _panel->_page->_mode);
			_pls->fill(4, x, y);
			_pls->spal1(ColormapManager::getInstance().getColorAxis(colorMapIndex).c_str(), true);
			continue;
		}

		if(col <= 0.)
		{
			if (minValColor.isSet())
			{
				restoreColor(_pls, minValColor, _panel->_page->_mode);
				_pls->fill(4, x, y);
				_pls->spal1(ColormapManager::getInstance().getColorAxis(colorMapIndex).c_str(), true);
			}
			else
			{
				_pls->col1(0);
				_pls->fill(4, x, y);
			}
		}
		else if (col>=1.)
		{
			if (maxValColor.isSet())
			{
				restoreColor(_pls, maxValColor, _panel->_page->_mode);
				_pls->fill(4, x, y);
				_pls->spal1(ColormapManager::getInstance().getColorAxis(colorMapIndex).c_str(), true);
			}
			else
			{
				_pls->col1(1);
				_pls->fill(4, x, y);
			}
		}
		else
		{
			_pls->col1(col);
			_pls->fill(4, x, y);
		}
	}

	//restore to initial color context
	_pls->spal1(
			ColormapManager::getInstance().get(_panel->_page->_mode,
					ColormapManager::DEFAULT_COLORMAP_1).c_str(), true);
	_pls->scol0(0, lInitialColor._red, lInitialColor._green, lInitialColor._blue);

	// Restore color.
	restoreColor(_pls, lInitialColor, _panel->_page->_mode);
}

/**
 * Draw errors segments
 */
void PanelPlotOutput::drawYErrors
	(
	LineType pType,
	LineStyle pStyle,
	int pWidth,
	Color& pColor,
	int pNbData,
	double* pXData,
	double* pYMinData,
	double* pYMaxData
	)
{
	if (pType == LineType::EMPTY)
		return;

	if (pType != LineType::LINE)
	{
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg("HISTO line type can't be used in time plot. Use LINE or EMPTY type"));
	}

	Color lInitialColor;

	// Set color.
	lInitialColor = changeColor(_pls, pColor, _panel->_page->_mode);

	// Set line type.
	_pls->lsty(static_cast<int>(getPlLineStyle(pStyle)));

	// Set line thickness.
	_pls->width(pWidth);

	// Set the default tich with
	_pls->smin (0, 0.5);

	// Draw error bars
	_pls->erry(pNbData, pXData, pYMinData, pYMaxData);

	// Restore color.
	restoreColor(_pls, lInitialColor, _panel->_page->_mode);
}

/**
 * Draws X constant lines linked to axis
 */
void PanelPlotOutput::drawXConstantLines(boost::shared_ptr<Axis> pAxis, PlWindow& pPlWindow) {
	double x [2], y [2];

078ec265   Benjamin Renard   Give the possibil...
1493
1494
	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow), std::get<2>(pPlWindow), std::get<3>(pPlWindow));

fbe3c2bb   Benjamin Renard   First commit
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
	for (auto constantLine : pAxis->_constantLines) {
		if (constantLine->isDrawn())
			continue;
		x[0] = convertXAxisValue (constantLine->getValue());
		x[1] = convertXAxisValue (constantLine->getValue());
		y[0] = std::get<2>(pPlWindow);
		y[1] = std::get<3>(pPlWindow);

		if (pAxis->_scale == Axis::Scale::LOGARITHMIC) {
			x[0] = log10 (x[0]);
			x[1] = log10 (x[1]);
		}

		drawLines(
				LineType::LINE,
				constantLine->getStyle(),
				constantLine->getWidth(),
				constantLine->getColor(),
				2, x, y);

		constantLine->setDrawn(true);
	}
}

/**
 * Draws Y constant lines linked to axis
 */
void PanelPlotOutput::drawYConstantLines(boost::shared_ptr<Axis> pAxis, PlWindow& pPlWindow) {
	double x [2], y [2];

078ec265   Benjamin Renard   Give the possibil...
1525
1526
	_pls->wind(std::get<0>(pPlWindow), std::get<1>(pPlWindow), std::get<2>(pPlWindow), std::get<3>(pPlWindow));

fbe3c2bb   Benjamin Renard   First commit
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
	for (auto constantLine : pAxis->_constantLines) {
		if (constantLine->isDrawn())
			continue;

		x[0] = std::get<0>(pPlWindow);
		x[1] = std::get<1>(pPlWindow);
		y[0] = convertYAxisValue(constantLine->getValue());
		y[1] = convertYAxisValue(constantLine->getValue());

		if (pAxis->_scale == Axis::Scale::LOGARITHMIC) {
			y[0] = log10 (y[0]);
			y[1] = log10 (y[1]);
		}

		drawLines(
				LineType::LINE,
				constantLine->getStyle(),
				constantLine->getWidth(),
				constantLine->getColor(),
				2, x, y);

		constantLine->setDrawn(true);
	}
}

/**
 * Draws TextPlots
 */
078ec265   Benjamin Renard   Give the possibil...
1555
void PanelPlotOutput::drawTextPlots(boost::shared_ptr<Axis> pXAxis, boost::shared_ptr<Axis> pYAxis, PlWindow& pPlWindow, const TextPlots &textPlots) {
fbe3c2bb   Benjamin Renard   First commit
1556
1557
1558
1559
1560
1561
1562
1563
	double x, y;
	double x1, x2, y1, y2;

	x1 = std::get<0>(pPlWindow);
	x2 = std::get<1>(pPlWindow);
	y1 = std::get<2>(pPlWindow);
	y2 = std::get<3>(pPlWindow);

078ec265   Benjamin Renard   Give the possibil...
1564
1565
	_pls->wind(x1, x2, y1, y2);

fbe3c2bb   Benjamin Renard   First commit
1566
1567
1568
1569
	for (auto textPlot: textPlots) {
		if (textPlot->isDrawn())
			continue;

078ec265   Benjamin Renard   Give the possibil...
1570
1571
1572
1573
1574
1575
		if (!textPlot->_xAxisId.empty() && (textPlot->_xAxisId.compare(pXAxis->_id) != 0))
			continue;

		if (!textPlot->_yAxisId.empty() && (textPlot->_yAxisId.compare(pYAxis->_id) != 0))
			continue;

fbe3c2bb   Benjamin Renard   First commit
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
		// Compute x y position for the text
		if (textPlot->_x.find("%") != std::string::npos) {
			// Remove % before conversion
			int pos = textPlot->_x.find("%");
			std::string xPos = textPlot->_x;
			xPos.erase(pos);
			// Compute x value as a percent of the x value
			x = x1 + (x2-x1) * std::stod (xPos) / 100.0;
		}
		else {
			x = convertXAxisValue(textPlot->_x);
		}

		if (textPlot->_y.find("%") != std::string::npos) {
			// Remove % before conversion
			int pos = textPlot->_y.find("%");
			std::string yPos = textPlot->_y;
			yPos.erase(pos);
			// Compute x value as a percent of the x value
			y = y1 + (y2-y1) * std::stod (yPos) / 100.0;
		}
		else {
			y = convertYAxisValue(textPlot->_y);
		}

		// Select font family, size, style and weight
f6eaec4e   Benjamin Renard   Optimize plot ele...
1602
		PlPlotUtil::setPlFont(textPlot->getFont());
fbe3c2bb   Benjamin Renard   First commit
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683

		// Set color
		Color lInitialColor = changeColor(_pls, textPlot->_color, _panel->_page->_mode);

		// Compute dx & dy orientation
		double dx = cos(textPlot->_angle*M_PI/180) * (x2-x1)/10.0;
		double dy = sin(textPlot->_angle*M_PI/180) * (y2-y1)/10.0 * _panelPlotXYRatio;

		// Draw text
		_pls->ptex (x, y, dx, dy, textPlot->_align, textPlot->_text.c_str());

		// Restore initial color.
		restoreColor(_pls, lInitialColor, _panel->_page->_mode);

		textPlot->setDrawn(true);
	}
}

/*
 * @brief Draw interval
 */
void PanelPlotOutput::drawSerieInterval(SeriesProperties& pSeries,
		double* xValues, double* yValues, double* timeValues,
		int nbValues, int intervalIndex)
{
	LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::drawSerieInterval");

	IntervalTickProperties itProps = pSeries.getIntervalTickProperties();

	// Draw Interval ticks if required !
	if (itProps.getMode() == IntervalTickMode::NONE)
		return;

	// Get X and Y axis.
	boost::shared_ptr<Axis> lXAxis(_panel->getAxis(pSeries.getXAxisId()));
	boost::shared_ptr<Axis> lYAxis(_panel->getAxis(pSeries.getYAxisId()));

	Range lXRange = getXAxisRange (pSeries, lXAxis);
	Range lYRange = getYAxisRange (pSeries, lYAxis);

	PlWindow lPlWindow = PlWindow(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());

	//prepare data for plot
	double xData[2] = {NAN,NAN};
	double yData[2] = {NAN,NAN};
	double timeData[2] = {NAN,NAN};

	//skip NAN values
	for (int i = 0; i < nbValues; ++i)
		if (!isNAN(xValues[i]) && !isNAN(yValues[i]))
		{
			xData[0] = xValues[i];
			yData[0] = yValues[i];
			timeData[0] = timeValues[i];
			break;
		}

	for (int i = nbValues - 1; i >= 0; --i)
		if (!isNAN(xValues[i]) && !isNAN(yValues[i]))
		{
			xData[1] = xValues[i];
			yData[1] = yValues[i];
			timeData[1] = timeValues[i];
			break;
		}

	//draw symbols
	drawSymbols(
		itProps.getSymbol().getType(),
		itProps.getSymbol().getSize(), 1.,
		itProps.getSymbol().getColor(),
		2, (double*)&xData, (double*)&yData, NULL);

	if (itProps.getMode() == IntervalTickMode::SYMBOL_ONLY)
		return;

	//Add start interval info to a list of TextPlot
	TextPlots textPlots;

	TextPlot baseTextPlot;
	baseTextPlot._color = itProps.getColor();
f6eaec4e   Benjamin Renard   Optimize plot ele...
1684
	baseTextPlot.setFont(itProps.getFont());
fbe3c2bb   Benjamin Renard   First commit
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725

	boost::shared_ptr<TextPlot> startTextPlot (new TextPlot (baseTextPlot));

	double xPos = (xData[0]-lXRange.getMin()) / (lXRange.getMax()-lXRange.getMin())*100;
	startTextPlot->_x = boost::lexical_cast<std::string>(xPos);
	startTextPlot->_x += "%";

	double yPos = (yData[0]-lYRange.getMin()) / (lYRange.getMax()-lYRange.getMin())*100 + 1.5;
	startTextPlot->_y = boost::lexical_cast<std::string>(yPos);
	startTextPlot->_y += "%";

	if (itProps.getMode() == IntervalTickMode::INTERVAL_INDEX)
	{
		startTextPlot->_text = "I";
		startTextPlot->_text += std::to_string(intervalIndex);
	}
	else
		startTextPlot->_text = AMDA::TimeUtil::formatTimeDateInIso(timeData[0]);

	textPlots.push_back(startTextPlot);

	if (itProps.getMode() != IntervalTickMode::START_TIME)
	{
		boost::shared_ptr<TextPlot> stopTextPlot (new TextPlot (baseTextPlot));

		xPos = (xData[1]-lXRange.getMin()) / (lXRange.getMax()-lXRange.getMin())*100;
		stopTextPlot->_x = boost::lexical_cast<std::string>(xPos);
		stopTextPlot->_x += "%";

		yPos = (yData[1]-lYRange.getMin()) / (lYRange.getMax()-lYRange.getMin())*100 + 1.5;
		stopTextPlot->_y = boost::lexical_cast<std::string>(yPos);
		stopTextPlot->_y += "%";

		if (itProps.getMode() == IntervalTickMode::INTERVAL_INDEX)
			stopTextPlot->_text = startTextPlot->_text;
		else
			stopTextPlot->_text = AMDA::TimeUtil::formatTimeDateInIso(timeData[1]);

		textPlots.push_back(stopTextPlot);
	}

078ec265   Benjamin Renard   Give the possibil...
1726
	drawTextPlots (lXAxis, lYAxis, lPlWindow, textPlots);
fbe3c2bb   Benjamin Renard   First commit
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
}

/**
 * @brief Draw parameters legend.
 */
void PanelPlotOutput::drawParamsLegend(void)
{
	ParamsLegendProperties &legendProp = _panel->_paramsLegendProperties;

	if (!legendProp.isVisible() || legendProp.isDrawn())
		return;

	std::list<LegendLineProperties> lines = legendProp.getLegendLines();

	if (lines.empty())
		return;

	//init arguments to call pllegend function
	PLINT nbLines = lines.size();

	PLINT      opt_array[nbLines];
	PLINT      text_colors[nbLines];
	PLINT      line_colors[nbLines];
	PLINT      line_styles[nbLines];
	PLFLT      line_widths[nbLines];
	PLINT      symbol_numbers[nbLines];
	PLINT      symbol_colors[nbLines];
	PLFLT      symbol_scales[nbLines];
	const char *symbols[nbLines];
	const char *texts[nbLines];

	int index = 0;
	std::string symbol_str[nbLines];
	for (auto line : lines)
	{
		opt_array[index] = 0;
		//set line options
		if (!legendProp.isOnlyText() && line.isLineVisible())
		{
			opt_array[index]  |= PL_LEGEND_LINE;
			line_colors[index] = legendProp.getColorIndex(_pls.get(),line.getLineProperties().getColor());
			line_styles[index] = static_cast<int>(getPlLineStyle(line.getLineProperties().getStyle()));
			line_widths[index] = line.getLineProperties().getWidth();
		}
		//set symbols options
		if (!legendProp.isOnlyText() && line.isSymbolsVisible())
		{
			opt_array[index]     |= PL_LEGEND_SYMBOL;
			symbol_numbers[index] = LEGEND_NB_SYMBOLS_TO_DRAW;
			symbol_colors[index]  = legendProp.getColorIndex(_pls.get(),line.getSymbolProperties().getColor());
f6eaec4e   Benjamin Renard   Optimize plot ele...
1777
			symbol_scales[index]  = (double)line.getSymbolProperties().getSize() / PlPlotUtil::DEFAULT_CHARACTER_SIZE;
fbe3c2bb   Benjamin Renard   First commit
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
			std::stringstream workingstr;
			workingstr << "#("<< fontTypeToSymSymbol[line.getSymbolProperties().getType()] << ")";
			symbol_str[index]     = workingstr.str();
			symbols[index]        = symbol_str[index].c_str();
		}

		text_colors[index] = legendProp.getColorIndex(_pls.get(),line.getTextColor(legendProp.isOnlyText()));
		texts[index]       = line.getText();
		++index;
	}


	PLFLT      legend_width, legend_height;
	PLINT opt = PL_LEGEND_BACKGROUND;

	//show or hide bounding box
	if (legendProp.isBorderVisible())
		opt |= PL_LEGEND_BOUNDING_BOX;

	PLINT position = PL_POSITION_VIEWPORT;
	switch (legendProp.getPosition())
	{
		case ParamsLegendPosition::POS_INSIDE :
			position |= PL_POSITION_INSIDE | PL_POSITION_TOP | PL_POSITION_RIGHT;
			break;
		case ParamsLegendPosition::POS_OUTSIDE :
			position |= PL_POSITION_OUTSIDE | PL_POSITION_RIGHT;
			break;
		default :
			LOG4CXX_WARN(gLogger, "Legend position not implemented => set to POS_INSIDE");
			position |= PL_POSITION_INSIDE | PL_POSITION_TOP | PL_POSITION_RIGHT;
	}

	//define offset
	PLFLT x_offset = 0.0;
	PLFLT y_offset = 0.0;

	switch (legendProp.getPosition())
	{
		case ParamsLegendPosition::POS_INSIDE :
			x_offset = LEGEND_INSIDE_OFFSET;
			y_offset = LEGEND_INSIDE_OFFSET * _panelPlotXYRatio;
			break;
		case ParamsLegendPosition::POS_OUTSIDE :
8b6d84db   Benjamin Renard   Fix legend positi...
1822
			x_offset = LEGEND_OUTSIDE_OFFSET;
fbe3c2bb   Benjamin Renard   First commit
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
			y_offset = 0.0;
			break;
		default :
			x_offset = LEGEND_INSIDE_OFFSET;
			y_offset = LEGEND_INSIDE_OFFSET * _panelPlotXYRatio;
	}

	//show or hide line and symbols
	PLFLT plot_width = 0;
	if (!legendProp.isOnlyText())
		plot_width = LEGEND_LINE_SYM_WIDTH;

	//background color = panel color
	PLINT bg_color = legendProp.getColorIndex(_pls.get(),_panel->_backgroundColor);

	//bounding box
	PLINT bb_color = legendProp.getColorIndex(_pls.get(),legendProp.getBorderColor());
	PLINT bb_style = 1;

	//text option
	PLFLT text_offset        = 0.0;
	if (!legendProp.isOnlyText())
		text_offset = LEGEND_TEXT_OFFSET;
f6eaec4e   Benjamin Renard   Optimize plot ele...
1846
	PLFLT text_scale         = PlPlotUtil::getPlFontScaleFactor(legendProp.getFont());
fbe3c2bb   Benjamin Renard   First commit
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
	PLFLT text_spacing       = LEGEND_TEXT_SPACING;
	PLFLT text_justification = LEGEND_TEXT_JUSTIFICATION;

	//colored boxes not used
	PLINT *box_colors      = NULL;
	PLINT *box_patterns    = NULL;
	PLFLT *box_scales      = NULL;
	PLFLT *box_line_widths = NULL;

	//save color
	Color fakeColor;
	Color initialColor = changeColor(_pls, fakeColor,
			_panel->_page->_mode);

	//set viewport
	_pls->vpor(_plotAreaBounds._x,
				_plotAreaBounds._x + _plotAreaBounds._width + legendProp.getLeftOffset(),
				_plotAreaBounds._y,
				_plotAreaBounds._y + _plotAreaBounds._height);

	//set font
f6eaec4e   Benjamin Renard   Optimize plot ele...
1868
	PlPlotUtil::setPlFont(legendProp.getFont());
fbe3c2bb   Benjamin Renard   First commit
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943

	//init cmap0 to draw legend
	std::vector<Color> colors = legendProp.getColorsMap();
	_pls->scmap0n(colors.size());
	index = 0;

	for (auto color : colors)
	{
		_pls->scol0(index,color._red,color._green,color._blue);
		++index;
	}

	//draw tthe legend
	_pls->legend(
			&legend_width,
			&legend_height,
			opt,
			position,
			x_offset,
			y_offset,
			plot_width,
			bg_color,
			bb_color,
			bb_style,
			0, /* nrow */
			0, /* ncolumn */
			nbLines,
			opt_array,
			text_offset,
			text_scale,
			text_spacing,
			text_justification,
			text_colors,
			(const char **) texts,
			box_colors,
			box_patterns,
			box_scales,
			box_line_widths,
			line_colors,
			line_styles,
			line_widths,
			symbol_colors,
			symbol_scales,
			symbol_numbers,
			(const char **) symbols);

	// Restore initial color.
	restoreColor(_pls, initialColor, _panel->_page->_mode);

	legendProp.setDrawn(true);
}

/**
 * @brief Draw text legends.
 */

void PanelPlotOutput::drawTextLegends(void) {
	double xmin = _plotAreaBounds._x;
	double xmax = _plotAreaBounds._x + _plotAreaBounds._width;
	double ymin = _plotAreaBounds._y;
	double ymax = _plotAreaBounds._y + _plotAreaBounds._height;

	bool	leftTextLegendFound		= false;
	bool	rightTextLegendFound 	= false;
	bool	topTextLegendFound 		= false;
	bool	bottomTextLegendFound 	= false;

	for (auto textLegend : _panel->_textLegendPropertiesList) {
		if (textLegend->isDrawn())
			continue;

		// Set color
		Color initialColor = changeColor(_pls, textLegend->getColor(), _panel->_page->_mode);

		//set font
f6eaec4e   Benjamin Renard   Optimize plot ele...
1944
		PlPlotUtil::setPlFont(textLegend->getFont());
fbe3c2bb   Benjamin Renard   First commit
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015

		// If legend at a given position not already drawn :
		//-  Set viewport depending on legend position
		// - Retrieve text lines from text legend and draw them
		// - See calculatePlotArea to know how text legend position are calculated
		std::vector<std::string> textLines = textLegend->getTextLines();
		double 	disp = 1;

		switch (textLegend->getPosition()) {
		case TextLegendPosition::POS_LEFT :
			if (leftTextLegendFound == false) {
				_pls->vpor(xmin - textLegend->getOffset(), xmax, ymin, ymax);
				for (int i=0; i<(int) textLines.size(); i++) {
					_pls->mtex ("l", disp, 0.5, 0.5, textLines.at(textLines.size() - 1 - i).c_str());
					disp += 1.5;
				}
				leftTextLegendFound = true;
			}
			break;

		case TextLegendPosition::POS_RIGHT :
			if (rightTextLegendFound == false) {
				_pls->vpor(xmin, xmax + textLegend->getOffset(), ymin, ymax);
				for (int i=0; i<(int) textLines.size(); i++) {
					_pls->mtex ("r", disp, 0.5, 0.5, textLines.at(i).c_str());
					disp += 1.5;
				}
				rightTextLegendFound = true;
			}
			break;

		case TextLegendPosition::POS_TOP :
			if (topTextLegendFound == false) {
				_pls->vpor(xmin, xmax, ymin, ymax + textLegend->getOffset());
				for (int i=0; i<(int) textLines.size(); i++) {
					_pls->mtex ("t", disp, 0.5, 0.5, textLines.at(textLines.size() - 1 - i).c_str());
					disp += 1.5;
				}
				topTextLegendFound = true;
			}
			break;

		case TextLegendPosition::POS_BOTTOM :
			if (bottomTextLegendFound == false) {
				_pls->vpor(xmin, xmax, ymin - textLegend->getOffset(), ymax);
				for (int i=0; i<(int) textLines.size(); i++) {
					_pls->mtex ("b", disp, 0.5, 0.5, textLines.at(i).c_str());
					disp += 1.5;
				}
				bottomTextLegendFound = true;
			}
			break;

		default :
			break;
		}

		restoreColor(_pls, initialColor, _panel->_page->_mode);

		textLegend->setDrawn(true);
	}
}

/**
 * Draws Curve
 */
void PanelPlotOutput::drawCurvePlot(CurvePlot &/*curvePlot*/) {
	//Nothing to do - Deleguate to subclasses
}

/**
8499fbdd   Benjamin Renard   Context file gene...
2016
2017
2018
 * @brief Write plot context
 */
void PanelPlotOutput::writeContext(ContextFileWriter& writer) {
7f7e3b39   Benjamin Renard   Fix a bug with st...
2019
2020
2021
2022
2023
2024
	DecoratorPlot *decoratorPlot = dynamic_cast< DecoratorPlot* >(this);

	if (decoratorPlot != NULL)
		if (!decoratorPlot->_isStandalone)
			return;

85bb5117   Benjamin Renard   Give the possibil...
2025
	writer.startElement("panel");
8499fbdd   Benjamin Renard   Context file gene...
2026
	_panel->writeContext(_pls, writer);
8499fbdd   Benjamin Renard   Context file gene...
2027

85bb5117   Benjamin Renard   Give the possibil...
2028
2029
	if (!_parameterAxesList.empty())
	{
24600903   Benjamin Renard   Add "hasSpectro" ...
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
		bool hasSpectro = false;
		for (auto parameter : _parameterAxesList)
		{
			if (parameter.getSpectroProperties() != nullptr) {
				hasSpectro = true;
				break;
			}
		}


85bb5117   Benjamin Renard   Give the possibil...
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
		writer.startElement("plotArea");
		if (_panel->_page->_orientation == PlotCommon::Orientation::PORTRAIT)
		{
			writer.addAttribute("x",std::to_string(_plotAreaBounds._y*std::get<0>(_panel->_page->getSize())).c_str());
			writer.addAttribute("y",std::to_string(_plotAreaBounds._x*std::get<1>(_panel->_page->getSize())).c_str());
			writer.addAttribute("width",std::to_string(_plotAreaBounds._height*std::get<0>(_panel->_page->getSize())).c_str());
			writer.addAttribute("height",std::to_string(_plotAreaBounds._width*std::get<1>(_panel->_page->getSize())).c_str());
		}
		else
		{
			writer.addAttribute("x",std::to_string(_plotAreaBounds._x*std::get<0>(_panel->_page->getSize())).c_str());
			writer.addAttribute("y",std::to_string(_plotAreaBounds._y*std::get<1>(_panel->_page->getSize())).c_str());
			writer.addAttribute("width",std::to_string(_plotAreaBounds._width*std::get<0>(_panel->_page->getSize())).c_str());
			writer.addAttribute("height",std::to_string(_plotAreaBounds._height*std::get<1>(_panel->_page->getSize())).c_str());
		}

24600903   Benjamin Renard   Add "hasSpectro" ...
2056
2057
		writer.addAttribute("hasSpectro", hasSpectro ? "true" : "false");

85bb5117   Benjamin Renard   Give the possibil...
2058
		for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it) {
8499fbdd   Benjamin Renard   Context file gene...
2059
2060
2061
2062
2063
			boost::shared_ptr<Axis> lAxis = it->second;

			if (lAxis == nullptr)
				continue;

08ec1dde   Benjamin Renard   Add propertie _us...
2064
			if (lAxis->_visible && lAxis->_used)
8499fbdd   Benjamin Renard   Context file gene...
2065
				lAxis->writeContext(writer);
85bb5117   Benjamin Renard   Give the possibil...
2066
2067
		}

24600903   Benjamin Renard   Add "hasSpectro" ...
2068

85bb5117   Benjamin Renard   Give the possibil...
2069
		writer.endElement();
8499fbdd   Benjamin Renard   Context file gene...
2070
	}
85bb5117   Benjamin Renard   Give the possibil...
2071
2072

	writer.endElement();
8499fbdd   Benjamin Renard   Context file gene...
2073
2074
2075
}

/**
fbe3c2bb   Benjamin Renard   First commit
2076
2077
2078
 * @brief Compute the initial plot area for the panel
 */
void PanelPlotOutput::preparePlotArea(double /*startTime*/, double /*stopTime*/, int /*intervalIndex*/) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
2079
	_plotAreaBounds = 	_panel->getBoundsInPlPage();
fbe3c2bb   Benjamin Renard   First commit
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
	calculatePlotArea (_plotAreaBounds);
}

/**
 * @brief Retrieve plot area bounds for the panel
 */
void PanelPlotOutput::getPlotAreaBounds (Bounds &plotAreaBounds) {
	plotAreaBounds = _plotAreaBounds;
}

/**
 * @brief Force the plot area horizontal position and width
 */
void PanelPlotOutput::forcePlotAreaPosAndWidth(double plotAreaX, double plotAreaWidth) {
	_plotAreaBounds._x = plotAreaX;
	_plotAreaBounds._width = plotAreaWidth;
}

/**
 * @brief Retrieve left axis tickMark width
 */
int PanelPlotOutput::getLeftAxisTickMarkWidth (void) {
	return _leftAxisTickMarkWidth;
}

/**
 * @brief Force left axis tickmark width for the panel
 */
void PanelPlotOutput::forceLeftAxisTickMarkWidth(int leftAxisTickMarkWidth) {
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it) {
		boost::shared_ptr<Axis> lAxis = it->second;
abded81c   Benjamin Renard   Plot area alignme...
2111
2112
		if (lAxis == nullptr)
			continue;
fbe3c2bb   Benjamin Renard   First commit
2113
2114
2115
2116
2117
2118
2119
2120
		// Look for a visible fleft Axis with legend and
		if ((lAxis->_visible) && (lAxis->_position == PlotCommon::Position::POS_LEFT)) {
			lAxis->setFixedTickMarkWidth(leftAxisTickMarkWidth);
		}
	}
}

/**
8bb0f02b   Benjamin Renard   Set colors in axi...
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
 * @brief Get nb series to draw by y axis
 */
std::map<std::string,int>& PanelPlotOutput::getNbSeriesByYAxis() {
	if (!_nbSeriesByYAxisMap.empty()) {
		return _nbSeriesByYAxisMap;
	}
	SeriesProperties lSeries;
	for (auto parameter : _parameterAxesList)
	{
		std::vector<AMDA::Common::ParameterIndexComponent> parameterYSerieIndexList = parameter.getYSerieIndexList(_pParameterValues);
		for (auto lIndex : parameterYSerieIndexList)
		{
			// Get series properties
			lSeries = parameter.getYSeriePropertiesAt(lIndex);

			
                        if (!lSeries.hasYAxis())
				continue;

			std::string yAxisId = lSeries.getYAxisId();

			if (_nbSeriesByYAxisMap.find(yAxisId) == _nbSeriesByYAxisMap.end())
				_nbSeriesByYAxisMap[yAxisId] = 0;

			++_nbSeriesByYAxisMap[yAxisId];
		}
	}
	return _nbSeriesByYAxisMap;
}

/**
fbe3c2bb   Benjamin Renard   First commit
2152
2153
 * @brief draw the plot for the current time interval
 */
d57f00dc   Benjamin Renard   Draw NO DATA
2154
bool PanelPlotOutput::draw(double startTime, double stopTime, int intervalIndex,
fbe3c2bb   Benjamin Renard   First commit
2155
2156
2157
2158
		bool isFirstInterval, bool isLastInterval) {
	// Sets panel plplot viewport, draw background & title for the panel
	_panel->draw(_pls);

d57f00dc   Benjamin Renard   Draw NO DATA
2159
2160
2161
2162
	 bool noData = true;

	if (_parameterAxesList.empty()) {
		noData = false; //Do not draw No Data if the panel is empty
b96aa975   Benjamin Renard   Draw border aroun...
2163
		_panel->drawEmptyPanel(_pls);
d57f00dc   Benjamin Renard   Draw NO DATA
2164
	}
08ec1dde   Benjamin Renard   Add propertie _us...
2165

fbe3c2bb   Benjamin Renard   First commit
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
	if (isFirstInterval)
		_panel->_paramsLegendProperties.reset();

	//Set pointer to ParameterData list
	if (_pParameterValues == NULL)
	{
		std::stringstream lError;
			lError << "PanelPlotOutput::draw - Pointer to parameterValues is not set";
		BOOST_THROW_EXCEPTION(
				PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

	LOG4CXX_DEBUG(gLogger, "Panel bounds = "<< _panel->_bounds.toString());
	LOG4CXX_DEBUG(gLogger, "Plot area = "<< _plotAreaBounds.toString());

	//Draw spectro
	for (auto parameter : _parameterAxesList) {
		if (parameter.getSpectroProperties() != nullptr) {
			//draw spectro
			LOG4CXX_DEBUG(gLogger, "Draw a spectro for parameter " << parameter._originalParamId);
			// Draw (configure) window for this series.
			drawSpectro(startTime, stopTime, parameter._originalParamId, *(parameter.getSpectroProperties()));
d57f00dc   Benjamin Renard   Draw NO DATA
2188
2189
2190
2191
2192
2193
2194

			ParameterData &data = (*_pParameterValues)[parameter.getSpectroProperties()->getParamId()];

			for (auto index : parameter.getSpectroProperties()->getIndexes()) {
				if (noData)
					noData = data.noData(index);
			}
fbe3c2bb   Benjamin Renard   First commit
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
		}
	}

	// Compute panel XY ratio used for angular conversions
	computePanelPlotXYRatio();

	// Draw fill area between parameter and constant or between parameters
	drawFills (startTime, stopTime);

	// Compute nb series to draw by y axis
8bb0f02b   Benjamin Renard   Set colors in axi...
2205
	std::map<std::string,int> nbSeriesByYAxisMap = getNbSeriesByYAxis();
fbe3c2bb   Benjamin Renard   First commit
2206
	SeriesProperties lSeries;
fbe3c2bb   Benjamin Renard   First commit
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
	// Draw series for parameters.
	for (auto parameter : _parameterAxesList) {
		// Get series index to draw for parameter
		// Draw each index of parameter
		std::vector<AMDA::Common::ParameterIndexComponent> parameterYSerieIndexList = parameter.getYSerieIndexList(_pParameterValues);
		for (auto lIndex : parameterYSerieIndexList) {
			// Get series properties
			lSeries = parameter.getYSeriePropertiesAt(lIndex);

			bool moreThanOneSerieForYAxis = false;
			if (lSeries.hasYAxis())
				moreThanOneSerieForYAxis = (nbSeriesByYAxisMap[lSeries.getYAxisId()] > 1);

			// Draw (configure) window for this series.
			drawSeries(startTime, stopTime, intervalIndex, parameter._originalParamId,
					lSeries, lIndex, parameter, moreThanOneSerieForYAxis);
d57f00dc   Benjamin Renard   Draw NO DATA
2223
2224
2225
2226
			ParameterData &data = (*_pParameterValues)[lSeries.getParamId()];
			if (noData) {
				noData = data.noData(lIndex);
			}
fbe3c2bb   Benjamin Renard   First commit
2227
2228
2229
2230
2231
		}
	}



078ec265   Benjamin Renard   Give the possibil...
2232
2233
	// Draw additional objects
	drawAdditionalObjects();
fbe3c2bb   Benjamin Renard   First commit
2234
2235
2236
2237
2238
2239
2240

	//Draw parameter legend
	if (isLastInterval || !_panel->_page->_superposeMode)
		drawParamsLegend();

	//Draw text legends
	drawTextLegends();
d57f00dc   Benjamin Renard   Draw NO DATA
2241
2242

	return !noData;
fbe3c2bb   Benjamin Renard   First commit
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
}

void PanelPlotOutput::drawSpectro(double /*startDate*/, double /*stopDate*/, std::string /*pParamId*/,
		SpectroProperties& pSpectro) {
	// Get X, Y and Z axis.
		boost::shared_ptr<Axis> lXAxis(_panel->getAxis(pSpectro.getXAxisId()));
		boost::shared_ptr<Axis> lYAxis(_panel->getAxis(pSpectro.getYAxisId()));
		boost::shared_ptr<Axis> lZAxis(_panel->getAxis(pSpectro.getZAxisId()));

		PlWindow lPlWindow;
		Range lXRange, lYRange, lZRange;
		if (pSpectro.hasXAxis() && lXAxis.get() == nullptr) {
			std::stringstream lError;
			lError << "PanelPlotOutput::drawSpectro" << ": X axis with id '"
					<< pSpectro.getXAxisId() << "' not found.";
			BOOST_THROW_EXCEPTION(
					PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
		}
		else if(pSpectro.hasXAxis()) {
			// fill X range (plplot window).
			lXRange = lXAxis->getRange();
		}

		if (pSpectro.hasYAxis() && lYAxis.get() == nullptr) {
			std::stringstream lError;
			lError << "PanelPlotOutput::drawSpectro" << ": Y axis with id '"
					<< pSpectro.getYAxisId() << "' not found.";
			BOOST_THROW_EXCEPTION(
					PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
			lYRange = Range();
		}
		else if(pSpectro.hasYAxis()){
			// fill Y range (plplot window).
			lYRange = lYAxis->getRange();
		}

		if (pSpectro.hasZAxis() && lZAxis.get() == nullptr) {
			std::stringstream lError;
			lError << "PanelPlotOutput::drawSpectro" << ": Z axis with id '"
					<< pSpectro.getZAxisId() << "' not found.";
			BOOST_THROW_EXCEPTION(
					PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
			lZRange = Range();
		}
		else if(pSpectro.hasZAxis()){
			// fill Z range (plplot window).
			lZRange = lZAxis->getRange();
		}

		lPlWindow = PlWindow(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());


		// Calculate X and Y tick
		TickConf lTickConf;
		double lXMajorTickSpace = nan("");
		int lXMinorTickNumber = 0;
		double lYMajorTickSpace = nan("");
		int lYMinorTickNumber = 0;

		if(pSpectro.hasXAxis()){
			// Calculate X tick
			lXMajorTickSpace = getMajorTickSpace(lXAxis.get(),
					std::get<0>(lPlWindow), std::get<1>(lPlWindow));
			lXMinorTickNumber = getMinorTickNumber(lXAxis.get(),
					std::get<0>(lPlWindow), std::get<1>(lPlWindow),	lXMajorTickSpace);
		}

		if(pSpectro.hasYAxis()){
			// Calculate Y tick
			lYMajorTickSpace = getMajorTickSpace(lYAxis.get(), std::get<2>(lPlWindow), std::get<3>(lPlWindow));
			lYMinorTickNumber = getMinorTickNumber(lYAxis.get(), std::get<2>(lPlWindow), std::get<3>(lPlWindow),
					lYMajorTickSpace);
		}

		lTickConf = TickConf(lXMajorTickSpace, lXMinorTickNumber, lYMajorTickSpace, lYMinorTickNumber);


		// Draw Y axis and legend
		if (pSpectro.hasYAxis() && !lYAxis->_drawn) {

			drawYAxis(lYAxis, lPlWindow, _plotAreaBounds, lTickConf);

			// Draw legend.
			drawLegends(lYAxis, lPlWindow, _plotAreaBounds);
		}

		// Draw X axis and legend
		if (pSpectro.hasXAxis() && !lXAxis->_drawn) {

			drawXAxis(lXAxis, lPlWindow, _plotAreaBounds, lTickConf);

			// Draw legend.
			drawLegends(lXAxis, lPlWindow, _plotAreaBounds);
		}

		// Draw Z axis and legend
		if (pSpectro.hasZAxis() && (lZAxis != nullptr) && !lZAxis->_drawn) {
				drawZAxis(lZAxis, lPlWindow, _plotAreaBounds, lTickConf);
		}
}

void PanelPlotOutput::drawFills(double /*startDate*/, double /*stopDate*/) {
	// Nothing done here except setting the viewport, see subclasses for specific implementation
	_pls->vpor( _plotAreaBounds._x,	_plotAreaBounds._x + _plotAreaBounds._width,
				_plotAreaBounds._y,	_plotAreaBounds._y + _plotAreaBounds._height);
}

void PanelPlotOutput::drawSeries(double /*startDate*/, double /*stopDate*/, int /*intervalIndex*/, std::string /*pParamId*/,
		SeriesProperties& pSeries, AMDA::Common::ParameterIndexComponent /*pParamIndex*/,
		ParameterAxes& /*param*/, bool /*moreThanOneSerieForAxis*/) {
	// Get X, Y and Z axis.
	boost::shared_ptr<Axis> lXAxis(_panel->getAxis(pSeries.getXAxisId()));
	boost::shared_ptr<Axis> lYAxis(_panel->getAxis(pSeries.getYAxisId()));
	boost::shared_ptr<Axis> lZAxis(_panel->getAxis(pSeries.getZAxisId()));

	Range lXRange = getXAxisRange (pSeries, lXAxis);
	Range lYRange = getYAxisRange (pSeries, lYAxis);
	//Range lZRange = getZAxisRange (pSeries, lZAxis);

	PlWindow lPlWindow = PlWindow(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());

	// Calculate X and Y tick
	TickConf lTickConf;
	double lXMajorTickSpace = nan("");
	int lXMinorTickNumber = 0;
	double lYMajorTickSpace = nan("");
	int lYMinorTickNumber = 0;

	if(pSeries.hasXAxis()){
		// Calculate X tick
		lXMajorTickSpace = getMajorTickSpace(lXAxis.get(),
				std::get<0>(lPlWindow), std::get<1>(lPlWindow));
		lXMinorTickNumber = getMinorTickNumber(lXAxis.get(),
				std::get<0>(lPlWindow), std::get<1>(lPlWindow),	lXMajorTickSpace);
	}

	if(pSeries.hasYAxis()){
		// Calculate Y tick
		lYMajorTickSpace = getMajorTickSpace(lYAxis.get(), std::get<2>(lPlWindow), std::get<3>(lPlWindow));
		lYMinorTickNumber = getMinorTickNumber(lYAxis.get(), std::get<2>(lPlWindow), std::get<3>(lPlWindow),
				lYMajorTickSpace);
	}

	lTickConf = TickConf(lXMajorTickSpace, lXMinorTickNumber, lYMajorTickSpace, lYMinorTickNumber);


	// Draw Y axis and legend
	if (pSeries.hasYAxis() && !lYAxis->_drawn) {

		drawYAxis(lYAxis, lPlWindow, _plotAreaBounds, lTickConf);

		// Draw legend.
		drawLegends(lYAxis, lPlWindow, _plotAreaBounds);
	}

	// Draw X axis and legend
	if (pSeries.hasXAxis() && !lXAxis->_drawn) {
		drawXAxis(lXAxis, lPlWindow, _plotAreaBounds, lTickConf);

		// Draw legend.
		drawLegends(lXAxis, lPlWindow, _plotAreaBounds);
	}

	// Draw Z axis and legend
	if (pSeries.hasZAxis() && (lZAxis != nullptr) && !lZAxis->_drawn) {
		drawZAxis(lZAxis, lPlWindow, _plotAreaBounds, lTickConf);
	}
}

078ec265   Benjamin Renard   Give the possibil...
2412
2413
2414
2415
2416
void PanelPlotOutput::drawAdditionalObjects() {
	for (auto parameter : _parameterAxesList) {
		if (parameter.getSpectroProperties() != nullptr) {
			boost::shared_ptr<Axis> lXAxis(_panel->getAxis(parameter.getSpectroProperties()->getXAxisId()));
			boost::shared_ptr<Axis> lYAxis(_panel->getAxis(parameter.getSpectroProperties()->getYAxisId()));
fbe3c2bb   Benjamin Renard   First commit
2417

537e3ab0   Benjamin Renard   Fix a bug with In...
2418
2419
2420
			if ((lXAxis == nullptr) || (lYAxis == nullptr))
				continue;

078ec265   Benjamin Renard   Give the possibil...
2421
2422
			Range lXRange = lXAxis->getRange();
			Range lYRange = lYAxis->getRange();
fbe3c2bb   Benjamin Renard   First commit
2423

078ec265   Benjamin Renard   Give the possibil...
2424
			PlWindow lPlWindow = PlWindow(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());
fbe3c2bb   Benjamin Renard   First commit
2425

078ec265   Benjamin Renard   Give the possibil...
2426
2427
			if (!lXAxis->_additionalObjDrawn)
				drawXConstantLines (lXAxis, lPlWindow);
fbe3c2bb   Benjamin Renard   First commit
2428

078ec265   Benjamin Renard   Give the possibil...
2429
2430
			if (!lYAxis->_additionalObjDrawn)
				drawYConstantLines (lYAxis, lPlWindow);
fbe3c2bb   Benjamin Renard   First commit
2431

078ec265   Benjamin Renard   Give the possibil...
2432
2433
			if (!lXAxis->_additionalObjDrawn || !lYAxis->_additionalObjDrawn)
				drawTextPlots (lXAxis, lYAxis, lPlWindow, _panel->_textPlots);
fbe3c2bb   Benjamin Renard   First commit
2434

078ec265   Benjamin Renard   Give the possibil...
2435
2436
2437
			lXAxis->_additionalObjDrawn = true;
			lYAxis->_additionalObjDrawn = true;
		}
fbe3c2bb   Benjamin Renard   First commit
2438
2439
	}

078ec265   Benjamin Renard   Give the possibil...
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
	SeriesProperties lSeries;
	for (auto parameter : _parameterAxesList) {
		std::vector<AMDA::Common::ParameterIndexComponent> parameterYSerieIndexList = parameter.getYSerieIndexList(_pParameterValues);
		for (auto lIndex : parameterYSerieIndexList) {
			// Get series properties
			lSeries = parameter.getYSeriePropertiesAt(lIndex);

			boost::shared_ptr<Axis> lXAxis(_panel->getAxis(lSeries.getXAxisId()));
			boost::shared_ptr<Axis> lYAxis(_panel->getAxis(lSeries.getYAxisId()));

c2b6616d   Benjamin Renard   Fix bug in drawAd...
2450
2451
2452
			if ((lXAxis == nullptr) || (lYAxis == nullptr))
				continue;

078ec265   Benjamin Renard   Give the possibil...
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
			Range lXRange = lXAxis->getRange();
			Range lYRange = lYAxis->getRange();

			PlWindow lPlWindow = PlWindow(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());

			if (!lXAxis->_additionalObjDrawn)
				drawXConstantLines (lXAxis, lPlWindow);

			if (!lYAxis->_additionalObjDrawn)
				drawYConstantLines (lYAxis, lPlWindow);

			if (!lXAxis->_additionalObjDrawn || !lYAxis->_additionalObjDrawn)
				drawTextPlots (lXAxis, lYAxis, lPlWindow, _panel->_textPlots);

			lXAxis->_additionalObjDrawn = true;
			lYAxis->_additionalObjDrawn = true;
		}
	}
fbe3c2bb   Benjamin Renard   First commit
2471
2472
2473
2474

	// Draw curvePlots
	for (auto curvePlot : _panel->_curvePlots)
		drawCurvePlot(*curvePlot);
fbe3c2bb   Benjamin Renard   First commit
2475
2476
2477
2478
2479
2480
}

void PanelPlotOutput::setPlStream(std::shared_ptr<plstream>& pls) {
	_pls = pls;
}

fbe3c2bb   Benjamin Renard   First commit
2481
2482
2483
2484
std::string PanelPlotOutput::drawOppositeSide(boost::shared_ptr<Axis> pAxis) {
	boost::shared_ptr<Axis> lNewAxis;
	std::string lOppositeSide;

c45180e1   Benjamin Renard   Add _used propert...
2485
2486


fbe3c2bb   Benjamin Renard   First commit
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
	switch (pAxis->_position) {
	case PlotCommon::Position::POS_BOTTOM:
		if (pAxis->_visible	&& !_plotAreaSideSet[PlotCommon::Position::POS_TOP]) {
			lOppositeSide = "c";
		}
		break;
	case PlotCommon::Position::POS_TOP:
		if (pAxis->_visible	&& !_plotAreaSideSet[PlotCommon::Position::POS_BOTTOM]) {
			lOppositeSide = "b";
		}
		break;
	case PlotCommon::Position::POS_LEFT:
		if (pAxis->_visible	&& !_plotAreaSideSet[PlotCommon::Position::POS_RIGHT]) {
			lOppositeSide = "c";
		}
		break;
	case PlotCommon::Position::POS_RIGHT:
		if (pAxis->_visible	&& !_plotAreaSideSet[PlotCommon::Position::POS_LEFT]) {
			lOppositeSide = "b";
		}
		break;
	case PlotCommon::Position::POS_CENTER:
	default:
		lOppositeSide = "";
	}

	return lOppositeSide;
}

/*
 * Create a sampled parameter from an original parameter and a sampling value
 */
AMDA::Parameters::ParameterSPtr PanelPlotOutput::createSampledParameter(AMDA::Parameters::ParameterSPtr& originalParam, float samplingValue)
{
	AMDA::Parameters::ParameterSPtr sampledParam = _parameterManager.getSampledParameter(
			originalParam->getId(),
			"classic",
			samplingValue,
			originalParam->getGapThreshold());

	if (sampledParam == NULL)
	{
		LOG4CXX_ERROR(gLogger,
				"ParamOutput::createSampledParameter : cannot create sampled parameter");
		BOOST_THROW_EXCEPTION(
				AMDA::Parameters::ParamOutput_exception());
	}

	LOG4CXX_INFO(gLogger, "ParamOutput::createSampledParameter : sampled parameter : " << sampledParam->getId() << " created");

	return sampledParam;
}

/*
 * Create a sampled parameter from an original parameter and a reference parameter for time definition
 */
AMDA::Parameters::ParameterSPtr PanelPlotOutput::createSampledParameterUnderReferenceParameter(AMDA::Parameters::ParameterSPtr& originalParam, AMDA::Parameters::ParameterSPtr& refParam)
{
	AMDA::Parameters::ParameterSPtr sampledParam = _parameterManager.getSampledParameterUnderRefParam(
			originalParam->getId(),
			refParam->getId()
	);

	if (sampledParam == NULL)
	{
		LOG4CXX_ERROR(gLogger,
				"ParamOutput::createSampledParameterUnderReferenceParameter : cannot create sampled parameter");
		BOOST_THROW_EXCEPTION(
				AMDA::Parameters::ParamOutput_exception());
	}

	LOG4CXX_INFO(gLogger, "ParamOutput::createSampledParameterUnderReferenceParameter : sampled parameter : " << sampledParam->getId() << " created");

	return sampledParam;
}

ParameterAxes* PanelPlotOutput::getParameterAxesByColorSerieId(int colorSerieId)
{
	if (colorSerieId < 0)
		return NULL;

	for (ParameterAxesList::iterator it = _parameterAxesList.begin();
			it != _parameterAxesList.end(); ++it)
	{
		for (auto serieProp : it->getColorSeriePropertiesList())
		{
			if (serieProp.getId() == colorSerieId)
				return &(*it);
		}
	}

	LOG4CXX_ERROR(gLogger, "ParamOutput::getColorSeriePropertiesById : Not founded : " << colorSerieId);
	return NULL;
}

/**
 * Create parameters needed for this plot.
 * By default, the creation method create parameters for a time serie.
 * Override it for other plot type
 */
void PanelPlotOutput::createParameters(std::list<std::string>& usedParametersId_)
{
	// -- for each y serie on each parameter, calculate
	// y serie sampling according to max resolution
	for (ParameterAxesList::iterator it = _parameterAxesList.begin();
			it != _parameterAxesList.end(); ++it)
	{
		AMDA::Parameters::ParameterSPtr originalParam =
				_parameterManager.getParameter(it->_originalParamId);

		//original parameter sampling
		double samplingValue = getSamplingInTreeParameter(originalParam);

		//For each series
		std::map<AMDA::Common::ParameterIndexComponent, SeriesProperties>::iterator ity;
		for (ity = it->getYSeriePropertiesMap().begin(); ity != it->getYSeriePropertiesMap().end();
				++ity)
		{
			ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(ity->second.getColorSerieId());

			AMDA::Parameters::ParameterSPtr originalColorParam;
			if (colorSerieParameterAxes != NULL)
				originalColorParam = _parameterManager.getParameter(colorSerieParameterAxes->_originalParamId);

			//get corrected sampling value in relation with max resolution
			double correctedSamplingValue = getCorrectedSamplingValue(ity->second.getMaxResolution(), samplingValue);

			AMDA::Parameters::ParameterSPtr usedParam;

			//create parameter and link to the serie
			switch (ity->second.getResamplingProperties().getType())
			{
			case ResamplingType::MANUAL :
				{
					//create resampling parameters for param
					usedParam = createSampledParameter(originalParam, ity->second.getResamplingProperties().getValue());
					break;
				}
			case ResamplingType::AUTO   :
			case ResamplingType::YPARAM :
			case ResamplingType::XPARAM :
				if (abs(samplingValue - correctedSamplingValue) > 1.)
				{
					//more than one second between samplingValue and correctedSamplingValue
					//=> use resampling parameter
					usedParam = createSampledParameter(originalParam, correctedSamplingValue);
				}
				else
				{
					//use original parameter
					usedParam = originalParam;
				}
				break;
			}
			//Add used parameter to parameters list
			if (std::find (usedParametersId_.begin(),usedParametersId_.end(),usedParam->getId()) == usedParametersId_.end())
				usedParametersId_.push_back(usedParam->getId());
			//link this paramter to the serie
			ity->second.setParamId(usedParam->getId());

			ErrorBarProperties &errorBarProp = ity->second.getErrorBarProperties();

			// Compute min / max re-sampled parameters if min/max error bar are defined for the serie
			if (errorBarProp.getErrorMinMax() != nullptr)
			{
				std::stringstream usedParamIndex;
				if (ity->second.getIndex().getDim1Index() != -1)
				{
					usedParamIndex << "[" << std::to_string(ity->second.getIndex().getDim1Index()) ;
					if (ity->second.getIndex().getDim2Index() != -1)
						usedParamIndex << "," << std::to_string(ity->second.getIndex().getDim2Index());
					usedParamIndex << "]";
				}

				std::stringstream minParamIndex;
				if (errorBarProp.getErrorMinMax()->getIndexMin().getDim1Index() != -1)
				{
					minParamIndex << "[" << std::to_string(errorBarProp.getErrorMinMax()->getIndexMin().getDim1Index());
					if (errorBarProp.getErrorMinMax()->getIndexMin().getDim2Index() != -1)
						minParamIndex << "," << std::to_string(errorBarProp.getErrorMinMax()->getIndexMin().getDim2Index());
					minParamIndex << "]";
				}

				std::stringstream maxParamIndex;
				if (errorBarProp.getErrorMinMax()->getIndexMax().getDim1Index() != -1)
				{
					maxParamIndex << "[" << std::to_string(errorBarProp.getErrorMinMax()->getIndexMax().getDim1Index());
					if (errorBarProp.getErrorMinMax()->getIndexMax().getDim2Index() != -1)
						maxParamIndex << "," << std::to_string(errorBarProp.getErrorMinMax()->getIndexMax().getDim2Index());
					maxParamIndex << "]";
				}

				// Build expression for computed parameter = usedParam - minParam
				std::stringstream minExpr;
				minExpr << "$" << usedParam->getId() << usedParamIndex.str()
						<< "-$" + errorBarProp.getErrorMinMax()->getOriginalParamMin() << minParamIndex.str();

				//create parameter from expression
634d98b1   Benjamin Renard   Set gap for deriv...
2685
				AMDA::Parameters::ParameterSPtr usedMinParam =  _parameterManager.getParameterFromExpression(minExpr.str(), originalParam->getGapThreshold());
fbe3c2bb   Benjamin Renard   First commit
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702

				if (usedMinParam == nullptr)
				{
					LOG4CXX_ERROR(gLogger, "PanelPlotOutput::createParameters - Cannot create parameter from expression " << minExpr);
					continue;
				}

				if (std::find (usedParametersId_.begin(),usedParametersId_.end(),usedMinParam->getId()) == usedParametersId_.end())
					usedParametersId_.push_back(usedMinParam->getId());
				errorBarProp.getErrorMinMax()->setUsedParamMin(usedMinParam->getId());

				// Build expression for computed parameter = usedParam + maxParam
				std::stringstream maxExpr;
				maxExpr << "$" << usedParam->getId() << usedParamIndex.str()
						<< "+$" + errorBarProp.getErrorMinMax()->getOriginalParamMax() << maxParamIndex.str();

				//create parameter from expression
634d98b1   Benjamin Renard   Set gap for deriv...
2703
				AMDA::Parameters::ParameterSPtr usedMaxParam =  _parameterManager.getParameterFromExpression(maxExpr.str(), originalParam->getGapThreshold());
fbe3c2bb   Benjamin Renard   First commit
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734

				if (usedMaxParam == nullptr)
				{
					LOG4CXX_ERROR(gLogger, "PanelPlotOutput::createParameters - Cannot create parameter from expression " << maxExpr);
					continue;
				}

				if (std::find (usedParametersId_.begin(),usedParametersId_.end(),usedMaxParam->getId()) == usedParametersId_.end())
					usedParametersId_.push_back(usedMaxParam->getId());
				errorBarProp.getErrorMinMax()->setUsedParamMax(usedMaxParam->getId());
			}

			if (originalColorParam != nullptr)
			{
				AMDA::Parameters::ParameterSPtr usedColorParam = createSampledParameterUnderReferenceParameter(originalColorParam, usedParam);
				//Add used color parameter to parameters list
				if (std::find (usedParametersId_.begin(),usedParametersId_.end(),usedColorParam->getId()) == usedParametersId_.end())
					usedParametersId_.push_back(usedColorParam->getId());
				//link this color parameter to the y serie
				ity->second.setColorParamId(usedColorParam->getId());
				//link the used parameter to the color serie
				colorSerieParameterAxes->getColorSeriePropertiesById(ity->second.getColorSerieId()).addParamId(usedParam->getId(), usedColorParam->getId());
				//activate the Z Axis
				ity->second.setZAxis(true);
			}
		}

		//For spectro if defined
		std::shared_ptr<SpectroProperties> pSpecProp = it->getSpectroProperties();
		if (pSpecProp != nullptr)
		{
f2db3c16   Benjamin Renard   Support variable ...
2735
2736
2737
2738
			AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(originalParam->getInfoId());
			boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
			if (paramInfo != nullptr)
				tableSPtr = paramInfo->getTable(pSpecProp->getRelatedDim());
fbe3c2bb   Benjamin Renard   First commit
2739
2740
			//get corrected sampling value in relation with max resolution
			double correctedSamplingValue = getCorrectedSamplingValue(pSpecProp->getMaxResolution(), samplingValue);
fbe3c2bb   Benjamin Renard   First commit
2741
2742
2743
2744
2745
2746
2747
			AMDA::Parameters::ParameterSPtr usedParam;

			if (abs(samplingValue - correctedSamplingValue) > 1.)
			{
				//more than one second between samplingValue and correctedSamplingValue
				//=> use resampling parameter
				usedParam = createSampledParameter(originalParam, correctedSamplingValue);
e7ea756d   Benjamin Renard   Implements tables...
2748
				if ((tableSPtr != nullptr) && tableSPtr->isVariable(&_parameterManager))
f2db3c16   Benjamin Renard   Support variable ...
2749
				{
e7ea756d   Benjamin Renard   Implements tables...
2750
					for (std::map<std::string, std::string>::iterator it = tableSPtr->getTableParams(&_parameterManager).begin(); it != tableSPtr->getTableParams(&_parameterManager).end(); ++it)
f2db3c16   Benjamin Renard   Support variable ...
2751
2752
2753
2754
2755
2756
2757
2758
2759
					{
						std::string tableParamKey = it->first;
						std::string tableParamName = it->second;

						AMDA::Parameters::ParameterSPtr originalTableParam = _parameterManager.getParameter(tableParamName);
						AMDA::Parameters::ParameterSPtr usedTableParam = createSampledParameter(originalTableParam, correctedSamplingValue);
						pSpecProp->addTableParam(tableParamKey, usedTableParam->getId());
					}
				}
fbe3c2bb   Benjamin Renard   First commit
2760
2761
2762
2763
2764
			}
			else
			{
				//use original parameter
				usedParam = originalParam;
e7ea756d   Benjamin Renard   Implements tables...
2765
				if ((tableSPtr != nullptr) && tableSPtr->isVariable(&_parameterManager))
f2db3c16   Benjamin Renard   Support variable ...
2766
				{
e7ea756d   Benjamin Renard   Implements tables...
2767
					for (std::map<std::string, std::string>::iterator it = tableSPtr->getTableParams(&_parameterManager).begin(); it != tableSPtr->getTableParams(&_parameterManager).end(); ++it)
f2db3c16   Benjamin Renard   Support variable ...
2768
2769
2770
2771
2772
2773
2774
2775
					{
						std::string tableParamKey = it->first;
						std::string tableParamName = it->second;

						AMDA::Parameters::ParameterSPtr originalTableParam = _parameterManager.getParameter(tableParamName);
						pSpecProp->addTableParam(tableParamKey, originalTableParam->getId());
					}
				}
fbe3c2bb   Benjamin Renard   First commit
2776
2777
2778
2779
2780
2781
			}

			//Add used parameter to parameters list
			if (std::find (usedParametersId_.begin(),usedParametersId_.end(),usedParam->getId()) == usedParametersId_.end())
				usedParametersId_.push_back(usedParam->getId());
			pSpecProp->setParamId(usedParam->getId());
f2db3c16   Benjamin Renard   Support variable ...
2782
2783
2784
			//Add table parameters to parameters list
			for (std::map<std::string, std::string>::iterator it = pSpecProp->getTableParams().begin(); it != pSpecProp->getTableParams().end(); ++it)
			{
f2db3c16   Benjamin Renard   Support variable ...
2785
2786
2787
2788
2789
				std::string tableParamId = it->second;

				if (std::find (usedParametersId_.begin(),usedParametersId_.end(),tableParamId) == usedParametersId_.end())
					usedParametersId_.push_back(tableParamId);
			}
fbe3c2bb   Benjamin Renard   First commit
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
		}
	}
}

/**
 * Gets sampling value from resolution (point-per-plot) according to
 * the plot time interval and the base parameter sampling value.
 */
double PanelPlotOutput::getCorrectedSamplingValue(int maxResolution, double samplingValue){
	double timeInt = 0.;
	if (_panel->_page->_superposeMode)
	{
		//merge all intervals size
		TimeIntervalList::iterator crtTimeInterval = _parameterManager.getInputIntervals()->begin();
		while (crtTimeInterval != _parameterManager.getInputIntervals()->end())
		{
			timeInt += (crtTimeInterval->_stopTime - crtTimeInterval->_startTime);
			++crtTimeInterval;
		}
	}
	else
	{
		//find the biggest intervals size
		TimeIntervalList::iterator crtTimeInterval = _parameterManager.getInputIntervals()->begin();
		while (crtTimeInterval != _parameterManager.getInputIntervals()->end())
		{
			if ((crtTimeInterval->_stopTime - crtTimeInterval->_startTime) > timeInt)
				timeInt = crtTimeInterval->_stopTime - crtTimeInterval->_startTime;
			++crtTimeInterval;
		}
	}

	if((timeInt == 0) || (maxResolution == -1) || (timeInt/samplingValue < maxResolution)){
		return samplingValue;
	}
	// get the exact sampling
	double correctedSampling = timeInt/maxResolution;
	// rounded it to the next int sampling
	double roundedSampling = (int) correctedSampling;
	if(roundedSampling < correctedSampling){
		roundedSampling += 1;
	}
	return roundedSampling;
}

/**
 * Gets indexes of series with no color definition on a given axis.
 */
int PanelPlotOutput::countAxisSerieWithUndefinedColor(const std::string& axisId_) {
	int numberOfSeries = 0;
	for (ParameterAxesList::iterator paramAxeIt = _parameterAxesList.begin();
			paramAxeIt != _parameterAxesList.end(); ++paramAxeIt) {
		try {
			// browse all real index (not serie index that may contain -1)
			for (auto index : paramAxeIt->getYSerieIndexList(_pParameterValues)) {
				SeriesProperties serie = paramAxeIt->getYSeriePropertiesAt(
						index);
				if (serie.getYAxisId() == axisId_
						&& !serie.getColor().isSet()) {
					++numberOfSeries;
				}
			}
		} catch (PanelPlotOutputException& ex) {
			// nop
		}
	}
	return numberOfSeries;
}

/**
 * @brief Get the list of indexes used for a parameter
 */
std::vector<AMDA::Common::ParameterIndexComponent> PanelPlotOutput::getParamUsedIndexes(std::string paramId,
		int dim1Size, int dim2Size)
{
	std::vector<AMDA::Common::ParameterIndexComponent> indexes;
	for (ParameterAxesList::iterator paramAxeIt = _parameterAxesList.begin();
				paramAxeIt != _parameterAxesList.end(); ++paramAxeIt)
	{
		//get indexes for spectro
		std::shared_ptr<SpectroProperties> pSpecProp = paramAxeIt->getSpectroProperties();
		if (pSpecProp != nullptr)
		{
			if (pSpecProp->getParamId() == paramId)
			{
				if (pSpecProp->getIndexes().empty())
				{
					//get used indexes by the spectro thanks to the index definition in the request
					AMDA::Common::ParameterIndexComponentList indexList;
					AMDA::Common::ParameterIndexesTool::parse(pSpecProp->getIndexDef(),
							dim1Size, dim2Size, indexList);
					pSpecProp->setIndexes(indexList);
				}

				for (auto index : pSpecProp->getIndexes())
				{
					if (std::find(indexes.begin(),indexes.end(),index) != indexes.end())
						continue;
					indexes.push_back(index);
				}
			}
		}

		//get indexes for series of this ParameterAxe
		std::vector<AMDA::Common::ParameterIndexComponent> seriesIndexes = paramAxeIt->getParamUsedIndexes(paramId);

		for (AMDA::Common::ParameterIndexComponent index : seriesIndexes)
		{
			if ((index.getDim1Index() == -1) && (index.getDim2Index() == -1))
			{
				//-1 => all indexes
				indexes.clear();
				indexes.push_back(AMDA::Common::ParameterIndexComponent(-1,-1));
				return indexes;
			}
			if (std::find(indexes.begin(),indexes.end(),index) != indexes.end())
				continue;
			indexes.push_back(index);
		}
	}

	if (indexes.empty())
		indexes.push_back(AMDA::Common::ParameterIndexComponent(-1,-1));

	return indexes;
}

/*
 * @brief Set pointer to params values
 */
void PanelPlotOutput::setParameterValues(std::map<std::string, ParameterData> *pParameterValues)
{
	_pParameterValues = pParameterValues;
}

/*
 * @brief Set a pointer to the time intervals list
 */
void PanelPlotOutput::setTimeIntervalListPtr(AMDA::Parameters::TimeIntervalList* timeIntervalListPtr)
{
	_timeIntervalListPtr = timeIntervalListPtr;
}

/*
 * @brief Get computed values (in relation with the y axis definition) for a y serie and a time interval
 * Do not forget to delete computedValues !!
 * Don't delete timeValues !!
 */
bool PanelPlotOutput::getComputedValuesFromSerieAndInterval(double startDate, double stopDate, SeriesProperties &rSeriesProperties,
		AMDA::Common::ParameterIndexComponent index, double** computedValues, double** timeValues, int& nbValues)
{
	LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getComputedValuesFromSerieAndInterval");
	//get parameter data for this serie
	ParameterData &data = (*_pParameterValues)[rSeriesProperties.getParamId()];

	//get original data for interval [startDate, stopDate]
	int startIndex;
	double *valuesInterval = data.getIntervalValues(startDate, stopDate, index,
				startIndex, nbValues);

	if (valuesInterval == NULL)
	{
		LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getComputedValuesFromSerieAndInterval - Cannot find data for serie with id " << rSeriesProperties.getId());
		return false;
	}

	//get computed data for interval [startDate, stopDate] in relation with the serie y axis
fbe3c2bb   Benjamin Renard   First commit
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
	(*computedValues) = _panel->getAxis(rSeriesProperties.getYAxisId())->getComputedValues(
			valuesInterval,
			nbValues,
			rSeriesProperties.getMin(),
			rSeriesProperties.getMax());

	//get time values
	(*timeValues) = &data.getTimes()[startIndex];

	return true;
}

/*
 * @brief Get computed values (in relation with the color axis definition) for a color serie and a time interval
 * Do not forget to delete computedValues !!
 * Don't delete timeValues !!
 */
bool PanelPlotOutput::getColoredComputedValuesFromSerieAndInterval(double startDate, double stopDate, SeriesProperties &rSeriesProperties,
		double** computedValues, double** timeValues, int& nbValues)
{
	LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getColoredComputedValuesFromSerieAndInterval");
	//get parameter data for this color serie
	ParameterData &data = (*_pParameterValues)[rSeriesProperties.getColorParamId()];

	ParameterAxes* colorSerieParameterAxes = getParameterAxesByColorSerieId(rSeriesProperties.getColorSerieId());

	if (colorSerieParameterAxes == NULL)
	{
		LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getColoredComputedValuesFromSerieAndInterval - Cannot retrieve parameter axe");
		return false;
	}

	ColorSeriesProperties& colorSerieProp = colorSerieParameterAxes->getColorSeriePropertiesById(rSeriesProperties.getColorSerieId());

	//get original data for interval [startDate, stopDate]
	int startIndex;
	double *valuesInterval = data.getIntervalValues(startDate, stopDate, colorSerieProp.getIndex(),
			startIndex, nbValues);

	if (valuesInterval == NULL)
	{
		LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getColoredComputedValuesFromSerieAndInterval - Cannot find data for color serie with id " << colorSerieProp.getId());
		return false;
	}

	//get computed data for interval [startDate, stopDate] in relation with the color axis
	(*computedValues) = _panel->getColorAxis()->getComputedValues(
				valuesInterval,
				nbValues,
				colorSerieProp.getMin(),
				colorSerieProp.getMax());

	//get time values
	(*timeValues) = &data.getTimes()[startIndex];

	return true;
}

/*
 * @brief Get computed values (in relation with the y axis definition) for a y serie and a time interval
 * Do not forget to delete computedValues !!
 * Don't delete timeValues !!
 */
bool PanelPlotOutput::getErrorComputedValuesFromSerieAndInterval(double startDate, double stopDate, SeriesProperties &rSeriesProperties,
		double** minComputedValues, double** minTimeValues, int& nbMinValues,
		double** maxComputedValues, double** maxTimeValues, int& nbMaxValues)
{
	LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getErrorComputedValuesFromSrieAndInterval");

	ErrorBarProperties &errorBarProp = rSeriesProperties.getErrorBarProperties();
	if (errorBarProp.getErrorMinMax() == nullptr)
		return false;

	//get parameter dataMin for this color bar
	ParameterData &dataMin = (*_pParameterValues)[errorBarProp.getErrorMinMax()->getUsedParamMin()];

	//get original min data for interval [startDate, stopDate]
	int minStartIndex;
	double *minValuesInterval = dataMin.getIntervalValues(startDate, stopDate, errorBarProp.getErrorMinMax()->getIndexMin(),
			minStartIndex, nbMinValues);

	if (minValuesInterval == NULL)
	{
		LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getErrorComputedValuesFromSerieAndInterval - Cannot get min data for error bar");
		return false;
	}

	//get computed min data for interval [startDate, stopDate] in relation with the serie y axis
	(*minComputedValues) = _panel->getAxis(rSeriesProperties.getYAxisId())->getComputedValues(
			minValuesInterval,
			nbMinValues,
			rSeriesProperties.getMin(),
			rSeriesProperties.getMax());

	//get time values
	(*minTimeValues) = &dataMin.getTimes()[minStartIndex];

	//get parameter dataMax for this color bar
	ParameterData &dataMax = (*_pParameterValues)[errorBarProp.getErrorMinMax()->getUsedParamMax()];

	//get original max data for interval [startDate, stopDate]
	int maxStartIndex;
	double *maxValuesInterval = dataMax.getIntervalValues(startDate, stopDate, errorBarProp.getErrorMinMax()->getIndexMax(),
			maxStartIndex, nbMaxValues);

	if (maxValuesInterval == NULL)
	{
		LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::getErrorComputedValuesFromSerieAndInterval - Cannot get min data for error bar");
		delete[] (*minComputedValues);
		return false;
	}

	//get computed max data for interval [startDate, stopDate] in relation with the serie y axis
	(*maxComputedValues) = _panel->getAxis(rSeriesProperties.getYAxisId())->getComputedValues(
			maxValuesInterval,
			nbMaxValues,
			rSeriesProperties.getMin(),
			rSeriesProperties.getMax());

	//get time values
	(*maxTimeValues) = &dataMax.getTimes()[maxStartIndex];

	return true;
}

/*
 * @brief Return the color to draw the line of a serie
 */
Color PanelPlotOutput::getSerieLineColor(SeriesProperties &rSeriesProperties, bool moreThanOneSerieForAxis)
{
	Color lLineColor = rSeriesProperties.getLineProperties().getColor();

	if((lLineColor._colorIndex == -1) &&
		(lLineColor._red == -1) &&
		(lLineColor._green == -1) &&
		(lLineColor._blue == -1))
	{
		//if line color not defined, try to use the serie color
		lLineColor = rSeriesProperties.getColor();

		if((lLineColor._colorIndex == -1) &&
			(lLineColor._red == -1) &&
			(lLineColor._green == -1) &&
			(lLineColor._blue == -1))
		{
			//if color not defined
			if (!_panel->_page->_superposeMode && !moreThanOneSerieForAxis)
			{
				lLineColor = _panel->getAxis(rSeriesProperties.getYAxisId())->_color;
			}
			else
			{
				//get a default color
				getDefaultColor(_panel->_page->_mode, _automaticSerieColorCursor, lLineColor);
			}
		}
	}

	return lLineColor;
}

/*
 * @brief Return the color to draw the symbols of a serie
 */
Color PanelPlotOutput::getSerieSymbolColor(SeriesProperties &rSeriesProperties, Color &pLineColor)
{
	Color lSymbolColor = rSeriesProperties.getSymbolProperties().getColor();

	if((lSymbolColor._colorIndex == -1) &&
		(lSymbolColor._red == -1) &&
		(lSymbolColor._green == -1) &&
		(lSymbolColor._blue == -1))
	{
		//if not defined, use the line color
		lSymbolColor = pLineColor;
	}

	return lSymbolColor;
}

/**
 * @brief Configure params legend.
 */
void PanelPlotOutput::configureParamsLegend(double startTime, double stopTime, int intervalIndex)
{
	_panel->_paramsLegendProperties.reset();

	for (auto parameter : _parameterAxesList)
	{
		for (auto lIndex : parameter.getYSerieIndexList(_pParameterValues))
		{
			SeriesProperties lSeriesProperties = parameter.getYSeriePropertiesAt(lIndex);

			//for the legend configuration, we don't need to know the line and symbol colors
			Color fakeColor(0,0,0);

			addSerieToParamsLegend(lSeriesProperties,lIndex, parameter._originalParamId,
					fakeColor, fakeColor, startTime, stopTime, intervalIndex);
		}
	}
}

/**
 * @brief Add a serie to the param legend
 */
void PanelPlotOutput::addSerieToParamsLegend(SeriesProperties& lSeriesProperties,
		AMDA::Common::ParameterIndexComponent& index, std::string originalParamId,
		Color& lineColor, Color& symbolColor,
		double startTime, double stopTime, int intervalIndex)
{
	if (!_panel->_paramsLegendProperties.isVisible())
		return;

	LOG4CXX_DEBUG(gLogger, "PanelPlotOutput::addSerieToParamsLegend");

	std::stringstream fullLegendText;
	if (_panel->_paramsLegendProperties.isParamInfoVisible())
	{
		//add params info
		fullLegendText << getSerieParamsLegendString(lSeriesProperties,index,originalParamId);
	}

	if (_panel->_paramsLegendProperties.isIntervalInfoVisible())
	{
		//add interval info
		if (!fullLegendText.str().empty())
			fullLegendText << "; ";
		switch (_panel->_paramsLegendProperties.getIntervalInfoType())
		{
		case ParamsLegendProperties::IntervalInfoType::INDEX :
			fullLegendText << "I";
			fullLegendText << intervalIndex;
			break;
		case ParamsLegendProperties::IntervalInfoType::STARTSTOP :
			fullLegendText << "[";
			fullLegendText << AMDA::TimeUtil::formatTimeDateInIso(startTime);
			fullLegendText << ", ";
			fullLegendText << AMDA::TimeUtil::formatTimeDateInIso(stopTime);
			fullLegendText << "]";
		}
	}

	//push this legend to the params legend properties
	_panel->_paramsLegendProperties.addSerie(lSeriesProperties,
			fullLegendText.str().c_str(), lineColor, symbolColor);
}

/*
 * @brief Return the associated params legend to a serie
 */
std::string PanelPlotOutput::getSerieParamsLegendString(SeriesProperties &rSeriesProperties,
		AMDA::Common::ParameterIndexComponent& index, std::string originalParamId)
{
	// Retrieve ParamInfo Manager
	ParamMgr 		*piMgr =ParamMgr::getInstance();

	// Try to retrieve informations from paramInfo
	ParameterSPtr p = _parameterManager.getParameter(rSeriesProperties.getParamId());
	ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());

	// Build parameter text legend depending on the availability of paramInfo
	std::stringstream paramLegendText;

	if (paramInfo)
	{
		if ((index.getDim1Index() == -1) && (index.getDim2Index() == -1))
		{
			// parameter legend text = short_name
			paramLegendText << paramInfo->getShortName();
		}
		else
		{
			if (paramInfo->getComponents(index).empty() == false)
				// parameter legend text = components at index lIndex]
				paramLegendText << paramInfo->getComponents(index);
			else
			{
				// parameter legend text = short_name [lIndex]
				paramLegendText << paramInfo->getShortName() << "[" << index.getDim1Index();
				if (index.getDim2Index() != -1)
					paramLegendText << "," << index.getDim2Index();
				paramLegendText << "]";
			}
		}
	}
	else
	{
		if ((index.getDim1Index() == -1) && (index.getDim2Index() == -1))
			// parameter legend text = _originalParamId
			paramLegendText << originalParamId;
		else
		{
			// parameter legend text = _originalParamId [lIndex]
			paramLegendText << originalParamId << "[" << index.getDim1Index();
			if (index.getDim2Index() != -1)
				paramLegendText << "," << index.getDim2Index();
			paramLegendText << "]";
		}
	}

	return paramLegendText.str();
}

/*
 * Dumps properties for test.
 */
void PanelPlotOutput::dump(std::ostream& out) {
	out << *(_panel->_page) << std::endl;
	out << *_panel << std::endl;
	std::string prefix = "parameter.";
	for (auto parameter : _parameterAxesList) {
		parameter.dump(out, prefix);
	}
}

}/* namespace plot */