Blame view

src/ParamOutputImpl/Plot/Time/TimePlot.cc 49.3 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/*
 * TimePlot.cc
 *
 *  Created on: 22 nov. 2013
 *      Author: CS
 */

#include "TimePlot.hh"
fbe3c2bb   Benjamin Renard   First commit
9
#include "AxesNode.hh"
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
10
11
#include "AxisLegendManager.hh"
#include "DefaultTimeAxisDecorator.hh"
fbe3c2bb   Benjamin Renard   First commit
12
#include "ParamInfo.hh"
fbe3c2bb   Benjamin Renard   First commit
13
#include "ParamMgr.hh"
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
14
15
16
17
18
19
20
#include "ParamTable.hh"
#include "Parameter.hh"
#include "ParamsNode.hh"
#include "PlPlotUtil.hh"
#include "PlotLogger.hh"
#include "PlotOutput.hh"
#include "Range.hh"
fbe3c2bb   Benjamin Renard   First commit
21
#include "ShadesTools.hh"
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
22
23
24
#include "TickMarkDecorator.hh"
#include "TimeUtil.hh"
#include <cstddef>
fbe3c2bb   Benjamin Renard   First commit
25
#include <fstream>
2acc7d49   Hacene SI HADJ MOHAND   progress
26
#include <limits>
fbe3c2bb   Benjamin Renard   First commit
27

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
28
29
30
#include <sstream>
#include <string>
#include <vector>
fbe3c2bb   Benjamin Renard   First commit
31
32

