Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 29.4 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)
        {
97f9b74e   Erdogan Furkan   #10776 - Density ...
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
            std::shared_ptr<Histogram2DSeriesProperties> pHistogram2DProperties = param.getHistogram2DSeriesProperties() ;
            if(pHistogram2DProperties != nullptr){
                if (!pHistogram2DProperties->hasYAxis() || !pHistogram2DProperties->hasXAxis())
                    continue;
                ParameterAxes *xParameter = plot->getParameterAxesByXSerieId(pHistogram2DProperties->getXId());
                XSeriesProperties xSerie = xParameter->getXSeriePropertiesById(pHistogram2DProperties->getXId());

                std::string xAxisId = pHistogram2DProperties->getXAxisId();
                boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
                if (lXAxis.get() == nullptr)
                {
                    continue;
                }
                Color compLegendColor = lXAxis->_color;
                ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(xSerie.getIndex(), compLegendColor);
                pushComponentInList(xSerie.getParamId(), xIndex, axesParamsComponents[xAxisId]);
            }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

            std::shared_ptr<Histogram1DSeriesProperties> pHistogram1DProperties = param.getHistogram1DSeriesProperties() ;
            if(pHistogram1DProperties != nullptr){
                if (!pHistogram1DProperties->hasXAxis())
                    continue;
                std::string xAxisId = pHistogram1DProperties->getXAxisId();
                boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
                if (lXAxis.get() == nullptr)
                {
                    continue;
                }
                Color compLegendColor = lXAxis->_color;
                ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(param.getHistogram1DSeriesProperties()->getIndex(), compLegendColor);
                pushComponentInList(pHistogram1DProperties->getParamId(), xIndex, axesParamsComponents[xAxisId]);
            }

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

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

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

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

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

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

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

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

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

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

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

            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 ...
125
126
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
127
128
129
130
131
132
133
        SeriesProperties lSeriesProperties;

        // 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;
07bf1e7c   Menouard AZIB   EveryThing works ...
134
135
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
136
137
            plot->resetAutomaticSerieColorCursor();
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
138
139
        for (auto param : plot->_parameterAxesList)
        {
97f9b74e   Erdogan Furkan   #10776 - Density ...
140
141
142
143
144
145
146
147
148
149
            std::shared_ptr<Histogram2DSeriesProperties> pHistogram2DProperties = param.getHistogram2DSeriesProperties() ;
            if(pHistogram2DProperties != nullptr){
                if (!pHistogram2DProperties->hasYAxis())
                    continue;
                std::string yAxisId = pHistogram2DProperties->getYAxisId();
                boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
                Color compLegendColor = lYAxis->_color;
                ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(param.getHistogram2DSeriesProperties()->getIndex(), compLegendColor);
                pushComponentInList(pHistogram2DProperties->getParamId(), yIndex, axesParamsComponents[yAxisId]);
            }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
            std::shared_ptr<Histogram1DSeriesProperties> pHistogram1DProperties = param.getHistogram1DSeriesProperties() ;
            if(pHistogram1DProperties != nullptr){
                if (!pHistogram1DProperties->hasYAxis())
                    continue;
                std::string yAxisTextLegend = "";
                std::string yAxisId = pHistogram1DProperties->getYAxisId();
                boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
                if (lYAxis.get() == nullptr)
                {
                    continue;
                }
                yAxisTextLegend = pHistogram1DProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
                Label yLabel(lYAxis->_legend.getFont(),lYAxis->_color);
                yLabel._text = yAxisTextLegend;
                lYAxis->_legend.pushLabel(yLabel);
                
                Color compLegendColor = lYAxis->_color;
                ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(param.getHistogram1DSeriesProperties()->getIndex(), compLegendColor);
                pushComponentInList(pHistogram1DProperties->getParamId(), yIndex, axesParamsComponents[yAxisId]);
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
170
171
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
172
173
174
175
176
177
178
                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 ...
179
180
                if (lYAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
181
182
183
                    continue;
                }

07bf1e7c   Menouard AZIB   EveryThing works ...
184
185
                for (auto index : lSeriesProperties.getIndexList(plot->_pParameterValues))
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
186
                    Color compLegendColor = lYAxis->_color;
07bf1e7c   Menouard AZIB   EveryThing works ...
187
188
                    if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode))
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
189
190
191
192
193
194
195
                        compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
                    }
                    ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(index, compLegendColor);
                    pushComponentInList(lSeriesProperties.getParamId(), yIndex, axesParamsComponents[yAxisId]);
                }
            }
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
196
197
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
198
199
200
201
            plot->resetAutomaticSerieColorCursor();
        }

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
202
203
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
204
205
206
207
208
209
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisParamsComponents.first);
            setAxisLegendForSeries(plot, lYAxis, axisParamsComponents.second);
        }
    }

    void AxisLegendManager::configureColorAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
