golib
0.5
|
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... | |
![]() | |
Object2DPoints (size_t N=1) | |
Object2DPoints (goAutoPtr< Points2D > p) | |
void | setPoints (goAutoPtr< Points2D > p) |
Points2D & | points () |
const Points2D & | points () const |
LineTraits & | lineTraits () |
const LineTraits & | lineTraits () const |
![]() | |
virtual void | setContext (cairo_t *c) |
const Trafo2D & | transform () 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) |
Axis.
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.
index | This axis' index |
l | Lower end of range |
u | Upper end of range |
int goPlot::GraphAxis::configuration | ( | ) | const |
void goPlot::GraphAxis::configure | ( | int | c | ) |
Set the axis configuration.
c | One position out of {BOTTOM, LEFT, TOP, RIGHT} or'ed with {MIDDLE, TICS, TICS_TEXT}. |
|
virtual |
Draws the axis and tics and tics texts according to flags.
Reimplemented from goPlot::Object2DPoints.
void goPlot::GraphAxis::drawTics | ( | cairo_t * | cr | ) |
Draws tics.
cr | Cairo context |
void goPlot::GraphAxis::enableTics | ( | bool | f | ) |
Sets or blanks tics flag.
f | If true, tics flag will be set and tics will be drawn. If false, the opposite will happen. |
void goPlot::GraphAxis::enableTicsText | ( | bool | f | ) |
Sets or blanks the tics text flag.
f | If true, the flag will be set and tics texts will be drawn. If false, the opposite will happen. |
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.
w | Width of window |
h | Height of window |
x1 | Border at left |
y1 | Border at top |
x2 | Border at right |
y2 | Border at bottom |
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.
x1 | Border at left |
y1 | Border at top |
x2 | Border at right |
y2 | Border at bottom |
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.
double goPlot::GraphAxis::length | ( | ) |
Returns the length of the axis (upper end - lower end).
double goPlot::GraphAxis::lower | ( | ) | const |
Get the lower end of range of this axis.
void goPlot::GraphAxis::setIndex | ( | int | i | ) |
Set the index of this axis.
Sets the index and configures this axis accordingly by calling configure().
i | This axis' index. |
void goPlot::GraphAxis::setLower | ( | double | l | ) |
Set the lower end of range of this axis.
l | Lower end of range |
void goPlot::GraphAxis::setPosition | ( | real | x, |
real | y | ||
) |
Sets position of axis. Only used by configure () so far, will be removed. @deprecate.
x | X position in (0,1) |
y | Y position in (0,1) |
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().
t | Vector of tics positions |
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.
count | Number of tics to set |
void goPlot::GraphAxis::setTics | ( | real | start, |
real | step, | ||
real | end | ||
) |
Set tics using the given range.
Sets tics from start, using step, up to end (inclusive, if end is reached exactly). Calls setTics(const std::vector<real>& t).
start | Start of range |
step | Step width |
end | End of range |
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.
f | String describing the font. |
void goPlot::GraphAxis::setUpper | ( | double | u | ) |
Set the upper end of range of this axis.
l | Upper end of range |
void goPlot::GraphAxis::setVisible | ( | bool | v | ) |
Set visibility.
v | If true, axis is visible, if false, axis is invisible. |
const char * goPlot::GraphAxis::ticsFont | ( | ) | const |
Get the tics font (as a descriptive string).
void goPlot::GraphAxis::updateTicsText | ( | ) |
double goPlot::GraphAxis::upper | ( | ) | const |
Get the upper end of range of this axis.
bool goPlot::GraphAxis::visible | ( | ) | const |
Check visibility.
real goPlot::GraphAxis::x | ( | ) | const |
x position of this axis. Only used by configure () so far, will be removed. @deprecate
real goPlot::GraphAxis::y | ( | ) | const |
y position of this axis. Only used by configure () so far, will be removed. @deprecate