#include <boost/format.hpp>
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
33
#include <iostream>
fbe3c2bb   Benjamin Renard   First commit
34
35
36
37

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

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
38
39
namespace plot
{
fbe3c2bb   Benjamin Renard   First commit
40

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
41
	QSASConfig *TimePlot::qsasconfig = NULL;
fbe3c2bb   Benjamin Renard   First commit
42

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
43
44
45
46
	TimePlot::TimePlot(AMDA::Parameters::ParameterManager &manager,
					   boost::shared_ptr<Panel> panel, TimeAxisDecorator *timeAxisDecorator, bool isStandalone) : PanelPlotOutput(manager, panel, isStandalone), _startDateDrawn(false)
	{
		setTimeAxisDecorator(std::shared_ptr<TimeAxisDecorator>(timeAxisDecorator));
fbe3c2bb   Benjamin Renard   First commit
47
	}
fbe3c2bb   Benjamin Renard   First commit
48

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
49
50
51
52
53
54
55
	TimePlot::~TimePlot()
	{
		if (qsasconfig != NULL)
		{
			free(qsasconfig);
			qsasconfig = nullptr;
		}
fbe3c2bb   Benjamin Renard   First commit
56
57
	}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
58
59
60
61
62
63
64
65
66
67
68
69
70
	TimeAxis *TimePlot::getTimeAxis()
	{
		std::string lAxisId = getXAxisId();
		boost::shared_ptr<Axis> xAxis = _panel->getAxis(lAxisId);
		if (xAxis.get() == nullptr)
		{
			std::stringstream lError;
			lError << "TimePlot::apply"
				   << ": time axis with id '" << lAxisId << "' not found.";
			BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
		}
		return dynamic_cast<TimeAxis *>(xAxis.get());
	}
fbe3c2bb   Benjamin Renard   First commit
71

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
72
73
74
75
76
77
78
79
80
81
	void TimePlot::preparePlotArea(double startTime, double stopTime, int intervalIndex)
	{
		// dump properties for test
		const char *lBuildType = getenv("BUILD_TYPE");
		if (lBuildType && std::string(lBuildType) == "Debug")
		{
			std::ofstream out("timePlot.txt");
			dump(out);
			out.close();
		}
fbe3c2bb   Benjamin Renard   First commit
82

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
83
84
85
		// Configure Series to draw on axis by checking which color to use and
		// number of series to draw on a same axis.
		configureSeriesAxis();
fbe3c2bb   Benjamin Renard   First commit
86

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
87
		configureAxisLegend();
fbe3c2bb   Benjamin Renard   First commit
88

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
89
		configureSpectroAxis();
fbe3c2bb   Benjamin Renard   First commit
90

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
91
		configureParamsLegend(startTime, stopTime, intervalIndex);
fbe3c2bb   Benjamin Renard   First commit
92

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
93
94
95
96
		// configure X axis
		getTimeAxisDecorator()->configure(this, getTimeAxis(), startTime, stopTime, _pParameterValues);
		getTimeAxis()->_used = true;
		_pls->timefmt(getTimeAxisDecorator()->getPlFormat().c_str());
fbe3c2bb   Benjamin Renard   First commit
97

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
98
99
		PanelPlotOutput::preparePlotArea(startTime, stopTime, intervalIndex);
	}
fbe3c2bb   Benjamin Renard   First commit
100

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
101
102
103
	bool TimePlot::draw(double startTime, double stopTime, int intervalIndex,
						bool isFirstInterval, bool isLastInterval)
	{
fbe3c2bb   Benjamin Renard   First commit
104

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
105
		bool dataPloted = PanelPlotOutput::draw(startTime, stopTime, intervalIndex, isFirstInterval, isLastInterval);
fbe3c2bb   Benjamin Renard   First commit
106

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
107
108
109
110
111
112
		// Draw start date
		if (!_startDateDrawn /*&& getTimeAxis()->_used*/)
			drawStartDate(getTimeAxis(), startTime, stopTime);
		_startDateDrawn = true;
		return dataPloted;
	}
fbe3c2bb   Benjamin Renard   First commit
113

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
114
115
116
117
118
119
	void TimePlot::calculatePlotArea(const Bounds &panelBounds_, Bounds &bounds_)
	{
		PanelPlotOutput::calculatePlotArea(panelBounds_, bounds_);
		// decorator is responsible of reserving extra space for what it manage (labels for instance).
		getTimeAxisDecorator()->updatePlotArea(this, getTimeAxis(), panelBounds_, bounds_);
	}
fbe3c2bb   Benjamin Renard   First commit
120

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
121
122
123
124
125
126
	void TimePlot::configureSeriesAxis()
	{
		// map<YAxisId, userRangeDefined>
		std::map<std::string, Range> lAxisRange;
		Range lColorAxeRange;
		SeriesProperties lSeriesProperties;
fbe3c2bb   Benjamin Renard   First commit
127

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
128
		boost::shared_ptr<ColorAxis> lZAxis = _panel->getColorAxis();
fbe3c2bb   Benjamin Renard   First commit
129

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
		// Parse each parameter to define on which axis to draw series.
		for (auto param : _parameterAxesList)
		{
			// Get number of series to draw
			// For each index of parameter identify to which axis series must be drawn.
			for (auto lSeriesProperties : param.getYSeriePropertiesList())
			{
				if (!lSeriesProperties.hasYAxis())
				{
					continue;
				}
				boost::shared_ptr<Axis> lYAxis = _panel->getAxis(lSeriesProperties.getYAxisId());
				if (lYAxis.get() == nullptr)
				{
					std::stringstream lError;
					lError << "TimePlot::configureSeriesAxis"
						   << ": Y axis with id '" << lSeriesProperties.getYAxisId() << "' not found.";
					BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
				}
fbe3c2bb   Benjamin Renard   First commit
149

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
150
151
152
153
154
155
156
157
158
159
				lYAxis->_used = true;
				Range lYAxisRequestRange = lYAxis->Axis::getRequestedRange();
				Range lRange = lYAxis->Axis::getRange();
				// If range status for this axis is set by the user do not update range "automatically".
				if (isnan(lYAxisRequestRange.getMin()) && isnan(lYAxisRequestRange.getMax()))
				{
					Range lEstimatedRange(lAxisRange[lYAxis->_id]);
					for (auto index : lSeriesProperties.getIndexList(_pParameterValues))
					{
						Range lParamIndexRange(
2fc1f2f8   Benjamin Renard   Full rework for s...
160
161
162
							(*_pParameterValues)[lSeriesProperties.getParamId()].getMin(index),
							(*_pParameterValues)[lSeriesProperties.getParamId()].getMax(index));

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
163
						ErrorBarProperties &errBarProp = lSeriesProperties.getErrorBarProperties();
2fc1f2f8   Benjamin Renard   Full rework for s...
164

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
165
166
167
168
						// Update lParamIndexRange depending on the use of ErrorBars on the plot
						if (errBarProp.getErrorMinMax() != nullptr)
						{
							Range lParamMinRange(
2fc1f2f8   Benjamin Renard   Full rework for s...
169
170
								(*_pParameterValues)[errBarProp.getErrorMinMax()->getUsedParamMin()].getMin(-1),
								(*_pParameterValues)[errBarProp.getErrorMinMax()->getUsedParamMin()].getMax(-1));
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
171
							Range lParamMaxRange(
2fc1f2f8   Benjamin Renard   Full rework for s...
172
173
174
								(*_pParameterValues)[errBarProp.getErrorMinMax()->getUsedParamMax()].getMin(-1),
								(*_pParameterValues)[errBarProp.getErrorMinMax()->getUsedParamMax()].getMax(-1));

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
175
176
177
178
							if (lParamMinRange.getMin() < lParamIndexRange.getMin())
								lParamIndexRange.setMin(lParamMinRange.getMin());
							if (lParamMinRange.getMax() > lParamIndexRange.getMax())
								lParamIndexRange.setMax(lParamMinRange.getMax());
2fc1f2f8   Benjamin Renard   Full rework for s...
179

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
180
181
182
183
184
							if (lParamMaxRange.getMin() < lParamIndexRange.getMin())
								lParamIndexRange.setMin(lParamMaxRange.getMin());
							if (lParamMaxRange.getMax() > lParamIndexRange.getMax())
								lParamIndexRange.setMax(lParamMaxRange.getMax());
						}
fbe3c2bb   Benjamin Renard   First commit
185

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
186
187
188
189
190
191
192
193
194
195
196
197
						if (isnan(lEstimatedRange.getMin()) && isnan(lEstimatedRange.getMax()))
						{
							lEstimatedRange.setMin(lParamIndexRange.getMin());
							lEstimatedRange.setMax(lParamIndexRange.getMax());
						}
						else
						{
							lEstimatedRange.setMin(std::min(lEstimatedRange.getMin(), lParamIndexRange.getMin()));
							lEstimatedRange.setMax(std::max(lEstimatedRange.getMax(), lParamIndexRange.getMax()));
						}
						if (lParamIndexRange.getMin() == lParamIndexRange.getMax())
							lEstimatedRange.setMargin(0.05);
2fc1f2f8   Benjamin Renard   Full rework for s...
198
					}
e062d6ef   Benjamin Renard   Fix axes range wh...
199

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
200
					lEstimatedRange._extend = lRange._extend;
641ba7e4   Hacene SI HADJ MOHAND   ok for time plot
201

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
202
203
					lAxisRange[lYAxis->_id] = lEstimatedRange;
				}
fbe3c2bb   Benjamin Renard   First commit
204

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
205
206
				// Set ZAxis range if a color param is defined for this serie
				if (lZAxis != nullptr)
fbe3c2bb   Benjamin Renard   First commit
207
				{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
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
					if (!lSeriesProperties.getColorParamId().empty())
					{
						lZAxis->_used = true;
						Range lRange(lZAxis->getRange());
						ParameterAxes *colorSerieParameterAxes = getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
						if (colorSerieParameterAxes == NULL)
							continue;
						ColorSeriesProperties &colorSerieProp = colorSerieParameterAxes->getColorSeriePropertiesById(lSeriesProperties.getColorSerieId());
						// If range status for this axis is set by the user do not update range "automatically".
						if (isnan(lRange.getMin()) && isnan(lRange.getMax()))
						{
							Range lEstimatedRange(lColorAxeRange);
							Range lParamIndexRange(
								(*_pParameterValues)[lSeriesProperties.getColorParamId()].getMin(
									colorSerieProp.getIndex()),
								(*_pParameterValues)[lSeriesProperties.getColorParamId()].getMax(
									colorSerieProp.getIndex()));

							if (isnan(lEstimatedRange.getMin()) && isnan(lEstimatedRange.getMax()))
							{
								lEstimatedRange.setMin(lParamIndexRange.getMin());
								lEstimatedRange.setMax(lParamIndexRange.getMax());
							}
							else
							{
								lEstimatedRange.setMin(std::min(lEstimatedRange.getMin(), lParamIndexRange.getMin()));
								lEstimatedRange.setMax(std::max(lEstimatedRange.getMax(), lParamIndexRange.getMax()));
							}
							if (lParamIndexRange.getMin() == lParamIndexRange.getMax())
								lEstimatedRange.setMargin(0.05);
							lEstimatedRange._extend = lRange._extend;
							lColorAxeRange = lEstimatedRange;
fbe3c2bb   Benjamin Renard   First commit
240
						}
fbe3c2bb   Benjamin Renard   First commit
241
242
243
244
					}
				}
			}
		}
fbe3c2bb   Benjamin Renard   First commit
245

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
246
247
248
249
250
251
252
253
		// Update range of axis. Done after because, axis range may be processed in several pass (one for each series)
		for (auto lAxis : lAxisRange)
		{
			boost::shared_ptr<Axis> lYAxis = _panel->getAxis(lAxis.first);
			Range lRange(lAxis.second);
			fixRange(lRange, lYAxis->_scale == Axis::Scale::LOGARITHMIC);
			lYAxis->setRange(lRange);
		}
fbe3c2bb   Benjamin Renard   First commit
254

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
255
256
257
258
259
		if (lZAxis != nullptr && lColorAxeRange.isSet())
		{
			fixRange(lColorAxeRange, lZAxis->_scale == Axis::Scale::LOGARITHMIC);
			lZAxis->setRange(lColorAxeRange);
		}
5c050d50   Benjamin Renard   Fix another bugs ...
260
	}
fbe3c2bb   Benjamin Renard   First commit
261

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
262
263
264
265
266
	void TimePlot::configureAxisLegend()
	{
		// Y axis
		AxisLegendManager::configureYAxisLegendForSpectro(this);
		AxisLegendManager::configureYAxisLegendForSeries(this);
fbe3c2bb   Benjamin Renard   First commit
267

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
268
269
270
271
		// Z axis
		AxisLegendManager::configureColorAxisLegendForSpectro(this);
		AxisLegendManager::configureColorAxisLegendForSeries(this);
	}
fbe3c2bb   Benjamin Renard   First commit
272

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
273
274
	void TimePlot::configureSpectroAxis()
	{
fbe3c2bb   Benjamin Renard   First commit
275
		// Parse each parameter to define on which axis to draw spectro
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
276
277
278
279
280
		for (auto param : _parameterAxesList)
		{
			std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
			if (spectroPropertiesPtr == nullptr)
				continue; //no spectro defined
08ec1dde   Benjamin Renard   Add propertie _us...
281

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
282
283
			if (!spectroPropertiesPtr->hasYAxis())
				continue;
fbe3c2bb   Benjamin Renard   First commit
284

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
285
286
287
288
289
290
291
292
293
			LOG4CXX_DEBUG(gLogger, "Spectro Y axis is " << spectroPropertiesPtr->getYAxisId());
			boost::shared_ptr<Axis> lYAxis = _panel->getAxis(spectroPropertiesPtr->getYAxisId());
			if (lYAxis.get() == nullptr)
			{
				std::stringstream lError;
				lError << "TimePlot::configureSpectroAxis"
					   << ": Y axis with id '" << spectroPropertiesPtr->getYAxisId() << "' not found.";
				BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
			}
966af096   Benjamin Renard   Fix 'sum in range...
294

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
295
			lYAxis->_used = true;
fbe3c2bb   Benjamin Renard   First commit
296

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
297
298
299
			//set Z axis range
			boost::shared_ptr<Axis> lZAxis = _panel->getAxis(spectroPropertiesPtr->getZAxisId());
			if (lZAxis.get() == nullptr)
fbe3c2bb   Benjamin Renard   First commit
300
			{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
301
302
303
304
				std::stringstream lError;
				lError << "TimePlot::configureSpectroAxis"
					   << ": Z axis with id '" << spectroPropertiesPtr->getZAxisId() << "' not found.";
				BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
fbe3c2bb   Benjamin Renard   First commit
305
			}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
306
307
308
309
310
311
312

			lZAxis->_used = true;

			ParameterSPtr p = _parameterManager.getParameter(param._originalParamId);
			int parameterDimension;
			if (spectroPropertiesPtr->getRelatedDim() == 0)
				parameterDimension = (*_pParameterValues)[spectroPropertiesPtr->getParamId()].getDim1Size();
fbe3c2bb   Benjamin Renard   First commit
313
			else
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
314
315
316
317
318
				parameterDimension = (*_pParameterValues)[spectroPropertiesPtr->getParamId()].getDim2Size();

			//set Y axis range
			Range lYAxisRequestRange = lYAxis->Axis::getRequestedRange();
			Range lYAxisRange = lYAxis->Axis::getRange();
f3cd5351   Hacene SI HADJ MOHAND   us ok
319
                        
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
320
			AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
f3cd5351   Hacene SI HADJ MOHAND   us ok
321
322
323
                        
                                                            
                                                            
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
324
			if (isnan(lYAxisRequestRange.getMin()) && isnan(lYAxisRequestRange.getMax()))
fbe3c2bb   Benjamin Renard   First commit
325
			{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
326
327
328
				boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
				if (paramInfo != nullptr)
					tableSPtr = paramInfo->getTable(spectroPropertiesPtr->getRelatedDim());
f3cd5351   Hacene SI HADJ MOHAND   us ok
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
                                                                                 
                                                                                if (tableSPtr == nullptr){
                                                                                    boost::shared_ptr<AMDA::Info::ParamTable> linkedTableSPtr;
                                                                                    int counter = 0;
                                                                                    // work on this 
                                                                                    for (auto pInfo :paramInfo->getLinkedParamList()){
                                                                                        linkedTableSPtr = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(pInfo)->getTable(spectroPropertiesPtr->getRelatedDim());
                                                                                        if (linkedTableSPtr == nullptr)
                                                                                            continue;
                                                                                        counter ++;
                                                                                    }
                                                                                    if(linkedTableSPtr == nullptr || counter !=1){
                                                                                        LOG4CXX_DEBUG(gLogger, "table cannot be defined from linked info params");
                                                                                    }else{
                                                                                        tableSPtr = linkedTableSPtr;
                                                                                    }
                                                                                }
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
346
347

				if (tableSPtr == nullptr)
fbe3c2bb   Benjamin Renard   First commit
348
				{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
349
350
351
					LOG4CXX_DEBUG(gLogger, "No table defined => use index");
					lYAxisRange.setMin(std::min(0., lYAxisRange.getMin()));
					lYAxisRange.setMax(std::max((double)parameterDimension, lYAxisRange.getMax()));
f2db3c16   Benjamin Renard   Support variable ...
352
353
354
				}
				else
				{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
355
356
					AMDA::Info::t_TableBound crtBound;
					if (!tableSPtr->isVariable(&_parameterManager))
f2db3c16   Benjamin Renard   Support variable ...
357
					{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
358
						for (int i = 0; i < parameterDimension; ++i)
f2db3c16   Benjamin Renard   Support variable ...
359
						{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
360
							crtBound = tableSPtr->getBound(&_parameterManager, i);
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
361
362
363
							if (!std::isnan(crtBound.min))
							{
								if (!((lYAxis->_scale == Axis::Scale::LOGARITHMIC) && (crtBound.min <= 0)))
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
364
									lYAxisRange.setMin(std::min(crtBound.min, lYAxisRange.getMin()));
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
365
366
367
368
							}
							if (!std::isnan(crtBound.max))
							{
								if (!((lYAxis->_scale == Axis::Scale::LOGARITHMIC) && (crtBound.max <= 0)))
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
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
									lYAxisRange.setMax(std::max(crtBound.max, lYAxisRange.getMax()));
							}
						}
					}
					else
					{
						//Variable table => we need to loop under all records to find axis min & max values
						for (int i = 0; i < (*_pParameterValues)[spectroPropertiesPtr->getParamId()].getSize(); ++i)
						{
							std::map<std::string, std::vector<double>> paramsTableData;
							for (std::map<std::string, std::string>::iterator it = spectroPropertiesPtr->getTableParams().begin(); it != spectroPropertiesPtr->getTableParams().end(); ++it)
							{
								ParameterData &data = (*_pParameterValues)[it->second];
								std::vector<double> paramTableValues;
								for (int j = 0; j < data.getDim1Size(); ++j)
								{
									if (i < data.getSize())
									{
										double *values = data.getValues(AMDA::Common::ParameterIndexComponent(j), i);
										paramTableValues.push_back((*values));
									}
								}
								paramsTableData[it->first] = paramTableValues;
							}
							for (int j = 0; j < parameterDimension; ++j)
							{
								crtBound = tableSPtr->getBound(&_parameterManager, j, &paramsTableData);
								if (!std::isnan(crtBound.min))
								{
									if (!((lYAxis->_scale == Axis::Scale::LOGARITHMIC) && (crtBound.min <= 0)))
										lYAxisRange.setMin(std::min(crtBound.min, lYAxisRange.getMin()));
								}
								if (!std::isnan(crtBound.max))
								{
									if (!((lYAxis->_scale == Axis::Scale::LOGARITHMIC) && (crtBound.max <= 0)))
										lYAxisRange.setMax(std::max(crtBound.max, lYAxisRange.getMax()));
								}
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
406
							}
f2db3c16   Benjamin Renard   Support variable ...
407
408
						}
					}
fbe3c2bb   Benjamin Renard   First commit
409
				}
fbe3c2bb   Benjamin Renard   First commit
410
			}
fbe3c2bb   Benjamin Renard   First commit
411

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
412
413
			//do not extend the axis
			lYAxisRange._extend = false;
fbe3c2bb   Benjamin Renard   First commit
414

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
415
			fixRange(lYAxisRange, lYAxis->_scale == Axis::Scale::LOGARITHMIC);
fbe3c2bb   Benjamin Renard   First commit
416

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
417
418
419
420
421
422
423
424
425
426
427
428
429
			lYAxis->setRange(lYAxisRange);

			LOG4CXX_DEBUG(gLogger, "Y axis range : min = " << lYAxisRange.getMin() << ", max = " << lYAxisRange.getMax());

			Range lParamRange = lZAxis->Axis::getRange();
			if (isnan(lParamRange.getMin()) && isnan(lParamRange.getMax()))
			{
				std::string normalization = spectroPropertiesPtr->getNormalization();
				if (normalization == "log" || normalization == "linear")
				{
					lParamRange.setMin(0);
					lParamRange.setMax(1);
				}
fbe3c2bb   Benjamin Renard   First commit
430
				else
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
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
				{
					//auto range
					for (auto index : spectroPropertiesPtr->getIndexes())
					{
						//compute global range for all indexes
						double minVal, maxVal;
						if (lZAxis->_scale == Axis::Scale::LOGARITHMIC)
							minVal = (*_pParameterValues)[spectroPropertiesPtr->getParamId()].getMinStrictPos(index);
						else
							minVal = (*_pParameterValues)[spectroPropertiesPtr->getParamId()].getMin(index);
						maxVal = (*_pParameterValues)[spectroPropertiesPtr->getParamId()].getMax(index);
						if (!isnan(minVal))
							lParamRange.setMin(std::min(minVal, lParamRange.getMin()));
						//else
						//	lParamRange.setMin(0);
						if (!isnan(maxVal))
							lParamRange.setMax(std::max(maxVal, lParamRange.getMax()));
						//else
						//	lParamRange.setMax(10);
					}
					if (isnan(lParamRange.getMin()))
						lParamRange.setMin(0);
					if (isnan(lParamRange.getMax()))
						lParamRange.setMax(10);
				}
fbe3c2bb   Benjamin Renard   First commit
456
			}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
457
458
			else
				lParamRange._extend = false;
fbe3c2bb   Benjamin Renard   First commit
459

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
460
461
462
463
464
			//set z axis range
			fixRange(lParamRange, lZAxis->_scale == Axis::Scale::LOGARITHMIC);
			LOG4CXX_DEBUG(gLogger, "ZAxis range : ZMin = " << lParamRange.getMin() << ", ZMax = " << lParamRange.getMax());
			lZAxis->setRange(lParamRange);
		}
fbe3c2bb   Benjamin Renard   First commit
465
	}
fbe3c2bb   Benjamin Renard   First commit
466

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
467
	/**
fbe3c2bb   Benjamin Renard   First commit
468
469
470
 * @brief Identify if other side of the plot area need to be drawn or not.
 * @note A plot area side need to be drawn when there is no axis associated to it.
 */
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
	std::string TimePlot::drawOppositeSide(boost::shared_ptr<Axis> pAxis)
	{
		if (pAxis.get() == getTimeAxis() && getTimeAxis()->isOnlyTickmarks())
		{
			return "";
		}
		else
		{
			return PanelPlotOutput::drawOppositeSide(pAxis);
		}
	}

