/* * Tick.hh * * Created on: 20 nov. 2013 * Author: CS */ #ifndef TICK_HH_ #define TICK_HH_ #include #include #include 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 _tickAsNumber; std::pair _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_ */