g4tools  5.4.0
Public Member Functions | Protected Attributes | List of all members
tools::data_axis Class Reference

Public Member Functions

 data_axis ()
 
virtual ~data_axis ()
 
 data_axis (const data_axis &a_from)
 
data_axisoperator= (const data_axis &a_from)
 
bool set_is_log (bool a_v)
 
bool set_min_value (float a_v)
 
bool set_max_value (float a_v)
 
bool is_log (bool a_v)
 
bool min_value (float a_v)
 
bool max_value (float a_v)
 
float min_value () const
 
float max_value () const
 
bool is_log () const
 
void adjust ()
 

Protected Attributes

float m_min_value
 
float m_max_value
 
bool m_is_log
 

Detailed Description

Definition at line 11 of file data_axis.

Constructor & Destructor Documentation

◆ data_axis() [1/2]

tools::data_axis::data_axis ( )
inline

Definition at line 13 of file data_axis.

13 :m_min_value(0),m_max_value(0),m_is_log(false){}

◆ ~data_axis()

virtual tools::data_axis::~data_axis ( )
inlinevirtual

Definition at line 14 of file data_axis.

14 {}

◆ data_axis() [2/2]

tools::data_axis::data_axis ( const data_axis a_from)
inline

Definition at line 16 of file data_axis.

17  :m_min_value(a_from.m_min_value)
18  ,m_max_value(a_from.m_max_value)
19  ,m_is_log(a_from.m_is_log)
20  {}

Member Function Documentation

◆ adjust()

void tools::data_axis::adjust ( )
inline

Definition at line 40 of file data_axis.

40  { //from hippodraw.
41  int _axis = 0;
42  float step;
43  float mylow, myhigh;
44  int N_NICE = 4;
45  static const float nice[/*N_NICE*/4] = { 1.0,2.0,2.5,5.0 };
46 
47  if (m_min_value > m_max_value) {
48  float low = m_min_value;
50  m_max_value = low;
51  } else if (m_min_value == m_max_value) {
52  float value = m_min_value;
53  m_min_value = value - 1;
54  m_max_value = value + 1;
55  return;
56  }
57 
58  //if (m_steps <= 0) { //if letting the if and m_steps as a field, twice this function do not give the same result.
59  _axis = 1;
60  unsigned int m_steps = 10;
61  //}
62 
63  // Round the "bin width" to a nice number.
64  // If this is being done for an axis (ie m_steps was 0 , then
65  // we don't have to go > *m_max_value.
66  //
67  float w = (m_max_value - m_min_value)/((float)m_steps);
68  float mag = ffloor(flog10(w));
69  int i = 0;
70  do {
71  step = nice[i] * fpow(10.0,mag);
72  mylow = ffloor(m_min_value/step) * step;
73  //myhigh = _axis==1 ? fceil(m_max_value/step) * step : mylow + step * m_steps;
74  myhigh = fceil(m_max_value/step) * step; //quiet Coverity.
75  i++;
76  if (i>=N_NICE) {i = 0;mag++;}
77  }
78  while ( ( (_axis==1) && (myhigh < m_max_value)) ||
79  ( (_axis==0) && (myhigh <= m_max_value)) );
80 
81  float range = myhigh - mylow;
82 
83  // we now have decided on a range. Try to move
84  // m_min_value/m_max_value a little
85  // to end up on a nice number.
86  //
87  // first check if either end is near 0.0
88  if ( !m_is_log && (m_min_value >= 0.0) &&
89  (( (_axis==1) && (range>=m_max_value) ) ||
90  ( (_axis==0) && (range>m_max_value) )) ) {
91  m_min_value = 0.0;
92  m_max_value = range;
93  return;
94  }
95 
96  if ( (( (_axis==1) && (m_max_value<=0.0) ) ||
97  ( (_axis==0) && (m_max_value<0.0) ))
98  && (-range<=m_min_value)) {
99  m_max_value = 0.0;
100  m_min_value = -range;
101  return;
102  }
103 
104  // try to round *m_min_value.
105  // correction
106  if( m_is_log && (m_min_value<=0.0)) m_min_value = 1.0;
107 
108  i = N_NICE-1;
109  mag = myhigh != 0.0 ? fceil(flog10(ffabs(myhigh))) : fceil(flog10(ffabs(mylow)));
110 
111  do {
112  step = nice[i] * fpow(10.0,mag);
113  mylow = ffloor(m_min_value/step) * step;
114  myhigh = mylow + range;
115  i--;
116  if (i<0) {
117  i = N_NICE-1;
118  mag--;
119  }
120  }
121  while (( m_is_log && (mylow <= 0.0) ) ||
122  ( (_axis==1) && (myhigh < m_max_value) ) ||
123  ( (_axis==0) && (myhigh <= m_max_value) ) );
124 
125  m_min_value = mylow;
126  m_max_value = myhigh;
127  }