	void TimePlot::drawXAxis(boost::shared_ptr<Axis> pXAxis, PlWindow &pPlWindow, Bounds &pPlotAreaSize, TickConf &pTickConf)
	{
		LOG4CXX_DEBUG(gLogger, "Drawing X axis ");
		// draw main axis...
		PanelPlotOutput::drawXAxis(pXAxis, pPlWindow, pPlotAreaSize, pTickConf);
		// delegate to decorator any extra drawing stuff it needs to perform...
		getTimeAxisDecorator()->draw(this, getTimeAxis(), _pls);
fbe3c2bb   Benjamin Renard   First commit
490
	}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
491
492
493
494
495

	// Convert an X axis string value to a double X value assuming it's a DD_Time value
	double TimePlot::convertXAxisValue(const std::string &value)
	{
		return DD_Time2Double(value.c_str());
fbe3c2bb   Benjamin Renard   First commit
496
497
	}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
	ConstantLine *TimePlot::getConstantLineFromId(int serieId, int constantId, boost::shared_ptr<Axis> &yAxis)
	{
		for (auto parameter : _parameterAxesList)
		{
			for (auto serieProperties : parameter.getYSeriePropertiesList())
			{
				if ((serieProperties.getId() == serieId) && (serieProperties.hasYAxis() == true))
				{
					yAxis = _panel->getAxis(serieProperties.getYAxisId());
					for (auto constantLine : yAxis->_constantLines)
					{
						if (constantLine->getId() == constantId)
						{
							return constantLine.get();
						}
fbe3c2bb   Benjamin Renard   First commit
513
514
515
516
					}
				}
			}
		}
fbe3c2bb   Benjamin Renard   First commit
517

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
518
519
520
521
522
523
		// ConstantId not found, we throw an exception
		std::stringstream lError;
		lError << "TimePlot::getConstantLineFromId : Unable to find constantId='" << constantId << "' for serieId='" << serieId << "'";
		BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
		return NULL;
	}
fbe3c2bb   Benjamin Renard   First commit
524

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
525
526
527
528
529
530
531
532
533
534
535
	bool TimePlot::getSeriePropertiesById(int serieId, SeriesProperties &rSerieProperties)
	{
		for (auto parameter : _parameterAxesList)
		{
			for (auto serieProperties : parameter.getYSeriePropertiesList())
			{
				if (serieProperties.getId() == serieId)
				{
					rSerieProperties = serieProperties;
					return true;
				}
fbe3c2bb   Benjamin Renard   First commit
536
537
			}
		}
fbe3c2bb   Benjamin Renard   First commit
538

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
539
540
		return false;
	}
fbe3c2bb   Benjamin Renard   First commit
541

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
542
	void TimePlot::mergeAndSortTime(double *values1Time, int values1Nb,
fbe3c2bb   Benjamin Renard   First commit
543
									double *values2Time, int values2Nb,
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
544
545
									std::vector<double> &valuesTime)
	{
fbe3c2bb   Benjamin Renard   First commit
546

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
547
548
549
		// Build 2 vectors
		std::vector<double> v1(values1Time, values1Time + values1Nb);
		std::vector<double> v2(values2Time, values2Time + values2Nb);
fbe3c2bb   Benjamin Renard   First commit
550

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
551
552
553
		// Populate resulting vector
		valuesTime.insert(valuesTime.end(), v1.begin(), v1.end());
		valuesTime.insert(valuesTime.end(), v2.begin(), v2.end());
fbe3c2bb   Benjamin Renard   First commit
554

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
555
556
557
		// Sort and remove duplicates for the resulting vector
		sort(valuesTime.begin(), valuesTime.end());
		valuesTime.erase(unique(valuesTime.begin(), valuesTime.end()), valuesTime.end());
fbe3c2bb   Benjamin Renard   First commit
558
559
	}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
560
561
	double TimePlot::getInterpolatedValue(double *values, double *valuesTime, int valuesNb, double atTime)
	{
fbe3c2bb   Benjamin Renard   First commit
562

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
563
564
565
566
		// get index of first time after given time_
		if (isnan(atTime))
		{
			return nan("");
fbe3c2bb   Benjamin Renard   First commit
567
		}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
568
569
570
571
572
573
574
575
576

		double *pTime = valuesTime;

		for (int t = 0; t < valuesNb; t++)
		{
			// No interpolation required
			if (*pTime == atTime)
			{
				return values[t];
fbe3c2bb   Benjamin Renard   First commit
577
			}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
			// Interpolation required
			if (*pTime >= atTime)
			{
				if (t == 0)
				{
					return nan("");
				}
				else
				{
					double v1 = values[t - 1];
					double v2 = values[t];
					double d1 = valuesTime[t - 1];
					double d2 = valuesTime[t];
					// Return a linear interpolation of the value for the index
					return (v1 + (v2 - v1) * (atTime - d1) / (d2 - d1));
				}
fbe3c2bb   Benjamin Renard   First commit
594
			}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
595
			pTime++;
fbe3c2bb   Benjamin Renard   First commit
596
		}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
597
		return nan("");
fbe3c2bb   Benjamin Renard   First commit
598
	}
fbe3c2bb   Benjamin Renard   First commit
599

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
600
601
602
603
	bool TimePlot::intersect(double xi, double y1i, double y2i,
							 double xj, double y1j, double y2j,
							 double *xInter)
	{
fbe3c2bb   Benjamin Renard   First commit
604

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
605
606
607
608
609
		// Simply checks if segment are above or below the other
		if (((y1i >= y2i) && (y1j >= y2j)) || ((y1i <= y2i) && (y1j <= y2j)))
		{
			return false;
		}
fbe3c2bb   Benjamin Renard   First commit
610

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
611
612
613
614
		// 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;
fbe3c2bb   Benjamin Renard   First commit
615

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
616
617
		double a2 = (y2j - y2i) / (xj - xi);
		double b2 = y2i - a2 * xi;
fbe3c2bb   Benjamin Renard   First commit
618

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
619
620
		// Compute intersection point (a1*x+b1 = a2*x+b2)
		*xInter = (b2 - b1) / (a1 - a2);
fbe3c2bb   Benjamin Renard   First commit
621

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
622
623
		return true;
	}
fbe3c2bb   Benjamin Renard   First commit
624

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
625
626
627
628
	void TimePlot::addIntersectionTime(double *values1, double *values1Time, int values1Nb,
									   double *values2, double *values2Time, int values2Nb,
									   std::vector<double> &valuesTime)
	{
fbe3c2bb   Benjamin Renard   First commit
629

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
630
631
		if (valuesTime.empty() == true)
			return;
fbe3c2bb   Benjamin Renard   First commit
632

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
633
634
		// For each time segment compute intersection if it exists
		std::vector<double> intersectionTime;
fbe3c2bb   Benjamin Renard   First commit
635

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
636
637
638
		double xi = valuesTime[0];
		double y1i = getInterpolatedValue(values1, values1Time, values1Nb, xi);
		double y2i = getInterpolatedValue(values2, values2Time, values2Nb, xi);
fbe3c2bb   Benjamin Renard   First commit
639

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
640
641
642
643
644
		for (size_t t = 1; t < valuesTime.size(); t++)
		{
			double xj = valuesTime[t];
			double y1j = getInterpolatedValue(values1, values1Time, values1Nb, xj);
			double y2j = getInterpolatedValue(values2, values2Time, values2Nb, xj);
fbe3c2bb   Benjamin Renard   First commit
645

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
646
647
648
649
650
			double xInter;
			if (intersect(xi, y1i, y2i, xj, y1j, y2j, &xInter) == true)
			{
				intersectionTime.push_back(xInter);
			}
fbe3c2bb   Benjamin Renard   First commit
651

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
652
653
654
655
656
			// Next vector element
			xi = xj;
			y1i = y1j;
			y2i = y2j;
		}
fbe3c2bb   Benjamin Renard   First commit
657

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
658
659
		// Add intersections informations to the resulting values
		valuesTime.insert(valuesTime.end(), intersectionTime.begin(), intersectionTime.end());
fbe3c2bb   Benjamin Renard   First commit
660

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
661
662
663
664
		// Sort and remove duplicates for the resulting vector
		sort(valuesTime.begin(), valuesTime.end());
		valuesTime.erase(unique(valuesTime.begin(), valuesTime.end()), valuesTime.end());
	}
fbe3c2bb   Benjamin Renard   First commit
665

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
666
	void TimePlot::drawFillArea(double *values1, double *values1Time, int values1Nb,
fbe3c2bb   Benjamin Renard   First commit
667
668
								double *values2, double *values2Time, int values2Nb,
								std::vector<double> &valuesTime,
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
669
670
671
672
673
674
675
								bool colorGreaterSpecified, Color &colorGreater,
								bool colorLessSpecified, Color &colorLess,
								SeriesProperties &rSeriesProperties)
	{
		// Get X and Y axis.
		boost::shared_ptr<Axis> lXAxis(_panel->getAxis(rSeriesProperties.getXAxisId()));
		boost::shared_ptr<Axis> lYAxis(_panel->getAxis(rSeriesProperties.getYAxisId()));
fbe3c2bb   Benjamin Renard   First commit
676

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
677
678
		Range lXRange = getXAxisRange(rSeriesProperties, lXAxis);
		Range lYRange = getYAxisRange(rSeriesProperties, lYAxis);
fbe3c2bb   Benjamin Renard   First commit
679

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
680
		_pls->wind(lXRange.getMin(), lXRange.getMax(), lYRange.getMin(), lYRange.getMax());
fbe3c2bb   Benjamin Renard   First commit
681

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
682
683
684
		PLFLT x[4], y[4], deltai, deltaj;
		Color curColor;
		Color lInitialColor = changeColor(_pls, colorGreater, _panel->_page->_mode);
fbe3c2bb   Benjamin Renard   First commit
685

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
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
		for (size_t i = 0; i < (valuesTime.size() - 1); i++)
		{
			x[0] = valuesTime[i];
			x[1] = x[0];
			x[2] = valuesTime[i + 1];
			x[3] = x[2];

			y[0] = getInterpolatedValue(values1, values1Time, values1Nb, valuesTime[i]);
			y[1] = getInterpolatedValue(values2, values2Time, values2Nb, valuesTime[i]);
			y[2] = getInterpolatedValue(values2, values2Time, values2Nb, valuesTime[i + 1]);
			y[3] = getInterpolatedValue(values1, values1Time, values1Nb, valuesTime[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;
				}
fbe3c2bb   Benjamin Renard   First commit
714
			}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
			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
fbe3c2bb   Benjamin Renard   First commit
731
732
				continue;
			}
fbe3c2bb   Benjamin Renard   First commit
733

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
734
735
736
737
			// Fill polygon using the given color
			changeColor(_pls, curColor, _panel->_page->_mode);
			_pls->fill(4, x, y);
		}
fbe3c2bb   Benjamin Renard   First commit
738

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
739
740
741
		// Restore color.
		restoreColor(_pls, lInitialColor, _panel->_page->_mode);
	}
