Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 15.3 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
#include "AxisLegendManager.hh"

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

namespace plot
{

5ee90a58   Benjamin Renard   Use AxisLegendMan...
8
9
10
11
12
13
void AxisLegendManager::configureXAxisLegendForSeries(
		XYPlot* plot)
{
	// Build list of all indexes used by each parameters for each x axes
	std::map<std::string, AxisParamsComponents> axesParamsComponents;

21ddb9f2   Benjamin Renard   Set legend color ...
14
15
16
	// Compute nb series to draw by y axis
	std::map<std::string,int> nbSeriesByYAxisMap = plot->getNbSeriesByYAxis();

5ee90a58   Benjamin Renard   Use AxisLegendMan...
17
18
	SeriesProperties lSeriesProperties;
	for (auto param: plot->_parameterAxesList) {
2fc1f2f8   Benjamin Renard   Full rework for s...
19
		for(auto lSeriesProperties : param.getYSeriePropertiesList()) {
5ee90a58   Benjamin Renard   Use AxisLegendMan...
20
21
			if(!lSeriesProperties.hasYAxis() || !lSeriesProperties.hasXAxis())
				continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
22

21ddb9f2   Benjamin Renard   Set legend color ...
23
24
			bool moreThanOneSerieForAxis = (nbSeriesByYAxisMap[lSeriesProperties.getYAxisId()] > 1);

c46af5a8   Benjamin Renard   Implements multi ...
25
			ParameterAxes* xParameter = plot->getParameterAxesByXSerieId(lSeriesProperties.getXId());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
26

c46af5a8   Benjamin Renard   Implements multi ...
27
			XSeriesProperties xSerie = xParameter->getXSeriePropertiesById(lSeriesProperties.getXId());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
28

c46af5a8   Benjamin Renard   Implements multi ...
29
			std::string xAxisId = lSeriesProperties.getXAxisId();
5ee90a58   Benjamin Renard   Use AxisLegendMan...
30
31
32
33
34
35

			boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(xAxisId);
			if (lXAxis.get() == nullptr) {
				continue;
			}

21ddb9f2   Benjamin Renard   Set legend color ...
36
37
38
39
40
41
			Color compLegendColor = lXAxis->_color;
			if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode)) {
				compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
			}

			ParameterIndexComponentColor xIndex = ParameterIndexComponentColor(xSerie.getIndex(), compLegendColor);
c46af5a8   Benjamin Renard   Implements multi ...
42
			pushComponentInList(xSerie.getParamId(), xIndex, axesParamsComponents[xAxisId]);
5ee90a58   Benjamin Renard   Use AxisLegendMan...
43
44
45
		}
	}

21ddb9f2   Benjamin Renard   Set legend color ...
46
47
48
49
	if (!plot->_panel->_page->_superposeMode) {
		plot->resetAutomaticSerieColorCursor();
	}

5ee90a58   Benjamin Renard   Use AxisLegendMan...
50
51
52
53
54
55
56
	std::list<std::string> legendLines;
	for (auto axisParamsComponents : axesParamsComponents) {
		boost::shared_ptr<Axis> lXAxis = plot->_panel->getAxis(axisParamsComponents.first);
		setAxisLegendForSeries(plot, lXAxis, axisParamsComponents.second);
        }
}

c2fa3b5d   Benjamin Renard   Rework of legend ...
57
58
void AxisLegendManager::configureYAxisLegendForSpectro(
                PanelPlotOutput* plot)
