Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 29 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
156
                    std::string yAxisId = pHistogramProperties->getYAxisId();
                    boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
                    if (lYAxis.get() == nullptr)
                    {
                        continue;
                    }
                    if(pHistogramProperties->getHistogramType() == "histogram1d"){
bec89e22   Erdogan Furkan   Fixes + refactori...
157
                        AMDA::Common::ParameterIndexComponent yIndexComp = AMDA::Common::ParameterIndexComponent(pHistogramProperties->getHistotypeProperties().getIndex(), -1);
4bced76d   Furkan   #11372 - Adding n...
158
                        std::string yParamId =  pHistogramProperties->getHistotypeProperties().getParamId();
bec89e22   Erdogan Furkan   Fixes + refactori...
159
160
                        yAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
                        
4bced76d   Furkan   #11372 - Adding n...
161
162
163
164
165
166
167
168
169
170
171
                        if(pHistogramProperties->getHistotypeProperties().getParamId().empty())
                        {
                            Label yLabel(lYAxis->_legend.getFont(),lYAxis->_color);
                            yLabel._text = yAxisTextLegend;
                            lYAxis->_legend.setLabel(yLabel);
                            continue;
                        }
                        Color compLegendColor = lYAxis->_color;
                        if(param.getHistogramSeriesPropertiesList().size() > 0)
                            compLegendColor = pHistogramProperties->getColor();
                        ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(yIndexComp, compLegendColor);
bec89e22   Erdogan Furkan   Fixes + refactori...
172
173
                        pushComponentInList(yParamId, yIndex, axesHistoParamsComponents[yAxisId]);
                                           
05089f4a   Erdogan Furkan   #11376 - Done.
174
                    }
1248af2b   Erdogan Furkan   Refactored, all w...
175
                }
7c94ae0d   Erdogan Furkan   For now, histo1d ...
176
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
177
178
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
179
180
181
182
183
184
185
                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 ...
186
187
                if (lYAxis.get() == nullptr)
                {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
188
189
190
                    continue;
                }

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

        std::list<std::string> legendLines;
07bf1e7c   Menouard AZIB   EveryThing works ...
209
210
        for (auto axisParamsComponents : axesParamsComponents)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
211
            boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisParamsComponents.first);
4bced76d   Furkan   #11372 - Adding n...
212
            setAxisLegendForSeries(plot, lYAxis, axisParamsComponents.second,yAxisTextLegend);
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
213
        }
bec89e22   Erdogan Furkan   Fixes + refactori...
214
215
216
217
218
219
        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
220
221
222
    }

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

07bf1e7c   Menouard AZIB   EveryThing works ...
230
231
        if (lZAxis.get() == nullptr)
        {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
232
233
234
235
236
            return;
        }

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

05089f4a   Erdogan Furkan   #11376 - Done.
245
246
247
248
249
250
251
252
253
254
255
                    if(pHistogramProperties->getHistogramType() == "histogram1d" )
                        zAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend();
                    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;
                        lZAxis->_legend.pushLabel(zLabel);
                        continue;
                    }
97f9b74e   Erdogan Furkan   #10776 - Density ...
256

05089f4a   Erdogan Furkan   #11376 - Done.
257
258
259
260
261
                    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 ...
262
            }
07bf1e7c   Menouard AZIB   EveryThing works ...
263
264
            for (auto lSeriesProperties : param.getYSeriePropertiesList())
            {
5e31eec0   Hacene SI HADJ MOHAND   resolu puissance
265
266
267
268
269
                if (!lSeriesProperties.hasYAxis())
                    continue;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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