Blame view

src/ParamOutputImpl/Plot/PanelPlotOutput.cc 104 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * PanelPlotOutput.cc
 *
 *  Created on: 29 oct. 2013
 *      Author: CS
 */

#include "PanelPlotOutput.hh"
#include "ColormapManager.hh"
#include "ColorAxis.hh"
#include "ParameterManager.hh"
#include "Page.hh"
#include "ShadesTools.hh"
#include "PlotLogger.hh"
#include "TimeUtil.hh"
#include "ParamMgr.hh"
7f7e3b39   Benjamin Renard   Fix a bug with st...
17
#include "DecoratorPlot.hh"
f6eaec4e   Benjamin Renard   Optimize plot ele...
18
#include "PlPlotUtil.hh"
fbe3c2bb   Benjamin Renard   First commit
19

8bb0f02b   Benjamin Renard   Set colors in axi...
20
#include <boost/range/adaptor/reversed.hpp>
fbe3c2bb   Benjamin Renard   First commit
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

using namespace AMDA::Parameters;
using namespace AMDA::Info;

namespace plot {

/**
 * Width character proportion is approximatively 0.83 times smaller than height.
 */
const float PanelPlotOutput::CHAR_RATIO = 5./6.;

const float PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR = 0.75;

// Vertical is for Y axis.
const float PanelPlotOutput::VERTICAL_TICK_LENGTH_LIMIT = 0.5;
// Horizontal is for X axis.
const float PanelPlotOutput::HORIZONTAL_TICK_LENGTH_LIMIT = 0.75;


PanelPlotOutput::PanelPlotOutput(AMDA::Parameters::ParameterManager& manager, boost::shared_ptr<Panel> panel) :
		_panel(panel),
		_parameterManager(manager),
		_pParameterValues(NULL),
		_timeIntervalListPtr(NULL),
fbe3c2bb   Benjamin Renard   First commit
45
46
47
48
49
50
51
52
53
		_panelPlotXYRatio(1),
		_leftAxisTickMarkWidth(0),
		_automaticSerieColorCursor(0)
{
}

PanelPlotOutput::~PanelPlotOutput() {
}

fbe3c2bb   Benjamin Renard   First commit
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
double getVerticalTickLength(Axis* pAxis, double charHeight) {
	float horizontalTickLengthLimit = PanelPlotOutput::HORIZONTAL_TICK_LENGTH_LIMIT;
	float defaultTickLengthFactor	= PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR;
	double tickLengthFactor 		= pAxis->_tick._lengthFactor;

	if ((!isnan(tickLengthFactor)) &&	(tickLengthFactor > horizontalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((tickLengthFactor - horizontalTickLengthLimit)
				* charHeight) / (defaultTickLengthFactor) );
	} else if ((isnan(tickLengthFactor))	&& (defaultTickLengthFactor > horizontalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((defaultTickLengthFactor - horizontalTickLengthLimit)
				* charHeight) / (defaultTickLengthFactor) );
	} else {
		return charHeight;
	}
}

double getHorizontalTickLength (Axis* pAxis, double charHeight) {
	float verticalTickLengthLimit 	= PanelPlotOutput::VERTICAL_TICK_LENGTH_LIMIT;
	float defaultTickLengthFactor	= PanelPlotOutput::DEFAULT_TICK_LENGTH_FACTOR;
	double tickLengthFactor 		= pAxis->_tick._lengthFactor;

	if ((!isnan(tickLengthFactor)) && (tickLengthFactor > verticalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((tickLengthFactor - verticalTickLengthLimit)
				* charHeight * PanelPlotOutput::CHAR_RATIO) / (defaultTickLengthFactor) );
	} else if ((isnan(tickLengthFactor)) && (defaultTickLengthFactor > verticalTickLengthLimit)) {
		// 1 character size is equal to 0.75 tick length.
		return charHeight + ( ((defaultTickLengthFactor - verticalTickLengthLimit)
				* charHeight * PanelPlotOutput::CHAR_RATIO) / (defaultTickLengthFactor) );
	} else {
		return charHeight;
	}
}

void PanelPlotOutput::calculatePlotArea(Bounds& bounds_) {
	double topSpace 	= 0;
	double bottomSpace 	= 0;
	double leftSpace 	= 0;
	double rightSpace	= 0;
fbe3c2bb   Benjamin Renard   First commit
95

b96aa975   Benjamin Renard   Draw border aroun...
96
97
98
99
100
101
102
	//Init
	_plotAreaSideSet[PlotCommon::Position::POS_TOP] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_BOTTOM] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_RIGHT] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_LEFT] = false;
	_plotAreaSideSet[PlotCommon::Position::POS_CENTER] = false;

f6eaec4e   Benjamin Renard   Optimize plot ele...
103
104
105
	// Reserve space for title
	double titleHeight = 0;
	_panel->reserveSpaceForTitle(topSpace, bottomSpace, titleHeight);
fbe3c2bb   Benjamin Renard   First commit
106

f6eaec4e   Benjamin Renard   Optimize plot ele...
107
	// Reserve space for axes
bdc50075   Benjamin Renard   Fix bug for posit...
108
109
110
111
112
113
114
115
116
117

	//
	std::map<PlotCommon::Position, int>  nbAxesBySide;
	nbAxesBySide[PlotCommon::Position::POS_TOP] = 0;
	nbAxesBySide[PlotCommon::Position::POS_BOTTOM] = 0;
	nbAxesBySide[PlotCommon::Position::POS_RIGHT] = 0;
	nbAxesBySide[PlotCommon::Position::POS_LEFT] = 0;
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it)
	{
		boost::shared_ptr<Axis> lAxis = it->second;
b76d3cfc   Benjamin Renard   Fix color axis po...
118
		if ((lAxis == nullptr) || (lAxis->_isZAxis) || (!lAxis->_used) || (!lAxis->_visible) || (lAxis->_position == PlotCommon::Position::POS_CENTER))
bdc50075   Benjamin Renard   Fix bug for posit...
119
120
121
122
			continue;
		++nbAxesBySide[lAxis->_position];
	}

