DataView.cxx
Go to the documentation of this file.
1 
12 // inconsistent dll linkage
13 #ifdef _MSC_VER
14 #include "msdevstudio/MSconfig.h"
15 #endif
16 
17 #include "DataView.h"
18 #include "graphics/FontBase.h"
19 
20 #include "axes/Range.h"
21 #include "plotters/PlotterBase.h"
22 
23 using namespace hippodraw;
24 
26  : ViewBase ()
27 {
28 }
29 
31 DataView ( PlotterBase * plotter )
32  // : ViewBase ( plotter )
33 {
34  // Initilize list does not work with virtual class?
35  m_plotter = plotter;
36 }
37 
40 {
41 }
42 
43 const Rect &
45 getMarginRect () const
46 {
47  return m_margin_rect;
48 }
49 
50 void
52 setMarginRect ( const Rect & rect )
53 {
54  m_margin_rect = rect;
55 }
56 
60 void
63 {
64  const Rect draw = getDrawRect();
65  float width = draw.getWidth();
66  float height = draw.getHeight();
67 
68  float marginXLeft = draw.getHeight () * 0.20;
69  marginXLeft = std::min ( marginXLeft, 55.0f );
70  float marginXRight = 20.0 ;
71 
72  // Get a pointer to the plotter.
73  PlotterBase* plotter = getPlotter();
74 
75  // Set and adjust top margin
76  float marginYTop = 30.0;
77  if ( m_plotter -> hasAxis ( Axes::Z) )
78  {
79  marginYTop = 70.0;
80  }
81  const FontBase* titlefont = plotter->titleFont();
82  if (titlefont) {
83  marginYTop = marginYTop+titlefont->pointSize()-9.0;
84  }
85  const FontBase* zfont = plotter->labelFont(Axes::Z);
86  if (zfont) {
87  marginYTop = marginYTop+zfont->pointSize()-7.0;
88  }
89 
90  // Set and adjust bottom margin
91  float marginYBottom = 34.0 ;
92  const FontBase* labelfont = plotter->labelFont(Axes::X);
93  if (labelfont) {
94  marginYBottom = marginYBottom+labelfont->pointSize()-11.0;
95  }
96 
97  // Add additional margins. Now it can be added by PNG title, labels.
98  marginYTop+=plotter->getTopMargin()+plotter->getZMargin();
99  marginYBottom+=plotter->getBottomMargin();
100  marginXLeft+=plotter->getLeftMargin();
101 
102  double aspect_ratio = m_plotter -> getAspectRatio ();
103 
104  float marginWidth = width - marginXLeft - marginXRight;
105  float marginHeight =height - marginYTop - marginYBottom;
106 
107  if ( aspect_ratio > 0.0 ) {
108  if ( marginWidth /aspect_ratio > marginHeight ){
109  marginWidth = aspect_ratio*marginHeight;
110  }
111  else {
112  marginHeight = marginWidth/aspect_ratio;
113  }
114  }
115 
116  m_margin_rect.setRect ( marginXLeft, marginYTop,
117  marginWidth, marginHeight );
118 }
119 
120 float
122 userToMarginX ( double x ) const
123 {
124  const Rect & user_rect = m_plotter -> getUserRect ();
125  double diff = x - user_rect.getX ();
126  double scale = m_margin_rect.getWidth() / user_rect.getWidth ();
127  double margin_x = m_margin_rect.getX () + diff * scale;
128  return margin_x;
129 }
130 
131 float
133 userToInvertedMarginX ( double x ) const
134 {
135  const Rect & user_rect = m_plotter -> getUserRect ();
136  double diff = x - user_rect.getX ();
137  double scale = m_margin_rect.getWidth() / user_rect.getWidth ();
138  double margin_ix = m_margin_rect.getX() + m_margin_rect.getWidth() - diff*scale;
139  return margin_ix;
140 }
141 
142 float
144 userToMarginY ( double y ) const
145 {
146  const Rect & user_rect = m_plotter -> getUserRect ();
147  return m_margin_rect.getY ()
148  + ( y - user_rect.getY () )
149  * m_margin_rect.getHeight () / user_rect.getHeight ();
150 }
151 
152 float
154 userToInvertedMarginY ( double y ) const
155 {
156  const Rect & user_rect = m_plotter -> getUserRect ();
157  return m_margin_rect.getY ()
159  - ( y - user_rect.getY () )
160  * m_margin_rect.getHeight () / user_rect.getHeight ();
161 }
162 
163 float
165 userToMarginColor ( double c ) const
166 {
167  const Rect & user_rect = m_plotter -> getUserRect ();
168 
169  return m_margin_rect.getX ()
170  + ( c - user_rect.getZ () )
171  * m_margin_rect.getWidth () / user_rect.getDepth ();
172 }
173 
174 double
176 marginToUserX ( double x ) const
177 {
178  const Rect & user_rect = m_plotter -> getUserRect ();
179 
180  return user_rect.getX ()
181  + ( x - m_margin_rect.getX() )
182  / ( m_margin_rect.getWidth () / user_rect.getWidth() );
183 }
184 
185 double
187 marginToInvertedUserX ( double x ) const
188 {
189  const Rect & user_rect = m_plotter -> getUserRect ();
190 
191  return user_rect.getX ()
192  + ( m_margin_rect.getX() + m_margin_rect.getWidth() - x )
193  / ( m_margin_rect.getWidth () / user_rect.getWidth() );
194 }
195 
196 double
198 marginToUserY ( double y ) const
199 {
200  const Rect & user_rect = m_plotter -> getUserRect ();
201 
202  return user_rect.getY ()
203  + ( y - m_margin_rect.getY() )
204  / ( m_margin_rect.getHeight () * user_rect.getHeight () );
205 }
206 
207 double
209 marginToInvertedUserY ( double y ) const
210 {
211  const Rect & user_rect = m_plotter -> getUserRect ();
212 
213  return user_rect.getY () +
214  ( m_margin_rect.getY()
215  + m_margin_rect.getHeight() - y )
216  / ( m_margin_rect.getHeight () / user_rect.getHeight () ) ;
217 }

Generated for HippoDraw Class Library by doxygen