Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::TikzWriter Class Reference

LaTeX+TikZ Writer. More...

#include <ogdf/fileformats/TikzWriter.h>

Public Types

enum class  LengthUnit { PT , MM , CM , IN , EX , EM , MU }
 Units of length available in LaTeX. More...
 

Public Member Functions

 TikzWriter (const ClusterGraphAttributes &attr, LengthUnit unit=LengthUnit::MM)
 Construct a new writer for drawing cluster graphs using graph attributes.
 
 TikzWriter (const GraphAttributes &attr, LengthUnit unit=LengthUnit::MM)
 Construct a new writer for drawing graphs using graph attributes.
 
bool draw (std::ostream &os)
 Output the member graph to an output stream in LaTeX+TikZ format.
 

Private Member Functions

double calcArrowSize () const
 Calculates the arrow size to be used for TikZ arrows.
 
void drawAllClusters (std::ostream &os)
 Draws a rectangle for each cluster in the ogdf::ClusterGraph.
 
void drawAllEdges (std::ostream &os)
 Draws a sequence of lines for each edge in the graph.
 
void drawAllNodes (std::ostream &os, bool uniformStyle, bool uniformWidth, bool uniformHeight)
 Draws each node of the graph.
 
void drawCluster (std::ostream &os, cluster c)
 Draws a cluster as a rectangle, using its size and style properties.
 
void drawEdge (std::ostream &os, edge e)
 Draws a sequence of lines for each edge in the graph.
 
void drawNode (std::ostream &os, node v, bool uniformStyle, bool uniformWidth, bool uniformHeight)
 Draws a node using its shape, size and style properties.
 
std::string getClusterStyle (cluster c) const
 Get the style of a cluster in TikZ syntax.
 
std::string getEdgeArrows (edge e) const
 Get the arrows of an edge in TikZ syntax.
 
std::string getEdgeLabel (edge e, const DPoint &previousPoint, const DPoint &labelPoint) const
 Get the label of an edge in TikZ syntax, positioned as a node on the edge path.
 
std::string getEdgeStyle (edge e) const
 Get the style of an edge in TikZ syntax.
 
std::string getLineStyle (StrokeType strokeType, double strokeWidth, Color strokeColor) const
 Convert an ogdf::StrokeType, strokeWidth and ogdf::Color to a a line style string in TikZ syntax.
 
std::string getNodeLabel (node v) const
 Get the label of a node in TikZ syntax.
 
std::string getNodeShape (node v) const
 Get the shape of a node in TikZ syntax.
 
std::string getNodeStyle (node v) const
 Get the style of a node in TikZ syntax.
 
double getTextWidth (node v) const
 Get the total width the node text may occupy.
 