fbe3c2bb   Benjamin Renard   First commit
742

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
743
744
745
746
	void TimePlot::drawFills(double startDate, double stopDate)
	{
		PanelPlotOutput::drawFills(startDate, stopDate);
		LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills");
fbe3c2bb   Benjamin Renard   First commit
747

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
748
		SeriesProperties rSeriesProperties;
fbe3c2bb   Benjamin Renard   First commit
749

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
750
751
752
		double *values1 = NULL;
		double *values1Time = NULL;
		int values1Nb = 0;
fbe3c2bb   Benjamin Renard   First commit
753

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
754
755
756
		double *values2 = NULL;
		double *values2Time = NULL;
		int values2Nb = 0;
fbe3c2bb   Benjamin Renard   First commit
757

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
758
		std::vector<double> valuesTime;
fbe3c2bb   Benjamin Renard   First commit
759

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
760
761
		// Drawing Fill Area located between Serie and Constant (horizontal) line
		for (auto fillSerieConstant : _panel->_fillSerieConstants)
fbe3c2bb   Benjamin Renard   First commit
762
		{
fbe3c2bb   Benjamin Renard   First commit
763

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
764
765
766
767
768
769
			// Retrieve serie parameter values for serieId
			if (!getSeriePropertiesById(fillSerieConstant->getSerieId(), rSeriesProperties))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills - Cannot find serie id " << fillSerieConstant->getSerieId());
				continue;
			}
e7b3586a   Benjamin Renard   Fix fill between ...
770

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
771
772
773
774
775
776
777
			//get computed values for this serie and interval
			if (!getComputedValuesFromSerieAndInterval(startDate, stopDate, rSeriesProperties,
													   rSeriesProperties.getIndex(), &values1, &values1Time, values1Nb))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills - Cannot get computed values for serie id " << fillSerieConstant->getSerieId());
				continue;
			}
