golib
0.5
|
Graph. Contains multiple Object2D and some axes to be drawn. Can also contain other Graphs. More...
#include <graph.h>
Public Member Functions | |
Graph (int dim=2) | |
Construct a graph (axes). More... | |
Graph (const Graph &other) | |
Graph & | operator= (const Graph &other) |
void | disableAxes () |
Disables all axes. More... | |
void | flipY () |
Multiply the current transformation so that the Y axis is mirrored. More... | |
void | clear () |
Removes all objects. | |
goAutoPtr< goPlot::Object2DPoints > | addCurve (const goMatrixd &c) |
Add a new curve to the graph. More... | |
goAutoPtr< goPlot::Object2DImage > | makeImage (int width, int height, int format=goPlot::Object2DImage::RGB24) |
Makes a new Object2DImage with the given parameters. More... | |
goAutoPtr< goPlot::Object2DImage > | addImage (const goSignal3DBase< void > &image) |
Adds an image to the graph. More... | |
void | setDimensions (goPlot::real xmin, goPlot::real xmax, goPlot::real ymin, goPlot::real ymax) |
Set the dimensions of this graph's axes. More... | |
void | setTicsFont (const char *f) |
Set the font for the tics text. More... | |
int | dim () const |
Number of dimensions (always 2) More... | |
goAutoPtr< goPlot::GraphAxis > | axis (int i) |
Get a pointer to a specific axis. More... | |
const goAutoPtr< goPlot::GraphAxis > | axis (int i) const |
Get a pointer to a specific axis. More... | |
void | add (goAutoPtr< goPlot::Object2D > o) |
Adds a Object2D to this graph. More... | |
void | remove (goAutoPtr< goPlot::Object2D > o) |
Removes all occurrences of o in this graph. More... | |
void | setTitle (const char *t) |
Sets the title of the graph. More... | |
const char * | title () const |
Get the title text. More... | |
goPlot::Object2DText & | addLabel (double x, double y, const char *label, double rel_x=0.0, double rel_y=0.0) |
Adds a text label. More... | |
virtual void | setContext (cairo_t *c) |
Sets the context and hands it on to all axes and drawable objects. More... | |
void | applyAxesTransform (cairo_t *c) |
Applies the transform given by the current axes to the given context. More... | |
virtual void | draw () |
Draws axes (according to their visibilities) and all objects. | |
void | getBorderHint (double w, double h, double &x1, double &y1, double &x2, double &y2) |
![]() | |
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) |
Protected Member Functions | |
std::list< goAutoPtr< goPlot::Object2D > > | objects2D () |
Graph::Graph | ( | int | dim = 2 | ) |
Construct a graph (axes).
Construct a graph with axes.
dim | Dimension – currently, only 2 is supported. |
void Graph::add | ( | goAutoPtr< goPlot::Object2D > | o | ) |
goAutoPtr< Object2DPoints > Graph::addCurve | ( | const goMatrixd & | c | ) |
Add a new curve to the graph.
c | Curve points as configuration matrix (one point per row) |
goAutoPtr< Object2DImage > Graph::addImage | ( | const goSignal3DBase< void > & | image | ) |
Adds an image to the graph.
You may want to adjust the transformation so that the image fits in the graph.
image | The image to draw. |
Object2DText & Graph::addLabel | ( | double | x, |
double | y, | ||
const char * | label, | ||
double | rel_x = 0.0 , |
||
double | rel_y = 0.0 |
||
) |
Adds a text label.
Convenience function that creates a Object2DText and calls add().
rel_x
and rel_y
can be used to align the label (see Object2DText::setPosition()).
x | X position |
y | Y position |
label | Label text |
rel_x | Relative x movement in units of text width |
rel_y | Relative y movement in units of text height |
void Graph::applyAxesTransform | ( | cairo_t * | c | ) |
Applies the transform given by the current axes to the given context.
This is called by draw() and probably does not need to be called by the user.
c | The context to apply the transformation to. |
Get a pointer to a specific axis.
Valid numbers are {0,1,2,3}. 0,1 are the x,y axes, 2 is the upper x axis, 3 is the right y axis.
i | Number of the axis. |
Get a pointer to a specific axis.
Valid numbers are {0,1,2,3}. 0,1 are the x,y axes, 2 is the upper x axis, 3 is the right y axis.
i | Number of the axis. |
int Graph::dim | ( | ) | const |
Number of dimensions (always 2)
void Graph::disableAxes | ( | ) |
Disables all axes.
This can e.g. be used if you want to use this graph as an image display.
void Graph::flipY | ( | ) |
Multiply the current transformation so that the Y axis is mirrored.
Useful if displaying an image which starts in the upper left corner.
goAutoPtr< Object2DImage > Graph::makeImage | ( | int | width, |
int | height, | ||
int | format = goPlot::Object2DImage::RGB24 |
||
) |
Makes a new Object2DImage with the given parameters.
width | Width in pixels |
height | Height in pixels |
format | Format, one of Object2DImage::ARGB32, Object2DImage::RGB24, Object2DImage::A8 |
void Graph::remove | ( | goAutoPtr< goPlot::Object2D > | o | ) |
Removes all occurrences of o
in this graph.
o | Object pointer to remove. |
|
virtual |
Sets the context and hands it on to all axes and drawable objects.
c | The context |
Reimplemented from goPlot::Object2D.
void Graph::setDimensions | ( | goPlot::real | xmin, |
goPlot::real | xmax, | ||
goPlot::real | ymin, | ||
goPlot::real | ymax | ||
) |
Set the dimensions of this graph's axes.
Convenience functions calling setLower and setUpper of all axes. Also sets the tics to 10 tics on each axis.
The default value range for the axes is [0,1]. Note that these dimensions define the "size" of the graph, that means the actual value range is in the given range. So if, for example, you want an object to fill the graph, you should scale it via its own transformation to the range given by the parameters to setDimensions.
xmin | Min x value |
xmax | Max x value |
ymin | Min y value |
ymax | Max y value |
void Graph::setTicsFont | ( | const char * | f | ) |
Set the font for the tics text.
Convenience function that sets the font of all axes to f
.
f | Font description text. |
void Graph::setTitle | ( | const char * | t | ) |
Sets the title of the graph.
The title is not drawn by the Graph::draw() method. It is only stored here and should be drawn by the class arranging and plotting the graphs.
t | Title |
const char * Graph::title | ( | ) | const |