AxisRepBase.cxx
Go to the documentation of this file.
1 
12 // for tex
13 #ifdef HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16 
17 // for truncation warning
18 #ifdef _MSC_VER
19 #include "msdevstudio/MSconfig.h"
20 #define finite _finite
21 #endif
22 
23 #include "AxisRepBase.h"
24 
25 #include "axes/AxisModelBase.h"
26 #include "graphics/Color.h"
27 #include "graphics/DataView.h"
28 #include "pattern/string_convert.h"
30 
31 #include <cmath>
32 #include <cassert>
33 #include <cstdio>
34 
35 using std::max;
36 using std::min;
37 using std::string;
38 using std::vector;
39 #ifdef __USE_ISOC99
40 using std::isfinite;
41 #endif
42 
43 using namespace hippodraw;
44 
46  : m_sci_note_x(false),
47  m_sci_note_y(false),
48  m_axis_x_origin (0.),
49  m_axis_y_origin ( 0.0),
50  m_axis_width ( 0.0 ),
51  m_axis_height ( 0.0 ),
52  m_font_size( 1.0 ),
53  m_x_tick_font_size ( 1.0 ),
54  m_y_tick_font_size ( 1.0 ),
55  m_x_font_size( 1.0 ),
56  m_y_font_size( 1.0 ),
57  m_xLabelFont( 0 ),
58  m_yLabelFont( 0 ),
59  m_zLabelFont( 0 ),
60  m_titleFont( 0 ),
61  m_draw_titles( true )
62 {
63 }
64 
66  : m_sci_note_x(axis_rep.m_sci_note_x),
67  m_sci_note_y(axis_rep.m_sci_note_y),
68  m_axis_x_origin( axis_rep.m_axis_x_origin ),
69  m_axis_y_origin( axis_rep.m_axis_y_origin ),
70  m_axis_width( axis_rep.m_axis_width ),
71  m_axis_height( axis_rep.m_axis_height ),
72  m_font_size( axis_rep.m_font_size ),
73  m_x_font_size( axis_rep.m_x_font_size ),
74  m_y_font_size( axis_rep.m_y_font_size ),
75  m_xLabelFont( axis_rep.m_xLabelFont ),
76  m_yLabelFont( axis_rep.m_yLabelFont ),
77  m_zLabelFont( axis_rep.m_zLabelFont ),
78  m_titleFont( axis_rep.m_titleFont ),
79  m_draw_titles( axis_rep.m_draw_titles )
80 {
81 }
82 
84 {
85  delete m_xLabelFont;
86  delete m_yLabelFont;
87  delete m_zLabelFont;
88  delete m_titleFont;
89 }
90 
91 void
94 {
95  const Rect & rect = view.getUserRect();
96 
97  m_axis_x_origin = rect.getX();
98  m_axis_y_origin = rect.getY();
99  m_axis_width = rect.getWidth();
100  m_axis_height = rect.getHeight();
101 }
102 
103 void
106 {
107  initAxisRect( view );
108 }
109 
111 {
112  m_draw_titles = set;
113 }
114 
115 void
117 drawTitle ( ViewBase & base, const std::string & title )
118 {
119 
120  DataView & view = dynamic_cast < DataView & > ( base );
121 
122  // Draw Latex at the top of the plotter if in Latex format
123 #ifdef HAVE_TEX_UTILS
124  if (String::ci_find(title, "tex:")==0) {
125  string tex_snippet = title.substr(4);
126  view.drawLatex ( tex_snippet, 1 );
127  }
128 
129  else {
130 #endif
131  const Rect & marginRect = view.getMarginRect();
132  float mx = marginRect.getX();
133  Rect rect = view.getDrawRect ();
134  float mw = rect.getWidth();
135 
136  double x_font_size = ( 1.3 * mw ) / title.size();
137  m_font_size = min(x_font_size,12.0);
138 
139  double one = 1.0;
140  m_font_size = max ( m_font_size, one );
141 
142  float x = mx + 0.5 * marginRect.getWidth ();
143  float y = 2.0;
144 
145  if ( m_titleFont != 0 ) {
146  view.drawText ( title, x, y, 0.0, 0.0, 'c', 't', false,
147  m_titleFont );
148  } else {
149  view.drawText ( title, x, y, m_font_size, 0.0, 'c', 't', false );
150  }
151 
152 #ifdef HAVE_TEX_UTILS
153  }
154 #endif
155 }
156 
157 void
159 setXFontSize ( const AxisModelBase & axisModel,
160  ViewBase & view )
161 {
162  Rect draw_rect = view.getDrawRect();
163  m_x_tick_font_size = min( ( draw_rect.getWidth() ) * 0.040, 12.0 );
164  double one = 1.0;
165  m_x_tick_font_size = max ( m_x_tick_font_size, one );
166 
167  AxisLoc location = axisModel.getScaleLocation();
168 
169  if ( location == PLOTBOTTOM )
170  {
171  m_x_font_size = min( (double)m_x_tick_font_size,
172  ( m_axis_y_origin -
173  draw_rect.getY() ) / 2.0 );
174  }
175  else if ( location == PLOTTOP )
176  {
177  m_x_font_size = min( (double)m_x_tick_font_size,
178  ( draw_rect.getHeight() -
179  m_axis_height -
181  - draw_rect.getY() ) ) /2.0 );
182  }
183 }
184 
185 void
187 setYFontSize ( const AxisModelBase & axisModel,
188  ViewBase & view )
189 {
190  assert ( m_y_tick_font_size > 0 );
191 
192  Rect draw_rect = view.getDrawRect();
193  double height = draw_rect.getHeight ();
194  double size = height * 0.040;
195  size = std::min ( size, 11.0 );
196  double one = 1.0;
197  m_y_tick_font_size = std::max ( size, one );
198 
199  assert ( m_y_tick_font_size > 0 );
200  const vector<AxisTick> & labels = axisModel.getTicks ( );
201  if ( labels.empty () == true ) return;
202 
203  if ( axisModel.getScaleLocation() & PLOTLEFT )
204  {
205  float yr;
206 
207  if ( m_draw_titles &&
208  axisModel.getLabelLocation() & PLOTLEFT ) {
209  yr = 14;
210  }
211  else {
212  yr = 0;
213  }
214  const AxisTick & tick = labels.back ( );
216  ( m_axis_x_origin -
217  draw_rect.getX() - yr )
218  / tick.content().size() );
219  }
220  else if ( axisModel.getScaleLocation() & PLOTRIGHT )
221  {
222  // Estimates the space needed for the Y axis label.
223  float yr;
224  if ( m_draw_titles &&
225  axisModel.getLabelLocation() & PLOTRIGHT ) {
226  yr = 14;
227  } else {
228  yr = 0;
229  }
230 
232  ( draw_rect.getWidth() -
233  m_axis_width -
234  ( m_axis_x_origin -
235  draw_rect.getX() ) - yr )
236  / labels[labels.size() - 1].content().size() );
237  }
238 }
239 
240 void
242 setZFontSize ( const AxisModelBase & axisModel,
243  ViewBase & view )
244 {
245  AxisLoc location = axisModel.getScaleLocation();
246  Rect draw_rect = view.getDrawRect();
247  if ( location == PLOTBOTTOM )
248  {
249  m_z_font_size = min( (double)m_font_size,
250  ( m_axis_y_origin -
251  draw_rect.getY() ) / 2.0 );
252  }
253  else if ( location == PLOTTOP )
254  {
255  m_z_font_size = min( (double)m_font_size,
256  ( draw_rect.getHeight() -
257  m_axis_height -
259  - draw_rect.getY() ) ) /2.0 );
260  }
261 }
262 
263 void
265 drawXLabels ( const AxisModelBase & axisModel,
266  ViewBase & base, const std::string & x_label )
267 {
268  DataView & view = dynamic_cast < DataView & > ( base );
269 
270  // Calculate the ratio of range(rmag) and value(pmag) to decide
271  // where scientific notation is needed.
272  const vector< AxisTick > & ticks = axisModel.getTicks();
273  m_sci_note_x=false;
274  int mid = ticks.size()/2;
275  double ref = ticks[mid].value();
276  double range = ticks[mid+1].value()-ref;
277  if (fabs(ref/range)>1e6) m_sci_note_x=true;
278 
279  // Draw Latex at the bottom of the plotter if in Latex format
280 #ifdef HAVE_TEX_UTILS
281  if (String::ci_find(x_label, "tex:")==0) {
282  string tex_snippet = x_label.substr(4);
283  if (m_sci_note_x) {
284  tex_snippet+="-"+ticks[mid].content();
285  if (axisModel.needPMag()) {
286  // Use LaTeX to generate: label-mid*10^Pmag
287  tex_snippet+="\\times 10^"+String::convert ( static_cast <int> (axisModel.getPMag()) );
288  }
289  }
290  view.drawLatex ( tex_snippet, 2 );
291  }
292 
293  else {
294 #endif
295  std::string label;
296  if (m_sci_note_x) {
297  label = x_label+" - "+ticks[mid].content();
298  }
299  else {
300  label = x_label;
301  }
302 
303  float x = 0., y = 0.;
304  Rect draw_rect = view.getDrawRect ();
305  float draw_h = draw_rect.getHeight ();
306  float draw_w = draw_rect.getWidth ();
307 
308  const Rect & margin_rect = view.getMarginRect ();
309  float margin_x = margin_rect.getX ();
310  float margin_w = margin_rect.getWidth ();
311 
312  x = margin_x + 0.5 * margin_w;
313 
314  float tmp = 0.045 * draw_w;
315  tmp = max ( tmp, 1.0f );
316  m_x_font_size = min ( tmp, static_cast<float>( 18.0 ) );
317  assert ( m_x_font_size > 0 );
318 
319  double ratio = draw_w / ( label.size() ) * 2;
320  m_x_font_size = std::min ( m_x_font_size, ratio );
321  assert ( m_x_font_size > 0 );
322  double one = 2.0;
323  m_x_font_size = std::max ( m_x_font_size, one );
324 
325  assert ( m_x_font_size > 0 );
326  if ( axisModel.getLabelLocation() & PLOTBOTTOM )
327  {
328  if ( m_xLabelFont != 0 ) {
329  y = draw_h - 1.5*m_xLabelFont->pointSize()-6.0; // experimental
330  view.drawText ( label, x, y, 0., 0.0, 'c', 't',
331  false, m_xLabelFont );
332  } else {
333  y = draw_h - m_x_font_size - 6.0; // take into account descenders
334  view.drawText ( label, x, y, m_x_font_size, 0.0, 'c', 't', false );
335  }
336  }
337  else if ( axisModel.getLabelLocation() & PLOTTOP )
338  {
339  y = 1.0;
340  if ( m_xLabelFont != 0 ) {
341 
342  view.drawText ( label, x, y, 0.0, 0.0, 'c', 't',
343  false, m_xLabelFont );
344  } else {
345 
346  view.drawText ( label, x, y, m_x_font_size, 0.0, 'c', 't', false );
347  }
348  }
349 
350 
351  // Draw the mag when both pmag and small range sci_note are needed.
352  // TODO: handle (location & PLOTTOP)
353  if ( (m_sci_note_x) && (axisModel.needPMag() ) ){
354  if ( m_xLabelFont == NULL ) {
355  x = x+0.27 * m_x_font_size * label.size();
356  y = y+0.2 * m_x_font_size;
357  view.drawText ( " x10", x, y, m_x_font_size*0.8, 0.0, 'c', 't', false );
358 
359  double pmag = axisModel.getPMag();
360  int i = static_cast < int > ( pmag );
361  const string text = String::convert ( i );
362  x += 1.0 * m_x_font_size ;
363  y -= 0.4 * m_x_font_size;
364  view.drawText ( text, x, y, m_x_font_size*0.8, 0.0, 'c', 't', false );
365  } else {
366  x = x+0.4 * m_xLabelFont->pointSize() * label.size();
367  view.drawText ( " x10", x, y, 0.0, 0.0, 'c', 't', false, m_xLabelFont );
368 
369  double pmag = axisModel.getPMag();
370  int i = static_cast < int > ( pmag );
371  const string text = String::convert ( i );
372  x += 1.6 * m_xLabelFont->pointSize() ;
373  y -= 0.4 * m_xLabelFont->pointSize();
374  view.drawText ( text, x, y, 0.0, 0.0, 'c', 't', false, m_xLabelFont );
375  }
376  }
377 #ifdef HAVE_TEX_UTILS
378  }
379 #endif
380 
381 }
382 void
384 drawYLabels ( const AxisModelBase & axisModel,
385  ViewBase & base, const std::string & y_label )
386 {
387  DataView & view = dynamic_cast < DataView & > ( base );
388 
389  // Calculate the ratio of range(rmag) and value(pmag) to decide
390  // where scientific notation is needed.
391  const vector< AxisTick > & ticks = axisModel.getTicks();
392  m_sci_note_y=false;
393  int mid = ticks.size()/2;
394  double ref = ticks[mid].value();
395  double range = ticks[mid+1].value()-ref;
396  if (fabs(ref/range)>1e6) m_sci_note_y=true;
397 
398 
399 #ifdef HAVE_TEX_UTILS
400  // Draw Latex at the left of the plotter if in Latex format
401  if (String::ci_find(y_label, "tex:")==0) {
402  string tex_snippet = y_label.substr(4);
403 
404  if (m_sci_note_y) {
405  tex_snippet+="-"+ticks[mid].content();
406  if (axisModel.needPMag()) {
407  // Use LaTeX to generate: label-mid*10^Pmag
408  tex_snippet+="\\times 10^"+String::convert ( static_cast <int> (axisModel.getPMag()) );
409  }
410  }
411 
412 
413  view.drawLatex ( tex_snippet, 3 );
414  }
415 
416  else {
417 #endif
418 
419 
420  std::string label;
421  if (m_sci_note_y) {
422  label = y_label+" - "+ticks[mid].content();
423  }
424  else {
425  label = y_label;
426  }
427 
428  Rect draw_rect = view.getDrawRect ();
429 
430  float x = 0., y = 0.;
431  AxisLoc location = axisModel.getLabelLocation();
432 
433  //float tmp = min ( view.getDrawRect().getWidth() * 0.05,
434  // view.getDrawRect().getHeight() * 0.05 );
435  float tmp = draw_rect.getHeight() * 0.05;
436  m_y_font_size = min( tmp, static_cast<float>( 18.0 ) );
437  m_y_font_size = min( m_y_font_size, draw_rect.getHeight()
438  / ( label.size() ) * 2 );
439  double one = 1.0;
440  m_y_font_size = max ( m_y_font_size, one );
441  y = view.getMarginRect().getY() +
442  view.getMarginRect().getHeight() *0.5;
443 
444  if ( location & PLOTLEFT )
445  {
446  x = 2.0;
447  if ( m_yLabelFont != 0 ) {
448  view.drawText ( label, x, y, 0.0, 90.0, 'c', 't',
449  false, m_yLabelFont );
450  } else {
451  view.drawText ( label, x, y, m_y_font_size, 90.0, 'c', 't', false );
452  }
453  }
454  else if ( location & PLOTRIGHT )
455  {
456  x = draw_rect.getWidth() - 2.0;
457  if ( m_yLabelFont != 0 ) {
458  view.drawText ( label, x, y, 0.0, -90.0, 'c', 't',
459  false, m_yLabelFont );
460  } else {
461  view.drawText ( label, x, y, m_y_font_size, -90.0, 'c', 't', false );
462  }
463  }
464 
465 
466  // Draw the mag when both pmag and small range sci_note are needed.
467  // TODO: handle (location & PLOTTOP)
468  if ( (m_sci_note_y) && (axisModel.needPMag() ) ){
469  if ( m_yLabelFont == NULL ) {
470  y = y-0.27 * m_y_font_size * label.size();
471  x = x+0.2 * m_y_font_size;
472  view.drawText ( " x10", x, y, m_y_font_size*0.8, 90.0, 'c', 't', false );
473 
474  double pmag = axisModel.getPMag();
475  int i = static_cast < int > ( pmag );
476  const string text = String::convert ( i );
477  x -= 0.4 * m_y_font_size ;
478  y -= 1.0 * m_y_font_size;
479  view.drawText ( text, x, y, m_y_font_size*0.8, 90.0, 'c', 't', false );
480  } else {
481  y = y-0.4 * m_yLabelFont->pointSize() * label.size();
482  view.drawText ( " x10", x, y, 0.0, 90.0, 'c', 't', false, m_yLabelFont );
483 
484  double pmag = axisModel.getPMag();
485  int i = static_cast < int > ( pmag );
486  const string text = String::convert ( i );
487  x -= 0.4 * m_yLabelFont->pointSize() ;
488  y -= 1.6 * m_yLabelFont->pointSize();
489  view.drawText ( text, x, y, 0.0, 90.0, 'c', 't', false, m_yLabelFont );
490  }
491  }
492 #ifdef HAVE_TEX_UTILS
493  }
494 #endif
495 }
496 
497 void
499 drawReferencePoint( const AxisModelBase & axisModel,
500  ViewBase & base,
501  const std::string & ref)
502 {
503  if ( axisModel.getScaleLocation() & PLOTBOTTOM )
504  {
505  DataView & view = dynamic_cast < DataView & > ( base );
506 
507  const Rect & margin_rect = view.getMarginRect ();
508  float x = margin_rect.getX() + margin_rect.getWidth ();
509 
510  x -= 1 * m_x_tick_font_size * ref.size();
511 
512  Rect view_rect = view.getDrawRect ();
513  float y = + view_rect.getHeight ();
514 
515  view.drawText ( "X Ref:"+ref, x, y, m_x_tick_font_size, 0., 'l', 'b' );
516  }
517  else if (axisModel.getScaleLocation() & PLOTLEFT)
518  {
519  DataView & view = dynamic_cast < DataView & > ( base );
520 
521  float x = 2.;
522  x += m_y_tick_font_size;
523 
524  const Rect & margin_rect = view.getMarginRect ();
525  float y = margin_rect.getY() + 0.2 * m_y_tick_font_size;
526 
527  view.drawText ( "Y Ref:"+ref, x, y, m_y_tick_font_size, 0., 'l', 'b' );
528  }
529 
530 }
531 
532 
533 void
535 drawXMag ( const AxisModelBase & axisModel,
536  ViewBase & base , const std::string & mag )
537 {
538  DataView & view = dynamic_cast < DataView & > ( base );
539 
540  const Rect & margin_rect = view.getMarginRect ();
541  float x = margin_rect.getX() + margin_rect.getWidth ();
542 
543  double pmag = axisModel.getPMag();
544  int i = static_cast<int> (pmag);
545  const string text = String::convert ( i );
546  x -= 0.8 * m_x_tick_font_size * text.size();
547 
548  Rect view_rect = view.getDrawRect ();
549  float y = + view_rect.getHeight ();
550 
551  view.drawText ( "x10", x, y, 0.75 * m_x_tick_font_size, 0., 'l', 'b' );
552 
553  x += 1.25 * m_x_tick_font_size ;
554  y -= 0.5 * m_x_tick_font_size;
555 
556  if (m_sci_note_x) {
557  view.drawText( mag, x, y, 0.75 * m_x_tick_font_size, 0., 'l', 'b' );
558  } else {
559  view.drawText ( text, x, y, 0.75 * m_x_tick_font_size, 0., 'l', 'b' );
560  }
561 }
562 
563 void
565 drawYMag ( const AxisModelBase & axisModel,
566  ViewBase & base, const std::string & mag )
567 {
568  DataView & view = dynamic_cast < DataView & > ( base );
569 
570  float x = 2.;
571  if ( axisModel.getScaleLocation() & PLOTLEFT ) {
572  x += m_y_tick_font_size;
573  }
574  else {
575  x -= m_y_tick_font_size;
576  }
577 
578  const Rect & margin_rect = view.getMarginRect ();
579  float y = margin_rect.getY() + 0.5 * m_y_tick_font_size;
580 
581  view.drawText ( "x10", x, y, m_y_tick_font_size, 0., 'l', 'b' );
582 
583  double pmag = axisModel.getPMag();
584  int i = static_cast < int > ( pmag );
585  const string text = String::convert ( i );
586  x += 1.75 * m_y_tick_font_size ;
587  y -= 0.5 * m_y_tick_font_size;
588 
589  if (m_sci_note_y) {
590  view.drawText ( mag, x, y, m_y_tick_font_size, 0., 'l', 'b' );
591  } else {
592  view.drawText ( text, x, y, m_y_tick_font_size, 0., 'l', 'b' );
593  }
594 
595 }
596 
597 void
600  ViewBase & view,
601  const Range & x_range,
602  const Range & y_range)
603 {
604  const BinaryTransform & t
605  = dynamic_cast< const BinaryTransform & > ( transform );
606  vector< double > xv ( 100 );
607  vector< double > yv ( 100 );
608  Color black ( 0, 0, 0 );
609 
610  xv[0] = x_range.low( );
611  yv[0] = y_range.low( );
612  for( int i = 1; i < 100; i++)
613  {
614  xv[i] = xv[i-1] + ( x_range.high() - x_range.low() )/99;
615  yv[i] = yv[i-1];
616  }
617  t.transform( xv, yv );
618  view.drawPolyLine ( xv, yv, Line::Solid, black, 1 );
619 
620 
621  xv[0] = x_range.high( );
622  yv[0] = y_range.low( );
623  for( int i = 1; i < 100; i++)
624  {
625  xv[i] = xv[i-1];
626  yv[i] = yv[i-1] + ( y_range.high() - y_range.low() )/99; ;
627  }
628  t.transform( xv, yv );
629  view.drawPolyLine ( xv, yv, Line::Solid, black, 1 );
630 
631 
632  xv[0] = x_range.low( );
633  yv[0] = y_range.high( );
634  for( int i = 1; i < 100; i++)
635  {
636  xv[i] = xv[i-1] + ( x_range.high() - x_range.low() )/99;
637  yv[i] = yv[i-1];
638  }
639 
640  t.transform( xv, yv );
641  view.drawPolyLine ( xv, yv, Line::Solid, black, 1 );
642 
643 
644  xv[0] = x_range.low( );
645  yv[0] = y_range.low( );
646  for( int i = 1; i < 100; i++)
647  {
648  xv[i] = xv[i-1];
649  yv[i] = yv[i-1] + ( y_range.high() - y_range.low() )/99;
650  }
651 
652  t.transform( xv, yv );
653  view.drawPolyLine ( xv, yv, Line::Solid, black, 1 );
654 
655 
656 }
657 
658 
659 
660 void AxisRepBase::drawGridLines( const AxisModelBase & axisModelX,
661  const AxisModelBase & axisModelY,
662  TransformBase & transform,
663  ViewBase & view )
664 {
665  Range x_range = axisModelX.getRange( false );
666  Range y_range = axisModelY.getRange( false );
667 
668 
669  const vector< AxisTick > & x_ticks = axisModelX.getTicks();
670  const vector< AxisTick > & y_ticks = axisModelY.getTicks();
671 
672  unsigned int nxpoints = 100;
673  unsigned int nypoints = 100;
674  vector< double > xv(100), yv(100);
675 
676  double user_x, user_y;
677  Color grey( 180, 180, 180 );
678 
679  BinaryTransform & t
680  = dynamic_cast< BinaryTransform & > ( transform );
681 
682  t.validate( x_range, y_range );
683 
684  if ( x_ticks.empty () == true || y_ticks.empty () == true )
685  return;
686 
687 
688  double dx = ( x_range.high() - x_range.low() ) / ( nxpoints - 1 );
689  double dy = ( y_range.high() - y_range.low() ) / ( nypoints - 1 ) ;
690 
691 
692  // Drawing the coordinates of the aligned along y-Axis
693  // i.e.curves for which x = const
694  // Don't draw first tick if it will cover the left edge.
695  for ( unsigned int i = ( x_range.low() == x_ticks[0].value() )?1:0;
696  i < x_ticks.size(); i++ )
697  {
698  user_x = x_ticks[ i ].value();
699 
700  for ( unsigned int j = 0; j < nypoints; j++ )
701  {
702  user_y = y_range.low() + j * dy;
703 
704  xv[ j ] = user_x;
705  yv[ j ] = user_y;
706 
707  }
708 
709  t.transform( xv, yv );
710  view.drawPolyLine ( xv, yv, Line::Dot, grey, 0 );
711 
712  }
713 
714 
715  // Drawing the coordinates of the aligned along x-Axis
716  // i.e.curves for which y = const
717  // Don't draw first tick if it will cover the bottom edge.
718  for ( unsigned int j = ( y_range.low() == y_ticks[0].value() )?1:0;
719  j < y_ticks.size(); j++ )
720  {
721  user_y = y_ticks[ j ].value();
722 
723  for ( unsigned int i = 0; i < nxpoints; i++ )
724  {
725  user_x = x_range.low() + i * dx;
726 
727  xv[ i ] = user_x ;
728  yv[ i ] = user_y ;
729  }
730 
731  t.transform( xv, yv );
732  view.drawPolyLine( xv, yv, Line::Dot, grey, 0 );
733  }
734 
735  return;
736 }
737 
738 void
740 drawXTickLines( const AxisModelBase & axisModelX,
741  const AxisModelBase & axisModelY,
742  const TransformBase & transform,
743  ViewBase & base )
744 {
745  DataView & view = dynamic_cast < DataView & > ( base );
746  AxisLoc loc = axisModelX.getLabelLocation();
747  assert( loc == PLOTBOTTOM || PLOTTOP );
748 
749  const vector< AxisTick > & ticks = axisModelX.getTicks();
750  if ( ticks.empty() == true ) return;
751 
752  vector< double > xv;
753  vector< double > yv;
754 
755  unsigned int size = 4 * ticks.size();
756  xv.reserve( size );
757  yv.reserve( size );
758 
759  const BinaryTransform & t
760  = dynamic_cast< const BinaryTransform & > ( transform );
761 
762  const Rect & view_rect = view.getMarginRect();
763  double tick_length = 0.05 * view_rect.getHeight();
764  tick_length = min ( tick_length, 8. );
765  Range yrange = axisModelY.getRange( false );
766 
767  for ( unsigned int i = 0; i < ticks.size(); i++ )
768  {
769  double user_x_start = ticks[i].value ();
770  double user_x_temp = user_x_start;
771 
772  double user_by_start = yrange.low();
773  double user_ty_start = yrange.high();
774 
775  // transform will change the x value, so we need the temp
776  t.transform ( user_x_start, user_by_start );
777  t.transform ( user_x_temp, user_ty_start );
778 
779  double view_x_start = view.userToDrawXAutoInv ( user_x_start );
780  double view_by_start = view.userToDrawY ( user_by_start );
781  double view_ty_start = view.userToDrawY ( user_ty_start );
782 
783  double view_x_end = view_x_start;
784  double view_by_end = view_by_start - tick_length;
785  double view_ty_end = view_ty_start + tick_length;
786 
787 #ifdef __USE_ISOC99
788  if( isfinite( view_x_start ) &&
789  isfinite( view_by_start ) &&
790  isfinite( view_ty_start ) &&
791  isfinite( view_x_start ) &&
792  isfinite( view_by_end ) )
793 #else
794  if( finite( view_x_start ) &&
795  finite( view_by_start ) &&
796  finite( view_ty_start ) &&
797  finite( view_x_start ) &&
798  finite( view_by_end ) )
799 #endif
800  {
801  xv.push_back( view_x_start );
802  yv.push_back( view_by_start );
803  xv.push_back( view_x_end );
804  yv.push_back( view_by_end );
805 
806  xv.push_back( view_x_start );
807  yv.push_back( view_ty_start );
808  xv.push_back( view_x_end );
809  yv.push_back( view_ty_end );
810  }
811  }
812 
813  view.drawViewLines ( xv, yv, Line::Solid, false, 1 );
814 }
815 
816 void
818 drawYTickLines ( const AxisModelBase & axisModelX,
819  const AxisModelBase & axisModelY,
820  const TransformBase & transform,
821  ViewBase & base )
822 {
823  AxisLoc loc = axisModelY.getLabelLocation ();
824  assert ( loc == PLOTLEFT || loc == PLOTRIGHT );
825 
826  DataView & view = dynamic_cast < DataView & > ( base );
827  const Rect & draw_rect = view.getMarginRect ();
828 
829  double tick_length = 0.05 * draw_rect.getWidth ();
830  tick_length = min ( tick_length, 8. );
831 
832  vector< double > xv;
833  vector< double > yv;
834 
835  const vector< AxisTick > & ticks = axisModelY.getTicks ();
836  unsigned int size = ticks.size ();
837 
838  if ( size == 0 ) return;
839 
840  size *= 4;
841 
842  xv.reserve ( size );
843  yv.reserve ( size );
844 
845  const BinaryTransform & t
846  = dynamic_cast< const BinaryTransform & > ( transform );
847 
848  Range xrange = axisModelX.getRange( false );
849 
850  for ( unsigned int i = 0; i < ticks.size(); i++ )
851  {
852  double user_lx_start = xrange.low();
853  double user_rx_start = xrange.high();
854  double user_y_start = ticks[i].value();
855  double user_y_temp = user_y_start; // for second call to transform
856 
857  // transform modifies its argument, thus we need 2 separate y's
858  t.transform( user_lx_start, user_y_start );
859  t.transform( user_rx_start, user_y_temp );
860 
861  double view_lx_start = view.userToDrawX( user_lx_start );
862  double view_rx_start = view.userToDrawX( user_rx_start );
863  double view_y_start = view.userToDrawY( user_y_start );
864 
865  double view_lx_end = view_lx_start + tick_length;
866  double view_rx_end = view_rx_start - tick_length;
867  double view_y_end = view_y_start;
868 
869 #ifdef __USE_ISOC99
870  if( isfinite( view_lx_start ) &&
871  isfinite( view_y_start ) &&
872  isfinite( view_lx_start ) &&
873  isfinite( view_y_end ) )
874 #else
875  if( finite( view_lx_start ) &&
876  finite( view_y_start ) &&
877  finite( view_lx_start ) &&
878  finite( view_y_end ) )
879 #endif
880  {
881  xv.push_back( view_lx_start );
882  yv.push_back( view_y_start );
883  xv.push_back( view_lx_end );
884  yv.push_back( view_y_end );
885 
886  xv.push_back( view_rx_start );
887  yv.push_back( view_y_start );
888  xv.push_back( view_rx_end );
889  yv.push_back( view_y_end );
890  }
891  }
892 
893  view.drawViewLines ( xv, yv, Line::Solid, false, 1 );
894 }
895 
896 void
898 setFontSize( const AxisModelBase * xAxisModel,
899  const AxisModelBase * yAxisModel,
900  const AxisModelBase * zAxisModel,
901  ViewBase & view )
902 {
903  Rect draw_rect = view.getDrawRect();
904 
905  m_font_size = min( ( draw_rect.getWidth() ) * 0.040, 12.0 );
906  m_font_size = min (m_font_size, 12.0);
907  double one = 1.0;
908  m_font_size = max ( m_font_size, one );
909  setXFontSize ( *xAxisModel, view );
910  setYFontSize ( *yAxisModel, view );
911  if ( zAxisModel != 0 ) setZFontSize ( *zAxisModel, view );
912 }
913 
914 void
916 drawXTickLabels ( const AxisModelBase & axisModelX,
917  const AxisModelBase & axisModelY,
918  const TransformBase & transform,
919  ViewBase & base )
920 {
921  double padding = 1.0;
922 
923  vector < double > xv;
924  vector < double > yv;
925 
926  const vector < AxisTick > & ticks = axisModelX.getTicks ();
927  unsigned int size = ticks.size ();
928  if ( size == 0 ) return;
929 
930  xv.reserve ( size );
931  yv.reserve ( size );
932 
933  Range yrange = axisModelY.getRange( false );
934 
935  for ( unsigned int i = 0; i < size; i++ ){
936  xv.push_back ( ticks[i].value () );
937  yv.push_back ( yrange.low() );
938  }
939 
940  const BinaryTransform & t
941  = dynamic_cast< const BinaryTransform & > ( transform );
942  t.transform ( xv, yv );
943 
944  // Calculate the Y position in view coordinates.
945  DataView & view = dynamic_cast < DataView & > ( base );
946  const Rect & margin = view.getMarginRect ();
947  float y = margin.getY ();
948  float x;
949  char yp = 'b';
950 
951  if ( axisModelX.getScaleLocation() & PLOTBOTTOM ) {
952  y = margin.getY () + margin.getHeight ();
953  yp = 't';
954  }
955 
956  // If scientific notation is needed, calculate mag.
957  string mag="";
958  double ref = 0.;
959  if (m_sci_note_x) {
960  int mid = ticks.size()/2;
961  ref = ticks[mid].value();
962  double range = ticks[mid+1].value()-ref;
963  char cstr[8];
964  sprintf(cstr, "%.0e", range);
965  string str(cstr);
966  string::size_type pos = str.find ( 'e' );
967  mag=string( str, pos + 1 ); // exponent
968  }
969 
970  for ( unsigned int i = 0; i < ticks.size(); i++ )
971  {
972  // In first stage we calculate the tick. This shall help us get
973  // the direction of the tick and using it we shall locate where
974  // to draw the tick labels.
975  double user_x_start = ticks[i].value();
976  double user_y_start = yrange.low();
977 
978  t.transform( user_x_start, user_y_start );
979 
980  double view_x_start = view.userToDrawXAutoInv( user_x_start );
981  double view_y_start = view.userToDrawY( user_y_start );
982 
983  double user_x_end = ticks[i].value ();
984  double user_y_end =
985  yrange.low() + .05 * ( yrange.high() - yrange.low() );
986 
987  t.transform( user_x_end, user_y_end );
988 
989  double view_x_end = view.userToDrawXAutoInv( user_x_end );
990  double view_y_end = view.userToDrawY( user_y_end );
991 
992  // Calculating the unit vector (ux,uy) in the direction of the tick
993  double dx = view_x_end - view_x_start;
994  double dy = view_y_end - view_y_start;
995 
996  double ux = dx / sqrt( dx * dx + dy * dy );
997  double uy = dy / sqrt ( dx * dx + dy * dy );
998 
999  // Now calculate the x coord of the end point of the tick by
1000  // moving a distance "tick_length" starting from view_x_start
1001  // in the direction of ux. Similarly for y coordinate.
1002  x = view_x_start - ux * padding;
1003  y = view_y_start - uy * padding;
1004 
1005  // Plot the labels now. ( Handle two mode. )
1006  if (m_sci_note_x){
1007  // Draw the difference from reference tick value.
1008  double diff=ticks[i].value()-ref;
1009  // 6 byte should be enough, as small as -1e-99
1010  char pstr[8];
1011  sprintf(pstr, "%.0e", diff);
1012  const std::string str(pstr);
1013  string::size_type pos = str.find ( 'e' );
1014  string m ( str, 0, pos ); // mantessa
1015  string e ( str, pos + 1 ); // exponent
1016  // Is this safe ?
1017  if (e!=mag && m!="0") m+="0";
1018  drawXTickLabel ( m, x, y, view );
1019  }
1020  else {
1021  // Draw the content of the ticks.
1022  drawXTickLabel ( ticks[i].content(), x, y, view );
1023  }
1024  }
1025 
1026  // Draw sct_note reference point or pmag.
1027  if (m_sci_note_x) {
1028  drawXMag( axisModelX, view, mag );
1029  //drawXLabels(axisModelX, view, "X="+ticks[mid].content());
1030  //drawReferencePoint( axisModelX, view, ticks[mid].content());
1031  }
1032 
1033  else if ( axisModelX.needPMag () )
1034  {
1035  // Logarithmic graphs do not need the magnitude written.
1036  if ( axisModelX.isLog () == false ) {
1037  drawXMag ( axisModelX, view );
1038  }
1039  }
1040 }
1041 
1042 void
1044 drawYTickLabels ( const AxisModelBase & axisModelX,
1045  const AxisModelBase & axisModelY,
1046  const TransformBase & transform,
1047  ViewBase & view )
1048 {
1049  double padding = 2.0;
1050 
1051  const vector< AxisTick > & ticks = axisModelY.getTicks ();
1052  unsigned int size = ticks.size ();
1053  if ( size == 0 ) return;
1054 
1055  const BinaryTransform & t
1056  = dynamic_cast< const BinaryTransform & > ( transform );
1057 
1058  Range xrange = axisModelX.getRange( false );
1059 
1060  // If scientific notation is needed, calculate mag.
1061  string mag="";
1062  double ref = 0.;
1063  if (m_sci_note_y) {
1064  int mid = ticks.size()/2;
1065  ref = ticks[mid].value();
1066  double range = ticks[mid+1].value()-ref;
1067  char cstr[8];
1068  sprintf(cstr, "%.0e", range);
1069  string str(cstr);
1070  string::size_type pos = str.find ( 'e' );
1071  mag=string( str, pos + 1 ); // exponent
1072  }
1073 
1074  for ( unsigned int i = 0; i < ticks.size(); i++ )
1075  {
1076  // In first stage we calculate the tick. This shall help us get
1077  // the direction of the tick and using it we shall locate where
1078  // to draw the tick labels.
1079  double user_x_start = xrange.low();
1080  double user_y_start = ticks[i].value();
1081 
1082  t.transform( user_x_start, user_y_start );
1083 
1084  double view_x_start = view.userToDrawX( user_x_start );
1085  double view_y_start = view.userToDrawY( user_y_start );
1086 
1087  double user_x_end
1088  = xrange.low() + .05 * ( xrange.high() - xrange.low() );
1089  double user_y_end = ticks[i].value ();
1090 
1091  t.transform( user_x_end, user_y_end );
1092 
1093  double view_x_end = view.userToDrawX( user_x_end );
1094  double view_y_end = view.userToDrawY( user_y_end );
1095 
1096  // Calculating the unit vector (ux,uy) in the direction of the tick
1097  double dx = view_x_end - view_x_start;
1098  double dy = view_y_end - view_y_start;
1099 
1100  double ux = dx / sqrt( dx * dx + dy * dy );
1101  double uy = dy / sqrt ( dx * dx + dy * dy );
1102 
1103  // Now calculate the x coord of the end point of the tick by
1104  // moving a distance "tick_length" starting from view_x_start
1105  // in the direction of ux. Similarly for y coordinate.
1106  float x = view_x_start - ux * padding;
1107  float y = view_y_start - uy * 1.5;
1108 
1109  // Plot the labels now. ( Handle two mode. )
1110  if (m_sci_note_y){
1111  // Draw the difference from reference tick value.
1112  double diff=ticks[i].value()-ref;
1113  // 6 byte should be enough, as small as -1e-99
1114  char pstr[8];
1115  sprintf(pstr, "%.0e", diff);
1116  const std::string str(pstr);
1117  string::size_type pos = str.find ( 'e' );
1118  string m ( str, 0, pos ); // mantessa
1119  string e ( str, pos + 1 ); // exponent
1120  // Is this safe?
1121  if (e!=mag && m!="0") m+="0";
1122  drawYTickLabel ( m, x, y, view );
1123  }
1124  else {
1125  // Draw the content of the ticks.
1126  drawYTickLabel ( ticks[i].content(), x, y, view );
1127  }
1128  }
1129 
1130 
1131  // Draw pmag.
1132  if (m_sci_note_y) {
1133  drawYMag( axisModelY, view, mag );
1134  }
1135 
1136  else if ( axisModelY.needPMag () ){
1137  // Logarithmic graphs do not need the magnitude written.
1138  if ( axisModelY.isLog () == false ) {
1139  drawYMag ( axisModelY, view );
1140  }
1141  }
1142 }
1143 
1144 void
1146 drawXTickLabel ( const std::string & label, float x, float y, ViewBase & view )
1147 {
1148  char xalign = 'c';
1149  char yalign = 't';
1150  float angle = 0.;
1151  double & font_size = m_x_tick_font_size;
1152 
1153  string::size_type pos = label.find ( 'e' );
1154  if ( pos == string::npos ) {
1155  view.drawText ( label, x, y, m_x_tick_font_size, angle, xalign, yalign );
1156  }
1157  else { // need superscript
1158  double ss_size = 0.9 * font_size;
1159  string m ( label, 0, pos ); // mantessa
1160  string e ( label, pos + 1 ); // exponent
1161  if ( m == "1" ) {
1162  m += "0";
1163  x += 0.25 * font_size; // don't know why this is needed.
1164  y += 0.25 * ss_size;
1165  view.drawText ( m, x, y, font_size, angle, 'r', yalign );
1166 
1167  if ( e[0] == '-' ) {
1168  x -= 0.10 * font_size;
1169  }
1170  y -= 0.5 * ss_size;
1171  view.drawText ( e, x, y, ss_size, angle, 'l', yalign );
1172  }
1173  else { // m != 1
1174  m += "x10";
1175  x += 0.25 * font_size;
1176  y += 0.25 * ss_size;
1177  view.drawText ( m, x, y, font_size, angle, 'r', yalign );
1178 
1179  if ( e[0] == '-' ) {
1180  x -= 0.10 * font_size;
1181  }
1182  y -= 0.5 * ss_size;
1183  view.drawText ( e, x, y, ss_size, angle, 'l', yalign );
1184  }
1185  }
1186 }
1187 
1188 
1189 void
1191 drawYTickLabel ( const std::string & label,
1192  float x, float y,
1193  ViewBase & view )
1194 {
1195  char xalign = 'r';
1196  char yalign = 'c';
1197  float angle = 0.;
1198  double font_size = m_y_tick_font_size;
1199 
1200  string::size_type pos = label.find ( 'e' );
1201  if ( pos == string::npos ) {
1202  view.drawText ( label, x, y, font_size, angle, xalign, yalign );
1203  }
1204 
1205  else { // need superscript
1206  string m ( label, 0, pos ); // mantessa
1207  string e ( label, pos + 1 ); // exponent
1208 
1209  if ( m == "1" ) {
1210  m += "0";
1211  x = x - 0.40 * font_size * e.size();
1212  view.drawText ( m, x, y, font_size, angle, xalign, yalign );
1213 
1214  if ( e[0] == '-' ) {
1215  x -= 0.20 * font_size;
1216  }
1217  y = y - 0.625 * font_size;
1218  view.drawText ( e, x, y, 0.9 * font_size, angle, 'l', yalign );
1219  }
1220  else { // m != '1' and need to leave room for label
1221  m += "x10";
1222  x = x - 0.40 * font_size * e.size();
1223  view.drawText (m, x, y, font_size, angle, xalign, yalign );
1224 
1225  if ( e[0] == '-' ) {
1226  x -= 0.20 * font_size;
1227  }
1228  y = y - 0.625 * font_size;
1229  view.drawText ( e, x, y, 0.9 * font_size, angle, 'l', yalign );
1230  }
1231  }
1232 }
1233 
1234 
1235 void
1237 drawYTickLabels ( const std::vector < AxisTick > & ticks,
1238  const std::vector < float > & xv,
1239  const std::vector < float> & yv,
1240  ViewBase & view)
1241 {
1242  char xalign = 'r';
1243  char yalign = 'c';
1244  float angle = 0.;
1245  double font_size = m_y_tick_font_size;
1246 
1247  const string & alabel = ticks[0].content();
1248  string::size_type pos = alabel.find ( 'e' );
1249  bool sci_notate = pos != string::npos;
1250 
1251  if ( sci_notate == false ) {
1252  for ( unsigned int i = 0; i < ticks.size(); i++ ) {
1253  view.drawText ( ticks[i].content(), xv[i], yv[i],
1254  font_size, angle, xalign, yalign );
1255  }
1256  }
1257  else { // need superscript
1258  bool mixed_m = false;
1259  for ( unsigned int i = 0; i < ticks.size (); i++ ) {
1260  const string & label = ticks[i].content ();
1261  string m ( label, 0, pos ); // mantessa
1262  string e ( label, pos + 1 ); // exponent
1263  mixed_m |= m != "1";
1264  }
1265  if ( mixed_m == true ) {
1266  font_size *= 0.90;
1267  }
1268  for ( unsigned int i = 0; i < ticks.size (); i++ ) {
1269  const string & label = ticks[i].content();
1270  string::size_type pos = alabel.find ( 'e' );
1271  string m ( label, 0, pos );
1272  string e ( label, pos + 1 );
1273  if ( m == "1" ) {
1274  m += "0";
1275  float x = xv[i] - 0.40 * font_size * e.size();
1276  view.drawText ( m, x, yv[i], font_size, angle, xalign, yalign );
1277 
1278  if ( e[0] == '-' ) {
1279  x -= 0.20 * font_size;
1280  }
1281  float y = yv[i] - 0.625 * font_size;
1282  view.drawText ( e, x, y, 0.9 * font_size, angle, 'l', yalign );
1283  }
1284  else { // m != '1' and need to leave room for label
1285  m += "x10";
1286  float x = xv[i] - 0.40 * font_size * e.size();
1287  view.drawText (m, x, yv[i], font_size, angle, xalign, yalign );
1288 
1289  if ( e[0] == '-' ) {
1290  x -= 0.20 * font_size;
1291  }
1292  float y = yv[i] - 0.625 * font_size;
1293  view.drawText ( e, x, y, 0.9 * font_size, angle, 'l', yalign );
1294  }
1295  }
1296  }
1297 }
1298 
1299 void
1301 drawCrossHairs ( double x, double y,
1302  TransformBase & tb,
1303  ViewBase & view )
1304 {
1305 
1306  vector < double > xv ( 4 );
1307  vector < double > yv ( 4 );
1308 
1309 
1310  const BinaryTransform & tf
1311  = dynamic_cast< const BinaryTransform & > ( tb );
1312 
1313  if ( tf.isPeriodic() )
1314  {
1315  const PeriodicBinaryTransform & tp
1316  = dynamic_cast < const PeriodicBinaryTransform & > ( tb );
1317 
1318  double xoffset = tp.xOffset();
1319  double yoffset = tp.yOffset();
1320 
1321  x = tp.moduloSubX( x, xoffset );
1322  y = tp.moduloSubY( y, yoffset );
1323  }
1324 
1325  tf.transform ( x,y );
1326 
1327  xv[0] = m_axis_x_origin;
1328  yv[0] = y;
1329 
1330  xv[1] = m_axis_width + m_axis_x_origin;
1331  yv[1] = y;
1332 
1333  xv[2] = x;
1334  yv[2] = m_axis_height + m_axis_y_origin;
1335 
1336  xv[3] = x;
1337  yv[3] = m_axis_y_origin;
1338 
1339  // Note: m_axis_* is already in the transformed system.
1340  Color grey ( 180, 180, 180 );
1341  view.drawLines ( xv, yv, Line::Solid, grey, 0 );
1342 
1343 }
1344 
1349 void
1351 drawAllXTicks ( const AxisModelBase & axisModelX,
1352  const AxisModelBase & axisModelY,
1353  const TransformBase & transform,
1354  ViewBase & view )
1355 {
1356  drawXTickLines ( axisModelX, axisModelY, transform, view );
1357  drawXTickLabels ( axisModelX, axisModelY, transform, view );
1358 }
1359 
1360 void
1362 drawAllYTicks ( const AxisModelBase & axisModelX,
1363  const AxisModelBase & axisModelY,
1364  const TransformBase & transform,
1365  ViewBase & view )
1366 {
1367  drawYTickLines ( axisModelX, axisModelY, transform, view );
1368  drawYTickLabels ( axisModelX, axisModelY, transform, view );
1369 }
1370 
1371 
1373 {
1374  assert( font != 0 );
1375  if( m_xLabelFont == NULL )
1376  m_xLabelFont = font;
1377  else
1378  {
1379  delete m_xLabelFont;
1380  m_xLabelFont = font;
1381  }
1382 }
1383 
1385 {
1386  return m_xLabelFont;
1387 }
1388 
1389 
1391 {
1392  assert( font != 0 );
1393  if( m_yLabelFont == NULL )
1394  m_yLabelFont = font;
1395  else
1396  {
1397  delete m_yLabelFont;
1398  m_yLabelFont = font;
1399  }
1400 }
1401 
1403 {
1404  return m_yLabelFont;
1405 }
1406 
1407 
1409 {
1410  assert( font != 0 );
1411  if( m_zLabelFont == NULL )
1412  m_zLabelFont = font;
1413  else
1414  {
1415  delete m_zLabelFont;
1416  m_zLabelFont = font;
1417  }
1418 }
1419 
1421 {
1422  return m_zLabelFont;
1423 }
1424 
1426 {
1427  assert( font != 0 );
1428  if( m_titleFont == NULL )
1429  m_titleFont = font;
1430  else
1431  {
1432  delete m_titleFont;
1433  m_titleFont = font;
1434  }
1435 }
1436 
1438 {
1439  return m_titleFont;
1440 }
1441 
1442 void
1444 {
1445  assert ( false );
1446 }
double m_z_font_size
Font size for the Z axis label.
Definition: AxisRepBase.h:95
unsigned int i
bool m_draw_titles
The following flag indicates whether the titles have to be drawn or not.
Definition: AxisRepBase.h:111
double m_x_tick_font_size
Font size for the x tick labels.
Definition: AxisRepBase.h:79
float m_axis_x_origin
The x coordinate of the origin of the coordinate system.
Definition: AxisRepBase.h:60
double high() const
Returns the maximum of the range object.
Definition: Range.cxx:100
void initAxisRect(ViewBase &view)
Gets the sizes of the two rectangles (the rectangles of the drawing on the screen) memorized by the V...
Definition: AxisRepBase.cxx:93
A class to maintain tick coordinates and string values.
Definition: AxisTick.h:29
double m_y_font_size
Font size for the Y axis label.
Definition: AxisRepBase.h:91
double m_font_size
Font size for the tick labels.
Definition: AxisRepBase.h:75
double getHeight() const
A shortcut to get size.height.
Definition: Rectangle.cxx:113
A transform that transforms coordinates from one coordinate system to another.
Definition: TransformBase.h:35
double m_x_font_size
Font size for X axis label.
Definition: AxisRepBase.h:87
The base class for the value to the color transformation.
Definition: BinToColor.h:30
virtual void drawLatex(const std::string &eq, int position=0)
Draws a Latex equation.
Definition: ViewBase.cxx:119
size_t ci_find(const string &str1, const string &str2)
Case insensitive find.
virtual void transform(double &x, double &y) const =0
Transform the coordinates on the X and Y axes.
void setYFontSize(const AxisModelBase &axis_model, ViewBase &view)
Calculates the font size for the y axis.
void drawYLabels(const AxisModelBase &axis_model, ViewBase &view, const std::string &y_label)
Draws the labels of the y axis.
hippodraw::PeriodicBinaryTransform class interface
float m_axis_y_origin
The y coordinate of the origin of the coordinate system.
Definition: AxisRepBase.h:65
virtual void drawAllYTicks(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, const TransformBase &transform, ViewBase &view)
This function is the principal function of the ticks drawing family because it draws the ticks on the...
double yOffset() const
Returns the yOffset of the (periodic) transform.
void drawYTickLabels(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, const TransformBase &transform, ViewBase &view)
Draws the labels for the Y ticks.
void setZLabelFont(FontBase *font)
Set the font to be used to override the default while drawing Z label.
void beginPlot(ViewBase &view)
Every class which draws has its beginPlot function.
double xOffset() const
Returns the xOffset of the (periodic) transform.
void setDrawTitles(bool set)
Sets the m_draw_titles flag to the set value.
virtual void drawTitle(ViewBase &view, const std::string &title)
Draws the title.
void drawYMag(const AxisModelBase &axisModel, ViewBase &view, const std::string &mag="")
Draws the Y magnitude label.
hippodraw::AxisRepBase class interface
virtual void drawColorScale(const BinToColor &, ViewBase &)
Draws the color scale bar.
virtual Rect getDrawRect() const =0
Returns the drawing Rectangle in the devices coordinate system.
virtual void drawAllXTicks(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, const TransformBase &transform, ViewBase &view)
This function is the principal function of the ticks drawing family because it draws the ticks on the...
virtual bool needPMag() const
The following functions are used by the AxisRepBase * object.
void drawXTickLines(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, const TransformBase &transform, ViewBase &view)
Draws the X tick lines.
virtual void drawGridLines(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, TransformBase &transform, ViewBase &view)
Draws the grid lines after transformation.
void drawYTickLines(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, const TransformBase &transform, ViewBase &view)
Draws the Y tick lines.
FontBase * m_xLabelFont
The font to be used to for the X label overriding the default font.
Definition: AxisRepBase.h:98
void drawXTickLabels(const AxisModelBase &axisModelX, const AxisModelBase &axisModelY, const TransformBase &transform, ViewBase &view)
Draws the labels for the X ticks.
virtual void drawCrossHairs(double x, double y, TransformBase &transform, ViewBase &view)
Draws the cross hairs after transformation.
The namespace for conversion to string.
FontBase * zLabelFont()
What font is being used to override the default while drawing Z label.
double getWidth() const
A shortcut to get size.width.
Definition: Rectangle.cxx:108
virtual void drawViewLines(const std::vector< double > &x, const std::vector< double > &y, Line::Style style, bool color, float size)=0
Draws multiple line segments.
virtual void drawAxesLines(TransformBase &transform, ViewBase &view, const Range &x_range, const Range &y_range)
Draws the axes lines after transformation.
A abstract base class for font handling.
Definition: FontBase.h:32
virtual float userToDrawX(double x) const =0
Converts a coordinate in user space to drawing space along the X axis.
void drawXMag(const AxisModelBase &axisModel, ViewBase &view, const std::string &mag="")
Draws the X magnitude label.
The abstract base class for views that have a region for drawing data points with area around it for ...
Definition: DataView.h:30
A Color class for creating the color object following the standard RGB color space.
Definition: Color.h:37
void drawXLabels(const AxisModelBase &axis_model, ViewBase &view, const std::string &x_label)
Draws the labels of the x axis.
A Periodic transform that transforms coordinates from one 2D coordinate system to another...
double moduloSubY(double y1, double y2) const
Modulo Subtraction along Y axis.
void setXFontSize(const AxisModelBase &axis_model, ViewBase &view)
Calculates the font size for the x axis.
AxisLoc
The base class for the binner hierarchy.
Definition: AxisLoc.h:17
FontBase * m_zLabelFont
The font to be used to for the Z label overriding the default font.
Definition: AxisRepBase.h:104
void setYLabelFont(FontBase *font)
Set the font to be used to override the default while drawing Y label.
FontBase * yLabelFont()
What font is being used to override the default while drawing Y label.
hippodraw::DataView class interface
stream * mw
Definition: CanvasView.cxx:169
virtual void validate(Range &x, Range &y) const =0
Validates the Ranges.
AxisLoc getScaleLocation() const
intp size(numeric::array arr)
Definition: num_util.cpp:296
Color class interface.
string convert(int i)
Converts an integer to a string.
virtual void drawLines(const std::vector< double > &x, const std::vector< double > &y, Line::Style style, const Color &color, float size)=0
Draws multiple line segments - that is, a line between x0,y0 and x1,y2, another between x2...
The AxisModelBase class maintains the Range and scaling of an axis.
Definition: AxisModelBase.h:33
void setTitleFont(FontBase *font)
Set the font to be used to override the default while drawing title.
void drawXTickLabel(const std::string &label, float x, float y, ViewBase &view)
Draws a tick label for X axis.
Class representing a rectangle.
Definition: Rectangle.h:34
virtual float userToDrawY(double y) const =0
Converts a coordinate in user space to drawing space along the Y axis.
FontBase * m_yLabelFont
The font to be used to for the Y label overriding the default font.
Definition: AxisRepBase.h:101
virtual float userToDrawXAutoInv(double x) const =0
void drawReferencePoint(const AxisModelBase &axisModel, ViewBase &base, const std::string &ref)
Draw the reference point for X or Y axis.
virtual bool isLog() const =0
Returns a boolean describing the type of the scale of the axis.
virtual void setFontSize(const AxisModelBase *x_axis, const AxisModelBase *y_axis, const AxisModelBase *z_axis, ViewBase &view)
Adjusts the font sizes.
The base class for the axis representation hierarchy.
Definition: AxisRepBase.h:49
double m_y_tick_font_size
Font size for the y tick labels.
Definition: AxisRepBase.h:83
virtual ~AxisRepBase()
The virtual destructor.
Definition: AxisRepBase.cxx:83
AxisLoc getLabelLocation() const
The abstract base class for views.
Definition: ViewBase.h:62
const std::vector< AxisTick > & getTicks() const
Returns a reference of generated ticks.
hippodraw::AxisModelBase class interface
void setXLabelFont(FontBase *font)
Set the font to be used to override the default while drawing X label.
virtual void drawText(const std::string &s, float x, float y, float fontsize, float angle=0.0, char xp= 'l', char yp= 't', bool resize=false, const FontBase *font=0, const Color *color=0)=0
Draws a text string at a point in the view&#39;s coordinate system.
float m_axis_width
The width of the rectangle in which the drawing is made.
Definition: AxisRepBase.h:68
double moduloSubX(double x1, double x2) const
Modulo Subtraction along X axis.
double getPMag() const
Returns the magnitude of the power of ten for the tick labels.
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
A transform that transforms coordinates from one 2D coordinate system to another. ...
const Range & getRange(bool scaled) const
Returns the range represented by this AxisModel.
FontBase * titleFont()
What font is being used to override the default while drawing title of plot.
const Rect & getMarginRect() const
Returns the rectangle area in which data points are drawn.
Definition: DataView.cxx:45
double low() const
Returns the minimum of the range object.
Definition: Range.cxx:87
void setZFontSize(const AxisModelBase &axis_model, ViewBase &view)
Calculates the font size for the z axis, if any.
const std::string & content() const
Returns the content at the coordinate.
Definition: AxisTick.cxx:51
virtual int pointSize() const =0
Get the pointsize of the font.
Expresses a range of values.
Definition: Range.h:33
virtual void drawPolyLine(const std::vector< double > &xpoints, const std::vector< double > &ypoints, Line::Style style, const Color &color, float size)=0
Draws a polyline.
FontBase * xLabelFont()
What font is being used to override the default while drawing X label.
float m_axis_height
The height of the rectangle in which the drawing is made.
Definition: AxisRepBase.h:71
bool isPeriodic() const
Sets whether this transform is periodic.
void drawYTickLabel(const std::string &label, float x, float y, ViewBase &view)
Draws the tick label for Y axis.
AxisRepBase()
The default constructor.
Definition: AxisRepBase.cxx:45
double getY() const
A shortcut to get origin.Y.
Definition: Rectangle.h:162
FontBase * m_titleFont
The font to be used to for the Z label overriding the default font.
Definition: AxisRepBase.h:107

Generated for HippoDraw Class Library by doxygen