golib  0.5
goPlot::GraphAxis Class Reference

Axis. More...

#include <graphaxis.h>

Public Types

enum  Conf {
  POS_MASK = 7, BOTTOM = 1, LEFT = 2, TOP = 3,
  RIGHT = 4, MIDDLE = 1 << 4, TICS = 1 << 5, TICS_TEXT = 1 << 6,
  VISIBLE = 1 << 7
}
 

Public Member Functions

 GraphAxis (int index=0, double l=0.0, double u=1.0)
 Constructor. More...
 
double length ()
 Returns the length of the axis (upper end - lower end). More...
 
real x () const
 x position of this axis. Only used by configure () so far, will be removed. @deprecate More...
 
real y () const
 y position of this axis. Only used by configure () so far, will be removed. @deprecate More...
 
void setPosition (real x, real y)
 Sets position of axis. Only used by configure () so far, will be removed. @deprecate. More...
 
const char * ticsFont () const
 Get the tics font (as a descriptive string). More...
 
void setTicsFont (const char *f)
 Set font for tics text. More...
 
bool visible () const
 Check visibility. More...
 
void setVisible (bool v)
 Set visibility. More...
 
void configure (int c)
 Set the axis configuration. More...
 
int configuration () const
 Get the configuration. More...
 
void enableTics (bool f)
 Sets or blanks tics flag. More...
 
void enableTicsText (bool f)
 Sets or blanks the tics text flag. More...
 
virtual void draw ()
 Draws the axis and tics and tics texts according to flags. More...
 
void drawTics (cairo_t *cr)
 Draws tics. More...
 
double lower () const
 Get the lower end of range of this axis. More...
 
double upper () const
 Get the upper end of range of this axis. More...
 
void setLower (double l)
 Set the lower end of range of this axis. More...
 
void setUpper (double u)
 Set the upper end of range of this axis. More...
 
int index () const
 Get the index of this axis. More...
 
void setIndex (int i)
 Set the index of this axis. More...
 
void setTics (const std::vector< real > &t)
 Set a vector of tics. More...
 
void setTics (real start, real step, real end)
 Set tics using the given range. More...
 
void setTics (int count=10)
 Set a certain amounf of equally spaced tics. More...
 
void updateTicsText ()
 Updates the texts for all tics of this axis. More...
 
void drawTicsText ()
 Draws the tics texts.
 
void getTicsTextPathExtents (double &x1, double &y1, double &x2, double &y2)
 Finds out the extents of the tics. More...
 
void getBorderHint (double w, double h, double &x1, double &y1, double &x2, double &y2)
 Tries to figure out how much border is needed to display the text at the tics of the axes. Assuming currently that the axes are drawn at left and bottom. More...
 
- Public Member Functions inherited from goPlot::Object2DPoints
 Object2DPoints (size_t N=1)
 
 Object2DPoints (goAutoPtr< Points2D > p)
 
void setPoints (goAutoPtr< Points2D > p)
 
Points2Dpoints ()
 
const Points2Dpoints () const
 
LineTraitslineTraits ()
 
const LineTraitslineTraits () const
 
- Public Member Functions inherited from goPlot::Object2D
virtual void setContext (cairo_t *c)
 
const Trafo2Dtransform () const
 
void setTransform (const Trafo2D &T)
 
cairo_t * context ()
 
const cairo_t * context () const
 
bool visible () const
 
void setVisible (bool t)
 
void applyTransform (cairo_t *cr)
 

Detailed Description

Axis.

Constructor & Destructor Documentation

◆ GraphAxis()

goPlot::GraphAxis::GraphAxis ( int  index = 0,
double  l = 0.0,
double  u = 1.0 
)

Constructor.

Makes an axis extending from l to \u. The index indicates which axis it is — in 2D, 0 indicates the x axis, 1 indicates the y axis. If, for example, you want to make a graph for a sine function in the range from 0 to 2 pi, you can set axis 0 to l = 0 and u = 2 * M_PI, and axis 1 to l = -1 and u = 1.

Parameters
indexThis axis' index
lLower end of range
uUpper end of range

Member Function Documentation

◆ configuration()

int goPlot::GraphAxis::configuration ( ) const

Get the configuration.

See also
configure()
Returns
Configuration

◆ configure()

void goPlot::GraphAxis::configure ( int  c)

Set the axis configuration.

Note
It is better to use setVisible(), enableTics(), enableTicsText(). 4 axes are configured when a Graph is constructed; fiddling should not be necessary.
Todo:
Replace this or leave it?
  • TICS: Sets if tics are drawn
  • TICS_TEXT: Sets if tic texts are drawn
  • MIDDLE: Axis will be positioned in the middle (this may be removed in the future)
  • VISIBLE: Switches visibility
Parameters
cOne position out of {BOTTOM, LEFT, TOP, RIGHT} or'ed with {MIDDLE, TICS, TICS_TEXT}.

◆ draw()

void goPlot::GraphAxis::draw ( )
virtual

Draws the axis and tics and tics texts according to flags.

See also
enableTicsText(), enableTics()

Reimplemented from goPlot::Object2DPoints.

