Blame view

src/ParamOutputImpl/Plot/LayoutVertical.cc 7.82 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
/*
 * LayoutVertical.hh
 *
 *  Created on: Sep, 2, 2014
 *      Author: AKKA
 */


#include "LayoutVertical.hh"
#include "PlotLogger.hh"
2f0b202e   Benjamin Renard   Reverse panels or...
11
#include "DecoratorPlot.hh"
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
12
#include "PlPlotUtil.hh"
2f0b202e   Benjamin Renard   Reverse panels or...
13
14

#include <boost/range/adaptor/reversed.hpp>
fbe3c2bb   Benjamin Renard   First commit
15
16
17
18
19
20
21

namespace plot {

/**
 * @Brief Add a panel characterized by it's constraint to the layout
 */

1d1a3b8a   Erdogan Furkan   Done for tickPlot...
22
23
void LayoutVertical::addPanel (PanelConstraint panelConstraint, 
							   double preferedWidth/*=-1*/, double preferedHeight/*=-1*/, bool isHeightFixed /*=false*/, double fixedHeight /*0*/) {
fbe3c2bb   Benjamin Renard   First commit
24
25
26
27
28
29
	double width=0, height=0;

	switch (panelConstraint) {
	case PanelConstraint::MaxWidth:

		width = 1.0;
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
30
31
32
33
		if(isHeightFixed){
			height = fixedHeight;
			break;
		}
fbe3c2bb   Benjamin Renard   First commit
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
		if (preferedHeight != -1)
			height = preferedHeight;
		else
			height = _requestPanelHeight;

		break;

	case PanelConstraint::Square:

		if (preferedWidth != -1)
			width = preferedWidth;
		else
			width = _requestPanelHeight / _xyRatio;

		if (preferedHeight != -1)
			height = preferedHeight;
		else
			height = _requestPanelHeight;

		break;
	default:
		// TODO lever exception ici ???
		break;
	}

1d1a3b8a   Erdogan Furkan   Done for tickPlot...
59
	_panelsInfo.push_back (new PanelInfo (panelConstraint, preferedWidth, preferedHeight, width, height, isHeightFixed));
fbe3c2bb   Benjamin Renard   First commit
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
}

/**
 * @Brief Reset Layout internal parameters and compute optimized parameters
 * like _panelHeight, _panelWidth, _panelYSpacing...
 */

void LayoutVertical::reset (void) {
	// Reset current panels and position
	_curPanel	= 0;
	_curYPosition = 0;
	_maxWidthConstraintFound = false;

	// Compute general data for the layout depending on
	// - the number of panel
	// - their constraint
	_panelYSpacing	= _requestPanelSpacing;

	double layoutWidth, layoutHeight;
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
79
80
	double fixedHeight;
	computeLayoutSize (layoutWidth, layoutHeight,fixedHeight);
fbe3c2bb   Benjamin Renard   First commit
81
82

	// Normalize width & height if more than 1
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
83
	if(layoutHeight > (1 - fixedHeight)){
fbe3c2bb   Benjamin Renard   First commit
84
		for (auto panelInfo : _panelsInfo) {
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
85
			if(!panelInfo->_isHeightFixed){
ddb1a7c2   Erdogan Furkan   FitNesse error re...
86
87
88
89
90
91
92
93
				if(fixedHeight > 0.){
					panelInfo->_preferedHeight /= (1/(layoutHeight-fixedHeight));
					panelInfo->_height /= (1/(layoutHeight-fixedHeight));
				}
				else{
					panelInfo->_preferedHeight /= layoutHeight;
					panelInfo->_height /= layoutHeight;
				}
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
94
			}
fbe3c2bb   Benjamin Renard   First commit
95
		}
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
96
		_panelYSpacing /= (layoutHeight+fixedHeight);
fbe3c2bb   Benjamin Renard   First commit
97
98
99
100
101
102
103
104
105
106
107
108
	}

	if (layoutWidth > 1) {
		for (auto panelInfo : _panelsInfo) {
			if (panelInfo->_constraint != PanelConstraint::MaxWidth) {
				panelInfo->_preferedWidth /= layoutWidth;
				panelInfo->_width /= layoutWidth;
			}
		}
	}

	// Expand _requestPanelHeight if necessary and asked
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
109
	if ((layoutHeight <(1-fixedHeight) ) && (layoutWidth <= 1) && (_autoExpand == true)) {
fbe3c2bb   Benjamin Renard   First commit
110
111
112
113
114
115
116
117
118
119
120
		expand (1.01);
		expand (1.001);
		expand (1.0001);
	}
}

/**
 * @Brief Increase panelHeight by step until layoutHeight reach (but not over step) 1.0
 */

void LayoutVertical::expand (double ratio) {
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
121
	double fixedHeight;
fbe3c2bb   Benjamin Renard   First commit
122
123
124
125
126
127
128
	double layoutWidth, layoutHeight;
	do
	{
		// Increase panelHeight by step and keep the same ratio for panelSpacing
		_panelYSpacing	*= ratio;

		for (auto panelInfo : _panelsInfo) {
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
129
130
			if(!panelInfo->_isHeightFixed)
				panelInfo->_height *= ratio;
fbe3c2bb   Benjamin Renard   First commit
131
132
133
134
135
136
137
138
			if (panelInfo->_constraint != PanelConstraint::MaxWidth) {
				if (panelInfo->_preferedWidth != -1) {
					panelInfo->_width = panelInfo->_preferedWidth;
				} else {
					panelInfo->_width *= ratio;
				}
			}
		}
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
139
140
		computeLayoutSize (layoutWidth, layoutHeight,fixedHeight);
	} while ((layoutHeight < 1.0-fixedHeight) && (layoutWidth <= 1.0));
fbe3c2bb   Benjamin Renard   First commit
141
142
143
144
145

	// Restore last valid value for panelHeight and panelSpacing
	_panelYSpacing	/= ratio;

	for (auto panelInfo : _panelsInfo) {
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
146
147
		if(!panelInfo->_isHeightFixed)
			panelInfo->_height /= ratio;
fbe3c2bb   Benjamin Renard   First commit
148
149
150
151
152
153
		if (panelInfo->_constraint != PanelConstraint::MaxWidth) {
			if (panelInfo->_preferedWidth == -1) {
				panelInfo->_width /= ratio;
			}
		}
	}
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
154
	computeLayoutSize (layoutWidth, layoutHeight,fixedHeight);
fbe3c2bb   Benjamin Renard   First commit
155
156
}

1d1a3b8a   Erdogan Furkan   Done for tickPlot...
157
void LayoutVertical::computeLayoutSize (double &layoutWidth, double &layoutHeight, double &fixedHeight) {
fbe3c2bb   Benjamin Renard   First commit
158
159
	layoutWidth = 0;
	layoutHeight = 0;
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
160
	fixedHeight = 0;
fbe3c2bb   Benjamin Renard   First commit
161
162
163
164
	_firstPanelHeightDelta = 0;
	bool maxWidthConstraintFound = false;

	for (auto panelInfo : _panelsInfo) {
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
165
166
167
168
169
		if (panelInfo->_isHeightFixed)
			fixedHeight += (panelInfo->_height+ _panelYSpacing);
		else
			layoutHeight += (panelInfo->_height + _panelYSpacing);
		
fbe3c2bb   Benjamin Renard   First commit
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
		if (panelInfo->_width > layoutWidth)
			layoutWidth = panelInfo->_width;

		if ((maxWidthConstraintFound == false) &&
			(panelInfo->_constraint == PanelConstraint::MaxWidth)) {
			maxWidthConstraintFound = true;
			_firstPanelHeightDelta = (_firstPanelHeightFactor-1.0) * panelInfo->_height;
			layoutHeight += _firstPanelHeightDelta;
		}
	}

	// Remove one spacing if more than 1 panel
	if (_panelsInfo.size () > 1)
		layoutHeight -= _panelYSpacing;
}

Bounds & LayoutVertical::getNextBounds (PanelConstraint panelConstraint) {

	PanelInfo *panelInfo = _panelsInfo.at(_curPanel);

	// Computes panels position on the layout depending on their constraints
	switch (panelConstraint) {

	case PanelConstraint::MaxWidth:
		_computedPanelBounds._x = 0;
		_computedPanelBounds._y = _curYPosition;
		_computedPanelBounds._width = 1.0;
		_computedPanelBounds._height = panelInfo->_height;

		// The first MaxWidth panel can have an extra panel height
		if (_maxWidthConstraintFound == false) {
			_maxWidthConstraintFound = true;
			_computedPanelBounds._height	+= _firstPanelHeightDelta;
			_curYPosition 					+= _firstPanelHeightDelta;
		}

		_curPanel++;
		_curYPosition += (panelInfo->_height + _panelYSpacing);
		break;

	case PanelConstraint::Square:
		// Compute x position of the SquarePanel on the line (centered)
		_computedPanelBounds._x = 0.5 - (panelInfo->_width / 2.0);
		_computedPanelBounds._y = _curYPosition;

		_computedPanelBounds._width = panelInfo->_width;
		_computedPanelBounds._height = panelInfo->_height;

		_curPanel++;
		_curYPosition += (panelInfo->_height + _panelYSpacing);
		break;

	default:
		// TODO lever exception ici ???
		break;
	}

	return _computedPanelBounds;
}

1d1a3b8a   Erdogan Furkan   Done for tickPlot...
230
void LayoutVertical::computePanelsPosition (std::vector<boost::shared_ptr<PanelPlotOutput>> _plots,  std::map<std::string, ParameterData> *parameterValues) {
2f0b202e   Benjamin Renard   Reverse panels or...
231
	// Add panels constraint to the layout
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
232
233

	bool isFirstPlot = true;
2f0b202e   Benjamin Renard   Reverse panels or...
234
	for (auto plot : boost::adaptors::reverse(_plots)) {
8c860e4f   Benjamin Renard   Rework for tickpl...
235
236
		if (!plot->isStandalone())
			continue;
2f0b202e   Benjamin Renard   Reverse panels or...
237

1d1a3b8a   Erdogan Furkan   Done for tickPlot...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
		double height = 0;
		if(plot->isHeightFixed()){
			bool isLegendHeightAdded = false;
			for (auto parameter : plot->_parameterAxesList)
			{
				SeriesProperties lSeries;
				for (auto lSeries : parameter.getYSeriePropertiesList())
				{
					boost::shared_ptr<Axis> lAxis( plot->_panel->getAxis(lSeries.getXAxisId()));
					Font legendFont(lAxis->getLegendFont(plot->_panel.get()));
					PlPlotUtil::setPlFont(legendFont);
					CharSize legendSize = PlPlotUtil::getCharacterSizeInPlPage(plot->_panel->_page);
					unsigned int nbComponent = lSeries.getIndexList(parameterValues).size();
					if(plot->subTypeName()=="tickPlot"){
						if (!isLegendHeightAdded){
							if(isFirstPlot){
								height += 0.05;
							}
							height += (nbComponent + 2) * legendSize.second*1.4;
							isLegendHeightAdded = true;
						}
						else{
							height += 0.05+ (nbComponent + 1) * legendSize.second*1.4;
						}
					}
					else if(plot->subTypeName()=="statusPlot"){
						if(isFirstPlot){
							if(!isLegendHeightAdded){
								height +=  5.3*legendSize.second;
								isLegendHeightAdded = true;
							}	
						}
						else{
							height += 0.025;
						}
						height += nbComponent*0.025 + nbComponent*legendSize.second*2.4;
					}
					else{
						continue;
					}
				}
			}
			
		}
		
2f0b202e   Benjamin Renard   Reverse panels or...
283
284
		this->addPanel ( plot->getLayoutConstraint(),
							plot->_panel->_preferedWidth,
1d1a3b8a   Erdogan Furkan   Done for tickPlot...
285
286
287
288
289
							plot->_panel->_preferedHeight,
							plot->isHeightFixed(),
							height);
		if(isFirstPlot)
			isFirstPlot = false;
2f0b202e   Benjamin Renard   Reverse panels or...
290
291
292
293
294
295
296
	}

	// Reset layout
	this->reset();


	for (auto plot : boost::adaptors::reverse(_plots)) {
8c860e4f   Benjamin Renard   Rework for tickpl...
297
298
		if (!plot->isStandalone())
			continue;
2f0b202e   Benjamin Renard   Reverse panels or...
299
300
301
302
303

		plot->_panel->_bounds = this->getNextBounds (plot->getLayoutConstraint());
	}
}

fbe3c2bb   Benjamin Renard   First commit
304
}