e7b3586a   Benjamin Renard   Fix fill between ...
778

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
779
780
781
			// Retrieve constantLine informations for these fill
			boost::shared_ptr<Axis> yAxis;
			ConstantLine *constantLine = getConstantLineFromId(fillSerieConstant->getSerieId(), fillSerieConstant->getConstantId(), yAxis);
fbe3c2bb   Benjamin Renard   First commit
782

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
783
			// Retrieve axis attachment
fbe3c2bb   Benjamin Renard   First commit
784

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
785
786
787
			// Build values2 values2Time array with 2 values : yConst & (first time, last time) for serie
			values2 = new double[2];
			values2Time = new double[2];
fbe3c2bb   Benjamin Renard   First commit
788

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
789
790
			values2[0] = convertYAxisValue(constantLine->getValue());
			values2[1] = convertYAxisValue(constantLine->getValue());
e7b3586a   Benjamin Renard   Fix fill between ...
791

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
792
793
794
795
796
			if (yAxis->_scale == Axis::Scale::LOGARITHMIC)
			{
				values2[0] = log10(values2[0]);
				values2[1] = log10(values2[1]);
			}
fbe3c2bb   Benjamin Renard   First commit
797

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
798
799
			values2Time[0] = values1Time[0];
			values2Time[1] = values1Time[values1Nb - 1];
fbe3c2bb   Benjamin Renard   First commit
800

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
801
			values2Nb = 2;
fbe3c2bb   Benjamin Renard   First commit
802

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
803
804
805
806
807
808
809
			// Build time vector by merging existing times and computing intersections, and draw it !
			mergeAndSortTime(values1Time, values1Nb, values2Time, values2Nb, valuesTime);
			addIntersectionTime(values1, values1Time, values1Nb, values2, values2Time, values2Nb, valuesTime);
			drawFillArea(values1, values1Time, values1Nb, values2, values2Time, values2Nb, valuesTime,
						 fillSerieConstant->isColorGreaterSpecified(), fillSerieConstant->getColorGreater(),
						 fillSerieConstant->isColorLessSpecified(), fillSerieConstant->getColorLess(),
						 rSeriesProperties);
fbe3c2bb   Benjamin Renard   First commit
810

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
811
812
813
			delete[] values1;
			delete[] values2;
			delete[] values2Time;
fbe3c2bb   Benjamin Renard   First commit
814
815
		}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
816
817
		// Drawing Fill Area located between first and second Serie
		for (auto fillSerieSerie : _panel->_fillSerieSeries)
fbe3c2bb   Benjamin Renard   First commit
818
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
819
820
821
822
823
824
			// Retrieve serie parameter values for firstSerieId
			if (!getSeriePropertiesById(fillSerieSerie->getFirstSerieId(), rSeriesProperties))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills - Cannot find serie id " << fillSerieSerie->getFirstSerieId());
				continue;
			}
fbe3c2bb   Benjamin Renard   First commit
825

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
826
827
828
829
830
831
832
			//get computed values for this serie and interval
			if (!getComputedValuesFromSerieAndInterval(startDate, stopDate, rSeriesProperties,
													   rSeriesProperties.getIndex(), &values1, &values1Time, values1Nb))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills - Cannot get computed values for serie id " << fillSerieSerie->getFirstSerieId());
				continue;
			}
fbe3c2bb   Benjamin Renard   First commit
833

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
834
835
836
837
838
839
			// Retrieve serie parameter values for secondSerieId
			if (!getSeriePropertiesById(fillSerieSerie->getSecondSerieId(), rSeriesProperties))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills - Cannot find serie id " << fillSerieSerie->getSecondSerieId());
				continue;
			}
fbe3c2bb   Benjamin Renard   First commit
840

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
841
842
843
844
845
846
847
			//get computed values for this serie and interval
			if (!getComputedValuesFromSerieAndInterval(startDate, stopDate, rSeriesProperties,
													   rSeriesProperties.getIndex(), &values2, &values2Time, values2Nb))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawFills - Cannot get computed values for serie id " << fillSerieSerie->getSecondSerieId());
				continue;
			}
fbe3c2bb   Benjamin Renard   First commit
848

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
849
850
851
852
853
854
855
			// Build time vector by merging existing times and computing intersections, and draw it !
			mergeAndSortTime(values1Time, values1Nb, values2Time, values2Nb, valuesTime);
			addIntersectionTime(values1, values1Time, values1Nb, values2, values2Time, values2Nb, valuesTime);
			drawFillArea(values1, values1Time, values1Nb, values2, values2Time, values2Nb, valuesTime,
						 fillSerieSerie->isColorGreaterSpecified(), fillSerieSerie->getColorGreater(),
						 fillSerieSerie->isColorLessSpecified(), fillSerieSerie->getColorLess(),
						 rSeriesProperties);
fbe3c2bb   Benjamin Renard   First commit
856

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
857
858
859
860
			delete[] values1;
			delete[] values2;
		}
	}
fbe3c2bb   Benjamin Renard   First commit
861

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
862
863
864
865
866
867
868
869
	void TimePlot::drawSeries(double startDate, double stopDate, int intervalIndex,
							  std::string pParamId, SeriesProperties &pSeries,
							  AMDA::Common::ParameterIndexComponent pParamIndex,
							  ParameterAxes &param, bool moreThanOneSerieForAxis)
	{
		LOG4CXX_DEBUG(gLogger, "TimePlot::drawSeries - Drawing serie for parameter " << pParamId << "[" << pParamIndex.getDim1Index() << "," << pParamIndex.getDim2Index() << "]");
		// This will configure window, draw axes (if needed) and legend of axes.
		PanelPlotOutput::drawSeries(startDate, stopDate, intervalIndex, pParamId, pSeries, pParamIndex, param, moreThanOneSerieForAxis);
fbe3c2bb   Benjamin Renard   First commit
870

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
871
872
		if (!pSeries.hasYAxis())
			return;
fbe3c2bb   Benjamin Renard   First commit
873

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
874
875
876
877
		// Y axis may be missing (tickplot for example)
		std::string yAxisId = pSeries.getYAxisId();
		if (yAxisId.empty())
			return;
fbe3c2bb   Benjamin Renard   First commit
878

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
879
880
881
882
883
884
		//get computed values
		double *computedValues = NULL;
		double *timeValues = NULL;
		int nbValues;
		if (!getComputedValuesFromSerieAndInterval(startDate, stopDate, pSeries, pParamIndex,
												   &computedValues, &timeValues, nbValues))
fbe3c2bb   Benjamin Renard   First commit
885
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
886
			LOG4CXX_DEBUG(gLogger, "TimePlot::drawSeries - Cannot get computed values for serie");
fbe3c2bb   Benjamin Renard   First commit
887
888
			return;
		}
