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 }
virtual float userToMarginColor(double c) const
Converts the user Z coordinate into the margin color (X) coordinate.
Definition: DataView.cxx:165
virtual double getTopMargin()
double getHeight() const
A shortcut to get size.height.
Definition: Rectangle.cxx:113
virtual ~DataView()
The virtual destructor.
Definition: DataView.cxx:39
virtual FontBase * labelFont(Axes::Type axes) const
What font is being used to override the default while drawing axis label.
void prepareMarginRect()
Prepares the margin rectangle.
Definition: DataView.cxx:62
virtual double getAspectRatio() const
Get the aspect ratio.
Definition: ViewBase.cxx:88
virtual float userToMarginX(double x) const
Converts the user X coordinate into the margin X coordinate.
Definition: DataView.cxx:122
virtual Rect getDrawRect() const =0
Returns the drawing Rectangle in the devices coordinate system.
double getWidth() const
A shortcut to get size.width.
Definition: Rectangle.cxx:108
A abstract base class for font handling.
Definition: FontBase.h:32
The base class for the PlotterBase hierarchy.
Definition: PlotterBase.h:55
PlotterBase * getPlotter() const
Returns the plotter used by this view.
Definition: ViewBase.cxx:50
PlotterBase * m_plotter
The plotter object used by this view.
Definition: ViewBase.h:69
void setRect(double x, double y, double width, double height)
Set the parameters of 2D Rectangle.
Definition: Rectangle.cxx:70
virtual double marginToUserY(double y) const
Converts from view coordinate to data coordinate, without taking into account transforms or scaling...
Definition: DataView.cxx:198
hippodraw::DataView class interface
virtual double getBottomMargin()
virtual double getZMargin()
double getZ() const
A shortcut to get origin.Z.
Definition: Rectangle.cxx:98
double getDepth() const
A shortcut to get size.depth.
Definition: Rectangle.cxx:118
virtual float userToInvertedMarginX(double x) const
Converts the user X coordinate into the inverted X coordinate.
Definition: DataView.cxx:133
Class representing a rectangle.
Definition: Rectangle.h:34
virtual const FontBase * titleFont() const
What font is being used to override the default while drawing title of plot.
void setMarginRect(const Rect &)
Sets the margin rectangle.
Definition: DataView.cxx:52
The abstract base class for views.
Definition: ViewBase.h:62
Rect m_margin_rect
The rectangle area in which the projected points are plotted.
Definition: DataView.h:48
FontBase class interface.
virtual double getLeftMargin()
virtual float userToMarginY(double y) const
Converts the user Y coordinate into the margin Y coordinate.
Definition: DataView.cxx:144
double getX() const
A shortcut to get origin.X.
Definition: Rectangle.h:154
const Rect & getUserRect() const
Is called by the AxisRepBase object (or one of its derived objects), and returns the rectangle where ...
Definition: ViewBase.cxx:76
hippodraw::Range class interface
DataView()
The default constructor.
Definition: DataView.cxx:25
const Rect & getMarginRect() const
Returns the rectangle area in which data points are drawn.
Definition: DataView.cxx:45
virtual float userToInvertedMarginY(double y) const
Converts the user Y coordinate into the top-left based margin Y coordinate.
Definition: DataView.cxx:154
virtual int pointSize() const =0
Get the pointsize of the font.
virtual double marginToInvertedUserX(double x) const
Converts from view coordinate to data conordiate, take into account the inversion of x axes...
Definition: DataView.cxx:187
virtual double marginToUserX(double x) const
Converts from view coordinate to data coordinate, without taking into account transforms or scaling...
Definition: DataView.cxx:176
virtual double marginToInvertedUserY(double y) const
Converts from inverted view coordinate to data coordinate, without taking into account transforms or ...
Definition: DataView.cxx:209
double getY() const
A shortcut to get origin.Y.
Definition: Rectangle.h:162
hippodraw::PlotterBase class interface.

Generated for HippoDraw Class Library by doxygen