Blame view

src/ParamOutputImpl/Plot/AxisLegendManager.cc 13.2 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
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void AxisLegendManager::configureXAxisLegendForSeries(
		XYPlot* plot)
{
	// Build list of all indexes used by each parameters for each x axes
	std::map<std::string, AxisParamsComponents> axesParamsComponents;

	SeriesProperties lSeriesProperties;
	for (auto param: plot->_parameterAxesList) {
		for(auto index: param.getYSerieIndexList(plot->_pParameterValues)) {
			lSeriesProperties = param.getYSeriePropertiesAt(index);
			if(!lSeriesProperties.hasYAxis() || !lSeriesProperties.hasXAxis())
				continue;

			ParameterAxes& xParameter = plot->getParameterAxeOnXAxis(lSeriesProperties.getXAxisId());

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

			XSeriesProperties& xSerie = plot->getSerieOnXAxisfromParameter(lSeriesProperties.getXAxisId(), xParameter);

			std::string xAxisId = xSerie.getAxisId();

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

			AMDA::Common::ParameterIndexComponent xIndex = xSerie.getIndex();
			pushComponentInList(xSerie.getXParamIds()[yParamId], xIndex, axesParamsComponents[xAxisId]);
		}
	}

	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 ...
46
47
void AxisLegendManager::configureYAxisLegendForSpectro(
                PanelPlotOutput* plot)
fbe3c2bb   Benjamin Renard   First commit
48
{
c2fa3b5d   Benjamin Renard   Rework of legend ...
49
50
51
52
	for (auto param: plot->_parameterAxesList) {
		std::shared_ptr<SpectroProperties> spectroPropertiesPtr = param.getSpectroProperties();
		if (spectroPropertiesPtr == nullptr)
			continue; //no spectro defined
fbe3c2bb   Benjamin Renard   First commit
53

c2fa3b5d   Benjamin Renard   Rework of legend ...
54
55
		if(!spectroPropertiesPtr->hasYAxis())
			continue;
fbe3c2bb   Benjamin Renard   First commit
56

c2fa3b5d   Benjamin Renard   Rework of legend ...
57
58
59
60
		std::string yAxisId = spectroPropertiesPtr->getYAxisId();
		boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
		if (lYAxis.get() == nullptr)
			continue;
fbe3c2bb   Benjamin Renard   First commit
61

c2fa3b5d   Benjamin Renard   Rework of legend ...
62
63
		if (!lYAxis->_legend._text.empty())
			continue;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
64
65
		
		setAxisLegendForTable(plot, lYAxis, param._originalParamId, spectroPropertiesPtr->getParamId(), spectroPropertiesPtr->getIndexes(), spectroPropertiesPtr->getRelatedDim());
c2fa3b5d   Benjamin Renard   Rework of legend ...
66
		return;
fbe3c2bb   Benjamin Renard   First commit
67
	}
c2fa3b5d   Benjamin Renard   Rework of legend ...
68
69
70
71
72
73
}

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

c2fa3b5d   Benjamin Renard   Rework of legend ...
75
76
	// Build list of all indexes used by each parameters for each y axes
	std::map<std::string, AxisParamsComponents> axesParamsComponents;
fbe3c2bb   Benjamin Renard   First commit
77
78
	for (auto param: plot->_parameterAxesList)
	{
fbe3c2bb   Benjamin Renard   First commit
79
80
81
82
83
84
85
		for(auto index: param.getYSerieIndexList(plot->_pParameterValues))
		{
			lSeriesProperties = param.getYSeriePropertiesAt(index);
			if(!lSeriesProperties.hasYAxis())
				continue;

			std::string yAxisId = lSeriesProperties.getYAxisId();
fbe3c2bb   Benjamin Renard   First commit
86
87
			boost::shared_ptr<Axis> lYAxis = plot->_panel->getAxis(yAxisId);
			if (lYAxis.get() == nullptr) {
fbe3c2bb   Benjamin Renard   First commit
88
				continue;
c2fa3b5d   Benjamin Renard   Rework of legend ...
89
 			}
fbe3c2bb   Benjamin Renard   First commit
90

c2fa3b5d   Benjamin Renard   Rework of legend ...
91
92
93
			pushComponentInList(lSeriesProperties.getParamId(), index, axesParamsComponents[yAxisId]);
		}
	}
fbe3c2bb   Benjamin Renard   First commit
94

c2fa3b5d   Benjamin Renard   Rework of legend ...
95
96
97
98
99
100
	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
101

5ee90a58   Benjamin Renard   Use AxisLegendMan...
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
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) {
		for(auto index: param.getYSerieIndexList(plot->_pParameterValues)) {
			lSeriesProperties = param.getYSeriePropertiesAt(index);

			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());

			AMDA::Common::ParameterIndexComponent colorSerieIndex = AMDA::Common::ParameterIndexComponent(-1,-1);
			if (lColorSerieProperties.getIndex() > -1)
				colorSerieIndex = AMDA::Common::ParameterIndexComponent(lColorSerieProperties.getIndex(), -1);
			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;
	}
}

c2fa3b5d   Benjamin Renard   Rework of legend ...
167
168
169
170
171
172
173
174
175
176
177
void AxisLegendManager::pushComponentInList(std::string paramId, AMDA::Common::ParameterIndexComponent& index, AxisParamsComponents& axisParamsComponents) {
	if (index == AMDA::Common::ParameterIndexComponent(-1,-1)) {
		//All indexes of this parameter are used
		axisParamsComponents[paramId].clear();
		axisParamsComponents[paramId].push_back(index);
	}
	else {
		if (axisParamsComponents[paramId].size() > 0) {
			if (axisParamsComponents[paramId].front() == AMDA::Common::ParameterIndexComponent(-1,-1)) {
				//Skip. All components already defined for this paramter on this axis
				return;
fbe3c2bb   Benjamin Renard   First commit
178
			}
c2fa3b5d   Benjamin Renard   Rework of legend ...
179
180
181
182
183
184
		}
		if (std::find(axisParamsComponents[paramId].begin(), axisParamsComponents[paramId].end(), index) == axisParamsComponents[paramId].end()) {
			//Add this components for this axis
			axisParamsComponents[paramId].push_back(index);
		}
	}
fbe3c2bb   Benjamin Renard   First commit
185

c2fa3b5d   Benjamin Renard   Rework of legend ...
186
}
fbe3c2bb   Benjamin Renard   First commit
187

c2fa3b5d   Benjamin Renard   Rework of legend ...
188
189
190
191
void AxisLegendManager::setAxisLegendForSeries(PanelPlotOutput* plot, boost::shared_ptr<Axis>& pAxis, AxisParamsComponents& axisParamsComponents) {
	if (pAxis == nullptr || !pAxis->_legend._text.empty()) {
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
192

c2fa3b5d   Benjamin Renard   Rework of legend ...
193
194
	// Retrieve ParamInfo Manager
	ParamMgr* piMgr = ParamMgr::getInstance();
fbe3c2bb   Benjamin Renard   First commit
195

c2fa3b5d   Benjamin Renard   Rework of legend ...
196
197
198
199
200
201
202
203
204
205
	//Build list of legend lines
	std::list<std::string> legendLines;
	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
			paramsComponents.second.clear();
			paramsComponents.second.push_back(AMDA::Common::ParameterIndexComponent(-1,-1));
		}
8c8ac7bf   Benjamin Renard   Write mission/ins...
206
		bool isFirstComponent = true;
c2fa3b5d   Benjamin Renard   Rework of legend ...
207
208
209
		for (auto components : paramsComponents.second) {
			if (paramInfo == nullptr)
				continue;
8c8ac7bf   Benjamin Renard   Write mission/ins...
210
211
212
213
214
215
			if ((axisParamsComponents.size() == 1) && isFirstComponent) {
				std::string info = getMissionInstrumentInfo(paramInfo);
				if (!info.empty()) {
					legendLines.push_back(info);
				}
			}
c2fa3b5d   Benjamin Renard   Rework of legend ...
216
			legendLines.push_back(getParamLegend(paramInfo, components));
8c8ac7bf   Benjamin Renard   Write mission/ins...
217
			isFirstComponent = false;
fbe3c2bb   Benjamin Renard   First commit
218
219
220
		}
	}

c2fa3b5d   Benjamin Renard   Rework of legend ...
221
222
223
224
	//Set legend to axis
	for (auto line : legendLines) {
		addBreakLine(pAxis->_legend._text);
		pAxis->_legend._text += line;
fbe3c2bb   Benjamin Renard   First commit
225
226
227
	}
}

5ee90a58   Benjamin Renard   Use AxisLegendMan...
228
229
230
void AxisLegendManager::setAxisLegendForSpectro(PanelPlotOutput* plot, boost::shared_ptr<Axis>& pAxis, std::string originalParamId) {
	if (pAxis == nullptr || !pAxis->_legend._text.empty()) {
		return;
fbe3c2bb   Benjamin Renard   First commit
231
	}
fbe3c2bb   Benjamin Renard   First commit
232

5ee90a58   Benjamin Renard   Use AxisLegendMan...
233
234
235
236
237
238
239
	// 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 ...
240

18110a9d   Benjamin Renard   Use parameter sho...
241
	addInfoPart(pAxis->_legend._text, paramInfo->getShortName());
5ee90a58   Benjamin Renard   Use AxisLegendMan...
242
	addInfoPart(pAxis->_legend._text, paramInfo->getUnits());
c2fa3b5d   Benjamin Renard   Rework of legend ...
243
244
}

5ee90a58   Benjamin Renard   Use AxisLegendMan...
245
246
247
248
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._text.empty()) {
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
249

5ee90a58   Benjamin Renard   Use AxisLegendMan...
250
251
252
253
254
255
256
257
	// 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
258

fb96d5d5   Benjamin Renard   Add mission name ...
259
260
261
262
263
264
	std::string info = getMissionInstrumentInfo(paramInfo);
	if (!info.empty()) {
		addInfoPart(pAxis->_legend._text, info);
		addBreakLine(pAxis->_legend._text);
	}

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

5ee90a58   Benjamin Renard   Use AxisLegendMan...
268
269
270
271
272
273
274
	if (tableSPtr == nullptr) {
		std::string tableInfo = "Table ";
		tableInfo += std::to_string(relatedDim);
		tableInfo += " indexes";
		addInfoPart(pAxis->_legend._text, tableInfo);
		return;
	}
fbe3c2bb   Benjamin Renard   First commit
275

5ee90a58   Benjamin Renard   Use AxisLegendMan...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
	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();
		}
		if ((otherTableSPtr != nullptr) && !otherTableSPtr->isVariable())
		{
			if (otherTableSPtr->getName().empty())
				addInfoPart(pAxis->_legend._text, "Table bounds");
			else
				addInfoPart(pAxis->_legend._text, otherTableSPtr->getName());
				
			AMDA::Info::t_TableBound crtBound = otherTableSPtr->getBound(&plot->_parameterManager, otherDimIndex);
			addBoundsPart(pAxis->_legend._text, crtBound.min, crtBound.max);
			addInfoPart(pAxis->_legend._text, otherTableSPtr->getUnits());
		}
		else
		{
			std::string part = "Table Index: ";
			part += otherDimIndex;
			addInfoPart(pAxis->_legend._text, part);
c2fa3b5d   Benjamin Renard   Rework of legend ...
308
		}
5ee90a58   Benjamin Renard   Use AxisLegendMan...
309
		addBreakLine(pAxis->_legend._text);
c2fa3b5d   Benjamin Renard   Rework of legend ...
310
	}
