Blame view

src/ParamOutputImpl/Plot/Range.cc 2.48 KB
fbe3c2bb   Benjamin Renard   First commit
1
2
3
4
5
6
7
8
/*
 * Range.cc
 *
 *  Created on: 17 déc. 2013
 *      Author: CS
 */

#include "Range.hh"
e062d6ef   Benjamin Renard   Fix axes range wh...
9
#include "ParamData.hh"
fbe3c2bb   Benjamin Renard   First commit
10
11
12
13
14
15
16
17
18
19
#include "iostream"

namespace plot {

Range extendRange(Range pRange) {
	// Check in term of value which is the maximum value
	// and which is the minimum.

	double lMin = pRange.getMin();
	double lMax = pRange.getMax();
641ba7e4   Hacene SI HADJ MOHAND   ok for time plot
20
                    double margin = pRange.getMargin();
fbe3c2bb   Benjamin Renard   First commit
21
22
23
	if(lMin < lMax) {
		if ( (lMin < 1 && lMin > -1) &&
			(lMax < 1 && lMax > -1) ) {
641ba7e4   Hacene SI HADJ MOHAND   ok for time plot
24
25
			lMin = extend2LowerValue(lMin-margin*(lMax-lMin));
			lMax = extend2UpperValue(lMax+margin*(lMax-lMin));
fbe3c2bb   Benjamin Renard   First commit
26
		} else {
641ba7e4   Hacene SI HADJ MOHAND   ok for time plot
27
28
			lMax = ceil(lMax+margin*(lMax-lMin));
			lMin = floor(lMin-margin*(lMax-lMin));
fbe3c2bb   Benjamin Renard   First commit
29
30
31
32
		}
	} else {
		if ( (lMin < 1 && lMin > -1) &&
			(lMax < 1 && lMax > -1) ) {
641ba7e4   Hacene SI HADJ MOHAND   ok for time plot
33
34
			lMin = extend2UpperValue(lMin+margin*(lMax-lMin));
			lMax = extend2LowerValue(lMax-margin*(lMax-lMin));
fbe3c2bb   Benjamin Renard   First commit
35
		} else {
641ba7e4   Hacene SI HADJ MOHAND   ok for time plot
36
37
			lMin = ceil(lMin+margin*(lMax-lMin));
			lMax = floor(lMax-margin*(lMax-lMin));
fbe3c2bb   Benjamin Renard   First commit
38
39
40
41
42
43
44
45
		}
	}

	Range lRange (lMin, lMax);
	lRange._extend = pRange._extend;
	return lRange;
}

faf4d845   Benjamin Renard   Add common functi...
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
void fixRange(Range &pRange, bool isLogScale) {
	if (isNAN(pRange.getMin()) && isNAN(pRange.getMax())) {
		if (isLogScale) {
			pRange.setMin(1.);
			pRange.setMax(10.);
		}
		else {
			pRange.setMin(0.);
			pRange.setMax(1.);
		}
	}
	else if (isNAN(pRange.getMin())) {
		if (isLogScale) {
			pRange.setMin(pRange.getMax() / 10.);
		}
		else {
			pRange.setMin(pRange.getMax() - 1.);
		}
	}
	else if (isNAN(pRange.getMax())) {
		if (isLogScale) {
			pRange.setMax(pRange.getMin() * 10.);
		}
		else {
			pRange.setMax(pRange.getMin() + 1.);
		}
	}
	else if (isApproximatelyEqual(pRange.getMin(),pRange.getMax())) {
65fadf3f   Benjamin Renard   Fix #8440
74
75
		pRange.setMin(floor(pRange.getMin()));
		pRange.setMax(floor(pRange.getMin())+1);
e062d6ef   Benjamin Renard   Fix axes range wh...
76
77
78
	}
}

fbe3c2bb   Benjamin Renard   First commit
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
double extend2UpperValue(double lValue) {
	// this give -0.0035 => 0.0035 => -2.4... => -3
	int lExp;
	if(lValue > 0) {
		lExp = floor(log10(lValue));
	} else {
		lExp = floor(log10(-1 * lValue));
	}
	// -0.0035 => -3.5
	double lTmpValue = lValue * pow(10, abs(lExp));
	// -3.5 => -3
	lTmpValue = ceil(lTmpValue);

	// -3 => -0.003
	lValue = lTmpValue * pow(10, lExp);

	return lValue;
}

double extend2LowerValue(double lValue) {
	// this give -0.0035 => 0.0035 => -2.4... => -3
	int lExp;
	if(lValue > 0) {
		lExp = floor(log10(lValue));
	} else {
		lExp = floor(log10(-1 * lValue));
	}
	// -0.0035 => -3.5
	double lTmpValue = lValue * pow(10, abs(lExp));
	// -3.5 => -4
	lTmpValue = floor(lTmpValue);

	// -4 => -0.004
	lValue = lTmpValue * pow(10, lExp);

	return lValue;
}

}