Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

TikzWriter.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/geometry.h>
36 #include <ogdf/basic/graphics.h>
39 
40 #include <iosfwd>
41 #include <string>
42 #include <vector>
43 
44 namespace ogdf {
45 class GraphAttributes;
46 
52 class TikzWriter {
53 public:
57  enum class LengthUnit {
58  PT,
59  MM,
60  CM,
61  IN,
62  EX,
63  EM,
64  MU
65  };
66 
74  : m_attr(attr), m_clsAttr(nullptr), m_unit(unit), m_nodeStyles(), m_edgeStyles() { }
75 
83  : m_attr(attr), m_clsAttr(&attr), m_unit(unit), m_nodeStyles(), m_edgeStyles() { }
84 
91  bool draw(std::ostream& os);
92 
93 private:
103  void wrapHeaderFooter(std::ostream& os, std::string tikzPic, bool uniformStyle,
104  bool uniformWidth, bool uniformHeight) const;
105 
111  void drawAllClusters(std::ostream& os);
112 
121  void drawAllNodes(std::ostream& os, bool uniformStyle, bool uniformWidth, bool uniformHeight);
122 
128  void drawAllEdges(std::ostream& os);
129 
136  void drawCluster(std::ostream& os, cluster c);
137 
147  void drawNode(std::ostream& os, node v, bool uniformStyle, bool uniformWidth, bool uniformHeight);
148 
155  void drawEdge(std::ostream& os, edge e);
156 
163  std::string getClusterStyle(cluster c) const;
164 
171  std::string getNodeShape(node v) const;
172 
179  std::string getNodeStyle(node v) const;
180 
187  std::string getNodeLabel(node v) const;
188 
195  double getTextWidth(node v) const;
196 
203  std::string getEdgeStyle(edge e) const;
204 
211  std::string getEdgeArrows(edge e) const;
212 
221  std::string getEdgeLabel(edge e, const DPoint& previousPoint, const DPoint& labelPoint) const;
222 
228  double calcArrowSize() const;
229 
236  std::string texLength(double f) const;
237 
246  std::string getLineStyle(StrokeType strokeType, double strokeWidth, Color strokeColor) const;
247 
254  static std::string getColorString(Color c);
255 
258 
261 
264 
266  std::vector<std::string> m_nodeStyles;
267 
269  std::vector<std::string> m_edgeStyles;
270 };
271 
272 }
ogdf::Color
Colors represented as RGBA values.
Definition: graphics.h:164
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
Graph.h
Includes declaration of graph class.
ogdf::GenericPoint< double >
graphics.h
Declaration of basic types for graphics.
ogdf::StrokeType
StrokeType
Line types of strokes.
Definition: graphics.h:50
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::TikzWriter::drawAllEdges
void drawAllEdges(std::ostream &os)
Draws a sequence of lines for each edge in the graph.
ogdf::TikzWriter::wrapHeaderFooter
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.
ogdf::TikzWriter::m_unit
LengthUnit m_unit
The LaTeX unit to use for all ocurring lengths.
Definition: TikzWriter.h:263
ogdf::TikzWriter
LaTeX+TikZ Writer.
Definition: TikzWriter.h:52
ogdf::TikzWriter::getTextWidth
double getTextWidth(node v) const
Get the total width the node text may occupy.
ogdf::TikzWriter::LengthUnit::MU
@ MU
math unit equal to 1/18 em, where em is taken from the math symbols family
ogdf::TikzWriter::m_nodeStyles
std::vector< std::string > m_nodeStyles
to avoid as much redundancy as possible, any occurring node style will be predefined and reused
Definition: TikzWriter.h:266
ogdf::TikzWriter::m_clsAttr
const ClusterGraphAttributes * m_clsAttr
attributes of the cluster graph (nullptr if no cluster graph given)
Definition: TikzWriter.h:260
ogdf::TikzWriter::m_edgeStyles
std::vector< std::string > m_edgeStyles
to avoid as much redundancy as possible, any occurring edge style will be predefined and reused
Definition: TikzWriter.h:269
ogdf::TikzWriter::LengthUnit::EM
@ EM
roughly the width of an 'M' (uppercase) in the current font (it depends on the font used)
ogdf::TikzWriter::LengthUnit::CM
@ CM
a centimeter
ogdf::TikzWriter::getEdgeLabel
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.
ogdf::TikzWriter::getEdgeArrows
std::string getEdgeArrows(edge e) const
Get the arrows of an edge in TikZ syntax.
ogdf::TikzWriter::draw
bool draw(std::ostream &os)
Output the member graph to an output stream in LaTeX+TikZ format.
ogdf::TikzWriter::drawAllNodes
void drawAllNodes(std::ostream &os, bool uniformStyle, bool uniformWidth, bool uniformHeight)
Draws each node of the graph.
ogdf::TikzWriter::getNodeStyle
std::string getNodeStyle(node v) const
Get the style of a node in TikZ syntax.
ogdf::TikzWriter::texLength
std::string texLength(double f) const
Mainly avoid scientific notation (not handled by LaTeX) and add length unit mm.
ogdf::TikzWriter::LengthUnit::PT
@ PT
0.3515 mm
ogdf::ClusterElement
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:62
ogdf::ClusterGraphAttributes
Stores additional attributes of a clustered graph (like layout information).
Definition: ClusterGraphAttributes.h:52
ogdf::TikzWriter::LengthUnit
LengthUnit
Units of length available in LaTeX.
Definition: TikzWriter.h:57
ogdf::TikzWriter::getColorString
static std::string getColorString(Color c)
Convert an ogdf::Color to a string in TikZ syntax.
ogdf::TikzWriter::calcArrowSize
double calcArrowSize() const
Calculates the arrow size to be used for TikZ arrows.
ogdf::TikzWriter::drawNode
void drawNode(std::ostream &os, node v, bool uniformStyle, bool uniformWidth, bool uniformHeight)
Draws a node using its shape, size and style properties.
ogdf::TikzWriter::TikzWriter
TikzWriter(const GraphAttributes &attr, LengthUnit unit=LengthUnit::MM)
Construct a new writer for drawing graphs using graph attributes.
Definition: TikzWriter.h:73
ogdf::TikzWriter::m_attr
const GraphAttributes & m_attr
attributes of the graph to be visualized
Definition: TikzWriter.h:257
ogdf::TikzWriter::TikzWriter
TikzWriter(const ClusterGraphAttributes &attr, LengthUnit unit=LengthUnit::MM)
Construct a new writer for drawing cluster graphs using graph attributes.
Definition: TikzWriter.h:82
ogdf::TikzWriter::getNodeShape
std::string getNodeShape(node v) const
Get the shape of a node in TikZ syntax.
ogdf::TikzWriter::getEdgeStyle
std::string getEdgeStyle(edge e) const
Get the style of an edge in TikZ syntax.
ogdf::TikzWriter::drawAllClusters
void drawAllClusters(std::ostream &os)
Draws a rectangle for each cluster in the ogdf::ClusterGraph.
ogdf::TikzWriter::drawCluster
void drawCluster(std::ostream &os, cluster c)
Draws a cluster as a rectangle, using its size and style properties.
ogdf::TikzWriter::LengthUnit::EX
@ EX
roughly the height of an 'x' (lowercase) in the current font (it depends on the font used)
ogdf::TikzWriter::getLineStyle
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.
ClusterGraphAttributes.h
Declares ClusterGraphAttributes, an extension of class GraphAttributes, to store clustergraph layout ...
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ClusterGraph.h
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
ogdf::TikzWriter::LengthUnit::MM
@ MM
a millimeter
ogdf::TikzWriter::getClusterStyle
std::string getClusterStyle(cluster c) const
Get the style of a cluster in TikZ syntax.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::TikzWriter::LengthUnit::IN
@ IN
an inch
ogdf::TikzWriter::drawEdge
void drawEdge(std::ostream &os, edge e)
Draws a sequence of lines for each edge in the graph.
ogdf::TikzWriter::getNodeLabel
std::string getNodeLabel(node v) const
Get the label of a node in TikZ syntax.