Blame view

src/ParamOutputImpl/Plot/TimeAxis.hh 2.87 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
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
46
47
48
49
50
51
52
53
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
95
96
97
98
99
100
101
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
/*
 * TimeAxis.hh
 *
 *  Created on: 22 nov. 2013
 *      Author: CS
 */

#ifndef TIMEAXIS_HH_
#define TIMEAXIS_HH_

#include "Axis.hh"

namespace plot {

/**
 * @brief Axis implementation for time.
 */
class TimeAxis: public plot::Axis {
public:
	TimeAxis() :
			Axis(), _onlyTickmarks(false){
	}

	TimeAxis(const TimeAxis& axis) :
			Axis(axis), _timeFormat(axis._timeFormat), _onlyTickmarks(axis._onlyTickmarks) {
	}

	virtual ~TimeAxis() {
	}

	/**
	 * @brief Label and start date time user format (QSAS).
	 */
	std::string _timeFormat;

	/**
	 * @brief For TU.
	 */
	void dump(std::ostream& out) {
		Axis::dump(out);
		out << _id << ".axis.timeFormat=" << _timeFormat;
	}

	/**
	 * @overload Axis::getPlotOpt
	 */
	virtual std::string getPlotOpt() {
		// o : use custom labelling (to hide min date)

		std::string options = "o";
		if( _visible && isOnlyTickmarks() ){
			options+="x";
			switch( _position ){
			case PlotCommon::Position::POS_TOP:
			case PlotCommon::Position::POS_RIGHT:
				options+="m";
			break;
			case PlotCommon::Position::POS_BOTTOM:
			case PlotCommon::Position::POS_LEFT :
				options+="n";
			break;
			default:
				options+="n";
				break;
			}
		}
		else{
			options += Axis::getPlotOpt();
		}
		return options;
	}

	void setOnlyTickmarks(bool flag_){
		_onlyTickmarks = flag_;
	}
	bool isOnlyTickmarks(){
		return _onlyTickmarks;
	}

	/**
	 * @overload Axis::getAutoMajorTickSpace
	 */
	virtual double getAutoMajorTickSpace(double min, double max);

	/**
	 * @overload Axis::getAutoMinorTickNumber
	 */
	virtual double getAutoMinorTickNumber(double min, double max);

	/**
	 * @overload Axis::getAutoMinorTickNumber
	 */
	static double computeAutoMajorTickSpace(double min, double max);
	/**
	 * Number of seconds in a day.
	 */
	static const double SECONDS_IN_DAY;

	/**
	 * Number of seconds in an hour.
	 */
	static const double SECONDS_IN_HOUR;

	/**
	 * Number of seconds in a minute.
	 */
	static const double SECONDS_IN_MINUTES;
private:
	/**
	 * when this flag is set, only labels at major tick marks are displayed.
	 */
	bool _onlyTickmarks;

};

inline std::ostream& operator <<(std::ostream& out, const TimeAxis& axis) {
	out << axis._id << ".axis.timeFormat=" << axis._timeFormat << std::endl;
	out << axis._id << ".axis.showLegend=" << axis._showLegend << std::endl;
	out << axis._id << ".axis.showTickMark=" << axis._showTickMark << std::endl;
	return out;
}

/**
 * @brief Calculate label date format according to a user format (dd/mm/yy or ddd/yy)
 * and the time format according to the time interval.
 */
std::string getPlTimeFormat(std::string userFormat, double startTime,
		double stopTime, double numberOfMajorTicks);

/**
 * @brief Calculate start date format according to a user format (dd/mm/yy or ddd/yy)
 * and time interval.
 */
std::string getPlStartTimeFormat(std::string userFormat, double startTime,
		double stopTime);

} /* namespace plot */
#endif /* TIMEAXIS_HH_ */