Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 27.5 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)
        {
1248af2b   Erdogan Furkan   Refactored, all w...
23
24
25
26
27
28
29
30
31
32
33
            std::shared_ptr<HistogramSeriesProperties> pHistogramProperties = param.getHistogramSeriesProperties() ;
            if(pHistogramProperties != nullptr){
                std::string xParamId = "";
                AMDA::Common::ParameterIndexComponent xIndexComp;

                if(pHistogramProperties->getHistogramType() == "histogram1d"){
                    if (!pHistogramProperties->hasXAxis())
                        continue;
                    xIndexComp = pHistogramProperties->getIndex();
                    xParamId = pHistogramProperties->getParamId();
                    
97f9b74e   Erdogan Furkan   #10776 - Density ...
34
                }
1248af2b   Erdogan Furkan   Refactored, all w...
35
36
37
38
39
40
41
42
43
44
                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();
                }
                
                std::string xAxisId = pHistogramProperties->getXAxisId();
7c94ae0d   Erdogan Furkan   For now, histo1d ...
45
46
47
48
49
50
                boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
                if (lXAxis.get() == nullptr)
                {
                    continue;
                }
                Color compLegendColor = lXAxis->_color;
1248af2b   Erdogan Furkan   Refactored, all w...
51
52
                ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(xIndexComp, compLegendColor);
                pushComponentInList(xParamId, xIndex, axesParamsComponents[xAxisId]);
7c94ae0d   Erdogan Furkan   For now, histo1d ...
53
54
            }

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

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

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

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

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

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

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

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

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

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

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

            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 ...
124
125
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
126
127
128
129
130
131
132
        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 ...
133
134
        if (!plot->_panel->_page->_superposeMode)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
135
136
            plot->resetAutomaticSerieColorCursor();
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
137
138
        for (auto param : plot->_parameterAxesList)
        {
1248af2b   Erdogan Furkan   Refactored, all w...
139
140
141
            std::shared_ptr<HistogramSeriesProperties> pHistogramProperties = param.getHistogramSeriesProperties() ;
            if(pHistogramProperties != nullptr){
                if (!pHistogramProperties->hasYAxis())
7c94ae0d   Erdogan Furkan   For now, histo1d ...
142
                    continue;
1248af2b   Erdogan Furkan   Refactored, all w...
143
144

                std::string yAxisId = pHistogramProperties->getYAxisId();
7c94ae0d   Erdogan Furkan   For now, histo1d ...
145
146
147
148
149
                boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
                if (lYAxis.get() == nullptr)
                {
                    continue;
                }
1248af2b   Erdogan Furkan   Refactored, all w...
150
151
152
153
154
                if(pHistogramProperties->getHistogramType() == "histogram1d"){
                    std::string yAxisTextLegend;
                    yAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
                    Label yLabel(lYAxis->_legend.getFont(),lYAxis->_color);
                    yLabel._text = yAxisTextLegend;
8c2fc628   Erdogan Furkan   EVerything ok now
155
                    lYAxis->_legend.setLabel(yLabel);
1248af2b   Erdogan Furkan   Refactored, all w...
156
                }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
157
158
                
                Color compLegendColor = lYAxis->_color;
1248af2b   Erdogan Furkan   Refactored, all w...
159
160
                ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(param.getHistogramSeriesProperties()->getIndex(), compLegendColor);
                pushComponentInList(pHistogramProperties->getParamId(), yIndex, axesParamsComponents[yAxisId]);
7c94ae0d   Erdogan Furkan   For now, histo1d ...
161
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
162
163
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
164
165
166
167
168
169
170
                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 ...
171
172
                if (lYAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
173
174
175
                    continue;
                }

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

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
194
195
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
196
197
198
199
200
201
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisParamsComponents.first);
            setAxisLegendForSeries(plot, lYAxis, axisParamsComponents.second);
        }
    }

    void AxisLegendManager::configureColorAxisLegendForSeries(
07bf1e7c   Menouard AZIB   EveryThing works ...
202
203
        PanelPlotOutput *plot)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
204
205
206
        SeriesProperties lSeriesProperties;
        ColorSeriesProperties lColorSerieProperties;
        boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();
97f9b74e   Erdogan Furkan   #10776 - Density ...
207
        std::string zAxisTextLegend = "";
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
208

07bf1e7c   Menouard AZIB   EveryThing works ...
209
210
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
211
212
213
214
215
            return;
        }

        // Build list of all indexes used by each parameters for each y axes
        AxisParamsComponents axisParamsComponents;
