TickMarkDecorator.hh 3.96 KB
/*
 * TickMarkDecorator.hh
 *
 *  Created on: Dec 18, 2013
 *      Author: amdadev
 */

#ifndef TICKMARKDECORATOR_HH_
#define TICKMARKDECORATOR_HH_

#include <boost/smart_ptr/shared_ptr.hpp>
#include <iosfwd>

#include "plplot/plplot.h"
#include <map>

#include "plplot/plstream.h"


#include "TimeAxisDecorator.hh"

using std::map;

namespace plot {

typedef std::map<double,double> SeriesData;

struct SeriesInfo{
	/**
	 * @brief name of that series (i.e. name of parameter and index if not a scalar parameter).
	 */
	std::string _name;
	/**
	 * @brief maximum len for name.
	 */
	unsigned int _maxLen;
	/**
	 * @brief format string used to format series values.
	 */
	std::string _valuesFormat;
	/**
	 * @brief maximum len for value. May be useful to justify formatted output.
	 */
	unsigned int _maxValueLen;
	/**
	 * @brief min time index. (used display _name instead of a value).
	 */
	double _min;
	/**
	 * @brief values for that series. Holds for each "time" at a tick ,
	 *  the related series value.
	 */
	SeriesData _data;
};

typedef std::vector<boost::shared_ptr<SeriesInfo>> SeriesList;

struct TimeInfo{

	/**
	 * @brief time format in label
	 */
	std::string _timeFormat;

	/**
	 * @brief time axis title.
	 */
	std::string _timeTitle;
	/**
	 * @brief maximum length for name.
	 */
	unsigned int _maxLen;
	/**
	 * @brief minimum time index. (used display _timeTitle instead of a value).
	 */
	double _min;
};
typedef boost::shared_ptr<TimeInfo> TimeInfoPtr;

/**
 * @brief decorator used when tickmarks label are needed for a time graph.
 */
class TickMarkDecorator: public TimeAxisDecorator {
public:
	TickMarkDecorator(bool isStandalone, PanelPlotOutput* decoratorPlot);

	TickMarkDecorator(const TickMarkDecorator& ref_ );

	TickMarkDecorator& operator=(const TickMarkDecorator& ref_);

	virtual ~TickMarkDecorator();

	void setValuesFormat( const std::string &format_){
		_valuesFormat = format_;
	}
	const std::string& getValuesFormat() const{
		return _valuesFormat;
	}

	/**
	 * Overrides XAxisDecorator::updatePlotArea
	 */
	void updatePlotArea(PanelPlotOutput* pplot_, Axis* axis_, Bounds& bounds_);

	/**
	 * Overrides XAxisDecorator::configure
	 */
	void configure(PanelPlotOutput* pplot_, Axis* axis_, double start_, double stop_,
			std::map<std::string, ParameterData> *pParameterValues);

	/**
	 * Overrides XAxisDecorator::draw
	 * @brief Draws tickmark on given time axis
	 */
	void draw(PanelPlotOutput* pplot_, Axis* axis_, std::shared_ptr<plstream> pls_);

protected:
	/**
	 * Overrides TimeAxisDecorator::installLabelGenerator.
	 */
	void installLabelGenerator(PanelPlotOutput* pplot_, TimeAxis* axis_);

private:

	/**
	 * @brief Calculates tick values (closest value from the tick time)
	 */
	unsigned int fillSeriesData(SeriesData& seriesdata_, TimeAxis* pAxis_, ParameterData& paramdata_, AMDA::Common::ParameterIndexComponent indexSerie_);

	/**
	 * @brief Calculates plot area for date display
	 */
	double computeStartDateWidth(PanelPlotOutput* pplot_, TimeAxis* pAxis_);

	/**
	 * @brief A logger for tick plot decorator
	 */
	static log4cxx::LoggerPtr _logger;
	
	/**
	 * @brief Some time properties that are used by time label generator
	 */
	TimeInfoPtr _pTimeInfo;
	
	/**
	 * @brief Series info that are used by Y label generators
	 */
	SeriesList _seriesInfoList;
	
	/**
	 * @brief A format for value display (see sprintf format)
	 */
	std::string _valuesFormat;
	
	/**
	 * @brief maximum length for formatted value.
	 */
	unsigned int _maxValueLen;

	/**
	 * @brief Single or multi plot
	 */
	bool _isStandalone;

	/**
	 * @brief Plot that owns parameter values.
	 */
	PanelPlotOutput* _decoratorPlot;

};

/**
 * @brief Custom generator for time label, just not display min time.
 */
void generateOrbitTimeLabel(PLINT axis, PLFLT value, char *label, PLINT length,
		PLPointer data);
/**
 * @brief Custom generator for a tick serie (one per serie).
 */
void generateYLabel(PLINT axis, PLFLT value, char *label, PLINT length,
		PLPointer data);
} /* namespace plot */

#endif /* TICKMARKDECORATOR_HH_ */