Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

GraphAttributes.h
Go to the documentation of this file.
1 
36 #pragma once
37 
38 #include <ogdf/basic/NodeArray.h>
39 #include <ogdf/basic/EdgeArray.h>
40 #include <ogdf/basic/geometry.h>
42 #include <ogdf/basic/exceptions.h>
43 
44 
45 namespace ogdf {
46 
48 
68 
69 protected:
70  const Graph *m_pGraph;
71 
72  bool m_directed;
73 
74  // graphical representation of nodes
88 
89  // other node attributes
93 
94  // graphical representation of edges
99 
100  // other edge attributes
105 
107 
108 public:
109 
113 
116  static const int nodeGraphics;
117 
119  static const int edgeGraphics;
120 
122  static const int edgeIntWeight;
123 
125  static const int edgeDoubleWeight;
126 
128  static const int edgeLabel;
129 
131  static const int nodeLabel;
132 
134  static const int edgeType;
135 
137  static const int nodeType;
138 
140  static const int nodeId;
141 
143  static const int edgeArrow;
144 
146  static const int edgeStyle;
147 
150  static const int nodeStyle;
151 
153  static const int nodeTemplate;
154 
157  static const int edgeSubGraphs;
158 
160  static const int nodeWeight;
161 
163  static const int threeD;
164 
166  static const int nodeLabelPosition;
167 
169 
173 
176 
179  GraphAttributes();
180 
182 
186  explicit GraphAttributes(const Graph &G, long attr = nodeGraphics | edgeGraphics);
187 
188  virtual ~GraphAttributes() {
189  }
190 
192  long attributes() const {
193  return m_attributes;
194  }
195 
197  inline bool has(long attr) const {
198  return (m_attributes & attr) == attr;
199  }
200 
202 
209  virtual void init(const Graph &G, long attr);
210 
213  void init(long attr);
214 
216  void addAttributes(long attr);
217 
219  void destroyAttributes(long attr);
220 
222  const Graph& constGraph() const {
223  return *m_pGraph;
224  }
225 
227 
230 
233  bool directed() const {
234  return m_directed;
235  }
236 
238  bool &directed() {
239  return m_directed;
240  }
241 
243 
246 
249 
252  double x(node v) const {
253  OGDF_ASSERT(has(nodeGraphics));
254  return m_x[v];
255  }
256 
257 
259 
262  double &x(node v) {
263  OGDF_ASSERT(has(nodeGraphics));
264  return m_x[v];
265  }
266 
267 
269 
272  double y(node v) const {
273  OGDF_ASSERT(has(nodeGraphics));
274  return m_y[v];
275  }
276 
277 
279 
282  double &y(node v) {
283  OGDF_ASSERT(has(nodeGraphics));
284  return m_y[v];
285  }
286 
287 
289 
292  double z(node v) const {
293  OGDF_ASSERT(has(threeD));
294  return m_z[v];
295  }
296 
297 
299 
302  double &z(node v) {
303  OGDF_ASSERT(has(threeD));
304  return m_z[v];
305  }
306 
307 
309 
312  double xLabel(node v) const {
313  OGDF_ASSERT(has(nodeLabelPosition));
314  return m_nodeLabelPosX[v];
315  }
316 
318 
321  double &xLabel(node v) {
322  OGDF_ASSERT(has(nodeLabelPosition));
323  return m_nodeLabelPosX[v];
324  }
325 
326 
328 
331  double yLabel(node v) const {
332  OGDF_ASSERT(has(nodeLabelPosition));
333  return m_nodeLabelPosY[v];
334  }
335 
337 
340  double &yLabel(node v) {
341  OGDF_ASSERT(has(nodeLabelPosition));
342  return m_nodeLabelPosY[v];
343  }
344 
345 
347 
350  double zLabel(node v) const {
351  OGDF_ASSERT(has(nodeLabelPosition));
352  OGDF_ASSERT(has(threeD));
353  return m_nodeLabelPosZ[v];
354  }
355 
357 
360  double &zLabel(node v) {
361  OGDF_ASSERT(has(nodeLabelPosition));
362  OGDF_ASSERT(has(threeD));
363  return m_nodeLabelPosZ[v];
364  }
365 
366 
368 
371  double width(node v) const {
372  OGDF_ASSERT(has(nodeGraphics));
373  return m_width[v];
374  }
375 
377 
380  double &width(node v) {
381  OGDF_ASSERT(has(nodeGraphics));
382  return m_width[v];
383  }
384 
385 
387 
390  const NodeArray<double> &width() const {
391  OGDF_ASSERT(has(nodeGraphics));
392  return m_width;
393  }
394 
396 
400  OGDF_ASSERT(has(nodeGraphics));
401  return m_width;
402  }
403 
404 
406 
409  double height(node v) const {
410  OGDF_ASSERT(has(nodeGraphics));
411  return m_height[v];
412  }
413 
415 
418  double &height(node v) {
419  OGDF_ASSERT(has(nodeGraphics));
420  return m_height[v];
421  }
422 
423 
425 
428  const NodeArray<double> &height() const {
429  OGDF_ASSERT(has(nodeGraphics));
430  return m_height;
431  }
432 
434 
438  OGDF_ASSERT(has(nodeGraphics));
439  return m_height;
440  }
441 
442 
444 
447  Shape shape(node v) const {
448  OGDF_ASSERT(has(nodeGraphics));
449  return m_nodeShape[v];
450  }
451 
453 
457  OGDF_ASSERT(has(nodeGraphics));
458  return m_nodeShape[v];
459  }
460 
461 
463 
467  OGDF_ASSERT(has(nodeStyle));
468  return m_nodeStroke[v].m_type;
469  }
470 
472 
476  OGDF_ASSERT(has(nodeStyle));
477  return m_nodeStroke[v].m_type;
478  }
479 
480 
482 
485  const Color &strokeColor(node v) const {
486  OGDF_ASSERT(has(nodeStyle));
487  return m_nodeStroke[v].m_color;
488  }
489 
491 
495  OGDF_ASSERT(has(nodeStyle));
496  return m_nodeStroke[v].m_color;
497  }
498 
499 
501 
504  float strokeWidth(node v) const {
505  OGDF_ASSERT(has(nodeStyle));
506  return m_nodeStroke[v].m_width;
507  }
508 
510 
513  float &strokeWidth(node v) {
514  OGDF_ASSERT(has(nodeStyle));
515  return m_nodeStroke[v].m_width;
516  }
517 
519 
523  OGDF_ASSERT(has(nodeStyle));
524  return m_nodeFill[v].m_pattern;
525  }
526 
528 
532  OGDF_ASSERT(has(nodeStyle));
533  return m_nodeFill[v].m_pattern;
534  }
535 
537 
540  const Color &fillColor(node v) const {
541  OGDF_ASSERT(has(nodeStyle));
542  return m_nodeFill[v].m_color;
543  }
544 
546 
550  OGDF_ASSERT(has(nodeStyle));
551  return m_nodeFill[v].m_color;
552  }
553 
554 
556 
559  const Color &fillBgColor(node v) const {
560  OGDF_ASSERT(has(nodeStyle));
561  return m_nodeFill[v].m_bgColor;
562  }
563 
565 
569  OGDF_ASSERT(has(nodeStyle));
570  return m_nodeFill[v].m_bgColor;
571  }
572 
573 
575 
578  const string &label(node v) const {
579  OGDF_ASSERT(has(nodeLabel));
580  return m_nodeLabel[v];
581  }
582 
584 
587  string &label(node v) {
588  OGDF_ASSERT(has(nodeLabel));
589  return m_nodeLabel[v];
590  }
591 
592 
594 
597  const string &templateNode(node v) const {
598  OGDF_ASSERT(has(nodeTemplate));
599  return m_nodeTemplate[v];
600  }
601 
603 
606  string &templateNode(node v) {
607  OGDF_ASSERT(has(nodeTemplate));
608  return m_nodeTemplate[v];
609  }
610 
611 
613 
616  int weight(node v) const {
617  OGDF_ASSERT(has(nodeWeight));
618  return m_nodeIntWeight[v];
619  }
620 
622 
625  int &weight(node v) {
626  OGDF_ASSERT(has(nodeWeight));
627  return m_nodeIntWeight[v];
628  }
629 
630 
632 
636  OGDF_ASSERT(has(nodeType));
637  return m_vType.valid() ? m_vType[v] : Graph::NodeType::vertex;
638  }
639 
641 
645  OGDF_ASSERT(has(nodeType));
646  return m_vType[v];
647  }
648 
649 
651 
654  int idNode(node v) const {
655  OGDF_ASSERT(has(nodeId));
656  return m_nodeId[v];
657  }
658 
660 
663  int &idNode(node v) {
664  OGDF_ASSERT(has(nodeId));
665  return m_nodeId[v];
666  }
667 
669 
672 
674 
676 
679  const DPolyline &bends(edge e) const {
680  OGDF_ASSERT(has(edgeGraphics));
681  return m_bends[e];
682  }
683 
685 
689  OGDF_ASSERT(has(edgeGraphics));
690  return m_bends[e];
691  }
692 
693 
695 
699  OGDF_ASSERT(has(edgeArrow));
700  return m_edgeArrow[e];
701  }
702 
704 
708  OGDF_ASSERT(has(edgeArrow));
709  return m_edgeArrow[e];
710  }
711 
712 
714 
718  OGDF_ASSERT(has(edgeStyle));
719  return m_edgeStroke[e].m_type;
720  }
721 
723 
727  OGDF_ASSERT(has(edgeStyle));
728  return m_edgeStroke[e].m_type;
729  }
730 
731 
733 
736  const Color &strokeColor(edge e) const {
737  OGDF_ASSERT(has(edgeStyle));
738  return m_edgeStroke[e].m_color;
739  }
740 
742 
746  OGDF_ASSERT(has(edgeStyle));
747  return m_edgeStroke[e].m_color;
748  }
749 
750 
752 
755  float strokeWidth(edge e) const {
756  OGDF_ASSERT(has(edgeStyle));
757  return m_edgeStroke[e].m_width;
758  }
759 
761 
764  float &strokeWidth(edge e) {
765  OGDF_ASSERT(has(edgeStyle));
766  return m_edgeStroke[e].m_width;
767  }
768 
769 
771 
774  const string &label(edge e) const {
775  OGDF_ASSERT(has(edgeLabel));
776  return m_edgeLabel[e];
777  }
778 
780 
783  string &label(edge e) {
784  OGDF_ASSERT(has(edgeLabel));
785  return m_edgeLabel[e];
786  }
787 
788 
790 
793  int intWeight(edge e) const {
794  OGDF_ASSERT(has(edgeIntWeight));
795  return m_intWeight[e];
796  }
797 
799 
802  int &intWeight(edge e) {
803  OGDF_ASSERT(has(edgeIntWeight));
804  return m_intWeight[e];
805  }
806 
807 
809 
812  double doubleWeight(edge e) const {
813  OGDF_ASSERT(has(edgeDoubleWeight));
814  return m_doubleWeight[e];
815  }
816 
818 
821  double &doubleWeight(edge e) {
822  OGDF_ASSERT(has(edgeDoubleWeight));
823  return m_doubleWeight[e];
824  }
825 
826 
828 
832  OGDF_ASSERT(has(edgeType));
833  return m_eType.valid() ? m_eType[e] : Graph::EdgeType::association;
834  }
835 
837 
841  OGDF_ASSERT(has(edgeType));
842  return m_eType[e];
843  }
844 
845 
847 
850  uint32_t subGraphBits(edge e) const {
851  OGDF_ASSERT(has(edgeSubGraphs));
852  return m_subGraph[e];
853  }
854 
856 
859  uint32_t &subGraphBits(edge e) {
860  OGDF_ASSERT(has(edgeSubGraphs));
861  return m_subGraph[e];
862  }
863 
864 
866 
869  bool inSubGraph(edge e, int n) const {
870  OGDF_ASSERT(has(edgeSubGraphs));
871  OGDF_ASSERT(n>=0);
872  OGDF_ASSERT(n<32);
873  return (m_subGraph[e] & (1 << n)) != 0;
874  }
875 
876 
878 
881  void addSubGraph(edge e, int n) {
882  OGDF_ASSERT(has(edgeSubGraphs));
883  OGDF_ASSERT(n>=0);
884  OGDF_ASSERT(n<32);
885  m_subGraph[e] |= (1 << n);
886  }
887 
888 
890 
893  void removeSubGraph(edge e, int n) {
894  OGDF_ASSERT(has(edgeSubGraphs));
895  OGDF_ASSERT(n>=0);
896  OGDF_ASSERT(n<32);
897  m_subGraph[e] &= ~(1 << n);
898  }
899 
901 
904 
907 
916  virtual void scale(double sx, double sy, bool scaleNodes = true);
917 
919 
927  virtual void scale(double s, bool scaleNodes = true) { scale(s, s, scaleNodes); }
928 
930 
934  virtual void translate(double dx, double dy);
935 
937  virtual void translateToNonNeg();
938 
940 
944  virtual void flipVertical() { flipVertical(boundingBox()); }
945 
947 
951  virtual void flipVertical(const DRect &box);
952 
954 
958  virtual void flipHorizontal() { flipHorizontal(boundingBox()); }
959 
961 
965  virtual void flipHorizontal(const DRect &box);
966 
968 
978  virtual void scaleAndTranslate(double sx, double sy, double dx, double dy, bool scaleNodes = true);
979 
981 
990  virtual void scaleAndTranslate(double s, double dx, double dy, bool scaleNodes = true) {
991  scaleAndTranslate(s, s, dx, dy, scaleNodes);
992  }
993 
995  virtual void rotateRight90();
996 
998  virtual void rotateLeft90();
999 
1001 
1004 
1007 
1010  virtual DRect boundingBox() const;
1011 
1013 
1016  void setAllWidth(double w);
1017 
1019 
1022  void setAllHeight(double h);
1023 
1025 
1028  void clearAllBends();
1029 
1031 
1040  void removeUnnecessaryBendsHV();
1041 
1043 
1054  void addNodeCenter2Bends(int mode = 1);
1055 
1057 
1065  bool isAssociationClass(node v) const {
1067  }
1068 
1070 
1078  int hierarchyList(List<List<node>*> &list) const;
1079 
1081 
1089  int hierarchyList(List<List<edge>*> &list) const;
1090 
1092 };
1093 
1094 }
bool & directed()
Returns if the graph is directed.
EdgeArrow & arrowType(edge e)
Returns the arrow type of edge e.
Color & strokeColor(edge e)
Returns the stroke color of edge e.
double width(node v) const
Returns the width of the bounding box of node v.
double & zLabel(node v)
Returns the label z-coordinate of node v.
static const int edgeGraphics
Corresponds to edge attribute bends(edge).
int & idNode(node v)
Returns the user ID of node v.
uint32_t & subGraphBits(edge e)
Returns the edgesubgraph value of an edge e.
EdgeArray< Stroke > m_edgeStroke
stroke of an edge
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
NodeArray< double > m_width
width of a node&#39;s bounding box
const Color & fillColor(node v) const
Returns the fill color of node v.
StrokeType & strokeType(edge e)
Returns the stroke type of edge e.
FillPattern fillPattern(node v) const
Returns the fill pattern of node v.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
static const int threeD
Corresponds to node attribute z(node). Note that all methods work on 2D coordinates only...
static const int edgeStyle
Corresponds to edge attributes strokeColor(edge), strokeType(edge), and strokeWidth(edge).
bool has(long attr) const
Returns true iff all attributes in attr are available.
NodeArray< double > m_z
z-coordinate of a node
bool m_directed
whether or not the graph is directed
virtual void scale(double s, bool scaleNodes=true)
Scales the layout by s.
const Color & strokeColor(node v) const
Returns the stroke color of node v.
Rectangles with real coordinates.
Definition: geometry.h:515
const Graph * m_pGraph
associated graph
virtual void flipVertical()
Flips the layout vertically within its bounding box.
static const int edgeType
Corresponds to edge attribute type(edge).
StrokeType & strokeType(node v)
Returns the stroke type of node v.
Polylines with real coordinates.
Definition: geometry.h:350
static const int nodeTemplate
Corresponds to node attribute templateNode(node).
static const int nodeGraphics
Corresponds to node attributes x(node), y(node), width(node), height(node), and shape(node).
double & z(node v)
Returns the z-coordinate of node v.
Graph::NodeType & type(node v)
Returns the type of node v.
EdgeArray< Graph::EdgeType > m_eType
type of an edge (association or generalization)
double & xLabel(node v)
Returns the label x-coordinate of node v.
Declares class LayoutStandards which specifies default / standard values used in graph layouts...
string & label(edge e)
Returns the label of edge e.
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
bool directed() const
Returns if the graph is directed.
int weight(node v) const
Returns the weight of node v.
FillPattern
Fill patterns.
Definition: graphics.h:88
bool valid() const
Returns true iff the array is associated with a graph.
Definition: EdgeArray.h:161
EdgeArrow
Types for edge arrows.
Definition: graphics.h:142
bool isAssociationClass(node v) const
Returns true iff v represents an association class.
string & label(node v)
Returns the label of node v.
const DPolyline & bends(edge e) const
Returns the list of bend points of edge e.
static const int nodeStyle
Corresponds to node attributes strokeColor(node), strokeType(node), strokeWidth(node), fillPattern(node), fillColor(node), and fillBgColor(node).
EdgeArray< uint32_t > m_subGraph
is element of subgraphs given by bitvector
Color & strokeColor(node v)
Returns the stroke color of node v.
NodeArray< Stroke > m_nodeStroke
stroke of a node
double height(node v) const
Returns the height of the bounding box of node v.
double & y(node v)
Returns the y-coordinate of node v.
void removeSubGraph(edge e, int n)
Removes edge e from basic graph n.
double xLabel(node v) const
Returns the label x-coordinate of node v.
const string & label(edge e) const
Returns the label of edge e.
EdgeArray< EdgeArrow > m_edgeArrow
arrow type of an edge
static const int edgeDoubleWeight
Corresponds to edge attribute doubleWeight(edge).
bool inSubGraph(edge e, int n) const
Checks whether edge e belongs to basic graph n.
double y(node v) const
Returns the y-coordinate of node v.
string & templateNode(node v)
Returns the template name of node v.
static const int edgeLabel
Corresponds to edge attribute label(edge).
Shape
Types for node shapes.
Definition: graphics.h:120
NodeArray< double > m_nodeLabelPosZ
z-coordinate of a node label
NodeArray< string > m_nodeLabel
label of a node
long m_attributes
bit vector of currently used attributes
virtual void flipHorizontal()
Flips the layout horizontally within its bounding box.
Declaration and implementation of EdgeArray class.
const string & label(node v) const
Returns the label of node v.
Graph::EdgeType type(edge e) const
Returns the type of edge e.
NodeArray< Graph::NodeType > m_vType
type (vertex, dummy, generalizationMerger)
NodeArray< double > & height()
Returns a reference to the node array m_height.
static const int nodeId
Corresponds to node attribute idNode(node).
NodeArray< int > m_nodeId
user ID of a node
EdgeType
The type of edges (only used in derived classes).
Definition: Graph_d.h:518
static const int nodeType
Corresponds to node attribute type(node).
DPolyline & bends(edge e)
Returns the list of bend points of edge e.
static const int nodeLabel
Corresponds to node attribute label(node).
Colors represented as RGBA values.
Definition: graphics.h:161
Stores additional attributes of a graph (like layout information).
int intWeight(edge e) const
Returns the (integer) weight of edge e.
float & strokeWidth(edge e)
Returns the stroke width of edge e.
double & height(node v)
Returns the height of the bounding box of node v.
NodeArray< string > m_nodeTemplate
name of template of a node
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
Definition of exception classes.
NodeArray< int > m_nodeIntWeight
(integer) weight of a node
virtual void scaleAndTranslate(double s, double dx, double dy, bool scaleNodes=true)
Scales the layout by s and then translates it by (dx,dy).
NodeArray< double > m_nodeLabelPosX
x-coordinate of a node label
int & intWeight(edge e)
Returns the (integer) weight of edge e.
const string & templateNode(node v) const
Returns the template name of node v.
Class for the representation of edges.
Definition: Graph_d.h:291
double z(node v) const
Returns the z-coordinate of node v.
int & weight(node v)
Returns the weight of node v.
double x(node v) const
Returns the x-coordinate of node v.
long attributes() const
Returns currently accessible attributes.
Class for the representation of nodes.
Definition: Graph_d.h:167
bool valid() const
Returns true iff the array is associated with a graph.
Definition: NodeArray.h:157
NodeArray< double > m_x
x-coordinate of a node
const Graph & constGraph() const
Returns a reference to the associated graph.
Declaration and implementation of NodeArray class.
float strokeWidth(edge e) const
Returns the stroke width of edge e.
double zLabel(node v) const
Returns the label z-coordinate of node v.
const Color & fillBgColor(node v) const
Returns the background color of fill patterns for node v.
NodeArray< Shape > m_nodeShape
shape of a node
NodeArray< double > m_height
height of a nodes&#39;s bounding box
double & x(node v)
Returns the x-coordinate of node v.
StrokeType strokeType(node v) const
Returns the stroke type of node v.
EdgeArray< double > m_doubleWeight
(real number) weight of an edge
Graph::EdgeType & type(edge e)
Returns the type of edge e.
Color & fillColor(node v)
Returns the fill color of node v.
double yLabel(node v) const
Returns the label y-coordinate of node v.
StrokeType strokeType(edge e) const
Returns the stroke type of edge e.
const NodeArray< double > & height() const
Returns a reference to the node array m_height.
Graph::NodeType type(node v) const
Returns the type of node v.
static const int edgeSubGraphs
Corresponds to edge attributes modified by addSubGraph(edge, int), inSubGraph(edge, int) const, and removeSubGraph(edge, int).
int idNode(node v) const
Returns the user ID of node v.
StrokeType
Line types of strokes.
Definition: graphics.h:43
double & width(node v)
Returns the width of the bounding box of node v.
const Color & strokeColor(edge e) const
Returns the stroke color of edge e.
EdgeArray< int > m_intWeight
(integer) weight of an edge
static const int edgeIntWeight
Corresponds to edge attribute intWeight(edge).
double doubleWeight(edge e) const
Returns the (real number) weight of edge e.
static const int edgeArrow
Corresponds to edge attribute arrowType(edge).
The namespace for all OGDF objects.
Declaration of classes DPoint, DPolyline, DLine, DRect, DIntersectableRect, DScaler.
float strokeWidth(node v) const
Returns the stroke width of node v.
NodeArray< double > m_nodeLabelPosY
y-coordinate of a node label
NodeArray< Fill > m_nodeFill
fill of a node
NodeType
The type of nodes.
Definition: Graph_d.h:525
static const int nodeLabelPosition
Corresponds to node attributes xLabel(node), yLabel(node), and zLabel(node).
double & yLabel(node v)
Returns the label y-coordinate of node v.
uint32_t subGraphBits(edge e) const
Returns the edgesubgraph value of an edge e.
float & strokeWidth(node v)
Returns the stroke width of node v.
EdgeArrow arrowType(edge e) const
Returns the arrow type of edge e.
NodeArray< double > m_y
y-coordinate of a node
Color & fillBgColor(node v)
Returns the background color of fill patterns for node v.
FillPattern & fillPattern(node v)
Returns the fill pattern of node v.
double & doubleWeight(edge e)
Returns the (real number) weight of edge e.
static const int nodeWeight
Corresponds to node attribute weight(node).
void addSubGraph(edge e, int n)
Adds edge e to basic graph n.
Shape shape(node v) const
Returns the shape type of node v.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
EdgeArray< DPolyline > m_bends
list of bend points of an edge
NodeArray< double > & width()
Returns a reference to the node array #m_width.
EdgeArray< string > m_edgeLabel
label of an edge
Shape & shape(node v)
Returns the shape type of node v.
const NodeArray< double > & width() const
Returns a reference to the node array m_width.