◆ is_log() [1/2]

bool tools::data_axis::is_log ( ) const
inline

Definition at line 38 of file data_axis.

38 {return m_is_log;}

◆ is_log() [2/2]

bool tools::data_axis::is_log ( bool  a_v)
inline

Definition at line 32 of file data_axis.

32 {if(m_is_log==a_v) return false;m_is_log = a_v;return true;}

◆ max_value() [1/2]

float tools::data_axis::max_value ( ) const
inline

Definition at line 37 of file data_axis.

37 {return m_max_value;}

◆ max_value() [2/2]

bool tools::data_axis::max_value ( float  a_v)
inline

Definition at line 34 of file data_axis.

34 {if(m_max_value==a_v) return false;m_max_value = a_v;return true;}

◆ min_value() [1/2]

float tools::data_axis::min_value ( ) const
inline

Definition at line 36 of file data_axis.

36 {return m_min_value;}

◆ min_value() [2/2]

bool tools::data_axis::min_value ( float  a_v)
inline

Definition at line 33 of file data_axis.

33 {if(m_min_value==a_v) return false;m_min_value = a_v;return true;}

◆ operator=()

data_axis& tools::data_axis::operator= ( const data_axis a_from)
inline

Definition at line 21 of file data_axis.

21  {
22  m_min_value = a_from.m_min_value;
23  m_max_value = a_from.m_max_value;
24  m_is_log = a_from.m_is_log;
25  return *this;
26  }

◆ set_is_log()

bool tools::data_axis::set_is_log ( bool  a_v)
inline

Definition at line 28 of file data_axis.

28 {if(m_is_log==a_v) return false;m_is_log = a_v;return true;}

◆ set_max_value()

bool tools::data_axis::set_max_value ( float  a_v)
inline

Definition at line 30 of file data_axis.

30 {if(m_max_value==a_v) return false;m_max_value = a_v;return true;}

◆ set_min_value()

bool tools::data_axis::set_min_value ( float  a_v)
inline

Definition at line 29 of file data_axis.

29 {if(m_min_value==a_v) return false;m_min_value = a_v;return true;}

Member Data Documentation

◆ m_is_log

bool tools::data_axis::m_is_log
protected

Definition at line 132 of file data_axis.

◆ m_max_value

float tools::data_axis::m_max_value
protected

Definition at line 130 of file data_axis.

◆ m_min_value

float tools::data_axis::m_min_value
protected

Definition at line 129 of file data_axis.


The documentation for this class was generated from the following file:
tools::ffabs
float ffabs(const float &x)
Definition: mathf:58
tools::fceil
float fceil(const float &x)
Definition: mathf:55
tools::flog10
float flog10(const float &x)
Definition: mathf:53
tools::data_axis::m_is_log
bool m_is_log
Definition: data_axis:132
tools::data_axis::m_min_value
float m_min_value
Definition: data_axis:129
tools::ffloor
float ffloor(const float &x)
Definition: mathf:54
tools::fpow
float fpow(const float &x, const float &y)
Definition: mathf:50
tools::data_axis::m_max_value
float m_max_value
Definition: data_axis:130