Blame view

src/ParamOutputImpl/Plot/TimeAxis.cc 5.56 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
/*
 * TimeAxis.cc
 *
 *  Created on: 27 nov. 2013
 *      Author: CS
 */

#include "TimeAxis.hh"
#include <iostream>
#include <map>

namespace plot {

const double TimeAxis::SECONDS_IN_MINUTES = 60.0;
const double TimeAxis::SECONDS_IN_HOUR = 60.0 * SECONDS_IN_MINUTES;
const double TimeAxis::SECONDS_IN_DAY = 24.0 * SECONDS_IN_HOUR;

/**
 * @overload Axis::getAutoMajorTickSpace
 */
double TimeAxis::getAutoMajorTickSpace(double min, double max) {
	return TimeAxis::computeAutoMajorTickSpace (min, max);
}

/**
 * @overload Axis::getAutoMajorTickSpace
 */
double TimeAxis::computeAutoMajorTickSpace(double min, double max) {
	double interval = abs(max - min);
	double basicInterval;
	double factor;
	if (interval < 3 * TimeAxis::SECONDS_IN_MINUTES) {
		// second
		factor = 1;
		basicInterval = interval;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_HOUR) {
		// minutes
		factor = SECONDS_IN_MINUTES;
		basicInterval = interval / factor;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_DAY) {
		// days
		factor = SECONDS_IN_HOUR;
		basicInterval = interval / factor;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_DAY * 7) {
		// weeks
		factor = SECONDS_IN_DAY;
		basicInterval = interval / factor;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_DAY * 365.25) {
		// years
		factor = SECONDS_IN_DAY * 7;
		basicInterval = interval / factor;
	} else {
		// a lot of years
		factor = SECONDS_IN_DAY * 365.25;
		basicInterval = interval / factor;
	}

	double t1 = log10(basicInterval);
	double np = floor(t1);
	t1 = t1 - np;

	double t2;
	if (t1 > 0.7781512503) {
		t2 = 2.0;
	} else if (t1 > 0.4771212549) {
		t2 = 1.0;
	} else if (t1 > 0.1760912591) {
		t2 = 5.0;
		np = np - 1;
	} else {
		t2 = 2.0;
		np = np - 1;
	}

	return t2 * pow(10.0, (double) np) * factor;
}

/**
 * @overload Axis::getAutoMinorTickNumber
 */
double TimeAxis::getAutoMinorTickNumber(double min, double max) {
	double interval = abs(max - min);
	double basicInterval;
	double factor;
	if (interval < 3 * TimeAxis::SECONDS_IN_MINUTES) {
		// second
		factor = 1;
		basicInterval = interval;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_HOUR) {
		// minutes
		factor = SECONDS_IN_MINUTES;
		basicInterval = interval / factor;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_DAY) {
		// days
		factor = SECONDS_IN_HOUR;
		basicInterval = interval / factor;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_DAY * 7) {
		// weeks
		factor = SECONDS_IN_DAY;
		basicInterval = interval / factor;
	} else if (interval < 3 * TimeAxis::SECONDS_IN_DAY * 365.25) {
		// years
		factor = SECONDS_IN_DAY * 7;
		basicInterval = interval / factor;
	} else {
		// a lot of years
		factor = SECONDS_IN_DAY * 365.25;
		basicInterval = interval / factor;
	}

	double t1 = log10(basicInterval);
	double np = floor(t1);
	t1 = t1 - np;

	double ns;
	if (t1 > 0.7781512503) {
		ns = 4;
	} else if (t1 > 0.4771212549) {
		ns = 5;
	} else if (t1 > 0.1760912591) {
		ns = 5;
c6a67968   Benjamin Renard   Fix some violatio...
122
		//np = np - 1;
fbe3c2bb   Benjamin Renard   First commit
123
124
125
126
127
128
129
130
131
132
133
134
	} else {
		ns = 4;
	}

	return ns;
}

std::string getPlTimeFormat(std::string userFormat, double startTime,
		double stopTime, double numberOfMajorTicks) {
	double interval = abs(stopTime - startTime);
	// interval is less than a minute, show seconds
	if (interval <= TimeAxis::SECONDS_IN_MINUTES) {
328faef9   Benjamin Renard   Fix tickmarks for...
135
		return "%H:%M:%S%3%";
fbe3c2bb   Benjamin Renard   First commit
136
137
138
139
140
141
142
	} // interval is less than an hour, show minutes
	else if (interval < TimeAxis::SECONDS_IN_HOUR) {
		/*if (!std::isnan(numberOfMajorTicks)
				&& interval / TimeAxis::SECONDS_IN_MINUTES
						< numberOfMajorTicks) {
			return "%M:%S%3%";
		}*/
328faef9   Benjamin Renard   Fix tickmarks for...
143
		return "%H:%M:%S";
fbe3c2bb   Benjamin Renard   First commit
144
145
146
147
148
149
150
151
152

	} // interval is less than an day, show hours
	else if (interval < TimeAxis::SECONDS_IN_DAY) {
		/*if (!std::isnan(numberOfMajorTicks)
				&& interval / TimeAxis::SECONDS_IN_HOUR < numberOfMajorTicks) {

			return "%H:%M:%S";
		}*/
		return "%H:%M";
243565aa   Benjamin Renard   Do not show date ...
153
154
155
	} //interval is one day and start time is at 00:00
	else if ((interval == TimeAxis::SECONDS_IN_DAY) && ((int)startTime%(int)TimeAxis::SECONDS_IN_DAY == 0)) {
		return "%H:%M";
fbe3c2bb   Benjamin Renard   First commit
156
157
158
159
160
161
162
163
164
	} // interval is more than a day, show days
	else {
		if (userFormat == "ddd/yy") {
			if (!std::isnan(numberOfMajorTicks)
					&& interval / TimeAxis::SECONDS_IN_DAY
							< numberOfMajorTicks) {
				return "%j/%H:%M";
			}
			return "%j/%y";
983f8c8c   Hacene SI HADJ MOHAND   # 7125
165
166
167
168
169
170
171
		} else if(userFormat == "DD/MM/YYYY" ){
			if (!std::isnan(numberOfMajorTicks)
					&& interval / TimeAxis::SECONDS_IN_DAY
							< numberOfMajorTicks) {
				return "%d/%H:%M";
			}
			return "%d/%m/%Y";
1af9b64b   Hacene SI HADJ MOHAND   resolution de 9751
172
173
174
175
176
177
178
179
180
181
182
183
184
185
                                        }else if(userFormat == "yyyy/dd/mm" ){
			if (!std::isnan(numberOfMajorTicks)
					&& interval / TimeAxis::SECONDS_IN_DAY
							< numberOfMajorTicks) {
				return "%d/%H:%M";
			}
			return "%Y/%m/%d";
                                        }else if(userFormat == "yyyy-dd-mm" ){
			if (!std::isnan(numberOfMajorTicks)
					&& interval / TimeAxis::SECONDS_IN_DAY
							< numberOfMajorTicks) {
				return "%d/%H:%M";
			}
			return "%Y-%m-%d";
983f8c8c   Hacene SI HADJ MOHAND   # 7125
186
                                        }else {
fbe3c2bb   Benjamin Renard   First commit
187
188
189
190
191
192
193
194
195
196
			if (!std::isnan(numberOfMajorTicks)
					&& interval / TimeAxis::SECONDS_IN_DAY
							< numberOfMajorTicks) {
				return "%d/%H:%M";
			}
			return "%d/%m/%y";
		}
	}
}

328faef9   Benjamin Renard   Fix tickmarks for...
197
198
std::string getPlStartTimeFormat(std::string userFormat, double /*startTime*/, double /*stopTime*/) {
	//double interval = stopTime - startTime;
fbe3c2bb   Benjamin Renard   First commit
199
200
	std::string dateStr;

328faef9   Benjamin Renard   Fix tickmarks for...
201
	/*if (interval >= TimeAxis::SECONDS_IN_DAY && ((int)startTime%(int)TimeAxis::SECONDS_IN_DAY != 0)) {
243565aa   Benjamin Renard   Do not show date ...
202
203
		dateStr = "%b %Y";
	}
328faef9   Benjamin Renard   Fix tickmarks for...
204
205
206
	else*/ if (userFormat == "ddd/yy") {
		//dateStr = "%b %d (%j) %Y";
		dateStr = "%j %Y";
fbe3c2bb   Benjamin Renard   First commit
207
	} else {
328faef9   Benjamin Renard   Fix tickmarks for...
208
209
		//dateStr = "%b %d %Y";
		dateStr = "%d %b %Y";
fbe3c2bb   Benjamin Renard   First commit
210
211
	}

328faef9   Benjamin Renard   Fix tickmarks for...
212
	/*if (interval < TimeAxis::SECONDS_IN_HOUR) {
fbe3c2bb   Benjamin Renard   First commit
213
		dateStr += " %H:%M";
328faef9   Benjamin Renard   Fix tickmarks for...
214
	}*/
fbe3c2bb   Benjamin Renard   First commit
215
216
217
218
	return dateStr;
}

} /* namespace plot */