210
211
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
212
213
214
        SeriesProperties lSeriesProperties;
        ColorSeriesProperties lColorSerieProperties;
        boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();
97f9b74e   Erdogan Furkan   #10776 - Density ...
215
        std::string zAxisTextLegend = "";
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
216

07bf1e7c   Menouard AZIB   EveryThing works ...
217
218
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
219
220
221
222
223
            return;
        }

        // Build list of all indexes used by each parameters for each y axes
        AxisParamsComponents axisParamsComponents;
07bf1e7c   Menouard AZIB   EveryThing works ...
224
225
        for (auto param : plot->_parameterAxesList)
        {
97f9b74e   Erdogan Furkan   #10776 - Density ...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
            std::shared_ptr<Histogram2DSeriesProperties> pHistogram2DProperties = param.getHistogram2DSeriesProperties() ;
            if(pHistogram2DProperties != nullptr){
                if (!pHistogram2DProperties->hasYAxis())
                    continue;

                zAxisTextLegend = pHistogram2DProperties->getHistotypeProperties().getHisto2DFunction()->getTextLegend();
                // check if a colored param is defined for this serie
                if (pHistogram2DProperties->getHistotypeProperties().getParamId().empty()){
                    Label zLabel(lZAxis->_legend.getFont(),lZAxis->_color);
                    zLabel._text = zAxisTextLegend;
                    lZAxis->_legend.pushLabel(zLabel);
                    continue;
                }

                ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
                if (pHistogram2DProperties->getHistotypeProperties().getIndex() > -1)
                    colorSerieIndex = ParameterIndexComponentColor(pHistogram2DProperties->getHistotypeProperties().getIndex(), -1, lZAxis->_color);
                pushComponentInList(pHistogram2DProperties->getHistotypeProperties().getParamId(), colorSerieIndex, axisParamsComponents);
            }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
            // std::shared_ptr<Histogram1DSeriesProperties> pHistogram1DProperties = param.getHistogram1DSeriesProperties() ;
            // if(pHistogram1DProperties != nullptr){
            //     if (!pHistogram1DProperties->hasYAxis())
            //         continue;

            //     zAxisTextLegend = pHistogram1DProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
            //     // check if a colored param is defined for this serie
            //     if (pHistogram1DProperties->getHistotypeProperties().getParamId().empty()){
            //         Label zLabel(lZAxis->_legend.getFont(),lZAxis->_color);
            //         zLabel._text = zAxisTextLegend;
            //         lZAxis->_legend.pushLabel(zLabel);
            //         continue;
            //     }

            //     ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
            //     if (pHistogram1DProperties->getHistotypeProperties().getIndex() > -1)
            //         colorSerieIndex = ParameterIndexComponentColor(pHistogram2DProperties->getHistotypeProperties().getIndex(), -1, lZAxis->_color);
            //     pushComponentInList(pHistogram1DProperties->getHistotypeProperties().getParamId(), colorSerieIndex, axisParamsComponents);
            // }
07bf1e7c   Menouard AZIB   EveryThing works ...
264
265
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
266
267
268
269
270
                if (!lSeriesProperties.hasYAxis())
                    continue;

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

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

07bf1e7c   Menouard AZIB   EveryThing works ...
275
                ParameterAxes *colorSerieParameterAxes = plot->getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
276
277
278
279
280
281
282
283
284
285
286
287
288

                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 ...
289
        setAxisLegendForSeries(plot, lZAxis, axisParamsComponents, zAxisTextLegend);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
290
291
292
    }

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

07bf1e7c   Menouard AZIB   EveryThing works ...
297
298
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
299
300
            return;
        }
5ee90a58   Benjamin Renard   Use AxisLegendMan...
301

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

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

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
311
312
313
            setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
            break;
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
314
315
316

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

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

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

07bf1e7c   Menouard AZIB   EveryThing works ...
329
330
331
332
333
    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
334
335
            axisParamsComponents[paramId].clear();
            axisParamsComponents[paramId].push_back(index);
07bf1e7c   Menouard AZIB   EveryThing works ...
336
337
338
339
340
341
342
343
        }
        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