08ec1dde   Benjamin Renard   Add propertie _us...
123
	// ZAxis must be drawn at last!
08ec1dde   Benjamin Renard   Add propertie _us...
124
125
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it)
	{
f6eaec4e   Benjamin Renard   Optimize plot ele...
126
		//Add X and Y axis
08ec1dde   Benjamin Renard   Add propertie _us...
127
		boost::shared_ptr<Axis> lAxis = it->second;
b96aa975   Benjamin Renard   Draw border aroun...
128
		if ((lAxis == nullptr) || (lAxis->_isZAxis))
08ec1dde   Benjamin Renard   Add propertie _us...
129
			continue;
bdc50075   Benjamin Renard   Fix bug for posit...
130
		reserveSpaceForAxis(lAxis, titleHeight, nbAxesBySide, topSpace, bottomSpace, leftSpace, rightSpace);
08ec1dde   Benjamin Renard   Add propertie _us...
131
	}
f6eaec4e   Benjamin Renard   Optimize plot ele...
132

08ec1dde   Benjamin Renard   Add propertie _us...
133
134
	for (Axes::iterator it = _panel->_axes.begin(); it != _panel->_axes.end();	++it)
	{
f6eaec4e   Benjamin Renard   Optimize plot ele...
135
		//Add Z axis
08ec1dde   Benjamin Renard   Add propertie _us...
136
		boost::shared_ptr<Axis> lAxis = it->second;
b96aa975   Benjamin Renard   Draw border aroun...
137
		if ((lAxis == nullptr) || (!lAxis->_isZAxis))
08ec1dde   Benjamin Renard   Add propertie _us...
138
			continue;
bdc50075   Benjamin Renard   Fix bug for posit...
139
		reserveSpaceForAxis(lAxis, titleHeight, nbAxesBySide, topSpace, bottomSpace, leftSpace, rightSpace);
08ec1dde   Benjamin Renard   Add propertie _us...
140
141
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
142
143
144
145
146
	// Get character size for panel.
	PlPlotUtil::setPlFont(_panel->getFont());
	CharSize lCharSizePanel = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);
	double panelCharWidth 	= lCharSizePanel.first;
	double panelCharHeight 	= lCharSizePanel.second;
fbe3c2bb   Benjamin Renard   First commit
147

fbe3c2bb   Benjamin Renard   First commit
148
149
150
151
152
	//add params legend right space when outside
	if (!_panel->_paramsLegendProperties.getLegendLines().empty() &&
			_panel->_paramsLegendProperties.isVisible() &&
			(_panel->_paramsLegendProperties.getPosition() == ParamsLegendPosition::POS_OUTSIDE))
	{
f6eaec4e   Benjamin Renard   Optimize plot ele...
153
154
		PlPlotUtil::setPlFont(_panel->_paramsLegendProperties.getFont());
		CharSize lCharSizeLegend = PlPlotUtil::getCharacterSizeInPlPage(_panel->_page);
fbe3c2bb   Benjamin Renard   First commit
155
156
157
158
159
160
161
162
163
		double legendCharWidth 	= lCharSizeLegend.first;

		//set offset
		_panel->_paramsLegendProperties.setLeftOffset(rightSpace);

		//reserve place for legend
		rightSpace += _panel->_paramsLegendProperties.getEstimateWidth(legendCharWidth);
	}

f6eaec4e   Benjamin Renard   Optimize plot ele...
164
	// Reserve space for text legend ( maximum 1 text legend by position
fbe3c2bb   Benjamin Renard   First commit
165
166
167
168
169
170
	bool	leftTextLegendFound		= false;
	bool	rightTextLegendFound 	= false;
	bool	topTextLegendFound 		= false;
	bool	bottomTextLegendFound 	= false;

	for (auto textLegendProp : _panel->_textLegendPropertiesList) {
f6eaec4e   Benjamin Renard   Optimize plot ele...
171
		bool toDraw = true;
fbe3c2bb   Benjamin Renard   First commit
172
173
174

		switch (textLegendProp->getPosition()) {
		case TextLegendPosition::POS_LEFT :
f6eaec4e   Benjamin Renard   Optimize plot ele...
175
176
177
			if (leftTextLegendFound)
				toDraw = false;
			leftTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
178
			break;
fbe3c2bb   Benjamin Renard   First commit
179
		case TextLegendPosition::POS_RIGHT :
f6eaec4e   Benjamin Renard   Optimize plot ele...
180
181
182
			if (rightTextLegendFound)
				toDraw = false;
			rightTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
183
			break;
fbe3c2bb   Benjamin Renard   First commit
184
		case TextLegendPosition::POS_TOP :
f6eaec4e   Benjamin Renard   Optimize plot ele...
185
186
187
			if (topTextLegendFound)
				toDraw = false;
			topTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
188
			break;
fbe3c2bb   Benjamin Renard   First commit
189
		case TextLegendPosition::POS_BOTTOM :
f6eaec4e   Benjamin Renard   Optimize plot ele...
190
191
192
			if (bottomTextLegendFound)
				toDraw = false;
			bottomTextLegendFound = true;
fbe3c2bb   Benjamin Renard   First commit
193
194
			break;
		}
f6eaec4e   Benjamin Renard   Optimize plot ele...
195
196
197

		if (toDraw)
			reserveSpaceForTextLegend (textLegendProp, titleHeight, topSpace, bottomSpace, leftSpace, rightSpace);
fbe3c2bb   Benjamin Renard   First commit