fbe3c2bb   Benjamin Renard   First commit
889

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
		double *coloredComputedValues = NULL;
		double *coloredTimeValues = NULL;
		//get colored value if needed
		if (!pSeries.getColorParamId().empty() && (_panel->getColorAxis() != nullptr))
		{
			int nbColoredValues;
			if (!getColoredComputedValuesFromSerieAndInterval(startDate, stopDate, pSeries,
															  &coloredComputedValues, &coloredTimeValues, nbColoredValues))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawSeries - Cannot get computed values for colored parameter");
				return;
			}
		}

		PlWindow lPlWindow = PlWindow(getTimeAxis()->getRange().getMin(), getTimeAxis()->getRange().getMax(),
									  _panel->getAxis(yAxisId)->getRange().getMin(), _panel->getAxis(yAxisId)->getRange().getMax());
fbe3c2bb   Benjamin Renard   First commit
906

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
907
908
		_pls->wind(std::get<0>(lPlWindow), std::get<1>(lPlWindow),
				   std::get<2>(lPlWindow), std::get<3>(lPlWindow));
fbe3c2bb   Benjamin Renard   First commit
909

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
910
911
912
		//draw serie
		Color lineColor = getSerieLineColor(pSeries, moreThanOneSerieForAxis);
		Color symbolColor = getSerieSymbolColor(pSeries, lineColor);
fbe3c2bb   Benjamin Renard   First commit
913

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
914
915
916
917
918
		drawSymbols(
			pSeries.getSymbolProperties().getType(),
			pSeries.getSymbolProperties().getSize(), 1.,
			symbolColor,
			nbValues, timeValues, computedValues, coloredComputedValues);
fbe3c2bb   Benjamin Renard   First commit
919

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
920
921
922
923
924
925
		drawLines(
			pSeries.getLineProperties().getType(),
			pSeries.getLineProperties().getStyle(),
			pSeries.getLineProperties().getWidth(),
			lineColor,
			nbValues, timeValues, computedValues, coloredComputedValues);
fbe3c2bb   Benjamin Renard   First commit
926

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
927
928
		//add serie to param legend
		addSerieToParamsLegend(pSeries, pParamIndex, param._originalParamId, lineColor, symbolColor, startDate, stopDate, intervalIndex);
fbe3c2bb   Benjamin Renard   First commit
929

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
930
931
		//draw interval
		drawSerieInterval(pSeries, timeValues, computedValues, timeValues, nbValues, intervalIndex);
fbe3c2bb   Benjamin Renard   First commit
932

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
933
934
935
		delete[] computedValues;
		if (coloredComputedValues != NULL)
			delete[] coloredComputedValues;
fbe3c2bb   Benjamin Renard   First commit
936

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
937
938
939
		// Draw min/max error bars if required
		ErrorBarProperties &errorBarProp = pSeries.getErrorBarProperties();
		if (errorBarProp.getErrorMinMax() != nullptr)
fbe3c2bb   Benjamin Renard   First commit
940
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
			//get computed min/max error data
			double *minComputedValues = NULL;
			double *minTimeValues = NULL;
			int nbMinValues;

			double *maxComputedValues = NULL;
			double *maxTimeValues = NULL;
			int nbMaxValues;

			if (!getErrorComputedValuesFromSerieAndInterval(startDate, stopDate, pSeries,
															&minComputedValues, &minTimeValues, nbMinValues,
															&maxComputedValues, &maxTimeValues, nbMaxValues))
			{
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawSeries - Cannot get min/max error values for serie");
				return;
			}
fbe3c2bb   Benjamin Renard   First commit
957

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
958
959
			LineProperties &lineProps = pSeries.getErrorBarProperties().getLineProperties();
			drawYErrors(lineProps.getType(),
fbe3c2bb   Benjamin Renard   First commit
960
961
962
963
964
965
						lineProps.getStyle(),
						lineProps.getWidth(),
						lineProps.getColor(),
						nbMinValues, minTimeValues,
						minComputedValues, maxComputedValues);

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
966
967
968
969
			// Free values
			delete[] minComputedValues;
			delete[] maxComputedValues;
		}
fbe3c2bb   Benjamin Renard   First commit
970
	}
fbe3c2bb   Benjamin Renard   First commit
971

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
972
973
974
975
976
	void TimePlot::drawSpectro(double startDate, double stopDate, std::string pParamId, SpectroProperties &pSpectro)
	{
		LOG4CXX_DEBUG(gLogger, "TimePlot::drawSpectro Drawing spectro for parameter " << pParamId);
		// This will configure window, draw axes (if needed) and legend of axes.
		PanelPlotOutput::drawSpectro(startDate, stopDate, pParamId, pSpectro);
fbe3c2bb   Benjamin Renard   First commit
977

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
978
979
		//get parameter data and info
		ParameterSPtr p = _parameterManager.getParameter(pParamId);
fbe3c2bb   Benjamin Renard   First commit
980

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
981
		ParameterData &data = (*_pParameterValues)[pSpectro.getParamId()];
fbe3c2bb   Benjamin Renard   First commit
982

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
983
984
985
986
		boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
		AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());
		if (paramInfo != nullptr)
			tableSPtr = paramInfo->getTable(pSpectro.getRelatedDim());
f3cd5351   Hacene SI HADJ MOHAND   us ok
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
                
                                        if (tableSPtr == nullptr){
                                            boost::shared_ptr<AMDA::Info::ParamTable> linkedTableSPtr;
                                            int counter = 0;
                                            // work on this 
                                            for (auto pInfo :paramInfo->getLinkedParamList()){
                                                linkedTableSPtr = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(pInfo)->getTable(pSpectro.getRelatedDim());
                                                if (linkedTableSPtr == nullptr)
                                                    continue;
                                                counter ++;
                                            }
                                            if(linkedTableSPtr == nullptr || counter !=1){
                                                LOG4CXX_DEBUG(gLogger, "table cannot be defined from linked info params");
                                            }else{
                                                tableSPtr = linkedTableSPtr;
                                            }
                                        }                
fbe3c2bb   Benjamin Renard   First commit
1004

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1005
1006
1007
1008
		//get axis
		boost::shared_ptr<Axis> lXAxis = _panel->getAxis(pSpectro.getXAxisId());
		boost::shared_ptr<Axis> lYAxis = _panel->getAxis(pSpectro.getYAxisId());
		boost::shared_ptr<ColorAxis> lZAxis = _panel->getColorAxis();
fbe3c2bb   Benjamin Renard   First commit
1009

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1010
1011
		//Check dimensions
		if (pSpectro.getRelatedDim() == 0)
fbe3c2bb   Benjamin Renard   First commit
1012
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1013
1014
1015
1016
1017
			if (data.getDim1Size() + 1 <= 0)
			{
				LOG4CXX_INFO(gLogger, "TimePlot::drawSpectro - No data to plot");
				return;
			}
fbe3c2bb   Benjamin Renard   First commit
1018
		}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1019
		else
fbe3c2bb   Benjamin Renard   First commit
1020
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1021
1022
1023
1024
1025
			if (data.getDim2Size() + 1 <= 0)
			{
				LOG4CXX_INFO(gLogger, "TimePlot::drawSpectro - No data to plot");
				return;
			}
fbe3c2bb   Benjamin Renard   First commit
1026
		}
fbe3c2bb   Benjamin Renard   First commit
1027

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1028
1029
		LOG4CXX_DEBUG(gLogger, "TimePlot::drawSpectro - Build data grid");
		MatrixGrid matrixGrid;
f2db3c16   Benjamin Renard   Support variable ...
1030

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1031
1032
1033
		//get specific colors for min / max values
		Color minValColor = lZAxis->getMinValColor();
		Color maxValColor = lZAxis->getMaxValColor();
2d64c235   Benjamin Renard   Fix bug with spec...
1034

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1035
		if ((tableSPtr == nullptr) || !tableSPtr->isVariable(&_parameterManager))
fbe3c2bb   Benjamin Renard   First commit
1036
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1037
1038
1039
1040
			int startIndex;
			int nbValues;
			data.getIntervalBounds(startDate, stopDate, startIndex, nbValues);
			for (auto index : pSpectro.getIndexes())
