Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 29.2 KB
fbe3c2bb   Benjamin Renard   First commit
1
#include "AxisLegendManager.hh"
07bf1e7c   Menouard AZIB   EveryThing works ...
2
3
#include <iostream> // std::cout
#include <string>
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
4
#include <vector>
fbe3c2bb   Benjamin Renard   First commit
5

fbe3c2bb   Benjamin Renard   First commit
6
7
using namespace AMDA::Info;

07bf1e7c   Menouard AZIB   EveryThing works ...
8
9
namespace plot
{
fbe3c2bb   Benjamin Renard   First commit
10

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
11
    void AxisLegendManager::configureXAxisLegendForSeries(
7c94ae0d   Erdogan Furkan   For now, histo1d ...
12
        PanelPlotOutput *plot)
07bf1e7c   Menouard AZIB   EveryThing works ...
13
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
14
15
        // Build list of all indexes used by each parameters for each x axes
        std::map<std::string, AxisParamsComponents> axesParamsComponents;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
16

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
17
18
        // Compute nb series to draw by y axis
        std::map<std::string, int> nbSeriesByYAxisMap = plot->getNbSeriesByYAxis();
21ddb9f2   Benjamin Renard   Set legend color ...
19

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
20
        SeriesProperties lSeriesProperties;
07bf1e7c   Menouard AZIB   EveryThing works ...
21
22
        for (auto param : plot->_parameterAxesList)
        {
05089f4a   Erdogan Furkan   #11376 - Done.
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
            for (auto pHistogramProperties : param.getHistogramSeriesPropertiesList())
            {
                if(pHistogramProperties != nullptr){
                    std::string xParamId = "";
                    AMDA::Common::ParameterIndexComponent xIndexComp;

                    if(pHistogramProperties->getHistogramType() == "histogram1d"){
                        if (!pHistogramProperties->hasXAxis())
                            continue;
                        xIndexComp = pHistogramProperties->getIndex();
                        xParamId = pHistogramProperties->getParamId();
                        
                    }
                    if(pHistogramProperties->getHistogramType() == "histogram2d"){
                        if (!pHistogramProperties->hasYAxis() || !pHistogramProperties->hasXAxis())
                            continue;
                        ParameterAxes *xParameter = plot->getParameterAxesByXSerieId(pHistogramProperties->getXId());
                        XSeriesProperties xSerie = xParameter->getXSeriePropertiesById(pHistogramProperties->getXId());
                        xIndexComp = xSerie.getIndex();
                        xParamId = xSerie.getParamId();
                    }
1248af2b   Erdogan Furkan   Refactored, all w...
44
                    
05089f4a   Erdogan Furkan   #11376 - Done.
45
46
47
48
                    std::string xAxisId = pHistogramProperties->getXAxisId();
                    boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
                    if (lXAxis.get() == nullptr)
                    {
1248af2b   Erdogan Furkan   Refactored, all w...
49
                        continue;
05089f4a   Erdogan Furkan   #11376 - Done.
50
51
52
53
54
55
                    }
                    Color compLegendColor = lXAxis->_color;
                    if(param.getHistogramSeriesPropertiesList().size() > 0)
                        compLegendColor = pHistogramProperties->getColor();
                    ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(xIndexComp, compLegendColor);
                    pushComponentInList(xParamId, xIndex, axesParamsComponents[xAxisId]);
7c94ae0d   Erdogan Furkan   For now, histo1d ...
56
                }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
57
58
            }

07bf1e7c   Menouard AZIB   EveryThing works ...
59
60
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
61
62
                if (!lSeriesProperties.hasYAxis() || !lSeriesProperties.hasXAxis())
                    continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
63

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
64
                bool moreThanOneSerieForAxis = (nbSeriesByYAxisMap[lSeriesProperties.getYAxisId()] > 1);
21ddb9f2   Benjamin Renard   Set legend color ...
65

07bf1e7c   Menouard AZIB   EveryThing works ...
66
                ParameterAxes *xParameter = plot->getParameterAxesByXSerieId(lSeriesProperties.getXId());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
67

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
68
                XSeriesProperties xSerie = xParameter->getXSeriePropertiesById(lSeriesProperties.getXId());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
69

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
70
                std::string xAxisId = lSeriesProperties.getXAxisId();
5ee90a58   Benjamin Renard   Use AxisLegendMan...
71

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
72
                boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
07bf1e7c   Menouard AZIB   EveryThing works ...
73
74
                if (lXAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
75
76
77
78
                    continue;
                }

                Color compLegendColor = lXAxis->_color;
07bf1e7c   Menouard AZIB   EveryThing works ...
79
80
                if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode))
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
81
82
83
84
85
86
87
88
                    compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
                }

                ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(xSerie.getIndex(), compLegendColor);
                pushComponentInList(xSerie.getParamId(), xIndex, axesParamsComponents[xAxisId]);
            }
        }