344
345
346
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
347
348
349
350
351
            for (auto crtIndex : axisParamsComponents[paramId])
            {
                if ((crtIndex.getDim1Index() == index.getDim1Index()) && (crtIndex.getDim2Index() == index.getDim2Index()))
                {
                    // Component already exists
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
352
353
354
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
355
            // Add this components for this axis
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
356
357
            axisParamsComponents[paramId].push_back(index);
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
358
359
    }

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

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

07bf1e7c   Menouard AZIB   EveryThing works ...
371
372
        for (auto paramsComponents : axisParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
373
            ParameterSPtr p = plot->_parameterManager.getParameter(paramsComponents.first);
7c94ae0d   Erdogan Furkan   For now, histo1d ...
374
375
            if (p == nullptr)
                continue;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
376
            ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
07bf1e7c   Menouard AZIB   EveryThing works ...
377
378
379
            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
380
381
382
383
384
                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 ...
385
386
            for (auto components : paramsComponents.second)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
387
388
389
                if (paramInfo == nullptr)
                    continue;
                Label label(pAxis->_legend.getFont(), components.getColor());
07bf1e7c   Menouard AZIB   EveryThing works ...
390
391
392
393
                if (axisParamsComponents.size() == 1)
                {
                    if (isFirstComponent)
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
394
                        std::string info = getMissionInstrumentInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
395
396
                        if (!info.empty())
                        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
397
398
399
400
                            label._text = info;
                            addBreakLine(label._text);
                        }
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
401
402
403
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
404
                    std::string info = getMissionInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
405
406
                    if (!info.empty())
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
407
408
409
                        label._text = info + ", ";
                    }
                }
97f9b74e   Erdogan Furkan   #10776 - Density ...
410
                label._text += legendPrefix;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
411
412
413
414
415
416
417
                label._text += getParamLegend(paramInfo, components);
                pAxis->_legend.pushLabel(label);
                isFirstComponent = false;
            }
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
418
419
420
421
    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
422
423
424
425
            return;
        }

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
426
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
427
428
429
430
431

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

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
433
434
435
436
437
438
        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 ...
439
440
441
442
    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
443
            return;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
444
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
445
446

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
447
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
448
449
450
451
452
453
454
455
456

        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 ...
457
458
        if (!info.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
459
460
461
462
463
464
            addInfoPart(label._text, info);
            addBreakLine(label._text);
        }

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

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

07bf1e7c   Menouard AZIB   EveryThing works ...
488
489
        if (tableSPtr == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
490
491
492
493
494
495
496
497
498
            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 ...
499
500
501
            ((*plot->_pParameterValues)[paramId].getDim2Size() > 0) &&
            !indexes.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
502
503
            boost::shared_ptr<AMDA::Info::ParamTable> otherTableSPtr;
            int otherDimIndex;
07bf1e7c   Menouard AZIB   EveryThing works ...
504
505
            if (relatedDim == 0)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
506
507
                otherTableSPtr = paramInfo->getTable(1);
                otherDimIndex = indexes.front().getDim2Index();
07bf1e7c   Menouard AZIB   EveryThing works ...
508
509
510
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
511
512
513
                otherTableSPtr = paramInfo->getTable(0);
                otherDimIndex = indexes.front().getDim1Index();
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
514
515
            if ((otherTableSPtr != nullptr) && !otherTableSPtr->isVariable(&plot->_parameterManager))
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
516
517
518
519
520
521
522
523
524
                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 ...
525
526
527
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
528
529
530
531
532
533
534
535
536
537
538
539
                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 ...
540
541
542
543
544
545
546
547
548
549
    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
550
551
                        legend += ", ";
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
552
553
554
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
555
556
557
558
559
560
561
                    legend += ", ";
                }
            }
            legend += info;
        }
    }

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

07bf1e7c   Menouard AZIB   EveryThing works ...
574
575
    void AxisLegendManager::addIndexPart(std::string &legend, int index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
576
577
578
579
580
        legend += "[";
        legend += std::to_string(index);
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
581
582
    void AxisLegendManager::addBoundsPart(std::string &legend, PLFLT min, PLFLT max)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
583
584
585
586
587
        legend += " ";

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

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

b358ee7d   Benjamin Renard   Adapt axes labels...
590
591
        getDigitalLabel(min, precision, minCount, 1024);
        getDigitalLabel(max, precision, maxCount, 1024);
fbe3c2bb   Benjamin Renard   First commit
592

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
593
594
595
596
597
        legend += std::string(minCount);
        legend += ", ";
        legend += std::string(maxCount);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
598
599
600
601
    void AxisLegendManager::addBreakLine(std::string &legend)
    {
        if (!legend.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
602
603
604
605
            legend += Label::DELIMITER;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
606
607
    std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
608
609
610
        std::string legend;
        addInfoPart(legend, paramInfo->getShortName());

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

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

c2fa3b5d   Benjamin Renard   Rework of legend ...
626
        return legend;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
    }

    /*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 ...
649
650
    std::string AxisLegendManager::getMissionInstrumentInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
651
652
653
654
655
656
657
658
        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 ...
659
660
    std::string AxisLegendManager::getMissionInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
661
662
663
        std::string info = paramInfo->getInstrumentId();
        if (info.empty())
            return info;
07bf1e7c   Menouard AZIB   EveryThing works ...
664
665
        if (info.find('_') != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
666
667
668
669
670
671
            info = info.substr(0, info.find('_'));
        }
        std::transform(info.begin(), info.end(), info.begin(), ::toupper);
        return info;
    }

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

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

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