Blame view

src/ParamOutputImpl/Plot/Tick.hh 3.82 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Tick.hh
 *
 *  Created on: 20 nov. 2013
 *      Author: CS
 */

#ifndef TICK_HH_
#define TICK_HH_

#include <utility>
#include <limits>
#include <string> 

namespace plot {

/**
 * @brief Tick Class defining the number of major and minor tick to use to plot axis graduation.
 */
class Tick {
public:
	enum TickPosition {
		INWARDS, OUTWARDS
	};

	/**
	 * @brief Tick Create default instance of Tick where major and minor ticks are set to the maximum value.
	 */
	Tick() :
			_position(TickPosition::OUTWARDS), _lengthFactor(nan("")), _isMinorGridVisible(
					false), _isMajorGridVisible(false), _tickAsNumber(-1, -1), _tickAsSpace(
					nan(""), nan("")) {

	}

	virtual ~Tick() {
	}

	int getMajorNumber() const {
		return _tickAsNumber.first;
	}
	int getMinorNumber() const {
		return _tickAsNumber.second;
	}

	void setMajorNumber(int number) {
		_tickAsNumber.first = number;
	}
	void setMinorNumber(int number) {
		_tickAsNumber.second = number;
	}

	double getMajorSpace() const {
		return _tickAsSpace.first;
	}
	double getMinorSpace() const {
		return _tickAsSpace.second;
	}

	void setMajorSpace(double number) {
		_tickAsSpace.first = number;
	}
	void setMinorSpace(double number) {
		_tickAsSpace.second = number;
	}

	bool isSet() {
		return (_tickAsNumber.first != -1 || !std::isnan(_tickAsSpace.first))
				&& (_tickAsNumber.second != -1
						|| !std::isnan(_tickAsSpace.second));
	}

	bool isMinorSet() {
		return (_tickAsNumber.second != -1 || !std::isnan(_tickAsSpace.second));
	}

	bool isMajorSet() {
		return (_tickAsNumber.first != -1 || !std::isnan(_tickAsSpace.first));
	}

	static TickPosition getTickPosition(std::string value) {
		if (value == "outwards") {
			return Tick::TickPosition::OUTWARDS;
		}
		return Tick::TickPosition::INWARDS;
	}

	// ********************** PUBLIC ATTRIBUTES ************************ //

	/**
	 * Position on axe line : Up or down
	 */
	TickPosition _position;

	/**
	 * Tick length
	 */
	double _lengthFactor;

	/**
	 * Flag to display or not grid on minor ticks
	 */
	bool _isMinorGridVisible;

	/**
	 * Flag to display or not grid on major ticks
	 */
	bool _isMajorGridVisible;

	/**
	 * For TU
	 */
	void dump(std::ostream& out, std::string& prefix) {
		out << prefix << "tick.major.number=" << getMajorNumber() << std::endl;
		out << prefix << "tick.minor.number=" << getMinorNumber() << std::endl;
		out << prefix << "tick.major.space=" << getMajorSpace() << std::endl;
		out << prefix << "tick.minor.space=" << getMinorSpace() << std::endl;
		out << prefix << "tick.minor.gridVisible=" << std::boolalpha
				<< _isMinorGridVisible << std::endl;
		out << prefix << "tick.major.gridVisible=" << std::boolalpha
				<< _isMajorGridVisible << std::endl;
		out << prefix << "tick.position=";
		switch (_position) {
		case Tick::TickPosition::OUTWARDS:
			out << "outwards";
			break;
		case Tick::TickPosition::INWARDS:
		default:
			out << "inwards";
		}
		out << std::endl;
		out << prefix << "tick.lengthFactor=" << _lengthFactor << std::endl;
	}

private:
	std::pair<int, int> _tickAsNumber;
	std::pair<double, double> _tickAsSpace;

};

inline std::ostream& operator <<(std::ostream& out, Tick& tick) {
	out << "[TICK]" << std::endl;
	out << "tick.major.number=" << tick.getMajorNumber() << std::endl;
	out << "tick.minor.number=" << tick.getMinorNumber() << std::endl;
	out << "tick.major.space=" << tick.getMajorSpace() << std::endl;
	out << "tick.minor.space=" << tick.getMinorSpace() << std::endl;
	out << "tick.position=" << tick._position << std::endl;
	out << "tick.lengthFactor=" << tick._lengthFactor << std::endl;
	return out;
}

inline std::ostream& operator <<(std::ostream& out,
		Tick::TickPosition& position) {
	switch (position) {
	case Tick::TickPosition::OUTWARDS:
		out << "outwards";
		break;
	case Tick::TickPosition::INWARDS:
	default:
		out << "inwards";
	}
	return out;
}

} /* namespace plot */
#endif /* RANGE_HH_ */