◆ drawTics()

void goPlot::GraphAxis::drawTics ( cairo_t *  cr)

Draws tics.

Parameters
crCairo context

◆ enableTics()

void goPlot::GraphAxis::enableTics ( bool  f)

Sets or blanks tics flag.

Parameters
fIf true, tics flag will be set and tics will be drawn. If false, the opposite will happen.

◆ enableTicsText()

void goPlot::GraphAxis::enableTicsText ( bool  f)

Sets or blanks the tics text flag.

Parameters
fIf true, the flag will be set and tics texts will be drawn. If false, the opposite will happen.

◆ getBorderHint()

void goPlot::GraphAxis::getBorderHint ( double  w,
double  h,
double &  x1,
double &  y1,
double &  x2,
double &  y2 
)

Tries to figure out how much border is needed to display the text at the tics of the axes. Assuming currently that the axes are drawn at left and bottom.

Parameters
wWidth of window
hHeight of window
x1Border at left
y1Border at top
x2Border at right
y2Border at bottom

◆ getTicsTextPathExtents()

void goPlot::GraphAxis::getTicsTextPathExtents ( double &  x1,
double &  y1,
double &  x2,
double &  y2 
)

Finds out the extents of the tics.

Used by getBorderHint() to find out how much space should be left around the axis.

If I am not mistaken, the extents should be returned in device coordinates.

Parameters
x1Border at left
y1Border at top
x2Border at right
y2Border at bottom

◆ index()

int goPlot::GraphAxis::index ( ) const

Get the index of this axis.

0 corresponds to x axis, 1 to y axis, 2 to the upper x axis, 3 to the right y axis.

Returns
Axis index

◆ length()

double goPlot::GraphAxis::length ( )

Returns the length of the axis (upper end - lower end).

Returns
Length of this axis

◆ lower()

double goPlot::GraphAxis::lower ( ) const

Get the lower end of range of this axis.

Returns
Lower end of range of this axis

◆ setIndex()

void goPlot::GraphAxis::setIndex ( int  i)

Set the index of this axis.

See also
index()

Sets the index and configures this axis accordingly by calling configure().

Parameters
iThis axis' index.

◆ setLower()

void goPlot::GraphAxis::setLower ( double  l)

Set the lower end of range of this axis.

Parameters
lLower end of range

◆ setPosition()

void goPlot::GraphAxis::setPosition ( real  x,
real  y 
)

Sets position of axis. Only used by configure () so far, will be removed. @deprecate.

Parameters
xX position in (0,1)
yY position in (0,1)

◆ setTics() [1/3]

void goPlot::GraphAxis::setTics ( const std::vector< real > &  t)

Set a vector of tics.

The tics must be in the range of [this->lower(), this->upper()] and indicate the positions at which to draw tics if the the tics flag is enabled with enableTics().

Parameters
tVector of tics positions

◆ setTics() [2/3]

void goPlot::GraphAxis::setTics ( int  count = 10)

Set a certain amounf of equally spaced tics.

Calls setTics(real start, real step, real end) to set count tics on this axis.

Parameters
countNumber of tics to set

◆ setTics() [3/3]

void goPlot::GraphAxis::setTics ( real  start,
real  step,
real  end 
)

Set tics using the given range.

See also
setTics(const std::vector<real>& t)

Sets tics from start, using step, up to end (inclusive, if end is reached exactly). Calls setTics(const std::vector<real>& t).

Parameters
startStart of range
stepStep width
endEnd of range

◆ setTicsFont()

void goPlot::GraphAxis::setTicsFont ( const char *  f)

Set font for tics text.

The font description is a string given to pango. The default is "sans normal light 7". See description of pango_font_description_from_string () here.

Parameters
fString describing the font.

◆ setUpper()

void goPlot::GraphAxis::setUpper ( double  u)

Set the upper end of range of this axis.

Parameters
lUpper end of range

◆ setVisible()

void goPlot::GraphAxis::setVisible ( bool  v)

Set visibility.

Parameters
vIf true, axis is visible, if false, axis is invisible.

◆ ticsFont()

const char * goPlot::GraphAxis::ticsFont ( ) const

Get the tics font (as a descriptive string).

See also
setTicsFont()
Returns
const char* to the font description string.

◆ updateTicsText()

void goPlot::GraphAxis::updateTicsText ( )

Updates the texts for all tics of this axis.

Todo:
Add variable precision

If the tics have been set newly, this is called by the setTics() methods in order to get the tics texts right.

◆ upper()

double goPlot::GraphAxis::upper ( ) const

Get the upper end of range of this axis.

Returns
Upper end of range of this axis

◆ visible()

bool goPlot::GraphAxis::visible ( ) const

Check visibility.

Returns
True if axis is visible, false otherwise.

◆ x()

real goPlot::GraphAxis::x ( ) const

x position of this axis. Only used by configure () so far, will be removed. @deprecate

Returns
x position of this axis

◆ y()

real goPlot::GraphAxis::y ( ) const

y position of this axis. Only used by configure () so far, will be removed. @deprecate

Returns
y position of this axis

The documentation for this class was generated from the following files: