DigitalAxis.hh 1.95 KB
/*
 * DigitalAxis.hh
 *
 *  Created on: 22 nov. 2013
 *      Author: CS
 */

#ifndef DIGITALAXIS_HH_
#define DIGITALAXIS_HH_

#include <cmath>
#include <ctgmath>
#include "Axis.hh"

namespace plot {

int computeScientificFormatPrecision(double min, double max);
void getDigitalLabel(double value, int precision, char* label, int length, double min, double max);
void generateDigitalLabel(PLINT axis, PLFLT value, char *label, PLINT length, PLPointer data);
void generateNoDigitalLabel(PLINT axis, PLFLT value, char *label, PLINT length,	PLPointer data);

class DigitalAxis: public plot::Axis {

public:
	static const int MAX_DIGIT_NUMBER;
	static const int STANDARD_FORMAT_PRECISION;
	/**
	 * Constant used to reinterpret log10(0).
	 */
	static const int LOG_CONSTANT;

	enum Format {
		STANDARD, SCIENTIFIC
	};

	DigitalAxis() :
			Axis(), _scientific_format_precision(1) {
		if (_showTickMark == true)
			_labelGenerator->_function = generateDigitalLabel;
		else
			_labelGenerator->_function = generateNoDigitalLabel;
                _labelGenerator->_data = this;
	}

	DigitalAxis(const DigitalAxis& axis) :
			Axis(axis), _scientific_format_precision(axis._scientific_format_precision) {
		if (_showTickMark == true)
			_labelGenerator->_function = generateDigitalLabel;
		else
			_labelGenerator->_function = generateNoDigitalLabel;
                _labelGenerator->_data = this;
	}

	virtual ~DigitalAxis() {
	}

	void dump(std::ostream& out) {
		Axis::dump(out);
		out << std::endl;
	}

	virtual std::string getPlotOpt();

	virtual Range getRange();

	virtual Format getFormat();

	virtual std::pair<int, int> getTickMarkSize();

	/**
	 * @overrides Axis::getComputedValues
	 */
	virtual double* getComputedValues(double* values_, int size_, double min, double max);
        
        int getScientificFormatPrecision() {
            return _scientific_format_precision;
        }

private:
        int _scientific_format_precision;
};

} /* namespace plot */

#endif /* DIGITALAXIS_HH_ */