Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
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
44namespace ogdf {
45class GraphAttributes;
46
53public:
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
84
91 bool draw(std::ostream& os);
92
93private:
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}
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Declares ClusterGraphAttributes, an extension of class GraphAttributes, to store clustergraph layout ...
Includes declaration of graph class.
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
Representation of clusters in a clustered graph.
Stores additional attributes of a clustered graph (like layout information).
Colors represented as RGBA values.
Definition graphics.h:164
Class for the representation of edges.
Definition Graph_d.h:364
Stores additional attributes of a graph (like layout information).
Class for the representation of nodes.
Definition Graph_d.h:241
LaTeX+TikZ Writer.
Definition TikzWriter.h:52
LengthUnit
Units of length available in LaTeX.
Definition TikzWriter.h:57
@ EM
roughly the width of an 'M' (uppercase) in the current font (it depends on the font used)
@ EX
roughly the height of an 'x' (lowercase) 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
std::string getEdgeArrows(edge e) const
Get the arrows of an edge in TikZ syntax.
std::string getNodeStyle(node v) const
Get the style of a node in TikZ syntax.
bool draw(std::ostream &os)
Output the member graph to an output stream in LaTeX+TikZ format.
const GraphAttributes & m_attr
attributes of the graph to be visualized
Definition TikzWriter.h:257
void drawAllEdges(std::ostream &os)
Draws a sequence of lines for each edge in the graph.
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::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
std::string getEdgeStyle(edge e) const
Get the style of an edge in TikZ syntax.
TikzWriter(const ClusterGraphAttributes &attr, LengthUnit unit=LengthUnit::MM)
Construct a new writer for drawing cluster graphs using graph attributes.
Definition TikzWriter.h:82
std::string getNodeLabel(node v) const
Get the label of a node in TikZ syntax.
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 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::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
double calcArrowSize() const
Calculates the arrow size to be used for TikZ arrows.
std::string getNodeShape(node v) const
Get the shape of a node in TikZ syntax.
void drawCluster(std::ostream &os, cluster c)
Draws a cluster as a rectangle, using its size and style properties.
TikzWriter(const GraphAttributes &attr, LengthUnit unit=LengthUnit::MM)
Construct a new writer for drawing graphs using graph attributes.
Definition TikzWriter.h:73
void drawAllNodes(std::ostream &os, bool uniformStyle, bool uniformWidth, bool uniformHeight)
Draws each node of the graph.
static std::string getColorString(Color c)
Convert an ogdf::Color to a string in TikZ syntax.
std::string texLength(double f) const
Mainly avoid scientific notation (not handled by LaTeX) and add length unit mm.
void drawAllClusters(std::ostream &os)
Draws a rectangle for each cluster in the ogdf::ClusterGraph.
std::string getClusterStyle(cluster c) const
Get the style of a cluster in TikZ syntax.
void drawEdge(std::ostream &os, edge e)
Draws a sequence of lines for each edge in the graph.
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.
LengthUnit m_unit
The LaTeX unit to use for all ocurring lengths.
Definition TikzWriter.h:263
double getTextWidth(node v) const
Get the total width the node text may occupy.
const ClusterGraphAttributes * m_clsAttr
attributes of the cluster graph (nullptr if no cluster graph given)
Definition TikzWriter.h:260
Declaration of basic types for graphics.
StrokeType
Line types of strokes.
Definition graphics.h:50
The namespace for all OGDF objects.