fbe3c2bb   Benjamin Renard   First commit
59
{
c2fa3b5d   Benjamin Renard   Rework of legend ...
60
61
62
63
	for (auto param: plot->_parameterAxesList) {
		std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
		if (spectroPropertiesPtr == nullptr)
			continue; //no spectro defined
fbe3c2bb   Benjamin Renard   First commit
64

c2fa3b5d   Benjamin Renard   Rework of legend ...
65
66
		if(!spectroPropertiesPtr->hasYAxis())
			continue;
fbe3c2bb   Benjamin Renard   First commit
67

c2fa3b5d   Benjamin Renard   Rework of legend ...
68
69
70
71
		std::string yAxisId = spectroPropertiesPtr->getYAxisId();
		boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
		if (lYAxis.get() == nullptr)
			continue;
fbe3c2bb   Benjamin Renard   First commit
72

df45df5e   Benjamin Renard   Introduce AxisLeg...
73
		if (!lYAxis->_legend.isEmpty())
c2fa3b5d   Benjamin Renard   Rework of legend ...
74
			continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
75
76
		
		setAxisLegendForTable(plot, lYAxis, param._originalParamId, spectroPropertiesPtr->getParamId(), spectroPropertiesPtr->getIndexes(), spectroPropertiesPtr->getRelatedDim());
c2fa3b5d   Benjamin Renard   Rework of legend ...
77
		return;
fbe3c2bb   Benjamin Renard   First commit
78
	}
c2fa3b5d   Benjamin Renard   Rework of legend ...
79
80
81
82
83
84
}

void AxisLegendManager::configureYAxisLegendForSeries(
		PanelPlotOutput* plot)
{
	SeriesProperties lSeriesProperties;
fbe3c2bb   Benjamin Renard   First commit
85

8bb0f02b   Benjamin Renard   Set colors in axi...
86
87
88
	// Compute nb series to draw by y axis
	std::map<std::string,int> nbSeriesByYAxisMap = plot->getNbSeriesByYAxis();

c2fa3b5d   Benjamin Renard   Rework of legend ...
89
90
	// Build list of all indexes used by each parameters for each y axes
	std::map<std::string, AxisParamsComponents> axesParamsComponents;
8bb0f02b   Benjamin Renard   Set colors in axi...
91
92
93
	if (!plot->_panel->_page->_superposeMode) {
		plot->resetAutomaticSerieColorCursor();
	}
fbe3c2bb   Benjamin Renard   First commit
94
95
	for (auto param: plot->_parameterAxesList)
	{
2fc1f2f8   Benjamin Renard   Full rework for s...
96
		for(auto lSeriesProperties : param.getYSeriePropertiesList()) {
fbe3c2bb   Benjamin Renard   First commit
97
98
99
			if(!lSeriesProperties.hasYAxis())
				continue;

8bb0f02b   Benjamin Renard   Set colors in axi...
100
101
			bool moreThanOneSerieForAxis = (nbSeriesByYAxisMap[lSeriesProperties.getYAxisId()] > 1);

fbe3c2bb   Benjamin Renard   First commit
102
			std::string yAxisId = lSeriesProperties.getYAxisId();
fbe3c2bb   Benjamin Renard   First commit
103
104
			boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
			if (lYAxis.get() == nullptr) {
fbe3c2bb   Benjamin Renard   First commit
105
				continue;
c2fa3b5d   Benjamin Renard   Rework of legend ...
106
 			}
fbe3c2bb   Benjamin Renard   First commit
107

2fc1f2f8   Benjamin Renard   Full rework for s...
108
109
110
111
112
113
114
			for (auto index : lSeriesProperties.getIndexList(plot->_pParameterValues)) {
				Color compLegendColor = lYAxis->_color;
				if (moreThanOneSerieForAxis && (lSeriesProperties.getColorSerieId() == -1) && (!plot->_panel->_page->_superposeMode)) {
					compLegendColor = plot->getSerieLineColor(lSeriesProperties, moreThanOneSerieForAxis);
				}
				ParameterIndexComponentColor yIndex = ParameterIndexComponentColor(index, compLegendColor);
				pushComponentInList(lSeriesProperties.getParamId(), yIndex, axesParamsComponents[yAxisId]);
8bb0f02b   Benjamin Renard   Set colors in axi...
115
			}
c2fa3b5d   Benjamin Renard   Rework of legend ...
116
117
		}
	}
8bb0f02b   Benjamin Renard   Set colors in axi...
118
119
120
	if (!plot->_panel->_page->_superposeMode) {
		plot->resetAutomaticSerieColorCursor();
	}
fbe3c2bb   Benjamin Renard   First commit
121

c2fa3b5d   Benjamin Renard   Rework of legend ...
122
123
124
125
126
127
	std::list<std::string> legendLines;
	for (auto axisParamsComponents : axesParamsComponents) {
		boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(axisParamsComponents.first);
		setAxisLegendForSeries(plot, lYAxis, axisParamsComponents.second);
	}
}
fbe3c2bb   Benjamin Renard   First commit
128

