golib  0.5
goPlot::Graph Class Reference

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)
 
Graphoperator= (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::Object2DPointsaddCurve (const goMatrixd &c)
 Add a new curve to the graph. More...
 
goAutoPtr< goPlot::Object2DImagemakeImage (int width, int height, int format=goPlot::Object2DImage::RGB24)
 Makes a new Object2DImage with the given parameters. More...
 
goAutoPtr< goPlot::Object2DImageaddImage (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::GraphAxisaxis (int i)
 Get a pointer to a specific axis. More...
 
const goAutoPtr< goPlot::GraphAxisaxis (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::Object2DTextaddLabel (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)
 
- Public Member Functions inherited from goPlot::Object2D
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)
 

Protected Member Functions

std::list< goAutoPtr< goPlot::Object2D > > objects2D ()
 

Detailed Description

Graph. Contains multiple Object2D and some axes to be drawn. Can also contain other Graphs.

Constructor & Destructor Documentation

◆ Graph()

Graph::Graph ( int  dim = 2)

Construct a graph (axes).

Construct a graph with axes.

Parameters
dimDimension – currently, only 2 is supported.

Member Function Documentation

◆ add()

void Graph::add ( goAutoPtr< goPlot::Object2D o)

Adds a Object2D to this graph.

Parameters
oThe object pointer (managed by a goAutoPtr)

◆ addCurve()

goAutoPtr< Object2DPoints > Graph::addCurve ( const goMatrixd &  c)

Add a new curve to the graph.

Parameters
cCurve points as configuration matrix (one point per row)
Returns
Pointer to the new Object2DPoints.

◆ addImage()

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.

Parameters
imageThe image to draw.
Returns
Pointer to the new Object2DImage object.

◆ addLabel()

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()).

Parameters
xX position
yY position
labelLabel text
rel_xRelative x movement in units of text width
rel_yRelative y movement in units of text height
Returns
Reference to the new Object2DText

◆ applyAxesTransform()

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.

Parameters
cThe context to apply the transformation to.

◆ axis() [1/2]

goAutoPtr< GraphAxis > Graph::axis ( int  i)

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.

Parameters
iNumber of the axis.
Returns
Pointer to the GraphAxis object.

◆ axis() [2/2]

const goAutoPtr< GraphAxis > Graph::axis ( int  i) const

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.

Parameters
iNumber of the axis.
Returns
Pointer to the GraphAxis object.

◆ dim()

int Graph::dim ( ) const

Number of dimensions (always 2)

Returns
2.

◆ disableAxes()

void Graph::disableAxes ( )

Disables all axes.

This can e.g. be used if you want to use this graph as an image display.

◆ flipY()

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.

◆ makeImage()

goAutoPtr< Object2DImage > Graph::makeImage ( int  width,
int  height,
int  format = goPlot::Object2DImage::RGB24 
)

Makes a new Object2DImage with the given parameters.

Parameters
widthWidth in pixels
heightHeight in pixels
formatFormat, one of Object2DImage::ARGB32, Object2DImage::RGB24, Object2DImage::A8
Returns
Pointer to the new Object2DImage

◆ remove()

void Graph::remove ( goAutoPtr< goPlot::Object2D o)

Removes all occurrences of o in this graph.

Parameters
oObject pointer to remove.

◆ setContext()

void Graph::setContext ( cairo_t *  c)
virtual

Sets the context and hands it on to all axes and drawable objects.

Parameters
cThe context

Reimplemented from goPlot::Object2D.

◆ setDimensions()

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.

Todo:
Setting the tics may not be wanted (rethink this).
Parameters
xminMin x value
xmaxMax x value
yminMin y value
ymaxMax y value

◆ setTicsFont()

void Graph::setTicsFont ( const char *  f)

Set the font for the tics text.

Convenience function that sets the font of all axes to f.

See also
GraphAxis::setTicsFont().
Parameters
fFont description text.

◆ setTitle()

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.

Parameters
tTitle

◆ title()

const char * Graph::title ( ) const

Get the title text.

See also
setTitle()
Returns
The title text

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