TickMarkDecorator.hh 3.46 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 {

struct TickParamIndexInfo{
	/**
	 * @brief format string used to format series values.
	 */
	std::string _valuesFormat;

	/**
	 * @brief link to the parameter data
	 */
	ParameterData* _parameterData;

	/**
	 * @brief serie component
	 */
	AMDA::Common::ParameterIndexComponent _index;
};

struct TickParamInfo{
	/**
	 * @brief param id
	 */
	std::string _paramId;

	/**
	 * @brief vector of index info
	 */
	std::vector<TickParamIndexInfo> _indexesInfo;
};

typedef std::vector<TickParamInfo> TickParamInfoList;

struct TimeInfo{

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

	/**
	 * @brief time axis title.
	 */
	std::string _timeTitle;

	TimeAxis* _pAxis;
};
typedef boost::shared_ptr<TimeInfo> TimeInfoPtr;

/**
 * @brief decorator used when tickmarks label are needed for a time graph.
 */
class TickMarkDecorator: public TimeAxisDecorator {
public:
	TickMarkDecorator(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_, const Bounds& panelBounds_, 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_);

	/**
	 * @brief Get tick mark label
	 */
	std::string getTickParamLabel(const std::string& paramId, const AMDA::Common::ParameterIndexComponent& index);

	/**
	 * @brief Get tick mark description
	 */
	std::string getTickParamDescription(const std::string& paramId, bool isScalar);

private:

	/**
	 * @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 List of tick info
	 */
	TickParamInfoList _tickInfoList;
	
	/**
	 * @brief A format for value display (see sprintf format)
	 */
	std::string _valuesFormat;
	
	/**
	 * @brief Plot that owns parameter values.
	 */
	PanelPlotOutput* _decoratorPlot;

};

/**
 * @brief Custom generator for tick time label
 */
void generateTickTimeLabel(PLINT axis, PLFLT value, char *label, PLINT length,
		PLPointer data);
/**
 * @brief Custom generator for a tick serie (one per serie).
 */
void generateTickSerieLabel(PLINT axis, PLFLT value, char *label, PLINT length,
		PLPointer data);
} /* namespace plot */

#endif /* TICKMARKDECORATOR_HH_ */