07bf1e7c   Menouard AZIB   EveryThing works ...
89
90
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
91
92
93
94
            plot->resetAutomaticSerieColorCursor();
        }

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
95
96
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
97
98
99
100
101
102
            boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(axisParamsComponents.first);
            setAxisLegendForSeries(plot, lXAxis, axisParamsComponents.second);
        }
    }

    void AxisLegendManager::configureYAxisLegendForSpectro(
07bf1e7c   Menouard AZIB   EveryThing works ...
103
104
105
106
        PanelPlotOutput *plot)
    {
        for (auto param : plot->_parameterAxesList)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
107
108
            std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
            if (spectroPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
109
                continue; // no spectro defined
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127

            if (!spectroPropertiesPtr->hasYAxis())
                continue;

            std::string yAxisId = spectroPropertiesPtr->getYAxisId();
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
            if (lYAxis.get() == nullptr)
                continue;

            if (!lYAxis->_legend.isEmpty())
                continue;

            setAxisLegendForTable(plot, lYAxis, param._originalParamId, spectroPropertiesPtr->getParamId(), spectroPropertiesPtr->getIndexes(), spectroPropertiesPtr->getRelatedDim());
            return;
        }
    }

    void AxisLegendManager::configureYAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
128
129
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
130
        SeriesProperties lSeriesProperties;
4bced76d   Furkan   #11372 - Adding n...
131
        std::string yAxisTextLegend;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
132
133
134
135
136
        // Compute nb series to draw by y axis
        std::map<std::string, int> nbSeriesByYAxisMap = plot->getNbSeriesByYAxis();

        // Build list of all indexes used by each parameters for each y axes
        std::map<std::string, AxisParamsComponents> axesParamsComponents;
bec89e22   Erdogan Furkan   Fixes + refactori...
137
        std::map<std::string, AxisParamsComponents> axesHistoParamsComponents;