5ee90a58   Benjamin Renard   Use AxisLegendMan...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
void AxisLegendManager::configureColorAxisLegendForSeries(
		PanelPlotOutput* plot)
{
	SeriesProperties lSeriesProperties;
	ColorSeriesProperties lColorSerieProperties;
	boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();
	
	if (lZAxis.get() == nullptr) {
		return;
 	}

	// Build list of all indexes used by each parameters for each y axes
	AxisParamsComponents axisParamsComponents;
	for (auto param: plot->_parameterAxesList) {
2fc1f2f8   Benjamin Renard   Full rework for s...
143
		for(auto lSeriesProperties : param.getYSeriePropertiesList()) {
5ee90a58   Benjamin Renard   Use AxisLegendMan...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
			if(!lSeriesProperties.hasYAxis())
				continue;

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

			//check if a colored param is defined for this serie
			if(lSeriesProperties.getColorParamId().empty())
				continue;

			ParameterAxes* colorSerieParameterAxes = plot->getParameterAxesByColorSerieId(lSeriesProperties.getColorSerieId());

			if (colorSerieParameterAxes == NULL)
				continue;

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

8bb0f02b   Benjamin Renard   Set colors in axi...
160
			ParameterIndexComponentColor colorSerieIndex = ParameterIndexComponentColor(-1, -1, lZAxis->_color);
5ee90a58   Benjamin Renard   Use AxisLegendMan...
161
			if (lColorSerieProperties.getIndex() > -1)
8bb0f02b   Benjamin Renard   Set colors in axi...
162
				colorSerieIndex = ParameterIndexComponentColor(lColorSerieProperties.getIndex(), -1, lZAxis->_color);
5ee90a58   Benjamin Renard   Use AxisLegendMan...
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
			pushComponentInList(lColorSerieProperties.getColorParamIds()[yParamId], colorSerieIndex, axisParamsComponents);
		}
	}

	setAxisLegendForSeries(plot, lZAxis, axisParamsComponents);
}

void AxisLegendManager::configureColorAxisLegendForSpectro(
		PanelPlotOutput* plot)
{
	boost::shared_ptr<Axis> lZAxis = plot->_panel->getColorAxis();
		
	if (lZAxis.get() == nullptr) {
		return;
 	}

	for (auto param: plot->_parameterAxesList) {
		std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
		if (spectroPropertiesPtr == nullptr)
			continue; //no spectro defined

		if(!spectroPropertiesPtr->hasZAxis())
			continue;
		
		setAxisLegendForSpectro(plot, lZAxis, param._originalParamId);
		break;
	}
}

8bb0f02b   Benjamin Renard   Set colors in axi...
192
193
void AxisLegendManager::pushComponentInList(std::string paramId, ParameterIndexComponentColor& index, AxisParamsComponents& axisParamsComponents) {
	if (index.getDim1Index() == -1 && index.getDim2Index() == -1) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
194
195
196
197
198
199
		//All indexes of this parameter are used
		axisParamsComponents[paramId].clear();
		axisParamsComponents[paramId].push_back(index);
	}
	else {
		if (axisParamsComponents[paramId].size() > 0) {
8bb0f02b   Benjamin Renard   Set colors in axi...
200
			if (axisParamsComponents[paramId].front().getDim1Index() == -1 && axisParamsComponents[paramId].front().getDim2Index() == -1) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
201
202
				//Skip. All components already defined for this paramter on this axis
				return;
fbe3c2bb   Benjamin Renard   First commit
203
			}
c2fa3b5d   Benjamin Renard   Rework of legend ...
204
		}
8bb0f02b   Benjamin Renard   Set colors in axi...
205
206
207
208
209
		for (auto crtIndex : axisParamsComponents[paramId]) {
			if ((crtIndex.getDim1Index() == index.getDim1Index()) && (crtIndex.getDim2Index() == index.getDim2Index())) {
				//Component already exists
				return;
			}
c2fa3b5d   Benjamin Renard   Rework of legend ...
210
		}
8bb0f02b   Benjamin Renard   Set colors in axi...
211
212
		//Add this components for this axis
		axisParamsComponents[paramId].push_back(index);
c2fa3b5d   Benjamin Renard   Rework of legend ...
213
	}
fbe3c2bb   Benjamin Renard   First commit
214

c2fa3b5d   Benjamin Renard   Rework of legend ...
215
}
fbe3c2bb   Benjamin Renard   First commit
216

c2fa3b5d   Benjamin Renard   Rework of legend ...
217
void AxisLegendManager::setAxisLegendForSeries(PanelPlotOutput* plot, boost::shared_ptr<Axis>& pAxis, AxisParamsComponents& axisParamsComponents) {
df45df5e   Benjamin Renard   Introduce AxisLeg...
218
	if (pAxis == nullptr || !pAxis->_legend.isEmpty()) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
219
220
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
221

c2fa3b5d   Benjamin Renard   Rework of legend ...
222
223
	// Retrieve ParamInfo Manager
	ParamMgr* piMgr = ParamMgr::getInstance();
fbe3c2bb   Benjamin Renard   First commit
224

c2fa3b5d   Benjamin Renard   Rework of legend ...
225
226
227
228
229
	for (auto paramsComponents : axisParamsComponents) {
		ParameterSPtr p = plot->_parameterManager.getParameter(paramsComponents.first);
		ParamInfoSPtr   paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
		if (paramsComponents.second.size() == p->getDataWriterTemplate()->getParamData()->getDim1() * p->getDataWriterTemplate()->getParamData()->getDim2()) {
			//All components of this parameter are used by this axis => merge
8bb0f02b   Benjamin Renard   Set colors in axi...
230
			Color color = paramsComponents.second.front().getColor();
c2fa3b5d   Benjamin Renard   Rework of legend ...
231
			paramsComponents.second.clear();
8bb0f02b   Benjamin Renard   Set colors in axi...
232
			paramsComponents.second.push_back(ParameterIndexComponentColor(-1,-1, color));
c2fa3b5d   Benjamin Renard   Rework of legend ...
233
		}
8c8ac7bf   Benjamin Renard   Write mission/ins...
234
		bool isFirstComponent = true;
c2fa3b5d   Benjamin Renard   Rework of legend ...
235
236
237
		for (auto components : paramsComponents.second) {
			if (paramInfo == nullptr)
				continue;
8bb0f02b   Benjamin Renard   Set colors in axi...
238
239
240
241
242
243
244
245
246
247
248
249
			Label label(pAxis->_legend.getFont(), components.getColor());
			if (axisParamsComponents.size() == 1) {
				if (isFirstComponent) {
					std::string info = getMissionInstrumentInfo(paramInfo);
					if (!info.empty()) {
						label._text = info;
						addBreakLine(label._text);
					}
				}
			}
			else {
				std::string info = getMissionInfo(paramInfo);
8c8ac7bf   Benjamin Renard   Write mission/ins...
250
				if (!info.empty()) {
8bb0f02b   Benjamin Renard   Set colors in axi...
251
					label._text = info + ", ";
8c8ac7bf   Benjamin Renard   Write mission/ins...
252
253
				}
			}
df45df5e   Benjamin Renard   Introduce AxisLeg...
254
			label._text += getParamLegend(paramInfo, components);
8bb0f02b   Benjamin Renard   Set colors in axi...
255
			pAxis->_legend.pushLabel(label);
8c8ac7bf   Benjamin Renard   Write mission/ins...
256
			isFirstComponent = false;
fbe3c2bb   Benjamin Renard   First commit
257
		}
fbe3c2bb   Benjamin Renard   First commit
258
259
260
	}
}