07bf1e7c   Menouard AZIB   EveryThing works ...
216
217
        for (auto param : plot->_parameterAxesList)
        {
1248af2b   Erdogan Furkan   Refactored, all w...
218
219
220
            std::shared_ptr<HistogramSeriesProperties> pHistogramProperties = param.getHistogramSeriesProperties() ;
            if(pHistogramProperties != nullptr){
                if (!pHistogramProperties->hasYAxis())
97f9b74e   Erdogan Furkan   #10776 - Density ...
221
222
                    continue;

1248af2b   Erdogan Furkan   Refactored, all w...
223
224
225
226
                if(pHistogramProperties->getHistogramType() == "histogram1d" )
                    zAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
                if(pHistogramProperties->getHistogramType() == "histogram2d" )
                    zAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto2DFunction()->getTextLegend();
97f9b74e   Erdogan Furkan   #10776 - Density ...
227
                // check if a colored param is defined for this serie
1248af2b   Erdogan Furkan   Refactored, all w...
228
                if (pHistogramProperties->getHistotypeProperties().getParamId().empty()){
97f9b74e   Erdogan Furkan   #10776 - Density ...
229
230
231
232
233
234
235
                    Label zLabel(lZAxis->_legend.getFont(),lZAxis->_color);
                    zLabel._text = zAxisTextLegend;
                    lZAxis->_legend.pushLabel(zLabel);
                    continue;
                }

                ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
1248af2b   Erdogan Furkan   Refactored, all w...
236
237
238
                if (pHistogramProperties->getHistotypeProperties().getIndex() > -1)
                    colorSerieIndex = ParameterIndexComponentColor(pHistogramProperties->getHistotypeProperties().getIndex(), -1, lZAxis->_color);
                pushComponentInList(pHistogramProperties->getHistotypeProperties().getParamId(), colorSerieIndex, axisParamsComponents);
97f9b74e   Erdogan Furkan   #10776 - Density ...
239
            }
1248af2b   Erdogan Furkan   Refactored, all w...
240

07bf1e7c   Menouard AZIB   EveryThing works ...
241
242
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
243
244
245
246
247
                if (!lSeriesProperties.hasYAxis())
                    continue;

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

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

07bf1e7c   Menouard AZIB   EveryThing works ...
252
                ParameterAxes *colorSerieParameterAxes = plot->getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
253
254
255
256
257
258
259
260
261
262
263
264
265

                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 ...
266
        setAxisLegendForSeries(plot, lZAxis, axisParamsComponents, zAxisTextLegend);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
267
268
269
    }

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

07bf1e7c   Menouard AZIB   EveryThing works ...
274
275
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
276
277
            return;
        }
5ee90a58   Benjamin Renard   Use AxisLegendMan...
278

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

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

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
288
289
290
            setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
            break;
        }
07bf1e7c   Menouard AZIB   EveryThing works ...
291
292
293

        for (auto param : plot->_parameterAxesList)
        {
b0205fd9   Hacene SI HADJ MOHAND   plot ok reste que...
294
295
            std::shared_ptr<SauvaudProperties> sauvaudPropertiesPtr = param.getSauvaudProperties();
            if (sauvaudPropertiesPtr == nullptr)
07bf1e7c   Menouard AZIB   EveryThing works ...
296
                continue; // no sauvaud defined
b0205fd9   Hacene SI HADJ MOHAND   plot ok reste que...
297
298
299
300
301
302
303

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

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

07bf1e7c   Menouard AZIB   EveryThing works ...
306
307
308
309
310
    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
311
312
            axisParamsComponents[paramId].clear();
            axisParamsComponents[paramId].push_back(index);
07bf1e7c   Menouard AZIB   EveryThing works ...
313
314
315
316
317
318
319
320
        }
        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
321
322
323
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
324
325
326
327
328
            for (auto crtIndex : axisParamsComponents[paramId])
            {
                if ((crtIndex.getDim1Index() == index.getDim1Index()) && (crtIndex.getDim2Index() == index.getDim2Index()))
                {
                    // Component already exists
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
329
330
331
                    return;
                }
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
332
            // Add this components for this axis
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
333
334
            axisParamsComponents[paramId].push_back(index);
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
335
336
    }

97f9b74e   Erdogan Furkan   #10776 - Density ...
337
338
    void AxisLegendManager::setAxisLegendForSeries(PanelPlotOutput *plot, boost::shared_ptr<Axis> &pAxis, AxisParamsComponents &axisParamsComponents, 
                                                    std::string legendPrefix)
