Logo ROOT   6.14/05
Reference Guide
TPadUserAxis.hxx
Go to the documentation of this file.
1 /// \file ROOT/TPadUserAxis.hxx
2 /// \ingroup Gpad ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2017-07-15
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2018, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_TPadUserAxis
17 #define ROOT7_TPadUserAxis
18 
19 #include <ROOT/TPadLength.hxx>
20 
21 #include <algorithm>
22 #include <limits>
23 
24 namespace ROOT {
25 namespace Experimental {
26 
27 /** \class ROOT::Experimental::Internal::TPadUserAxisBase
28  Base class for user coordinates (e.g. for histograms) used by `TPad` and `TCanvas`.
29  */
30 
32 public:
33  /// Types of axis bounds to respect by the painter. Non-fixed ones will be updated by
34  /// the painter once the first paint has happened.
36  kAxisBoundsAuto, ///< no defined axis range; the painter will decide
37  kAxisBoundsBegin = 1, ///< the axis begin is to be respected by the painter.
38  kAxisBoundsEnd = 2, ///< the axis end is to be respected by the painter.
39  kAxisBoundsBeginEnd = kAxisBoundsBegin | kAxisBoundsEnd, ///< the axis minimum and maximum are to be respected by the painter
40  };
41 
42 private:
43  /// Axis bounds to be used by the painter.
45 
46  /// Begin of the axis range (but see fBoundsKind)
47  double fBegin = 0.;
48 
49  /// End of the axis range (but see fBoundsKind)
50  double fEnd = 1.;
51 
52 protected:
53  /// Allow derived classes to default construct a TPadUserAxisBase.
54  TPadUserAxisBase() = default;
55 
56  /// Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
57  TPadUserAxisBase(double begin, double end): fBoundsKind(kAxisBoundsBeginEnd), fBegin(begin), fEnd(end) {}
58 
59  /// Construct a cartesian axis with min or max, depending on the boundKind parameter.
60  TPadUserAxisBase(EAxisBoundsKind boundKind, double bound):
61  fBoundsKind(boundKind), fBegin(bound), fEnd(bound) {}
62 
63  /// Disable spliced copy construction.
64  TPadUserAxisBase(const TPadUserAxisBase &) = default;
65 
66  /// Disable spliced assignment.
67  TPadUserAxisBase &operator=(const TPadUserAxisBase &) = default;
68 
69  /// For (pos-min)/(max-min) calculations, return a sensible, div-by-0 protected denominator.
70  double GetSensibleDenominator() const
71  {
72  if (fBegin < fEnd)
73  return std::max(std::numeric_limits<double>::min(), fEnd - fBegin);
74  return std::min(-std::numeric_limits<double>::min(), fEnd - fBegin);
75  }
76 
77 public:
78  virtual ~TPadUserAxisBase();
79 
80  EAxisBoundsKind GetBoundsKind() const { return static_cast<EAxisBoundsKind>(fBoundsKind); }
81  bool RespectBegin() const { return fBoundsKind & kAxisBoundsBegin; }
82  bool RespectEnd() const { return fBoundsKind & kAxisBoundsEnd; }
83 
84  double GetBegin() const { return fBegin; }
85  double GetEnd() const { return fEnd; }
86 
87  void SetBounds(double begin, double end)
88  {
89  fBoundsKind = kAxisBoundsBeginEnd;
90  fBegin = begin;
91  fEnd = end;
92  }
93  void SetBound(EAxisBoundsKind boundKind, double bound) { fBoundsKind = boundKind; fBegin = fEnd = bound; }
94  void SetAutoBounds() { fBoundsKind = kAxisBoundsAuto; }
95 
96  void SetBegin(double begin) { fBoundsKind |= kAxisBoundsBegin; fBegin = begin; }
97  void SetEnd(double end) { fBoundsKind |= kAxisBoundsEnd; fEnd = end; }
98 
99  /// Convert user coordinates to normal coordinates.
100  virtual TPadLength::Normal ToNormal(const TPadLength::User &) const = 0;
101 };
102 
104 private:
105  /// Whether this axis should be painted as log scale.
106  bool fLogScale = false;
107 
108 public:
109  /// Construct a cartesian axis with automatic axis bounds.
110  TPadCartesianUserAxis() = default;
111 
112  /// Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
113  TPadCartesianUserAxis(double begin, double end): TPadUserAxisBase(begin, end) {}
114 
115  /// Construct a cartesian axis with min or max, depending on the boundKind parameter.
116  TPadCartesianUserAxis(EAxisBoundsKind boundKind, double bound):
117  TPadUserAxisBase(boundKind, bound) {}
118 
119  bool IsLogScale() const { return fLogScale; }
120  void SetLogScale(bool logScale = true) { fLogScale = logScale; }
121 
122  /// Convert user coordinates to normal coordinates.
123  TPadLength::Normal ToNormal(const TPadLength::User &usercoord) const override;
124 
125 };
126 } // namespace Experimental
127 } // namespace ROOT
128 
129 #endif
virtual TPadLength::Normal ToNormal(const TPadLength::User &) const =0
Convert user coordinates to normal coordinates.
A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the TPad...
Definition: TPadLength.hxx:75
the axis minimum and maximum are to be respected by the painter
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
TPadCartesianUserAxis(double begin, double end)
Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
no defined axis range; the painter will decide
the axis begin is to be respected by the painter.
double GetSensibleDenominator() const
For (pos-min)/(max-min) calculations, return a sensible, div-by-0 protected denominator.
void SetBound(EAxisBoundsKind boundKind, double bound)
the axis end is to be respected by the painter.
double fBegin
Begin of the axis range (but see fBoundsKind)
EAxisBoundsKind GetBoundsKind() const
A user coordinate, as defined by the EUserCoordSystem parameter of the TPad.
Definition: TPadLength.hxx:90
TPadCartesianUserAxis(EAxisBoundsKind boundKind, double bound)
Construct a cartesian axis with min or max, depending on the boundKind parameter. ...
TPadUserAxisBase(double begin, double end)
Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
double fEnd
End of the axis range (but see fBoundsKind)
void SetBounds(double begin, double end)
EAxisBoundsKind
Types of axis bounds to respect by the painter.
TPadUserAxisBase & operator=(const TPadUserAxisBase &)=default
Disable spliced assignment.
TPadUserAxisBase(EAxisBoundsKind boundKind, double bound)
Construct a cartesian axis with min or max, depending on the boundKind parameter. ...
TPadUserAxisBase()=default
Allow derived classes to default construct a TPadUserAxisBase.
int fBoundsKind
Axis bounds to be used by the painter.