5ee90a58   Benjamin Renard   Use AxisLegendMan...
261
void AxisLegendManager::setAxisLegendForSpectro(PanelPlotOutput* plot, boost::shared_ptr<Axis>& pAxis, std::string originalParamId) {
df45df5e   Benjamin Renard   Introduce AxisLeg...
262
	if (pAxis == nullptr || !pAxis->_legend.isEmpty()) {
5ee90a58   Benjamin Renard   Use AxisLegendMan...
263
		return;
fbe3c2bb   Benjamin Renard   First commit
264
	}
fbe3c2bb   Benjamin Renard   First commit
265

5ee90a58   Benjamin Renard   Use AxisLegendMan...
266
267
268
269
270
271
272
	// Retrieve ParamInfo Manager
	ParamMgr* piMgr = ParamMgr::getInstance();
	
	ParameterSPtr p = plot->_parameterManager.getParameter(originalParamId);
	AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
	if (paramInfo == nullptr)
		return;
c2fa3b5d   Benjamin Renard   Rework of legend ...
273

df45df5e   Benjamin Renard   Introduce AxisLeg...
274
275
276
277
	Label label(pAxis->_legend.getFont(), pAxis->_legend.getColor());
	addInfoPart(label._text, paramInfo->getShortName());
	addInfoPart(label._text, paramInfo->getUnits());
	pAxis->_legend.setLabel(label);
c2fa3b5d   Benjamin Renard   Rework of legend ...
278
279
}