07bf1e7c   Menouard AZIB   EveryThing works ...
138
139
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
140
141
            plot->resetAutomaticSerieColorCursor();
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
142
143
        for (auto param : plot->_parameterAxesList)
        {
05089f4a   Erdogan Furkan   #11376 - Done.
144
145
146
147
148
            for (auto pHistogramProperties : param.getHistogramSeriesPropertiesList())
            {
                if(pHistogramProperties != nullptr){
                    if (!pHistogramProperties->hasYAxis())
                        continue;
1248af2b   Erdogan Furkan   Refactored, all w...
149

05089f4a   Erdogan Furkan   #11376 - Done.
150
151
152
153
154
155
                    std::string yAxisId = pHistogramProperties->getYAxisId();
                    boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
                    if (lYAxis.get() == nullptr)
                    {
                        continue;
                    }
650942c4   Erdogan Furkan   #11372 - Done.
156
157
                    std::string yParamId ;
                    AMDA::Common::ParameterIndexComponent yIndexComp;
05089f4a   Erdogan Furkan   #11376 - Done.
158
                    if(pHistogramProperties->getHistogramType() == "histogram1d"){
650942c4   Erdogan Furkan   #11372 - Done.
159
160
                        yParamId =  pHistogramProperties->getHistotypeProperties().getParamId();
                        yIndexComp = AMDA::Common::ParameterIndexComponent(pHistogramProperties->getHistotypeProperties().getIndex(), -1);
bec89e22   Erdogan Furkan   Fixes + refactori...
161
162
                        yAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
                        
4bced76d   Furkan   #11372 - Adding n...
163
164
165
166
167
168
                        if(pHistogramProperties->getHistotypeProperties().getParamId().empty())
                        {
                            Label yLabel(lYAxis->_legend.getFont(),lYAxis->_color);
                            yLabel._text = yAxisTextLegend;
                            lYAxis->_legend.setLabel(yLabel);
                            continue;
650942c4   Erdogan Furkan   #11372 - Done.
169
                        }                  
05089f4a   Erdogan Furkan   #11376 - Done.
170
                    }
650942c4   Erdogan Furkan   #11372 - Done.
171
172
173
174
175
176
177
178
179
180
                    else if (pHistogramProperties->getHistogramType() == "histogram2d"){
                        yParamId = pHistogramProperties->getParamId();
                        yIndexComp = pHistogramProperties->getIndex();
                    }

                    Color compLegendColor = lYAxis->_color;
                    if(param.getHistogramSeriesPropertiesList().size() > 0)
                        compLegendColor = pHistogramProperties->getColor();
                    ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(yIndexComp, compLegendColor);
                    pushComponentInList(yParamId, yIndex, axesHistoParamsComponents[yAxisId]);
1248af2b   Erdogan Furkan   Refactored, all w...
181
                }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
182
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
183
184
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
185
186
187
188
189
190
191
                if (!lSeriesProperties.hasYAxis())
                    continue;

                bool moreThanOneSerieForAxis = (nbSeriesByYAxisMap[lSeriesProperties.getYAxisId()] > 1);

                std::string yAxisId = lSeriesProperties.getYAxisId();
                boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
07bf1e7c   Menouard AZIB   EveryThing works ...
192
193
                if (lYAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
194
195
196
                    continue;
                }

07bf1e7c   Menouard AZIB   EveryThing works ...
197
198
                for (auto index : lSeriesProperties.getIndexList(plot->_pParameterValues))
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
199
                    Color compLegendColor = lYAxis->_color;
07bf1e7c   Menouard AZIB   EveryThing works ...
200
201
                    if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode))
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
202
203
204
205
206
207
208
                        compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
                    }
                    ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(index, compLegendColor);
                    pushComponentInList(lSeriesProperties.getParamId(), yIndex, axesParamsComponents[yAxisId]);
                }
            }
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
209
210
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
211
212
213
214
            plot->resetAutomaticSerieColorCursor();
        }

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
215
216
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
217
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisParamsComponents.first);
4bced76d   Furkan   #11372 - Adding n...
218
            setAxisLegendForSeries(plot, lYAxis, axisParamsComponents.second,yAxisTextLegend);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
219
        }
bec89e22   Erdogan Furkan   Fixes + refactori...
220
221
222
223
224
225
        for (auto axisHistoParamsComponents : axesHistoParamsComponents)
        {
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisHistoParamsComponents.first);
            setAxisLegendForSeries(plot, lYAxis, axisHistoParamsComponents.second, yAxisTextLegend );
            
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
226
227
228
    }

    void AxisLegendManager::configureColorAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
229
230
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
231
232
233
        SeriesProperties lSeriesProperties;
        ColorSeriesProperties lColorSerieProperties;
        boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();
97f9b74e   Erdogan Furkan   #10776 - Density ...
234
        std::string zAxisTextLegend = "";
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
235

07bf1e7c   Menouard AZIB   EveryThing works ...
236
237
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
238
239
240
241
242
            return;
        }

        // Build list of all indexes used by each parameters for each y axes
        AxisParamsComponents axisParamsComponents;
