TimeAxis.hh 2.96 KB
/*
 * 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;
	out << axis._id << ".axis.visible=" << std::boolalpha << axis._visible << 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_ */