5ee90a58   Benjamin Renard   Use AxisLegendMan...
280
void AxisLegendManager::setAxisLegendForTable(PanelPlotOutput* plot, boost::shared_ptr<Axis>& pAxis, std::string originalParamId, std::string paramId, AMDA::Common::ParameterIndexComponentList& indexes, int relatedDim) {
df45df5e   Benjamin Renard   Introduce AxisLeg...
281
	if (pAxis == nullptr || !pAxis->_legend.isEmpty()) {
5ee90a58   Benjamin Renard   Use AxisLegendMan...
282
283
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
284

5ee90a58   Benjamin Renard   Use AxisLegendMan...
285
286
287
288
289
290
291
292
	// Retrieve ParamInfo Manager
	ParamMgr* piMgr = ParamMgr::getInstance();
	
	ParameterSPtr p = plot->_parameterManager.getParameter(originalParamId);
	AMDA::Info::ParamInfoSPtr paramInfo = piMgr->getParamInfoFromId(p->getInfoId());
	
	if (paramInfo == nullptr)
			return;
fbe3c2bb   Benjamin Renard   First commit
293

df45df5e   Benjamin Renard   Introduce AxisLeg...
294
	Label label(pAxis->_legend.getFont(), pAxis->_legend.getColor());
fb96d5d5   Benjamin Renard   Add mission name ...
295
296
	std::string info = getMissionInstrumentInfo(paramInfo);
	if (!info.empty()) {
df45df5e   Benjamin Renard   Introduce AxisLeg...
297
298
		addInfoPart(label._text, info);
		addBreakLine(label._text);
fb96d5d5   Benjamin Renard   Add mission name ...
299
300
	}

5ee90a58   Benjamin Renard   Use AxisLegendMan...
301
302
	boost::shared_ptr<AMDA::Info::ParamTable> tableSPtr;
	tableSPtr = paramInfo->getTable(relatedDim);
fbe3c2bb   Benjamin Renard   First commit
303

5ee90a58   Benjamin Renard   Use AxisLegendMan...
304
305
306
307
	if (tableSPtr == nullptr) {
		std::string tableInfo = "Table ";
		tableInfo += std::to_string(relatedDim);
		tableInfo += " indexes";
df45df5e   Benjamin Renard   Introduce AxisLeg...
308
309
		addInfoPart(label._text, tableInfo);
		pAxis->_legend.pushLabel(label);
5ee90a58   Benjamin Renard   Use AxisLegendMan...
310
311
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
312

5ee90a58   Benjamin Renard   Use AxisLegendMan...
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
	if (((*plot->_pParameterValues)[paramId].getDim1Size() > 0) &&
		((*plot->_pParameterValues)[paramId].getDim2Size() > 0) &&
		!indexes.empty())
	{
		boost::shared_ptr<AMDA::Info::ParamTable> otherTableSPtr;
		int otherDimIndex;
		if (relatedDim == 0)
		{
			otherTableSPtr = paramInfo->getTable(1);
			otherDimIndex = indexes.front().getDim2Index();
		}
		else
		{
			otherTableSPtr = paramInfo->getTable(0);
			otherDimIndex = indexes.front().getDim1Index();
		}
e7ea756d   Benjamin Renard   Implements tables...
329
		if ((otherTableSPtr != nullptr) && !otherTableSPtr->isVariable(&plot->_parameterManager))
5ee90a58   Benjamin Renard   Use AxisLegendMan...
330
		{
e7ea756d   Benjamin Renard   Implements tables...
331
			if (otherTableSPtr->getName(&plot->_parameterManager).empty())
df45df5e   Benjamin Renard   Introduce AxisLeg...
332
				addInfoPart(label._text, "Table bounds");
5ee90a58   Benjamin Renard   Use AxisLegendMan...
333
			else
e7ea756d   Benjamin Renard   Implements tables...
334
				addInfoPart(label._text, otherTableSPtr->getName(&plot->_parameterManager));
5ee90a58   Benjamin Renard   Use AxisLegendMan...
335
336
				
			AMDA::Info::t_TableBound crtBound = otherTableSPtr->getBound(&plot->_parameterManager, otherDimIndex);
df45df5e   Benjamin Renard   Introduce AxisLeg...
337
			addBoundsPart(label._text, crtBound.min, crtBound.max);
e7ea756d   Benjamin Renard   Implements tables...
338
			addInfoPart(label._text, otherTableSPtr->getUnits(&plot->_parameterManager));
5ee90a58   Benjamin Renard   Use AxisLegendMan...
339
340
341
342
343
		}
		else
		{
			std::string part = "Table Index: ";
			part += otherDimIndex;
df45df5e   Benjamin Renard   Introduce AxisLeg...
344
			addInfoPart(label._text, part);
c2fa3b5d   Benjamin Renard   Rework of legend ...
345
		}
df45df5e   Benjamin Renard   Introduce AxisLeg...
346
		addBreakLine(label._text);
c2fa3b5d   Benjamin Renard   Rework of legend ...
347
	}
e7ea756d   Benjamin Renard   Implements tables...
348
349
	addInfoPart(label._text, tableSPtr->getName(&plot->_parameterManager));
	addInfoPart(label._text, tableSPtr->getUnits(&plot->_parameterManager));
df45df5e   Benjamin Renard   Introduce AxisLeg...
350
	pAxis->_legend.pushLabel(label);
c2fa3b5d   Benjamin Renard   Rework of legend ...
351
}
fbe3c2bb   Benjamin Renard   First commit
352

c2fa3b5d   Benjamin Renard   Rework of legend ...
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
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) {
					legend += ", ";
				}
			}
			else {
				legend += ", ";
			}
		}
		legend += info;
	}
}
fbe3c2bb   Benjamin Renard   First commit
368

8bb0f02b   Benjamin Renard   Set colors in axi...
369
void AxisLegendManager::addIndexPart(std::string& legend, ParameterIndexComponentColor& index) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
370
371
372
373
374
375
376
377
	legend += "[";
	legend += std::to_string(index.getDim1Index());
	if (index.getDim2Index() != -1) {
		legend += ",";
		legend += std::to_string(index.getDim2Index());
	}
	legend += "]";
}
fbe3c2bb   Benjamin Renard   First commit
378

