Logo ROOT   6.18/05
Reference Guide
RPadUserAxis.hxx
Go to the documentation of this file.
1/// \file ROOT/RPadUserAxis.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_RPadUserAxis
17#define ROOT7_RPadUserAxis
18
19#include <ROOT/RPadLength.hxx>
20
21#include <algorithm>
22#include <limits>
23
24namespace ROOT {
25namespace Experimental {
26
27/** \class ROOT::Experimental::Internal::RPadUserAxisBase
28 Base class for user coordinates (e.g. for histograms) used by `RPad` and `RCanvas`.
29 */
30
32public:
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
42private:
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
52protected:
53 /// Allow derived classes to default construct a RPadUserAxisBase.
54 RPadUserAxisBase() = default;
55
56 /// Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
57 RPadUserAxisBase(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 RPadUserAxisBase(EAxisBoundsKind boundKind, double bound):
61 fBoundsKind(boundKind), fBegin(bound), fEnd(bound) {}
62
63 /// Disable spliced copy construction.
65
66 /// Disable spliced assignment.
68
69 /// For (pos-min)/(max-min) calculations, return a sensible, div-by-0 protected denominator.
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
77public:
78 virtual ~RPadUserAxisBase();
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 {
90 fBegin = begin;
91 fEnd = end;
92 }
93 void SetBound(EAxisBoundsKind boundKind, double bound) { fBoundsKind = boundKind; fBegin = fEnd = bound; }
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 RPadLength::Normal ToNormal(const RPadLength::User &) const = 0;
101};
102
104private:
105 /// Whether this axis should be painted as log scale.
106 bool fLogScale = false;
107
108public:
109 /// Construct a cartesian axis with automatic axis bounds.
111
112 /// Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
113 RPadCartesianUserAxis(double begin, double end): RPadUserAxisBase(begin, end) {}
114
115 /// Construct a cartesian axis with min or max, depending on the boundKind parameter.
116 RPadCartesianUserAxis(EAxisBoundsKind boundKind, double bound):
117 RPadUserAxisBase(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 RPadLength::Normal ToNormal(const RPadLength::User &usercoord) const override;
124
125};
126} // namespace Experimental
127} // namespace ROOT
128
129#endif
RPadLength::Normal ToNormal(const RPadLength::User &usercoord) const override
Convert user coordinates to normal coordinates.
RPadCartesianUserAxis(double begin, double end)
Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
RPadCartesianUserAxis()=default
Construct a cartesian axis with automatic axis bounds.
bool fLogScale
Whether this axis should be painted as log scale.
RPadCartesianUserAxis(EAxisBoundsKind boundKind, double bound)
Construct a cartesian axis with min or max, depending on the boundKind parameter.
RPadUserAxisBase(EAxisBoundsKind boundKind, double bound)
Construct a cartesian axis with min or max, depending on the boundKind parameter.
void SetBounds(double begin, double end)
void SetBound(EAxisBoundsKind boundKind, double bound)
int fBoundsKind
Axis bounds to be used by the painter.
double fEnd
End of the axis range (but see fBoundsKind)
RPadUserAxisBase()=default
Allow derived classes to default construct a RPadUserAxisBase.
double fBegin
Begin of the axis range (but see fBoundsKind)
double GetSensibleDenominator() const
For (pos-min)/(max-min) calculations, return a sensible, div-by-0 protected denominator.
EAxisBoundsKind
Types of axis bounds to respect by the painter.
@ kAxisBoundsAuto
no defined axis range; the painter will decide
@ kAxisBoundsEnd
the axis end is to be respected by the painter.
@ kAxisBoundsBeginEnd
the axis minimum and maximum are to be respected by the painter
@ kAxisBoundsBegin
the axis begin is to be respected by the painter.
RPadUserAxisBase(double begin, double end)
Construct a cartesian axis from min and max, setting fBoundsKind to kAxisBoundsMinMax.
RPadUserAxisBase & operator=(const RPadUserAxisBase &)=default
Disable spliced assignment.
EAxisBoundsKind GetBoundsKind() const
virtual RPadLength::Normal ToNormal(const RPadLength::User &) const =0
Convert user coordinates to normal coordinates.
RPadUserAxisBase(const RPadUserAxisBase &)=default
Disable spliced copy construction.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
A normalized coordinate: 0 in the left, bottom corner, 1 in the top, right corner of the RPad.
Definition: RPadLength.hxx:77
A user coordinate, as defined by the EUserCoordSystem parameter of the RPad.
Definition: RPadLength.hxx:92