Blame view

src/ParamOutputImpl/Plot/InstantPlot/InstantPlot.cc 45.4 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

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),
11080d60   Erdogan Furkan   Previous/next but...
30
31
		_prevTime(0),
		_nextTime(0),
fbe3c2bb   Benjamin Renard   First commit
32
33
34
35
36
37
38
		_originalParamId("") {
}

InstantPlot::~InstantPlot() {
}

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

	// 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...
52
53
54
55
56
57
58
59
60
61
62
63

	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...
64
			if ((tableSPtr != nullptr) && (tableSPtr->isVariable(&_parameterManager)))
1c0193a5   Benjamin Renard   Implement variabl...
65
			{
e7ea756d   Benjamin Renard   Implements tables...
66
				for (std::map<std::string, std::string>::iterator it = tableSPtr->getTableParams(&_parameterManager).begin(); it != tableSPtr->getTableParams(&_parameterManager).end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
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
95
				{
					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...
96
			if ((table0SPtr != nullptr) && table0SPtr->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
97
			{
e7ea756d   Benjamin Renard   Implements tables...
98
				for (std::map<std::string, std::string>::iterator it = table0SPtr->getTableParams(&_parameterManager).begin(); it != table0SPtr->getTableParams(&_parameterManager).end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
				{
					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...
117
			if ((table1SPtr != nullptr) && table1SPtr->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
118
			{
e7ea756d   Benjamin Renard   Implements tables...
119
				for (std::map<std::string, std::string>::iterator it = table1SPtr->getTableParams(&_parameterManager).begin(); it != table1SPtr->getTableParams(&_parameterManager).end(); ++it)
1c0193a5   Benjamin Renard   Implement variabl...
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
				{
					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
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
186
187
}

/**
 * @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...
188
	if (_panel->getTitle()->_text.empty() || _panel->_updateTitleOnNextInterval) {
fbe3c2bb   Benjamin Renard   First commit
189
190
191
192
		//Title must be updated during the next interval plot
		_panel->_updateTitleOnNextInterval = true;

		// Set start date and end date.
2ff3868e   Erdogan Furkan   #10663 - Modify T...
193
		std::string lTimeFormat("%Y/%m/%d %H:%M:%S");
fbe3c2bb   Benjamin Renard   First commit
194
195
196
197
198
199
200

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

		// Format date.
		strftime(lStartTimeChr, 80, lTimeFormat.c_str(), lStartTimeTm);
2ff3868e   Erdogan Furkan   #10663 - Modify T...
201
202
203
		std::string lStartTimeStr= lStartTimeChr;
		lStartTimeStr += '.'+std::to_string(_time -lStartTime ).substr(2,3);
		_panel->setTitleText((const char*)lStartTimeStr.c_str());
fbe3c2bb   Benjamin Renard   First commit
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
271
272
273
	}

	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...
274
275
276


		*nbValues = paramData.getDim1Size();
fbe3c2bb   Benjamin Renard   First commit
277
278
279
280
281
282
283
284
285
286
287
288

		// 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) {
11080d60   Erdogan Furkan   Previous/next but...
289
			double value = paramData.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i),_prevTime, _nextTime);
fbe3c2bb   Benjamin Renard   First commit
290
291
292
293
294
			valueData[i] = value;
			valueMin = std::min (valueMin,value);
			valueMax = std::max (valueMax,value);

			if (paramTable) {
e7ea756d   Benjamin Renard   Implements tables...
295
				if (!paramTable->isVariable(&_parameterManager))
1c0193a5   Benjamin Renard   Implement variabl...
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
					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
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
467
468
			} 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
469
	for (size_t t=1; t<valuesTableMerged.size(); t++) {
c6a67968   Benjamin Renard   Fix some violatio...
470
471
472
		double xj = valuesTableMerged [t];
		double y1j = getInterpolatedValue (values1Data, values1Table, values1Nb, xj);
		double y2j = getInterpolatedValue (values2Data, values2Table, values2Nb, xj);
fbe3c2bb   Benjamin Renard   First commit
473

c6a67968   Benjamin Renard   Fix some violatio...
474
		double xInter;
fbe3c2bb   Benjamin Renard   First commit
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
575
576
		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
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
608
609

	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...
610
		int values2Nb = 2;
fbe3c2bb   Benjamin Renard   First commit
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
648
649

		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...
650
		bool moreThanOneSerieForAxis, bool& noData) {
fbe3c2bb   Benjamin Renard   First commit
651
652
653
654
655
656
657
658
659
660
661
662
	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...
663
664
665
666
667
668
669
670
	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
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
	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...
714
715
	lXAxis->_used = true;

fbe3c2bb   Benjamin Renard   First commit
716
717
718
719
720
721
722
	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...
723
724
	lYAxis->_used = true;

fbe3c2bb   Benjamin Renard   First commit
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
	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...
767
			if (!tableSPtr->isVariable(&_parameterManager))
fbe3c2bb   Benjamin Renard   First commit
768
			{
1c0193a5   Benjamin Renard   Implement variabl...
769
770
771
772
773
774
				for (int i = 0; i < dimSize; ++i)
				{
					crtBound = tableSPtr->getBound(&_parameterManager, i);

					if (isSpectro)
					{
11754f01   Benjamin Renard   Fix axis range fo...
775
776
777
778
						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...
779
780
781
					}
					else
					{
11754f01   Benjamin Renard   Fix axis range fo...
782
783
784
785
						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...
786
787
788
789
790
791
					}
				}
			}
			else
			{
				std::map<std::string, std::string> relatedTableParam;
fbe3c2bb   Benjamin Renard   First commit
792
793
				if (isSpectro)
				{
1c0193a5   Benjamin Renard   Implement variabl...
794
795
796
797
798
799
800
801
802
					switch (relatedDim)
					{
					case 0 :
						relatedTableParam = _iSpectroProperties->getTable0Params();
						break;
					case 1 :
						relatedTableParam = _iSpectroProperties->getTable1Params();
						break;
					}
fbe3c2bb   Benjamin Renard   First commit
803
804
805
				}
				else
				{
1c0193a5   Benjamin Renard   Implement variabl...
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
					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...
828
829
830
831
						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...
832
833
834
					}
					else
					{
11754f01   Benjamin Renard   Fix axis range fo...
835
836
837
838
						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...
839
					}
fbe3c2bb   Benjamin Renard   First commit
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
				}
			}
		}
	}

	//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...
864
865
		double instantTimeMin = NAN;
		double instantTimeMax = NAN;
fbe3c2bb   Benjamin Renard   First commit
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) {
11080d60   Erdogan Furkan   Previous/next but...
873
					double valIdx = data.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i,j),_prevTime, _nextTime);
fbe3c2bb   Benjamin Renard   First commit
874

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

faf4d845   Benjamin Renard   Add common functi...
879
880
881
						if (isNAN(instantTimeMin) || (valIdx < instantTimeMin))
							instantTimeMin = valIdx;
					}
fbe3c2bb   Benjamin Renard   First commit
882
883
884
885
886
887
				}
			}
		}
		else
		{
			for (int i = 0; i < dim1Size; ++i) {
11080d60   Erdogan Furkan   Previous/next but...
888
				double valIdx = data.getInterpolatedValue(_time, AMDA::Common::ParameterIndexComponent(i),_prevTime, _nextTime);
fbe3c2bb   Benjamin Renard   First commit
889

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

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

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

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

fbe3c2bb   Benjamin Renard   First commit
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
946
947
		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...
948
949
	AMDA::Common::ParameterIndexComponentList indexes;
	AxisLegendManager::setAxisLegendForTable(this, axisSPtr, _originalParamId, _originalParamId, indexes, relatedDim);
fbe3c2bb   Benjamin Renard   First commit
950
951
952
}

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

void InstantPlot::drawSpectro(double startDate, double stopDate, std::string pParamId,
5c050d50   Benjamin Renard   Fix another bugs ...
966
		SpectroProperties& pSpectro, bool& noData)
fbe3c2bb   Benjamin Renard   First commit
967
968
969
970
971
972
973
974
975
976
977
978
{
	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 ...
979
980
981
982
983
984
	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
985
	AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
7d5239f5   Benjamin Renard   Fix instant plot ...
986
	if (_iSpectroProperties->getDimOnXAxis() == 0)
fbe3c2bb   Benjamin Renard   First commit
987
	{
7d5239f5   Benjamin Renard   Fix instant plot ...
988
989
990
		if (paramInfo != nullptr) {
			tableOnXSPtr = paramInfo->getTable(0);
			tableOnYSPtr = paramInfo->getTable(1);
fbe3c2bb   Benjamin Renard   First commit
991
		}
7d5239f5   Benjamin Renard   Fix instant plot ...
992
993
994
995
996
997
998
999
1000
1001
		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
1002
		}
7d5239f5   Benjamin Renard   Fix instant plot ...
1003
1004
1005
1006
		dimOnXSize   = data.getDim2Size();
		dimOnYSize   = data.getDim1Size();
		paramsOnX    = _iSpectroProperties->getTable1Params();
		paramsOnY    = _iSpectroProperties->getTable0Params();
fbe3c2bb   Benjamin Renard   First commit
1007
1008
1009
1010
1011
1012
1013
1014
	}

	//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 ...
1015
	if ((dimOnXSize <= 0) || (dimOnYSize <= 0))
fbe3c2bb   Benjamin Renard   First commit
1016
1017
1018
1019
	{
		LOG4CXX_INFO(gLogger, "InstantPlot::drawSpectro - No data to plot");
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
1020
	MatrixGrid matrixGrid;
7d5239f5   Benjamin Renard   Fix instant plot ...
1021
	for (int i = 0; i < dimOnXSize; ++i)
fbe3c2bb   Benjamin Renard   First commit
1022
1023
	{
		GridPart part;
7d5239f5   Benjamin Renard   Fix instant plot ...
1024
1025
1026
1027
1028
1029
1030
		if (tableOnXSPtr == nullptr)
		{
			//no table defined => use index
			part.x[0] = i;
			part.x[1] = i+1;
		}
		else
fbe3c2bb   Benjamin Renard   First commit
1031
		{
7d5239f5   Benjamin Renard   Fix instant plot ...
1032
			if (!tableOnXSPtr->isVariable(&_parameterManager))
fbe3c2bb   Benjamin Renard   First commit
1033
			{
7d5239f5   Benjamin Renard   Fix instant plot ...
1034
1035
				part.x[0] = tableOnXSPtr->getBound(&_parameterManager, i).min;
				part.x[1] = tableOnXSPtr->getBound(&_parameterManager, i).max;
fbe3c2bb   Benjamin Renard   First commit
1036
1037
1038
			}
			else
			{
7d5239f5   Benjamin Renard   Fix instant plot ...
1039
1040
				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...
1041
				{
7d5239f5   Benjamin Renard   Fix instant plot ...
1042
1043
1044
1045
					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...
1046
					{
7d5239f5   Benjamin Renard   Fix instant plot ...
1047
1048
						double* values = data.getValues(AMDA::Common::ParameterIndexComponent(k), valIdx);
						paramTableValues.push_back((*values));
1c0193a5   Benjamin Renard   Implement variabl...
1049
					}
7d5239f5   Benjamin Renard   Fix instant plot ...
1050
					paramsTableData[it->first] = paramTableValues;
1c0193a5   Benjamin Renard   Implement variabl...
1051
				}
7d5239f5   Benjamin Renard   Fix instant plot ...
1052
1053
				part.x[0] = tableOnXSPtr->getBound(&_parameterManager, i, &paramsTableData).min;
				part.x[1] = tableOnXSPtr->getBound(&_parameterManager, i, &paramsTableData).max;
fbe3c2bb   Benjamin Renard   First commit
1054
1055
			}
		}
7d5239f5   Benjamin Renard   Fix instant plot ...
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

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

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

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

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

5c050d50   Benjamin Renard   Fix another bugs ...
1125
1126
			if (!isNAN(part.value))
				noData = false;
fbe3c2bb   Benjamin Renard   First commit
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
			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...
1157
	lXAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
1158
1159
1160
1161
1162
1163
1164

	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...
1165
	lYAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
1166
1167
1168
1169
1170
1171
1172

	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...
1173
	lZAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
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
1261

	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...
1262
			tableLegendText = tableSPtr->getName(&_parameterManager);
fbe3c2bb   Benjamin Renard   First commit
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
		} 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...
1290
	_panel->_paramsLegendProperties.resetPlot();
fbe3c2bb   Benjamin Renard   First commit
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306

	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
1307
bool InstantPlot::draw(double startTime, double stopTime, int intervalIndex,
fbe3c2bb   Benjamin Renard   First commit
1308
1309
1310
		bool /*isFirstInterval*/, bool /*isLastInterval*/) {
	LOG4CXX_DEBUG(gLogger, "InstantPlot::draw");

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

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

fbe3c2bb   Benjamin Renard   First commit
1316

d57f00dc   Benjamin Renard   Draw NO DATA
1317
	bool noData = true;
ece33d6f   Benjamin Renard   Draw the panel of...
1318
	if (!_originalParamId.empty())
fbe3c2bb   Benjamin Renard   First commit
1319
	{
ece33d6f   Benjamin Renard   Draw the panel of...
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
		//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...
1341
					param, false, noData);
ece33d6f   Benjamin Renard   Draw the panel of...
1342
1343
1344
		}
		else if (_iSpectroProperties != nullptr)
		{
faf4d845   Benjamin Renard   Add common functi...
1345
			drawSpectro(startTime, stopTime, _originalParamId, *_iSpectroProperties, noData);
ece33d6f   Benjamin Renard   Draw the panel of...
1346
1347
		}

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

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

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

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

/**
 * @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...
1387

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

537e3ab0   Benjamin Renard   Fix a bug with In...
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
			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
1405

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

11080d60   Erdogan Furkan   Previous/next but...
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
void InstantPlot::writeContext(ContextFileWriter &writer, AMDA::Parameters::TimeIntervalList::iterator currentTimeInterval)
{
	PanelPlotOutput::writeContext(writer, currentTimeInterval);
	if (!isStandalone())
			return;

		writer.startElement("instantTimeNav");
		writer.addAttribute("prevTime", std::to_string(_prevTime).c_str());
		writer.addAttribute("nextTime", std::to_string(_nextTime).c_str());
		writer.endElement();

}

fbe3c2bb   Benjamin Renard   First commit
1436
} /* namespace plot */