Commit 99ff615c7842f74f6da5027e945fa3bd3736a402
1 parent
edef04ea
Exists in
master
and in
45 other branches
Change nbEchantillons to ParamsNbPoints
Showing
5 changed files
with
757 additions
and
2 deletions
Show diff stats
config/xsd/request/plotFunction.xsd
... | ... | @@ -37,8 +37,7 @@ |
37 | 37 | <xs:attribute name="scale_abscisse" type="xs:string"></xs:attribute> |
38 | 38 | <xs:attribute name="scale_ordonnee" type="xs:string"></xs:attribute> |
39 | 39 | <xs:attribute name="type" type="xs:string"></xs:attribute> |
40 | - <xs:complexType name="param_nb_points"> | |
41 | - </xs:complexType> | |
40 | + <xs:attribute name="param_nb_points" type="xs:string"></xs:attribute> | |
42 | 41 | </xs:complexType> |
43 | 42 | </xs:element> |
44 | 43 | </xs:schema> | ... | ... |
... | ... | @@ -0,0 +1,379 @@ |
1 | +#include <boost/lexical_cast.hpp> | |
2 | +#include <fstream> | |
3 | +#include <iomanip> | |
4 | + | |
5 | +#include "AxesNode.hh" | |
6 | +#include "AxisLegendManager.hh" | |
7 | +#include "ParamMgr.hh" | |
8 | +#include "ParamsNode.hh" | |
9 | +#include "PlPlotUtil.hh" | |
10 | +#include "PlotFunction.hh" | |
11 | +#include "PlotLogger.hh" | |
12 | +#include "PlotOutput.hh" | |
13 | +#include "TimeUtil.hh" | |
14 | +#include "fonctions/fourier/DiscreteFourierTransform.cc" | |
15 | +#include "fonctions/fourier/DiscreteFourierTransform.hh" | |
16 | +#include <algorithm> | |
17 | +#include <limits> | |
18 | +#include <numeric> | |
19 | + | |
20 | +#include "DefaultTimeAxisDecorator.hh" | |
21 | + | |
22 | +#include "TimeAxisDecorator.hh" | |
23 | + | |
24 | +using namespace AMDA::Parameters; | |
25 | +using namespace AMDA::Info; | |
26 | + | |
27 | +namespace plot | |
28 | +{ | |
29 | + QSASConfig *PlotFunction::qsasconfig = NULL; | |
30 | + | |
31 | + PlotFunction::PlotFunction(AMDA::Parameters::ParameterManager &manager, | |
32 | + boost::shared_ptr<Panel> panel, TimeAxisDecorator *timeAxisDecorator) : PanelPlotOutput(manager, panel), function(PlotFunction::Function::NONE), abscisse("Time. ", "(s)", Abscisse::Abscisse_Type::TIME) | |
33 | + | |
34 | + { | |
35 | + LOG4CXX_DEBUG(gLogger, "Function to apply " << function); | |
36 | + setTimeAxisDecorator(std::shared_ptr<TimeAxisDecorator>(timeAxisDecorator)); | |
37 | + } | |
38 | + | |
39 | + PlotFunction::~PlotFunction() | |
40 | + { | |
41 | + if (qsasconfig != NULL) | |
42 | + { | |
43 | + free(qsasconfig); | |
44 | + qsasconfig = nullptr; | |
45 | + } | |
46 | + } | |
47 | + | |
48 | + void PlotFunction::drawSeries(double startDate, double stopDate, int intervalIndex, std::string pParamId, | |
49 | + SeriesProperties &pSerie, | |
50 | + AMDA::Common::ParameterIndexComponent pParamIndex, | |
51 | + ParameterAxes ¶m, bool moreThanOneSerieForAxis) | |
52 | + { | |
53 | + std::string id = std::to_string(pSerie.getId()) + "_" + pSerie.getParamId() + "_" + std::to_string(pParamIndex.getDim1Index()); | |
54 | + std::vector<double> xValues = xValuesMap[id]; | |
55 | + std::vector<double> yValues = yValuesMap[id]; | |
56 | + | |
57 | + double *coloredComputedValues = NULL; | |
58 | + int nbValues = yValues.size(); | |
59 | + | |
60 | + double *yValuesTemp = &yValues[0]; | |
61 | + double *xValuesTemp = &xValues[0]; | |
62 | + | |
63 | + pSerie.setXAxisId(X_AXIS_ID); | |
64 | + pSerie.setYAxisId(Y_AXIS_ID); | |
65 | + | |
66 | + PanelPlotOutput::drawSeries(startDate, stopDate, intervalIndex, pParamId, | |
67 | + pSerie, pParamIndex, param, moreThanOneSerieForAxis); | |
68 | + // draw serie | |
69 | + Color lineColor = getSerieLineColor(pSerie, moreThanOneSerieForAxis); | |
70 | + Color symbolColor = getSerieSymbolColor(pSerie, lineColor); | |
71 | + | |
72 | + drawSymbols( | |
73 | + pSerie.getSymbolProperties().getType(), | |
74 | + pSerie.getSymbolProperties().getSize(), 1., | |
75 | + symbolColor, | |
76 | + nbValues, xValuesTemp, yValuesTemp, coloredComputedValues); | |
77 | + | |
78 | + drawLines( | |
79 | + pSerie.getLineProperties().getType(), | |
80 | + pSerie.getLineProperties().getStyle(), | |
81 | + pSerie.getLineProperties().getWidth() + 1, | |
82 | + lineColor, | |
83 | + nbValues, xValuesTemp, yValuesTemp, coloredComputedValues); | |
84 | + } | |
85 | + | |
86 | + void PlotFunction::configureSeriesAxis() | |
87 | + { | |
88 | + //_panel->_leftMargin = 10; | |
89 | + //_panel->_rightMargin = 5; | |
90 | + //_panel->_bottomMargin = 4; | |
91 | + | |
92 | + SeriesProperties lSeries; | |
93 | + for (auto parameter : _parameterAxesList) | |
94 | + { | |
95 | + for (auto lSeries : parameter.getYSeriePropertiesList()) | |
96 | + { | |
97 | + for (auto lIndex : lSeries.getIndexList(_pParameterValues)) | |
98 | + { | |
99 | + std::string id = std::to_string(lSeries.getId()) + "_" + lSeries.getParamId() + "_" + std::to_string(lIndex.getDim1Index()); | |
100 | + plot::ParameterData data = (*_pParameterValues)[lSeries.getParamId()]; | |
101 | + PlotFunction::compute(lIndex, data, id); | |
102 | + } | |
103 | + } | |
104 | + } | |
105 | + | |
106 | + PlotFunction::createXAxis(); | |
107 | + PlotFunction::createYAxis(); | |
108 | + } | |
109 | + | |
110 | + void PlotFunction::createXAxis() | |
111 | + { | |
112 | + double minValue = 0; | |
113 | + double maxValue = 0; | |
114 | + PlotFunction::getMinMax(xValuesMap, &minValue, &maxValue); | |
115 | + // Create X axis | |
116 | + boost::shared_ptr<TimeAxis> lXAxis(new TimeAxis()); | |
117 | + lXAxis.get()->_timeFormat = "%H:%M"; | |
118 | + plot::Range range_x = Range(minValue, maxValue); | |
119 | + lXAxis.get()->setRange(range_x); | |
120 | + lXAxis.get()->_drawn = false; | |
121 | + lXAxis.get()->_position = PlotCommon::Position::POS_BOTTOM; | |
122 | + Label label1 = Label(); | |
123 | + // lXAxis.get()->setLegendOffset(0.03); | |
124 | + label1._text = abscisse.getLabel() + abscisse.getUnit(); | |
125 | + lXAxis.get()->_legend.pushLabel(label1); | |
126 | + lXAxis.get()->_scale = abscisseScale; | |
127 | + lXAxis.get()->_showLegend = true; | |
128 | + lXAxis.get()->_showTickMark = true; | |
129 | + lXAxis.get()->_used = true; | |
130 | + | |
131 | + // add X Axis to panel | |
132 | + _panel->addAxis(X_AXIS_ID, lXAxis); | |
133 | + } | |
134 | + | |
135 | + void PlotFunction::createYAxis() | |
136 | + { | |
137 | + std::string y_label = ""; | |
138 | + if (function == PlotFunction::Function::SUM) | |
139 | + y_label = "Sum"; | |
140 | + else | |
141 | + y_label = "Amplitude"; | |
142 | + | |
143 | + double minValue = 0; | |
144 | + double maxValue = 0; | |
145 | + | |
146 | + PlotFunction::getMinMax(yValuesMap, &minValue, &maxValue); | |
147 | + LOG4CXX_DEBUG(gLogger, "Min value " << minValue << " " | |
148 | + << "Max Value" << maxValue); | |
149 | + // Create X axis | |
150 | + boost::shared_ptr<Axis> lYAxis(new Axis(false)); | |
151 | + plot::Range range_x = Range(minValue - minValue * 0.1, maxValue + maxValue * 0.1); | |
152 | + lYAxis.get()->setRange(range_x); | |
153 | + lYAxis.get()->_drawn = false; | |
154 | + lYAxis.get()->_position = PlotCommon::Position::POS_LEFT; | |
155 | + Label label1 = Label(); | |
156 | + // lYAxis.get()->setLegendOffset(0.05); | |
157 | + label1._text = y_label; | |
158 | + lYAxis.get()->_legend.pushLabel(label1); | |
159 | + lYAxis.get()->_scale = ordonneeScale; | |
160 | + lYAxis.get()->_showLegend = true; | |
161 | + lYAxis.get()->_showTickMark = true; | |
162 | + lYAxis.get()->_used = true; | |
163 | + // add X Axis to panel | |
164 | + _panel->addAxis(Y_AXIS_ID, lYAxis); | |
165 | + } | |
166 | + | |
167 | + void PlotFunction::getMinMax(std::map<std::string, std::vector<double>> dataMap, double *minToFill, double *maxToFill) | |
168 | + { | |
169 | + double maxValue = INT_MIN; | |
170 | + double minValue = INT_MAX; | |
171 | + std::map<std::string, std::vector<double>>::iterator it; | |
172 | + for (it = dataMap.begin(); it != dataMap.end(); it++) | |
173 | + { | |
174 | + std::vector<double> data = it->second; | |
175 | + double max_x = *max_element(data.begin(), data.end()); | |
176 | + double min_x = *min_element(data.begin(), data.end()); | |
177 | + if (max_x > maxValue) | |
178 | + maxValue = max_x; | |
179 | + if (min_x < minValue) | |
180 | + minValue = min_x; | |
181 | + } | |
182 | + *minToFill = minValue; | |
183 | + *maxToFill = maxValue; | |
184 | + } | |
185 | + | |
186 | + void PlotFunction::compute(AMDA::Common::ParameterIndexComponent pParamIndex, plot::ParameterData data, std::string id) | |
187 | + { | |
188 | + double samplingValue = 60.0; | |
189 | + double *values = data.getValues(pParamIndex, 0); | |
190 | + int startIndex; | |
191 | + int nbValues = 0; | |
192 | + | |
193 | + // data.getIntervalBounds(startTime, stopTime, &startIndex, &nbValues); | |
194 | + | |
195 | + double *timeValues = &data.getTimes()[0]; | |
196 | + LOG4CXX_DEBUG(gLogger, " First Time : " << timeValues[0]); | |
197 | + | |
198 | + std::vector<double> signal; | |
199 | + for (int i = 0; i < data.getSize(); i++) | |
200 | + signal.push_back(values[i]); | |
201 | + | |
202 | + std::vector<double> xValues; | |
203 | + std::vector<double> yValues; | |
204 | + | |
205 | + if (function == PlotFunction::Function::SUM) | |
206 | + { | |
207 | + double sum = std::accumulate(signal.begin(), signal.end(), 0); | |
208 | + for (int i = 0; i < data.getSize(); i++) | |
209 | + { | |
210 | + yValues.push_back(sum); | |
211 | + xValues.push_back(timeValues[i]); | |
212 | + } | |
213 | + } | |
214 | + else | |
215 | + { | |
216 | + DiscreteFourierTransform<double, double> DFT(std::min(nbEchantillons, data.getSize()), signal, 1 / samplingValue); | |
217 | + DFT.compute(); | |
218 | + | |
219 | + yValues = DFT.getAmplitudes(); | |
220 | + | |
221 | + if (abscisse.getType() == Abscisse::Abscisse_Type::FREQUENCY) | |
222 | + xValues = DFT.getFrequences(); | |
223 | + else | |
224 | + xValues = DFT.getPeriodes(); | |
225 | + } | |
226 | + | |
227 | + if (ordonneeScale == Axis::Scale::LOGARITHMIC) | |
228 | + { | |
229 | + std::for_each(yValues.begin(), yValues.end(), [&](double &i) | |
230 | + { return log10(i); }); | |
231 | + } | |
232 | + | |
233 | + if (abscisseScale == Axis::Scale::LOGARITHMIC) | |
234 | + { | |
235 | + std::for_each(xValues.begin(), xValues.end(), [&](double &i) | |
236 | + { return log10(i); }); | |
237 | + } | |
238 | + | |
239 | + PlotFunction::xValuesMap[id] = xValues; | |
240 | + PlotFunction::yValuesMap[id] = yValues; | |
241 | + } | |
242 | + | |
243 | + void PlotFunction::configureAxisLegend() | |
244 | + { | |
245 | + // Y axis | |
246 | + AxisLegendManager::configureYAxisLegendForSpectro(this); | |
247 | + AxisLegendManager::configureYAxisLegendForSeries(this); | |
248 | + | |
249 | + // Z axis | |
250 | + AxisLegendManager::configureColorAxisLegendForSpectro(this); | |
251 | + AxisLegendManager::configureColorAxisLegendForSeries(this); | |
252 | + } | |
253 | + | |
254 | + void PlotFunction::drawStartDate(std::string _timeFormat, double startTime, double stopTime) | |
255 | + { | |
256 | + Font font(_panel->getFont()); | |
257 | + Bounds lPanelBounds(_panel->getBoundsInPlPage()); | |
258 | + | |
259 | + PLFLT lXMin, lXMax, lYMin, lYMax; | |
260 | + _pls->gvpd(lXMin, lXMax, lYMin, lYMax); | |
261 | + | |
262 | + float lPosition = 0.0; | |
263 | + // display it one line above the main panel bottom border : | |
264 | + float disp = -1; | |
265 | + | |
266 | + long int lTime = static_cast<long int>(startTime); | |
267 | + tm *lTimeTm = gmtime(&lTime); | |
268 | + char lTimeChr[80]; | |
269 | + | |
270 | + // Format date. | |
271 | + strftime(lTimeChr, 80, | |
272 | + getPlStartTimeFormat(_timeFormat, | |
273 | + startTime, | |
274 | + stopTime) | |
275 | + .c_str(), | |
276 | + lTimeTm); | |
277 | + | |
278 | + PLFLT mxmin, mxmax, mymin, mymax; | |
279 | + plgspa(&mxmin, &mxmax, &mymin, &mymax); | |
280 | + float x_subpage_per_mm = 1. / (mxmax - mxmin); | |
281 | + | |
282 | + LOG4CXX_DEBUG(gLogger, "Start date to draw : " << lTimeChr); | |
283 | + | |
284 | + // Set font | |
285 | + PlPlotUtil::setPlFont(font); | |
286 | + | |
287 | + PLFLT dateWidthInMm; | |
288 | + dateWidthInMm = plstrl(lTimeChr); | |
289 | + | |
290 | + // set viewport for start date : | |
291 | + _pls->vpor(lXMin, lXMax, lPanelBounds._y, lPanelBounds._y + lPanelBounds._height); | |
292 | + | |
293 | + lPosition = 0.; | |
294 | + if (dateWidthInMm * x_subpage_per_mm > lXMin - lPanelBounds._x) | |
295 | + lPosition = (dateWidthInMm * x_subpage_per_mm - lXMin + lPanelBounds._x) / (lXMax - lXMin); | |
296 | + _pls->mtex("b", disp, lPosition, 1., lTimeChr); | |
297 | + | |
298 | + // restore viewport : | |
299 | + _pls->vpor(lXMin, lXMax, lYMin, lYMax); | |
300 | + } | |
301 | + | |
302 | + void PlotFunction::preparePlotArea(double startTime, double stopTime, int intervalIndex) | |
303 | + { | |
304 | + PlotFunction::configureSeriesAxis(); | |
305 | + | |
306 | + if (abscisse.getType() == Abscisse::TIME) | |
307 | + { | |
308 | + boost::shared_ptr<Axis> xAxis = _panel->getAxis(X_AXIS_ID); | |
309 | + getTimeAxisDecorator()->configure(this, dynamic_cast<TimeAxis *>(xAxis.get()), startTime, stopTime, _pParameterValues); | |
310 | + _pls->timefmt(getTimeAxisDecorator()->getPlFormat().c_str()); | |
311 | + } | |
312 | + PanelPlotOutput::preparePlotArea(startTime, stopTime, intervalIndex); | |
313 | + } | |
314 | + | |
315 | + void PlotFunction::createParameters(std::list<std::string> & usedParametersId_) | |
316 | + { | |
317 | + // -- for each y serie on each parameter, calculate | |
318 | + // y serie sampling according to max resolution | |
319 | + for (ParameterAxesList::iterator it = _parameterAxesList.begin(); | |
320 | + it != _parameterAxesList.end(); ++it) | |
321 | + { | |
322 | + AMDA::Parameters::ParameterSPtr originalParam = | |
323 | + _parameterManager.getParameter(it->_originalParamId); | |
324 | + | |
325 | + LOG4CXX_DEBUG(gLogger, "before resampling : " << it->_originalParamId); | |
326 | + | |
327 | + // original parameter sampling | |
328 | + double samplingValue = getSamplingInTreeParameter(originalParam); | |
329 | + | |
330 | + // For each series | |
331 | + std::vector<SeriesProperties>::iterator ity; | |
332 | + for (ity = it->getYSeriePropertiesList().begin(); ity != it->getYSeriePropertiesList().end(); | |
333 | + ++ity) | |
334 | + { | |
335 | + // get corrected sampling value in relation with max resolution | |
336 | + double correctedSamplingValue = getCorrectedSamplingValue(ity->getMaxResolution(), samplingValue); | |
337 | + | |
338 | + AMDA::Parameters::ParameterSPtr usedParam; | |
339 | + // create resampling parameters for param | |
340 | + if (abs(samplingValue - correctedSamplingValue) > 1.) | |
341 | + { | |
342 | + // more than one second between samplingValue and correctedSamplingValue | |
343 | + //=> use resampling parameter | |
344 | + usedParam = createSampledParameter(originalParam, correctedSamplingValue); | |
345 | + } | |
346 | + else | |
347 | + { | |
348 | + // use original parameter | |
349 | + usedParam = originalParam; | |
350 | + } | |
351 | + | |
352 | + // Add used parameter to parameters list | |
353 | + if (std::find(usedParametersId_.begin(), usedParametersId_.end(), | |
354 | + usedParam->getId()) == usedParametersId_.end()) | |
355 | + usedParametersId_.push_back(usedParam->getId()); | |
356 | + | |
357 | + // link this paramter to the serie | |
358 | + ity->setParamId(usedParam->getId()); | |
359 | + } | |
360 | + } | |
361 | + } | |
362 | + | |
363 | + /** | |
364 | + * @brief draw the plot for the current time interval | |
365 | + */ | |
366 | + bool PlotFunction::draw(double startTime, double stopTime, int intervalIndex, | |
367 | + bool isFirstInterval, bool isLastInterval) | |
368 | + { | |
369 | + bool out = PanelPlotOutput::draw(startTime, stopTime, intervalIndex, isFirstInterval, isLastInterval); | |
370 | + | |
371 | + if (abscisse.getType() == Abscisse::TIME) | |
372 | + { | |
373 | + std::string _timeFormat = "hh:mm:ss"; | |
374 | + PlotFunction::drawStartDate(_timeFormat, startTime, stopTime); | |
375 | + } | |
376 | + | |
377 | + return out; | |
378 | + } | |
379 | +} | ... | ... |
... | ... | @@ -0,0 +1,172 @@ |
1 | + | |
2 | +#ifndef PLOTFUNCTION_HH_ | |
3 | +#define PLOTFUNCTION_HH_ | |
4 | + | |
5 | +// includes boost | |
6 | +#include <boost/shared_ptr.hpp> | |
7 | + | |
8 | +#include "NodeCfg.hh" | |
9 | +#include "PanelPlotOutput.hh" | |
10 | +#include "PlPlotUtil.hh" | |
11 | +#include "PlotFunctionNode.hh" | |
12 | +#include "plotFunctionElements/Abscisse.hh" | |
13 | +#include <climits> | |
14 | + | |
15 | +#include "DefaultTimeAxisDecorator.hh" | |
16 | + | |
17 | +#include "TimeAxisDecorator.hh" | |
18 | + | |
19 | +#include "plplot/plplot.h" | |
20 | +#include "plplot/plplotP.h" | |
21 | +#include "plplot/plstream.h" | |
22 | +#include <map> | |
23 | + | |
24 | +#include "plplot/plstream.h" | |
25 | + | |
26 | +extern "C" | |
27 | +{ | |
28 | +#include <plplot/qsastime.h> | |
29 | +} | |
30 | + | |
31 | +#define X_AXIS_ID "x_axis_id" | |
32 | +#define Y_AXIS_ID "" | |
33 | + | |
34 | +namespace plot | |
35 | +{ | |
36 | + | |
37 | + class PlotFunction : public PanelPlotOutput | |
38 | + { | |
39 | + public: | |
40 | + enum Function | |
41 | + { | |
42 | + NONE, | |
43 | + FFT, | |
44 | + SUM | |
45 | + }; | |
46 | + | |
47 | + PlotFunction(AMDA::Parameters::ParameterManager &manager, | |
48 | + boost::shared_ptr<Panel> panel, TimeAxisDecorator *timeAxisDecorator = new DefaultTimeAxisDecorator()); | |
49 | + virtual ~PlotFunction(); | |
50 | + | |
51 | + /** | |
52 | + * @overload plot::PanelPlotOutput | |
53 | + */ | |
54 | + virtual const std::string typeName() | |
55 | + { | |
56 | + return PlotFunction_NODENAME; | |
57 | + } | |
58 | + | |
59 | + void setOriginalParamId(std::string originalParamId_) | |
60 | + { | |
61 | + originalParamId = originalParamId_; | |
62 | + }; | |
63 | + | |
64 | + void setAbscisse(Abscisse abscisse_) | |
65 | + { | |
66 | + abscisse = abscisse_; | |
67 | + }; | |
68 | + | |
69 | + Abscisse getAbscisse() | |
70 | + { | |
71 | + return abscisse; | |
72 | + }; | |
73 | + | |
74 | + Function getFunction() | |
75 | + { | |
76 | + return function; | |
77 | + }; | |
78 | + | |
79 | + void setFunction(Function function_) | |
80 | + { | |
81 | + function = function_; | |
82 | + }; | |
83 | + | |
84 | + void setParamsNbPoints(std::string nb) | |
85 | + { | |
86 | + paramsNbPoints = nb; | |
87 | + }; | |
88 | + | |
89 | + void setAbscisseScale(Axis::Scale scale) | |
90 | + { | |
91 | + abscisseScale = scale; | |
92 | + }; | |
93 | + | |
94 | + Axis::Scale getAbscisseScale() | |
95 | + { | |
96 | + return abscisseScale; | |
97 | + }; | |
98 | + | |
99 | + Axis::Scale getOrdonneeScale() | |
100 | + { | |
101 | + return ordonneeScale; | |
102 | + }; | |
103 | + | |
104 | + void setOrdonneeScale(Axis::Scale scale) | |
105 | + { | |
106 | + ordonneeScale = scale; | |
107 | + }; | |
108 | + static QSASConfig *qsasconfig; | |
109 | + | |
110 | + void setTimeAxisDecorator(std::shared_ptr<TimeAxisDecorator> pDecorator_) | |
111 | + { | |
112 | + _xdecoratorPtr = pDecorator_; | |
113 | + } | |
114 | + | |
115 | + std::shared_ptr<TimeAxisDecorator> getTimeAxisDecorator() | |
116 | + { | |
117 | + return _xdecoratorPtr; | |
118 | + } | |
119 | + | |
120 | + protected: | |
121 | + /** | |
122 | + *@brief Draw the serie of a parameter component on plot. | |
123 | + */ | |
124 | + virtual void | |
125 | + drawSeries(double startDate, double stopDate, int intervalIndex, std::string pParamId, | |
126 | + SeriesProperties &pSerie, | |
127 | + AMDA::Common::ParameterIndexComponent pParamIndex, | |
128 | + ParameterAxes ¶m, bool moreThanOneSerieForAxis); | |
129 | + | |
130 | + virtual void preparePlotArea(double startTime, double stopTime, int intervalIndex); | |
131 | + /** | |
132 | + * @brief Get original id of the concerned parameter (for the plot) then add it to the usedParametersId_ and store it in originalParamId | |
133 | + * | |
134 | + * @param usedParametersId_ | |
135 | + */ | |
136 | + virtual void createParameters(std::list<std::string> &usedParametersId_); | |
137 | + /** | |
138 | + * @brief draw the plot for the current time interval | |
139 | + */ | |
140 | + virtual bool draw(double startTime, double stopTime, int intervalIndex, | |
141 | + bool isFirstInterval, bool isLastInterval); | |
142 | + | |
143 | + // virtual void drawFills(double startDate, double stopDate); | |
144 | + | |
145 | + private: | |
146 | + void configureSeriesAxis(); | |
147 | + void configureAxisLegend(); | |
148 | + void drawStartDate(std::string _timeFormat, double startTime, double stopTime); | |
149 | + void createYAxis(); | |
150 | + void createXAxis(); | |
151 | + void getMinMax(std::map<std::string, std::vector<double>>, double *minToFill, double *maxToFill); | |
152 | + | |
153 | + void compute(AMDA::Common::ParameterIndexComponent pParamIndex, plot::ParameterData data, std::string id); | |
154 | + std::map<std::string, std::vector<double>> xValuesMap; | |
155 | + std::map<std::string, std::vector<double>> yValuesMap; | |
156 | + Function function; | |
157 | + std::string paramsNbPoints = ""; | |
158 | + Abscisse abscisse; | |
159 | + Axis::Scale abscisseScale; | |
160 | + Axis::Scale ordonneeScale; | |
161 | + std::shared_ptr<TimeAxisDecorator> _xdecoratorPtr; | |
162 | + | |
163 | + /** | |
164 | + * @brief original param Id. | |
165 | + */ | |
166 | + std::string originalParamId; | |
167 | + std::list<std::string> listParamsId; | |
168 | + // std::vector<double> xValues; | |
169 | + // std::vector<double> yValues; | |
170 | + }; | |
171 | +} | |
172 | +#endif | ... | ... |
src/ParamOutputImpl/Plot/InstantPlot/PlotFunctionNode.cc
0 → 100644
... | ... | @@ -0,0 +1,148 @@ |
1 | + | |
2 | + | |
3 | +#include "PlotFunctionNode.hh" | |
4 | +#include "AxesNode.hh" | |
5 | +#include "FillsNode.hh" | |
6 | +#include "PanelPlotNodeRegistry.hh" | |
7 | +#include "ParamsNode.hh" | |
8 | +#include "PlotFunction.hh" | |
9 | +#include "PlotLegendNode.hh" | |
10 | +#include "PlotLogger.hh" | |
11 | + | |
12 | +// DD_Client_r_lib module includes | |
13 | +#include "TimeUtil.hh" | |
14 | + | |
15 | +namespace plot | |
16 | +{ | |
17 | + | |
18 | + const std::string PlotFunctionNode::NODENAME = PlotFunction_NODENAME; | |
19 | + | |
20 | + std::string PlotFunctionNode::_key = PanelPlotNodeRegistry::getInstance().addElement( | |
21 | + NODENAME, boost::shared_ptr<PlotFunctionNode>(new PlotFunctionNode())); | |
22 | + | |
23 | + PlotFunctionNode::PlotFunctionNode() : AbstractPanelPlotNode() | |
24 | + { | |
25 | + getChildList()["legends"] = AMDA::XMLConfigurator::NodeCfgSPtr( | |
26 | + new PlotLegendNode()); | |
27 | + getChildList()["params"] = AMDA::XMLConfigurator::NodeCfgSPtr( | |
28 | + new ParamsNode<PlotFunction>()); | |
29 | + getChildList()["axes"] = AMDA::XMLConfigurator::NodeCfgSPtr(new AxesNode()); | |
30 | + } | |
31 | + | |
32 | + PlotFunctionNode::~PlotFunctionNode() | |
33 | + { | |
34 | + } | |
35 | + | |
36 | + boost::shared_ptr<PanelPlotOutput> PlotFunctionNode::proceed(xmlNodePtr pNode_, | |
37 | + PlotOutput *plotManager_, Panel *panel_) | |
38 | + { | |
39 | + | |
40 | + LOG4CXX_DEBUG(gLogger, "PlotFunctionNode::proceed"); | |
41 | + boost::shared_ptr<PlotFunction> plot( | |
42 | + new PlotFunction(plotManager_->getParameterManager(), | |
43 | + boost::shared_ptr<Panel>(panel_))); | |
44 | + | |
45 | + // Copy default pages values for the panel if not already specified | |
46 | + if (panel_->_leftMargin == -1) | |
47 | + panel_->_leftMargin = panel_->_page->_defaultXYPlotLeftMargin; | |
48 | + if (panel_->_rightMargin == -1) | |
49 | + panel_->_rightMargin = panel_->_page->_defaultXYPlotRightMargin; | |
50 | + if (panel_->_topMargin == -1) | |
51 | + panel_->_topMargin = panel_->_page->_defaultXYPlotTopMargin; | |
52 | + if (panel_->_bottomMargin == -1) | |
53 | + panel_->_bottomMargin = panel_->_page->_defaultXYPlotBottomMargin; | |
54 | + | |
55 | + if (panel_->_preferedWidth == -1) | |
56 | + panel_->_preferedWidth = panel_->_page->_defaultXYPlotWidth; | |
57 | + if (panel_->_preferedHeight == -1) | |
58 | + panel_->_preferedHeight = panel_->_page->_defaultXYPlotHeight; | |
59 | + | |
60 | + // Read PlotFunction attributes | |
61 | + xmlChar *value; | |
62 | + value = xmlGetProp(pNode_, (const xmlChar *)PlotFunctuion_Type); | |
63 | + if (value) | |
64 | + { | |
65 | + const char *valueString = (const char *)value; | |
66 | + if (strcmp(valueString, PlotFunctuion_Type_SUM) == 0) | |
67 | + plot->setFunction(PlotFunction::Function::SUM); | |
68 | + else if (strcmp(valueString, PlotFunctuion_Type_FFT) == 0) | |
69 | + plot->setFunction(PlotFunction::Function::FFT); | |
70 | + else | |
71 | + plot->setFunction(PlotFunction::Function::NONE); | |
72 | + xmlFree(value); | |
73 | + } | |
74 | + | |
75 | + value = xmlGetProp(pNode_, (const xmlChar *)PlotFunction_Abscisse); | |
76 | + if (value && plot->getFunction() == PlotFunction::Function::FFT) | |
77 | + { | |
78 | + const char *valueString = (const char *)value; | |
79 | + if (strcmp(valueString, PlotFunction_Abscisse_Frequency) == 0) | |
80 | + { | |
81 | + Abscisse abscisse("Freq. ", "(Hz)", Abscisse::Abscisse_Type::FREQUENCY); | |
82 | + plot->setAbscisse(abscisse); | |
83 | + } | |
84 | + else if (strcmp(valueString, PlotFunction_Abscisse_Period) == 0) | |
85 | + { | |
86 | + Abscisse abscisse("Period. ", "(S)", Abscisse::Abscisse_Type::PERIOD); | |
87 | + plot->setAbscisse(abscisse); | |
88 | + } | |
89 | + | |
90 | + xmlFree(value); | |
91 | + } | |
92 | + else | |
93 | + { | |
94 | + Abscisse abscisse("Time, ", "UT", Abscisse::Abscisse_Type::TIME); | |
95 | + plot->setAbscisse(abscisse); | |
96 | + } | |
97 | + | |
98 | + value = xmlGetProp(pNode_, (const xmlChar *)PlotFunctuion_Params_Nb_Points); | |
99 | + if (value) | |
100 | + { | |
101 | + const char *newValueBrut = (char *)value; | |
102 | + std::string newValue = std::str(newValueBrut); | |
103 | + plot->setParamsNbPoints(newValue); | |
104 | + xmlFree(value); | |
105 | + } | |
106 | + | |
107 | + value = xmlGetProp(pNode_, (const xmlChar *)PlotFunction_Scale_Abscisse); | |
108 | + if (value) | |
109 | + { | |
110 | + const char *valueAbscisseScale = (char *)value; | |
111 | + if (strcmp(valueAbscisseScale, PlotFunction_Linear) == 0) | |
112 | + plot->setAbscisseScale(Axis::Scale::LINEAR); | |
113 | + else if (strcmp(valueAbscisseScale, PlotFunction_Log) == 0) | |
114 | + plot->setAbscisseScale(Axis::Scale::LOGARITHMIC); | |
115 | + | |
116 | + LOG4CXX_DEBUG(gLogger, valueAbscisseScale); | |
117 | + LOG4CXX_DEBUG(gLogger, plot->getAbscisseScale()); | |
118 | + xmlFree(value); | |
119 | + } | |
120 | + | |
121 | + value = xmlGetProp(pNode_, (const xmlChar *)PlotFunction_Scale_Ordonnee); | |
122 | + if (value) | |
123 | + { | |
124 | + const char *valueOrdonneeScale = (char *)value; | |
125 | + if (strcmp(valueOrdonneeScale, PlotFunction_Linear) == 0) | |
126 | + plot->setOrdonneeScale(Axis::Scale::LINEAR); | |
127 | + | |
128 | + else if (strcmp(valueOrdonneeScale, PlotFunction_Log) == 0) | |
129 | + plot->setOrdonneeScale(Axis::Scale::LOGARITHMIC); | |
130 | + LOG4CXX_DEBUG(gLogger, valueOrdonneeScale); | |
131 | + LOG4CXX_DEBUG(gLogger, plot->getOrdonneeScale()); | |
132 | + xmlFree(value); | |
133 | + } | |
134 | + else | |
135 | + { | |
136 | + LOG4CXX_DEBUG(gLogger, "non value"); | |
137 | + } | |
138 | + | |
139 | + AMDA::Parameters::CfgContext context; | |
140 | + context.push<PanelPlotOutput *>(plot.get()); | |
141 | + context.push<PlotFunction *>(plot.get()); | |
142 | + context.push<Panel *>(panel_); | |
143 | + AMDA::XMLConfigurator::NodeGrpCfg::proceed(pNode_, context); | |
144 | + | |
145 | + return plot; | |
146 | + } | |
147 | + | |
148 | +} /* namespace plot */ | ... | ... |
src/ParamOutputImpl/Plot/InstantPlot/PlotFunctionNode.hh
0 → 100644
... | ... | @@ -0,0 +1,57 @@ |
1 | + | |
2 | +#ifndef PlotFunctionNODE_HH_ | |
3 | +#define PlotFunctionNODE_HH_ | |
4 | + | |
5 | +#include <boost/smart_ptr/shared_ptr.hpp> | |
6 | +#include <libxml/tree.h> | |
7 | + | |
8 | +#include "AbstractPanelPlotNode.hh" | |
9 | +#include "Panel.hh" | |
10 | +#include "PanelPlotOutput.hh" | |
11 | +#include "PlotOutput.hh" | |
12 | + | |
13 | +namespace plot | |
14 | +{ | |
15 | +/** | |
16 | + * xml node name, this name is used in both config and request xml files. | |
17 | + */ | |
18 | +#define PlotFunction_NODENAME "plotFunction" | |
19 | +#define PlotFunction_Abscisse "abscisse" | |
20 | +#define PlotFunction_Scale_Abscisse "scale_abscisse" | |
21 | +#define PlotFunction_Scale_Ordonnee "scale_ordonnee" | |
22 | +#define PlotFunction_Abscisse_Frequency "Frequency" | |
23 | +#define PlotFunction_Abscisse_Period "Period" | |
24 | +#define PlotFunction_Abscisse_Time "Time" | |
25 | +#define PlotFunctuion_Type "type" | |
26 | +#define PlotFunctuion_Type_FFT "FFT" | |
27 | +#define PlotFunctuion_Type_SUM "SUM" | |
28 | +#define PlotFunctuion_Params_Nb_Points "param_nb_points" | |
29 | +#define PlotFunction_Linear "Linear" | |
30 | +#define PlotFunction_Log "Log" | |
31 | + | |
32 | + class PlotFunctionNode : public plot::AbstractPanelPlotNode | |
33 | + { | |
34 | + public: | |
35 | + PlotFunctionNode(); | |
36 | + virtual ~PlotFunctionNode(); | |
37 | + | |
38 | + protected: | |
39 | + /** | |
40 | + * @overload plot::AbstractPanelPlotNode::proceed | |
41 | + */ | |
42 | + boost::shared_ptr<PanelPlotOutput> proceed(xmlNodePtr, PlotOutput *, Panel *); | |
43 | + | |
44 | + private: | |
45 | + /** | |
46 | + * constant to uniquely identify this node in the registry | |
47 | + */ | |
48 | + static const std::string NODENAME; | |
49 | + /** | |
50 | + * artificial special attribute to force registering node. | |
51 | + */ | |
52 | + static std::string _key; | |
53 | + }; | |
54 | + | |
55 | +} // namespace plot | |
56 | + | |
57 | +#endif /* TIMEPLOTNODE_HH_ */ | ... | ... |