bool isCoveredBy (const DPoint &p, node v) const
 Check whether a point (e.g.
 
std::string texLength (double f) const
 Mainly avoid scientific notation (not handled by LaTeX) and add length unit mm.
 
void wrapHeaderFooter (std::ostream &os, std::string tikzPic, bool uniformStyle, bool uniformWidth, bool uniformHeight) const
 Wrap LaTeX/TikZ header/footer around a tikzpicture and write to output stream.
 

Static Private Member Functions

static std::string getColorString (Color c)
 Convert an ogdf::Color to a string in TikZ syntax.
 

Private Attributes

const GraphAttributesm_attr
 attributes of the graph to be visualized
 
const ClusterGraphAttributesm_clsAttr
 attributes of the cluster graph (nullptr if no cluster graph given)
 
std::vector< std::string > m_edgeStyles
 to avoid as much redundancy as possible, any occurring edge style will be predefined and reused
 
std::vector< std::string > m_nodeStyles
 to avoid as much redundancy as possible, any occurring node style will be predefined and reused
 
LengthUnit m_unit
 The LaTeX unit to use for all ocurring lengths.
 

Detailed Description

LaTeX+TikZ Writer.

Generates and outputs standalone LaTeX documents/graphics using Tikz.

Definition at line 43 of file TikzWriter.h.

Member Enumeration Documentation

◆ LengthUnit

Units of length available in LaTeX.

Enumerator
PT 

0.3515 mm

MM 

a millimeter

CM 

a centimeter

IN 

an inch

EX 

roughly the height of an 'x' (lowercase) in the current font (it depends on the font used)

EM 

roughly the width of an 'M' (uppercase) in the current font (it depends on the font used)

MU 

math unit equal to 1/18 em, where em is taken from the math symbols family

Definition at line 48 of file TikzWriter.h.

Constructor & Destructor Documentation

◆ TikzWriter() [1/2]

ogdf::TikzWriter::TikzWriter ( const GraphAttributes attr,
LengthUnit  unit = LengthUnit::MM 
)
inline

Construct a new writer for drawing graphs using graph attributes.

Parameters
attrthe attributes of the graph to draw
unitthe unit to use for LaTeX lengths

Definition at line 64 of file TikzWriter.h.

◆ TikzWriter() [2/2]

ogdf::TikzWriter::TikzWriter ( const ClusterGraphAttributes attr,
LengthUnit  unit = LengthUnit::MM 
)
inline

Construct a new writer for drawing cluster graphs using graph attributes.

Parameters
attrthe attributes of the cluster graph to draw
unitthe unit to use for LaTeX lengths

Definition at line 73 of file TikzWriter.h.

Member Function Documentation

◆ calcArrowSize()

double ogdf::TikzWriter::calcArrowSize ( ) const
private

Calculates the arrow size to be used for TikZ arrows.

Returns
double

◆ draw()

bool ogdf::TikzWriter::draw ( std::ostream &  os)

Output the member graph to an output stream in LaTeX+TikZ format.

Parameters
osoutput stream
Returns
true iff successfull

◆ drawAllClusters()

void ogdf::TikzWriter::drawAllClusters ( std::ostream &  os)
private

Draws a rectangle for each cluster in the ogdf::ClusterGraph.

Parameters
osoutput stream

◆ drawAllEdges()

void ogdf::TikzWriter::drawAllEdges ( std::ostream &  os)
private

Draws a sequence of lines for each edge in the graph.

Parameters
osoutput stream

◆ drawAllNodes()

void ogdf::TikzWriter::drawAllNodes ( std::ostream &  os,
bool  uniformStyle,
bool  uniformWidth,
bool  uniformHeight 
)
private

Draws each node of the graph.

Parameters
osoutput stream
uniformStylewhether not to set style per node
uniformWidthwhether not to set width per node
uniformHeightwhether not to set height per node

◆ drawCluster()

void ogdf::TikzWriter::drawCluster ( std::ostream &  os,
cluster  c 
)
private

Draws a cluster as a rectangle, using its size and style properties.

Parameters
osoutput stream
ccluster to draw

◆ drawEdge()

void ogdf::TikzWriter::drawEdge ( std::ostream &  os,
edge  e 
)
private

Draws a sequence of lines for each edge in the graph.

Parameters
osoutput stream
eedge to draw

◆ drawNode()

void ogdf::TikzWriter::drawNode ( std::ostream &  os,
node  v,
bool  uniformStyle,
bool  uniformWidth,
bool  uniformHeight 
)
private

Draws a node using its shape, size and style properties.

Parameters
osoutput stream
vnode to draw
uniformStylewhether not to set style per node
uniformWidthwhether not to set width per node
uniformHeightwhether not to set height per node

◆ getClusterStyle()

std::string ogdf::TikzWriter::getClusterStyle ( cluster  c) const
private

Get the style of a cluster in TikZ syntax.

Parameters
ccluster
Returns
std::string style of c in TikZ syntax

◆ getColorString()

static std::string ogdf::TikzWriter::getColorString ( Color  c)
staticprivate

Convert an ogdf::Color to a string in TikZ syntax.

Parameters
ccolor
Returns
std::string c in TikZ syntax

◆ getEdgeArrows()

std::string ogdf::TikzWriter::getEdgeArrows ( edge  e) const
private

Get the arrows of an edge in TikZ syntax.

Parameters
eedge
Returns
std::string arrows of e in TikZ syntax

◆ getEdgeLabel()

std::string ogdf::TikzWriter::getEdgeLabel ( edge  e,
const DPoint previousPoint,
const DPoint labelPoint 
) const
private

Get the label of an edge in TikZ syntax, positioned as a node on the edge path.

Parameters
eedge
previousPointprevious point on edge path
labelPointwhere to put the edge label
Returns
std::string label of e in TikZ syntax

◆ getEdgeStyle()

std::string ogdf::TikzWriter::getEdgeStyle ( edge  e) const
private

Get the style of an edge in TikZ syntax.

Parameters
eedge
Returns
std::string style of e in TikZ syntax

◆ getLineStyle()

std::string ogdf::TikzWriter::getLineStyle ( StrokeType  strokeType,
double  strokeWidth,
Color  strokeColor 
) const
private

Convert an ogdf::StrokeType, strokeWidth and ogdf::Color to a a line style string in TikZ syntax.

Parameters
strokeTypestroke type
strokeWidthstroke width
strokeColorstroke color
Returns
std::string line style in TikZ syntax

◆ getNodeLabel()

std::string ogdf::TikzWriter::getNodeLabel ( node  v) const
private

Get the label of a node in TikZ syntax.

Parameters
vnode
Returns
std::string label of v in TikZ syntax

◆ getNodeShape()

std::string ogdf::TikzWriter::getNodeShape ( node  v) const
private

Get the shape of a node in TikZ syntax.

Parameters
vnode
Returns
std::string shape of v in TikZ syntax

◆ getNodeStyle()

std::string ogdf::TikzWriter::getNodeStyle ( node  v) const
private

Get the style of a node in TikZ syntax.

Parameters
vnode
Returns
std::string style of v in TikZ syntax

◆ getTextWidth()

double ogdf::TikzWriter::getTextWidth ( node  v) const
private

Get the total width the node text may occupy.

Parameters
vnode
Returns
double width that may be occupied by label text for node v

◆ isCoveredBy()

bool ogdf::TikzWriter::isCoveredBy ( const DPoint p,
node  v 
) const
private

Check whether a point (e.g.

edge bend point) lies within a node (using node shapes with same size and aspect as in TikZ).

Parameters
ppoint to check
vnode to check
Returns
true iff lies within the border of v

◆ texLength()

std::string ogdf::TikzWriter::texLength ( double  f) const
private

Mainly avoid scientific notation (not handled by LaTeX) and add length unit mm.

Parameters
ffloating point number
Returns
std::string f in mm as formatted string

◆ wrapHeaderFooter()

void ogdf::TikzWriter::wrapHeaderFooter ( std::ostream &  os,
std::string  tikzPic,
bool  uniformStyle,
bool  uniformWidth,
bool  uniformHeight 
) const
private

Wrap LaTeX/TikZ header/footer around a tikzpicture and write to output stream.

Parameters
osoutput stream
tikzPicthe content of the tikzPicture
uniformStylewhether not to set style per node
uniformWidthwhether not to set width per node
uniformHeightwhether not to set height per node

Member Data Documentation

◆ m_attr

const GraphAttributes& ogdf::TikzWriter::m_attr
private

attributes of the graph to be visualized

Definition at line 258 of file TikzWriter.h.

◆ m_clsAttr

const ClusterGraphAttributes* ogdf::TikzWriter::m_clsAttr
private

attributes of the cluster graph (nullptr if no cluster graph given)

Definition at line 261 of file TikzWriter.h.

◆ m_edgeStyles

std::vector<std::string> ogdf::TikzWriter::m_edgeStyles
private

to avoid as much redundancy as possible, any occurring edge style will be predefined and reused

Definition at line 270 of file TikzWriter.h.

◆ m_nodeStyles

std::vector<std::string> ogdf::TikzWriter::m_nodeStyles
private

to avoid as much redundancy as possible, any occurring node style will be predefined and reused

Definition at line 267 of file TikzWriter.h.

◆ m_unit

LengthUnit ogdf::TikzWriter::m_unit
private

The LaTeX unit to use for all ocurring lengths.

Definition at line 264 of file TikzWriter.h.


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