ErrorBarRep.cxx
Go to the documentation of this file.
1 
12 #ifdef _MSC_VER
13 // include max() and min() missing from MicroSoft Visual C++
14 #include "msdevstudio/MSconfig.h"
15 #endif //_MSC_VER
16 
17 #include "ErrorBarRep.h"
18 
20 #include "datasrcs/DataSource.h"
21 #include "graphics/ViewBase.h"
23 
24 #include <cassert>
25 
26 using std::string;
27 using std::vector;
28 
29 using namespace hippodraw;
30 
32  : RepBase ( "ErrorBar", 0 ),
33  m_x_flag ( false ),
34  m_y_flag ( false )
35 {
36 }
37 
39 {
40 }
41 
43 {
44  return new ErrorBarRep( *this );
45 }
46 
47 void ErrorBarRep::setXError ( bool flag )
48 {
49  m_x_flag = flag;
50 }
51 
52 void ErrorBarRep::setYError ( bool flag )
53 {
54  m_y_flag = flag;
55 }
56 
57 void
59 drawXError ( double x, double y, double error,
60  const TransformBase & tb )
61 {
62  try {
63  const BinaryTransform & t
64  = dynamic_cast < const BinaryTransform & > ( tb );
65 
66  double bull;
67 
68  double thi = m_y_range.high();
69  double tlo = m_y_range.low();
70  t.transform( bull, thi );
71  t.transform( bull, tlo );
72 
73  Range new_range( tlo, thi );
74  m_y_range = new_range;
75 
76  double xhi = x + error;
77  double xlo = x - error;
78 
79  t.transform( x, y );
80  t.transform( xlo, bull );
81  t.transform( xhi, bull );
82 
83  // The line.
84  m_x_err.push_back ( xhi );
85  m_y_err.push_back ( y );
86  m_x_err.push_back ( xlo );
87  m_y_err.push_back ( y );
88 
89  }
90  catch ( ... ) {
91  assert ( false );
92  }
93 }
94 
95 void
97 drawYError ( double x, double y, double error,
98  const TransformBase & tb )
99 {
100  try {
101  const BinaryTransform & t
102  = dynamic_cast < const BinaryTransform & > ( tb );
103 
104  double bull = 0.0;
105 
106  double thi = m_x_range.high();
107  double tlo = m_x_range.low();
108  t.transform( thi, bull );
109  t.transform( tlo, bull );
110 
111  Range new_range( tlo, thi );
112  m_x_range = new_range;
113 
114  double yhi = y + error; //0.5 * error;
115  double ylo = y - error; //0.5 * error;
116 
117  t.transform( x, y );
118  t.transform( bull, ylo );
119  t.transform( bull, yhi );
120 
121  // The line.
122  m_x_err.push_back ( x );
123  m_y_err.push_back ( yhi );
124  m_x_err.push_back ( x );
125  m_y_err.push_back ( ylo );
126 
127  }
128  catch ( ... ) {
129  assert ( false );
130  }
131 }
132 namespace dp = hippodraw::DataPoint2DTuple;
133 
134 void
137  TransformBase * transform,
138  ViewBase * view )
139 {
140  if ( m_x_flag == false &&
141  m_y_flag == false ) return;
142 
143  unsigned int size = ntuple -> rows ();
144  if ( size == 0 ) return;
145 
146  m_x_err.clear ();
147  m_y_err.clear ();
148 
149  unsigned int new_size = 0;
150  if ( m_x_flag ) {
151  new_size += 6 * size;
152  }
153  if ( m_y_flag ) {
154  new_size += 6 * size;
155  }
156 
157  m_x_err.reserve ( new_size );
158  m_y_err.reserve ( new_size );
159 
160  getRanges ( view );
161 
162  for ( unsigned int i = 0; i < size; i++ ) {
163  const vector < double > & row = ntuple -> getRow ( i );
164  double x = row [ dp::X ];
165  double y = row [ dp::Y ];
166 
167  if ( m_x_flag == true ) {
168  double err = row [ dp::XERR ];
169  drawXError ( x, y, err, *transform );
170  }
171 
172  if ( m_y_flag == true ) {
173  double err = row [ dp::YERR ];
174  drawYError ( x, y, err, *transform );
175  }
176  }
177 
178  const Rect & user_rect = view -> getUserRect ();
179  user_rect.makeInBounds ( m_x_err, m_y_err );
180  const Color & cur_color = color ();
181 
182  view -> drawLines ( m_x_err, m_y_err, Line::Solid, cur_color, m_size );
183 }
184 
185 void
187 getRanges ( const ViewBase * view )
188 {
189  m_x_range = view -> getRange ( Axes::X );
190  m_y_range = view -> getRange ( Axes::Y );
191 }
void getRanges(const ViewBase *view)
Gets the ranges of the plotter on X and Y axis.
unsigned int i
virtual void drawProjectedValues(const DataSource *ntuple, TransformBase *transform, ViewBase *view)
Draws the projected values.
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
void makeInBounds(double &x, double &y) const
Changes the coordinates so that they are inside or on the boundary of the rectangle.
Definition: Rectangle.cxx:185
hippodraw::ErrorBarRep class interface
A transform that transforms coordinates from one coordinate system to another.
Definition: TransformBase.h:35
virtual void transform(double &x, double &y) const =0
Transform the coordinates on the X and Y axes.
ErrorBarRep()
The default constructor.
Definition: ErrorBarRep.cxx:31
void setYError(bool)
Sets the flag to plot the errors on the Y axis.
Definition: ErrorBarRep.cxx:52
std::vector< double > m_y_err
A cache of the Y errors.
Definition: ErrorBarRep.h:37
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
void drawXError(double x, double y, double error, const TransformBase &t)
Creates the line segment for the X error bar.
Definition: ErrorBarRep.cxx:59
bool m_x_flag
The X error flag.
Definition: ErrorBarRep.h:41
hippodraw::DataSource class interface.
~ErrorBarRep()
The destructor.
Definition: ErrorBarRep.cxx:38
error on X or half bin width
hippodraw::BinaryTransform class interface
virtual const Color & color() const
Returns the representation&#39;s color.
Definition: RepBase.cxx:63
bool m_y_flag
The Y error flag.
Definition: ErrorBarRep.h:45
void drawYError(double x, double y, double error, const TransformBase &t)
Creates the line segment for the Y error bar.
Definition: ErrorBarRep.cxx:97
Class representing a rectangle.
Definition: Rectangle.h:34
Range m_y_range
The Y axis range for cap calculation.
Definition: ErrorBarRep.h:51
float m_size
The size of the representation.
Definition: RepBase.h:63
The abstract base class for views.
Definition: ViewBase.h:62
void setXError(bool)
Sets the flag to plot the errors on the X axis.
Definition: ErrorBarRep.cxx:47
RepBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
Definition: ErrorBarRep.cxx:42
Range m_x_range
The X axis range for cap calculation.
Definition: ErrorBarRep.h:48
A transform that transforms coordinates from one 2D coordinate system to another. ...
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
Expresses a range of values.
Definition: Range.h:33
hippodraw::DataPointTuple namespace interface
std::vector< double > m_x_err
A cache of the X errors.
Definition: ErrorBarRep.h:34
hippodraw::ViewBase class interface
float size() const
Returns the size of the representation.
Definition: RepBase.cxx:91
The base class for the point representation hierarchy.
Definition: RepBase.h:45
Base class for DataSource.
Definition: DataSource.h:55

Generated for HippoDraw Class Library by doxygen