fbe3c2bb   Benjamin Renard   First commit
1041
			{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1042
1043
1044
1045
1046
1047
1048
1049
1050
				GridPart part;
				if (tableSPtr == nullptr)
				{
					if (pSpectro.getRelatedDim() == 0)
						part.y[0] = index.getDim1Index();
					else
						part.y[0] = index.getDim2Index();
					part.y[1] = part.y[0] + 1;
				}
f2db3c16   Benjamin Renard   Support variable ...
1051
				else
f2db3c16   Benjamin Renard   Support variable ...
1052
				{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1053
1054
1055
1056
1057
1058
					AMDA::Info::t_TableBound crtBound;
					if (pSpectro.getRelatedDim() == 0)
						crtBound = tableSPtr->getBound(&_parameterManager, index.getDim1Index());
					else
						crtBound = tableSPtr->getBound(&_parameterManager, index.getDim2Index());
					if (std::isnan(crtBound.min) || std::isnan(crtBound.max))
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
1059
						continue;
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1060
1061
1062
1063
1064
1065
1066
1067
1068
					part.y[0] = crtBound.min;
					part.y[1] = crtBound.max;
					if (lYAxis->_scale == Axis::Scale::LOGARITHMIC)
					{
						if ((crtBound.min <= 0) || (crtBound.max <= 0))
							continue;
						part.y[0] = log10(part.y[0]);
						part.y[1] = log10(part.y[1]);
					}
f2db3c16   Benjamin Renard   Support variable ...
1069
				}
fbe3c2bb   Benjamin Renard   First commit
1070

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1071
1072
1073
1074
1075
1076
1077
				if (lYAxis->_reverse)
				{
					if (((part.y[0] < lYAxis->getRange().getMax()) && (part.y[1] < lYAxis->getRange().getMax())) ||
						((part.y[0] > lYAxis->getRange().getMin()) && (part.y[1] < lYAxis->getRange().getMin())))
					{
						continue;
					}
2d64c235   Benjamin Renard   Fix bug with spec...
1078
				}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1079
1080
1081
1082
1083
1084
1085
				else
				{
					if (((part.y[0] < lYAxis->getRange().getMin()) && (part.y[1] < lYAxis->getRange().getMin())) ||
						((part.y[0] > lYAxis->getRange().getMax()) && (part.y[1] < lYAxis->getRange().getMax())))
					{
						continue;
					}
2d64c235   Benjamin Renard   Fix bug with spec...
1086
				}
2d64c235   Benjamin Renard   Fix bug with spec...
1087

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
				for (int i = 0; i < nbValues - 1; ++i)
				{
					part.x[0] = data.getTimes()[startIndex + i];
					part.x[1] = data.getTimes()[startIndex + i + 1];
					part.isColorIndex = false;
					part.value = data.getValues(index, startIndex)[i];
					matrixGrid.push_back(part);
				}
				//Apply background subtraction
				applyBackgroundSubtraction(matrixGrid, pSpectro, data);
				//draw spectro
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawSpectro - Draw data grid - " << matrixGrid.size());
				std::string normalization = pSpectro.getNormalization();
				if (!normalization.empty())
					normalize(matrixGrid, normalization);
				drawMatrix(matrixGrid, pSpectro.getMin(), pSpectro.getMax(),
						   minValColor, maxValColor, lZAxis->_color._colorMapIndex, pSpectro.getUseLog0AsMin());
				matrixGrid.clear();
			}
f2db3c16   Benjamin Renard   Support variable ...
1107
		}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1108
		else
fbe3c2bb   Benjamin Renard   First commit
1109
		{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1110
1111
1112
1113
1114
1115
1116
1117
			//Variable table
			AMDA::Info::t_TableBound crtBound;
			//for (auto index : pSpectro.getIndexes())
			//{
			int startIndex;
			int nbValues;
			data.getIntervalBounds(startDate, stopDate, startIndex, nbValues);
			for (int i = 0; i < nbValues - 1; ++i)
8c71f50a   Benjamin Renard   Improve execution...
1118
			{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1119
1120
1121
1122
1123
1124
				GridPart part;
				part.x[0] = data.getTimes()[startIndex + i];
				part.x[1] = data.getTimes()[startIndex + i + 1];

				std::map<std::string, std::vector<double>> paramsTableData;
				for (std::map<std::string, std::string>::iterator it = pSpectro.getTableParams().begin(); it != pSpectro.getTableParams().end(); ++it)
f2db3c16   Benjamin Renard   Support variable ...
1125
				{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1126
1127
1128
1129
1130
1131
1132
1133
					ParameterData &tableData = (*_pParameterValues)[it->second];
					std::vector<double> paramTableValues;
					for (int j = 0; j < tableData.getDim1Size(); ++j)
					{
						double *values = tableData.getValues(AMDA::Common::ParameterIndexComponent(j, -1), i);
						paramTableValues.push_back((*values));
					}
					paramsTableData[it->first] = paramTableValues;
f2db3c16   Benjamin Renard   Support variable ...
1134
				}
8c71f50a   Benjamin Renard   Improve execution...
1135

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1136
1137
1138
1139
				for (auto index : pSpectro.getIndexes())
				{
					part.isColorIndex = false;
					part.value = data.getValues(index, startIndex)[i];
f2db3c16   Benjamin Renard   Support variable ...
1140

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1141
1142
1143
1144
					if (pSpectro.getRelatedDim() == 0)
						crtBound = tableSPtr->getBound(&_parameterManager, index.getDim1Index(), &paramsTableData);
					else
						crtBound = tableSPtr->getBound(&_parameterManager, index.getDim2Index(), &paramsTableData);
f2db3c16   Benjamin Renard   Support variable ...
1145

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1146
1147
					part.y[0] = crtBound.min;
					part.y[1] = crtBound.max;
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
1148

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1149
					if (!std::isnan(crtBound.min) && !std::isnan(crtBound.max))
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
1150
					{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1151
						if (lYAxis->_scale == Axis::Scale::LOGARITHMIC)
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
1152
						{
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1153
1154
1155
1156
1157
1158
							if ((crtBound.min > 0) && (crtBound.max > 0))
							{
								part.y[0] = log10(part.y[0]);
								part.y[1] = log10(part.y[1]);
								matrixGrid.push_back(part);
							}
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
1159
						}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1160
1161
						else
							matrixGrid.push_back(part);
ed9a1eaf   Benjamin Renard   Add Maven STATIC ...
1162
					}
f2db3c16   Benjamin Renard   Support variable ...
1163
				}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1164
1165
1166
1167
1168
1169
1170
1171
				//draw spectro
				LOG4CXX_DEBUG(gLogger, "TimePlot::drawSpectro - Draw data grid - " << matrixGrid.size());
				std::string normalization = pSpectro.getNormalization();
				if (!normalization.empty())
					normalize(matrixGrid, normalization);
				drawMatrix(matrixGrid, pSpectro.getMin(), pSpectro.getMax(),
						   minValColor, maxValColor, lZAxis->_color._colorMapIndex, pSpectro.getUseLog0AsMin());
				matrixGrid.clear();
f2db3c16   Benjamin Renard   Support variable ...
1172
			}
fbe3c2bb   Benjamin Renard   First commit
1173
1174
		}
	}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1175
1176
1177
1178
1179
1180

	void TimePlot::applyBackgroundSubtraction(MatrixGrid &matrixGrid, SpectroProperties &pSpectro, ParameterData &data)
	{
		//We get the background subtraction value given by the user
		const double backgroundSubValue = pSpectro.getBackgroundSubValue();

9e7f1f63   Menouard AZIB   Remplacer les str...
1181
1182
1183
		//If negative value then quit and do nothing
		if (backgroundSubValue < 0)
			return;
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1184
1185
1186

		const int len = matrixGrid.size();
		//Channel subtraction
9e7f1f63   Menouard AZIB   Remplacer les str...
1187
		if (pSpectro.getBackgroundSubType() == SpectroProperties::BackgroundSubType::BYCHANNEL)
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
		{
			int indexChannelDim1 = -1;
			int indexChannelDim2 = -1;

			//The selected dimension of the background subtraction
			if (pSpectro.getBackgroundSubDim() == 0)
				indexChannelDim1 = (int)backgroundSubValue;
			else
				indexChannelDim2 = (int)backgroundSubValue;

			//Get the values which corresponds to the selected channel
			double *values = data.getValues(AMDA::Common::ParameterIndexComponent(indexChannelDim1, indexChannelDim2), 0);
			//Apply the subtraction
			for (int i = 0; i < len; i++)
				matrixGrid[i].value -= values[i];
		}
		//Fixed value substraction
9e7f1f63   Menouard AZIB   Remplacer les str...
1205
		else if (pSpectro.getBackgroundSubType() == SpectroProperties::BackgroundSubType::FIXEDVALUE)
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1206
1207
1208
1209
1210
1211
1212
1213
		{
			for (int i = 0; i < len; i++)
				matrixGrid[i].value -= backgroundSubValue;
		}
		else
		{
			std::stringstream lError;
			lError << "Unknown background substracion type "
9e7f1f63   Menouard AZIB   Remplacer les str...
1214
				   << pSpectro.getBackgroundSubType();
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
			BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
		}

		return;
	}

	void TimePlot::normalize(MatrixGrid &matrixGrid, std::string normalizationType)
	{
		if (normalizationType == "none")
			return;
		double min = DBL_MAX;
		double max = DBL_MIN;
		int len = matrixGrid.size();
		if (normalizationType == "log")
		{
			for (auto val : matrixGrid)
			{
				if (val.value < min && val.value > 0)
					min = val.value;
				if (val.value > max)
					max = val.value;
			}
		}
		else
		{
			for (auto val : matrixGrid)
			{
				if (val.value < min)
					min = val.value;
				if (val.value > max)
					max = val.value;
			}
		}
		if (std::isnan(min) || std::isnan(max))
		{
			return;
		}
		else if (min == max)
		{
			for (int i = 0; i < len; i++)
				matrixGrid[i].value = matrixGrid[i].value / max;
		}
		else
		{
			if (normalizationType == "log")
			{
				for (int i = 0; i < len; i++)
					matrixGrid[i].value = (std::log10(matrixGrid[i].value) - std::log10(min)) / (std::log10(max) - std::log10(min));
				return;
			}
			else if (normalizationType == "linear")
			{
				for (int i = 0; i < len; i++)
					matrixGrid[i].value = (matrixGrid[i].value - min) / (max - min);
				return;
			}
			else
			{
				std::stringstream lError;
				lError << "Unknwon normalization " << normalizationType;
				BOOST_THROW_EXCEPTION(PanelPlotOutputException() << AMDA::ex_msg(lError.str()));
			}
		}
	}

	Color TimePlot::getStatusColor(AMDA::Info::ParamInfoSPtr &paramInfo, double value)
	{
		Color color;

		if ((paramInfo != nullptr) && !paramInfo->getStatusDef().empty())
		{
			for (int s = 0; s < (int)paramInfo->getStatusDef().size(); ++s)
			{
				if (value >= paramInfo->getStatusDef()[s].getMinValue() && value <= paramInfo->getStatusDef()[s].getMaxValue())
				{
					if (!paramInfo->getStatusDef()[s].getColor().empty())
					{
						std::string colorStr = paramInfo->getStatusDef()[s].getColor();
						createColor(color, colorStr);
						return color;
					}
677db865   Benjamin Renard   Draw intervals on...
1296
1297
1298
				}
			}
		}
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1299
1300

		return color;
677db865   Benjamin Renard   Draw intervals on...
1301
1302
	}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1303