07bf1e7c   Menouard AZIB   EveryThing works ...
243
244
        for (auto param : plot->_parameterAxesList)
        {
05089f4a   Erdogan Furkan   #11376 - Done.
245
246
247
248
249
            for (auto pHistogramProperties : param.getHistogramSeriesPropertiesList())
            {
                if(pHistogramProperties != nullptr){
                    if (!pHistogramProperties->hasYAxis())
                        continue;
97f9b74e   Erdogan Furkan   #10776 - Density ...
250

05089f4a   Erdogan Furkan   #11376 - Done.
251
                    if(pHistogramProperties->getHistogramType() == "histogram1d" )
650942c4   Erdogan Furkan   #11372 - Done.
252
                        continue;
05089f4a   Erdogan Furkan   #11376 - Done.
253
254
255
256
257
258
                    if(pHistogramProperties->getHistogramType() == "histogram2d" )
                        zAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto2DFunction()->getTextLegend();
                    // check if a colored param is defined for this serie
                    if (pHistogramProperties->getHistotypeProperties().getParamId().empty()){
                        Label zLabel(lZAxis->_legend.getFont(),lZAxis->_color);
                        zLabel._text = zAxisTextLegend;
5a5d916f   Erdogan Furkan   Histograms : fixi...
259
                        lZAxis->_legend.setLabel(zLabel);
05089f4a   Erdogan Furkan   #11376 - Done.
260
261
                        continue;
                    }
97f9b74e   Erdogan Furkan   #10776 - Density ...
262

05089f4a   Erdogan Furkan   #11376 - Done.
263
264
265
266
267
                    ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
                    if (pHistogramProperties->getHistotypeProperties().getIndex() > -1)
                        colorSerieIndex = ParameterIndexComponentColor(pHistogramProperties->getHistotypeProperties().getIndex(), -1, lZAxis->_color);
                    pushComponentInList(pHistogramProperties->getHistotypeProperties().getParamId(), colorSerieIndex, axisParamsComponents);
                }
97f9b74e   Erdogan Furkan   #10776 - Density ...
268
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
269
270
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
271
272
273
274
275
                if (!lSeriesProperties.hasYAxis())
                    continue;

                std::string yParamId = lSeriesProperties.getParamId();

07bf1e7c   Menouard AZIB   EveryThing works ...
276
                // check if a colored param is defined for this serie
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
277
278
279
                if (lSeriesProperties.getColorParamId().empty())
                    continue;

07bf1e7c   Menouard AZIB   EveryThing works ...
280
                ParameterAxes *colorSerieParameterAxes = plot->getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
281
282
283
284
285
286
287
288
289
290
291
292
293

                if (colorSerieParameterAxes == NULL)
                    continue;

                lColorSerieProperties = colorSerieParameterAxes->getColorSeriePropertiesById(lSeriesProperties.getColorSerieId());

                ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
                if (lColorSerieProperties.getIndex() > -1)
                    colorSerieIndex = ParameterIndexComponentColor(lColorSerieProperties.getIndex(), -1, lZAxis->_color);
                pushComponentInList(lColorSerieProperties.getColorParamIds()[yParamId], colorSerieIndex, axisParamsComponents);
            }
        }

97f9b74e   Erdogan Furkan   #10776 - Density ...
294
        setAxisLegendForSeries(plot, lZAxis, axisParamsComponents, zAxisTextLegend);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
295
296
297
    }

    void AxisLegendManager::configureColorAxisLegendForSpectro(
07bf1e7c   Menouard AZIB   EveryThing works ...
298
299
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
300
301
        boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();

07bf1e7c   Menouard AZIB   EveryThing works ...
302
303
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
304
305
            return;
        }
5ee90a58   Benjamin Renard   Use AxisLegendMan...
306

07bf1e7c   Menouard AZIB   EveryThing works ...
307
308
        for (auto param : plot->_parameterAxesList)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
