Blame view

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

#include <fstream>
#include <iomanip>
#include <boost/lexical_cast.hpp>

#include "InstantPlot.hh"
#include "ParamsNode.hh"
#include "AxesNode.hh"
#include "PlotLogger.hh"
#include "PlotOutput.hh"
#include "TimeUtil.hh"
#include "ParamMgr.hh"
5ee90a58   Benjamin Renard   Use AxisLegendMan...
19
#include "AxisLegendManager.hh"
fbe3c2bb   Benjamin Renard   First commit
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

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

namespace plot {

InstantPlot::InstantPlot(AMDA::Parameters::ParameterManager& manager,
		boost::shared_ptr<Panel> panel) :
		PanelPlotOutput(manager, panel),
		_time(0),
		_originalParamId("") {
}

InstantPlot::~InstantPlot() {
}

void InstantPlot::createParameters(std::list<std::string>& usedParametersId_) {
ece33d6f   Benjamin Renard   Draw the panel of...
37
38
	if (_originalParamId.empty())
		return;
fbe3c2bb   Benjamin Renard   First commit
39
40
41
42
43
44
45
46
47
48
49

	// Fill usedParameterId_ list with the only used parameter
	// We do not want any resampling on the parameter

	AMDA::Parameters::ParameterSPtr originalParam =	_parameterManager.getParameter(_originalParamId);

	if (std::find (usedParametersId_.begin(),usedParametersId_.end(),originalParam->getId()) == usedParametersId_.end())
		usedParametersId_.push_back(originalParam->getId());

	// Force use of normalized parameter id
	_originalParamId = originalParam->getId();
1c0193a5   Benjamin Renard   Implement variabl...
50
51
52
53
54
55
56
57
58
59
60
61

	AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(originalParam->getInfoId());

	if (paramInfo != nullptr)
	{
		if (_iSerieProperties != nullptr)
		{
			boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;

			if (paramInfo != nullptr)
				tableSPtr = paramInfo->getTable(0);

e7ea756d   Benjamin Renard   Implements tables...
62
			if ((tableSPtr != nullptr) && (tableSPtr->isVariable(&_parameterManager)))
1c0193a5   Benjamin Renard   Implement variabl...
63
			{
e7ea756d   Benjamin Renard   Implements tables...
64
				for (std::map<std::string, std::string>::iterator it = tableSPtr->getTableParams(&_parameterManager).begin(); it != tableSPtr->getTableParams(&_parameterManager).end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
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
				{
					std::string tableParamKey = it->first;
					std::string tableParamName = it->second;

					AMDA::Parameters::ParameterSPtr originalTableParam = _parameterManager.getParameter(tableParamName);
					_iSerieProperties->addTableParam(tableParamKey, originalTableParam->getId());
				}

				//Add table parameters to parameters list
				for (std::map<std::string, std::string>::iterator it = _iSerieProperties->getTableParams().begin(); it != _iSerieProperties->getTableParams().end(); ++it)
				{
					std::string tableParamId = it->second;

					if (std::find (usedParametersId_.begin(),usedParametersId_.end(),tableParamId) == usedParametersId_.end())
						usedParametersId_.push_back(tableParamId);
				}
			}
		}
		else if (_iSpectroProperties != nullptr)
		{
			boost::shared_ptr<AMDA::Info::ParamTable> table0SPtr;
			boost::shared_ptr<AMDA::Info::ParamTable> table1SPtr;

			if (paramInfo != nullptr)
			{
				table0SPtr = paramInfo->getTable(0);
				table1SPtr = paramInfo->getTable(1);
			}

e7ea756d   Benjamin Renard   Implements tables...
94
			if ((table0SPtr != nullptr) && table0SPtr->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
95
			{
e7ea756d   Benjamin Renard   Implements tables...
96
				for (std::map<std::string, std::string>::iterator it = table0SPtr->getTableParams(&_parameterManager).begin(); it != table0SPtr->getTableParams(&_parameterManager).end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
				{
					std::string tableParamKey = it->first;
					std::string tableParamName = it->second;

					AMDA::Parameters::ParameterSPtr originalTableParam = _parameterManager.getParameter(tableParamName);
					_iSpectroProperties->addTable0Param(tableParamKey, originalTableParam->getId());
				}

				//Add table parameters to parameters list
				for (std::map<std::string, std::string>::iterator it = _iSpectroProperties->getTable0Params().begin(); it != _iSpectroProperties->getTable0Params().end(); ++it)
				{
					std::string tableParamId = it->second;

					if (std::find (usedParametersId_.begin(),usedParametersId_.end(),tableParamId) == usedParametersId_.end())
						usedParametersId_.push_back(tableParamId);
				}
			}

e7ea756d   Benjamin Renard   Implements tables...
115
			if ((table1SPtr != nullptr) && table1SPtr->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
116
			{
e7ea756d   Benjamin Renard   Implements tables...
117
				for (std::map<std::string, std::string>::iterator it = table1SPtr->getTableParams(&_parameterManager).begin(); it != table1SPtr->getTableParams(&_parameterManager).end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
				{
					std::string tableParamKey = it->first;
					std::string tableParamName = it->second;

					AMDA::Parameters::ParameterSPtr originalTableParam = _parameterManager.getParameter(tableParamName);
					_iSpectroProperties->addTable1Param(tableParamKey, originalTableParam->getId());
				}

				//Add table parameters to parameters list
				for (std::map<std::string, std::string>::iterator it = _iSpectroProperties->getTable1Params().begin(); it != _iSpectroProperties->getTable1Params().end(); ++it)
				{
					std::string tableParamId = it->second;

					if (std::find (usedParametersId_.begin(),usedParametersId_.end(),tableParamId) == usedParametersId_.end())
						usedParametersId_.push_back(tableParamId);
				}
			}
		}
	}
fbe3c2bb   Benjamin Renard   First commit
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
}

/**
 * @overload PanelPlotOutput::preparePlotArea()
 */
void InstantPlot::preparePlotArea(double startTime, double stopTime, int intervalIndex) {
	LOG4CXX_DEBUG(gLogger, "InstantPlot::preparePlotArea");
	// for test, dump plot properties
	const char* lBuildType=getenv("BUILD_TYPE");
	if(lBuildType && std::string(lBuildType) == "Debug") {
		std::ofstream out("instantPlot.txt");
		dump(out);
		out.close();
	}

	if (_iSerieProperties != nullptr)
	{
		/*
		 * Sequence for an instant series
		 */
		// Configure range of series and color.
		configureSeriesAxis();

		// Configure axis legend
		configureSeriesAxisLegend();

		// Configure params legend
		configureParamsLegend(startTime,stopTime,intervalIndex);
	}
	else if (_iSpectroProperties != nullptr)
	{
		/*
		 * Sequence for an instant spectro
		 */
		// Configure range of spectro axis.
		configureSpectroAxis();

		// Configure axis legend
		configureSpectroAxisLegend();
	}

	// check instant "cut" time validity
	if ((_time == 0) || (_time < startTime) || (_time > stopTime)) {
		double middleTime = (startTime + stopTime) / 2;
		LOG4CXX_WARN(gLogger, "InstantPlot::preparePlotArea invalid \"cut\" time : " << _time << " replaced by middle time : " << middleTime);
		_time = middleTime;
	}

	// If panel title is empty, replace it with start and end date.
f6eaec4e   Benjamin Renard   Optimize plot ele...
186
	if (_panel->getTitle()->_text.empty() || _panel->_updateTitleOnNextInterval) {
fbe3c2bb   Benjamin Renard   First commit
187
188
189
190
		//Title must be updated during the next interval plot
		_panel->_updateTitleOnNextInterval = true;

		// Set start date and end date.
904d4160   Hacene SI HADJ MOHAND   year 4 digits
191
		std::string lTimeFormat("%H:%M:%S %d/%m/%Y");
fbe3c2bb   Benjamin Renard   First commit
192
193
194
195
196
197
198
199

		long int lStartTime = static_cast<long int>(_time);
		tm * lStartTimeTm = gmtime(&lStartTime);
		char lStartTimeChr[80];

		// Format date.
		strftime(lStartTimeChr, 80, lTimeFormat.c_str(), lStartTimeTm);

f6eaec4e   Benjamin Renard   Optimize plot ele...
200
		_panel->setTitleText((const char*)lStartTimeChr);
fbe3c2bb   Benjamin Renard   First commit
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
	}

	PanelPlotOutput::preparePlotArea(startTime,stopTime,intervalIndex);
}

/*
 * Dumps properties for test.
 */
void InstantPlot::dump(std::ostream& out_){
	PanelPlotOutput::dump(out_);
	std::string prefix = "instantplot.";
	if (_iSerieProperties != nullptr)
		_iSerieProperties->dump(out_,prefix);
	if (_iSpectroProperties != nullptr)
		_iSpectroProperties->dump(out_,prefix);
}

/**
* @brief Retrieve ConstantLine informations for a given serieId and constantId.
*/
ConstantLine * InstantPlot::getConstantLineFromSerieId (int serieId, int constantId) {
	if (_iSerieProperties == nullptr)
		return NULL;
	// Look for serieId correspondence
	if (_iSerieProperties->getId() == serieId) {
		if (_iSerieProperties->getTableOnXAxis()) {
			boost::shared_ptr<Axis> yAxis(_panel->getAxis(_iSerieProperties->getYAxisId()));
			// Look for constantId correspondence
			for (auto constantLine : yAxis->_constantLines) {
				if (constantLine->getId() == constantId) {
					return constantLine.get();
				}
			}
		} else {
			boost::shared_ptr<Axis> xAxis(_panel->getAxis(_iSerieProperties->getXAxisId()));
			// Look for constantId correspondence
			for (auto constantLine : xAxis->_constantLines) {
				if (constantLine->getId() == constantId) {
					return constantLine.get();
				}
			}
		}
	}

	// ConstantId not found, we throw an exception
	std::stringstream lError;
	lError << "InstantPlot::getConstantLineFromSerieId : Unable to find constantId='" << constantId << "' for serieId='" << serieId << "'";
	BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	return NULL;
}

/**
* @brief Retrieve values for a given serieId.
*/
void InstantPlot::getSerieParameterValues(int serieId, double **xValues, double **yValues, int *nbValues) {
	*nbValues = 0;

	if (_iSerieProperties == nullptr)
		return;

	if (_iSerieProperties->getId() == serieId) {

		// Retrieve parameter informations and param Table if it exists
		ParameterSPtr p = _parameterManager.getParameter(_originalParamId);
		AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
		boost::shared_ptr<AMDA::Info::ParamTable> paramTable;
		if (paramInfo)
			paramTable = paramInfo->getTable(0);

		ParameterData& paramData = (*_pParameterValues)[_originalParamId];
1c0193a5   Benjamin Renard   Implement variabl...
271
272
273


		*nbValues = paramData.getDim1Size();
fbe3c2bb   Benjamin Renard   First commit
274
275
276
277
278
279
280
281
282
283
284
285

		// Build valueData and tableData
		double valueData[*nbValues];
		double tableData[*nbValues];
		double valueMin = DBL_MAX;
		double valueMax = -DBL_MAX;
		double tableMin = DBL_MAX;
		double tableMax = -DBL_MAX;
		double tableValue = 0;
		AMDA::Info::t_TableBound crtBound;

		for (int i = 0; i < *nbValues; ++i) {
1c0193a5   Benjamin Renard   Implement variabl...
286
			double value = paramData.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i));
fbe3c2bb   Benjamin Renard   First commit
287
288
289
290
291
292

			valueData[i] = value;
			valueMin = std::min (valueMin,value);
			valueMax = std::max (valueMax,value);

			if (paramTable) {
e7ea756d   Benjamin Renard   Implements tables...
293
				if (!paramTable->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
					crtBound = paramTable->getBound(&_parameterManager, i);
				else
				{
					std::map<std::string, std::vector<double>> paramsTableData;
					for (std::map<std::string, std::string>::iterator it = _iSerieProperties->getTableParams().begin(); it != _iSerieProperties->getTableParams().end(); ++it)
					{
						ParameterData& data = (*_pParameterValues)[it->second];
						double valIdx = data.indexOf(_time);
						std::vector<double> paramTableValues;
						for (int j = 0; j < data.getDim1Size(); ++j)
						{
							double* values = data.getValues(AMDA::Common::ParameterIndexComponent(j), valIdx);
							paramTableValues.push_back((*values));
						}
						paramsTableData[it->first] = paramTableValues;
					}
					crtBound = paramTable->getBound(&_parameterManager, i, &paramsTableData);
				}
				tableValue = (crtBound.min + crtBound.max) /2;
fbe3c2bb   Benjamin Renard   First commit
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
			} else {
				tableValue = i;
			}

			tableData [i] = tableValue;
			tableMin = std::min (tableMin,tableValue);
			tableMax = std::max (tableMax,tableValue);
		}

		//Attach valueData and tableData x / y value depending on table values associated axe
		if (_iSerieProperties->getTableOnXAxis()) {
			*xValues = _panel->getAxis (_iSerieProperties->getXAxisId())->getComputedValues(
										tableData, *nbValues, tableMin, tableMax);

			*yValues = _panel->getAxis (_iSerieProperties->getYAxisId())->getComputedValues(
										valueData, *nbValues, valueMin, valueMax);

			// If table values decrease, change values order
			if ((*xValues) [0] > (*xValues) [(*nbValues) -1]) {
				double swapX [*nbValues];
				double swapY [*nbValues];
				for (int i=0; i<*nbValues; i++) {
					swapX [i] = (*xValues) [*nbValues - 1 - i];
					swapY [i] = (*yValues) [*nbValues - 1 - i];
				}
				for (int i=0; i<*nbValues; i++) {
					(*xValues) [i] = swapX [i];
					(*yValues) [i] = swapY [i];
				}
			}
		}
		else {
			*xValues = _panel->getAxis (_iSerieProperties->getXAxisId())->getComputedValues(
										valueData, *nbValues, valueMin, valueMax);

			*yValues = _panel->getAxis (_iSerieProperties->getYAxisId())->getComputedValues(
										tableData, *nbValues, tableMin, tableMax);

			// If table values decrease, change values order
			if ((*yValues) [0] > (*yValues) [(*nbValues) -1]) {
				double swapX [*nbValues];
				double swapY [*nbValues];
				for (int i=0; i<*nbValues; i++) {
					swapX [i] = (*xValues) [*nbValues - 1 - i];
					swapY [i] = (*yValues) [*nbValues - 1 - i];
				}
				for (int i=0; i<*nbValues; i++) {
					(*xValues) [i] = swapX [i];
					(*yValues) [i] = swapY [i];
				}
			}
		}
	}
}

/**
* @brief Merge, sort and remove duplicate from 2 arrays in a vector
*/
void InstantPlot::mergeAndSortTime (	double *values1Table, int values1Nb,
									double *values2Table, int values2Nb,
									std::vector<double> &valuesTableMerged) {

	// Build 2 vectors
	std::vector<double> v1(values1Table, values1Table + values1Nb);
	std::vector<double> v2(values2Table, values2Table + values2Nb);

	// Populate resulting vector
	valuesTableMerged.insert( valuesTableMerged.end(), v1.begin(), v1.end() );
	valuesTableMerged.insert( valuesTableMerged.end(), v2.begin(), v2.end() );

	// Sort and remove duplicates for the resulting vector
	sort (valuesTableMerged.begin(), valuesTableMerged.end());
	valuesTableMerged.erase( unique( valuesTableMerged.begin(), valuesTableMerged.end() ), valuesTableMerged.end() );
}

/**
* @brief Return or compute an interpolated value
*/
double InstantPlot::getInterpolatedValue (double *valuesData, double *valuesTable, int valuesNb, double atTableValue) {

	// get index of first time after given time_
	if(isnan(atTableValue)){
		return nan("");
	}

	double *pTable = valuesTable;

	for(int t=0; t<valuesNb; t++) {
		// No interpolation required
		if (*pTable == atTableValue){
			return valuesData [t];
		}
		// Interpolation required
		if (*pTable >= atTableValue){
			if (t == 0) {
				return nan("");
			}
			else {
				double v1 = valuesData [t-1];
				double v2 = valuesData [t];
				double d1 = valuesTable [t-1];
				double d2 = valuesTable [t];
				// Return a linear interpolation of the value for the index
				return (v1 + (v2-v1) * (atTableValue-d1)/(d2-d1));
			}
		}
		pTable++;
	}
	return nan("");
}

/**
* @brief Compute if two ligne segments intersects
*/
bool InstantPlot::intersect (	double xi, double y1i, double y2i,
								double xj, double y1j, double y2j,
								double *xInter) {

	// Simply checks if segment are above or below the other
	if ( ((y1i >= y2i) && (y1j >= y2j)) ||( (y1i <= y2i) && (y1j <= y2j)) ) {
		return false;
	}

	// Computes intersection point :
    // Compute a and b (y = a * x + b) for each segment
    double a1 = (y1j - y1i) / (xj - xi);
    double b1 = y1i - a1 * xi ;

    double a2 = (y2j - y2i) / (xj - xi);
    double b2 = y2i - a2 * xi ;

    // Compute intersection point (a1*x+b1 = a2*x+b2)
    *xInter = (b2-b1) / (a1-a2);

    return true;
}

/**
* @brief Compute and add intersections time to the vector if intersections exist
*/
void InstantPlot::addIntersectionTable (double *values1Data, double *values1Table, int values1Nb,
										double *values2Data, double *values2Table, int values2Nb,
										std::vector<double> &valuesTableMerged) {

	if (valuesTableMerged.empty() == true)
		return;

	// For each table segment compute intersection if it exists
	std::vector<double> intersectionTable;

	double xi = valuesTableMerged [0];
	double y1i = getInterpolatedValue (values1Data, values1Table, values1Nb, xi);
	double y2i = getInterpolatedValue (values2Data, values2Table, values2Nb, xi);

fbe3c2bb   Benjamin Renard   First commit
467
	for (size_t t=1; t<valuesTableMerged.size(); t++) {
c6a67968   Benjamin Renard   Fix some violatio...
468
469
470
		double xj = valuesTableMerged [t];
		double y1j = getInterpolatedValue (values1Data, values1Table, values1Nb, xj);
		double y2j = getInterpolatedValue (values2Data, values2Table, values2Nb, xj);
fbe3c2bb   Benjamin Renard   First commit
471

c6a67968   Benjamin Renard   Fix some violatio...
472
		double xInter;
fbe3c2bb   Benjamin Renard   First commit
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
		if (intersect (xi, y1i, y2i, xj, y1j, y2j, &xInter) == true) {
			intersectionTable.push_back(xInter);
		}

		// Next vector element
		xi = xj;
		y1i = y1j;
		y2i = y2j;
	}

	// Add intersections informations to the resulting values
	valuesTableMerged.insert( valuesTableMerged.end(), intersectionTable.begin(), intersectionTable.end() );

	// Sort and remove duplicates for the resulting vector
	sort (valuesTableMerged.begin(), valuesTableMerged.end());
	valuesTableMerged.erase( unique( valuesTableMerged.begin(), valuesTableMerged.end() ), valuesTableMerged.end() );
}

/**
* @brief Draw Fill Area for the given arrays and the valueTime timeline
*/
void InstantPlot::drawFillArea (double *values1Data, double *values1Table, int values1Nb,
								double *values2Data, double *values2Table, int values2Nb,
								std::vector<double> &valuesTableMerged,
								bool colorGreaterSpecified, Color& colorGreater,
								bool colorLessSpecified, Color& colorLess) {
	// Get X and Y axis.
	boost::shared_ptr<Axis> lXAxis(_panel->getAxis(_iSerieProperties->getXAxisId()));
	boost::shared_ptr<Axis> lYAxis(_panel->getAxis(_iSerieProperties->getYAxisId()));

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

	_pls->wind(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());

	PLFLT x[4], y[4], deltai, deltaj;
	Color curColor;
	Color lInitialColor = changeColor(_pls, colorGreater, _panel->_page->_mode);

	for ( size_t i = 0; i < (valuesTableMerged.size() - 1); i++ )
	{
		x[0] = valuesTableMerged[i];
		x[1] = x[0];
		x[2] = valuesTableMerged[i+1];
		x[3] = x[2];

		y[0] = getInterpolatedValue (values1Data, values1Table, values1Nb, valuesTableMerged[i]);
		y[1] = getInterpolatedValue (values2Data, values2Table, values2Nb, valuesTableMerged[i]);
		y[2] = getInterpolatedValue (values2Data, values2Table, values2Nb, valuesTableMerged[i+1]);
		y[3] = getInterpolatedValue (values1Data, values1Table, values1Nb, valuesTableMerged[i+1]);

		deltai = y[1] - y[0];
		deltaj = y[2] - y[3];

		// Set fill color depending on segment position
		if ( ((deltai > 0) && (fabs(deltai) > fabs(deltaj))) ||
			 ((deltaj > 0) && (fabs(deltaj) > fabs(deltai))) ) {
			// s1 above s2
			if (colorGreaterSpecified == true) {
				curColor = colorGreater;
			} else {
				continue;
			}
		}
		else if ( 	((deltai < 0) && (fabs(deltai) > fabs(deltaj))) ||
					((deltaj < 0) && (fabs(deltaj) > fabs(deltai))) ) {
			// s1 under s2
			if (colorLessSpecified == true) {
				curColor = colorLess;
			} else {
				continue;
			}
		} else {
			// Colinear segments, no fill required
			continue;
		}

		// Fill polygon using the given color
		changeColor(_pls, curColor, _panel->_page->_mode);
		if (_iSerieProperties->getTableOnXAxis())
			_pls->fill(4, x, y);
		else
			_pls->fill(4, y, x);
    }

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

void InstantPlot::drawFills(double startDate, double stopDate) {
	if (_iSerieProperties == nullptr)
		return;

	PanelPlotOutput::drawFills(startDate, stopDate);
	LOG4CXX_DEBUG(gLogger, "InstantPlot::drawFillArea");

	double *values1Data 	= NULL;
	double *values1Table 	= NULL;
	int 	values1Nb	= 0;

	double 	values2Data [2];
	double 	values2Table [2];
fbe3c2bb   Benjamin Renard   First commit
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607

	double *values1X 	= NULL;
	double *values1Y 	= NULL;

	std::vector<double> valuesTableMerged;

	// Drawing Fill Area located between Serie and Constant (horizontal) line
	for (auto fillSerieConstant : _panel->_fillSerieConstants) {

		// Retrieve serie parameter values for serieId
		getSerieParameterValues (fillSerieConstant->getSerieId(), &values1X, &values1Y, &values1Nb);

		if (_iSerieProperties->getTableOnXAxis()) {
			values1Table = values1X;
			values1Data = values1Y;
		} else {
			values1Table = values1Y;
			values1Data = values1X;
		}

		// Retrieve constantLine informations for these fill
		ConstantLine *constantLine = getConstantLineFromSerieId (	fillSerieConstant->getSerieId(),
																fillSerieConstant->getConstantId());

		// Build values2 values2Time array with 2 values : yConst & (first value, last value) for serie
		values2Data [0] = convertYAxisValue (constantLine->getValue());
		values2Data [1] = convertYAxisValue (constantLine->getValue());

		values2Table [0] = values1Table [0];
		values2Table [1] = values1Table [values1Nb-1];
		// Logarithmic scale for X ?
		// already done !

c6a67968   Benjamin Renard   Fix some violatio...
608
		int values2Nb = 2;
fbe3c2bb   Benjamin Renard   First commit
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

		if (_iSerieProperties->getTableOnXAxis()) {
			// Logarithmic scale for Y ?
			if (_panel->getAxis(_iSerieProperties->getYAxisId())->_scale == Axis::Scale::LOGARITHMIC) {
				values2Data [0] = log10 (values2Data [0]);
				values2Data [1] = log10 (values2Data [1]);
			}
		} else {
			// Logarithmic scale for X ?
			if (_panel->getAxis(_iSerieProperties->getXAxisId())->_scale == Axis::Scale::LOGARITHMIC) {
				values2Data [0] = log10 (values2Data [0]);
				values2Data [1] = log10 (values2Data [1]);
			}
		}


		// Build time vector by merging existing times and computing intersections, and draw it !
		mergeAndSortTime (	values1Table, values1Nb,
							values2Table, values2Nb,
							valuesTableMerged);

		addIntersectionTable (values1Data, values1Table, values1Nb,
							 values2Data, values2Table, values2Nb,
							 valuesTableMerged);

		drawFillArea (	values1Data, values1Table, values1Nb,
						values2Data, values2Table, values2Nb,
						valuesTableMerged,
						fillSerieConstant->isColorGreaterSpecified(), fillSerieConstant->getColorGreater(),
						fillSerieConstant->isColorLessSpecified(), fillSerieConstant->getColorLess());

		delete [] values1Data;
		delete [] values1Table;
	}
}

void InstantPlot::drawSeries(double startDate, double stopDate, int intervalIndex, std::string pParamId,
		SeriesProperties& pSeries,
		AMDA::Common::ParameterIndexComponent pParamIndex, ParameterAxes& param,
faf4d845   Benjamin Renard   Add common functi...
648
		bool moreThanOneSerieForAxis, bool& noData) {
fbe3c2bb   Benjamin Renard   First commit
649
650
651
652
653
654
655
656
657
658
659
660
	if (_iSerieProperties == nullptr)
		return;

	PanelPlotOutput::drawSeries(startDate, stopDate, intervalIndex, pParamId, pSeries, pParamIndex, param, moreThanOneSerieForAxis);
	LOG4CXX_DEBUG(gLogger, "InstantPlot::drawSeries");

	double* xValues = NULL;
	double* yValues = NULL;
	int 	nbValues;

	getSerieParameterValues (_iSerieProperties->getId(), &xValues, &yValues, &nbValues);

faf4d845   Benjamin Renard   Add common functi...
661
662
663
664
665
666
667
668
	if (noData && (nbValues > 0)) {
		for (int i = 0; i < nbValues; ++i) {
			if (!isNAN(xValues[i]) && !isNAN(yValues[i])) {
				noData = false;
			}
		}
	}

fbe3c2bb   Benjamin Renard   First commit
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
	Color lineColor   = getSerieLineColor(pSeries, moreThanOneSerieForAxis);
	Color symbolColor = getSerieSymbolColor(pSeries, lineColor);

	drawSymbols(
		pSeries.getSymbolProperties().getType(),
		pSeries.getSymbolProperties().getSize(), 1.,
		symbolColor,
		nbValues, xValues, yValues);

	drawLines(
		pSeries.getLineProperties().getType(),
		pSeries.getLineProperties().getStyle(),
		pSeries.getLineProperties().getWidth(),
		lineColor,
		nbValues, xValues, yValues);

	//add serie to the params legend
	addSerieToParamsLegend(*_iSerieProperties,pParamIndex,param._originalParamId,
			lineColor,symbolColor,startDate,stopDate, intervalIndex);

	//delete data
	delete [] xValues;
	delete [] yValues;
}

void InstantPlot::configureSeriesAxis() {
	if (_iSerieProperties == nullptr)
		//nothing to do
		return;

	LOG4CXX_DEBUG(gLogger, "InstantPlot::configureSeriesAxis");

	///////////////////////////////////////////////////////////////////////////
	// Retrieve X and Y axis
	///////////////////////////////////////////////////////////////////////////

	boost::shared_ptr<Axis> lXAxis = _panel->getAxis(_iSerieProperties->getXAxisId());
	if (lXAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "InstantPlot::configureSeriesAxis" << ": X axis with id '" << _iSerieProperties->getXAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

08ec1dde   Benjamin Renard   Add propertie _us...
712
713
	lXAxis->_used = true;

fbe3c2bb   Benjamin Renard   First commit
714
715
716
717
718
719
720
	boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSerieProperties->getYAxisId());
	if (lYAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "InstantPlot::configureSeriesAxis" << ": Y axis with id '" << _iSerieProperties->getYAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

08ec1dde   Benjamin Renard   Add propertie _us...
721
722
	lYAxis->_used = true;

fbe3c2bb   Benjamin Renard   First commit
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
	if (_iSerieProperties->getTableOnXAxis())
	{
		configureTableAxis (lXAxis, false, 0);
		configureDataAxis (lYAxis, false);
	}
	else
	{
		configureTableAxis (lYAxis, false, 0);
		configureDataAxis (lXAxis, false);
	}
}

void InstantPlot::configureTableAxis (boost::shared_ptr<Axis> axisSPtr, bool isSpectro, int relatedDim)
{
	///////////////////////////////////////////////////////////////////////////
	// Configure range for table axis.
	///////////////////////////////////////////////////////////////////////////

	ParameterSPtr p = _parameterManager.getParameter(_originalParamId);

	int dimSize;
	if (relatedDim == 0)
		dimSize = (*_pParameterValues)[_originalParamId].getDim1Size();
	else
		dimSize = (*_pParameterValues)[_originalParamId].getDim2Size();

	//set axis range
	Range lAxisRange = axisSPtr->Axis::getRange();
	AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
	if (isnan(lAxisRange.getMin()) && isnan(lAxisRange.getMax()))
	{
		boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
		if (paramInfo != nullptr)
			tableSPtr = paramInfo->getTable(relatedDim);

		if (tableSPtr == nullptr) {
			LOG4CXX_DEBUG(gLogger, "No table defined => use index");
			lAxisRange.setMin(std::min(0.,lAxisRange.getMin()));
			lAxisRange.setMax(std::max((double)dimSize,lAxisRange.getMax()));
		} else {
			AMDA::Info::t_TableBound crtBound;

e7ea756d   Benjamin Renard   Implements tables...
765
			if (!tableSPtr->isVariable(&_parameterManager))
fbe3c2bb   Benjamin Renard   First commit
766
			{
1c0193a5   Benjamin Renard   Implement variabl...
767
768
769
770
771
772
				for (int i = 0; i < dimSize; ++i)
				{
					crtBound = tableSPtr->getBound(&_parameterManager, i);

					if (isSpectro)
					{
11754f01   Benjamin Renard   Fix axis range fo...
773
774
775
776
						if (!isNAN(crtBound.min))
							lAxisRange.setMin(std::min(crtBound.min,lAxisRange.getMin()));
						if (!isNAN(crtBound.max))
							lAxisRange.setMax(std::max(crtBound.max,lAxisRange.getMax()));
1c0193a5   Benjamin Renard   Implement variabl...
777
778
779
					}
					else
					{
11754f01   Benjamin Renard   Fix axis range fo...
780
781
782
783
						if (!isNAN(crtBound.min) && !isNAN(crtBound.max))
							lAxisRange.setMin(std::min((crtBound.min+ crtBound.max) / 2.0,lAxisRange.getMin()));
						if (!isNAN(crtBound.min) && !isNAN(crtBound.max))
							lAxisRange.setMax(std::max((crtBound.min+ crtBound.max) / 2.0,lAxisRange.getMax()));
1c0193a5   Benjamin Renard   Implement variabl...
784
785
786
787
788
789
					}
				}
			}
			else
			{
				std::map<std::string, std::string> relatedTableParam;
fbe3c2bb   Benjamin Renard   First commit
790
791
				if (isSpectro)
				{
1c0193a5   Benjamin Renard   Implement variabl...
792
793
794
795
796
797
798
799
800
					switch (relatedDim)
					{
					case 0 :
						relatedTableParam = _iSpectroProperties->getTable0Params();
						break;
					case 1 :
						relatedTableParam = _iSpectroProperties->getTable1Params();
						break;
					}
fbe3c2bb   Benjamin Renard   First commit
801
802
803
				}
				else
				{
1c0193a5   Benjamin Renard   Implement variabl...
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
					relatedTableParam = _iSerieProperties->getTableParams();
				}

				std::map<std::string, std::vector<double>> paramsTableData;
				for (std::map<std::string, std::string>::iterator it = relatedTableParam.begin(); it != relatedTableParam.end(); ++it)
				{
					ParameterData& data = (*_pParameterValues)[it->second];
					double valIdx = data.indexOf(_time);
					std::vector<double> paramTableValues;
					for (int i = 0; i < data.getDim1Size(); ++i)
					{
						double* values = data.getValues(AMDA::Common::ParameterIndexComponent(i), valIdx);
						paramTableValues.push_back((*values));
					}
					paramsTableData[it->first] = paramTableValues;
				}

				for (int i = 0; i < dimSize; ++i)
				{
					crtBound = tableSPtr->getBound(&_parameterManager, i, &paramsTableData);
					if (isSpectro)
					{
11754f01   Benjamin Renard   Fix axis range fo...
826
827
828
829
						if (!isNAN(crtBound.min))
							lAxisRange.setMin(std::min(crtBound.min,lAxisRange.getMin()));
						if (!isNAN(crtBound.max))
							lAxisRange.setMax(std::max(crtBound.max,lAxisRange.getMax()));
1c0193a5   Benjamin Renard   Implement variabl...
830
831
832
					}
					else
					{
11754f01   Benjamin Renard   Fix axis range fo...
833
834
835
836
						if (!isNAN(crtBound.min) && !isNAN(crtBound.max))
							lAxisRange.setMin(std::min((crtBound.min+ crtBound.max) / 2.0,lAxisRange.getMin()));
						if (!isNAN(crtBound.min) && !isNAN(crtBound.max))
							lAxisRange.setMax(std::max((crtBound.min+ crtBound.max) / 2.0,lAxisRange.getMax()));
1c0193a5   Benjamin Renard   Implement variabl...
837
					}
fbe3c2bb   Benjamin Renard   First commit
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
				}
			}
		}
	}

	//do not extend the axis
	lAxisRange._extend = false;
	axisSPtr->setRange(lAxisRange);

	LOG4CXX_DEBUG(gLogger, "Table axis range : min = " << lAxisRange.getMin() << ", max = " << lAxisRange.getMax());
}

void InstantPlot::configureDataAxis (boost::shared_ptr<Axis> axisSPtr, bool isSpectro)
{
	int dim1Size = (*_pParameterValues)[_originalParamId].getDim1Size();
	int dim2Size = (*_pParameterValues)[_originalParamId].getDim2Size();

	///////////////////////////////////////////////////////////////////////////
	// Configure range axis
	///////////////////////////////////////////////////////////////////////////
	Range lAxisRange(axisSPtr->getRange());

	// If user didn't set a range, calculate range automatically (based on parameters values).
	if (!lAxisRange.isSet()) {
faf4d845   Benjamin Renard   Add common functi...
862
863
		double instantTimeMin = NAN;
		double instantTimeMax = NAN;
fbe3c2bb   Benjamin Renard   First commit
864
865
866
867
868
869
870
871
872

		ParameterData& data = (*_pParameterValues)[_originalParamId];

		if (isSpectro)
		{
			for (int i = 0; i < dim1Size; ++i) {
				for (int j = 0; j < dim2Size; ++j) {
					double valIdx = data.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i,j));

faf4d845   Benjamin Renard   Add common functi...
873
874
875
					if (!isNAN(valIdx)) {
						if (isNAN(instantTimeMax) || (valIdx > instantTimeMax))
							instantTimeMax = valIdx;
fbe3c2bb   Benjamin Renard   First commit
876

faf4d845   Benjamin Renard   Add common functi...
877
878
879
						if (isNAN(instantTimeMin) || (valIdx < instantTimeMin))
							instantTimeMin = valIdx;
					}
fbe3c2bb   Benjamin Renard   First commit
880
881
882
883
884
885
886
887
				}
			}
		}
		else
		{
			for (int i = 0; i < dim1Size; ++i) {
				double valIdx = data.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i));

faf4d845   Benjamin Renard   Add common functi...
888
889
890
				if (!isNAN(valIdx)) {
					if (isNAN(instantTimeMax) || (valIdx > instantTimeMax))
						instantTimeMax = valIdx;
fbe3c2bb   Benjamin Renard   First commit
891

faf4d845   Benjamin Renard   Add common functi...
892
893
894
					if (isNAN(instantTimeMin) || (valIdx < instantTimeMin))
						instantTimeMin = valIdx;
				}
fbe3c2bb   Benjamin Renard   First commit
895
896
897
898
899
900
901
902
			}
		}

		//do not extend the axis
		lAxisRange._extend = false;
		lAxisRange.setMin(instantTimeMin);
		lAxisRange.setMax(instantTimeMax);

faf4d845   Benjamin Renard   Add common functi...
903
		fixRange(lAxisRange, axisSPtr->_scale == Axis::Scale::LOGARITHMIC);
e062d6ef   Benjamin Renard   Fix axes range wh...
904

fbe3c2bb   Benjamin Renard   First commit
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
		axisSPtr->setRange(lAxisRange);

	}
	LOG4CXX_DEBUG(gLogger, "Data axis range : min = " << lAxisRange.getMin() << ", max = " << lAxisRange.getMax());
}

void InstantPlot::configureSeriesAxisLegend () {
	if (_iSerieProperties == nullptr)
		return;

	std::string yAxisId = _iSerieProperties->getYAxisId();

	boost::shared_ptr<Axis> lYAxis = _panel->getAxis(yAxisId);
	if (lYAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "TimePlot::configureSeriesAxis" << ": Y axis with id '" << yAxisId << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

	std::string xAxisId = _iSerieProperties->getXAxisId();

	boost::shared_ptr<Axis> lXAxis = _panel->getAxis(xAxisId);
	if (lXAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "TimePlot::configureSeriesAxis" << ": Y axis with id '" << xAxisId << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

	if (_iSerieProperties->getTableOnXAxis())
	{
		configureTableAxisLegend(lXAxis,0);
		configureDataAxisLegend(lYAxis, false);
	}
	else
	{
		configureTableAxisLegend(lYAxis,0);
		configureDataAxisLegend(lXAxis, false);
	}
}

void InstantPlot::configureTableAxisLegend(boost::shared_ptr<Axis> axisSPtr, int relatedDim) {
5ee90a58   Benjamin Renard   Use AxisLegendMan...
946
947
	AMDA::Common::ParameterIndexComponentList indexes;
	AxisLegendManager::setAxisLegendForTable(this, axisSPtr, _originalParamId, _originalParamId, indexes, relatedDim);
fbe3c2bb   Benjamin Renard   First commit
948
949
950
}

void InstantPlot::configureDataAxisLegend(boost::shared_ptr<Axis> axisSPtr, bool isSpectro) {
5ee90a58   Benjamin Renard   Use AxisLegendMan...
951
952
953
954
955
956
957
	if (isSpectro)
	{
		AxisLegendManager::setAxisLegendForSpectro(this, axisSPtr, _originalParamId);
	}
	else
	{
		AxisLegendManager::AxisParamsComponents axisParamsComponents;
8bb0f02b   Benjamin Renard   Set colors in axi...
958
		axisParamsComponents[_originalParamId].push_back(ParameterIndexComponentColor(-1,-1, axisSPtr->_color));
5ee90a58   Benjamin Renard   Use AxisLegendMan...
959
		AxisLegendManager::setAxisLegendForSeries(this, axisSPtr, axisParamsComponents);
fbe3c2bb   Benjamin Renard   First commit
960
961
962
963
	}
}

void InstantPlot::drawSpectro(double startDate, double stopDate, std::string pParamId,
5c050d50   Benjamin Renard   Fix another bugs ...
964
		SpectroProperties& pSpectro, bool& noData)
fbe3c2bb   Benjamin Renard   First commit
965
966
967
968
969
970
971
972
973
974
975
976
{
	if (_iSpectroProperties == nullptr)
		return;

	PanelPlotOutput::drawSpectro(startDate, stopDate, pParamId, pSpectro);
	LOG4CXX_DEBUG(gLogger, "InstantPlot::drawSpectro");

	//get parameter data and info
	ParameterSPtr p = _parameterManager.getParameter(pParamId);

	ParameterData& data = (*_pParameterValues)[pParamId];

7d5239f5   Benjamin Renard   Fix instant plot ...
977
978
979
980
981
982
	boost::shared_ptr<AMDA::Info::ParamTable> tableOnXSPtr;
	boost::shared_ptr<AMDA::Info::ParamTable> tableOnYSPtr;
	int dimOnXSize = 0.;
	int dimOnYSize = 0.;
	std::map<std::string, std::string> paramsOnX;
	std::map<std::string, std::string> paramsOnY;
fbe3c2bb   Benjamin Renard   First commit
983
	AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
7d5239f5   Benjamin Renard   Fix instant plot ...
984
	if (_iSpectroProperties->getDimOnXAxis() == 0)
fbe3c2bb   Benjamin Renard   First commit
985
	{
7d5239f5   Benjamin Renard   Fix instant plot ...
986
987
988
		if (paramInfo != nullptr) {
			tableOnXSPtr = paramInfo->getTable(0);
			tableOnYSPtr = paramInfo->getTable(1);
fbe3c2bb   Benjamin Renard   First commit
989
		}
7d5239f5   Benjamin Renard   Fix instant plot ...
990
991
992
993
994
995
996
997
998
999
		dimOnXSize   = data.getDim1Size();
		dimOnYSize   = data.getDim2Size();
		paramsOnX    = _iSpectroProperties->getTable0Params();
		paramsOnY    = _iSpectroProperties->getTable1Params();
	}
	else
	{
		if (paramInfo != nullptr) {
			tableOnXSPtr = paramInfo->getTable(1);
			tableOnYSPtr = paramInfo->getTable(0);
fbe3c2bb   Benjamin Renard   First commit
1000
		}
7d5239f5   Benjamin Renard   Fix instant plot ...
1001
1002
1003
1004
		dimOnXSize   = data.getDim2Size();
		dimOnYSize   = data.getDim1Size();
		paramsOnX    = _iSpectroProperties->getTable1Params();
		paramsOnY    = _iSpectroProperties->getTable0Params();
fbe3c2bb   Benjamin Renard   First commit
1005
1006
1007
1008
1009
1010
1011
1012
	}

	//get axis
	boost::shared_ptr<Axis> lXAxis = _panel->getAxis(_iSpectroProperties->getXAxisId());
	boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSpectroProperties->getYAxisId());
	boost::shared_ptr<ColorAxis> lZAxis = _panel->getColorAxis();

	//Check dimensions
7d5239f5   Benjamin Renard   Fix instant plot ...
1013
	if ((dimOnXSize <= 0) || (dimOnYSize <= 0))
fbe3c2bb   Benjamin Renard   First commit
1014
1015
1016
1017
1018
1019
	{
		LOG4CXX_INFO(gLogger, "InstantPlot::drawSpectro - No data to plot");
		return;
	}

	MatrixGrid matrixGrid;
7d5239f5   Benjamin Renard   Fix instant plot ...
1020
	for (int i = 0; i < dimOnXSize; ++i)
fbe3c2bb   Benjamin Renard   First commit
1021
1022
	{
		GridPart part;
7d5239f5   Benjamin Renard   Fix instant plot ...
1023
1024
1025
1026
1027
1028
1029
		if (tableOnXSPtr == nullptr)
		{
			//no table defined => use index
			part.x[0] = i;
			part.x[1] = i+1;
		}
		else
fbe3c2bb   Benjamin Renard   First commit
1030
		{
7d5239f5   Benjamin Renard   Fix instant plot ...
1031
			if (!tableOnXSPtr->isVariable(&_parameterManager))
fbe3c2bb   Benjamin Renard   First commit
1032
			{
7d5239f5   Benjamin Renard   Fix instant plot ...
1033
1034
				part.x[0] = tableOnXSPtr->getBound(&_parameterManager, i).min;
				part.x[1] = tableOnXSPtr->getBound(&_parameterManager, i).max;
fbe3c2bb   Benjamin Renard   First commit
1035
1036
1037
			}
			else
			{
7d5239f5   Benjamin Renard   Fix instant plot ...
1038
1039
				std::map<std::string, std::vector<double>> paramsTableData;
				for (std::map<std::string, std::string>::iterator it = paramsOnX.begin(); it != paramsOnX.end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
1040
				{
7d5239f5   Benjamin Renard   Fix instant plot ...
1041
1042
1043
1044
					ParameterData& data = (*_pParameterValues)[it->second];
					double valIdx = data.indexOf(_time);
					std::vector<double> paramTableValues;
					for (int k = 0; k < data.getDim1Size(); ++k)
1c0193a5   Benjamin Renard   Implement variabl...
1045
					{
7d5239f5   Benjamin Renard   Fix instant plot ...
1046
1047
						double* values = data.getValues(AMDA::Common::ParameterIndexComponent(k), valIdx);
						paramTableValues.push_back((*values));
1c0193a5   Benjamin Renard   Implement variabl...
1048
					}
7d5239f5   Benjamin Renard   Fix instant plot ...
1049
					paramsTableData[it->first] = paramTableValues;
1c0193a5   Benjamin Renard   Implement variabl...
1050
				}
7d5239f5   Benjamin Renard   Fix instant plot ...
1051
1052
				part.x[0] = tableOnXSPtr->getBound(&_parameterManager, i, &paramsTableData).min;
				part.x[1] = tableOnXSPtr->getBound(&_parameterManager, i, &paramsTableData).max;
fbe3c2bb   Benjamin Renard   First commit
1053
1054
			}
		}
7d5239f5   Benjamin Renard   Fix instant plot ...
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068

		if (std::isnan(part.x[0]) || std::isnan(part.x[1])) {
			continue;
		}

		if (lXAxis->_scale == Axis::Scale::LOGARITHMIC) {
			if ((part.x[0] <= 0) || (part.x[1] <= 0)) {
				continue;
			}
			part.x[0] = log10(part.x[0]);
			part.x[1] = log10(part.x[1]);
		}

		for (int j = 0; j < dimOnYSize; ++j)
fbe3c2bb   Benjamin Renard   First commit
1069
		{
7d5239f5   Benjamin Renard   Fix instant plot ...
1070
			if (tableOnYSPtr == nullptr)
fbe3c2bb   Benjamin Renard   First commit
1071
1072
			{
				//no table defined => use index
7d5239f5   Benjamin Renard   Fix instant plot ...
1073
1074
				part.y[0] = j;
				part.y[1] = j+1;
fbe3c2bb   Benjamin Renard   First commit
1075
1076
1077
			}
			else
			{
7d5239f5   Benjamin Renard   Fix instant plot ...
1078
				if (!tableOnYSPtr->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
1079
				{
7d5239f5   Benjamin Renard   Fix instant plot ...
1080
1081
					part.y[0] = tableOnYSPtr->getBound(&_parameterManager, j).min;
					part.y[1] = tableOnYSPtr->getBound(&_parameterManager, j).max;
1c0193a5   Benjamin Renard   Implement variabl...
1082
1083
1084
1085
				}
				else
				{
					std::map<std::string, std::vector<double>> paramsTableData;
7d5239f5   Benjamin Renard   Fix instant plot ...
1086
					for (std::map<std::string, std::string>::iterator it = paramsOnY.begin(); it != paramsOnY.end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
1087
1088
1089
1090
					{
						ParameterData& data = (*_pParameterValues)[it->second];
						double valIdx = data.indexOf(_time);
						std::vector<double> paramTableValues;
7d5239f5   Benjamin Renard   Fix instant plot ...
1091
						for (int k = 0; k < data.getDim1Size(); ++k)
1c0193a5   Benjamin Renard   Implement variabl...
1092
						{
7d5239f5   Benjamin Renard   Fix instant plot ...
1093
							double* values = data.getValues(AMDA::Common::ParameterIndexComponent(k), valIdx);
1c0193a5   Benjamin Renard   Implement variabl...
1094
1095
1096
1097
							paramTableValues.push_back((*values));
						}
						paramsTableData[it->first] = paramTableValues;
					}
7d5239f5   Benjamin Renard   Fix instant plot ...
1098
1099
					part.y[0] = tableOnYSPtr->getBound(&_parameterManager, j, &paramsTableData).min;
					part.y[1] = tableOnYSPtr->getBound(&_parameterManager, j, &paramsTableData).max;
1c0193a5   Benjamin Renard   Implement variabl...
1100
				}
fbe3c2bb   Benjamin Renard   First commit
1101
			}
fbe3c2bb   Benjamin Renard   First commit
1102

7d5239f5   Benjamin Renard   Fix instant plot ...
1103
1104
			if (std::isnan(part.y[0]) || std::isnan(part.y[1])) {
				continue;
fbe3c2bb   Benjamin Renard   First commit
1105
			}
7d5239f5   Benjamin Renard   Fix instant plot ...
1106
1107

			if (lYAxis->_scale == Axis::Scale::LOGARITHMIC)
fbe3c2bb   Benjamin Renard   First commit
1108
			{
7d5239f5   Benjamin Renard   Fix instant plot ...
1109
1110
				if ((part.y[0] <= 0) || (part.y[1] <= 0)) {
					continue;
fbe3c2bb   Benjamin Renard   First commit
1111
				}
7d5239f5   Benjamin Renard   Fix instant plot ...
1112
1113
				part.y[0] = log10(part.y[0]);
				part.y[1] = log10(part.y[1]);
fbe3c2bb   Benjamin Renard   First commit
1114
1115
			}

5d98ca3d   Benjamin Renard   Draw intervals in...
1116
			part.isColorIndex = false;
7d5239f5   Benjamin Renard   Fix instant plot ...
1117
1118
			if (_iSpectroProperties->getDimOnXAxis() == 0) {
				part.value = data.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i,j));
fbe3c2bb   Benjamin Renard   First commit
1119
			}
7d5239f5   Benjamin Renard   Fix instant plot ...
1120
1121
			else {
				part.value = data.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(j,i));
fbe3c2bb   Benjamin Renard   First commit
1122
			}
35fde2f4   Benjamin Renard   Remove a log used...
1123

5c050d50   Benjamin Renard   Fix another bugs ...
1124
1125
			if (!isNAN(part.value))
				noData = false;
fbe3c2bb   Benjamin Renard   First commit
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
			matrixGrid.push_back(part);
		}
	}

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

	//draw spectro
	drawMatrix(matrixGrid, _iSpectroProperties->getMin(), _iSpectroProperties->getMax(),
		minValColor, maxValColor, lZAxis->_color._colorMapIndex);
}

void InstantPlot::configureSpectroAxis()
{
	if (_iSpectroProperties == nullptr)
		return;

	LOG4CXX_DEBUG(gLogger, "InstantPlot::configureSpectroAxis");

	///////////////////////////////////////////////////////////////////////////
	// Retrieve X, Y and Z axis
	///////////////////////////////////////////////////////////////////////////

	boost::shared_ptr<Axis> lXAxis = _panel->getAxis(_iSpectroProperties->getXAxisId());
	if (lXAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "InstantPlot::configureSpectroAxis" << ": X axis with id '" << _iSpectroProperties->getXAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}
08ec1dde   Benjamin Renard   Add propertie _us...
1156
	lXAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
1157
1158
1159
1160
1161
1162
1163

	boost::shared_ptr<Axis> lYAxis = _panel->getAxis(_iSpectroProperties->getYAxisId());
	if (lYAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "InstantPlot::configureSpectroAxis" << ": Y axis with id '" << _iSpectroProperties->getYAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}
08ec1dde   Benjamin Renard   Add propertie _us...
1164
	lYAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
1165
1166
1167
1168
1169
1170
1171

	boost::shared_ptr<Axis> lZAxis = _panel->getAxis(_iSpectroProperties->getZAxisId());
	if (lZAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "InstantPlot::configureSpectroAxis" << ": Z axis with id '" << _iSpectroProperties->getYAxisId() << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}
08ec1dde   Benjamin Renard   Add propertie _us...
1172
	lZAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
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

	if (_iSpectroProperties->getDimOnXAxis() == 0)
	{
		configureTableAxis (lXAxis, true, 0);
		configureTableAxis (lYAxis, true, 1);
		configureDataAxis (lZAxis, true);
	}
	else
	{
		configureTableAxis (lXAxis, true, 1);
		configureTableAxis (lYAxis, true, 0);
		configureDataAxis (lZAxis, true);
	}
}

void InstantPlot::configureSpectroAxisLegend ()
{
	if (_iSpectroProperties == nullptr)
		return;

	LOG4CXX_DEBUG(gLogger, "InstantPlot::configureSpectroAxisLegend");

	//get X axis
	std::string xAxisId = _iSpectroProperties->getXAxisId();
	boost::shared_ptr<Axis> lXAxis = _panel->getAxis(xAxisId);
	if (lXAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "TimePlot::configureSpectroAxisLegend" << ": X axis with id '" << xAxisId << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

	//get y axis
	std::string yAxisId = _iSpectroProperties->getYAxisId();
	boost::shared_ptr<Axis> lYAxis = _panel->getAxis(yAxisId);
	if (lYAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "TimePlot::configureSpectroAxisLegend" << ": Y axis with id '" << yAxisId << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

	//get z axis
	std::string zAxisId = _iSpectroProperties->getZAxisId();
	boost::shared_ptr<Axis> lZAxis = _panel->getAxis(zAxisId);
	if (lZAxis.get() == nullptr) {
		std::stringstream lError;
		lError << "InstantPlot::configureSpectroAxisLegend" << ": Z axis with id '" << zAxisId << "' not found.";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
	}

	if (_iSpectroProperties->getDimOnXAxis() == 0)
	{
		configureTableAxisLegend(lXAxis,0);
		configureTableAxisLegend(lYAxis,1);
		configureDataAxisLegend(lZAxis, true);
	}
	else
	{
		configureTableAxisLegend(lXAxis,1);
		configureTableAxisLegend(lYAxis,0);
		configureDataAxisLegend(lZAxis, true);
	}
}

/**
 * @overload  PanelPlotOutput::getSerieParamsLegendString Get the instant serie legend
 */
std::string InstantPlot::getSerieParamsLegendString(SeriesProperties &/*rSeriesProperties*/,
			AMDA::Common::ParameterIndexComponent& /*index*/, std::string /*originalParamId*/)
{
	if (_iSerieProperties == nullptr)
		return "";

	// Retrieve ParamInfo Manager
	ParamMgr 		*piMgr =ParamMgr::getInstance();

	// Build parameter text legend depending on the availability of paramInfo
	// for Y and X component

	// Try to retrieve informations from paramInfo for table component
	ParameterSPtr p = _parameterManager.getParameter(_originalParamId);
	ParamInfoSPtr	paramInfo = piMgr->getParamInfoFromId(p->getInfoId());

	std::string tableLegendText;
	if (paramInfo)
	{
		boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr = paramInfo->getTable(0);

		if (tableSPtr) {
e7ea756d   Benjamin Renard   Implements tables...
1261
			tableLegendText = tableSPtr->getName(&_parameterManager);
fbe3c2bb   Benjamin Renard   First commit
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
		} else {
			tableLegendText = "Table indexes";
		}
	}

	// Build parameter text legend depending on the availability of paramInfo
	std::string dataLegendText;
	if (paramInfo) {
		dataLegendText = paramInfo->getShortName();
	} else {
		dataLegendText = _originalParamId;
	}

	// Data always depends on table, no inversion even if table not on x axis
	std::stringstream paramLegendText;
	paramLegendText << dataLegendText << " = f(" << tableLegendText << ")";

	return paramLegendText.str();
}

/**
 * @overload PanelPlotOutput::configureParamsLegend Configure params legend for an instant plot.
 */
void InstantPlot::configureParamsLegend(double startTime, double stopTime, int intervalIndex)
{
	LOG4CXX_DEBUG(gLogger, "InstantPlot::configureParamsLegend");

20fef3b6   Benjamin Renard   Fix reset functio...
1289
	_panel->_paramsLegendProperties.resetPlot();
fbe3c2bb   Benjamin Renard   First commit
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305

	if (_iSerieProperties == nullptr)
		return;

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

	AMDA::Common::ParameterIndexComponent index(-1,-1);
	addSerieToParamsLegend(*_iSerieProperties,index,
			_originalParamId,fakeColor, fakeColor,startTime,stopTime, intervalIndex);
}

/**
 * @brief Override PanelPlotOutput:draw
 * draw the plot for the current time interval
 */
d57f00dc   Benjamin Renard   Draw NO DATA
1306
bool InstantPlot::draw(double startTime, double stopTime, int intervalIndex,
fbe3c2bb   Benjamin Renard   First commit
1307
1308
1309
		bool /*isFirstInterval*/, bool /*isLastInterval*/) {
	LOG4CXX_DEBUG(gLogger, "InstantPlot::draw");

20fef3b6   Benjamin Renard   Fix reset functio...
1310
	_panel->_paramsLegendProperties.resetPlot();
fbe3c2bb   Benjamin Renard   First commit
1311
1312
1313
1314

	// Sets panel plplot viewport, draw background & title for the panel
	_panel->draw(_pls);

fbe3c2bb   Benjamin Renard   First commit
1315

d57f00dc   Benjamin Renard   Draw NO DATA
1316
	bool noData = true;
ece33d6f   Benjamin Renard   Draw the panel of...
1317
	if (!_originalParamId.empty())
fbe3c2bb   Benjamin Renard   First commit
1318
	{
ece33d6f   Benjamin Renard   Draw the panel of...
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
		//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()));
			}

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

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

		if (_iSerieProperties != nullptr)
		{
			// Draw series for parameters.
			ParameterAxes param;
			drawSeries(startTime, stopTime, intervalIndex, _originalParamId,
					*_iSerieProperties, AMDA::Common::ParameterIndexComponent(-1,-1),
faf4d845   Benjamin Renard   Add common functi...
1340
					param, false, noData);
ece33d6f   Benjamin Renard   Draw the panel of...
1341
1342
1343
		}
		else if (_iSpectroProperties != nullptr)
		{
faf4d845   Benjamin Renard   Add common functi...
1344
			drawSpectro(startTime, stopTime, _originalParamId, *_iSpectroProperties, noData);
ece33d6f   Benjamin Renard   Draw the panel of...
1345
1346
		}

537e3ab0   Benjamin Renard   Fix a bug with In...
1347
1348
1349
		// Draw additionnal objects for this series.
		drawAdditionalObjects();

ece33d6f   Benjamin Renard   Draw the panel of...
1350
1351
1352
1353
1354
		//Draw parameter legend
		drawParamsLegend();

		//Draw text legends
		drawTextLegends();
d57f00dc   Benjamin Renard   Draw NO DATA
1355
1356

		return !noData;
fbe3c2bb   Benjamin Renard   First commit
1357
	}
d57f00dc   Benjamin Renard   Draw NO DATA
1358
	else {
ece33d6f   Benjamin Renard   Draw the panel of...
1359
		_panel->drawEmptyPanel(_pls);
d57f00dc   Benjamin Renard   Draw NO DATA
1360
1361
		return true;
	}
537e3ab0   Benjamin Renard   Fix a bug with In...
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
}

/**
 * @brief Override drawAdditionalObjects
 * draw additional objects
 */
void InstantPlot::drawAdditionalObjects() {
	if (_iSpectroProperties != nullptr)
	{
		boost::shared_ptr<Axis> lXAxis(_panel->getAxis(_iSpectroProperties->getXAxisId()));
		boost::shared_ptr<Axis> lYAxis(_panel->getAxis(_iSpectroProperties->getYAxisId()));

		if ((lXAxis != nullptr) && (lYAxis != nullptr))
		{
			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);
ece33d6f   Benjamin Renard   Draw the panel of...
1386

537e3ab0   Benjamin Renard   Fix a bug with In...
1387
1388
			if (!lXAxis->_additionalObjDrawn || !lYAxis->_additionalObjDrawn)
				drawTextPlots (lXAxis, lYAxis, lPlWindow, _panel->_textPlots);
fbe3c2bb   Benjamin Renard   First commit
1389

537e3ab0   Benjamin Renard   Fix a bug with In...
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
			lXAxis->_additionalObjDrawn = true;
			lYAxis->_additionalObjDrawn = true;
		}
	}

	if (_iSerieProperties != nullptr)
	{
		boost::shared_ptr<Axis> lXAxis(_panel->getAxis(_iSerieProperties->getXAxisId()));
		boost::shared_ptr<Axis> lYAxis(_panel->getAxis(_iSerieProperties->getYAxisId()));

		if ((lXAxis != nullptr) && (lYAxis != nullptr))
		{
			Range lXRange = lXAxis->getRange();
			Range lYRange = lYAxis->getRange();
fbe3c2bb   Benjamin Renard   First commit
1404

537e3ab0   Benjamin Renard   Fix a bug with In...
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
			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
1420
1421
1422
}

} /* namespace plot */