DataView.cxx

Go to the documentation of this file.
00001 
00012 // inconsistent dll linkage
00013 #ifdef _MSC_VER
00014 #include "msdevstudio/MSconfig.h"
00015 #endif
00016 
00017 #include "DataView.h"
00018 #include "graphics/FontBase.h"
00019 
00020 #include "axes/Range.h"
00021 #include "plotters/PlotterBase.h"
00022 
00023 using namespace hippodraw;
00024 
00025 DataView::DataView( )
00026   : ViewBase ()
00027 {
00028 }
00029 
00030 DataView::
00031 DataView ( PlotterBase * plotter )
00032   // : ViewBase ( plotter )
00033 {
00034   // Initilize list does not work with virtual class?
00035   m_plotter = plotter;
00036 }
00037 
00038 DataView::
00039 ~DataView()
00040 {
00041 }
00042 
00043 const Rect &
00044 DataView::
00045 getMarginRect () const
00046 {
00047   return m_margin_rect;
00048 }
00049 
00050 void
00051 DataView::
00052 setMarginRect ( const Rect & rect )
00053 {
00054   m_margin_rect = rect;
00055 }
00056 
00060 void
00061 DataView::
00062 prepareMarginRect ( )
00063 {
00064   const Rect draw = getDrawRect();
00065   float width = draw.getWidth();
00066   float height = draw.getHeight();
00067 
00068   float marginXLeft = draw.getHeight () * 0.20;
00069   marginXLeft = std::min ( marginXLeft, 55.0f );
00070   float marginXRight = 20.0 ;
00071 
00072   // Get a pointer to the plotter.
00073   PlotterBase* plotter = getPlotter();
00074 
00075   // Set and adjust top margin
00076   float marginYTop = 30.0;
00077   if ( m_plotter -> hasAxis ( Axes::Z) )
00078     {
00079       marginYTop = 70.0;
00080     }
00081   const FontBase* titlefont = plotter->titleFont();
00082   if (titlefont) {
00083     marginYTop = marginYTop+titlefont->pointSize()-9.0;
00084   }
00085   const FontBase* zfont = plotter->labelFont(Axes::Z);
00086   if (zfont) {
00087     marginYTop = marginYTop+zfont->pointSize()-7.0;
00088   }
00089    
00090   // Set and adjust bottom margin
00091   float marginYBottom = 34.0 ;
00092   const FontBase* labelfont = plotter->labelFont(Axes::X);
00093   if (labelfont) {
00094     marginYBottom = marginYBottom+labelfont->pointSize()-11.0;
00095   }
00096 
00097   // Add additional margins. Now it can be added by PNG title, labels.
00098   marginYTop+=plotter->getTopMargin()+plotter->getZMargin();
00099   marginYBottom+=plotter->getBottomMargin();
00100   marginXLeft+=plotter->getLeftMargin();
00101 
00102   double aspect_ratio = m_plotter -> getAspectRatio ();
00103 
00104   float marginWidth = width - marginXLeft - marginXRight;
00105   float marginHeight =height - marginYTop - marginYBottom; 
00106 
00107   if ( aspect_ratio >  0.0 ) { 
00108     if ( marginWidth /aspect_ratio > marginHeight ){
00109       marginWidth = aspect_ratio*marginHeight;
00110     } 
00111     else {
00112       marginHeight = marginWidth/aspect_ratio;
00113     }
00114   }
00115   
00116   m_margin_rect.setRect ( marginXLeft, marginYTop,
00117                           marginWidth, marginHeight );
00118 }
00119 
00120 float
00121 DataView::
00122 userToMarginX ( double x ) const
00123 {
00124   const Rect & user_rect = m_plotter -> getUserRect ();
00125   double diff = x - user_rect.getX ();
00126   double scale = m_margin_rect.getWidth() / user_rect.getWidth ();
00127   double margin_x = m_margin_rect.getX () + diff * scale;
00128   return margin_x;
00129 }
00130 
00131 float
00132 DataView::
00133 userToInvertedMarginX ( double x ) const
00134 {
00135   const Rect & user_rect = m_plotter -> getUserRect ();
00136   double diff = x - user_rect.getX ();
00137   double scale = m_margin_rect.getWidth() / user_rect.getWidth ();
00138   double margin_ix = m_margin_rect.getX() + m_margin_rect.getWidth() - diff*scale;
00139   return margin_ix;
00140 }
00141 
00142 float
00143 DataView::
00144 userToMarginY ( double y ) const
00145 {
00146   const Rect & user_rect = m_plotter -> getUserRect ();
00147   return m_margin_rect.getY () 
00148     + ( y - user_rect.getY () )
00149     * m_margin_rect.getHeight () / user_rect.getHeight ();
00150 }
00151 
00152 float
00153 DataView::
00154 userToInvertedMarginY ( double y ) const
00155 {
00156   const Rect & user_rect = m_plotter -> getUserRect ();
00157   return m_margin_rect.getY () 
00158     + m_margin_rect.getHeight ()
00159     - ( y - user_rect.getY () )
00160     * m_margin_rect.getHeight () / user_rect.getHeight ();
00161 }
00162 
00163 float
00164 DataView::
00165 userToMarginColor ( double c ) const
00166 {
00167   const Rect & user_rect = m_plotter -> getUserRect ();
00168 
00169   return m_margin_rect.getX () 
00170     + ( c - user_rect.getZ () )
00171     * m_margin_rect.getWidth () / user_rect.getDepth ();
00172 }
00173 
00174 double 
00175 DataView::
00176 marginToUserX ( double x ) const
00177 {
00178   const Rect & user_rect = m_plotter -> getUserRect ();
00179 
00180   return user_rect.getX () 
00181     + ( x - m_margin_rect.getX() ) 
00182     / ( m_margin_rect.getWidth () / user_rect.getWidth() ); 
00183 }
00184 
00185 double 
00186 DataView::
00187 marginToInvertedUserX ( double x ) const
00188 {
00189   const Rect & user_rect = m_plotter -> getUserRect ();
00190 
00191   return user_rect.getX () 
00192     + ( m_margin_rect.getX() + m_margin_rect.getWidth() - x ) 
00193     / ( m_margin_rect.getWidth () / user_rect.getWidth() ); 
00194 }
00195 
00196 double
00197 DataView::
00198 marginToUserY ( double y ) const
00199 {
00200   const Rect & user_rect = m_plotter -> getUserRect ();
00201 
00202   return user_rect.getY () 
00203     + ( y - m_margin_rect.getY() ) 
00204     /  ( m_margin_rect.getHeight () * user_rect.getHeight () );
00205 }
00206 
00207 double
00208 DataView::
00209 marginToInvertedUserY ( double y ) const
00210 {
00211   const Rect & user_rect = m_plotter -> getUserRect ();
00212 
00213   return user_rect.getY () + 
00214     ( m_margin_rect.getY() 
00215       + m_margin_rect.getHeight() - y ) 
00216     / ( m_margin_rect.getHeight () / user_rect.getHeight () ) ;
00217 }

Generated for HippoDraw Class Library by doxygen