1304
1305
1306
1307
1308
	void TimePlot::drawOneInterval(double tmin, double tmax, Color color)
	{
		if (!color.isSet())
		{
			return;
		}
677db865   Benjamin Renard   Draw intervals on...
1309

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
		//Fill interval
		PanelPlotOutput::drawRectangle(tmin, tmax, 0., 1., color, 0.25);

		//Draw borders
		PLFLT x[2], y[2];
		x[0] = tmin;
		y[0] = 0.;
		x[1] = tmin;
		y[1] = 1.;
		PanelPlotOutput::drawLines(LineType::LINE, LineStyle::PLAIN, 2, color, 2, x, y);

		x[0] = tmax;
		y[0] = 0.;
		x[1] = tmax;
		y[1] = 1.;
		PanelPlotOutput::drawLines(LineType::LINE, LineStyle::PLAIN, 2, color, 2, x, y);
677db865   Benjamin Renard   Draw intervals on...
1326
1327
	}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
	void TimePlot::drawIntervals(double startDate, double stopDate, std::string pParamId,
								 IntervalsProperties &pIntervals)
	{
		LOG4CXX_DEBUG(gLogger, "TimePlot::drawIntervals Drawing intervals for parameter " << pParamId);
		// This will configure window, draw axes (if needed) and legend of axes.
		PanelPlotOutput::drawIntervals(startDate, stopDate, pParamId, pIntervals);

		PlWindow lPlWindow = PlWindow(getTimeAxis()->getRange().getMin(), getTimeAxis()->getRange().getMax(), 0, 1);

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

		ParameterData &data = (*_pParameterValues)[pIntervals.getParamId()];

		ParameterSPtr p = _parameterManager.getParameter(pIntervals.getParamId());
		AMDA::Info::ParamInfoSPtr paramInfo = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(p->getInfoId());

		//get computed values
		int startIndex, nbData;
		data.getIntervalBounds(startDate, stopDate, startIndex, nbData);

		Color crtColor;

		// Draw intervals
		double crtVal = NAN;
		double tmin = 0, tmax = 0;
		for (int i = 0; i < nbData - 1; ++i)
		{
			double t1 = data.getTimes()[startIndex + i];
			double t2 = data.getTimes()[startIndex + i + 1];
			double v = *data.getValues(AMDA::Common::ParameterIndexComponent(-1, -1), startIndex + i);

			if (isNAN(crtVal))
			{
				tmin = t1;
				tmax = t2;
				crtVal = v;
				continue;
			}
			else if (crtVal == v)
			{
				tmax = t2;
				continue;
			}

			crtColor = getStatusColor(paramInfo, crtVal);

			drawOneInterval(tmin, tmax, crtColor);

			tmin = t1;
			tmax = t2;
			crtVal = v;
			crtColor = Color();
		}

		//Draw last interval if need
		if ((tmin != tmax) && !isNAN(crtVal))
		{
			crtColor = getStatusColor(paramInfo, crtVal);
			drawOneInterval(tmin, tmax, crtColor);
		}
4de2b52c   Benjamin Renard   Fix some tests + ...
1389
	}
e257cfb9   Benjamin Renard   First implementat...
1390

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1391
	/**
fbe3c2bb   Benjamin Renard   First commit
1392
1393
 * @brief Draw further information (for instance start date).
 */
fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1394
1395
1396
	void TimePlot::drawStartDate(TimeAxis *pXAxis, double startTime, double stopTime)
	{
		LOG4CXX_DEBUG(gLogger, "Drawing start date.");
fbe3c2bb   Benjamin Renard   First commit
1397

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1398
1399
		if (pXAxis->_showTickMark == false || !pXAxis->_drawn || !pXAxis->_visible)
			return;
fbe3c2bb   Benjamin Renard   First commit
1400

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1401
		// use panel font to draw start date.
fbe3c2bb   Benjamin Renard   First commit
1402

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1403
1404
		// If font of legend is not defined, use panel font.
		Font font(_panel->getFont());
fbe3c2bb   Benjamin Renard   First commit
1405

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
		// PlPlotUtil::setPlFont(font);
		//CharSize charsize = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);
		// panel bounds.
		Bounds lPanelBounds(_panel->getBoundsInPlPage());

		// plotting area bounds (i.e. current viewport dimensions)
		PLFLT lXMin, lXMax, lYMin, lYMax;
		_pls->gvpd(lXMin, lXMax, lYMin, lYMax);

		// position of reference point of string along the bottom edge
		// expressed as a fraction of the length of the bottom edge
		// set it at the very beginning of edge and use justification to handle
		// reverse axis.
		float lPosition = 0.0;
		// display it one line above the main panel bottom border :
		float disp = -1;

		long int lTime = static_cast<long int>(startTime);
		tm *lTimeTm = gmtime(&lTime);
		char lTimeChr[80];

		// Format date.
		strftime(lTimeChr, 80,
				 getPlStartTimeFormat(pXAxis->_timeFormat,
									  startTime,
									  stopTime)
					 .c_str(),
				 lTimeTm);

		PLFLT mxmin, mxmax, mymin, mymax;
		plgspa(&mxmin, &mxmax, &mymin, &mymax);
		float x_subpage_per_mm = 1. / (mxmax - mxmin);

		LOG4CXX_DEBUG(gLogger, "Start date to draw : " << lTimeChr);

		// Set font
		PlPlotUtil::setPlFont(font);

		PLFLT dateWidthInMm;
		dateWidthInMm = plstrl(lTimeChr);

		// set viewport for start date :
		_pls->vpor(lXMin, lXMax, lPanelBounds._y, lPanelBounds._y + lPanelBounds._height);

		// Draw start date.
		if (pXAxis->_reverse)
		{
			lPosition = 1.;
			if (dateWidthInMm * x_subpage_per_mm > lPanelBounds._x + lPanelBounds._width - lXMax)
				lPosition = 1. - (dateWidthInMm * x_subpage_per_mm - (lPanelBounds._x + lPanelBounds._width - lXMax)) / (lXMax - lXMin);
			_pls->mtex("b", disp, lPosition, 0., lTimeChr);
		}
		else
		{
			lPosition = 0.;
			if (dateWidthInMm * x_subpage_per_mm > lXMin - lPanelBounds._x)
				lPosition = (dateWidthInMm * x_subpage_per_mm - lXMin + lPanelBounds._x) / (lXMax - lXMin);
			_pls->mtex("b", disp, lPosition, 1., lTimeChr);
		}

		// restore viewport :
		_pls->vpor(lXMin, lXMax, lYMin, lYMax);
fbe3c2bb   Benjamin Renard   First commit
1468
1469
	}

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
	const std::string TimePlot::getXAxisId() const
	{
		// time plot can manage only one x axis.
		// search for its id
		for (auto param : _parameterAxesList)
		{
			//search time axis in color serie if exist
			if (!param.getYSeriePropertiesList().empty())
				return param.getYSeriePropertiesList().begin()->getXAxisId();
			//search time axis in spectro if exist
			if (param.getSpectroProperties() != nullptr)
				return param.getSpectroProperties()->getXAxisId();
		}
fbe3c2bb   Benjamin Renard   First commit
1483

fe6b6521   Menouard AZIB   J'ai ajouté le tr...
1484
1485
		return DefaultPlotConfiguration::TIME_DEFAULT_ID;
	}
fbe3c2bb   Benjamin Renard   First commit
1486
1487

} /* namespace plot */