Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

TikzWriter.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 
36 namespace ogdf {
37 
43 class TikzWriter {
44 public:
48  enum class LengthUnit {
49  PT,
50  MM,
51  CM,
52  IN,
53  EX,
54  EM,
55  MU
56  };
57 
65  : m_attr(attr), m_clsAttr(nullptr), m_unit(unit), m_nodeStyles(), m_edgeStyles() { }
66 
74  : m_attr(attr), m_clsAttr(&attr), m_unit(unit), m_nodeStyles(), m_edgeStyles() { }
75 
82  bool draw(std::ostream& os);
83 
84 private:
94  void wrapHeaderFooter(std::ostream& os, std::string tikzPic, bool uniformStyle,
95  bool uniformWidth, bool uniformHeight) const;
96 
102  void drawAllClusters(std::ostream& os);
103 
112  void drawAllNodes(std::ostream& os, bool uniformStyle, bool uniformWidth, bool uniformHeight);
113 
119  void drawAllEdges(std::ostream& os);
120 
127  void drawCluster(std::ostream& os, cluster c);
128 
138  void drawNode(std::ostream& os, node v, bool uniformStyle, bool uniformWidth, bool uniformHeight);
139 
146  void drawEdge(std::ostream& os, edge e);
147 
154  std::string getClusterStyle(cluster c) const;
155 
162  std::string getNodeShape(node v) const;
163 
170  std::string getNodeStyle(node v) const;
171 
178  std::string getNodeLabel(node v) const;
179 
186  double getTextWidth(node v) const;
187 
194  std::string getEdgeStyle(edge e) const;
195 
202  std::string getEdgeArrows(edge e) const;
203 
212  std::string getEdgeLabel(edge e, const DPoint& previousPoint, const DPoint& labelPoint) const;
213 
219  double calcArrowSize() const;
220 
227  std::string texLength(double f) const;
228 
237  std::string getLineStyle(StrokeType strokeType, double strokeWidth, Color strokeColor) const;
238 
245  static std::string getColorString(Color c);
246 
249 
252 
255 
257  std::vector<std::string> m_nodeStyles;
258 
260  std::vector<std::string> m_edgeStyles;
261 };
262 
263 }
ogdf::Color
Colors represented as RGBA values.
Definition: graphics.h:160
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:66
ogdf::GenericPoint< double >
ogdf::StrokeType
StrokeType
Line types of strokes.
Definition: graphics.h:46
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:254
ogdf::TikzWriter
LaTeX+TikZ Writer.
Definition: TikzWriter.h:43
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:257
ogdf::TikzWriter::m_clsAttr
const ClusterGraphAttributes * m_clsAttr
attributes of the cluster graph (nullptr if no cluster graph given)
Definition: TikzWriter.h:251
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:260
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:55
ogdf::ClusterGraphAttributes
Stores additional attributes of a clustered graph (like layout information).
Definition: ClusterGraphAttributes.h:46
ogdf::TikzWriter::LengthUnit
LengthUnit
Units of length available in LaTeX.
Definition: TikzWriter.h:48
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:64
GraphIO.h
Declares class GraphIO which provides access to all graph read and write functionality.
ogdf::TikzWriter::m_attr
const GraphAttributes & m_attr
attributes of the graph to be visualized
Definition: TikzWriter.h:248
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:73
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.
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
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:233
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.