309
310
            std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
            if (spectroPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
311
                continue; // no spectro defined
21ddb9f2   Benjamin Renard   Set legend color ...
312

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
313
314
            if (!spectroPropertiesPtr->hasZAxis())
                continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
315

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
316
317
318
            setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
            break;
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
319
320
321

        for (auto param : plot->_parameterAxesList)
        {
b0205fd9   Hacene SI HADJ MOHAND   plot ok reste que...
322
323
            std::shared_ptr<SauvaudProperties> sauvaudPropertiesPtr = param.getSauvaudProperties();
            if (sauvaudPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
324
                continue; // no sauvaud defined
b0205fd9   Hacene SI HADJ MOHAND   plot ok reste que...
325
326
327
328
329
330
331

            if (!sauvaudPropertiesPtr->hasZAxis())
                continue;

            setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
            break;
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
332
333
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
334
335
336
337
338
    void AxisLegendManager::pushComponentInList(std::string paramId, ParameterIndexComponentColor &index, AxisParamsComponents &axisParamsComponents)
    {
        if (index.getDim1Index() == -1 && index.getDim2Index() == -1)
        {
            // All indexes of this parameter are used
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
339
340
            axisParamsComponents[paramId].clear();
            axisParamsComponents[paramId].push_back(index);
07bf1e7c   Menouard AZIB   EveryThing works ...
341
342
343
344
345
346
347
348
        }
        else
        {
            if (axisParamsComponents[paramId].size() > 0)
            {
                if (axisParamsComponents[paramId].front().getDim1Index() == -1 && axisParamsComponents[paramId].front().getDim2Index() == -1)
                {
                    // Skip. All components already defined for this paramter on this axis
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
349
350
351
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
352
353
354
355
356
            for (auto crtIndex : axisParamsComponents[paramId])
            {
                if ((crtIndex.getDim1Index() == index.getDim1Index()) && (crtIndex.getDim2Index() == index.getDim2Index()))
                {
                    // Component already exists
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
357
358
359
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
360
            // Add this components for this axis
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
361
362
            axisParamsComponents[paramId].push_back(index);
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
363
364
    }

97f9b74e   Erdogan Furkan   #10776 - Density ...
365
366
    void AxisLegendManager::setAxisLegendForSeries(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, AxisParamsComponents &axisParamsComponents, 
                                                    std::string legendPrefix)
07bf1e7c   Menouard AZIB   EveryThing works ...
367
368
369
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
370
371
372
373
            return;
        }

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
374
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
375

07bf1e7c   Menouard AZIB   EveryThing works ...
376
377
        for (auto paramsComponents : axisParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
378
            ParameterSPtr p = plot->_parameterManager.getParameter(paramsComponents.first);
7c94ae0d   Erdogan Furkan   For now, histo1d ...
379
380
            if (p == nullptr)
                continue;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
381
            ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
07bf1e7c   Menouard AZIB   EveryThing works ...
382
383
384
            if (paramsComponents.second.size() == p->getDataWriterTemplate()->getParamData()->getDim1() * p->getDataWriterTemplate()->getParamData()->getDim2())
            {
                // All components of this parameter are used by this axis => merge
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
385
386
387
388
389
                Color color = paramsComponents.second.front().getColor();
                paramsComponents.second.clear();
                paramsComponents.second.push_back(ParameterIndexComponentColor(-1, -1, color));
            }
            bool isFirstComponent = true;
07bf1e7c   Menouard AZIB   EveryThing works ...
390
391
            for (auto components : paramsComponents.second)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
392
393
394
                if (paramInfo == nullptr)
                    continue;
                Label label(pAxis->_legend.getFont(), components.getColor());
07bf1e7c   Menouard AZIB   EveryThing works ...
395
396
397
398
                if (axisParamsComponents.size() == 1)
                {
                    if (isFirstComponent)
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
399
                        std::string info = getMissionInstrumentInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
400
401
                        if (!info.empty())
                        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
402
403
404
405
                            label._text = info;
                            addBreakLine(label._text);
                        }
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
406
407
408
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
409
                    std::string info = getMissionInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
410
411
                    if (!info.empty())
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
412
413
414
                        label._text = info + ", ";
                    }
                }
97f9b74e   Erdogan Furkan   #10776 - Density ...
415
                label._text += legendPrefix;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
416
417
418
419
420
421
422
                label._text += getParamLegend(paramInfo, components);
                pAxis->_legend.pushLabel(label);
                isFirstComponent = false;
            }
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
423
424
425
426
    void AxisLegendManager::setAxisLegendForSpectro(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, std::string originalParamId)
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
427
428
429
430
            return;
        }

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
431
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
432
433
434
435
436

        ParameterSPtr p = plot->_parameterManager.getParameter(originalParamId);
        AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
        if (paramInfo == nullptr)
            return;
21ddb9f2   Benjamin Renard   Set legend color ...
437

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
438
439
440
441
442
443
        Label label(pAxis->_legend.getFont(), pAxis->_legend.getColor());
        addInfoPart(label._text, paramInfo->getShortName());
        addInfoPart(label._text, getTransformedUnits(paramInfo->getUnits()));
        pAxis->_legend.setLabel(label);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
444
445
446
447
    void AxisLegendManager::setAxisLegendForTable(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, std::string originalParamId, std::string paramId, AMDA::Common::ParameterIndexComponentList &indexes, int relatedDim)
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
448
            return;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
449
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
450
451

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
452
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
453
454
455
456
457
458
459
460
461

        ParameterSPtr p = plot->_parameterManager.getParameter(originalParamId);
        AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());

        if (paramInfo == nullptr)
            return;

        Label label(pAxis->_legend.getFont(), pAxis->_legend.getColor());
        std::string info = getMissionInstrumentInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
462
463
        if (!info.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
464
465
466
467
468
469
            addInfoPart(label._text, info);
            addBreakLine(label._text);
        }

        boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
        tableSPtr = paramInfo->getTable(relatedDim);
07bf1e7c   Menouard AZIB   EveryThing works ...
470
471
472

        if (tableSPtr == nullptr)
        {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
473
474
475
            // look for unique embedded table
            boost::shared_ptr<AMDA::Info::ParamTable> linkedTableSPtr;
            int counter = 0;
07bf1e7c   Menouard AZIB   EveryThing works ...
476
477
            for (auto pInfo : paramInfo->getLinkedParamList())
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
478
479
480
                linkedTableSPtr = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(pInfo)->getTable(relatedDim);
                if (linkedTableSPtr == nullptr)
                    continue;
07bf1e7c   Menouard AZIB   EveryThing works ...
481
                counter++;
0831b2cf   Hacene SI HADJ MOHAND   axis legend
482
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
483
484
            if (linkedTableSPtr == nullptr || counter != 1)
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
485
                LOG4CXX_DEBUG(gLogger, "table cannot be defined from linked info params");
07bf1e7c   Menouard AZIB   EveryThing works ...
486
487
488
            }
            else
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
489
490
                tableSPtr = linkedTableSPtr;
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
491
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
492

07bf1e7c   Menouard AZIB   EveryThing works ...
493
494
        if (tableSPtr == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
495
496
497
498
499
500
501
502
503
            std::string tableInfo = "Table ";
            tableInfo += std::to_string(relatedDim);
            tableInfo += " indexes";
            addInfoPart(label._text, tableInfo);
            pAxis->_legend.pushLabel(label);
            return;
        }

        if (((*plot->_pParameterValues)[paramId].getDim1Size() > 0) &&
07bf1e7c   Menouard AZIB   EveryThing works ...
504
505
506
            ((*plot->_pParameterValues)[paramId].getDim2Size() > 0) &&
            !indexes.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
507
508
            boost::shared_ptr<AMDA::Info::ParamTable> otherTableSPtr;
            int otherDimIndex;
07bf1e7c   Menouard AZIB   EveryThing works ...
509
510
            if (relatedDim == 0)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
511
512
                otherTableSPtr = paramInfo->getTable(1);
                otherDimIndex = indexes.front().getDim2Index();
07bf1e7c   Menouard AZIB   EveryThing works ...
513
514
515
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
516
517
518
                otherTableSPtr = paramInfo->getTable(0);
                otherDimIndex = indexes.front().getDim1Index();
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
519
520
            if ((otherTableSPtr != nullptr) && !otherTableSPtr->isVariable(&plot->_parameterManager))
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
521
522
523
524
525
526
527
528
529
                if (otherTableSPtr->getName(&plot->_parameterManager).empty())
                    addInfoPart(label._text, "Table bounds");
                else
                    addInfoPart(label._text, otherTableSPtr->getName(&plot->_parameterManager));

                AMDA::Info::t_TableBound crtBound = otherTableSPtr->getBound(&plot->_parameterManager, otherDimIndex);
                addBoundsPart(label._text, crtBound.min, crtBound.max);
                std::string rawUnit = otherTableSPtr->getUnits(&plot->_parameterManager);
                addInfoPart(label._text, getTransformedUnits(rawUnit));
07bf1e7c   Menouard AZIB   EveryThing works ...
530
531
532
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
533
534
535
536
537
538
539
540
541
542
543
544
                std::string part = "Table Index: ";
                part += std::to_string(otherDimIndex);
                addInfoPart(label._text, part);
            }
            addBreakLine(label._text);
        }
        addInfoPart(label._text, tableSPtr->getName(&plot->_parameterManager));
        std::string rawUnit = tableSPtr->getUnits(&plot->_parameterManager);
        addInfoPart(label._text, getTransformedUnits(rawUnit));
        pAxis->_legend.pushLabel(label);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
545
546
547
548
549
550
551
552
553
554
    void AxisLegendManager::addInfoPart(std::string &legend, std::string info)
    {
        if (!info.empty())
        {
            if (!legend.empty())
            {
                if (legend.length() >= Label::DELIMITER.length())
                {
                    if (legend.compare(legend.length() - Label::DELIMITER.length(), Label::DELIMITER.length(), Label::DELIMITER) != 0)
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
555
556
                        legend += ", ";
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
557
558
559
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
560
561
562
563
564
565
566
                    legend += ", ";
                }
            }
            legend += info;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
567
568
    void AxisLegendManager::addIndexPart(std::string &legend, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
569
570
        legend += "[";
        legend += std::to_string(index.getDim1Index());
07bf1e7c   Menouard AZIB   EveryThing works ...
571
572
        if (index.getDim2Index() != -1)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
573
574
575
576
577
578
            legend += ",";
            legend += std::to_string(index.getDim2Index());
        }
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
579
580
    void AxisLegendManager::addIndexPart(std::string &legend, int index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
581
582
583
584
585
        legend += "[";
        legend += std::to_string(index);
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
586
587
    void AxisLegendManager::addBoundsPart(std::string &legend, PLFLT min, PLFLT max)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
588
589
590
591
592
        legend += " ";

        char minCount[1024];
        char maxCount[1024];

b358ee7d   Benjamin Renard   Adapt axes labels...
593
        int precision = computeScientificFormatPrecision(min, max);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
594

3371b1c8   Erdogan Furkan   #11199 - done
595
596
        getDigitalLabel(min, precision, minCount, 1024, min, max);
        getDigitalLabel(max, precision, maxCount, 1024, min, max);
fbe3c2bb   Benjamin Renard   First commit
597

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
598
599
600
601
602
        legend += std::string(minCount);
        legend += ", ";
        legend += std::string(maxCount);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
603
604
605
606
    void AxisLegendManager::addBreakLine(std::string &legend)
    {
        if (!legend.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
607
608
609
610
            legend += Label::DELIMITER;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
611
612
    std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
613
614
615
        std::string legend;
        addInfoPart(legend, paramInfo->getShortName());

07bf1e7c   Menouard AZIB   EveryThing works ...
616
617
        if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1))
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
618
619
620
            AMDA::Common::ParameterIndexComponent paramIndex(index.getDim1Index(), index.getDim2Index());
            if (paramInfo->getComponents(paramIndex).empty() == false)
                addInfoPart(legend, paramInfo->getComponents(paramIndex));
07bf1e7c   Menouard AZIB   EveryThing works ...
621
622
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
623
624
625
                addInfoPart(legend, paramInfo->getShortName());
                addIndexPart(legend, index);
            }
c2fa3b5d   Benjamin Renard   Rework of legend ...
626
627
        }

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
628
        addInfoPart(legend, getTransformedUnits(paramInfo->getUnits()));
c2fa3b5d   Benjamin Renard   Rework of legend ...
629
        addInfoPart(legend, paramInfo->getCoordinatesSystem());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
630

c2fa3b5d   Benjamin Renard   Rework of legend ...
631
        return legend;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
    }

    /*std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, int index) {
            std::string legend;
            addInfoPart(legend, paramInfo->getShortName());

            if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1)) {
                    if (paramInfo->getComponents(index).empty() == false)
                            addInfoPart(legend, paramInfo->getComponents(index));
                    else
                    {
                            addInfoPart(legend, paramInfo->getShortName());
                            addIndexPart(legend, index);
                    }
            }

            addInfoPart(legend, paramInfo->getUnits());
            addInfoPart(legend, paramInfo->getCoordinatesSystem());

            return legend;
    }*/

07bf1e7c   Menouard AZIB   EveryThing works ...
654
655
    std::string AxisLegendManager::getMissionInstrumentInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
656
657
658
659
660
661
662
663
        std::string info = paramInfo->getInstrumentId();
        if (info.empty())
            return info;
        std::replace(info.begin(), info.end(), '_', ' ');
        std::transform(info.begin(), info.end(), info.begin(), ::toupper);
        return info;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
664
665
    std::string AxisLegendManager::getMissionInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
666
667
668
        std::string info = paramInfo->getInstrumentId();
        if (info.empty())
            return info;
07bf1e7c   Menouard AZIB   EveryThing works ...
669
670
        if (info.find('_') != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
671
672
673
674
675
676
            info = info.substr(0, info.find('_'));
        }
        std::transform(info.begin(), info.end(), info.begin(), ::toupper);
        return info;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
677
678
    std::string AxisLegendManager::getTransformedUnits(const std::string &rawUnit)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
679
680
681
682
683
684
685
686
        std::string unit = rawUnit;
        if (unit.find("^"))
            unit = transformPower(unit, "^");
        if (unit.find("**"))
            unit = transformPower(unit, "**");
        return unit;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
687
688
    std::string AxisLegendManager::transformPower(std::string &unit, std::string pattern)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
689
690
691
        std::map<size_t, size_t> positions; // holds all the positions that pattern occurs within unit
        size_t pos_first = unit.find(pattern, 0);
        size_t pos_last;
07bf1e7c   Menouard AZIB   EveryThing works ...
692
693
        while (pos_first != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
694
695
            char afterPattern = unit[pos_first + pattern.length()];
            pos_last = pos_first + pattern.length();
07bf1e7c   Menouard AZIB   EveryThing works ...
696
697
698
699
700
701
702
703
            if (afterPattern == '+' || afterPattern == '-')
            {
                afterPattern = unit[pos_first + pattern.length() + 1];
                pos_last++;
            }
            if (afterPattern == '(')
            {
                pos_last = unit.find(")", pos_first + pattern.length()) + 1;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
704
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
705
706
707
            else if (afterPattern == '|')
            {
                pos_last = unit.find("|", pos_first + pattern.length() + 2) + 1;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
708
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
709
710
711
712
713
714
            else if (isdigit(afterPattern) || afterPattern == '.')
            {
                pos_last++;
                while (isdigit(unit[pos_last]) || unit[pos_last] == '.')
                {
                    pos_last++;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
715
                }
07bf1e7c   Menouard AZIB   EveryThing works ...
716
717
718
719
            }
            else
            {
                pos_last++;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
720
721
722
723
724
            }
            positions.insert(std::pair<size_t, size_t>(pos_first, pos_last));
            pos_first = unit.find(pattern, pos_first + pattern.length());
        }
        std::map<size_t, size_t>::reverse_iterator it;
07bf1e7c   Menouard AZIB   EveryThing works ...
725
726
        for (it = positions.rbegin(); it != positions.rend(); ++it)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
727
728
729
730
731
732
733
            unit.insert(it->second, "#d");
            unit.erase(it->first, pattern.length());
            unit.insert(it->first, "#u");
        }
        return unit;
    }

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