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 }

Generated for HippoDraw Class Library by doxygen