ColumnPointRep.cxx
Go to the documentation of this file.
1 
12 // For truncation warning
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "ColumnPointRep.h"
18 #include "ErrorBarRep.h"
19 
21 #include "datasrcs/DataSource.h"
22 #include "graphics/ViewBase.h"
24 
25 #include <cmath>
26 
27 #include <cassert>
28 
29 using std::abs;
30 using std::string;
31 using std::vector;
32 
33 using namespace hippodraw;
34 
40  : PointRepBase ( "Column", 1.0 ),
41  m_line_style( Line::Solid ),
42  m_y_flag ( false )
43 {
44  m_error_rep = new ErrorBarRep();
45 }
46 
48  : PointRepBase ( point_rep ),
49  m_line_style ( point_rep.m_line_style ),
50  m_y_flag ( point_rep.m_y_flag )
51 {
52  RepBase * clone = point_rep.m_error_rep->clone ();
53  m_error_rep = dynamic_cast< ErrorBarRep *> ( clone );
54 }
55 
57 {
58  delete m_error_rep;
59 }
60 
62 {
63  return new ColumnPointRep ( *this );
64 }
65 
66 void ColumnPointRep::setColor ( const Color & color )
67 {
68  RepBase::setColor ( color );
69 
70  if ( m_error_rep ) {
71  m_error_rep->setColor ( color );
72  }
73 }
74 
75 void
77 setStyle ( unsigned int style )
78 {
79  m_line_style = Line::convert ( style );
80 }
81 
82 unsigned int
84 getStyle ( ) const
85 {
86  return m_line_style;
87 }
88 
89 void
91 setErrorOn ( Axes::Type axis, bool flag )
92 {
93  if ( axis == Axes::Y ) {
94  m_error_rep->setYError ( flag );
95  m_y_flag = flag;
96  }
97 }
98 
100 {
101  return m_y_flag;
102 }
103 
104 void
106 drawValues ( ViewBase * view ) const
107 {
108  const Color & cur_color = color();
109  view -> drawPolyLine ( m_x, m_y, m_line_style, cur_color, m_size );
110 }
111 
112 namespace dp = hippodraw::DataPoint2DTuple;
113 
116 void
119  TransformBase * transform,
120  ViewBase * view )
121 {
122  m_x.clear();
123  m_y.clear();
124 
125  unsigned int size = ntuple -> rows ();
126  unsigned int reserve = 2 * ( size + 1 );
127 
128  m_x.reserve ( reserve );
129  m_y.reserve ( reserve );
130 
131  double last_x = 0.0;
132 
133  const Rect & user_rect = view -> getUserRect ();
134 
135  for ( unsigned int i = 0; i < size; i ++ ) {
136  const vector < double > & row = ntuple -> getRow ( i );
137  double x = row [ dp::X ];
138  double hw = row [ dp::XERR ];
139  if ( i == 0 ) {
140  m_x.push_back ( x - hw );
141  m_y.push_back ( 0.0 ); // The first y is always zero.
142 
143  m_x.push_back ( x -hw );
144  }
145  else {
146  m_x.push_back ( last_x );
147  }
148  double y = row [ dp::Y ];
149  m_y.push_back ( y ); // X was already set.
150  x += hw;
151  m_x.push_back ( x );
152  m_y.push_back ( y );
153 
154  last_x = x;
155  }
156  m_x.push_back ( last_x );
157 
158  const BinaryTransform * t
159  = dynamic_cast < const BinaryTransform * > ( transform );
160  assert ( t != 0 );
161 
162  m_y.push_back ( 0.0 ); // The last y is always zero.
163  assert ( m_x.size() == m_y.size() );
164 
165  t -> transform ( m_x, m_y );
166 
167  user_rect.makeInBounds ( m_x, m_y );
168 
169  drawValues ( view );
170 
171  if ( m_y_flag ) {
172  m_error_rep -> drawProjectedValues ( ntuple, transform, view );
173  }
174 }
175 
176 bool
178 uses ( Line::Style ) const
179 {
180  return true;
181 }
182 
183 void
185 setSize ( float value )
186 {
187  RepBase::setSize ( value );
188 
189  m_error_rep -> setSize ( value );
190 }
The abstract base class for views.
Definition: ViewBase.h:62
std::vector< double > m_y
A cache of the points to be drawn along the Y axis.
Style
Line style constants.
Definition: LineStyle.h:25
A PointRep class that draws a column to represent the value.
hippodraw::ColumnPointRep class interface
virtual void drawValues(ViewBase *view) const
Does the drawing based on the accumulated polyline.
virtual RepBase * clone()
The clone function returns an object of its own kind which is a copy of this object at this moment...
void setYError(bool)
Sets the flag to plot the errors on the Y axis.
Definition: ErrorBarRep.cxx:52
hippodraw::DataPointTuple namespace interface
~ColumnPointRep()
The destructor.
The base class for the point representation hierarchy.
Definition: PointRepBase.h:37
Base class for DataSource.
Definition: DataSource.h:55
A rep to draw error bars, owned by point reps.
Definition: ErrorBarRep.h:28
hippodraw::ViewBase class interface
virtual void setSize(float value)
Sets the size of the line drawing and that of the error bar.
virtual bool yError() const
Returns true if the point representation displays error on the Y axis.
The base class for the point representation hierarchy.
Definition: RepBase.h:45
hippodraw::BinaryTransform class interface
virtual void setStyle(unsigned int style)
Sets the style of the line drawing.
virtual const Color & color() const
Returns the representation's color.
Definition: RepBase.cxx:63
bool m_y_flag
The Y error flag.
virtual void setErrorOn(hippodraw::Axes::Type axis, bool yes=true)
Sets the error display on or off.
hippodraw::ErrorBarRep class interface
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
virtual void drawProjectedValues(const DataSource *ntuple, TransformBase *transform, ViewBase *view)
ColumnPointRep()
The default constructor.
A transform that transforms coordinates from one 2D coordinate system to another. ...
float m_size
The size of the representation.
Definition: RepBase.h:63
virtual unsigned int getStyle() const
Returns the style of the line drawing.
hippodraw::Line::Style m_line_style
The style currently used.
virtual void setColor(const Color &color)
Sets the Color.
float size() const
Returns the size of the representation.
Definition: RepBase.cxx:91
virtual bool uses(hippodraw::Line::Style) const
Returns true as this class uses hippodraw::Line::Style.
std::vector< double > m_x
A cache of the points to be drawn along the X axis.
Style convert(unsigned int style)
Definition: LineStyle.cxx:29
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
virtual void setSize(float value)
Sets the size of the representation.
Definition: RepBase.cxx:96
hippodraw::DataSource class interface.
Class representing a rectangle.
Definition: Rectangle.h:34
error on X or half bin width
virtual void setColor(const Color &)
Sets the color of the representation.
Definition: RepBase.cxx:53
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
Type
Axes constants.
Definition: AxesType.h:31
A transform that transforms coordinates from one coordinate system to another.
Definition: TransformBase.h:35
ErrorBarRep * m_error_rep
The error bar representation.
Definition: PointRepBase.h:44

Generated for HippoDraw Class Library by doxygen