00001
00012
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016
00017 #include "ColumnPointRep.h"
00018 #include "ErrorBarRep.h"
00019
00020 #include "datasrcs/DataPointTuple.h"
00021 #include "datasrcs/DataSource.h"
00022 #include "graphics/ViewBase.h"
00023 #include "transforms/BinaryTransform.h"
00024
00025 #include <cmath>
00026
00027 #include <cassert>
00028
00029 using std::abs;
00030 using std::string;
00031 using std::vector;
00032
00033 using namespace hippodraw;
00034
00039 ColumnPointRep::ColumnPointRep ()
00040 : PointRepBase ( "Column", 1.0 ),
00041 m_y_flag ( false ),
00042 m_line_style( Line::Solid )
00043 {
00044 m_error_rep = new ErrorBarRep();
00045 }
00046
00047 ColumnPointRep::ColumnPointRep ( const ColumnPointRep & point_rep )
00048 : PointRepBase ( point_rep ),
00049 m_y_flag ( point_rep.m_y_flag ),
00050 m_line_style ( point_rep.m_line_style )
00051 {
00052 RepBase * clone = point_rep.m_error_rep->clone ();
00053 m_error_rep = dynamic_cast< ErrorBarRep *> ( clone );
00054 }
00055
00056 ColumnPointRep::~ColumnPointRep ()
00057 {
00058 delete m_error_rep;
00059 }
00060
00061 RepBase * ColumnPointRep::clone ()
00062 {
00063 return new ColumnPointRep ( *this );
00064 }
00065
00066
00067 void ColumnPointRep::setColor ( const Color & color )
00068 {
00069 RepBase::setColor ( color );
00070
00071 if ( m_error_rep ) {
00072 m_error_rep->setColor ( color );
00073 }
00074 }
00075
00076 void
00077 ColumnPointRep::
00078 setStyle ( unsigned int style )
00079 {
00080 m_line_style = Line::convert ( style );
00081 }
00082
00083 unsigned int
00084 ColumnPointRep::
00085 getStyle ( ) const
00086 {
00087 return m_line_style;
00088 }
00089
00090 void
00091 ColumnPointRep::
00092 setErrorOn ( const std::string & axis, bool flag )
00093 {
00094 if ( axis == "y" || axis == "Y" ) {
00095 m_error_rep->setYError ( flag );
00096 m_y_flag = flag;
00097 }
00098 }
00099
00100 bool ColumnPointRep::yError () const
00101 {
00102 return m_y_flag;
00103 }
00104
00105 namespace {
00106 inline double FLT_EQUAL( double x, double y )
00107 {
00108 return ( (double)abs( x - y ) <= 2.0 * ( y * FLT_EPSILON + FLT_MIN ) );
00109 }
00110 }
00111
00112 namespace dp = hippodraw::DataPoint2DTuple;
00113
00114 void
00115 ColumnPointRep::
00116 drawProjectedValues ( const DataSource * ntuple,
00117 TransformBase * transform,
00118 ViewBase * view )
00119 {
00120 m_x.clear();
00121 m_y.clear();
00122
00123 unsigned int size = ntuple -> rows ();
00124 unsigned int reserve = 2 * ( size + 1 );
00125
00126 m_x.reserve ( reserve );
00127 m_y.reserve ( reserve );
00128
00129 double last_x = 0.0;
00130
00131 for ( unsigned int i = 0; i < size; i ++ ) {
00132 const vector < double > & row = ntuple -> getRow ( i );
00133 double x = row [ dp::X ];
00134 double hw = row [ dp::XERR ];
00135 if ( i == 0 ) {
00136 m_x.push_back ( x - hw );
00137 m_y.push_back ( 0.0 );
00138
00139 m_x.push_back ( x -hw );
00140 }
00141 else {
00142 m_x.push_back ( last_x );
00143 }
00144 double y = row [ dp::Y ];
00145 m_y.push_back ( y );
00146 x += hw;
00147 m_x.push_back ( x );
00148 m_y.push_back ( y );
00149
00150 last_x = x;
00151 }
00152 m_x.push_back ( last_x );
00153
00154 const BinaryTransform * t
00155 = dynamic_cast < const BinaryTransform * > ( transform );
00156 assert ( t != 0 );
00157
00158 m_y.push_back ( 0.0 );
00159 assert ( m_x.size() == m_y.size() );
00160
00161 t -> transform ( m_x, m_y );
00162
00163 const HippoRectangle & user_rect = view -> getUserRect ();
00164 user_rect.makeInBounds ( m_x, m_y );
00165
00166 const Color & cur_color = color();
00167 view -> drawPolyLine ( m_x, m_y, m_line_style, cur_color, m_size );
00168
00169 if ( m_y_flag ) {
00170 m_error_rep -> drawProjectedValues ( ntuple, transform, view );
00171 }
00172 }