07bf1e7c   Menouard AZIB   EveryThing works ...
339
340
341
    {
        if (pAxis == nullptr || !pAxis->_legend.isEmpty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
342
343
344
345
            return;
        }

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

07bf1e7c   Menouard AZIB   EveryThing works ...
348
349
        for (auto paramsComponents : axisParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
350
            ParameterSPtr p = plot->_parameterManager.getParameter(paramsComponents.first);
7c94ae0d   Erdogan Furkan   For now, histo1d ...
351
352
            if (p == nullptr)
                continue;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
353
            ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
07bf1e7c   Menouard AZIB   EveryThing works ...
354
355
356
            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
357
358
359
360
361
                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 ...
362
363
            for (auto components : paramsComponents.second)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
364
365
366
                if (paramInfo == nullptr)
                    continue;
                Label label(pAxis->_legend.getFont(), components.getColor());
07bf1e7c   Menouard AZIB   EveryThing works ...
367
368
369
370
                if (axisParamsComponents.size() == 1)
                {
                    if (isFirstComponent)
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
371
                        std::string info = getMissionInstrumentInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
372
373
                        if (!info.empty())
                        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
374
375
376
377
                            label._text = info;
                            addBreakLine(label._text);
                        }
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
378
379
380
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
381
                    std::string info = getMissionInfo(paramInfo);
07bf1e7c   Menouard AZIB   EveryThing works ...
382
383
                    if (!info.empty())
                    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
384
385
386
                        label._text = info + ", ";
                    }
                }
97f9b74e   Erdogan Furkan   #10776 - Density ...
387
                label._text += legendPrefix;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
388
389
390
391
392
393
394
                label._text += getParamLegend(paramInfo, components);
                pAxis->_legend.pushLabel(label);
                isFirstComponent = false;
            }
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
395
396
397
398
    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
399
400
401
402
            return;
        }

        // Retrieve ParamInfo Manager
07bf1e7c   Menouard AZIB   EveryThing works ...
403
        ParamMgr *piMgr = ParamMgr::getInstance();
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
404
405
406
407
408

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

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
410
411
412
413
414
415
        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 ...
416
417
418
419
    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
420
            return;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
421
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
422
423

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

        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 ...
434
435
        if (!info.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
436
437
438
439
440
441
            addInfoPart(label._text, info);
            addBreakLine(label._text);
        }

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

        if (tableSPtr == nullptr)
        {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
445
446
447
            // look for unique embedded table
            boost::shared_ptr<AMDA::Info::ParamTable> linkedTableSPtr;
            int counter = 0;
07bf1e7c   Menouard AZIB   EveryThing works ...
448
449
            for (auto pInfo : paramInfo->getLinkedParamList())
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
450
451
452
                linkedTableSPtr = AMDA::Info::ParamMgr::getInstance()->getParamInfoFromId(pInfo)->getTable(relatedDim);
                if (linkedTableSPtr == nullptr)
                    continue;
07bf1e7c   Menouard AZIB   EveryThing works ...
453
                counter++;
0831b2cf   Hacene SI HADJ MOHAND   axis legend
454
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
455
456
            if (linkedTableSPtr == nullptr || counter != 1)
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
457
                LOG4CXX_DEBUG(gLogger, "table cannot be defined from linked info params");
07bf1e7c   Menouard AZIB   EveryThing works ...
458
459
460
            }
            else
            {
0831b2cf   Hacene SI HADJ MOHAND   axis legend
461
462
                tableSPtr = linkedTableSPtr;
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
463
        }
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
464

07bf1e7c   Menouard AZIB   EveryThing works ...
465
466
        if (tableSPtr == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
467
468
469
470
471
472
473
474
475
            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 ...
476
477
478
            ((*plot->_pParameterValues)[paramId].getDim2Size() > 0) &&
            !indexes.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
479
480
            boost::shared_ptr<AMDA::Info::ParamTable> otherTableSPtr;
            int otherDimIndex;
07bf1e7c   Menouard AZIB   EveryThing works ...
481
482
            if (relatedDim == 0)
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
483
484
                otherTableSPtr = paramInfo->getTable(1);
                otherDimIndex = indexes.front().getDim2Index();
07bf1e7c   Menouard AZIB   EveryThing works ...
485
486
487
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
488
489
490
                otherTableSPtr = paramInfo->getTable(0);
                otherDimIndex = indexes.front().getDim1Index();
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
491
492
            if ((otherTableSPtr != nullptr) && !otherTableSPtr->isVariable(&plot->_parameterManager))
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
493
494
495
496
497
498
499
500
501
                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 ...
502
503
504
            }
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
505
506
507
508
509
510
511
512
513
514
515
516
                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 ...
517
518
519
520
521
522
523
524
525
526
    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
527
528
                        legend += ", ";
                    }
07bf1e7c   Menouard AZIB   EveryThing works ...
529
530
531
                }
                else
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
532
533
534
535
536
537
538
                    legend += ", ";
                }
            }
            legend += info;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