5ee90a58   Benjamin Renard   Use AxisLegendMan...
311
312
	addInfoPart(pAxis->_legend._text, tableSPtr->getName());
	addInfoPart(pAxis->_legend._text, tableSPtr->getUnits());
c2fa3b5d   Benjamin Renard   Rework of legend ...
313
}
fbe3c2bb   Benjamin Renard   First commit
314

c2fa3b5d   Benjamin Renard   Rework of legend ...
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
330

c2fa3b5d   Benjamin Renard   Rework of legend ...
331
332
333
334
335
336
337
338
339
void AxisLegendManager::addIndexPart(std::string& legend, AMDA::Common::ParameterIndexComponent& index) {
	legend += "[";
	legend += std::to_string(index.getDim1Index());
	if (index.getDim2Index() != -1) {
		legend += ",";
		legend += std::to_string(index.getDim2Index());
	}
	legend += "]";
}
fbe3c2bb   Benjamin Renard   First commit
340

c2fa3b5d   Benjamin Renard   Rework of legend ...
341
342
343
344
345
void AxisLegendManager::addIndexPart(std::string& legend, int index) {
	legend += "[";
	legend += std::to_string(index);
	legend += "]";
}
fbe3c2bb   Benjamin Renard   First commit
346

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

c2fa3b5d   Benjamin Renard   Rework of legend ...
350
351
352
353
	PLINT axis = 0;
	PLPointer data = NULL;
	char minCount[1024];
	char maxCount[1024];
fbe3c2bb   Benjamin Renard   First commit
354

c2fa3b5d   Benjamin Renard   Rework of legend ...
355
356
	generateDigitalLabel(axis, min, minCount, 1024, data);
	generateDigitalLabel(axis, max, maxCount, 1024, data);
fbe3c2bb   Benjamin Renard   First commit
357

c2fa3b5d   Benjamin Renard   Rework of legend ...
358
359
360
361
	legend += std::string(minCount);
	legend += ", ";
	legend += std::string(maxCount);
}
fbe3c2bb   Benjamin Renard   First commit
362

c2fa3b5d   Benjamin Renard   Rework of legend ...
363
364
365
void AxisLegendManager::addBreakLine(std::string& legend) {
	if (!legend.empty()) {
		legend += Label::DELIMITER;
fbe3c2bb   Benjamin Renard   First commit
366
	}
c2fa3b5d   Benjamin Renard   Rework of legend ...
367
}
fbe3c2bb   Benjamin Renard   First commit
368

c2fa3b5d   Benjamin Renard   Rework of legend ...
369
370
371
372
373
374
375
376
std::string AxisLegendManager::getParamLegend(AMDA::Info::ParamInfoSPtr paramInfo, AMDA::Common::ParameterIndexComponent& 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
fbe3c2bb   Benjamin Renard   First commit
377
		{
c2fa3b5d   Benjamin Renard   Rework of legend ...
378
379
			addInfoPart(legend, paramInfo->getShortName());
			addIndexPart(legend, index);
fbe3c2bb   Benjamin Renard   First commit
380
		}
fbe3c2bb   Benjamin Renard   First commit
381
	}
c2fa3b5d   Benjamin Renard   Rework of legend ...
382
383
384
385
386
387
388

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

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

5ee90a58   Benjamin Renard   Use AxisLegendMan...
393
	if ((index.getDim1Index() != -1) || (index.getDim2Index() != -1)) {
c2fa3b5d   Benjamin Renard   Rework of legend ...
394
395
396
397
398
399
400
401
402
403
404
                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...
405

c2fa3b5d   Benjamin Renard   Rework of legend ...
406
        return legend;
5ee90a58   Benjamin Renard   Use AxisLegendMan...
407
}*/
fbe3c2bb   Benjamin Renard   First commit
408

8c8ac7bf   Benjamin Renard   Write mission/ins...
409
410
411
412
413
414
415
416
417
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;
}

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