c2fa3b5d   Benjamin Renard   Rework of legend ...
379
380
381
382
383
void AxisLegendManager::addIndexPart(std::string& legend, int index) {
	legend += "[";
	legend += std::to_string(index);
	legend += "]";
}
fbe3c2bb   Benjamin Renard   First commit
384

c2fa3b5d   Benjamin Renard   Rework of legend ...
385
386
void AxisLegendManager::addBoundsPart(std::string& legend, PLFLT min, PLFLT max) {
	legend += " ";
fbe3c2bb   Benjamin Renard   First commit
387

c2fa3b5d   Benjamin Renard   Rework of legend ...
388
389
	char minCount[1024];
	char maxCount[1024];
b358ee7d   Benjamin Renard   Adapt axes labels...
390
391
392
393
394
        
        int precision = computeScientificFormatPrecision(min, max);
        
        getDigitalLabel(min, precision, minCount, 1024);
        getDigitalLabel(max, precision, maxCount, 1024);
fbe3c2bb   Benjamin Renard   First commit
395

c2fa3b5d   Benjamin Renard   Rework of legend ...
396
397
398
399
	legend += std::string(minCount);
	legend += ", ";
	legend += std::string(maxCount);
}
fbe3c2bb   Benjamin Renard   First commit
400

c2fa3b5d   Benjamin Renard   Rework of legend ...
401
402
403
void AxisLegendManager::addBreakLine(std::string& legend) {
	if (!legend.empty()) {
		legend += Label::DELIMITER;
fbe3c2bb   Benjamin Renard   First commit
404
	}
c2fa3b5d   Benjamin Renard   Rework of legend ...
405
}
fbe3c2bb   Benjamin Renard   First commit
406

8bb0f02b   Benjamin Renard   Set colors in axi...
407
std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, ParameterIndexComponentColor& index) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
408
409
410
411
	std::string legend;
	addInfoPart(legend, paramInfo->getShortName());

	if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1)) {
8bb0f02b   Benjamin Renard   Set colors in axi...
412
413
414
		AMDA::Common::ParameterIndexComponent paramIndex(index.getDim1Index(), index.getDim2Index());
		if (paramInfo->getComponents(paramIndex).empty() == false)
			addInfoPart(legend, paramInfo->getComponents(paramIndex));
c2fa3b5d   Benjamin Renard   Rework of legend ...
415
		else
fbe3c2bb   Benjamin Renard   First commit
416
		{
c2fa3b5d   Benjamin Renard   Rework of legend ...
417
418
			addInfoPart(legend, paramInfo->getShortName());
			addIndexPart(legend, index);
fbe3c2bb   Benjamin Renard   First commit
419
		}
fbe3c2bb   Benjamin Renard   First commit
420
	}
c2fa3b5d   Benjamin Renard   Rework of legend ...
421
422
423
424
425
426
427

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

5ee90a58   Benjamin Renard   Use AxisLegendMan...
428
/*std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, int index) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
429
430
431
	std::string legend;
	addInfoPart(legend, paramInfo->getShortName());

5ee90a58   Benjamin Renard   Use AxisLegendMan...
432
	if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1)) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
433
434
435
436
437
438
439
440
441
442
443
                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());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
444

c2fa3b5d   Benjamin Renard   Rework of legend ...
445
        return legend;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
446
}*/
fbe3c2bb   Benjamin Renard   First commit
447

8c8ac7bf   Benjamin Renard   Write mission/ins...
448
449
450
451
452
453
454
455
456
std::string AxisLegendManager::getMissionInstrumentInfo(AMDA::Info::ParamInfoSPtr paramInfo) {
	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;
}

8bb0f02b   Benjamin Renard   Set colors in axi...
457
458
459
460
461
462
463
464
465
466
467
std::string AxisLegendManager::getMissionInfo(AMDA::Info::ParamInfoSPtr paramInfo) {
	std::string info = paramInfo->getInstrumentId();
	if (info.empty())
		return info;
	if (info.find('_') != std::string::npos) {
		info = info.substr(0, info.find('_'));
	}
	std::transform(info.begin(), info.end(), info.begin(), ::toupper);
	return info;
}

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