539
540
    void AxisLegendManager::addIndexPart(std::string &legend, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
541
542
        legend += "[";
        legend += std::to_string(index.getDim1Index());
07bf1e7c   Menouard AZIB   EveryThing works ...
543
544
        if (index.getDim2Index() != -1)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
545
546
547
548
549
550
            legend += ",";
            legend += std::to_string(index.getDim2Index());
        }
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
551
552
    void AxisLegendManager::addIndexPart(std::string &legend, int index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
553
554
555
556
557
        legend += "[";
        legend += std::to_string(index);
        legend += "]";
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
558
559
    void AxisLegendManager::addBoundsPart(std::string &legend, PLFLT min, PLFLT max)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
560
561
562
563
564
        legend += " ";

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

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

b358ee7d   Benjamin Renard   Adapt axes labels...
567
568
        getDigitalLabel(min, precision, minCount, 1024);
        getDigitalLabel(max, precision, maxCount, 1024);
fbe3c2bb   Benjamin Renard   First commit
569

5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
570
571
572
573
574
        legend += std::string(minCount);
        legend += ", ";
        legend += std::string(maxCount);
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
575
576
577
578
    void AxisLegendManager::addBreakLine(std::string &legend)
    {
        if (!legend.empty())
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
579
580
581
582
            legend += Label::DELIMITER;
        }
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
583
584
    std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, ParameterIndexComponentColor &index)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
585
586
587
        std::string legend;
        addInfoPart(legend, paramInfo->getShortName());

07bf1e7c   Menouard AZIB   EveryThing works ...
588
589
        if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1))
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
590
591
592
            AMDA::Common::ParameterIndexComponent paramIndex(index.getDim1Index(), index.getDim2Index());
            if (paramInfo->getComponents(paramIndex).empty() == false)
                addInfoPart(legend, paramInfo->getComponents(paramIndex));
07bf1e7c   Menouard AZIB   EveryThing works ...
593
594
            else
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
595
596
597
                addInfoPart(legend, paramInfo->getShortName());
                addIndexPart(legend, index);
            }
c2fa3b5d   Benjamin Renard   Rework of legend ...
598
599
        }

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

c2fa3b5d   Benjamin Renard   Rework of legend ...
603
        return legend;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
    }

    /*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 ...
626
627
    std::string AxisLegendManager::getMissionInstrumentInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
628
629
630
631
632
633
634
635
        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 ...
636
637
    std::string AxisLegendManager::getMissionInfo(AMDA::Info::ParamInfoSPtr paramInfo)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
638
639
640
        std::string info = paramInfo->getInstrumentId();
        if (info.empty())
            return info;
07bf1e7c   Menouard AZIB   EveryThing works ...
641
642
        if (info.find('_') != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
643
644
645
646
647
648
            info = info.substr(0, info.find('_'));
        }
        std::transform(info.begin(), info.end(), info.begin(), ::toupper);
        return info;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
649
650
    std::string AxisLegendManager::getTransformedUnits(const std::string &rawUnit)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
651
652
653
654
655
656
657
658
        std::string unit = rawUnit;
        if (unit.find("^"))
            unit = transformPower(unit, "^");
        if (unit.find("**"))
            unit = transformPower(unit, "**");
        return unit;
    }

07bf1e7c   Menouard AZIB   EveryThing works ...
659
660
    std::string AxisLegendManager::transformPower(std::string &unit, std::string pattern)
    {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
661
662
663
        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 ...
664
665
        while (pos_first != std::string::npos)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
666
667
            char afterPattern = unit[pos_first + pattern.length()];
            pos_last = pos_first + pattern.length();
07bf1e7c   Menouard AZIB   EveryThing works ...
668
669
670
671
672
673
674
675
            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
676
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
677
678
679
            else if (afterPattern == '|')
            {
                pos_last = unit.find("|", pos_first + pattern.length() + 2) + 1;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
680
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
681
682
683
684
685
686
            else if (isdigit(afterPattern) || afterPattern == '.')
            {
                pos_last++;
                while (isdigit(unit[pos_last]) || unit[pos_last] == '.')
                {
                    pos_last++;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
687
                }
07bf1e7c   Menouard AZIB   EveryThing works ...
688
689
690
691
            }
            else
            {
                pos_last++;
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
692
693
694
695
696
            }
            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 ...
697
698
        for (it = positions.rbegin(); it != positions.rend(); ++it)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
699
700
701
702
703
704
705
            unit.insert(it->second, "#d");
            unit.erase(it->first, pattern.length());
            unit.insert(it->first, "#u");
        }
        return unit;
    }

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